2 * Copyright (c) 2000-2001 Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $Id: smb_conn.h,v 1.32.42.1 2005/05/27 02:35:29 lindak Exp $
36 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
37 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
38 * Use is subject to license terms.
44 #include <sys/dditypes.h>
45 #include <sys/t_lock.h>
46 #include <sys/queue.h> /* for SLIST below */
49 #include <netsmb/smb_dev.h>
52 * Credentials of user/process for processing in the connection procedures
54 typedef struct smb_cred
{
55 struct cred
*scr_cred
;
61 #define SMBO_GONE 0x1000000
64 * Bits in vc_flags (a.k.a. vc_co.co_flags)
65 * Many of these were duplicates of SMBVOPT_ flags
66 * and we now keep those too instead of merging
70 #define SMBV_WIN95 0x0010 /* used to apply bugfixes for this OS */
71 #define SMBV_NT4 0x0020 /* used when NT4 issues invalid resp */
72 #define SMBV_UNICODE 0x0040 /* conn configured to use Unicode */
75 * Note: the common "obj" level uses this GONE flag by
76 * the name SMBO_GONE. Keep this alias as a reminder.
78 #define SMBV_GONE SMBO_GONE
81 * bits in smb_share ss_flags (a.k.a. ss_co.co_flags)
83 #define SMBS_RECONNECTING 0x0002
84 #define SMBS_CONNECTED 0x0004
85 #define SMBS_TCON_WAIT 0x0008
86 #define SMBS_FST_FAT 0x0010 /* share FS Type is FAT */
88 * Note: the common "obj" level uses this GONE flag by
89 * the name SMBO_GONE. Keep this alias as a reminder.
91 #define SMBS_GONE SMBO_GONE
94 /* This declares struct smb_rqhead */
95 TAILQ_HEAD(smb_rqhead
, smb_rq
);
98 #define SMB_DEFRQTIMO 30 /* 30 for oplock revoke/writeback */
100 #define SMBSSNSETUPTIMO 60
101 #define SMBNOREPLYWAIT (0)
103 #define SMB_DIALECT(vcp) ((vcp)->vc_sopt.sv_proto)
109 #define SMB_CO_LOCK(cp) mutex_enter(&(cp)->co_lock)
110 #define SMB_CO_UNLOCK(cp) mutex_exit(&(cp)->co_lock)
113 * Common part of smb_vc, smb_share
114 * Locking: co_lock protects most
115 * fields in this struct, except
120 int co_level
; /* SMBL_ */
124 /* Note: must lock co_parent before child. */
125 struct smb_connobj
*co_parent
;
127 /* this.co_lock protects the co_children list */
128 SLIST_HEAD(, smb_connobj
) co_children
;
131 * Linkage in parent's list of children.
132 * Must hold parent.co_lock to traverse.
134 SLIST_ENTRY(smb_connobj
) co_next
;
136 /* These two are set only at creation. */
137 void (*co_gone
)(struct smb_connobj
*);
138 void (*co_free
)(struct smb_connobj
*);
140 typedef struct smb_connobj smb_connobj_t
;
143 * "Level" in the connection object hierarchy
150 * Virtual Circuit to a server (really connection + session).
151 * Yes, calling this a "Virtual Circuit" is confusining,
152 * because it has nothing to do with the SMB notion of a
155 typedef struct smb_vc
{
156 struct smb_connobj vc_co
; /* keep first! See CPTOVC */
157 enum smbiod_state vc_state
;
158 kcondvar_t vc_statechg
;
161 uid_t vc_owner
; /* Unix owner */
162 int vc_genid
; /* "generation" ID */
164 int vc_mackeylen
; /* length of MAC key */
165 uint8_t *vc_mackey
; /* MAC key */
168 struct smb_tran_desc
*vc_tdesc
; /* transport ops. vector */
169 void *vc_tdata
; /* transport control block */
171 kcondvar_t iod_idle
; /* IOD thread idle CV */
172 krwlock_t iod_rqlock
; /* iod_rqlist */
173 struct smb_rqhead iod_rqlist
; /* list of outstanding reqs */
174 struct _kthread
*iod_thr
; /* the IOD (reader) thread */
175 int iod_flags
; /* see SMBIOD_* below */
176 int iod_newrq
; /* send needed (iod_rqlock) */
177 int iod_muxfull
; /* maxmux limit reached */
179 /* This is copied in/out when IOD enters/returns */
180 smbioc_ssn_work_t vc_work
;
182 /* session identity, etc. */
183 smbioc_ossn_t vc_ssn
;
186 #define vc_lock vc_co.co_lock
187 #define vc_flags vc_co.co_flags
189 /* defines for members in vc_ssn */
190 #define vc_owner vc_ssn.ssn_owner
191 #define vc_srvname vc_ssn.ssn_srvname
192 #define vc_srvaddr vc_ssn.ssn_id.id_srvaddr
193 #define vc_domain vc_ssn.ssn_id.id_domain
194 #define vc_username vc_ssn.ssn_id.id_user
195 #define vc_vopt vc_ssn.ssn_vopt
197 /* defines for members in vc_work */
198 #define vc_sopt vc_work.wk_sopt
199 #define vc_maxmux vc_work.wk_sopt.sv_maxmux
200 #define vc_tran_fd vc_work.wk_iods.is_tran_fd
201 #define vc_hflags vc_work.wk_iods.is_hflags
202 #define vc_hflags2 vc_work.wk_iods.is_hflags2
203 #define vc_smbuid vc_work.wk_iods.is_smbuid
204 #define vc_next_mid vc_work.wk_iods.is_next_mid
205 #define vc_txmax vc_work.wk_iods.is_txmax
206 #define vc_rwmax vc_work.wk_iods.is_rwmax
207 #define vc_rxmax vc_work.wk_iods.is_rxmax
208 #define vc_wxmax vc_work.wk_iods.is_wxmax
209 #define vc_ssn_key vc_work.wk_iods.is_ssn_key
210 #define vc_next_seq vc_work.wk_iods.is_next_seq
211 #define vc_u_mackey vc_work.wk_iods.is_u_mackey
212 #define vc_u_maclen vc_work.wk_iods.is_u_maclen
214 #define SMB_VC_LOCK(vcp) mutex_enter(&(vcp)->vc_lock)
215 #define SMB_VC_UNLOCK(vcp) mutex_exit(&(vcp)->vc_lock)
217 #define SMB_UNICODE_STRINGS(vcp) ((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE)
219 /* Bits in iod_flags */
220 #define SMBIOD_RUNNING 0x0001
221 #define SMBIOD_SHUTDOWN 0x0002
224 * smb_share structure describes connection to the given SMB share (tree).
225 * Connection to share is always built on top of the VC.
228 typedef struct smb_share
{
229 struct smb_connobj ss_co
; /* keep first! See CPTOSS */
230 kcondvar_t ss_conn_done
; /* wait for reconnect */
232 int ss_vcgenid
; /* check VC generation ID */
233 uint16_t ss_tid
; /* TID */
234 uint16_t ss_options
; /* option support bits */
235 smbioc_oshare_t ss_ioc
;
238 #define ss_lock ss_co.co_lock
239 #define ss_flags ss_co.co_flags
241 #define ss_use ss_ioc.sh_use
242 #define ss_type ss_ioc.sh_type
243 #define ss_name ss_ioc.sh_name
244 #define ss_pass ss_ioc.sh_pass
246 #define SMB_SS_LOCK(ssp) mutex_enter(&(ssp)->ss_lock)
247 #define SMB_SS_UNLOCK(ssp) mutex_exit(&(ssp)->ss_lock)
249 #define CPTOVC(cp) ((struct smb_vc *)((void *)(cp)))
250 #define VCTOCP(vcp) (&(vcp)->vc_co)
252 #define CPTOSS(cp) ((struct smb_share *)((void *)(cp)))
253 #define SSTOVC(ssp) CPTOVC(((ssp)->ss_co.co_parent))
254 #define SSTOCP(ssp) (&(ssp)->ss_co)
257 * Call-back operations vector, so the netsmb module
258 * can notify smbfs about events affecting mounts.
259 * Installed in netsmb after smbfs loads.
261 typedef struct smb_fscb
{
262 /* Called when the VC has disconnected. */
263 void (*fscb_disconn
)(smb_share_t
*);
264 /* Called when the VC has reconnected. */
265 void (*fscb_connect
)(smb_share_t
*);
266 /* Called when the server becomes unresponsive. */
267 void (*fscb_down
)(smb_share_t
*);
268 /* Called when the server is responding again. */
269 void (*fscb_up
)(smb_share_t
*);
271 /* Install the above vector, or pass NULL to clear it. */
272 void smb_fscb_set(smb_fscb_t
*);
275 * The driver per open instance object.
276 * Mostly used in: smb_dev.c, smb_usr.c
278 typedef struct smb_dev
{
280 struct smb_vc
*sd_vc
; /* Reference to VC */
281 struct smb_share
*sd_share
; /* Reference to share if any */
282 int sd_level
; /* SMBL_VC, ... */
283 int sd_vcgenid
; /* Generation of share or VC */
284 int sd_poll
; /* Future use */
285 int sd_flags
; /* State of connection */
286 #define NSMBFL_OPEN 0x0001
287 #define NSMBFL_IOD 0x0002
288 #define NSMBFL_IOCTL 0x0004
289 int sd_smbfid
; /* library read/write */
290 zoneid_t zoneid
; /* Zone id */
293 extern const uint32_t nsmb_version
;
298 int smb_dev2share(int fd
, struct smb_share
**sspp
);
304 int smb_usr_get_flags2(smb_dev_t
*sdp
, intptr_t arg
, int flags
);
305 int smb_usr_get_ssnkey(smb_dev_t
*sdp
, intptr_t arg
, int flags
);
306 int smb_usr_dup_dev(smb_dev_t
*sdp
, intptr_t arg
, int flags
);
308 int smb_usr_simplerq(smb_dev_t
*sdp
, intptr_t arg
, int flags
, cred_t
*cr
);
309 int smb_usr_t2request(smb_dev_t
*sdp
, intptr_t arg
, int flags
, cred_t
*cr
);
311 int smb_usr_closefh(smb_dev_t
*, cred_t
*);
312 int smb_usr_rw(smb_dev_t
*sdp
, int cmd
, intptr_t arg
, int flags
, cred_t
*cr
);
313 int smb_usr_ntcreate(smb_dev_t
*, intptr_t, int, cred_t
*);
314 int smb_usr_printjob(smb_dev_t
*, intptr_t, int, cred_t
*);
316 int smb_usr_get_ssn(smb_dev_t
*, int, intptr_t, int, cred_t
*);
317 int smb_usr_drop_ssn(smb_dev_t
*sdp
, int cmd
);
319 int smb_usr_get_tree(smb_dev_t
*, int, intptr_t, int, cred_t
*);
320 int smb_usr_drop_tree(smb_dev_t
*sdp
, int cmd
);
322 int smb_usr_iod_work(smb_dev_t
*sdp
, intptr_t arg
, int flags
, cred_t
*cr
);
323 int smb_usr_iod_ioctl(smb_dev_t
*sdp
, int cmd
, intptr_t arg
, int flags
);
329 int smb_iod_create(smb_vc_t
*vcp
);
330 int smb_iod_destroy(smb_vc_t
*vcp
);
331 int smb_iod_connect(smb_vc_t
*vcp
);
332 void smb_iod_disconnect(smb_vc_t
*vcp
);
333 int smb_iod_addrq(struct smb_rq
*rqp
);
334 int smb_iod_multirq(struct smb_rq
*rqp
);
335 int smb_iod_waitrq(struct smb_rq
*rqp
);
336 void smb_iod_removerq(struct smb_rq
*rqp
);
337 void smb_iod_shutdown_share(smb_share_t
*ssp
);
339 void smb_iod_sendall(smb_vc_t
*);
340 int smb_iod_recvall(smb_vc_t
*);
342 int smb_iod_vc_work(smb_vc_t
*, cred_t
*);
343 int smb_iod_vc_idle(smb_vc_t
*);
344 int smb_iod_vc_rcfail(smb_vc_t
*);
345 int smb_iod_reconnect(smb_vc_t
*);
348 * Session level functions
350 int smb_sm_init(void);
351 int smb_sm_idle(void);
352 void smb_sm_done(void);
357 void smb_vc_hold(smb_vc_t
*vcp
);
358 void smb_vc_rele(smb_vc_t
*vcp
);
359 void smb_vc_kill(smb_vc_t
*vcp
);
361 int smb_vc_findcreate(smbioc_ossn_t
*, smb_cred_t
*, smb_vc_t
**);
362 int smb_vc_create(smbioc_ossn_t
*ossn
, smb_cred_t
*scred
, smb_vc_t
**vcpp
);
364 const char *smb_vc_getpass(smb_vc_t
*vcp
);
365 uint16_t smb_vc_nextmid(smb_vc_t
*vcp
);
366 void *smb_vc_getipaddr(smb_vc_t
*vcp
, int *ipvers
);
368 typedef void (*walk_share_func_t
)(smb_share_t
*);
369 void smb_vc_walkshares(struct smb_vc
*, walk_share_func_t
);
372 * share level functions
375 int smb_share_findcreate(smbioc_tcon_t
*, smb_vc_t
*,
376 smb_share_t
**, smb_cred_t
*);
378 void smb_share_hold(smb_share_t
*ssp
);
379 void smb_share_rele(smb_share_t
*ssp
);
380 void smb_share_kill(smb_share_t
*ssp
);
382 void smb_share_invalidate(smb_share_t
*ssp
);
383 int smb_share_tcon(smb_share_t
*, smb_cred_t
*);
385 #endif /* _SMB_CONN_H */