14bff34ethurlow/*
24bff34ethurlow * Copyright (c) 2000-2001 Boris Popov
34bff34ethurlow * All rights reserved.
44bff34ethurlow *
54bff34ethurlow * Redistribution and use in source and binary forms, with or without
64bff34ethurlow * modification, are permitted provided that the following conditions
74bff34ethurlow * are met:
84bff34ethurlow * 1. Redistributions of source code must retain the above copyright
94bff34ethurlow *    notice, this list of conditions and the following disclaimer.
104bff34ethurlow * 2. Redistributions in binary form must reproduce the above copyright
114bff34ethurlow *    notice, this list of conditions and the following disclaimer in the
124bff34ethurlow *    documentation and/or other materials provided with the distribution.
134bff34ethurlow * 3. All advertising materials mentioning features or use of this software
144bff34ethurlow *    must display the following acknowledgement:
154bff34ethurlow *    This product includes software developed by Boris Popov.
164bff34ethurlow * 4. Neither the name of the author nor the names of any co-contributors
174bff34ethurlow *    may be used to endorse or promote products derived from this software
184bff34ethurlow *    without specific prior written permission.
194bff34ethurlow *
204bff34ethurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
214bff34ethurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224bff34ethurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234bff34ethurlow * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
244bff34ethurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254bff34ethurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264bff34ethurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274bff34ethurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284bff34ethurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294bff34ethurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304bff34ethurlow * SUCH DAMAGE.
314bff34ethurlow *
324bff34ethurlow * $Id: smb_conn.h,v 1.32.42.1 2005/05/27 02:35:29 lindak Exp $
334bff34ethurlow */
344bff34ethurlow
354bff34ethurlow/*
36613a2f6Gordon Ross * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
374bff34ethurlow * Use is subject to license terms.
3840c0e23Gordon Ross *
39adee678Gordon Ross * Portions Copyright (C) 2001 - 2013 Apple Inc. All rights reserved.
4040c0e23Gordon Ross * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
414bff34ethurlow */
424bff34ethurlow
434bff34ethurlow#ifndef _SMB_CONN_H
444bff34ethurlow#define	_SMB_CONN_H
454bff34ethurlow
46613a2f6Gordon Ross#include <sys/dditypes.h>
474bff34ethurlow#include <sys/t_lock.h>
484bff34ethurlow#include <sys/queue.h> /* for SLIST below */
494bff34ethurlow#include <sys/uio.h>
504bff34ethurlow#include <netsmb/smb_dev.h>
51adee678Gordon Ross#include "smb_signing.h"
524bff34ethurlow
534bff34ethurlow/*
544bff34ethurlow * Credentials of user/process for processing in the connection procedures
554bff34ethurlow */
564bff34ethurlowtypedef struct smb_cred {
57613a2f6Gordon Ross	struct cred *scr_cred;
584bff34ethurlow} smb_cred_t;
594bff34ethurlow
604bff34ethurlow/*
614bff34ethurlow * Common object flags
624bff34ethurlow */
634bff34ethurlow#define	SMBO_GONE		0x1000000
644bff34ethurlow
654bff34ethurlow/*
664bff34ethurlow * Bits in vc_flags (a.k.a. vc_co.co_flags)
6740c0e23Gordon Ross * Note: SMBO_GONE is also in vc_flags
684bff34ethurlow */
699c9af25Gordon Ross#define	SMBV_UNICODE		0x0040	/* conn configured to use Unicode */
7040c0e23Gordon Ross#define	SMBV_EXT_SEC		0x0080	/* conn to use extended security */
71adee678Gordon Ross#define	SMBV_SIGNING		0x0100	/* negotiated signing */
72adee678Gordon Ross#define	SMBV_SMB2		0x0200	/* VC using SMB 2 or 3 */
73686670eGordon Ross#define	SMBV_HAS_FILEIDS	0x0400	/* Use File IDs for hash and inums */
74adee678Gordon Ross#define	SMBV_NO_WRITE_THRU	0x0800	/* Can't use ... */
754bff34ethurlow
764bff34ethurlow/*
774bff34ethurlow * Note: the common "obj" level uses this GONE flag by
784bff34ethurlow * the name SMBO_GONE.  Keep this alias as a reminder.
794bff34ethurlow */
80613a2f6Gordon Ross#define	SMBV_GONE		SMBO_GONE
814bff34ethurlow
824bff34ethurlow/*
834bff34ethurlow * bits in smb_share ss_flags (a.k.a. ss_co.co_flags)
844bff34ethurlow */
854bff34ethurlow#define	SMBS_RECONNECTING	0x0002
864bff34ethurlow#define	SMBS_CONNECTED		0x0004
874bff34ethurlow#define	SMBS_TCON_WAIT		0x0008
8802d09e0Gordon Ross#define	SMBS_FST_FAT		0x0010	/* share FS Type is FAT */
894bff34ethurlow/*
904bff34ethurlow * Note: the common "obj" level uses this GONE flag by
914bff34ethurlow * the name SMBO_GONE.  Keep this alias as a reminder.
924bff34ethurlow */
93613a2f6Gordon Ross#define	SMBS_GONE		SMBO_GONE
944bff34ethurlow
95adee678Gordon Ross/*
96adee678Gordon Ross * bits in smb_fh fh_flags (a.k.a. ss_co.co_flags)
97adee678Gordon Ross */
98adee678Gordon Ross#define	SMBFH_VALID		0x0002	/* FID is valid */
99adee678Gordon Ross/*
100adee678Gordon Ross * Note: the common "obj" level uses this GONE flag by
101adee678Gordon Ross * the name SMBO_GONE.  Keep this alias as a reminder.
102adee678Gordon Ross */
103adee678Gordon Ross#define	SMBFH_GONE		SMBO_GONE
104adee678Gordon Ross
1054bff34ethurlowstruct smb_rq;
1064bff34ethurlow/* This declares struct smb_rqhead */
1074bff34ethurlowTAILQ_HEAD(smb_rqhead, smb_rq);
1084bff34ethurlow
1094bff34ethurlow#define	SMB_NBTIMO	15
1104bff34ethurlow#define	SMB_DEFRQTIMO	30	/* 30 for oplock revoke/writeback */
1114bff34ethurlow#define	SMBWRTTIMO	60
1124bff34ethurlow#define	SMBSSNSETUPTIMO	60
1134bff34ethurlow#define	SMBNOREPLYWAIT (0)
1144bff34ethurlow
1154bff34ethurlow#define	SMB_DIALECT(vcp)	((vcp)->vc_sopt.sv_proto)
1164bff34ethurlow
1174bff34ethurlow/*
1184bff34ethurlow * Connection object
1194bff34ethurlow */
1204bff34ethurlow
1214bff34ethurlow#define	SMB_CO_LOCK(cp)		mutex_enter(&(cp)->co_lock)
1224bff34ethurlow#define	SMB_CO_UNLOCK(cp)	mutex_exit(&(cp)->co_lock)
1234bff34ethurlow
1244bff34ethurlow/*
1254bff34ethurlow * Common part of smb_vc, smb_share
1264bff34ethurlow * Locking: co_lock protects most
1274bff34ethurlow * fields in this struct, except
1284bff34ethurlow * as noted below:
1294bff34ethurlow */
1304bff34ethurlowstruct smb_connobj {
1314bff34ethurlow	kmutex_t		co_lock;
1324bff34ethurlow	int			co_level;	/* SMBL_ */
1334bff34ethurlow	int			co_flags;
1344bff34ethurlow	int			co_usecount;
1354bff34ethurlow
1364bff34ethurlow	/* Note: must lock co_parent before child. */
1374bff34ethurlow	struct smb_connobj	*co_parent;
1384bff34ethurlow
1394bff34ethurlow	/* this.co_lock protects the co_children list */
1404bff34ethurlow	SLIST_HEAD(, smb_connobj) co_children;
1414bff34ethurlow
1424bff34ethurlow	/*
1434bff34ethurlow	 * Linkage in parent's list of children.
1444bff34ethurlow	 * Must hold parent.co_lock to traverse.
1454bff34ethurlow	 */
1464bff34ethurlow	SLIST_ENTRY(smb_connobj) co_next;
1474bff34ethurlow
1484bff34ethurlow	/* These two are set only at creation. */
1494bff34ethurlow	void (*co_gone)(struct smb_connobj *);
1504bff34ethurlow	void (*co_free)(struct smb_connobj *);
1514bff34ethurlow};
1524bff34ethurlowtypedef struct smb_connobj smb_connobj_t;
1534bff34ethurlow
1544bff34ethurlow/*
155613a2f6Gordon Ross * "Level" in the connection object hierarchy
1564bff34ethurlow */
157adee678Gordon Rossenum smbco_level {
158adee678Gordon Ross	SMBL_SM = 0,
159adee678Gordon Ross	SMBL_VC = 1,
160adee678Gordon Ross	SMBL_SHARE = 2,
161adee678Gordon Ross	SMBL_FH = 3
162adee678Gordon Ross};
1634bff34ethurlow
164613a2f6Gordon Ross/*
16540c0e23Gordon Ross * SMB1 Negotiated protocol parameters
16640c0e23Gordon Ross */
16740c0e23Gordon Rossstruct smb_sopt {
168686670eGordon Ross	uint16_t	sv_proto;	/* protocol dialect */
16940c0e23Gordon Ross	uchar_t		sv_sm;		/* security mode */
17040c0e23Gordon Ross	int16_t		sv_tz;		/* offset in min relative to UTC */
17140c0e23Gordon Ross	uint16_t	sv_maxmux;	/* max number of outstanding rq's */
17240c0e23Gordon Ross	uint16_t	sv_maxvcs;	/* max number of VCs */
17340c0e23Gordon Ross	uint16_t	sv_rawmode;
17440c0e23Gordon Ross	uint32_t	sv_maxtx;	/* maximum transmit buf size */
17540c0e23Gordon Ross	uint32_t	sv_maxraw;	/* maximum raw-buffer size */
17640c0e23Gordon Ross	uint32_t	sv_skey;	/* session key */
17740c0e23Gordon Ross	uint32_t	sv_caps;	/* capabilites SMB_CAP_ */
178adee678Gordon Ross
179adee678Gordon Ross	/* SMB2+ fields */
180adee678Gordon Ross	uint32_t	sv2_sessflags;	/* final session setup reply flags */
181adee678Gordon Ross	uint32_t	sv2_capabilities;	/* capabilities */
182adee678Gordon Ross	uint32_t	sv2_maxtransact;	/* max transact size */
183adee678Gordon Ross	uint32_t	sv2_maxread;	/* max read size */
184adee678Gordon Ross	uint32_t	sv2_maxwrite;	/* max write size */
185adee678Gordon Ross	uint16_t	sv2_security_mode;	/* security mode */
186686670eGordon Ross	uint8_t		sv2_guid[16];	/* GUID */
18740c0e23Gordon Ross};
18840c0e23Gordon Rosstypedef struct smb_sopt smb_sopt_t;
18940c0e23Gordon Ross
19040c0e23Gordon Ross/*
19140c0e23Gordon Ross * SMB1 I/O Deamon state
19240c0e23Gordon Ross */
19340c0e23Gordon Rossstruct smb_iods {
19440c0e23Gordon Ross	uint8_t		is_hflags;	/* SMB header flags */
19540c0e23Gordon Ross	uint16_t	is_hflags2;	/* SMB header flags2 */
19640c0e23Gordon Ross	uint16_t	is_smbuid;	/* SMB header UID */
19740c0e23Gordon Ross	uint16_t	is_next_mid;	/* SMB header MID */
19840c0e23Gordon Ross	uint32_t	is_txmax;	/* max tx/rx packet size */
19940c0e23Gordon Ross	uint32_t	is_rwmax;	/* max read/write data size */
20040c0e23Gordon Ross	uint32_t	is_rxmax;	/* max readx data size */
20140c0e23Gordon Ross	uint32_t	is_wxmax;	/* max writex data size */
20240c0e23Gordon Ross	/* Signing state */
20340c0e23Gordon Ross	uint32_t	is_next_seq;	/* my next sequence number */
20440c0e23Gordon Ross
20540c0e23Gordon Ross};
20640c0e23Gordon Rosstypedef struct smb_iods smb_iods_t;
20740c0e23Gordon Ross
20840c0e23Gordon Ross/*
209613a2f6Gordon Ross * Virtual Circuit to a server (really connection + session).
210613a2f6Gordon Ross * Yes, calling this a "Virtual Circuit" is confusining,
211613a2f6Gordon Ross * because it has nothing to do with the SMB notion of a
212613a2f6Gordon Ross * "Virtual Circuit".
213613a2f6Gordon Ross */
2144bff34ethurlowtypedef struct smb_vc {
215613a2f6Gordon Ross	struct smb_connobj	vc_co;	/* keep first! See CPTOVC */
216613a2f6Gordon Ross	enum smbiod_state	vc_state;
217613a2f6Gordon Ross	kcondvar_t		vc_statechg;
2184bff34ethurlow
219613a2f6Gordon Ross	zoneid_t		vc_zoneid;
220613a2f6Gordon Ross	uid_t			vc_owner;	/* Unix owner */
221613a2f6Gordon Ross	int			vc_genid;	/* "generation" ID */
222613a2f6Gordon Ross
22340c0e23Gordon Ross	int			vc_mackeylen;	/* MAC key length */
22440c0e23Gordon Ross	int			vc_ssnkeylen;	/* session key length */
22540c0e23Gordon Ross	uint8_t			*vc_mackey;	/* MAC key buffer */
22640c0e23Gordon Ross	uint8_t			*vc_ssnkey;	/* session key buffer */
227adee678Gordon Ross	smb_sign_mech_t		vc_signmech;
228686670eGordon Ross	struct smb_mac_ops	*vc_sign_ops;
229613a2f6Gordon Ross
230613a2f6Gordon Ross	struct smb_tran_desc	*vc_tdesc;	/* transport ops. vector */
231613a2f6Gordon Ross	void			*vc_tdata;	/* transport control block */
232613a2f6Gordon Ross
233adee678Gordon Ross	/* SMB2+ fields */
234adee678Gordon Ross	uint64_t	vc2_oldest_message_id;
235adee678Gordon Ross	uint64_t	vc2_next_message_id;
236adee678Gordon Ross	uint64_t	vc2_limit_message_id;
237adee678Gordon Ross	uint64_t	vc2_session_id;		/* session id */
238adee678Gordon Ross	uint64_t	vc2_prev_session_id;	/* for reconnect */
239adee678Gordon Ross	uint32_t	vc2_lease_key;		/* lease key gen */
240adee678Gordon Ross
24140c0e23Gordon Ross	kcondvar_t		iod_idle;	/* IOD thread idle CV */
242613a2f6Gordon Ross	krwlock_t		iod_rqlock;	/* iod_rqlist */
243adee678Gordon Ross	struct smb_rqhead	iod_rqlist;	/* list of active reqs */
24440c0e23Gordon Ross	struct _kthread		*iod_thr;	/* the IOD (reader) thread */
2454bff34ethurlow	int			iod_flags;	/* see SMBIOD_* below */
246adee678Gordon Ross	uint_t			iod_muxcnt;	/* num. active requests */
247adee678Gordon Ross	uint_t			iod_muxwant;	/* waiting to be active */
248adee678Gordon Ross	kcondvar_t		iod_muxwait;
249adee678Gordon Ross	boolean_t		iod_noresp;	/* Logged "not responding" */
250613a2f6Gordon Ross
25140c0e23Gordon Ross	smb_iods_t		vc_iods;
25240c0e23Gordon Ross	smb_sopt_t		vc_sopt;
25340c0e23Gordon Ross
254613a2f6Gordon Ross	/* This is copied in/out when IOD enters/returns */
255613a2f6Gordon Ross	smbioc_ssn_work_t	vc_work;
256613a2f6Gordon Ross
257613a2f6Gordon Ross	/* session identity, etc. */
258613a2f6Gordon Ross	smbioc_ossn_t		vc_ssn;
2594bff34ethurlow} smb_vc_t;
2604bff34ethurlow
2614bff34ethurlow#define	vc_lock		vc_co.co_lock
2624bff34ethurlow#define	vc_flags	vc_co.co_flags
263613a2f6Gordon Ross
264613a2f6Gordon Ross/* defines for members in vc_ssn */
265613a2f6Gordon Ross#define	vc_owner	vc_ssn.ssn_owner
266adee678Gordon Ross#define	vc_vopt		vc_ssn.ssn_vopt
267adee678Gordon Ross#define	vc_minver	vc_ssn.ssn_minver
268adee678Gordon Ross#define	vc_maxver	vc_ssn.ssn_maxver
269613a2f6Gordon Ross#define	vc_srvname	vc_ssn.ssn_srvname
270613a2f6Gordon Ross#define	vc_srvaddr	vc_ssn.ssn_id.id_srvaddr
271613a2f6Gordon Ross#define	vc_domain	vc_ssn.ssn_id.id_domain
272613a2f6Gordon Ross#define	vc_username	vc_ssn.ssn_id.id_user
273613a2f6Gordon Ross
274613a2f6Gordon Ross/* defines for members in vc_work */
275adee678Gordon Ross#define	vc_cl_guid	vc_work.wk_cl_guid
27640c0e23Gordon Ross
27740c0e23Gordon Ross/* defines for members in vc_sopt ? */
27840c0e23Gordon Ross#define	vc_maxmux	vc_sopt.sv_maxmux
27940c0e23Gordon Ross
28040c0e23Gordon Ross/* defines for members in vc_iods */
28140c0e23Gordon Ross#define	vc_hflags	vc_iods.is_hflags
28240c0e23Gordon Ross#define	vc_hflags2	vc_iods.is_hflags2
28340c0e23Gordon Ross#define	vc_smbuid	vc_iods.is_smbuid
28440c0e23Gordon Ross#define	vc_next_mid	vc_iods.is_next_mid
28540c0e23Gordon Ross#define	vc_txmax	vc_iods.is_txmax
28640c0e23Gordon Ross#define	vc_rwmax	vc_iods.is_rwmax
28740c0e23Gordon Ross#define	vc_rxmax	vc_iods.is_rxmax
28840c0e23Gordon Ross#define	vc_wxmax	vc_iods.is_wxmax
28940c0e23Gordon Ross#define	vc_next_seq	vc_iods.is_next_seq
2904bff34ethurlow
2914bff34ethurlow#define	SMB_VC_LOCK(vcp)	mutex_enter(&(vcp)->vc_lock)
2924bff34ethurlow#define	SMB_VC_UNLOCK(vcp)	mutex_exit(&(vcp)->vc_lock)
2934bff34ethurlow
294adee678Gordon Ross#define	CPTOVC(cp)	((struct smb_vc *)((void *)(cp)))
295adee678Gordon Ross#define	VCTOCP(vcp)	(&(vcp)->vc_co)
296adee678Gordon Ross
297adee678Gordon Ross#define	SMB_UNICODE_STRINGS(vcp) \
298adee678Gordon Ross	(((vcp)->vc_flags & SMBV_SMB2) != 0 ||	\
299adee678Gordon Ross	((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE) != 0)
3004bff34ethurlow
3014bff34ethurlow/* Bits in iod_flags */
3024bff34ethurlow#define	SMBIOD_RUNNING		0x0001
3034bff34ethurlow#define	SMBIOD_SHUTDOWN		0x0002
3044bff34ethurlow
3054bff34ethurlow/*
3064bff34ethurlow * smb_share structure describes connection to the given SMB share (tree).
3074bff34ethurlow * Connection to share is always built on top of the VC.
3084bff34ethurlow */
3094bff34ethurlow
3104bff34ethurlowtypedef struct smb_share {
311613a2f6Gordon Ross	struct smb_connobj ss_co;	/* keep first! See CPTOSS */
3124bff34ethurlow	kcondvar_t	ss_conn_done;	/* wait for reconnect */
3134bff34ethurlow	int		ss_conn_waiters;
3144bff34ethurlow	int		ss_vcgenid;	/* check VC generation ID */
315613a2f6Gordon Ross	uint16_t	ss_tid;		/* TID */
316613a2f6Gordon Ross	uint16_t	ss_options;	/* option support bits */
317adee678Gordon Ross	uint32_t	ss2_tree_id;
318adee678Gordon Ross	uint32_t	ss2_share_flags;
319adee678Gordon Ross	uint32_t	ss2_share_caps;
320613a2f6Gordon Ross	smbioc_oshare_t ss_ioc;
3214bff34ethurlow} smb_share_t;
3224bff34ethurlow
3234bff34ethurlow#define	ss_lock		ss_co.co_lock
3244bff34ethurlow#define	ss_flags	ss_co.co_flags
3254bff34ethurlow
326430b4c4Gordon Ross#define	ss_use		ss_ioc.sh_use
327430b4c4Gordon Ross#define	ss_type		ss_ioc.sh_type
328613a2f6Gordon Ross#define	ss_name		ss_ioc.sh_name
329613a2f6Gordon Ross#define	ss_pass		ss_ioc.sh_pass
330613a2f6Gordon Ross
3314bff34ethurlow#define	SMB_SS_LOCK(ssp)	mutex_enter(&(ssp)->ss_lock)
3324bff34ethurlow#define	SMB_SS_UNLOCK(ssp)	mutex_exit(&(ssp)->ss_lock)
3334bff34ethurlow
334613a2f6Gordon Ross#define	CPTOSS(cp)	((struct smb_share *)((void *)(cp)))
3354bff34ethurlow#define	SSTOCP(ssp)	(&(ssp)->ss_co)
336adee678Gordon Ross#define	SSTOVC(ssp)	CPTOVC(((ssp)->ss_co.co_parent))
337adee678Gordon Ross
338adee678Gordon Rosstypedef struct smb2fid {
339adee678Gordon Ross	uint64_t fid_persistent;
340adee678Gordon Ross	uint64_t fid_volatile;
341adee678Gordon Ross} smb2fid_t;
342adee678Gordon Ross
343adee678Gordon Ross/*
344adee678Gordon Ross * smb_fh struct describes an open file handle under some share.
345adee678Gordon Ross */
346adee678Gordon Rosstypedef struct smb_fh {
347adee678Gordon Ross	struct smb_connobj fh_co;	/* keep first! See CPTOSS */
348adee678Gordon Ross	int	fh_vcgenid;		/* check VC generation ID */
349adee678Gordon Ross	uint32_t fh_rights;		/* granted access */
350adee678Gordon Ross	smb2fid_t fh_fid2;
351adee678Gordon Ross	uint16_t fh_fid1;
352adee678Gordon Ross} smb_fh_t;
353adee678Gordon Ross
354adee678Gordon Ross#define	fh_lock		fh_co.co_lock
355adee678Gordon Ross#define	fh_flags	fh_co.co_flags
356adee678Gordon Ross
357adee678Gordon Ross#define	SMB_FH_LOCK(fhp)	mutex_enter(&(fhp)->fh_lock)
358adee678Gordon Ross#define	SMB_FH_UNLOCK(fhp)	mutex_exit(&(fhp)->fh_lock)
359adee678Gordon Ross
360adee678Gordon Ross#define	CPTOFH(cp)	((struct smb_fh *)((void *)(cp)))
361adee678Gordon Ross#define	FHTOCP(fhp)	(&(fhp)->fh_co)
362adee678Gordon Ross#define	FHTOSS(fhp)	CPTOSS(((fhp)->fh_co.co_parent))
3634bff34ethurlow
3644bff34ethurlow/*
3654bff34ethurlow * Call-back operations vector, so the netsmb module
3664bff34ethurlow * can notify smbfs about events affecting mounts.
3674bff34ethurlow * Installed in netsmb after smbfs loads.
368adee678Gordon Ross * Note: smbfs only uses the fscb_discon hook.
3694bff34ethurlow */
3704bff34ethurlowtypedef struct smb_fscb {
371613a2f6Gordon Ross	/* Called when the VC has disconnected. */
372613a2f6Gordon Ross	void (*fscb_disconn)(smb_share_t *);
373613a2f6Gordon Ross	/* Called when the VC has reconnected. */
374613a2f6Gordon Ross	void (*fscb_connect)(smb_share_t *);
3754bff34ethurlow} smb_fscb_t;
3764bff34ethurlow/* Install the above vector, or pass NULL to clear it. */
37702d09e0Gordon Rossvoid smb_fscb_set(smb_fscb_t *);
378613a2f6Gordon Ross
379613a2f6Gordon Ross/*
380613a2f6Gordon Ross * The driver per open instance object.
381613a2f6Gordon Ross * Mostly used in: smb_dev.c, smb_usr.c
382613a2f6Gordon Ross */
383613a2f6Gordon Rosstypedef struct smb_dev {
384216041cGordon Ross	kmutex_t	sd_lock;
385613a2f6Gordon Ross	struct smb_vc	*sd_vc;		/* Reference to VC */
386613a2f6Gordon Ross	struct smb_share *sd_share;	/* Reference to share if any */
387adee678Gordon Ross	struct smb_fh	*sd_fh;		/* Reference to FH, if any */
388430b4c4Gordon Ross	int		sd_level;	/* SMBL_VC, ... */
389613a2f6Gordon Ross	int		sd_vcgenid;	/* Generation of share or VC */
390613a2f6Gordon Ross	int		sd_poll;	/* Future use */
391613a2f6Gordon Ross	int		sd_flags;	/* State of connection */
392adee678Gordon Ross#define	NSMBFL_OPEN		0x0001	/* Device minor is open */
393adee678Gordon Ross#define	NSMBFL_IOD		0x0004	/* Open by IOD */
394adee678Gordon Ross#define	NSMBFL_IOCTL		0x0010	/* Serialize ioctl calls */
395613a2f6Gordon Ross	zoneid_t	zoneid;		/* Zone id */
396613a2f6Gordon Ross} smb_dev_t;
397613a2f6Gordon Ross
398613a2f6Gordon Rossextern const uint32_t nsmb_version;
399613a2f6Gordon Ross
400613a2f6Gordon Ross/*
401613a2f6Gordon Ross * smb_dev.c
402613a2f6Gordon Ross */
403613a2f6Gordon Rossint  smb_dev2share(int fd, struct smb_share **sspp);
404613a2f6Gordon Ross
405613a2f6Gordon Ross
406613a2f6Gordon Ross/*
407613a2f6Gordon Ross * smb_usr.c
408613a2f6Gordon Ross */
40940c0e23Gordon Rossint smb_usr_ioctl(smb_dev_t *, int, intptr_t, int, cred_t *);
41040c0e23Gordon Ross
411613a2f6Gordon Rossint smb_usr_get_flags2(smb_dev_t *sdp, intptr_t arg, int flags);
412613a2f6Gordon Rossint smb_usr_get_ssnkey(smb_dev_t *sdp, intptr_t arg, int flags);
413430b4c4Gordon Rossint smb_usr_dup_dev(smb_dev_t *sdp, intptr_t arg, int flags);
414613a2f6Gordon Ross
415613a2f6Gordon Rossint smb_usr_simplerq(smb_dev_t *sdp, intptr_t arg, int flags, cred_t *cr);
416613a2f6Gordon Rossint smb_usr_t2request(smb_dev_t *sdp, intptr_t arg, int flags, cred_t *cr);
417430b4c4Gordon Ross
418430b4c4Gordon Rossint smb_usr_closefh(smb_dev_t *, cred_t *);
419613a2f6Gordon Rossint smb_usr_rw(smb_dev_t *sdp, int cmd, intptr_t arg, int flags, cred_t *cr);
420430b4c4Gordon Rossint smb_usr_ntcreate(smb_dev_t *, intptr_t, int, cred_t *);
421430b4c4Gordon Rossint smb_usr_printjob(smb_dev_t *, intptr_t, int, cred_t *);
422613a2f6Gordon Ross
423613a2f6Gordon Rossint smb_usr_get_ssn(smb_dev_t *, int, intptr_t, int, cred_t *);
424613a2f6Gordon Rossint smb_usr_drop_ssn(smb_dev_t *sdp, int cmd);
425613a2f6Gordon Ross
426613a2f6Gordon Rossint smb_usr_get_tree(smb_dev_t *, int, intptr_t, int, cred_t *);
427613a2f6Gordon Rossint smb_usr_drop_tree(smb_dev_t *sdp, int cmd);
428613a2f6Gordon Ross
429613a2f6Gordon Rossint smb_usr_iod_work(smb_dev_t *sdp, intptr_t arg, int flags, cred_t *cr);
43040c0e23Gordon Rossint smb_usr_iod_ioctl(smb_dev_t *sdp, int cmd, intptr_t arg, int flags,
43140c0e23Gordon Ross    cred_t *cr);
43240c0e23Gordon Ross
43340c0e23Gordon Rossint smb_pkey_ioctl(int, intptr_t, int, cred_t *);
434613a2f6Gordon Ross
4354bff34ethurlow
4364bff34ethurlow/*
4374bff34ethurlow * IOD functions
4384bff34ethurlow */
439613a2f6Gordon Rossint  smb_iod_create(smb_vc_t *vcp);
440613a2f6Gordon Rossint  smb_iod_destroy(smb_vc_t *vcp);
44102d09e0Gordon Rossvoid smb_iod_disconnect(smb_vc_t *vcp);
442adee678Gordon Rossint  smb2_iod_addrq(struct smb_rq *rqp);
443adee678Gordon Rossint  smb1_iod_addrq(struct smb_rq *rqp);
444adee678Gordon Rossint  smb1_iod_multirq(struct smb_rq *rqp);
4454bff34ethurlowint  smb_iod_waitrq(struct smb_rq *rqp);
446adee678Gordon Rossint  smb_iod_waitrq_int(struct smb_rq *rqp);
44702d09e0Gordon Rossvoid smb_iod_removerq(struct smb_rq *rqp);
44840c0e23Gordon Rossint  smb_iod_sendrecv(struct smb_rq *, int);
449613a2f6Gordon Rossvoid smb_iod_shutdown_share(smb_share_t *ssp);
450613a2f6Gordon Ross
451613a2f6Gordon Rossvoid smb_iod_sendall(smb_vc_t *);
45240c0e23Gordon Rossint smb_iod_recvall(smb_vc_t *, boolean_t);
453613a2f6Gordon Ross
454adee678Gordon Rossint nsmb_iod_connect(smb_vc_t *vcp, cred_t *cr);
45540c0e23Gordon Rossint nsmb_iod_negotiate(smb_vc_t *vcp, cred_t *cr);
45640c0e23Gordon Rossint nsmb_iod_ssnsetup(smb_vc_t *vcp, cred_t *cr);
45740c0e23Gordon Rossint smb_iod_vc_work(smb_vc_t *, int, cred_t *);
458613a2f6Gordon Rossint smb_iod_vc_idle(smb_vc_t *);
459613a2f6Gordon Rossint smb_iod_vc_rcfail(smb_vc_t *);
460613a2f6Gordon Rossint smb_iod_reconnect(smb_vc_t *);
4614bff34ethurlow
4624bff34ethurlow/*
4634bff34ethurlow * Session level functions
4644bff34ethurlow */
4654bff34ethurlowint  smb_sm_init(void);
4664bff34ethurlowint  smb_sm_idle(void);
4674bff34ethurlowvoid smb_sm_done(void);
4684bff34ethurlow
4694bff34ethurlow/*
4704bff34ethurlow * VC level functions
4714bff34ethurlow */
472613a2f6Gordon Rossvoid smb_vc_hold(smb_vc_t *vcp);
473613a2f6Gordon Rossvoid smb_vc_rele(smb_vc_t *vcp);
474613a2f6Gordon Rossvoid smb_vc_kill(smb_vc_t *vcp);
475613a2f6Gordon Ross
476613a2f6Gordon Rossint smb_vc_findcreate(smbioc_ossn_t *, smb_cred_t *, smb_vc_t **);
477613a2f6Gordon Rossint smb_vc_create(smbioc_ossn_t *ossn, smb_cred_t *scred, smb_vc_t **vcpp);
478613a2f6Gordon Ross
479613a2f6Gordon Rossconst char *smb_vc_getpass(smb_vc_t *vcp);
480613a2f6Gordon Rossuint16_t smb_vc_nextmid(smb_vc_t *vcp);
481613a2f6Gordon Rossvoid *smb_vc_getipaddr(smb_vc_t *vcp, int *ipvers);
482613a2f6Gordon Ross
483613a2f6Gordon Rosstypedef void (*walk_share_func_t)(smb_share_t *);
484613a2f6Gordon Rossvoid smb_vc_walkshares(struct smb_vc *,	walk_share_func_t);
4854bff34ethurlow
4864bff34ethurlow/*
4874bff34ethurlow * share level functions
4884bff34ethurlow */
4894bff34ethurlow
490613a2f6Gordon Rossint smb_share_findcreate(smbioc_tcon_t *, smb_vc_t *,
491613a2f6Gordon Ross	smb_share_t **, smb_cred_t *);
492613a2f6Gordon Ross
493613a2f6Gordon Rossvoid smb_share_hold(smb_share_t *ssp);
494613a2f6Gordon Rossvoid smb_share_rele(smb_share_t *ssp);
495613a2f6Gordon Rossvoid smb_share_kill(smb_share_t *ssp);
4964bff34ethurlow
497613a2f6Gordon Rossvoid smb_share_invalidate(smb_share_t *ssp);
498613a2f6Gordon Rossint  smb_share_tcon(smb_share_t *, smb_cred_t *);
4994bff34ethurlow
500adee678Gordon Ross/*
501adee678Gordon Ross * File handle level functions
502adee678Gordon Ross */
503adee678Gordon Rossint smb_fh_create(smb_share_t *ssp, struct smb_fh **fhpp);
504adee678Gordon Rossvoid smb_fh_opened(struct smb_fh *fhp);
505adee678Gordon Rossvoid smb_fh_close(struct smb_fh *fhp);
506adee678Gordon Rossvoid smb_fh_hold(struct smb_fh *fhp);
507adee678Gordon Rossvoid smb_fh_rele(struct smb_fh *fhp);
508adee678Gordon Ross
5094bff34ethurlow#endif /* _SMB_CONN_H */
510