4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
27 * Structures and type definitions for the SMB module.
30 #ifndef _SMBSRV_SMB_KTYPES_H
31 #define _SMBSRV_SMB_KTYPES_H
38 #include <sys/systm.h>
39 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/synch.h>
42 #include <sys/taskq.h>
43 #include <sys/socket.h>
47 #include <sys/vnode.h>
49 #include <netinet/in.h>
50 #include <sys/ksocket.h>
53 #include <sys/extdirent.h>
54 #include <smbsrv/smb.h>
55 #include <smbsrv/smbinfo.h>
56 #include <smbsrv/mbuf.h>
57 #include <smbsrv/smb_sid.h>
58 #include <smbsrv/smb_xdr.h>
59 #include <smbsrv/netbios.h>
60 #include <smbsrv/smb_vops.h>
61 #include <smbsrv/smb_kstat.h>
63 struct smb_disp_entry
;
69 * Accumulated time and queue length statistics.
71 * Accumulated time statistics are kept as a running sum of "active" time.
72 * Queue length statistics are kept as a running sum of the product of queue
73 * length and elapsed time at that length -- i.e., a Riemann sum for queue
74 * length integrated against time. (You can also think of the active time as a
75 * Riemann sum, for the boolean function (queue_length > 0) integrated against
76 * time, or you can think of it as the Lebesgue measure of the set on which
84 * Length | _________ | |
89 * |_______________________________|
92 * At each change of state (entry or exit from the queue), we add the elapsed
93 * time (since the previous state change) to the active time if the queue length
94 * was non-zero during that interval; and we add the product of the elapsed time
95 * times the queue length to the running length*time sum.
97 * This method is generalizable to measuring residency in any defined system:
98 * instead of queue lengths, think of "outstanding RPC calls to server X".
100 * A large number of I/O subsystems have at least two basic "lists" of
101 * transactions they manage: one for transactions that have been accepted for
102 * processing but for which processing has yet to begin, and one for
103 * transactions which are actively being processed (but not done). For this
104 * reason, two cumulative time statistics are defined here: wait (pre-service)
105 * time, and run (service) time.
107 * All times are 64-bit nanoseconds (hrtime_t), as returned by gethrtime().
109 * The units of cumulative busy time are accumulated nanoseconds. The units of
110 * cumulative length*time products are elapsed time times queue length.
112 * Updates to the fields below are performed implicitly by calls to
116 * smb_srqueue_destroy()
117 * smb_srqueue_waitq_enter()
118 * smb_srqueue_runq_exit()
119 * smb_srqueue_waitq_to_runq()
120 * smb_srqueue_update()
122 * These fields should never be updated by any other means.
124 typedef struct smb_srqueue
{
126 hrtime_t srq_wlastupdate
;
128 hrtime_t srq_wlentime
;
129 hrtime_t srq_rlastupdate
;
131 hrtime_t srq_rlentime
;
137 * The fields with the prefix 'ly_a' contain the statistics collected since the
138 * server was last started ('a' for 'aggregated'). The fields with the prefix
139 * 'ly_d' contain the statistics collected since the last snapshot ('d' for
142 typedef struct smb_latency
{
147 hrtime_t ly_a_stddev
;
151 hrtime_t ly_d_stddev
;
154 int smb_noop(void *, size_t, int);
156 #define SMB_AUDIT_STACK_DEPTH 16
157 #define SMB_AUDIT_BUF_MAX_REC 16
158 #define SMB_AUDIT_NODE 0x00000001
161 * Maximum number of records returned in SMBsearch, SMBfind
162 * and SMBfindunique response. Value set to 10 for compatibility
165 #define SMB_MAX_SEARCH 10
167 #define SMB_SEARCH_ATTRIBUTES \
168 (FILE_ATTRIBUTE_HIDDEN | \
169 FILE_ATTRIBUTE_SYSTEM | \
170 FILE_ATTRIBUTE_DIRECTORY)
172 #define SMB_SEARCH_HIDDEN(sattr) ((sattr) & FILE_ATTRIBUTE_HIDDEN)
173 #define SMB_SEARCH_SYSTEM(sattr) ((sattr) & FILE_ATTRIBUTE_SYSTEM)
174 #define SMB_SEARCH_DIRECTORY(sattr) ((sattr) & FILE_ATTRIBUTE_DIRECTORY)
175 #define SMB_SEARCH_ALL(sattr) ((sattr) & SMB_SEARCH_ATTRIBUTES)
180 pc_t anr_stack
[SMB_AUDIT_STACK_DEPTH
];
181 } smb_audit_record_node_t
;
186 smb_audit_record_node_t anb_records
[SMB_AUDIT_BUF_MAX_REC
];
187 } smb_audit_buf_node_t
;
189 #define SMB_WORKER_PRIORITY 99
191 * Thread State Machine
192 * --------------------
195 * smb_thread_destroy() <-------+ +------- smb_thread_init()
198 * +-----------------------------+
199 * | SMB_THREAD_STATE_EXITED |<---+
200 * +-----------------------------+ |
203 * +-----------------------------+ |
204 * | SMB_THREAD_STATE_STARTING | |
205 * +-----------------------------+ |
208 * +-----------------------------+ |
209 * | SMB_THREAD_STATE_RUNNING | |
210 * +-----------------------------+ |
213 * +-----------------------------+ |
214 * | SMB_THREAD_STATE_EXITING |----+
215 * +-----------------------------+
219 * This transition is executed in smb_thread_init().
223 * This transition is executed in smb_thread_start().
227 * This transition is executed by the thread itself when it starts running.
231 * This transition is executed by the thread itself in
232 * smb_thread_entry_point() just before calling thread_exit().
237 * This transition is executed in smb_thread_stop().
241 * This transition is executed in smb_thread_destroy().
243 typedef enum smb_thread_state
{
244 SMB_THREAD_STATE_STARTING
= 0,
245 SMB_THREAD_STATE_RUNNING
,
246 SMB_THREAD_STATE_EXITING
,
247 SMB_THREAD_STATE_EXITED
248 } smb_thread_state_t
;
252 typedef void (*smb_thread_ep_t
)(struct _smb_thread
*, void *ep_arg
);
254 #define SMB_THREAD_MAGIC 0x534D4254 /* SMBT */
256 typedef struct _smb_thread
{
259 smb_thread_state_t sth_state
;
262 smb_thread_ep_t sth_ep
;
273 * A pool of IDs is a pool of 16 bit numbers. It is implemented as a bitmap.
274 * A bit set to '1' indicates that that particular value has been allocated.
275 * The allocation process is done shifting a bit through the whole bitmap.
276 * The current position of that index bit is kept in the smb_idpool_t
277 * structure and represented by a byte index (0 to buffer size minus 1) and
278 * a bit index (0 to 7).
280 * The pools start with a size of 8 bytes or 64 IDs. Each time the pool runs
281 * out of IDs its current size is doubled until it reaches its maximum size
282 * (8192 bytes or 65536 IDs). The IDs 0 and 65535 are never given out which
283 * means that a pool can have a maximum number of 65534 IDs available.
285 #define SMB_IDPOOL_MAGIC 0x4944504C /* IDPL */
286 #define SMB_IDPOOL_MIN_SIZE 64 /* Number of IDs to begin with */
287 #define SMB_IDPOOL_MAX_SIZE 64 * 1024
289 typedef struct smb_idpool
{
298 uint32_t id_free_counter
;
299 uint32_t id_max_free_counter
;
303 * Maximum size of a Transport Data Unit when CAP_LARGE_READX and
304 * CAP_LARGE_WRITEX are not set. CAP_LARGE_READX/CAP_LARGE_WRITEX
305 * allow the payload to exceed the negotiated buffer size.
306 * 4 --> NBT/TCP Transport Header.
308 * 1 --> Word Count byte
309 * 510 --> Maximum Number of bytes of the Word Table (2 * 255)
310 * 2 --> Byte count of the data
311 * 65535 --> Maximum size of the data
315 #define SMB_REQ_MAX_SIZE 66560 /* 65KB */
316 #define SMB_XPRT_MAX_SIZE (SMB_REQ_MAX_SIZE + NETBIOS_HDR_SZ)
318 #define SMB_TXREQ_MAGIC 0X54524251 /* 'TREQ' */
323 uint8_t tr_buf
[SMB_XPRT_MAX_SIZE
];
326 #define SMB_TXLST_MAGIC 0X544C5354 /* 'TLST' */
335 * Maximum buffer size for NT is 37KB. If all clients are Windows 2000, this
336 * can be changed to 64KB. 37KB must be used with a mix of NT/Windows 2000
337 * clients because NT loses directory entries when values greater than 37KB are
340 * Note: NBT_MAXBUF will be subtracted from the specified max buffer size to
341 * account for the NBT header.
344 #define SMB_NT_MAXBUF (37 * 1024)
346 #define OUTBUFSIZE (65 * 1024)
347 #define SMBHEADERSIZE 32
348 #define SMBND_HASH_MASK (0xFF)
349 #define MAX_IOVEC 512
350 #define MAX_READREF (8 * 1024)
352 #define SMB_WORKER_MIN 4
353 #define SMB_WORKER_DEFAULT 64
354 #define SMB_WORKER_MAX 1024
357 * Destructor object used in the locked-list delete queue.
359 #define SMB_DTOR_MAGIC 0x44544F52 /* DTOR */
360 #define SMB_DTOR_VALID(d) \
361 ASSERT(((d) != NULL) && ((d)->dt_magic == SMB_DTOR_MAGIC))
363 typedef void (*smb_dtorproc_t
)(void *);
365 typedef struct smb_dtor
{
369 smb_dtorproc_t dt_proc
;
372 typedef struct smb_llist
{
379 uint32_t ll_deleteq_count
;
380 boolean_t ll_flushing
;
383 typedef struct smb_slist
{
388 boolean_t sl_waiting
;
392 * smb_avl_t State Machine
393 * --------------------
395 * +-----------------------------+
396 * | SMB_AVL_STATE_START |
397 * +-----------------------------+
400 * +-----------------------------+
401 * | SMB_AVL_STATE_READY |
402 * +-----------------------------+
405 * +-----------------------------+
406 * | SMB_AVL_STATE_DESTROYING |
407 * +-----------------------------+
411 * This transition is executed in smb_avl_create().
415 * This transition is executed in smb_avl_destroy().
419 SMB_AVL_STATE_START
= 0,
421 SMB_AVL_STATE_DESTROYING
424 typedef struct smb_avl_nops
{
425 int (*avln_cmp
) (const void *, const void *);
426 void (*avln_hold
)(const void *);
427 boolean_t (*avln_rele
)(const void *);
428 void (*avln_destroy
)(void *);
431 typedef struct smb_avl_cursor
{
433 uint32_t avlc_sequence
;
436 typedef struct smb_avl
{
441 smb_avl_state_t avl_state
;
443 uint32_t avl_sequence
;
444 smb_avl_nops_t
*avl_nops
;
451 boolean_t rwx_waiting
;
455 typedef struct smb_node_fcn
{
458 list_t fcn_watchers
; /* smb_request_t, sr_ncr.nc_lnd */
461 typedef struct smb_notify_change_req
{
462 list_node_t nc_lnd
; /* n_fcn.fcn_watchers */
463 kcondvar_t nc_cv
; /* prot: sr_mutex */
467 } smb_notify_change_req_t
;
470 * SMB operates over a NetBIOS-over-TCP transport (NBT) or directly
471 * over TCP, which is also known as direct hosted NetBIOS-less SMB
474 * NBT messages have a 4-byte header that defines the message type
475 * (8-bits), a 7-bit flags field and a 17-bit length.
477 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
478 * | TYPE | FLAGS |E| LENGTH |
479 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
481 * 8-bit type Defined in RFC 1002
482 * 7-bit flags Bits 0-6 reserved (must be 0)
483 * Bit 7: Length extension bit (E)
484 * 17-bit length Includes bit 7 of the flags byte
487 * SMB-over-TCP is defined to use a modified version of the NBT header
488 * containing an 8-bit message type and 24-bit message length.
490 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
492 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
494 * 8-bit type Must be 0
497 * The following structure is used to represent a generic, in-memory
498 * SMB transport header; it is not intended to map directly to either
499 * of the over-the-wire formats.
506 int MBC_LENGTH(struct mbuf_chain
*);
507 int MBC_MAXBYTES(struct mbuf_chain
*);
508 void MBC_SETUP(struct mbuf_chain
*, uint32_t);
509 void MBC_INIT(struct mbuf_chain
*, uint32_t);
510 void MBC_FLUSH(struct mbuf_chain
*);
511 void MBC_ATTACH_MBUF(struct mbuf_chain
*, struct mbuf
*);
512 void MBC_APPEND_MBUF(struct mbuf_chain
*, struct mbuf
*);
513 void MBC_ATTACH_BUF(struct mbuf_chain
*MBC
, unsigned char *BUF
, int LEN
);
514 int MBC_SHADOW_CHAIN(struct mbuf_chain
*SUBMBC
, struct mbuf_chain
*MBC
,
517 #define MBC_ROOM_FOR(b, n) (((b)->chain_offset + (n)) <= (b)->max_bytes)
519 #define OPLOCK_MIN_TIMEOUT (5 * 1000)
520 #define OPLOCK_STD_TIMEOUT (30 * 1000)
523 * Oplock break flags:
524 * SMB_OPLOCK_BREAK_EXCLUSIVE - only break exclusive oplock
525 * (type SMB_OPLOCK_EXCLUSIVE or SMB_OPLOCK_BATCH)
526 * SMB_OPLOCK_BREAK_BATCH - only break exclusive BATCH oplock
527 * SMB_OPLOCK_BREAK_NOWAIT - do not wait for oplock break ack
529 #define SMB_OPLOCK_NO_BREAK 0x00
530 #define SMB_OPLOCK_BREAK_TO_NONE 0x01
531 #define SMB_OPLOCK_BREAK_TO_LEVEL_II 0x02
532 #define SMB_OPLOCK_BREAK_EXCLUSIVE 0x04
533 #define SMB_OPLOCK_BREAK_BATCH 0x08
534 #define SMB_OPLOCK_BREAK_NOWAIT 0x10
537 * Oplocks levels are defined to match the levels in the SMB
538 * protocol (nt_create_andx / nt_transact_create) and should
541 #define SMB_OPLOCK_NONE 0
542 #define SMB_OPLOCK_EXCLUSIVE 1
543 #define SMB_OPLOCK_BATCH 2
544 #define SMB_OPLOCK_LEVEL_II 3
546 typedef struct smb_oplock
{
549 kthread_t
*ol_xthread
;
550 boolean_t ol_fem
; /* fem monitor installed? */
552 uint32_t ol_count
; /* number of grants */
553 list_t ol_grants
; /* list of smb_oplock_grant_t */
556 #define SMB_OPLOCK_GRANT_MAGIC 0x4F4C4B47 /* OLKG */
557 #define SMB_OPLOCK_GRANT_VALID(p) \
558 ASSERT((p)->og_magic == SMB_OPLOCK_GRANT_MAGIC)
559 #define SMB_OFILE_OPLOCK_GRANTED(p) \
560 ((p)->f_oplock_grant.og_magic == SMB_OPLOCK_GRANT_MAGIC)
561 typedef struct smb_oplock_grant
{
568 struct smb_session
*og_session
;
569 struct smb_ofile
*og_ofile
;
570 } smb_oplock_grant_t
;
572 #define SMB_OPLOCK_BREAK_MAGIC 0x4F4C4B42 /* OLKB */
573 #define SMB_OPLOCK_BREAK_VALID(p) \
574 ASSERT((p)->ob_magic == SMB_OPLOCK_BREAK_MAGIC)
575 typedef struct smb_oplock_break
{
578 struct smb_node
*ob_node
;
579 } smb_oplock_break_t
;
582 #define SMB_VFS_MAGIC 0x534D4256 /* 'SMBV' */
584 typedef struct smb_vfs
{
593 * Solaris file systems handle timestamps differently from NTFS.
594 * In order to provide a more similar view of an open file's
595 * timestamps, we cache the timestamps in the node and manipulate
596 * them in a manner more consistent with windows.
597 * t_cached is B_TRUE when timestamps are cached.
598 * Timestamps remain cached while there are open ofiles for the node.
599 * This includes open ofiles for named streams. t_open_ofiles is a
600 * count of open ofiles on the node, including named streams' ofiles,
601 * n_open_count cannot be used as it doesn't include ofiles opened
602 * for the node's named streams.
604 typedef struct smb_times
{
605 uint32_t t_open_ofiles
;
610 timestruc_t t_crtime
;
613 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */
614 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC)
617 SMB_NODE_STATE_AVAILABLE
= 0,
618 SMB_NODE_STATE_DESTROYING
622 * waiting_event # of clients requesting FCN
623 * n_timestamps cached timestamps
624 * n_allocsz cached file allocation size
625 * n_dnode directory node
626 * n_unode unnamed stream node
627 * delete_on_close_cred credentials for delayed delete
629 typedef struct smb_node
{
634 smb_node_state_t n_state
;
637 smb_llist_t
*n_hash_bucket
;
638 uint32_t n_open_count
;
639 uint32_t n_opening_count
;
640 smb_llist_t n_ofile_list
;
641 smb_llist_t n_lock_list
;
642 struct smb_ofile
*readonly_creator
;
644 volatile int waiting_event
;
645 smb_times_t n_timestamps
;
646 u_offset_t n_allocsz
;
647 smb_node_fcn_t n_fcn
;
648 smb_oplock_t n_oplock
;
649 struct smb_node
*n_dnode
;
650 struct smb_node
*n_unode
;
651 cred_t
*delete_on_close_cred
;
652 uint32_t n_delete_on_close_flags
;
653 char od_name
[MAXNAMELEN
];
655 smb_audit_buf_node_t
*n_audit_buf
;
658 #define NODE_FLAGS_REPARSE 0x00001000
659 #define NODE_FLAGS_DFSLINK 0x00002000
660 #define NODE_FLAGS_VFSROOT 0x00004000
661 #define NODE_FLAGS_SYSTEM 0x00008000
662 #define NODE_FLAGS_WRITE_THROUGH 0x00100000
663 #define NODE_XATTR_DIR 0x01000000
664 #define NODE_FLAGS_DELETE_ON_CLOSE 0x40000000
665 #define NODE_FLAGS_EXECUTABLE 0x80000000
667 #define SMB_NODE_VFS(node) ((node)->vp->v_vfsp)
668 #define SMB_NODE_FSID(node) ((node)->vp->v_vfsp->vfs_fsid)
670 /* Maximum buffer size for encryption key */
671 #define SMB_ENCRYPT_KEY_MAXLEN 32
673 #define SMB_SHARE_MAGIC 0x4B534852 /* KSHR */
675 typedef struct smb_kshare
{
685 uint32_t shr_autocnt
;
688 char *shr_access_none
;
692 kmem_cache_t
*shr_cache
;
697 typedef struct smb_arg_negotiate
{
701 uint32_t ni_capabilities
;
702 uint16_t ni_maxmpxcount
;
703 int16_t ni_tzcorrection
;
705 uint8_t ni_key
[SMB_ENCRYPT_KEY_MAXLEN
];
706 timestruc_t ni_servertime
;
707 } smb_arg_negotiate_t
;
709 typedef struct smb_arg_sessionsetup
{
712 uint16_t ssi_cipwlen
;
714 uint16_t ssi_cspwlen
;
716 uint16_t ssi_maxmpxcount
;
717 uint32_t ssi_capabilities
;
718 uint32_t ssi_sesskey
;
720 } smb_arg_sessionsetup_t
;
722 typedef struct tcon
{
728 uint16_t optional_support
;
733 * Based on section 2.6.1.2 (Connection Management) of the June 13,
734 * 1996 CIFS spec, a server may terminate the transport connection
735 * due to inactivity. The client software is expected to be able to
736 * automatically reconnect to the server if this happens. Like much
737 * of the useful background information, this section appears to
738 * have been dropped from later revisions of the document.
740 * Each session has an activity timestamp that's updated whenever a
741 * request is dispatched. If the session is idle, i.e. receives no
742 * requests, for SMB_SESSION_INACTIVITY_TIMEOUT minutes it will be
745 * Each session has an I/O semaphore to serialize communication with
746 * the client. For example, after receiving a raw-read request, the
747 * server is not allowed to send an oplock break to the client until
748 * after it has sent the raw-read data.
750 #define SMB_SESSION_INACTIVITY_TIMEOUT (15 * 60)
752 #define SMB_SESSION_OFILE_MAX (16 * 1024)
755 * When a connection is set up we need to remember both the client
756 * (peer) IP address and the local IP address used to establish the
757 * connection. When a client connects with a vc number of zero, we
758 * are supposed to abort any existing connections with that client
759 * (see notes in smb_negotiate.c and smb_session_setup_andx.c). For
760 * servers with multiple network interfaces or IP aliases, however,
761 * each interface has to be managed independently since the client
762 * is not aware of the server configuration. We have to allow the
763 * client to establish a connection on each interface with a vc
764 * number of zero without aborting the other connections.
766 * ipaddr: the client (peer) IP address for the session.
767 * local_ipaddr: the local IP address used to connect to the server.
770 #define SMB_MAC_KEYSZ 512
774 unsigned int mackey_len
;
776 unsigned char mackey
[SMB_MAC_KEYSZ
];
779 #define SMB_SIGNING_ENABLED 1
780 #define SMB_SIGNING_CHECK 2
783 * Session State Machine
784 * ---------------------
786 * +-----------------------------+ +------------------------------+
787 * | SMB_SESSION_STATE_CONNECTED | | SMB_SESSION_STATE_TERMINATED |
788 * +-----------------------------+ +------------------------------+
790 * +--------------------+ |T13
792 * +-------------------------------+ | +--------------------------------+
793 * | SMB_SESSION_STATE_ESTABLISHED |---+--->| SMB_SESSION_STATE_DISCONNECTED |
794 * +-------------------------------+ +--------------------------------+
796 * +----------+ |T9 | | |
798 * +------------------------------+ | | |
799 * | SMB_SESSION_STATE_NEGOTIATED | | | |
800 * +------------------------------+ | | |
802 * +----------------+| || | | | | |
803 * |+----------------+ || T7| |T8 | | |
805 * || +----------------+| | | | | |
806 * || |+----------------+ | | | | |
808 * || || +-----------------------------------+ T10| | |
809 * || || | SMB_SESSION_STATE_OPLOCK_BREAKING |----+ | |
810 * || || +-----------------------------------+ | |
812 * || |+-->+-----------------------------------+ T11| |
813 * || |T6 | SMB_SESSION_STATE_READ_RAW_ACTIVE |------+ |
814 * || +----+-----------------------------------+ |
816 * |+------->+------------------------------------+ T12|
817 * |T4 | SMB_SESSION_STATE_WRITE_RAW_ACTIVE |-------+
818 * +---------+------------------------------------+
881 #define SMB_SESSION_MAGIC 0x53455353 /* 'SESS' */
882 #define SMB_SESSION_VALID(p) \
883 ASSERT(((p) != NULL) && ((p)->s_magic == SMB_SESSION_MAGIC))
886 SMB_SESSION_STATE_INITIALIZED
= 0,
887 SMB_SESSION_STATE_DISCONNECTED
,
888 SMB_SESSION_STATE_CONNECTED
,
889 SMB_SESSION_STATE_ESTABLISHED
,
890 SMB_SESSION_STATE_NEGOTIATED
,
891 SMB_SESSION_STATE_OPLOCK_BREAKING
,
892 SMB_SESSION_STATE_WRITE_RAW_ACTIVE
,
893 SMB_SESSION_STATE_READ_RAW_ACTIVE
,
894 SMB_SESSION_STATE_TERMINATED
,
895 SMB_SESSION_STATE_SENTINEL
896 } smb_session_state_t
;
898 typedef struct smb_session
{
903 smb_session_state_t s_state
;
905 int s_write_raw_status
;
908 smb_kmod_cfg_t s_cfg
;
909 kmem_cache_t
*s_cache
;
910 kmem_cache_t
*s_cache_request
;
911 struct smb_server
*s_server
;
916 uint16_t s_local_port
;
918 smb_inaddr_t local_ipaddr
;
919 char workstation
[SMB_PI_MAX_HOST
];
924 uint32_t capabilities
;
925 struct smb_sign signing
;
929 smb_slist_t s_req_list
;
930 smb_llist_t s_xa_list
;
931 smb_llist_t s_user_list
;
932 smb_idpool_t s_uid_pool
;
935 volatile uint32_t s_tree_cnt
;
936 volatile uint32_t s_file_cnt
;
937 volatile uint32_t s_dir_cnt
;
941 uint32_t challenge_len
;
942 unsigned char challenge_key
[8];
943 unsigned char MAC_key
[44];
944 int64_t activity_timestamp
;
946 * Maximum negotiated buffer size between SMB client and server
947 * in SMB_SESSION_SETUP_ANDX
949 uint16_t smb_msg_size
;
950 uchar_t
*outpipe_data
;
953 list_t s_oplock_brkreqs
;
954 smb_srqueue_t
*s_srqueue
;
957 #define SMB_USER_MAGIC 0x55534552 /* 'USER' */
958 #define SMB_USER_VALID(u) \
959 ASSERT(((u) != NULL) && ((u)->u_magic == SMB_USER_MAGIC))
961 #define SMB_USER_FLAG_GUEST SMB_ATF_GUEST
962 #define SMB_USER_FLAG_IPC SMB_ATF_ANON
963 #define SMB_USER_FLAG_ADMIN SMB_ATF_ADMIN
964 #define SMB_USER_FLAG_POWER_USER SMB_ATF_POWERUSER
965 #define SMB_USER_FLAG_BACKUP_OPERATOR SMB_ATF_BACKUPOP
967 #define SMB_USER_IS_ADMIN(U) (((U)->u_flags & SMB_USER_FLAG_ADMIN) != 0)
968 #define SMB_USER_IS_GUEST(U) (((U)->u_flags & SMB_USER_FLAG_GUEST) != 0)
970 #define SMB_USER_PRIV_TAKE_OWNERSHIP 0x00000001
971 #define SMB_USER_PRIV_BACKUP 0x00000002
972 #define SMB_USER_PRIV_RESTORE 0x00000004
973 #define SMB_USER_PRIV_SECURITY 0x00000008
977 SMB_USER_STATE_LOGGED_IN
= 0,
978 SMB_USER_STATE_LOGGING_OFF
,
979 SMB_USER_STATE_LOGGED_OFF
,
980 SMB_USER_STATE_SENTINEL
983 typedef struct smb_user
{
987 smb_user_state_t u_state
;
989 struct smb_server
*u_server
;
990 smb_session_t
*u_session
;
993 uint16_t u_domain_len
;
999 smb_llist_t u_tree_list
;
1000 smb_idpool_t u_tid_pool
;
1004 uint32_t u_privileges
;
1006 uint32_t u_audit_sid
;
1009 #define SMB_TREE_MAGIC 0x54524545 /* 'TREE' */
1010 #define SMB_TREE_VALID(p) \
1011 ASSERT((p != NULL) && ((p)->t_magic == SMB_TREE_MAGIC))
1013 #define SMB_TYPENAMELEN _ST_FSTYPSZ
1014 #define SMB_VOLNAMELEN 32
1016 #define SMB_TREE_READONLY 0x00000001
1017 #define SMB_TREE_SUPPORTS_ACLS 0x00000002
1018 #define SMB_TREE_STREAMS 0x00000004
1019 #define SMB_TREE_CASEINSENSITIVE 0x00000008
1020 #define SMB_TREE_NO_CASESENSITIVE 0x00000010
1021 #define SMB_TREE_NO_EXPORT 0x00000020
1022 #define SMB_TREE_OPLOCKS 0x00000040
1023 #define SMB_TREE_SHORTNAMES 0x00000080
1024 #define SMB_TREE_XVATTR 0x00000100
1025 #define SMB_TREE_DIRENTFLAGS 0x00000200
1026 #define SMB_TREE_ACLONCREATE 0x00000400
1027 #define SMB_TREE_ACEMASKONACCESS 0x00000800
1028 #define SMB_TREE_NFS_MOUNTED 0x00001000
1029 #define SMB_TREE_UNICODE_ON_DISK 0x00002000
1030 #define SMB_TREE_CATIA 0x00004000
1031 #define SMB_TREE_ABE 0x00008000
1032 #define SMB_TREE_QUOTA 0x00010000
1033 #define SMB_TREE_DFSROOT 0x00020000
1034 #define SMB_TREE_SPARSE 0x00040000
1035 #define SMB_TREE_TRAVERSE_MOUNTS 0x00080000
1038 SMB_TREE_STATE_CONNECTED
= 0,
1039 SMB_TREE_STATE_DISCONNECTING
,
1040 SMB_TREE_STATE_DISCONNECTED
,
1041 SMB_TREE_STATE_SENTINEL
1044 typedef struct smb_tree
{
1048 smb_tree_state_t t_state
;
1050 struct smb_server
*t_server
;
1051 smb_session_t
*t_session
;
1053 smb_node_t
*t_snode
;
1055 smb_llist_t t_ofile_list
;
1056 smb_idpool_t t_fid_pool
;
1058 smb_llist_t t_odir_list
;
1059 smb_idpool_t t_odid_pool
;
1066 char t_sharename
[MAXNAMELEN
];
1067 char t_resource
[MAXPATHLEN
];
1068 char t_typename
[SMB_TYPENAMELEN
];
1069 char t_volume
[SMB_VOLNAMELEN
];
1070 acl_type_t t_acltype
;
1072 uint32_t t_execflags
;
1073 time_t t_connect_time
;
1074 volatile uint32_t t_open_files
;
1077 #define SMB_TREE_VFS(tree) ((tree)->t_snode->vp->v_vfsp)
1078 #define SMB_TREE_FSID(tree) ((tree)->t_snode->vp->v_vfsp->vfs_fsid)
1080 #define SMB_TREE_IS_READONLY(sr) \
1081 ((sr) != NULL && (sr)->tid_tree != NULL && \
1082 !((sr)->tid_tree->t_access & ACE_ALL_WRITE_PERMS))
1084 #define SMB_TREE_IS_CASEINSENSITIVE(sr) \
1085 (((sr) && (sr)->tid_tree) ? \
1086 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CASEINSENSITIVE) : 0)
1088 #define SMB_TREE_HAS_ACCESS(sr, acemask) \
1089 ((sr) == NULL ? ACE_ALL_PERMS : ( \
1090 (((sr) && (sr)->tid_tree) ? \
1091 (((sr)->tid_tree->t_access) & (acemask)) : 0)))
1093 #define SMB_TREE_SUPPORTS_CATIA(sr) \
1094 (((sr) && (sr)->tid_tree) ? \
1095 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CATIA) : 0)
1097 #define SMB_TREE_SUPPORTS_ABE(sr) \
1098 (((sr) && (sr)->tid_tree) ? \
1099 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_ABE) : 0)
1101 #define SMB_TREE_IS_DFSROOT(sr) \
1102 (((sr) && (sr)->tid_tree) ? \
1103 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_DFSROOT) : 0)
1105 #define SMB_TREE_SUPPORTS_SHORTNAMES(sr) \
1106 (((sr) && (sr)->tid_tree) ? \
1107 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_SHORTNAMES) : 0)
1110 * SMB_TREE_CONTAINS_NODE is used to check if a node is on the same
1111 * file system as the tree's root filesystem, or if mount point traversal
1112 * should be allowed. Note that this is also called in some cases with
1113 * sr=NULL, where it is expected to evaluate to TRUE.
1116 #define SMB_TREE_CONTAINS_NODE(sr, node) \
1117 ((sr) == NULL || (sr)->tid_tree == NULL || \
1118 SMB_TREE_VFS((sr)->tid_tree) == SMB_NODE_VFS(node) || \
1119 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_TRAVERSE_MOUNTS))
1122 * SMB_OFILE_IS_READONLY reflects whether an ofile is readonly or not.
1123 * The macro takes into account
1124 * - the tree readonly state
1125 * - the node readonly state
1126 * - whether the specified ofile is the readonly creator
1127 * The readonly creator has write permission until the ofile is closed.
1130 #define SMB_OFILE_IS_READONLY(of) \
1131 (((of)->f_flags & SMB_OFLAGS_READONLY) || \
1132 smb_node_file_is_readonly((of)->f_node) || \
1133 (((of)->f_node->readonly_creator) && \
1134 ((of)->f_node->readonly_creator != (of))))
1137 * SMB_PATHFILE_IS_READONLY indicates whether or not a file is
1138 * readonly when the caller has a path rather than an ofile. Unlike
1139 * SMB_OFILE_IS_READONLY, the caller cannot be the readonly creator,
1140 * since that requires an ofile.
1143 #define SMB_PATHFILE_IS_READONLY(sr, node) \
1144 (SMB_TREE_IS_READONLY((sr)) || \
1145 smb_node_file_is_readonly((node)) || \
1146 ((node)->readonly_creator))
1148 #define SMB_OPIPE_MAGIC 0x50495045 /* 'PIPE' */
1149 #define SMB_OPIPE_VALID(p) \
1150 ASSERT(((p) != NULL) && (p)->p_magic == SMB_OPIPE_MAGIC)
1153 * Data structure for SMB_FTYPE_MESG_PIPE ofiles, which is used
1154 * at the interface between SMB and NDR RPC.
1156 typedef struct smb_opipe
{
1161 struct smb_server
*p_server
;
1162 struct smb_event
*p_event
;
1165 smb_doorhdr_t p_hdr
;
1166 smb_netuserinfo_t p_user
;
1172 * The of_ftype of an open file should contain the SMB_FTYPE value
1173 * returned when the file/pipe was opened. The following
1174 * assumptions are currently made:
1176 * File Type Node PipeInfo
1177 * --------- -------- --------
1178 * SMB_FTYPE_DISK Valid Null
1179 * SMB_FTYPE_BYTE_PIPE Undefined Undefined
1180 * SMB_FTYPE_MESG_PIPE Null Valid
1181 * SMB_FTYPE_PRINTER Undefined Undefined
1182 * SMB_FTYPE_UNKNOWN Undefined Undefined
1186 * Some flags for ofile structure
1188 * SMB_OFLAGS_SET_DELETE_ON_CLOSE
1189 * Set this flag when the corresponding open operation whose
1190 * DELETE_ON_CLOSE bit of the CreateOptions is set. If any
1191 * open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE
1192 * will be set for the file node upon close.
1194 * SMB_OFLAGS_TIMESTAMPS_PENDING
1195 * This flag gets set when a write operation is performed on the
1196 * ofile. The timestamps will be updated, and the flags cleared,
1197 * when the ofile gets closed or a setattr is performed on the ofile.
1200 #define SMB_OFLAGS_READONLY 0x0001
1201 #define SMB_OFLAGS_EXECONLY 0x0002
1202 #define SMB_OFLAGS_SET_DELETE_ON_CLOSE 0x0004
1203 #define SMB_OFLAGS_LLF_POS_VALID 0x0008
1204 #define SMB_OFLAGS_TIMESTAMPS_PENDING 0x0010
1206 #define SMB_OFILE_MAGIC 0x4F464C45 /* 'OFLE' */
1207 #define SMB_OFILE_VALID(p) \
1208 ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC))
1211 SMB_OFILE_STATE_OPEN
= 0,
1212 SMB_OFILE_STATE_CLOSING
,
1213 SMB_OFILE_STATE_CLOSED
,
1214 SMB_OFILE_STATE_SENTINEL
1215 } smb_ofile_state_t
;
1217 typedef struct smb_ofile
{
1222 smb_ofile_state_t f_state
;
1224 struct smb_server
*f_server
;
1225 smb_session_t
*f_session
;
1229 smb_opipe_t
*f_pipe
;
1233 uint64_t f_seek_pos
;
1235 uint32_t f_granted_access
;
1236 uint32_t f_share_access
;
1237 uint32_t f_create_options
;
1239 uint16_t f_opened_by_pid
;
1245 uint32_t f_explicit_times
;
1246 char f_quota_resume
[SMB_SID_STRSZ
];
1247 smb_oplock_grant_t f_oplock_grant
;
1250 #define SMB_ODIR_MAGIC 0x4F444952 /* 'ODIR' */
1251 #define SMB_ODIR_VALID(p) \
1252 ASSERT((p != NULL) && ((p)->d_magic == SMB_ODIR_MAGIC))
1254 #define SMB_ODIR_BUFSIZE (8 * 1024)
1256 #define SMB_ODIR_FLAG_WILDCARDS 0x0001
1257 #define SMB_ODIR_FLAG_IGNORE_CASE 0x0002
1258 #define SMB_ODIR_FLAG_XATTR 0x0004
1259 #define SMB_ODIR_FLAG_EDIRENT 0x0008
1260 #define SMB_ODIR_FLAG_CATIA 0x0010
1261 #define SMB_ODIR_FLAG_ABE 0x0020
1262 #define SMB_ODIR_FLAG_SHORTNAMES 0x0040
1265 SMB_ODIR_STATE_OPEN
= 0,
1266 SMB_ODIR_STATE_IN_USE
,
1267 SMB_ODIR_STATE_CLOSING
,
1268 SMB_ODIR_STATE_CLOSED
,
1269 SMB_ODIR_STATE_SENTINEL
1273 SMB_ODIR_RESUME_CONT
,
1274 SMB_ODIR_RESUME_IDX
,
1275 SMB_ODIR_RESUME_COOKIE
,
1276 SMB_ODIR_RESUME_FNAME
1277 } smb_odir_resume_type_t
;
1279 typedef struct smb_odir_resume
{
1280 smb_odir_resume_type_t or_type
;
1284 } smb_odir_resume_t
;
1287 * Flags used when opening an odir
1289 #define SMB_ODIR_OPENF_BACKUP_INTENT 0x01
1291 typedef struct smb_odir
{
1295 smb_odir_state_t d_state
;
1296 smb_session_t
*d_session
;
1298 smb_node_t
*d_dnode
;
1301 uint16_t d_opened_by_pid
;
1313 uint32_t d_last_cookie
;
1314 uint32_t d_cookies
[SMB_MAX_SEARCH
];
1315 char d_pattern
[MAXNAMELEN
];
1316 char d_buf
[SMB_ODIR_BUFSIZE
];
1317 char d_last_name
[MAXNAMELEN
];
1319 #define d_bufptr d_u.u_bufptr
1320 #define d_edp d_u.u_edp
1321 #define d_dp d_u.u_dp
1323 typedef struct smb_odirent
{
1324 char od_name
[MAXNAMELEN
]; /* on disk name */
1329 typedef struct smb_fileinfo
{
1330 char fi_name
[MAXNAMELEN
];
1331 char fi_shortname
[SMB_SHORTNAMELEN
];
1332 uint32_t fi_cookie
; /* Dir offset (of next entry) */
1333 uint32_t fi_dosattr
; /* DOS attributes */
1334 uint64_t fi_nodeid
; /* file system node id */
1335 uint64_t fi_size
; /* file size in bytes */
1336 uint64_t fi_alloc_size
; /* allocation size in bytes */
1337 timestruc_t fi_atime
; /* last access */
1338 timestruc_t fi_mtime
; /* last modification */
1339 timestruc_t fi_ctime
; /* last status change */
1340 timestruc_t fi_crtime
; /* file creation */
1343 typedef struct smb_streaminfo
{
1345 uint64_t si_alloc_size
;
1346 char si_name
[MAXPATHLEN
];
1349 #define SMB_LOCK_MAGIC 0x4C4F434B /* 'LOCK' */
1351 typedef struct smb_lock
{
1357 list_node_t l_conflict_lnd
;
1358 smb_slist_t l_conflict_list
;
1360 smb_session_t
*l_session
;
1361 smb_ofile_t
*l_file
;
1362 struct smb_request
*l_sr
;
1365 uint64_t l_session_kid
;
1366 struct smb_lock
*l_blocked_by
; /* Debug info only */
1376 #define SMB_LOCK_FLAG_INDEFINITE 0x0004
1377 #define SMB_LOCK_INDEFINITE_WAIT(lock) \
1378 ((lock)->l_flags & SMB_LOCK_FLAG_INDEFINITE)
1380 #define SMB_LOCK_TYPE_READWRITE 101
1381 #define SMB_LOCK_TYPE_READONLY 102
1383 typedef struct vardata_block
{
1387 struct iovec vdb_iovec
[MAX_IOVEC
];
1390 #define SMB_WRMODE_WRITE_THRU 0x0001
1391 #define SMB_WRMODE_IS_STABLE(M) ((M) & SMB_WRMODE_WRITE_THRU)
1393 #define SMB_RW_MAGIC 0x52445257 /* 'RDRW' */
1395 typedef struct smb_rw_param
{
1399 uint32_t rw_last_write
;
1401 uint32_t rw_count
; /* bytes in this request */
1403 uint32_t rw_total
; /* total bytes (write-raw) */
1404 uint16_t rw_dsoff
; /* SMB data offset */
1405 uint8_t rw_andx
; /* SMB secondary andx command */
1408 typedef struct smb_pathname
{
1419 typedef struct smb_fqi
{
1420 smb_pathname_t fq_path
;
1422 smb_node_t
*fq_dnode
;
1423 smb_node_t
*fq_fnode
;
1424 smb_attr_t fq_fattr
;
1425 char fq_last_comp
[MAXNAMELEN
];
1428 typedef struct dirop
{
1431 uint16_t info_level
;
1441 typedef struct open_param
{
1451 uint32_t desired_access
;
1452 uint32_t share_access
;
1453 uint32_t create_options
;
1454 uint32_t create_disposition
;
1455 boolean_t created_readonly
;
1458 uint32_t action_taken
;
1460 uint32_t rootdirfid
;
1462 /* This is only set by NTTransactCreate */
1464 uint8_t op_oplock_level
; /* requested/granted level */
1465 boolean_t op_oplock_levelII
; /* TRUE if levelII supported */
1469 * SMB Request State Machine
1470 * -------------------------
1473 * +--------------------------->| FREE |---------------------------+
1479 * | T15 +----------+ v
1480 * +------------+ T6 | | +--------------+
1481 * | CLEANED_UP |<-----------------| CANCELED | | INITIALIZING |
1482 * +------------+ | | +--------------+
1483 * | ^ +----------+ |
1485 * | | +-------------+ | | | |
1486 * | | T3 | | | | T13 | T1
1487 * | +-------------------------+ | | +----------------------+ |
1488 * +----------------------------+ | | | | |
1489 * T16 | | | | +-----------+ | |
1491 * +-----------------+ | T12 +--------+ | T2 +-----------+
1492 * | EVENT_OCCURRED |------------->| ACTIVE |<--------------------| SUBMITTED |
1493 * +-----------------+ | +--------+ | +-----------+
1496 * | T10 T9 | +----------+ | +-------+ | T11
1497 * | | | +-------+ | |
1500 * +----------------------+ +--------------+
1501 * | WAITING_EVENT | | WAITING_LOCK |
1502 * +----------------------+ +--------------+
1510 * This transition occurs when the request is allocated and is still under the
1511 * control of the session thread.
1515 * This transition occurs when the session thread dispatches a task to treat the
1524 * A request completes and smbsr_cleanup is called to release resources
1525 * associated with the request (but not the smb_request_t itself). This
1526 * includes references on smb_ofile_t, smb_node_t, and other structures.
1527 * CLEANED_UP state exists to detect if we attempt to cleanup a request
1528 * multiple times and to allow us to detect that we are accessing a
1529 * request that has already been cleaned up.
1577 * Request processing is completed (control returns from smb_dispatch)
1581 * Multipart (andx) request was cleaned up with smbsr_cleanup but more "andx"
1582 * sections remain to be processed.
1586 #define SMB_REQ_MAGIC 0x534D4252 /* 'SMBR' */
1587 #define SMB_REQ_VALID(p) ASSERT((p)->sr_magic == SMB_REQ_MAGIC)
1589 typedef enum smb_req_state
{
1590 SMB_REQ_STATE_FREE
= 0,
1591 SMB_REQ_STATE_INITIALIZING
,
1592 SMB_REQ_STATE_SUBMITTED
,
1593 SMB_REQ_STATE_ACTIVE
,
1594 SMB_REQ_STATE_WAITING_EVENT
,
1595 SMB_REQ_STATE_EVENT_OCCURRED
,
1596 SMB_REQ_STATE_WAITING_LOCK
,
1597 SMB_REQ_STATE_COMPLETED
,
1598 SMB_REQ_STATE_CANCELED
,
1599 SMB_REQ_STATE_CLEANED_UP
,
1600 SMB_REQ_STATE_SENTINEL
1603 typedef struct smb_request
{
1606 list_node_t sr_session_lnd
;
1607 smb_req_state_t sr_state
;
1608 kmem_cache_t
*sr_cache
;
1609 struct smb_server
*sr_server
;
1612 smb_session_t
*session
;
1613 smb_kmod_cfg_t
*sr_cfg
;
1614 smb_notify_change_req_t sr_ncr
;
1616 /* Info from session service header */
1617 uint32_t sr_req_length
; /* Excluding NBT header */
1619 /* Request buffer excluding NBT header */
1620 void *sr_request_buf
;
1622 smb_lock_t
*sr_awaiting
;
1623 struct mbuf_chain command
;
1624 struct mbuf_chain reply
;
1625 struct mbuf_chain raw_data
;
1627 struct smb_xa
*r_xa
;
1629 int cur_reply_offset
;
1630 int orig_request_hdr
;
1631 unsigned int reply_seqnum
; /* reply sequence number */
1632 unsigned char first_smb_com
; /* command code */
1633 unsigned char smb_com
; /* command code */
1635 uint8_t smb_rcls
; /* error code class */
1636 uint8_t smb_reh
; /* rsvd (AH DOS INT-24 ERR) */
1637 uint16_t smb_err
; /* error code */
1638 smb_error_t smb_error
;
1640 uint8_t smb_flg
; /* flags */
1641 uint16_t smb_flg2
; /* flags */
1642 uint16_t smb_pid_high
; /* high part of pid */
1643 unsigned char smb_sig
[8]; /* signiture */
1644 uint16_t smb_tid
; /* tree id # */
1645 uint16_t smb_pid
; /* caller's process id # */
1646 uint16_t smb_uid
; /* user id # */
1647 uint16_t smb_mid
; /* mutiplex id # */
1648 unsigned char smb_wct
; /* count of parameter words */
1649 uint16_t smb_bcc
; /* data byte count */
1652 struct mbuf_chain smb_vwv
; /* variable width value */
1655 struct mbuf_chain smb_data
;
1657 uint16_t smb_fid
; /* not in hdr, but common */
1659 unsigned char andx_com
;
1662 struct smb_tree
*tid_tree
;
1663 struct smb_ofile
*fid_ofile
;
1664 smb_user_t
*uid_user
;
1667 smb_arg_negotiate_t
*negprot
;
1668 smb_arg_sessionsetup_t
*ssetup
;
1669 smb_arg_tcon_t tcon
;
1670 smb_arg_dirop_t dirop
;
1671 smb_arg_open_t open
;
1677 kthread_t
*sr_worker
;
1678 hrtime_t sr_time_submitted
;
1679 hrtime_t sr_time_active
;
1680 hrtime_t sr_time_start
;
1685 #define sr_ssetup arg.ssetup
1686 #define sr_negprot arg.negprot
1687 #define sr_tcon arg.tcon
1688 #define sr_dirop arg.dirop
1689 #define sr_open arg.open
1690 #define sr_rw arg.rw
1691 #define sr_timestamp arg.timestamp
1693 #define SMB_READ_PROTOCOL(hdr) \
1694 LE_IN32(((smb_hdr_t *)(hdr))->protocol)
1696 #define SMB_PROTOCOL_MAGIC_INVALID(rd_sr) \
1697 (SMB_READ_PROTOCOL((rd_sr)->sr_request_buf) != SMB_PROTOCOL_MAGIC)
1699 #define SMB_READ_COMMAND(hdr) \
1700 (((smb_hdr_t *)(hdr))->command)
1702 #define SMB_IS_WRITERAW(rd_sr) \
1703 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_WRITE_RAW)
1705 #define SMB_IS_NT_CANCEL(rd_sr) \
1706 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NT_CANCEL)
1708 #define SMB_IS_SESSION_SETUP_ANDX(rd_sr) \
1709 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == \
1710 SMB_COM_SESSION_SETUP_ANDX)
1712 #define SMB_IS_NT_NEGOTIATE(rd_sr) \
1713 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NEGOTIATE)
1715 #define SMB_IS_TREE_CONNECT_ANDX(rd_sr) \
1716 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_TREE_CONNECT_ANDX)
1718 #define SMB_XA_FLAG_OPEN 0x0001
1719 #define SMB_XA_FLAG_CLOSE 0x0002
1720 #define SMB_XA_FLAG_COMPLETE 0x0004
1721 #define SMB_XA_CLOSED(xa) (!((xa)->xa_flags & SMB_XA_FLAG_OPEN))
1723 #define SMB_XA_MAGIC 0x534D4258 /* 'SMBX' */
1725 typedef struct smb_xa
{
1733 struct smb_session
*xa_session
;
1735 unsigned char smb_com
; /* which TRANS type */
1736 unsigned char smb_flg
; /* flags */
1737 uint16_t smb_flg2
; /* flags */
1738 uint16_t smb_tid
; /* tree id number */
1739 uint16_t smb_pid
; /* caller's process id number */
1740 uint16_t smb_uid
; /* user id number */
1741 uint32_t smb_func
; /* NT_TRANS function */
1743 uint16_t xa_smb_mid
; /* mutiplex id number */
1744 uint16_t xa_smb_fid
; /* TRANS2 secondary */
1746 unsigned int reply_seqnum
; /* reply sequence number */
1748 uint32_t smb_tpscnt
; /* total parameter bytes being sent */
1749 uint32_t smb_tdscnt
; /* total data bytes being sent */
1750 uint32_t smb_mprcnt
; /* max parameter bytes to return */
1751 uint32_t smb_mdrcnt
; /* max data bytes to return */
1752 uint32_t smb_msrcnt
; /* max setup words to return */
1753 uint32_t smb_flags
; /* additional information: */
1754 /* bit 0 - if set, disconnect TID in smb_tid */
1755 /* bit 1 - if set, transaction is one way */
1756 /* (no final response) */
1757 int32_t smb_timeout
; /* number of milliseconds to await completion */
1758 uint32_t smb_suwcnt
; /* set up word count */
1765 struct mbuf_chain req_setup_mb
;
1766 struct mbuf_chain req_param_mb
;
1767 struct mbuf_chain req_data_mb
;
1769 struct mbuf_chain rep_setup_mb
;
1770 struct mbuf_chain rep_param_mb
;
1771 struct mbuf_chain rep_data_mb
;
1775 #define SDDF_NO_FLAGS 0
1776 #define SDDF_SUPPRESS_TID 0x0001
1777 #define SDDF_SUPPRESS_UID 0x0002
1780 * SMB dispatch return codes.
1788 SDRC_NOT_IMPLEMENTED
1791 #define VAR_BCC ((short)-1)
1793 #define SMB_SERVER_MAGIC 0x53534552 /* 'SSER' */
1794 #define SMB_SERVER_VALID(s) \
1795 ASSERT(((s) != NULL) && ((s)->sv_magic == SMB_SERVER_MAGIC))
1797 #define SMB_LISTENER_MAGIC 0x4C53544E /* 'LSTN' */
1798 #define SMB_LISTENER_VALID(ld) \
1799 ASSERT(((ld) != NULL) && ((ld)->ld_magic == SMB_LISTENER_MAGIC))
1803 struct smb_server
*ld_sv
;
1804 smb_thread_t ld_thread
;
1808 struct sockaddr_in ld_sin
;
1809 struct sockaddr_in6 ld_sin6
;
1810 smb_llist_t ld_session_list
;
1811 } smb_listener_daemon_t
;
1813 #define SMB_SSETUP_CMD "authentication"
1814 #define SMB_TCON_CMD "share mapping"
1815 #define SMB_OPIPE_CMD "pipe open"
1816 #define SMB_THRESHOLD_REPORT_THROTTLE 50
1817 typedef struct smb_cmd_threshold
{
1820 volatile uint32_t ct_active_cnt
;
1821 volatile uint32_t ct_blocked_cnt
;
1822 volatile uint32_t ct_error_cnt
;
1823 uint32_t ct_threshold
;
1824 struct smb_event
*ct_event
;
1825 uint32_t ct_event_id
;
1826 } smb_cmd_threshold_t
;
1829 kstat_named_t ls_files
;
1830 kstat_named_t ls_trees
;
1831 kstat_named_t ls_users
;
1832 } smb_server_legacy_kstat_t
;
1834 typedef enum smb_server_state
{
1835 SMB_SERVER_STATE_CREATED
= 0,
1836 SMB_SERVER_STATE_CONFIGURED
,
1837 SMB_SERVER_STATE_RUNNING
,
1838 SMB_SERVER_STATE_STOPPING
,
1839 SMB_SERVER_STATE_DELETING
,
1840 SMB_SERVER_STATE_SENTINEL
1841 } smb_server_state_t
;
1844 /* protected by sv_mutex */
1847 smb_llist_t sp_list
;
1848 smb_llist_t sp_fidlist
;
1851 #define SMB_SERVER_STATE_VALID(S) \
1852 ASSERT(((S) == SMB_SERVER_STATE_CREATED) || \
1853 ((S) == SMB_SERVER_STATE_CONFIGURED) || \
1854 ((S) == SMB_SERVER_STATE_RUNNING) || \
1855 ((S) == SMB_SERVER_STATE_STOPPING) || \
1856 ((S) == SMB_SERVER_STATE_DELETING))
1858 typedef struct smb_server
{
1863 smb_server_state_t sv_state
;
1867 smb_listener_daemon_t sv_nbt_daemon
;
1868 smb_listener_daemon_t sv_tcp_daemon
;
1869 krwlock_t sv_cfg_lock
;
1870 smb_kmod_cfg_t sv_cfg
;
1871 smb_session_t
*sv_session
;
1873 door_handle_t sv_lmshrd
;
1877 smb_thread_t si_thread_timers
;
1879 taskq_t
*sv_worker_pool
;
1880 taskq_t
*sv_receiver_pool
;
1882 kmem_cache_t
*si_cache_request
;
1883 kmem_cache_t
*si_cache_session
;
1884 kmem_cache_t
*si_cache_user
;
1885 kmem_cache_t
*si_cache_tree
;
1886 kmem_cache_t
*si_cache_ofile
;
1887 kmem_cache_t
*si_cache_odir
;
1888 kmem_cache_t
*si_cache_opipe
;
1889 kmem_cache_t
*si_cache_event
;
1891 smb_node_t
*si_root_smb_node
;
1892 smb_llist_t sv_opipe_list
;
1893 smb_llist_t sv_event_list
;
1896 hrtime_t sv_start_time
;
1898 volatile uint32_t sv_nbt_sess
;
1899 volatile uint32_t sv_tcp_sess
;
1900 volatile uint32_t sv_users
;
1901 volatile uint32_t sv_trees
;
1902 volatile uint32_t sv_files
;
1903 volatile uint32_t sv_pipes
;
1904 volatile uint64_t sv_txb
;
1905 volatile uint64_t sv_rxb
;
1906 volatile uint64_t sv_nreq
;
1907 smb_srqueue_t sv_srqueue
;
1908 smb_spool_t sp_info
;
1909 smb_cmd_threshold_t sv_ssetup_ct
;
1910 smb_cmd_threshold_t sv_tcon_ct
;
1911 smb_cmd_threshold_t sv_opipe_ct
;
1912 kstat_t
*sv_legacy_ksp
;
1913 kmutex_t sv_legacy_ksmtx
;
1916 #define SMB_EVENT_MAGIC 0x45564E54 /* EVNT */
1917 #define SMB_EVENT_TIMEOUT 45 /* seconds */
1918 #define SMB_EVENT_VALID(e) \
1919 ASSERT(((e) != NULL) && ((e)->se_magic == SMB_EVENT_MAGIC))
1920 typedef struct smb_event
{
1925 smb_server_t
*se_server
;
1927 boolean_t se_notified
;
1933 typedef struct smb_kspooldoc
{
1936 smb_inaddr_t sd_ipaddr
;
1937 uint32_t sd_spool_num
;
1939 char sd_username
[MAXNAMELEN
];
1940 char sd_path
[MAXPATHLEN
];
1943 typedef struct smb_spoolfid
{
1949 #define SMB_INFO_NETBIOS_SESSION_SVC_RUNNING 0x0001
1950 #define SMB_INFO_NETBIOS_SESSION_SVC_FAILED 0x0002
1951 #define SMB_INFO_USER_LEVEL_SECURITY 0x40000000
1952 #define SMB_INFO_ENCRYPT_PASSWORDS 0x80000000
1954 #define SMB_NEW_KID() atomic_inc_64_nv(&smb_kids)
1955 #define SMB_UNIQ_FID() atomic_inc_32_nv(&smb_fids)
1957 #define SMB_IS_STREAM(node) ((node)->n_unode)
1959 typedef struct smb_tsd
{
1965 typedef struct smb_disp_entry
{
1966 char sdt_name
[KSTAT_STRLEN
];
1967 smb_sdrc_t (*sdt_pre_op
)(smb_request_t
*);
1968 smb_sdrc_t (*sdt_function
)(smb_request_t
*);
1969 void (*sdt_post_op
)(smb_request_t
*);
1973 volatile uint64_t sdt_txb
;
1974 volatile uint64_t sdt_rxb
;
1975 smb_latency_t sdt_lat
;
1978 typedef struct smb_xlate
{
1983 typedef struct smb_export
{
1986 smb_llist_t e_vfs_list
;
1987 smb_avl_t e_share_avl
;
1988 smb_slist_t e_unexport_list
;
1990 kmem_cache_t
*e_cache_share
;
1991 kmem_cache_t
*e_cache_vfs
;
1992 kmem_cache_t
*e_cache_unexport
;
1994 smb_thread_t e_unexport_thread
;
1998 * This structure is a helper for building RAP NetShareEnum response
2000 * es_posix_uid UID of the user requesting the shares list which
2001 * is used to detect if the user has any autohome
2002 * es_bufsize size of the response buffer
2003 * es_buf pointer to the response buffer
2004 * es_ntotal total number of shares exported by server which
2005 * their OEM names is less then 13 chars
2006 * es_nsent number of shares that can fit in the specified buffer
2007 * es_datasize actual data size (share's data) which was encoded
2008 * in the response buffer
2010 typedef struct smb_enumshare_info
{
2012 uint16_t es_bufsize
;
2016 uint16_t es_datasize
;
2017 } smb_enumshare_info_t
;
2023 #endif /* _SMBSRV_SMB_KTYPES_H */