xref: /onnv-gate/usr/src/uts/common/fs/smbsrv/smb_dispatch.c (revision 9343:ef29909f1c11)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
215331Samw /*
228670SJose.Borrego@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
235331Samw  * Use is subject to license terms.
245331Samw  */
255331Samw 
265331Samw /*
278934SJose.Borrego@Sun.COM  * SMB requests.
285331Samw  *
295331Samw  * Request
305331Samw  *   Header
315331Samw  *	Magic		0xFF 'S' 'M' 'B'
325331Samw  *	smb_com 	a byte, the "first" command
335331Samw  *	Error		a 4-byte union, ignored in a request
345331Samw  *	smb_flg		a one byte set of eight flags
355331Samw  *	smb_flg2	a two byte set of 16 flags
365331Samw  *	.		twelve reserved bytes, have a role
375331Samw  *			in connectionless transports (IPX, UDP?)
385331Samw  *	smb_tid		a 16-bit tree ID, a mount point sorta,
395331Samw  *			0xFFFF is this command does not have
405331Samw  *			or require a tree context
415331Samw  *	smb_pid		a 16-bit process ID
425331Samw  *	smb_uid		a 16-bit user ID, specific to this "session"
435331Samw  *			and mapped to a system (bona-fide) UID
445331Samw  *	smb_mid		a 16-bit multiplex ID, used to differentiate
455331Samw  *			multiple simultaneous requests from the same
465331Samw  *			process (pid) (ref RPC "xid")
475331Samw  *
485331Samw  *   Chained (AndX) commands (0 or more)
495331Samw  *	smb_wct		a byte, number of 16-bit words containing
505331Samw  *			command parameters, min 2 for chained command
515331Samw  *	andx_com	a byte, the "next" command, 0xFF for none
525331Samw  *	.		an unused byte
535331Samw  *	andx_off	a 16-bit offset, byte displacement from &Magic
545331Samw  *			to the smb_wct field of the "next" command,
555331Samw  *			ignore if andx_com is 0xFF, s/b 0 if no next
565331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
575331Samw  *			"this" command (i.e. smb_com if this is the
585331Samw  *			first parameters, or the andx_com of the just
595331Samw  *			previous block.
605331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
615331Samw  *	smb_data[]	0 or more bytes, format specific to commands
625331Samw  *	padding[]	Optional padding
635331Samw  *
645331Samw  *   Last command
655331Samw  *	smb_wct		a byte, number of 16-bit words containing
665331Samw  *			command parameters, min 0 for chained command
675331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
685331Samw  *			"this" command (i.e. smb_com if this is the
695331Samw  *			first parameters, or the andx_com of the just
705331Samw  *			previous block.
715331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
725331Samw  *	smb_data[]	0 or more bytes, format specific to commands
735331Samw  *
745331Samw  * Reply
755331Samw  *   Header
765331Samw  *	Magic		0xFF 'S' 'M' 'B'
775331Samw  *	smb_com 	a byte, the "first" command, corresponds
785331Samw  *			to request
795331Samw  *	Error		a 4-byte union, coding depends on dialect in use
805331Samw  *			for "DOS" errors
815331Samw  *				a byte for error class
825331Samw  *				an unused byte
835331Samw  *				a 16-bit word for error code
845331Samw  *			for "NT" errors
855331Samw  *				a 32-bit error code which
865331Samw  *				is a packed class and specifier
875331Samw  *			for "OS/2" errors
885331Samw  *				I don't know
895331Samw  *			The error information is specific to the
905331Samw  *			last command in the reply chain.
915331Samw  *	smb_flg		a one byte set of eight flags, 0x80 bit set
925331Samw  *			indicating this message is a reply
935331Samw  *	smb_flg2	a two byte set of 16 flags
945331Samw  *	.		twelve reserved bytes, have a role
955331Samw  *			in connectionless transports (IPX, UDP?)
965331Samw  *	smb_tid		a 16-bit tree ID, a mount point sorta,
975331Samw  *			should be the same as the request
985331Samw  *	smb_pid		a 16-bit process ID, MUST BE the same as request
995331Samw  *	smb_uid		a 16-bit user ID, specific to this "session"
1005331Samw  *			and mapped to a system (bona-fide) UID,
1015331Samw  *			should be the same as request
1025331Samw  *	smb_mid		a 16-bit multiplex ID, used to differentiate
1035331Samw  *			multiple simultaneous requests from the same
1045331Samw  *			process (pid) (ref RPC "xid"), MUST BE the
1055331Samw  *			same as request
1065331Samw  *	padding[]	Optional padding
1075331Samw  *
1085331Samw  *   Chained (AndX) commands (0 or more)
1095331Samw  *	smb_wct		a byte, number of 16-bit words containing
1105331Samw  *			command parameters, min 2 for chained command,
1115331Samw  *	andx_com	a byte, the "next" command, 0xFF for none,
1125331Samw  *			corresponds to request, if this is the chained
1135331Samw  *			command that had an error set to 0xFF
1145331Samw  *	.		an unused byte
1155331Samw  *	andx_off	a 16-bit offset, byte displacement from &Magic
1165331Samw  *			to the smb_wct field of the "next" command,
1175331Samw  *			ignore if andx_com is 0xFF, s/b 0 if no next
1185331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
1195331Samw  *			"this" command (i.e. smb_com if this is the
1205331Samw  *			first parameters, or the andx_com of the just
1215331Samw  *			previous block. Empty if an error.
1225331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
1235331Samw  *	smb_data[]	0 or more bytes, format specific to commands
1245331Samw  *			empty if an error.
1255331Samw  *
1265331Samw  *   Last command
1275331Samw  *	smb_wct		a byte, number of 16-bit words containing
1285331Samw  *			command parameters, min 0 for chained command
1295331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
1305331Samw  *			"this" command (i.e. smb_com if this is the
1315331Samw  *			first parameters, or the andx_com of the just
1325331Samw  *			previous block, empty if an error.
1335331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
1345331Samw  *	smb_data[]	0 or more bytes, format specific to commands,
1355331Samw  *			empty if an error.
1365331Samw  */
1375331Samw 
1385331Samw #include <smbsrv/smb_incl.h>
1396432Sas200622 #include <smbsrv/smb_kstat.h>
1405331Samw #include <sys/sdt.h>
1415331Samw 
1425331Samw #define	SMB_ALL_DISPATCH_STAT_INCR(stat)	atomic_inc_64(&stat);
1436139Sjb150015 #define	SMB_COM_NUM	256
1445331Samw 
1455331Samw static kstat_t *smb_dispatch_ksp = NULL;
1466139Sjb150015 static kmutex_t smb_dispatch_ksmtx;
1475331Samw 
1486030Sjb150015 static int is_andx_com(unsigned char);
1496030Sjb150015 static int smbsr_check_result(struct smb_request *, int, int);
1505331Samw 
1518934SJose.Borrego@Sun.COM static smb_disp_entry_t	dispatch[SMB_COM_NUM] = {
1526139Sjb150015 	{ SMB_SDT_OPS(create_directory),			/* 0x00 000 */
153*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1545331Samw 	    { "SmbCreateDirectory", KSTAT_DATA_UINT64 } },
1556139Sjb150015 	{ SMB_SDT_OPS(delete_directory),			/* 0x01 001 */
156*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1575331Samw 	    { "SmbDeleteDirectory", KSTAT_DATA_UINT64 } },
1586139Sjb150015 	{ SMB_SDT_OPS(open),					/* 0x02 002 */
159*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1605331Samw 	    { "SmbOpen", KSTAT_DATA_UINT64 } },
1616139Sjb150015 	{ SMB_SDT_OPS(create),					/* 0x03 003 */
162*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1635331Samw 	    { "SmbCreate", KSTAT_DATA_UINT64 } },
1646139Sjb150015 	{ SMB_SDT_OPS(close),					/* 0x04 004 */
165*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1665331Samw 	    { "SmbClose", KSTAT_DATA_UINT64 } },
1676139Sjb150015 	{ SMB_SDT_OPS(flush),					/* 0x05 005 */
168*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1695331Samw 	    { "SmbFlush", KSTAT_DATA_UINT64 } },
1706139Sjb150015 	{ SMB_SDT_OPS(delete),					/* 0x06 006 */
171*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1725331Samw 	    { "SmbDelete", KSTAT_DATA_UINT64 } },
1736139Sjb150015 	{ SMB_SDT_OPS(rename),					/* 0x07 007 */
174*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1755331Samw 	    { "SmbRename", KSTAT_DATA_UINT64 } },
1766139Sjb150015 	{ SMB_SDT_OPS(query_information),			/* 0x08 008 */
177*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1785331Samw 	    { "SmbQueryInformation", KSTAT_DATA_UINT64 } },
1796139Sjb150015 	{ SMB_SDT_OPS(set_information),				/* 0x09 009 */
180*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1815331Samw 	    { "SmbSetInformation", KSTAT_DATA_UINT64 } },
1826139Sjb150015 	{ SMB_SDT_OPS(read),					/* 0x0A 010 */
183*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1845331Samw 	    { "SmbRead", KSTAT_DATA_UINT64 } },
1856139Sjb150015 	{ SMB_SDT_OPS(write),					/* 0x0B 011 */
186*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1875331Samw 	    { "SmbWrite", KSTAT_DATA_UINT64 } },
1886139Sjb150015 	{ SMB_SDT_OPS(lock_byte_range),				/* 0x0C 012 */
189*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1905331Samw 	    { "SmbLockByteRange", KSTAT_DATA_UINT64 } },
1916139Sjb150015 	{ SMB_SDT_OPS(unlock_byte_range),			/* 0x0D 013 */
192*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1935331Samw 	    { "SmbUnlockByteRange", KSTAT_DATA_UINT64 } },
1946139Sjb150015 	{ SMB_SDT_OPS(create_temporary),			/* 0x0E 014 */
195*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1965331Samw 	    { "SmbCreateTemporary", KSTAT_DATA_UINT64 } },
1976139Sjb150015 	{ SMB_SDT_OPS(create_new),				/* 0x0F 015 */
198*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
1995331Samw 	    { "SmbCreateNew",	KSTAT_DATA_UINT64 } },
2006139Sjb150015 	{ SMB_SDT_OPS(check_directory),				/* 0x10 016 */
201*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
2025331Samw 	    { "SmbCheckDirectory", KSTAT_DATA_UINT64 } },
2036139Sjb150015 	{ SMB_SDT_OPS(process_exit),				/* 0x11 017 */
2045331Samw 	    PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
2055331Samw 	    { "SmbProcessExit", KSTAT_DATA_UINT64 } },
2066139Sjb150015 	{ SMB_SDT_OPS(seek),					/* 0x12 018 */
207*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
2085331Samw 	    { "SmbSeek", KSTAT_DATA_UINT64 } },
2096139Sjb150015 	{ SMB_SDT_OPS(lock_and_read),				/* 0x13 019 */
210*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2115331Samw 	    { "SmbLockAndRead", KSTAT_DATA_UINT64 } },
2126139Sjb150015 	{ SMB_SDT_OPS(write_and_unlock),			/* 0x14 020 */
213*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2145331Samw 	    { "SmbWriteAndUnlock", KSTAT_DATA_UINT64 } },
215*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x15 021 */
216*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x16 022 */
217*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x17 023 */
218*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x18 024 */
219*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x19 025 */
2206139Sjb150015 	{ SMB_SDT_OPS(read_raw),				/* 0x1A 026 */
221*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2225331Samw 	    { "SmbReadRaw", KSTAT_DATA_UINT64 } },
223*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x1B 027 */
224*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x1C 028 */
2256139Sjb150015 	{ SMB_SDT_OPS(write_raw),				/* 0x1D 029 */
226*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2275331Samw 	    { "SmbWriteRaw", KSTAT_DATA_UINT64 } },
228*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x1E 030 */
229*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x1F 031 */
230*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x20 032 */
231*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x21 033 */
2326139Sjb150015 	{ SMB_SDT_OPS(set_information2),			/* 0x22 034 */
233*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2345331Samw 	    { "SmbSetInformation2", KSTAT_DATA_UINT64 } },
2356139Sjb150015 	{ SMB_SDT_OPS(query_information2),			/* 0x23 035 */
236*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2375331Samw 	    { "SmbQueryInformation2",	KSTAT_DATA_UINT64 } },
2386139Sjb150015 	{ SMB_SDT_OPS(locking_andx),				/* 0x24 036 */
239*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2405331Samw 	    { "SmbLockingX", KSTAT_DATA_UINT64 } },
2416139Sjb150015 	{ SMB_SDT_OPS(transaction),				/* 0x25 037 */
242*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2435331Samw 	    { "SmbTransaction", KSTAT_DATA_UINT64 } },
2446139Sjb150015 	{ SMB_SDT_OPS(transaction_secondary),			/* 0x26 038 */
245*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2465331Samw 	    { "SmbTransactionSecondary", KSTAT_DATA_UINT64 } },
2476139Sjb150015 	{ SMB_SDT_OPS(ioctl),					/* 0x27 039 */
248*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2495331Samw 	    { "SmbIoctl", KSTAT_DATA_UINT64 } },
250*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x28 040 */
251*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x29 041 */
252*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x2A 042 */
2536139Sjb150015 	{ SMB_SDT_OPS(echo),					/* 0x2B 043 */
2545331Samw 	    LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
2555331Samw 	    { "SmbEcho", KSTAT_DATA_UINT64 } },
2566139Sjb150015 	{ SMB_SDT_OPS(write_and_close),				/* 0x2C 044 */
257*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2585331Samw 	    { "SmbWriteAndClose", KSTAT_DATA_UINT64 } },
2596139Sjb150015 	{ SMB_SDT_OPS(open_andx),				/* 0x2D 045 */
260*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2615331Samw 	    { "SmbOpenX", KSTAT_DATA_UINT64 } },
2626139Sjb150015 	{ SMB_SDT_OPS(read_andx),				/* 0x2E 046 */
263*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2645331Samw 	    { "SmbReadX", KSTAT_DATA_UINT64 } },
2656139Sjb150015 	{ SMB_SDT_OPS(write_andx),				/* 0x2F 047 */
266*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2675331Samw 	    { "SmbWriteX",	KSTAT_DATA_UINT64 } },
268*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x30 048 */
2696139Sjb150015 	{ SMB_SDT_OPS(close_and_tree_disconnect),		/* 0x31 049 */
270*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
2715331Samw 	    { "SmbCloseAndTreeDisconnect", KSTAT_DATA_UINT64 } },
2726139Sjb150015 	{ SMB_SDT_OPS(transaction2),				/* 0x32 050 */
273*9343SAfshin.Ardakani@Sun.COM 	    LM1_2X002, 0,
2745331Samw 	    { "SmbTransaction2", KSTAT_DATA_UINT64 } },
2756139Sjb150015 	{ SMB_SDT_OPS(transaction2_secondary),			/* 0x33 051 */
276*9343SAfshin.Ardakani@Sun.COM 	    LM1_2X002, 0,
2775331Samw 	    { "SmbTransaction2Secondary", KSTAT_DATA_UINT64 } },
2786139Sjb150015 	{ SMB_SDT_OPS(find_close2),				/* 0x34 052 */
279*9343SAfshin.Ardakani@Sun.COM 	    LM1_2X002, 0,
2805331Samw 	    { "SmbFindClose2", KSTAT_DATA_UINT64 } },
281*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x35 053 */
282*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x36 054 */
283*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x37 055 */
284*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x38 056 */
285*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x39 057 */
286*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x3A 058 */
287*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x3B 059 */
288*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x3C 060 */
289*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x3D 061 */
290*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x3E 062 */
291*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x3F 063 */
292*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x40 064 */
293*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x41 065 */
294*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x42 066 */
295*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x43 067 */
296*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x44 068 */
297*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x45 069 */
298*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x46 070 */
299*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x47 071 */
300*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x48 072 */
301*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x49 073 */
302*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x4A 074 */
303*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x4B 075 */
304*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x4C 076 */
305*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x4D 077 */
306*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x4E 078 */
307*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x4F 079 */
308*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x50 080 */
309*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x51 081 */
310*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x52 082 */
311*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x53 083 */
312*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x54 084 */
313*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x55 085 */
314*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x56 086 */
315*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x57 087 */
316*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x58 088 */
317*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x59 089 */
318*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x5A 090 */
319*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x5B 091 */
320*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x5C 092 */
321*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x5D 093 */
322*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x5E 094 */
323*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x5F 095 */
324*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x60 096 */
325*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x61 097 */
326*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x62 098 */
327*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x63 099 */
328*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x64 100 */
329*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x65 101 */
330*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x66 102 */
331*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x67 103 */
332*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x68 104 */
333*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x69 105 */
334*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x6A 106 */
335*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x6B 107 */
336*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x6C 108 */
337*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x6D 109 */
338*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x6E 110 */
339*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x6F 111 */
3406139Sjb150015 	{ SMB_SDT_OPS(tree_connect),				/* 0x70 112 */
341*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID,
3425331Samw 	    { "SmbTreeConnect", KSTAT_DATA_UINT64 } },
3436139Sjb150015 	{ SMB_SDT_OPS(tree_disconnect),				/* 0x71 113 */
3445331Samw 	    PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
3455331Samw 	    { "SmbTreeDisconnect", KSTAT_DATA_UINT64 } },
3466139Sjb150015 	{ SMB_SDT_OPS(negotiate),				/* 0x72 114 */
3475331Samw 	    PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
3485331Samw 	    { "SmbNegotiate", KSTAT_DATA_UINT64 } },
3496139Sjb150015 	{ SMB_SDT_OPS(session_setup_andx),			/* 0x73 115 */
3505331Samw 	    LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
3515331Samw 	    { "SmbSessionSetupX",	KSTAT_DATA_UINT64 } },
3526139Sjb150015 	{ SMB_SDT_OPS(logoff_andx),				/* 0x74 116 */
353*9343SAfshin.Ardakani@Sun.COM 	    LM1_2X002, SDDF_SUPPRESS_TID,
3545331Samw 	    { "SmbLogoffX", KSTAT_DATA_UINT64 } },
3556139Sjb150015 	{ SMB_SDT_OPS(tree_connect_andx),			/* 0x75 117 */
356*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, SDDF_SUPPRESS_TID,
3575331Samw 	    { "SmbTreeConnectX", KSTAT_DATA_UINT64 } },
358*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x76 118 */
359*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x77 119 */
360*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x78 120 */
361*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x79 121 */
362*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x7A 122 */
363*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x7B 123 */
364*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x7C 124 */
365*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x7D 125 */
366*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x7E 126 */
367*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x7F 127 */
3686139Sjb150015 	{ SMB_SDT_OPS(query_information_disk),			/* 0x80 128 */
369*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
3705331Samw 	    { "SmbQueryInformationDisk", KSTAT_DATA_UINT64 } },
3716139Sjb150015 	{ SMB_SDT_OPS(search),					/* 0x81 129 */
372*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
3735331Samw 	    { "SmbSearch", KSTAT_DATA_UINT64 } },
3746139Sjb150015 	{ SMB_SDT_OPS(find),					/* 0x82 130 */
375*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
3765331Samw 	    { "SmbFind", KSTAT_DATA_UINT64 } },
3776139Sjb150015 	{ SMB_SDT_OPS(find_unique),				/* 0x83 131 */
378*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
3795331Samw 	    { "SmbFindUnique", KSTAT_DATA_UINT64 } },
3806139Sjb150015 	{ SMB_SDT_OPS(find_close),				/* 0x84 132 */
381*9343SAfshin.Ardakani@Sun.COM 	    LANMAN1_0, 0,
3825331Samw 	    { "SmbFindClose", KSTAT_DATA_UINT64 } },
383*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x85 133 */
384*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x86 134 */
385*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x87 135 */
386*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x88 136 */
387*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x89 137 */
388*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x8A 138 */
389*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x8B 139 */
390*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x8C 140 */
391*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x8D 141 */
392*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x8E 142 */
393*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x8F 143 */
394*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x90 144 */
395*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x91 145 */
396*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x92 146 */
397*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x93 147 */
398*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x94 148 */
399*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x95 149 */
400*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x96 150 */
401*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x97 151 */
402*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x98 152 */
403*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x99 153 */
404*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x9A 154 */
405*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x9B 155 */
406*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x9C 156 */
407*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x9D 157 */
408*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x9E 158 */
409*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0x9F 159 */
4106139Sjb150015 	{ SMB_SDT_OPS(nt_transact),				/* 0xA0 160 */
411*9343SAfshin.Ardakani@Sun.COM 	    NT_LM_0_12, 0,
4125331Samw 	    { "SmbNtTransact",	KSTAT_DATA_UINT64 } },
4136139Sjb150015 	{ SMB_SDT_OPS(nt_transact_secondary),			/* 0xA1 161 */
414*9343SAfshin.Ardakani@Sun.COM 	    NT_LM_0_12, 0,
4155331Samw 	    { "SmbNtTransactSecondary",	KSTAT_DATA_UINT64 } },
4166139Sjb150015 	{ SMB_SDT_OPS(nt_create_andx),				/* 0xA2 162 */
417*9343SAfshin.Ardakani@Sun.COM 	    NT_LM_0_12, 0,
4185331Samw 	    { "SmbNtCreateX",	KSTAT_DATA_UINT64 } },
419*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xA3 163 */
4206139Sjb150015 	{ SMB_SDT_OPS(nt_cancel),				/* 0xA4 164 */
421*9343SAfshin.Ardakani@Sun.COM 	    NT_LM_0_12, 0,
4225331Samw 	    { "SmbNtCancel",	KSTAT_DATA_UINT64 } },
423*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xA5 165 */
424*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xA6 166 */
425*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xA7 167 */
426*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xA8 168 */
427*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xA9 169 */
428*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xAA 170 */
429*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xAB 171 */
430*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xAC 172 */
431*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xAD 173 */
432*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xAE 174 */
433*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xAF 175 */
434*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB0 176 */
435*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB1 177 */
436*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB2 178 */
437*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB3 179 */
438*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB4 180 */
439*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB5 181 */
440*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB6 182 */
441*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB7 183 */
442*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB8 184 */
443*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xB9 185 */
444*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xBA 186 */
445*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xBB 187 */
446*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xBC 188 */
447*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xBD 189 */
448*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xBE 190 */
449*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xBF 191 */
4506139Sjb150015 	{ SMB_SDT_OPS(open_print_file),				/* 0xC0 192 */
451*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
4525331Samw 	    { "SmbOpenPrintFile", KSTAT_DATA_UINT64 } },
4536139Sjb150015 	{ SMB_SDT_OPS(write_print_file),			/* 0xC1 193 */
454*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
4555331Samw 	    { "SmbWritePrintFile", KSTAT_DATA_UINT64 } },
4566139Sjb150015 	{ SMB_SDT_OPS(close_print_file),			/* 0xC2 194 */
457*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
4585331Samw 	    { "SmbClosePrintFile", KSTAT_DATA_UINT64 } },
4596139Sjb150015 	{ SMB_SDT_OPS(get_print_queue),				/* 0xC3 195 */
460*9343SAfshin.Ardakani@Sun.COM 	    PC_NETWORK_PROGRAM_1_0, 0,
4615331Samw 	    { "SmbGetPrintQueue", KSTAT_DATA_UINT64 } },
462*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xC4 196 */
463*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xC5 197 */
464*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xC6 198 */
465*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xC7 199 */
466*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xC8 200 */
467*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xC9 201 */
468*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xCA 202 */
469*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xCB 203 */
470*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xCC 204 */
471*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xCD 205 */
472*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xCE 206 */
473*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xCF 207 */
474*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD0 208 */
475*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD1 209 */
476*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD2 210 */
477*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD3 211 */
478*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD4 212 */
479*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD5 213 */
480*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD6 214 */
481*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD7 215 */
482*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD8 216 */
483*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xD9 217 */
484*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xDA 218 */
485*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xDB 219 */
486*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xDC 220 */
487*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xDD 221 */
488*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xDE 222 */
489*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xDF 223 */
490*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE0 224 */
491*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE1 225 */
492*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE2 226 */
493*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE3 227 */
494*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE4 228 */
495*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE5 229 */
496*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE6 230 */
497*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE7 231 */
498*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE8 232 */
499*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xE9 233 */
500*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xEA 234 */
501*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xEB 235 */
502*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xEC 236 */
503*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xED 237 */
504*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xEE 238 */
505*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xEF 239 */
506*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF0 240 */
507*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF1 241 */
508*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF2 242 */
509*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF3 243 */
510*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF4 244 */
511*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF5 245 */
512*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF6 246 */
513*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF7 247 */
514*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF8 248 */
515*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xF9 249 */
516*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xFA 250 */
517*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xFB 251 */
518*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xFC 252 */
519*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 },			/* 0xFD 253 */
520*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), LANMAN1_0, 0,			/* 0xFE 254 */
5215331Samw 	    { "SmbInvalidCommand", KSTAT_DATA_UINT64 } },
522*9343SAfshin.Ardakani@Sun.COM 	{ SMB_SDT_OPS(invalid), 0, 0, 0 }			/* 0xFF 255 */
5235331Samw };
5245331Samw 
5255331Samw /*
5265331Samw  * smbsr_cleanup
5275331Samw  *
5285331Samw  * If any user/tree/file is used by given request then
5295331Samw  * the reference count for that resource has been incremented.
5305331Samw  * This function decrements the reference count and close
5315331Samw  * the resource if it's needed.
5325331Samw  */
5335331Samw 
5345331Samw void
5356139Sjb150015 smbsr_cleanup(smb_request_t *sr)
5365331Samw {
5375331Samw 	ASSERT((sr->sr_state != SMB_REQ_STATE_CLEANED_UP) &&
5385331Samw 	    (sr->sr_state != SMB_REQ_STATE_COMPLETED));
5395331Samw 
5405331Samw 	if (sr->r_xa) {
5415331Samw 		if (sr->r_xa->xa_flags & SMB_XA_FLAG_COMPLETE)
5425331Samw 			smb_xa_close(sr->r_xa);
5435331Samw 		smb_xa_rele(sr->session, sr->r_xa);
5445331Samw 		sr->r_xa = NULL;
5455331Samw 	}
5465331Samw 
5475331Samw 	/*
5485331Samw 	 * Mark this request so we know that we've already cleaned it up.
5495331Samw 	 * A request should only get cleaned up once so multiple calls to
5505331Samw 	 * smbsr_cleanup for the same request indicate a bug.
5515331Samw 	 */
5525331Samw 	mutex_enter(&sr->sr_mutex);
5535331Samw 	if (sr->sr_state != SMB_REQ_STATE_CANCELED)
5545331Samw 		sr->sr_state = SMB_REQ_STATE_CLEANED_UP;
5555331Samw 	mutex_exit(&sr->sr_mutex);
5565331Samw }
5578262SJose.Borrego@Sun.COM /*
5588262SJose.Borrego@Sun.COM  * smb_dispatch_request
5598262SJose.Borrego@Sun.COM  *
5608262SJose.Borrego@Sun.COM  * Returns:
5618262SJose.Borrego@Sun.COM  *
5628262SJose.Borrego@Sun.COM  *    B_TRUE	The caller must free the smb request passed in.
5638262SJose.Borrego@Sun.COM  *    B_FALSE	The caller must not access the smb request passed in. It has
5648262SJose.Borrego@Sun.COM  *		been kept in an internal queue and may have already been freed.
5658262SJose.Borrego@Sun.COM  */
5668262SJose.Borrego@Sun.COM boolean_t
5675331Samw smb_dispatch_request(struct smb_request *sr)
5685331Samw {
5696030Sjb150015 	smb_sdrc_t		sdrc;
5708934SJose.Borrego@Sun.COM 	smb_disp_entry_t	*sdd;
5716030Sjb150015 	boolean_t		disconnect = B_FALSE;
5728262SJose.Borrego@Sun.COM 	smb_session_t		*session;
5738934SJose.Borrego@Sun.COM 	uint32_t		capabilities;
5748934SJose.Borrego@Sun.COM 	uint32_t		byte_count;
5758262SJose.Borrego@Sun.COM 
5768262SJose.Borrego@Sun.COM 	session = sr->session;
5778934SJose.Borrego@Sun.COM 	capabilities = session->capabilities;
5785331Samw 
5795331Samw 	ASSERT(sr->tid_tree == 0);
5805331Samw 	ASSERT(sr->uid_user == 0);
5815331Samw 	ASSERT(sr->fid_ofile == 0);
5825331Samw 	sr->smb_fid = (uint16_t)-1;
5835331Samw 
5845331Samw 	/* temporary until we identify a user */
5855331Samw 	sr->user_cr = kcred;
5865331Samw 	sr->orig_request_hdr = sr->command.chain_offset;
5875331Samw 
5885331Samw 	/* If this connection is shutting down just kill request */
5897052Samw 	if (smb_mbc_decodef(&sr->command, SMB_HEADER_ED_FMT,
5905331Samw 	    &sr->smb_com,
5915331Samw 	    &sr->smb_rcls,
5925331Samw 	    &sr->smb_reh,
5935331Samw 	    &sr->smb_err,
5945331Samw 	    &sr->smb_flg,
5955331Samw 	    &sr->smb_flg2,
5965331Samw 	    &sr->smb_pid_high,
5975331Samw 	    sr->smb_sig,
5985331Samw 	    &sr->smb_tid,
5995331Samw 	    &sr->smb_pid,
6005331Samw 	    &sr->smb_uid,
6015331Samw 	    &sr->smb_mid) != 0) {
6026030Sjb150015 		disconnect = B_TRUE;
6036030Sjb150015 		goto drop_connection;
6045331Samw 	}
6055331Samw 
6065331Samw 	/*
6076030Sjb150015 	 * The reply "header" is filled in now even though it will,
6086030Sjb150015 	 * most likely, be rewritten under reply_ready below.  We
6096030Sjb150015 	 * could reserve the space but this is convenient in case
6106030Sjb150015 	 * the dialect dispatcher has to send a special reply (like
6116030Sjb150015 	 * TRANSACT).
6125331Samw 	 *
6135331Samw 	 * Ensure that the 32-bit error code flag is turned off.
6145331Samw 	 * Clients seem to set it in transact requests and they may
6155331Samw 	 * get confused if we return success or a 16-bit SMB code.
6165331Samw 	 */
6175331Samw 	sr->smb_rcls = 0;
6185331Samw 	sr->smb_reh = 0;
6195331Samw 	sr->smb_err = 0;
6205331Samw 	sr->smb_flg2 &= ~SMB_FLAGS2_NT_STATUS;
6215331Samw 
6227052Samw 	(void) smb_mbc_encodef(&sr->reply, SMB_HEADER_ED_FMT,
6235331Samw 	    sr->smb_com,
6245331Samw 	    sr->smb_rcls,
6255331Samw 	    sr->smb_reh,
6265331Samw 	    sr->smb_err,
6275331Samw 	    sr->smb_flg,
6285331Samw 	    sr->smb_flg2,
6295331Samw 	    sr->smb_pid_high,
6305331Samw 	    sr->smb_sig,
6315331Samw 	    sr->smb_tid,
6325331Samw 	    sr->smb_pid,
6335331Samw 	    sr->smb_uid,
6345331Samw 	    sr->smb_mid);
6355331Samw 	sr->first_smb_com = sr->smb_com;
6365331Samw 
6375331Samw 	/*
6385772Sas200622 	 * Verify SMB signature if signing is enabled, dialect is NT LM 0.12,
6395331Samw 	 * signing was negotiated and authentication has occurred.
6405331Samw 	 */
6418262SJose.Borrego@Sun.COM 	if (session->signing.flags & SMB_SIGNING_ENABLED) {
6425331Samw 		if (smb_sign_check_request(sr) != 0) {
6436030Sjb150015 			smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
6446030Sjb150015 			    ERRDOS, ERROR_ACCESS_DENIED);
6456030Sjb150015 			disconnect = B_TRUE;
6466030Sjb150015 			goto report_error;
6475331Samw 		}
6485331Samw 	}
6495331Samw 
6505331Samw andx_more:
6515331Samw 	sdd = &dispatch[sr->smb_com];
6526139Sjb150015 	ASSERT(sdd->sdt_function);
6535331Samw 
6547052Samw 	if (smb_mbc_decodef(&sr->command, "b", &sr->smb_wct) != 0) {
6556030Sjb150015 		disconnect = B_TRUE;
6566030Sjb150015 		goto report_error;
6575331Samw 	}
6585331Samw 
6595331Samw 	(void) MBC_SHADOW_CHAIN(&sr->smb_vwv, &sr->command,
6605331Samw 	    sr->command.chain_offset, sr->smb_wct * 2);
6615331Samw 
6627052Samw 	if (smb_mbc_decodef(&sr->command, "#.w", sr->smb_wct*2, &sr->smb_bcc)) {
6636030Sjb150015 		disconnect = B_TRUE;
6646030Sjb150015 		goto report_error;
6655331Samw 	}
6665331Samw 
6678934SJose.Borrego@Sun.COM 	/*
6688934SJose.Borrego@Sun.COM 	 * Ignore smb_bcc if CAP_LARGE_READX/CAP_LARGE_WRITEX
6698934SJose.Borrego@Sun.COM 	 * and this is SmbReadX/SmbWriteX since this enables
6708934SJose.Borrego@Sun.COM 	 * large reads/write and bcc is only 16-bits.
6718934SJose.Borrego@Sun.COM 	 */
6728934SJose.Borrego@Sun.COM 	if (((sr->smb_com == SMB_COM_READ_ANDX) &&
6738934SJose.Borrego@Sun.COM 	    (capabilities & CAP_LARGE_READX)) ||
6748934SJose.Borrego@Sun.COM 	    ((sr->smb_com == SMB_COM_WRITE_ANDX) &&
6758934SJose.Borrego@Sun.COM 	    (capabilities & CAP_LARGE_WRITEX))) {
6768934SJose.Borrego@Sun.COM 		byte_count = sr->command.max_bytes - sr->command.chain_offset;
6778934SJose.Borrego@Sun.COM 	} else {
6788934SJose.Borrego@Sun.COM 		byte_count = (uint32_t)sr->smb_bcc;
6798934SJose.Borrego@Sun.COM 	}
6808934SJose.Borrego@Sun.COM 
6815331Samw 	(void) MBC_SHADOW_CHAIN(&sr->smb_data, &sr->command,
6828934SJose.Borrego@Sun.COM 	    sr->command.chain_offset, byte_count);
6835331Samw 
6848934SJose.Borrego@Sun.COM 	sr->command.chain_offset += byte_count;
6855331Samw 	if (sr->command.chain_offset > sr->command.max_bytes) {
6866030Sjb150015 		disconnect = B_TRUE;
6876030Sjb150015 		goto report_error;
6885331Samw 	}
6895331Samw 
6905331Samw 	/* Store pointers for later */
6915331Samw 	sr->cur_reply_offset = sr->reply.chain_offset;
6925331Samw 
6935331Samw 	if (is_andx_com(sr->smb_com)) {
6945331Samw 		/* Peek ahead and don't disturb vwv */
6957052Samw 		if (smb_mbc_peek(&sr->smb_vwv, sr->smb_vwv.chain_offset, "b.w",
6965331Samw 		    &sr->andx_com, &sr->andx_off) < 0) {
6976030Sjb150015 			disconnect = B_TRUE;
6986030Sjb150015 			goto report_error;
6995331Samw 		}
7005331Samw 	} else {
7015331Samw 		sr->andx_com = (unsigned char)-1;
7025331Samw 	}
7035331Samw 
7045331Samw 	mutex_enter(&sr->sr_mutex);
7055331Samw 	switch (sr->sr_state) {
7065331Samw 	case SMB_REQ_STATE_SUBMITTED:
7075331Samw 	case SMB_REQ_STATE_CLEANED_UP:
7085331Samw 		sr->sr_state = SMB_REQ_STATE_ACTIVE;
7095331Samw 		break;
7105331Samw 	case SMB_REQ_STATE_CANCELED:
7115331Samw 		break;
7125331Samw 	default:
7135331Samw 		ASSERT(0);
7145331Samw 		break;
7155331Samw 	}
7165331Samw 	mutex_exit(&sr->sr_mutex);
7175331Samw 
7186030Sjb150015 	/*
7196030Sjb150015 	 * Setup UID and TID information (if required). Both functions
7206030Sjb150015 	 * will set the sr credentials. In domain mode, the user and
7216030Sjb150015 	 * tree credentials should be the same. In share mode, the
7226030Sjb150015 	 * tree credentials (defined in the share definition) should
7236030Sjb150015 	 * override the user credentials.
7246030Sjb150015 	 */
7256139Sjb150015 	if (!(sdd->sdt_flags & SDDF_SUPPRESS_UID) && (sr->uid_user == NULL)) {
7268262SJose.Borrego@Sun.COM 		sr->uid_user = smb_user_lookup_by_uid(session, sr->smb_uid);
7276030Sjb150015 		if (sr->uid_user == NULL) {
7286030Sjb150015 			smbsr_error(sr, 0, ERRSRV, ERRbaduid);
7296139Sjb150015 			smbsr_cleanup(sr);
7306030Sjb150015 			goto report_error;
7315331Samw 		}
7325331Samw 
7337961SNatalie.Li@Sun.COM 		sr->user_cr = smb_user_getcred(sr->uid_user);
7347961SNatalie.Li@Sun.COM 
7356139Sjb150015 		if (!(sdd->sdt_flags & SDDF_SUPPRESS_TID) &&
7366139Sjb150015 		    (sr->tid_tree == NULL)) {
7377348SJose.Borrego@Sun.COM 			sr->tid_tree = smb_user_lookup_tree(
7386030Sjb150015 			    sr->uid_user, sr->smb_tid);
7396030Sjb150015 			if (sr->tid_tree == NULL) {
7406030Sjb150015 				smbsr_error(sr, 0, ERRSRV, ERRinvnid);
7416139Sjb150015 				smbsr_cleanup(sr);
7426030Sjb150015 				goto report_error;
7435331Samw 			}
7445331Samw 		}
7455331Samw 	}
7465331Samw 
7476030Sjb150015 	/*
7486030Sjb150015 	 * If the command is not a read raw request we can set the
7496030Sjb150015 	 * state of the session back to SMB_SESSION_STATE_NEGOTIATED
7506030Sjb150015 	 * (if the current state is SMB_SESSION_STATE_OPLOCK_BREAKING).
7516030Sjb150015 	 * Otherwise we let the read raw handler to deal with it.
7526030Sjb150015 	 */
753*9343SAfshin.Ardakani@Sun.COM 	smb_rwx_rwenter(&session->s_lock, RW_READER);
7548262SJose.Borrego@Sun.COM 	if ((session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING) &&
7556030Sjb150015 	    (sr->smb_com != SMB_COM_READ_RAW)) {
756*9343SAfshin.Ardakani@Sun.COM 		(void) smb_rwx_rwupgrade(&session->s_lock);
7578262SJose.Borrego@Sun.COM 		if (session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING)
7588262SJose.Borrego@Sun.COM 			session->s_state = SMB_SESSION_STATE_NEGOTIATED;
7596030Sjb150015 	}
760*9343SAfshin.Ardakani@Sun.COM 	smb_rwx_rwexit(&session->s_lock);
7616030Sjb150015 
7626030Sjb150015 	/*
7636030Sjb150015 	 * Increment method invocation count. This value is exposed
7646030Sjb150015 	 * via kstats, and it represents a count of all the dispatched
7656030Sjb150015 	 * requests, including the ones that have a return value, other
7666139Sjb150015 	 * than SDRC_SUCCESS.
7676030Sjb150015 	 */
7686030Sjb150015 	SMB_ALL_DISPATCH_STAT_INCR(sdd->sdt_dispatch_stats.value.ui64);
7696030Sjb150015 
7706139Sjb150015 	if ((sdrc = (*sdd->sdt_pre_op)(sr)) == SDRC_SUCCESS)
7716139Sjb150015 		sdrc = (*sdd->sdt_function)(sr);
7726139Sjb150015 
773*9343SAfshin.Ardakani@Sun.COM 	if (sdrc != SDRC_SR_KEPT) {
774*9343SAfshin.Ardakani@Sun.COM 		(*sdd->sdt_post_op)(sr);
775*9343SAfshin.Ardakani@Sun.COM 		smbsr_cleanup(sr);
776*9343SAfshin.Ardakani@Sun.COM 	}
777*9343SAfshin.Ardakani@Sun.COM 
7786139Sjb150015 	if (sdrc != SDRC_SUCCESS) {
7796030Sjb150015 		/*
7806030Sjb150015 		 * Handle errors from raw write.
7816030Sjb150015 		 */
782*9343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwenter(&session->s_lock, RW_WRITER);
7838262SJose.Borrego@Sun.COM 		if (session->s_state == SMB_SESSION_STATE_WRITE_RAW_ACTIVE) {
7846030Sjb150015 			/*
7856030Sjb150015 			 * Set state so that the netbios session
7866030Sjb150015 			 * daemon will start accepting data again.
7876030Sjb150015 			 */
7888262SJose.Borrego@Sun.COM 			session->s_write_raw_status = 0;
7898262SJose.Borrego@Sun.COM 			session->s_state = SMB_SESSION_STATE_NEGOTIATED;
7906030Sjb150015 		}
791*9343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwexit(&session->s_lock);
7928262SJose.Borrego@Sun.COM 	}
7936030Sjb150015 
7946030Sjb150015 	switch (sdrc) {
7956139Sjb150015 	case SDRC_SUCCESS:
7966030Sjb150015 		break;
7976030Sjb150015 
7986030Sjb150015 	case SDRC_DROP_VC:
7996030Sjb150015 		disconnect = B_TRUE;
8006030Sjb150015 		goto drop_connection;
8016030Sjb150015 
8026030Sjb150015 	case SDRC_NO_REPLY:
8038262SJose.Borrego@Sun.COM 		return (B_TRUE);
8048262SJose.Borrego@Sun.COM 
8058262SJose.Borrego@Sun.COM 	case SDRC_SR_KEPT:
8068262SJose.Borrego@Sun.COM 		return (B_FALSE);
8076030Sjb150015 
8086139Sjb150015 	case SDRC_ERROR:
8096030Sjb150015 		goto report_error;
8106030Sjb150015 
8116139Sjb150015 	case SDRC_NOT_IMPLEMENTED:
8126030Sjb150015 	default:
8136030Sjb150015 		smbsr_error(sr, 0, ERRDOS, ERRbadfunc);
8146030Sjb150015 		goto report_error;
8156030Sjb150015 	}
8166030Sjb150015 
8176030Sjb150015 	/*
8186030Sjb150015 	 * If there's no AndX command, we're done.
8196030Sjb150015 	 */
8205331Samw 	if (sr->andx_com == 0xff)
8215331Samw 		goto reply_ready;
8225331Samw 
8236030Sjb150015 	/*
8246030Sjb150015 	 * Otherwise, we have to back-patch the AndXCommand and AndXOffset
8256030Sjb150015 	 * and continue processing.
8266030Sjb150015 	 */
8275331Samw 	sr->andx_prev_wct = sr->cur_reply_offset;
8287052Samw 	(void) smb_mbc_poke(&sr->reply, sr->andx_prev_wct + 1, "b.w",
8295331Samw 	    sr->andx_com, MBC_LENGTH(&sr->reply));
8305331Samw 
8315331Samw 	sr->command.chain_offset = sr->orig_request_hdr + sr->andx_off;
8325331Samw 	sr->smb_com = sr->andx_com;
8335331Samw 	goto andx_more;
8345331Samw 
8356030Sjb150015 report_error:
8365331Samw 	sr->reply.chain_offset = sr->cur_reply_offset;
8377052Samw 	(void) smb_mbc_encodef(&sr->reply, "bw", 0, 0);
8385331Samw 
8395331Samw 	sr->smb_wct = 0;
8405331Samw 	sr->smb_bcc = 0;
8415331Samw 
8426139Sjb150015 	if (sr->smb_rcls == 0 && sr->smb_reh == 0 && sr->smb_err == 0)
8436030Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
8446030Sjb150015 
8456030Sjb150015 reply_ready:
8466030Sjb150015 	smbsr_send_reply(sr);
8476030Sjb150015 
8486030Sjb150015 drop_connection:
8496030Sjb150015 	if (disconnect) {
850*9343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwenter(&session->s_lock, RW_WRITER);
8518262SJose.Borrego@Sun.COM 		switch (session->s_state) {
8526030Sjb150015 		case SMB_SESSION_STATE_DISCONNECTED:
8536030Sjb150015 		case SMB_SESSION_STATE_TERMINATED:
8546030Sjb150015 			break;
8556030Sjb150015 		default:
8568262SJose.Borrego@Sun.COM 			smb_soshutdown(session->sock);
8578262SJose.Borrego@Sun.COM 			session->s_state = SMB_SESSION_STATE_DISCONNECTED;
8586030Sjb150015 			break;
8596030Sjb150015 		}
860*9343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwexit(&session->s_lock);
8615331Samw 	}
8626030Sjb150015 
8638262SJose.Borrego@Sun.COM 	return (B_TRUE);
8645331Samw }
8655331Samw 
8666030Sjb150015 int
8676030Sjb150015 smbsr_encode_empty_result(struct smb_request *sr)
8686030Sjb150015 {
8696030Sjb150015 	return (smbsr_encode_result(sr, 0, 0, "bw", 0, 0));
8706030Sjb150015 }
8715331Samw 
8726030Sjb150015 int
8736030Sjb150015 smbsr_encode_result(struct smb_request *sr, int wct, int bcc, char *fmt, ...)
8745331Samw {
8755331Samw 	va_list ap;
8765331Samw 
8776030Sjb150015 	if (MBC_LENGTH(&sr->reply) != sr->cur_reply_offset)
8786030Sjb150015 		return (-1);
8795331Samw 
8805331Samw 	va_start(ap, fmt);
8817052Samw 	(void) smb_mbc_vencodef(&sr->reply, fmt, ap);
8825331Samw 	va_end(ap);
8835331Samw 
8845331Samw 	sr->smb_wct = (unsigned char)wct;
8855331Samw 	sr->smb_bcc = (uint16_t)bcc;
8865331Samw 
8876030Sjb150015 	if (smbsr_check_result(sr, wct, bcc) != 0)
8886030Sjb150015 		return (-1);
8896030Sjb150015 
8906030Sjb150015 	return (0);
8915331Samw }
8925331Samw 
8936030Sjb150015 static int
8945331Samw smbsr_check_result(struct smb_request *sr, int wct, int bcc)
8955331Samw {
8965331Samw 	int		offset = sr->cur_reply_offset;
8975331Samw 	int		total_bytes;
8985331Samw 	unsigned char	temp, temp1;
8995331Samw 	struct mbuf	*m;
9005331Samw 
9015331Samw 	total_bytes = 0;
9025331Samw 	m = sr->reply.chain;
9035331Samw 	while (m != 0) {
9045331Samw 		total_bytes += m->m_len;
9055331Samw 		m = m->m_next;
9065331Samw 	}
9075331Samw 
9086030Sjb150015 	if ((offset + 3) > total_bytes)
9096030Sjb150015 		return (-1);
9105331Samw 
9117052Samw 	(void) smb_mbc_peek(&sr->reply, offset, "b", &temp);
9126030Sjb150015 	if (temp != wct)
9136030Sjb150015 		return (-1);
9145331Samw 
9156030Sjb150015 	if ((offset + (wct * 2 + 1)) > total_bytes)
9166030Sjb150015 		return (-1);
9175331Samw 
9185331Samw 	/* reply wct & vwv seem ok, consider data now */
9195331Samw 	offset += wct * 2 + 1;
9205331Samw 
9216030Sjb150015 	if ((offset + 2) > total_bytes)
9226030Sjb150015 		return (-1);
9235331Samw 
9247052Samw 	(void) smb_mbc_peek(&sr->reply, offset, "bb", &temp, &temp1);
9255331Samw 	if (bcc == VAR_BCC) {
9265331Samw 		if ((temp != 0xFF) || (temp1 != 0xFF)) {
9276030Sjb150015 			return (-1);
9285331Samw 		} else {
9295331Samw 			bcc = (total_bytes - offset) - 2;
9307052Samw 			(void) smb_mbc_poke(&sr->reply, offset, "bb",
9315331Samw 			    bcc, bcc >> 8);
9325331Samw 		}
9335331Samw 	} else {
9346030Sjb150015 		if ((temp != (bcc&0xFF)) || (temp1 != ((bcc>>8)&0xFF)))
9356030Sjb150015 			return (-1);
9365331Samw 	}
9375331Samw 
9385331Samw 	offset += bcc + 2;
9395331Samw 
9406030Sjb150015 	if (offset != total_bytes)
9416030Sjb150015 		return (-1);
9425331Samw 
9435331Samw 	sr->smb_wct = (unsigned char)wct;
9445331Samw 	sr->smb_bcc = (uint16_t)bcc;
9456030Sjb150015 	return (0);
9465331Samw }
9475331Samw 
9485331Samw int
9495331Samw smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...)
9505331Samw {
9515331Samw 	int rc;
9525331Samw 	va_list ap;
9535331Samw 
9545331Samw 	va_start(ap, fmt);
9557052Samw 	rc = smb_mbc_vdecodef(&sr->smb_vwv, fmt, ap);
9565331Samw 	va_end(ap);
9575331Samw 
9586139Sjb150015 	if (rc)
9596139Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
9605331Samw 	return (rc);
9615331Samw }
9625331Samw 
9635331Samw int
9645331Samw smbsr_decode_data(struct smb_request *sr, char *fmt, ...)
9655331Samw {
9666139Sjb150015 	int rc;
9675331Samw 	va_list ap;
9686139Sjb150015 
9695331Samw 	va_start(ap, fmt);
9707052Samw 	rc = smb_mbc_vdecodef(&sr->smb_data, fmt, ap);
9715331Samw 	va_end(ap);
9726139Sjb150015 
9736139Sjb150015 	if (rc)
9746139Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
9756139Sjb150015 	return (rc);
9765331Samw }
9775331Samw 
9785331Samw void
9795331Samw smbsr_send_reply(struct smb_request *sr)
9805331Samw {
9817348SJose.Borrego@Sun.COM 	if (SMB_TREE_IS_CASEINSENSITIVE(sr))
9826030Sjb150015 		sr->smb_flg |= SMB_FLAGS_CASE_INSENSITIVE;
9836030Sjb150015 	else
9846030Sjb150015 		sr->smb_flg &= ~SMB_FLAGS_CASE_INSENSITIVE;
9856030Sjb150015 
9867052Samw 	(void) smb_mbc_poke(&sr->reply, 0, SMB_HEADER_ED_FMT,
9875331Samw 	    sr->first_smb_com,
9885331Samw 	    sr->smb_rcls,
9895331Samw 	    sr->smb_reh,
9905331Samw 	    sr->smb_err,
9915331Samw 	    sr->smb_flg | SMB_FLAGS_REPLY,
9925331Samw 	    sr->smb_flg2,
9935331Samw 	    sr->smb_pid_high,
9945331Samw 	    sr->smb_sig,
9955331Samw 	    sr->smb_tid,
9965331Samw 	    sr->smb_pid,
9975331Samw 	    sr->smb_uid,
9985331Samw 	    sr->smb_mid);
9995331Samw 
10005331Samw 	if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
10015331Samw 		smb_sign_reply(sr, NULL);
10025331Samw 
10036030Sjb150015 	if (smb_session_send(sr->session, 0, &sr->reply) == 0)
10046030Sjb150015 		sr->reply.chain = 0;
10055331Samw }
10065331Samw 
10075331Samw /*
10085772Sas200622  * Map errno values to SMB and NT status values.
10095772Sas200622  * Note: ESRCH is a special case to handle a streams lookup failure.
10105331Samw  */
10115331Samw static struct {
10125772Sas200622 	int errnum;
10135772Sas200622 	int errcls;
10145772Sas200622 	int errcode;
10155772Sas200622 	DWORD status32;
10165772Sas200622 } smb_errno_map[] = {
10175331Samw 	{ ENOSPC,	ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL },
10185331Samw 	{ EDQUOT,	ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL },
10195331Samw 	{ EPERM,	ERRSRV, ERRaccess, NT_STATUS_ACCESS_DENIED },
10205331Samw 	{ ENOTDIR,	ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND },
10215331Samw 	{ EISDIR,	ERRDOS, ERRbadpath, NT_STATUS_FILE_IS_A_DIRECTORY },
10225331Samw 	{ ENOENT,	ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE },
10235331Samw 	{ ENOTEMPTY,	ERRDOS, ERROR_DIR_NOT_EMPTY,
10245331Samw 	    NT_STATUS_DIRECTORY_NOT_EMPTY },
10259231SAfshin.Ardakani@Sun.COM 	{ EILSEQ,	ERRDOS, ERROR_INVALID_NAME,
10269231SAfshin.Ardakani@Sun.COM 	    NT_STATUS_OBJECT_NAME_INVALID },
10275331Samw 	{ EACCES,	ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
10285331Samw 	{ ENOMEM,	ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY },
10295331Samw 	{ EIO,		ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR },
10305331Samw 	{ EXDEV, 	ERRSRV, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE },
10315331Samw 	{ EROFS,	ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED },
10329231SAfshin.Ardakani@Sun.COM 	{ ESTALE,	ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE },
10339231SAfshin.Ardakani@Sun.COM 	{ EBADF,	ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE },
10349231SAfshin.Ardakani@Sun.COM 	{ EEXIST,	ERRDOS, ERRfilexists, NT_STATUS_OBJECT_NAME_COLLISION },
10359231SAfshin.Ardakani@Sun.COM 	{ ENXIO,	ERRSRV, ERRinvdevice, NT_STATUS_BAD_DEVICE_TYPE },
10365331Samw 	{ ESRCH,	ERRDOS, ERROR_FILE_NOT_FOUND,
10375331Samw 	    NT_STATUS_OBJECT_NAME_NOT_FOUND },
10385331Samw 	/*
10395331Samw 	 * It's not clear why smb_read_common effectively returns
10405331Samw 	 * ERRnoaccess if a range lock prevents access and smb_write_common
10415331Samw 	 * effectively returns ERRaccess.  This table entry is used by
10425331Samw 	 * smb_read_common and preserves the behavior that was there before.
10435331Samw 	 */
10445331Samw 	{ ERANGE,	ERRDOS, ERRnoaccess, NT_STATUS_FILE_LOCK_CONFLICT }
10455331Samw };
10465331Samw 
10475331Samw void
10485772Sas200622 smbsr_map_errno(int errnum, smb_error_t *err)
10495331Samw {
10505331Samw 	int i;
10515331Samw 
10525772Sas200622 	for (i = 0; i < sizeof (smb_errno_map)/sizeof (smb_errno_map[0]); ++i) {
10535772Sas200622 		if (smb_errno_map[i].errnum == errnum) {
10545772Sas200622 			err->severity = ERROR_SEVERITY_ERROR;
10555772Sas200622 			err->status   = smb_errno_map[i].status32;
10565772Sas200622 			err->errcls   = smb_errno_map[i].errcls;
10575772Sas200622 			err->errcode  = smb_errno_map[i].errcode;
10585772Sas200622 			return;
10595331Samw 		}
10605331Samw 	}
10615331Samw 
10625772Sas200622 	err->severity = ERROR_SEVERITY_ERROR;
10635772Sas200622 	err->status   = NT_STATUS_INTERNAL_ERROR;
10645772Sas200622 	err->errcls   = ERRDOS;
10655772Sas200622 	err->errcode  = ERROR_INTERNAL_ERROR;
10665331Samw }
10675331Samw 
10685331Samw void
10695772Sas200622 smbsr_errno(struct smb_request *sr, int errnum)
10705772Sas200622 {
10716030Sjb150015 	smbsr_map_errno(errnum, &sr->smb_error);
10726030Sjb150015 	smbsr_set_error(sr, &sr->smb_error);
10735772Sas200622 }
10745772Sas200622 
10755772Sas200622 /*
10765772Sas200622  * Report a request processing warning.
10775772Sas200622  */
10785772Sas200622 void
10795772Sas200622 smbsr_warn(smb_request_t *sr, DWORD status, uint16_t errcls, uint16_t errcode)
10805772Sas200622 {
10816030Sjb150015 	sr->smb_error.severity = ERROR_SEVERITY_WARNING;
10826030Sjb150015 	sr->smb_error.status   = status;
10836030Sjb150015 	sr->smb_error.errcls   = errcls;
10846030Sjb150015 	sr->smb_error.errcode  = errcode;
10855772Sas200622 
10866030Sjb150015 	smbsr_set_error(sr, &sr->smb_error);
10875772Sas200622 }
10885772Sas200622 
10895772Sas200622 /*
10905772Sas200622  * Report a request processing error.  This function will not return.
10915772Sas200622  */
10925772Sas200622 void
10935772Sas200622 smbsr_error(smb_request_t *sr, DWORD status, uint16_t errcls, uint16_t errcode)
10945331Samw {
10956030Sjb150015 	sr->smb_error.severity = ERROR_SEVERITY_ERROR;
10966030Sjb150015 	sr->smb_error.status   = status;
10976030Sjb150015 	sr->smb_error.errcls   = errcls;
10986030Sjb150015 	sr->smb_error.errcode  = errcode;
10995772Sas200622 
11006030Sjb150015 	smbsr_set_error(sr, &sr->smb_error);
11015772Sas200622 }
11025772Sas200622 
11035772Sas200622 /*
11045772Sas200622  * Setup a request processing error.  This function can be used to
11055772Sas200622  * report 32-bit status codes or DOS errors.  Set the status code
11065772Sas200622  * to 0 (NT_STATUS_SUCCESS) to explicitly report a DOS error,
11075772Sas200622  * regardless of the client capabilities.
11085772Sas200622  *
11095772Sas200622  * If status is non-zero and the client supports 32-bit status
11105772Sas200622  * codes, report the status.  Otherwise, report the DOS error.
11115772Sas200622  */
11125772Sas200622 void
11135772Sas200622 smbsr_set_error(smb_request_t *sr, smb_error_t *err)
11145772Sas200622 {
11155772Sas200622 	uint32_t status;
11165772Sas200622 	uint32_t severity;
11175772Sas200622 	uint32_t capabilities;
11185772Sas200622 
11195772Sas200622 	ASSERT(sr);
11205772Sas200622 	ASSERT(err);
11215772Sas200622 
11225772Sas200622 	status = err->status;
11235772Sas200622 	severity = (err->severity == 0) ? ERROR_SEVERITY_ERROR : err->severity;
11245772Sas200622 	capabilities = sr->session->capabilities;
11255772Sas200622 
11265772Sas200622 	if ((err->errcls == 0) && (err->errcode == 0)) {
11275772Sas200622 		capabilities |= CAP_STATUS32;
11285772Sas200622 		if (status == 0)
11295772Sas200622 			status = NT_STATUS_INTERNAL_ERROR;
11305772Sas200622 	}
11315772Sas200622 
11325772Sas200622 	if ((capabilities & CAP_STATUS32) && (status != 0)) {
11335772Sas200622 		status |= severity;
11345772Sas200622 		sr->smb_rcls = status & 0xff;
11355772Sas200622 		sr->smb_reh = (status >> 8) & 0xff;
11365772Sas200622 		sr->smb_err  = status >> 16;
11375772Sas200622 		sr->smb_flg2 |= SMB_FLAGS2_NT_STATUS;
11385772Sas200622 	} else {
11395772Sas200622 		if ((err->errcls == 0) || (err->errcode == 0)) {
11405772Sas200622 			sr->smb_rcls = ERRSRV;
11415772Sas200622 			sr->smb_err  = ERRerror;
11425772Sas200622 		} else {
11435772Sas200622 			sr->smb_rcls = (uint8_t)err->errcls;
11445772Sas200622 			sr->smb_err  = (uint16_t)err->errcode;
11455331Samw 		}
11465331Samw 	}
11475331Samw }
11485331Samw 
11495331Samw smb_xa_t *
11505331Samw smbsr_lookup_xa(smb_request_t *sr)
11515331Samw {
11525331Samw 	ASSERT(sr->r_xa == 0);
11535331Samw 
11545331Samw 	sr->r_xa = smb_xa_find(sr->session, sr->smb_pid, sr->smb_mid);
11555331Samw 	return (sr->r_xa);
11565331Samw }
11575331Samw 
11585331Samw void
11595331Samw smbsr_disconnect_file(smb_request_t *sr)
11605331Samw {
11615331Samw 	smb_ofile_t	*of = sr->fid_ofile;
11625331Samw 
11635331Samw 	sr->fid_ofile = NULL;
11645331Samw 	(void) smb_ofile_release(of);
11655331Samw }
11665331Samw 
11678934SJose.Borrego@Sun.COM void
11688934SJose.Borrego@Sun.COM smbsr_lookup_file(smb_request_t *sr)
11698934SJose.Borrego@Sun.COM {
11708934SJose.Borrego@Sun.COM 	if (sr->fid_ofile == NULL)
11718934SJose.Borrego@Sun.COM 		sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree,
11728934SJose.Borrego@Sun.COM 		    sr->smb_fid);
11738934SJose.Borrego@Sun.COM }
11748934SJose.Borrego@Sun.COM 
11755331Samw static int
11765331Samw is_andx_com(unsigned char com)
11775331Samw {
11785331Samw 	switch (com) {
11795331Samw 	case SMB_COM_LOCKING_ANDX:
11805331Samw 	case SMB_COM_OPEN_ANDX:
11815331Samw 	case SMB_COM_READ_ANDX:
11825331Samw 	case SMB_COM_WRITE_ANDX:
11835331Samw 	case SMB_COM_SESSION_SETUP_ANDX:
11845331Samw 	case SMB_COM_LOGOFF_ANDX:
11855331Samw 	case SMB_COM_TREE_CONNECT_ANDX:
11865331Samw 	case SMB_COM_NT_CREATE_ANDX:
11875331Samw 		return (1);
11885331Samw 	}
11895331Samw 	return (0);
11905331Samw }
11915331Samw 
11925331Samw /*
11936139Sjb150015  * Invalid command stubs.
11946139Sjb150015  *
11956139Sjb150015  * SmbWriteComplete is sent to acknowledge completion of raw write requests.
11966139Sjb150015  * We never send raw write commands to other servers so, if we receive
11976139Sjb150015  * SmbWriteComplete, we treat it as an error.
11986139Sjb150015  *
11996139Sjb150015  * The Read/Write Block Multiplexed (mpx) protocol is used to maximize
12006139Sjb150015  * performance when reading/writing a large block of data: it can be
12016139Sjb150015  * used in parallel with other client/server operations.  The mpx sub-
12026139Sjb150015  * protocol is not supported because we support only connection oriented
12036139Sjb150015  * transports and NT supports mpx only over connectionless transports.
12045331Samw  */
12056030Sjb150015 smb_sdrc_t
12066139Sjb150015 smb_pre_invalid(smb_request_t *sr)
12076139Sjb150015 {
12086139Sjb150015 	DTRACE_SMB_1(op__Invalid__start, smb_request_t *, sr);
12096139Sjb150015 	return (SDRC_SUCCESS);
12106139Sjb150015 }
12116139Sjb150015 
12126139Sjb150015 void
12136139Sjb150015 smb_post_invalid(smb_request_t *sr)
12146139Sjb150015 {
12156139Sjb150015 	DTRACE_SMB_1(op__Invalid__done, smb_request_t *, sr);
12166139Sjb150015 }
12176139Sjb150015 
12186139Sjb150015 smb_sdrc_t
12196139Sjb150015 smb_com_invalid(smb_request_t *sr)
12205331Samw {
12216139Sjb150015 	smb_sdrc_t sdrc;
12226139Sjb150015 
12236139Sjb150015 	switch (sr->smb_com) {
12246139Sjb150015 	case SMB_COM_WRITE_COMPLETE:
12256139Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
12266139Sjb150015 		sdrc = SDRC_ERROR;
12276139Sjb150015 		break;
12286139Sjb150015 
12296139Sjb150015 	default:
12306139Sjb150015 		smbsr_error(sr, NT_STATUS_NOT_IMPLEMENTED,
12316139Sjb150015 		    ERRDOS, ERROR_INVALID_FUNCTION);
12326139Sjb150015 		sdrc = SDRC_NOT_IMPLEMENTED;
12336139Sjb150015 		break;
12346139Sjb150015 	}
12356139Sjb150015 
12366139Sjb150015 	return (sdrc);
12375331Samw }
12385331Samw 
12395331Samw /*
12406139Sjb150015  * smb_dispatch_kstat_update
12415331Samw  *
12425331Samw  * This callback function updates the smb_dispatch_kstat_data when kstat
12435331Samw  * command is invoked.
12445331Samw  */
12455331Samw static int
12466139Sjb150015 smb_dispatch_kstat_update(kstat_t *ksp, int rw)
12475331Samw {
12488934SJose.Borrego@Sun.COM 	smb_disp_entry_t	*sdd;
12498934SJose.Borrego@Sun.COM 	kstat_named_t		*ks_named;
12506139Sjb150015 	int i;
12515331Samw 
12526139Sjb150015 	if (rw == KSTAT_WRITE)
12535331Samw 		return (EACCES);
12546139Sjb150015 
12556139Sjb150015 	ASSERT(MUTEX_HELD(ksp->ks_lock));
12566139Sjb150015 
12576139Sjb150015 	ks_named = ksp->ks_data;
12586139Sjb150015 	for (i = 0; i < SMB_COM_NUM; i++) {
12596139Sjb150015 		sdd = &dispatch[i];
12606139Sjb150015 
12616139Sjb150015 		if (sdd->sdt_function != smb_com_invalid) {
12626139Sjb150015 			bcopy(&sdd->sdt_dispatch_stats, ks_named,
12636139Sjb150015 			    sizeof (kstat_named_t));
12646139Sjb150015 			++ks_named;
12655331Samw 		}
12665331Samw 	}
12676139Sjb150015 
12685331Samw 	return (0);
12695331Samw }
12705331Samw 
12715331Samw /*
12726139Sjb150015  * smb_dispatch_kstat_init
12735331Samw  *
12745331Samw  * Initialize dispatch kstats.
12755331Samw  */
12765331Samw void
12776139Sjb150015 smb_dispatch_kstat_init(void)
12785331Samw {
12796139Sjb150015 	int ks_ndata;
12806139Sjb150015 	int i;
12815331Samw 
12826139Sjb150015 	for (i = 0, ks_ndata = 0; i < SMB_COM_NUM; i++) {
12836139Sjb150015 		if (dispatch[i].sdt_function != smb_com_invalid)
12846139Sjb150015 			ks_ndata++;
12855331Samw 	}
12865331Samw 
12876432Sas200622 	smb_dispatch_ksp = kstat_create(SMBSRV_KSTAT_MODULE, 0,
12886432Sas200622 	    SMBSRV_KSTAT_NAME_CMDS, SMBSRV_KSTAT_CLASS,
12896139Sjb150015 	    KSTAT_TYPE_NAMED, ks_ndata, 0);
12905331Samw 
12915331Samw 	if (smb_dispatch_ksp) {
12926139Sjb150015 		mutex_init(&smb_dispatch_ksmtx, NULL, MUTEX_DEFAULT, NULL);
12936139Sjb150015 		smb_dispatch_ksp->ks_update = smb_dispatch_kstat_update;
12946139Sjb150015 		smb_dispatch_ksp->ks_lock = &smb_dispatch_ksmtx;
12955331Samw 		kstat_install(smb_dispatch_ksp);
12965331Samw 	}
12975331Samw }
12985331Samw 
12995331Samw /*
13006139Sjb150015  * smb_dispatch_kstat_fini
13015331Samw  *
13025331Samw  * Remove dispatch kstats.
13035331Samw  */
13045331Samw void
13056139Sjb150015 smb_dispatch_kstat_fini(void)
13065331Samw {
13075331Samw 	if (smb_dispatch_ksp != NULL) {
13085331Samw 		kstat_delete(smb_dispatch_ksp);
13096139Sjb150015 		mutex_destroy(&smb_dispatch_ksmtx);
13105331Samw 		smb_dispatch_ksp = NULL;
13115331Samw 	}
13125331Samw }
1313