3882 Remove xmod & friends
[illumos-gate.git] / usr / src / uts / common / smbsrv / smb_ktypes.h
blob53bceab332dc720f6ff4eb378d6fd442055e2656
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 #include <sys/note.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>
44 #include <sys/acl.h>
45 #include <sys/sdt.h>
46 #include <sys/stat.h>
47 #include <sys/vnode.h>
48 #include <sys/cred.h>
49 #include <netinet/in.h>
50 #include <sys/ksocket.h>
51 #include <sys/fem.h>
52 #include <sys/door.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;
64 struct smb_request;
65 struct smb_server;
66 struct smb_event;
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
77 * queue_length > 0.)
79 * ^
80 * | _________
81 * 8 | i4 |
82 * | | |
83 * Queue 6 | |
84 * Length | _________ | |
85 * 4 | i2 |_______| |
86 * | | i3 |
87 * 2_______| |
88 * | i1 |
89 * |_______________________________|
90 * Time-> t1 t2 t3 t4
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
113 * these functions:
115 * smb_srqueue_init()
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 {
125 kmutex_t srq_mutex;
126 hrtime_t srq_wlastupdate;
127 hrtime_t srq_wtime;
128 hrtime_t srq_wlentime;
129 hrtime_t srq_rlastupdate;
130 hrtime_t srq_rtime;
131 hrtime_t srq_rlentime;
132 uint32_t srq_wcnt;
133 uint32_t srq_rcnt;
134 } smb_srqueue_t;
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
140 * 'delta').
142 typedef struct smb_latency {
143 kmutex_t ly_mutex;
144 uint64_t ly_a_nreq;
145 hrtime_t ly_a_sum;
146 hrtime_t ly_a_mean;
147 hrtime_t ly_a_stddev;
148 uint64_t ly_d_nreq;
149 hrtime_t ly_d_sum;
150 hrtime_t ly_d_mean;
151 hrtime_t ly_d_stddev;
152 } smb_latency_t;
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
163 * with Windows.
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)
177 typedef struct {
178 uint32_t anr_refcnt;
179 int anr_depth;
180 pc_t anr_stack[SMB_AUDIT_STACK_DEPTH];
181 } smb_audit_record_node_t;
183 typedef struct {
184 int anb_index;
185 int anb_max_index;
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 * --------------------
194 * T5 T0
195 * smb_thread_destroy() <-------+ +------- smb_thread_init()
196 * | |
197 * | v
198 * +-----------------------------+
199 * | SMB_THREAD_STATE_EXITED |<---+
200 * +-----------------------------+ |
201 * | T1 |
202 * v |
203 * +-----------------------------+ |
204 * | SMB_THREAD_STATE_STARTING | |
205 * +-----------------------------+ |
206 * | T2 | T4
207 * v |
208 * +-----------------------------+ |
209 * | SMB_THREAD_STATE_RUNNING | |
210 * +-----------------------------+ |
211 * | T3 |
212 * v |
213 * +-----------------------------+ |
214 * | SMB_THREAD_STATE_EXITING |----+
215 * +-----------------------------+
217 * Transition T0
219 * This transition is executed in smb_thread_init().
221 * Transition T1
223 * This transition is executed in smb_thread_start().
225 * Transition T2
227 * This transition is executed by the thread itself when it starts running.
229 * Transition T3
231 * This transition is executed by the thread itself in
232 * smb_thread_entry_point() just before calling thread_exit().
235 * Transition T4
237 * This transition is executed in smb_thread_stop().
239 * Transition T5
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;
250 struct _smb_thread;
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 {
257 uint32_t sth_magic;
258 char sth_name[16];
259 smb_thread_state_t sth_state;
260 kthread_t *sth_th;
261 kt_did_t sth_did;
262 smb_thread_ep_t sth_ep;
263 void *sth_ep_arg;
264 boolean_t sth_kill;
265 kmutex_t sth_mtx;
266 kcondvar_t sth_cv;
267 } smb_thread_t;
270 * Pool of IDs
271 * -----------
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 {
290 uint32_t id_magic;
291 kmutex_t id_mutex;
292 uint8_t *id_pool;
293 uint32_t id_size;
294 uint8_t id_bit;
295 uint8_t id_bit_idx;
296 uint32_t id_idx;
297 uint32_t id_idx_msk;
298 uint32_t id_free_counter;
299 uint32_t id_max_free_counter;
300 } smb_idpool_t;
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.
307 * 32 --> SMB 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
312 * -----
313 * 66084
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' */
319 typedef struct {
320 uint32_t tr_magic;
321 list_node_t tr_lnd;
322 int tr_len;
323 uint8_t tr_buf[SMB_XPRT_MAX_SIZE];
324 } smb_txreq_t;
326 #define SMB_TXLST_MAGIC 0X544C5354 /* 'TLST' */
327 typedef struct {
328 uint32_t tl_magic;
329 kmutex_t tl_mutex;
330 boolean_t tl_active;
331 list_t tl_list;
332 } smb_txlst_t;
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
338 * used.
340 * Note: NBT_MAXBUF will be subtracted from the specified max buffer size to
341 * account for the NBT header.
343 #define NBT_MAXBUF 8
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 {
366 uint32_t dt_magic;
367 list_node_t dt_lnd;
368 void *dt_object;
369 smb_dtorproc_t dt_proc;
370 } smb_dtor_t;
372 typedef struct smb_llist {
373 krwlock_t ll_lock;
374 list_t ll_list;
375 uint32_t ll_count;
376 uint64_t ll_wrop;
377 kmutex_t ll_mutex;
378 list_t ll_deleteq;
379 uint32_t ll_deleteq_count;
380 boolean_t ll_flushing;
381 } smb_llist_t;
383 typedef struct smb_slist {
384 kmutex_t sl_mutex;
385 kcondvar_t sl_cv;
386 list_t sl_list;
387 uint32_t sl_count;
388 boolean_t sl_waiting;
389 } smb_slist_t;
392 * smb_avl_t State Machine
393 * --------------------
395 * +-----------------------------+
396 * | SMB_AVL_STATE_START |
397 * +-----------------------------+
398 * | T0
400 * +-----------------------------+
401 * | SMB_AVL_STATE_READY |
402 * +-----------------------------+
403 * | T1
405 * +-----------------------------+
406 * | SMB_AVL_STATE_DESTROYING |
407 * +-----------------------------+
409 * Transition T0
411 * This transition is executed in smb_avl_create().
413 * Transition T1
415 * This transition is executed in smb_avl_destroy().
418 typedef enum {
419 SMB_AVL_STATE_START = 0,
420 SMB_AVL_STATE_READY,
421 SMB_AVL_STATE_DESTROYING
422 } smb_avl_state_t;
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 *);
429 } smb_avl_nops_t;
431 typedef struct smb_avl_cursor {
432 void *avlc_next;
433 uint32_t avlc_sequence;
434 } smb_avl_cursor_t;
436 typedef struct smb_avl {
437 krwlock_t avl_lock;
438 avl_tree_t avl_tree;
439 kmutex_t avl_mutex;
440 kcondvar_t avl_cv;
441 smb_avl_state_t avl_state;
442 uint32_t avl_refcnt;
443 uint32_t avl_sequence;
444 smb_avl_nops_t *avl_nops;
445 } smb_avl_t;
447 typedef struct {
448 kcondvar_t rwx_cv;
449 kmutex_t rwx_mutex;
450 krwlock_t rwx_lock;
451 boolean_t rwx_waiting;
452 } smb_rwx_t;
454 /* NOTIFY CHANGE */
455 typedef struct smb_node_fcn {
456 kmutex_t fcn_mutex;
457 uint32_t fcn_count;
458 list_t fcn_watchers; /* smb_request_t, sr_ncr.nc_lnd */
459 } smb_node_fcn_t;
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 */
464 uint32_t nc_flags;
465 uint32_t nc_action;
466 char *nc_fname;
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
472 * or SMB-over-TCP.
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
491 * | TYPE | LENGTH |
492 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
494 * 8-bit type Must be 0
495 * 24-bit length
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.
501 typedef struct {
502 uint8_t xh_type;
503 uint32_t xh_length;
504 } smb_xprt_t;
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,
515 int OFF, int LEN);
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
539 * not be changed
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 {
547 kmutex_t ol_mutex;
548 kcondvar_t ol_cv;
549 kthread_t *ol_xthread;
550 boolean_t ol_fem; /* fem monitor installed? */
551 uint8_t ol_break;
552 uint32_t ol_count; /* number of grants */
553 list_t ol_grants; /* list of smb_oplock_grant_t */
554 } smb_oplock_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 {
562 uint32_t og_magic;
563 list_node_t og_lnd;
564 uint8_t og_level;
565 uint16_t og_fid;
566 uint16_t og_tid;
567 uint16_t og_uid;
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 {
576 uint32_t ob_magic;
577 list_node_t ob_lnd;
578 struct smb_node *ob_node;
579 } smb_oplock_break_t;
582 #define SMB_VFS_MAGIC 0x534D4256 /* 'SMBV' */
584 typedef struct smb_vfs {
585 uint32_t sv_magic;
586 list_node_t sv_lnd;
587 uint32_t sv_refcnt;
588 vfs_t *sv_vfsp;
589 vnode_t *sv_rootvp;
590 } smb_vfs_t;
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;
606 boolean_t t_cached;
607 timestruc_t t_atime;
608 timestruc_t t_mtime;
609 timestruc_t t_ctime;
610 timestruc_t t_crtime;
611 } smb_times_t;
613 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */
614 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC)
616 typedef enum {
617 SMB_NODE_STATE_AVAILABLE = 0,
618 SMB_NODE_STATE_DESTROYING
619 } smb_node_state_t;
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 {
630 uint32_t n_magic;
631 krwlock_t n_lock;
632 kmutex_t n_mutex;
633 list_node_t n_lnd;
634 smb_node_state_t n_state;
635 uint32_t n_refcnt;
636 uint32_t n_hashkey;
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;
643 volatile int flags;
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];
654 vnode_t *vp;
655 smb_audit_buf_node_t *n_audit_buf;
656 } smb_node_t;
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 {
676 uint32_t shr_magic;
677 char *shr_name;
678 char *shr_path;
679 char *shr_cmnt;
680 char *shr_container;
681 char *shr_oemname;
682 uint32_t shr_flags;
683 uint32_t shr_type;
684 uint32_t shr_refcnt;
685 uint32_t shr_autocnt;
686 uid_t shr_uid;
687 gid_t shr_gid;
688 char *shr_access_none;
689 char *shr_access_ro;
690 char *shr_access_rw;
691 avl_node_t shr_link;
692 kmem_cache_t *shr_cache;
693 kmutex_t shr_mutex;
694 } smb_kshare_t;
697 typedef struct smb_arg_negotiate {
698 char *ni_name;
699 int ni_dialect;
700 int ni_index;
701 uint32_t ni_capabilities;
702 uint16_t ni_maxmpxcount;
703 int16_t ni_tzcorrection;
704 uint8_t ni_keylen;
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 {
710 char *ssi_user;
711 char *ssi_domain;
712 uint16_t ssi_cipwlen;
713 uint8_t *ssi_cipwd;
714 uint16_t ssi_cspwlen;
715 uint8_t *ssi_cspwd;
716 uint16_t ssi_maxmpxcount;
717 uint32_t ssi_capabilities;
718 uint32_t ssi_sesskey;
719 boolean_t ssi_guest;
720 } smb_arg_sessionsetup_t;
722 typedef struct tcon {
723 char *path;
724 char *service;
725 int pwdlen;
726 char *password;
727 uint16_t flags;
728 uint16_t optional_support;
729 smb_kshare_t *si;
730 } smb_arg_tcon_t;
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
743 * closed.
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
772 struct smb_sign {
773 unsigned int seqnum;
774 unsigned int mackey_len;
775 unsigned int flags;
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 * +-----------------------------+ +------------------------------+
789 * T0| ^
790 * +--------------------+ |T13
791 * v |T14 |
792 * +-------------------------------+ | +--------------------------------+
793 * | SMB_SESSION_STATE_ESTABLISHED |---+--->| SMB_SESSION_STATE_DISCONNECTED |
794 * +-------------------------------+ +--------------------------------+
795 * T1| ^ ^ ^ ^
796 * +----------+ |T9 | | |
797 * v | | | |
798 * +------------------------------+ | | |
799 * | SMB_SESSION_STATE_NEGOTIATED | | | |
800 * +------------------------------+ | | |
801 * ^| ^| | ^ | | |
802 * +----------------+| || | | | | |
803 * |+----------------+ || T7| |T8 | | |
804 * || || | | | | |
805 * || +----------------+| | | | | |
806 * || |+----------------+ | | | | |
807 * || || v | | | |
808 * || || +-----------------------------------+ T10| | |
809 * || || | SMB_SESSION_STATE_OPLOCK_BREAKING |----+ | |
810 * || || +-----------------------------------+ | |
811 * || ||T5 | |
812 * || |+-->+-----------------------------------+ T11| |
813 * || |T6 | SMB_SESSION_STATE_READ_RAW_ACTIVE |------+ |
814 * || +----+-----------------------------------+ |
815 * ||T3 |
816 * |+------->+------------------------------------+ T12|
817 * |T4 | SMB_SESSION_STATE_WRITE_RAW_ACTIVE |-------+
818 * +---------+------------------------------------+
820 * Transition T0
824 * Transition T1
828 * Transition T2
832 * Transition T3
836 * Transition T4
840 * Transition T5
844 * Transition T6
848 * Transition T7
852 * Transition T8
856 * Transition T9
860 * Transition T10
864 * Transition T11
868 * Transition T12
872 * Transition T13
876 * Transition T14
881 #define SMB_SESSION_MAGIC 0x53455353 /* 'SESS' */
882 #define SMB_SESSION_VALID(p) \
883 ASSERT(((p) != NULL) && ((p)->s_magic == SMB_SESSION_MAGIC))
885 typedef enum {
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 {
899 uint32_t s_magic;
900 smb_rwx_t s_lock;
901 list_node_t s_lnd;
902 uint64_t s_kid;
903 smb_session_state_t s_state;
904 uint32_t s_flags;
905 int s_write_raw_status;
906 kthread_t *s_thread;
907 kt_did_t s_ktdid;
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;
912 int32_t s_gmtoff;
913 uint32_t keep_alive;
914 uint64_t opentime;
915 uint16_t vcnumber;
916 uint16_t s_local_port;
917 smb_inaddr_t ipaddr;
918 smb_inaddr_t local_ipaddr;
919 char workstation[SMB_PI_MAX_HOST];
920 int dialect;
921 int native_os;
922 int native_lm;
924 uint32_t capabilities;
925 struct smb_sign signing;
927 ksocket_t sock;
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;
933 smb_txlst_t s_txlst;
935 volatile uint32_t s_tree_cnt;
936 volatile uint32_t s_file_cnt;
937 volatile uint32_t s_dir_cnt;
939 uint16_t secmode;
940 uint32_t sesskey;
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;
951 int outpipe_datalen;
952 int outpipe_cookie;
953 list_t s_oplock_brkreqs;
954 smb_srqueue_t *s_srqueue;
955 } smb_session_t;
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
976 typedef enum {
977 SMB_USER_STATE_LOGGED_IN = 0,
978 SMB_USER_STATE_LOGGING_OFF,
979 SMB_USER_STATE_LOGGED_OFF,
980 SMB_USER_STATE_SENTINEL
981 } smb_user_state_t;
983 typedef struct smb_user {
984 uint32_t u_magic;
985 list_node_t u_lnd;
986 kmutex_t u_mutex;
987 smb_user_state_t u_state;
989 struct smb_server *u_server;
990 smb_session_t *u_session;
991 uint16_t u_name_len;
992 char *u_name;
993 uint16_t u_domain_len;
994 char *u_domain;
995 time_t u_logon_time;
996 cred_t *u_cred;
997 cred_t *u_privcred;
999 smb_llist_t u_tree_list;
1000 smb_idpool_t u_tid_pool;
1002 uint32_t u_refcnt;
1003 uint32_t u_flags;
1004 uint32_t u_privileges;
1005 uint16_t u_uid;
1006 uint32_t u_audit_sid;
1007 } smb_user_t;
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
1037 typedef enum {
1038 SMB_TREE_STATE_CONNECTED = 0,
1039 SMB_TREE_STATE_DISCONNECTING,
1040 SMB_TREE_STATE_DISCONNECTED,
1041 SMB_TREE_STATE_SENTINEL
1042 } smb_tree_state_t;
1044 typedef struct smb_tree {
1045 uint32_t t_magic;
1046 kmutex_t t_mutex;
1047 list_node_t t_lnd;
1048 smb_tree_state_t t_state;
1050 struct smb_server *t_server;
1051 smb_session_t *t_session;
1052 smb_user_t *t_user;
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;
1061 uint32_t t_refcnt;
1062 uint32_t t_flags;
1063 int32_t t_res_type;
1064 uint16_t t_tid;
1065 uint16_t t_umask;
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;
1071 uint32_t t_access;
1072 uint32_t t_execflags;
1073 time_t t_connect_time;
1074 volatile uint32_t t_open_files;
1075 } smb_tree_t;
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 {
1157 uint32_t p_magic;
1158 list_node_t p_lnd;
1159 kmutex_t p_mutex;
1160 kcondvar_t p_cv;
1161 struct smb_server *p_server;
1162 struct smb_event *p_event;
1163 char *p_name;
1164 uint32_t p_busy;
1165 smb_doorhdr_t p_hdr;
1166 smb_netuserinfo_t p_user;
1167 uint8_t *p_doorbuf;
1168 uint8_t *p_data;
1169 } smb_opipe_t;
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))
1210 typedef enum {
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 {
1218 uint32_t f_magic;
1219 kmutex_t f_mutex;
1220 list_node_t f_lnd;
1221 list_node_t f_nnd;
1222 smb_ofile_state_t f_state;
1224 struct smb_server *f_server;
1225 smb_session_t *f_session;
1226 smb_user_t *f_user;
1227 smb_tree_t *f_tree;
1228 smb_node_t *f_node;
1229 smb_opipe_t *f_pipe;
1231 uint32_t f_uniqid;
1232 uint32_t f_refcnt;
1233 uint64_t f_seek_pos;
1234 uint32_t f_flags;
1235 uint32_t f_granted_access;
1236 uint32_t f_share_access;
1237 uint32_t f_create_options;
1238 uint16_t f_fid;
1239 uint16_t f_opened_by_pid;
1240 uint16_t f_ftype;
1241 uint64_t f_llf_pos;
1242 int f_mode;
1243 cred_t *f_cr;
1244 pid_t f_pid;
1245 uint32_t f_explicit_times;
1246 char f_quota_resume[SMB_SID_STRSZ];
1247 smb_oplock_grant_t f_oplock_grant;
1248 } smb_ofile_t;
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
1264 typedef enum {
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
1270 } smb_odir_state_t;
1272 typedef enum {
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;
1281 int or_idx;
1282 uint32_t or_cookie;
1283 char *or_fname;
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 {
1292 uint32_t d_magic;
1293 kmutex_t d_mutex;
1294 list_node_t d_lnd;
1295 smb_odir_state_t d_state;
1296 smb_session_t *d_session;
1297 smb_tree_t *d_tree;
1298 smb_node_t *d_dnode;
1299 cred_t *d_cred;
1300 uint16_t d_odid;
1301 uint16_t d_opened_by_pid;
1302 uint16_t d_sattr;
1303 uint32_t d_refcnt;
1304 uint32_t d_flags;
1305 boolean_t d_eof;
1306 int d_bufsize;
1307 uint64_t d_offset;
1308 union {
1309 char *u_bufptr;
1310 edirent_t *u_edp;
1311 dirent64_t *u_dp;
1312 } d_u;
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];
1318 } smb_odir_t;
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 */
1325 ino64_t od_ino;
1326 uint32_t od_eflags;
1327 } smb_odirent_t;
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 */
1341 } smb_fileinfo_t;
1343 typedef struct smb_streaminfo {
1344 uint64_t si_size;
1345 uint64_t si_alloc_size;
1346 char si_name[MAXPATHLEN];
1347 } smb_streaminfo_t;
1349 #define SMB_LOCK_MAGIC 0x4C4F434B /* 'LOCK' */
1351 typedef struct smb_lock {
1352 uint32_t l_magic;
1353 kmutex_t l_mutex;
1354 list_node_t l_lnd;
1355 kcondvar_t l_cv;
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;
1364 uint32_t l_flags;
1365 uint64_t l_session_kid;
1366 struct smb_lock *l_blocked_by; /* Debug info only */
1368 uint16_t l_pid;
1369 uint16_t l_uid;
1370 uint32_t l_type;
1371 uint64_t l_start;
1372 uint64_t l_length;
1373 clock_t l_end_time;
1374 } smb_lock_t;
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 {
1384 uint8_t vdb_tag;
1385 uint32_t vdb_len;
1386 struct uio vdb_uio;
1387 struct iovec vdb_iovec[MAX_IOVEC];
1388 } smb_vdb_t;
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 {
1396 uint32_t rw_magic;
1397 smb_vdb_t rw_vdb;
1398 uint64_t rw_offset;
1399 uint32_t rw_last_write;
1400 uint16_t rw_mode;
1401 uint32_t rw_count; /* bytes in this request */
1402 uint16_t rw_mincnt;
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 */
1406 } smb_rw_param_t;
1408 typedef struct smb_pathname {
1409 char *pn_path;
1410 char *pn_pname;
1411 char *pn_fname;
1412 char *pn_sname;
1413 char *pn_stype;
1414 } smb_pathname_t;
1417 * fs_query_info
1419 typedef struct smb_fqi {
1420 smb_pathname_t fq_path;
1421 uint16_t fq_sattr;
1422 smb_node_t *fq_dnode;
1423 smb_node_t *fq_fnode;
1424 smb_attr_t fq_fattr;
1425 char fq_last_comp[MAXNAMELEN];
1426 } smb_fqi_t;
1428 typedef struct dirop {
1429 smb_fqi_t fqi;
1430 smb_fqi_t dst_fqi;
1431 uint16_t info_level;
1432 uint16_t flags;
1433 } smb_arg_dirop_t;
1435 typedef struct {
1436 uint32_t status;
1437 uint16_t errcls;
1438 uint16_t errcode;
1439 } smb_error_t;
1441 typedef struct open_param {
1442 smb_fqi_t fqi;
1443 uint16_t omode;
1444 uint16_t ofun;
1445 uint32_t nt_flags;
1446 uint32_t timeo;
1447 uint32_t dattr;
1448 timestruc_t crtime;
1449 timestruc_t mtime;
1450 uint64_t dsize;
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;
1456 uint32_t ftype;
1457 uint32_t devstate;
1458 uint32_t action_taken;
1459 uint64_t fileid;
1460 uint32_t rootdirfid;
1461 smb_ofile_t *dir;
1462 /* This is only set by NTTransactCreate */
1463 struct smb_sd *sd;
1464 uint8_t op_oplock_level; /* requested/granted level */
1465 boolean_t op_oplock_levelII; /* TRUE if levelII supported */
1466 } smb_arg_open_t;
1469 * SMB Request State Machine
1470 * -------------------------
1472 * T4 +------+ T0
1473 * +--------------------------->| FREE |---------------------------+
1474 * | +------+ |
1475 * +-----------+ |
1476 * | COMPLETED | |
1477 * +-----------+
1478 * ^ |
1479 * | T15 +----------+ v
1480 * +------------+ T6 | | +--------------+
1481 * | CLEANED_UP |<-----------------| CANCELED | | INITIALIZING |
1482 * +------------+ | | +--------------+
1483 * | ^ +----------+ |
1484 * | | ^ ^ ^ ^ |
1485 * | | +-------------+ | | | |
1486 * | | T3 | | | | T13 | T1
1487 * | +-------------------------+ | | +----------------------+ |
1488 * +----------------------------+ | | | | |
1489 * T16 | | | | +-----------+ | |
1490 * | \/ | | T5 | | v
1491 * +-----------------+ | T12 +--------+ | T2 +-----------+
1492 * | EVENT_OCCURRED |------------->| ACTIVE |<--------------------| SUBMITTED |
1493 * +-----------------+ | +--------+ | +-----------+
1494 * ^ | | ^ | |
1495 * | | T8 | | | T7 |
1496 * | T10 T9 | +----------+ | +-------+ | T11
1497 * | | | +-------+ | |
1498 * | | | T14 | | |
1499 * | | v | v |
1500 * +----------------------+ +--------------+
1501 * | WAITING_EVENT | | WAITING_LOCK |
1502 * +----------------------+ +--------------+
1508 * Transition T0
1510 * This transition occurs when the request is allocated and is still under the
1511 * control of the session thread.
1513 * Transition T1
1515 * This transition occurs when the session thread dispatches a task to treat the
1516 * request.
1518 * Transition T2
1522 * Transition T3
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.
1531 * Transition T4
1535 * Transition T5
1539 * Transition T6
1543 * Transition T7
1547 * Transition T8
1551 * Transition T9
1555 * Transition T10
1559 * Transition T11
1563 * Transition T12
1567 * Transition T13
1571 * Transition T14
1575 * Transition T15
1577 * Request processing is completed (control returns from smb_dispatch)
1579 * Transition T16
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
1601 } smb_req_state_t;
1603 typedef struct smb_request {
1604 uint32_t sr_magic;
1605 kmutex_t sr_mutex;
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;
1610 pid_t *sr_pid;
1611 int32_t sr_gmtoff;
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;
1626 list_t sr_storage;
1627 struct smb_xa *r_xa;
1628 int andx_prev_wct;
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 */
1651 /* Parameters */
1652 struct mbuf_chain smb_vwv; /* variable width value */
1654 /* Data */
1655 struct mbuf_chain smb_data;
1657 uint16_t smb_fid; /* not in hdr, but common */
1659 unsigned char andx_com;
1660 uint16_t andx_off;
1662 struct smb_tree *tid_tree;
1663 struct smb_ofile *fid_ofile;
1664 smb_user_t *uid_user;
1666 union {
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;
1672 smb_rw_param_t *rw;
1673 uint32_t timestamp;
1674 } arg;
1676 cred_t *user_cr;
1677 kthread_t *sr_worker;
1678 hrtime_t sr_time_submitted;
1679 hrtime_t sr_time_active;
1680 hrtime_t sr_time_start;
1681 int32_t sr_txb;
1682 uint32_t sr_seqnum;
1683 } smb_request_t;
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 {
1726 uint32_t xa_magic;
1727 kmutex_t xa_mutex;
1728 list_node_t xa_lnd;
1730 uint32_t xa_refcnt;
1731 uint32_t xa_flags;
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 */
1760 char *xa_pipe_name;
1762 int req_disp_param;
1763 int req_disp_data;
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;
1772 } smb_xa_t;
1775 #define SDDF_NO_FLAGS 0
1776 #define SDDF_SUPPRESS_TID 0x0001
1777 #define SDDF_SUPPRESS_UID 0x0002
1780 * SMB dispatch return codes.
1782 typedef enum {
1783 SDRC_SUCCESS = 0,
1784 SDRC_ERROR,
1785 SDRC_DROP_VC,
1786 SDRC_NO_REPLY,
1787 SDRC_SR_KEPT,
1788 SDRC_NOT_IMPLEMENTED
1789 } smb_sdrc_t;
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))
1801 typedef struct {
1802 uint32_t ld_magic;
1803 struct smb_server *ld_sv;
1804 smb_thread_t ld_thread;
1805 ksocket_t ld_so;
1806 in_port_t ld_port;
1807 int ld_family;
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 {
1818 char *ct_cmd;
1819 kmutex_t ct_mutex;
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;
1828 typedef struct {
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;
1843 typedef struct {
1844 /* protected by sv_mutex */
1845 kcondvar_t sp_cv;
1846 uint32_t sp_cnt;
1847 smb_llist_t sp_list;
1848 smb_llist_t sp_fidlist;
1849 } smb_spool_t;
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 {
1859 uint32_t sv_magic;
1860 kcondvar_t sv_cv;
1861 kmutex_t sv_mutex;
1862 list_node_t sv_lnd;
1863 smb_server_state_t sv_state;
1864 uint32_t sv_refcnt;
1865 pid_t sv_pid;
1866 zoneid_t sv_zid;
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;
1875 int32_t si_gmtoff;
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;
1895 /* Statistics */
1896 hrtime_t sv_start_time;
1897 kstat_t *sv_ksp;
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;
1914 } smb_server_t;
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 {
1921 uint32_t se_magic;
1922 list_node_t se_lnd;
1923 kmutex_t se_mutex;
1924 kcondvar_t se_cv;
1925 smb_server_t *se_server;
1926 uint32_t se_txid;
1927 boolean_t se_notified;
1928 int se_waittime;
1929 int se_timeout;
1930 int se_errno;
1931 } smb_event_t;
1933 typedef struct smb_kspooldoc {
1934 uint32_t sd_magic;
1935 list_node_t sd_lnd;
1936 smb_inaddr_t sd_ipaddr;
1937 uint32_t sd_spool_num;
1938 uint16_t sd_fid;
1939 char sd_username[MAXNAMELEN];
1940 char sd_path[MAXPATHLEN];
1941 } smb_kspooldoc_t;
1943 typedef struct smb_spoolfid {
1944 uint32_t sf_magic;
1945 list_node_t sf_lnd;
1946 uint16_t sf_fid;
1947 } smb_spoolfid_t;
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 {
1960 void (*proc)();
1961 void *arg;
1962 char name[100];
1963 } smb_tsd_t;
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 *);
1970 uint8_t sdt_com;
1971 char sdt_dialect;
1972 uint8_t sdt_flags;
1973 volatile uint64_t sdt_txb;
1974 volatile uint64_t sdt_rxb;
1975 smb_latency_t sdt_lat;
1976 } smb_disp_entry_t;
1978 typedef struct smb_xlate {
1979 int code;
1980 char *str;
1981 } smb_xlate_t;
1983 typedef struct smb_export {
1984 kmutex_t e_mutex;
1985 boolean_t e_ready;
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;
1995 } smb_export_t;
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 {
2011 uid_t es_posix_uid;
2012 uint16_t es_bufsize;
2013 char *es_buf;
2014 uint16_t es_ntotal;
2015 uint16_t es_nsent;
2016 uint16_t es_datasize;
2017 } smb_enumshare_info_t;
2019 #ifdef __cplusplus
2021 #endif
2023 #endif /* _SMBSRV_SMB_KTYPES_H */