xref: /illumos-gate/usr/src/uts/common/nfs/export.h (revision 0dfe541e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51cc55349Srmesta  * Common Development and Distribution License (the "License").
61cc55349Srmesta  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2189621fe1SMarcel Telka 
227c478bd9Sstevel@tonic-gate /*
2389621fe1SMarcel Telka  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24f7db5903SVitaliy Gusev  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
251a444326SJason King  * Copyright 2016 Jason King.
26*0dfe541eSEvan Layton  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
30b4203d75SMarcel Telka /*	  All Rights Reserved	*/
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifndef	_NFS_EXPORT_H
337c478bd9Sstevel@tonic-gate #define	_NFS_EXPORT_H
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <nfs/nfs_sec.h>
361cc55349Srmesta #include <nfs/auth.h>
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
387c478bd9Sstevel@tonic-gate #include <nfs/nfs4.h>
39b89a8333Snatalie li - Sun Microsystems - Irvine United States #include <sys/kiconv.h>
4071da0c32SMarcel Telka #include <sys/avl.h>
41*0dfe541eSEvan Layton #include <sys/zone.h>
42*0dfe541eSEvan Layton 
43*0dfe541eSEvan Layton #ifdef _KERNEL
44*0dfe541eSEvan Layton #include <sys/pkp_hash.h> /* for PKP_HASH_SIZE */
45*0dfe541eSEvan Layton #endif /* _KERNEL */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
487c478bd9Sstevel@tonic-gate extern "C" {
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * nfs pseudo flavor number is owned by IANA. Need to make sure the
537c478bd9Sstevel@tonic-gate  * Solaris specific NFS_FLAVOR_NOMAP number will not overlap with any
547c478bd9Sstevel@tonic-gate  * new IANA defined pseudo flavor numbers. The chance for the overlap
557c478bd9Sstevel@tonic-gate  * is very small since the growth of new flavor numbers is expected
567c478bd9Sstevel@tonic-gate  * to be limited.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #define	NFS_FLAVOR_NOMAP	999999	/* no nfs flavor mapping */
597c478bd9Sstevel@tonic-gate 
608a429e7eSms /*
618a429e7eSms  * As duplicate flavors can be passed into exportfs in the arguments, we
628a429e7eSms  * allocate a cleaned up array with non duplicate flavors on the stack.
638a429e7eSms  * So we need to know how much to allocate.
648a429e7eSms  */
658a429e7eSms #define	MAX_FLAVORS		6	/* none, sys, dh, krb5, krb5i krb5p */
668a429e7eSms 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * Note: exported_lock is currently used to ensure the integrity of
697c478bd9Sstevel@tonic-gate  * the secinfo fields.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate struct secinfo {
727c478bd9Sstevel@tonic-gate 	seconfig_t	s_secinfo;	/* /etc/nfssec.conf entry */
737c478bd9Sstevel@tonic-gate 	unsigned int	s_flags;	/* flags (see below) */
748a429e7eSms 	int32_t		s_refcnt;	/* reference count for tracking */
757c478bd9Sstevel@tonic-gate 					/* how many children (self included) */
767c478bd9Sstevel@tonic-gate 					/* use this flavor. */
77f7db5903SVitaliy Gusev 	int		s_window;	/* window */
78b89a8333Snatalie li - Sun Microsystems - Irvine United States 	uint_t		s_rootid;	/* UID to use for authorized roots */
797c478bd9Sstevel@tonic-gate 	int		s_rootcnt;	/* count of root names */
807c478bd9Sstevel@tonic-gate 	caddr_t		*s_rootnames;	/* array of root names */
817c478bd9Sstevel@tonic-gate 					/* they are strings for AUTH_DES and */
827c478bd9Sstevel@tonic-gate 					/* rpc_gss_principal_t for RPCSEC_GSS */
837c478bd9Sstevel@tonic-gate };
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
867c478bd9Sstevel@tonic-gate struct secinfo32 {
877c478bd9Sstevel@tonic-gate 	seconfig32_t	s_secinfo;	/* /etc/nfssec.conf entry */
887c478bd9Sstevel@tonic-gate 	uint32_t	s_flags;	/* flags (see below) */
898a429e7eSms 	int32_t		s_refcnt;	/* reference count for tracking */
907c478bd9Sstevel@tonic-gate 					/* how many children (self included) */
917c478bd9Sstevel@tonic-gate 					/* use this flavor. */
92f7db5903SVitaliy Gusev 	int32_t		s_window;	/* window */
93b89a8333Snatalie li - Sun Microsystems - Irvine United States 	uint32_t	s_rootid;	/* UID to use for authorized roots */
947c478bd9Sstevel@tonic-gate 	int32_t		s_rootcnt;	/* count of root names */
957c478bd9Sstevel@tonic-gate 	caddr32_t	s_rootnames;	/* array of root names */
967c478bd9Sstevel@tonic-gate 					/* they are strings for AUTH_DES and */
977c478bd9Sstevel@tonic-gate 					/* rpc_gss_principal_t for RPCSEC_GSS */
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * security negotiation related
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #define	SEC_QUERY	0x01	/* query sec modes */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate struct sec_ol {
1087c478bd9Sstevel@tonic-gate 	int		sec_flags;	/* security nego flags */
1097c478bd9Sstevel@tonic-gate 	uint_t		sec_index;	/* index into sec flavor array */
1107c478bd9Sstevel@tonic-gate };
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * Per-mode flags (secinfo.s_flags)
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate #define	M_RO		0x01	/* exported ro to all */
1167c478bd9Sstevel@tonic-gate #define	M_ROL		0x02	/* exported ro to all listed */
1177c478bd9Sstevel@tonic-gate #define	M_RW		0x04	/* exported rw to all */
1187c478bd9Sstevel@tonic-gate #define	M_RWL		0x08	/* exported ro to all listed */
1197c478bd9Sstevel@tonic-gate #define	M_ROOT		0x10	/* root list is defined */
1207c478bd9Sstevel@tonic-gate #define	M_4SEC_EXPORTED	0x20	/* this is an explicitly shared flavor */
121b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	M_NONE		0x40	/* none list is defined */
1225cb0d679SMarcel Telka #define	M_MAP		0x80	/* uidmap and/or gidmap is defined */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /* invalid secinfo reference count */
1257c478bd9Sstevel@tonic-gate #define	SEC_REF_INVALID(p) ((p)->s_refcnt < 1)
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /* last secinfo reference */
1287c478bd9Sstevel@tonic-gate #define	SEC_REF_LAST(p) ((p)->s_refcnt == 1)
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /* sec flavor explicitly shared for the exported node */
1317c478bd9Sstevel@tonic-gate #define	SEC_REF_EXPORTED(p) ((p)->s_flags & M_4SEC_EXPORTED)
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /* the only reference count left is for referring itself */
1347c478bd9Sstevel@tonic-gate #define	SEC_REF_SELF(p) (SEC_REF_LAST(p) && SEC_REF_EXPORTED(p))
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * The export information passed to exportfs() (Version 2)
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate #define	EX_CURRENT_VERSION 2	/* current version of exportdata struct */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate struct exportdata {
1427c478bd9Sstevel@tonic-gate 	int		ex_version;	/* structure version */
1437c478bd9Sstevel@tonic-gate 	char		*ex_path;	/* exported path */
1447c478bd9Sstevel@tonic-gate 	size_t		ex_pathlen;	/* path length */
1457c478bd9Sstevel@tonic-gate 	int		ex_flags;	/* flags */
1467c478bd9Sstevel@tonic-gate 	unsigned int	ex_anon;	/* uid for unauthenticated requests */
1477c478bd9Sstevel@tonic-gate 	int		ex_seccnt;	/* count of security modes */
1487c478bd9Sstevel@tonic-gate 	struct secinfo	*ex_secinfo;	/* security mode info */
1497c478bd9Sstevel@tonic-gate 	char		*ex_index;	/* index file for public filesystem */
1507c478bd9Sstevel@tonic-gate 	char		*ex_log_buffer;	/* path to logging buffer file */
1517c478bd9Sstevel@tonic-gate 	size_t		ex_log_bufferlen;	/* buffer file path len */
1527c478bd9Sstevel@tonic-gate 	char		*ex_tag;	/* tag used to identify log config */
1537c478bd9Sstevel@tonic-gate 	size_t		ex_taglen;	/* tag length */
1547c478bd9Sstevel@tonic-gate };
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
1577c478bd9Sstevel@tonic-gate struct exportdata32 {
1587c478bd9Sstevel@tonic-gate 	int32_t		ex_version;	/* structure version */
1597c478bd9Sstevel@tonic-gate 	caddr32_t	ex_path;	/* exported path */
1607c478bd9Sstevel@tonic-gate 	int32_t		ex_pathlen;	/* path length */
1617c478bd9Sstevel@tonic-gate 	int32_t		ex_flags;	/* flags */
1627c478bd9Sstevel@tonic-gate 	uint32_t	ex_anon;	/* uid for unauthenticated requests */
1637c478bd9Sstevel@tonic-gate 	int32_t		ex_seccnt;	/* count of security modes */
1647c478bd9Sstevel@tonic-gate 	caddr32_t	ex_secinfo;	/* security mode info */
1657c478bd9Sstevel@tonic-gate 	caddr32_t	ex_index;	/* index file for public filesystem */
1667c478bd9Sstevel@tonic-gate 	caddr32_t	ex_log_buffer;	/* path to logging buffer file */
1677c478bd9Sstevel@tonic-gate 	int32_t		ex_log_bufferlen;	/* buffer file path len */
1687c478bd9Sstevel@tonic-gate 	caddr32_t	ex_tag;		/* tag used to identify log config */
1697c478bd9Sstevel@tonic-gate 	int32_t		ex_taglen;	/* tag length */
1707c478bd9Sstevel@tonic-gate };
1717c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * exported vfs flags.
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #define	EX_NOSUID	0x01	/* exported with unsetable set[ug]ids */
1787c478bd9Sstevel@tonic-gate #define	EX_ACLOK	0x02	/* exported with maximal access if acl exists */
1797c478bd9Sstevel@tonic-gate #define	EX_PUBLIC	0x04	/* exported with public filehandle */
1807c478bd9Sstevel@tonic-gate #define	EX_NOSUB	0x08	/* no nfs_getfh or MCL below export point */
1817c478bd9Sstevel@tonic-gate #define	EX_INDEX	0x10	/* exported with index file specified */
1827c478bd9Sstevel@tonic-gate #define	EX_LOG		0x20	/* logging enabled */
1837c478bd9Sstevel@tonic-gate #define	EX_LOG_ALLOPS	0x40	/* logging of all RPC operations enabled */
1847c478bd9Sstevel@tonic-gate 				/* by default only operations which affect */
1857c478bd9Sstevel@tonic-gate 				/* transaction logging are enabled */
1867c478bd9Sstevel@tonic-gate #define	EX_PSEUDO	0x80	/* pseudo filesystem export */
1877c478bd9Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST
1887c478bd9Sstevel@tonic-gate #define	EX_VOLFH	0x100	/* XXX nfsv4 fh may expire anytime */
1897c478bd9Sstevel@tonic-gate #define	EX_VOLRNM	0x200	/* XXX nfsv4 fh expire at rename */
1907c478bd9Sstevel@tonic-gate #define	EX_VOLMIG	0x400	/* XXX nfsv4 fh expire at migration */
1917c478bd9Sstevel@tonic-gate #define	EX_NOEXPOPEN	0x800	/* XXX nfsv4 fh no expire with open */
1927c478bd9Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */
1937c478bd9Sstevel@tonic-gate 
194b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	EX_CHARMAP	0x1000	/* NFS may need a character set conversion */
1951a444326SJason King #define	EX_NOACLFAB	0x2000	/* If set, NFSv2 and v3 servers won't */
1961a444326SJason King 				/* fabricate an aclent_t ACL on file systems */
1971a444326SJason King 				/* that don't support aclent_t ACLs */
198f7db5903SVitaliy Gusev #define	EX_NOHIDE	0x4000	/* traversable from exported parent */
199b89a8333Snatalie li - Sun Microsystems - Irvine United States 
2007c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #define	RPC_IDEMPOTENT	0x1	/* idempotent or not */
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * Be very careful about which NFS procedures get the RPC_ALLOWANON bit.
2055cb0d679SMarcel Telka  * Right now, if this bit is on, we ignore the results of per NFS request
2067c478bd9Sstevel@tonic-gate  * access control.
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate #define	RPC_ALLOWANON	0x2	/* allow anonymous access */
2097c478bd9Sstevel@tonic-gate #define	RPC_MAPRESP	0x4	/* use mapped response buffer */
2107c478bd9Sstevel@tonic-gate #define	RPC_AVOIDWORK	0x8	/* do work avoidance for dups */
2117c478bd9Sstevel@tonic-gate #define	RPC_PUBLICFH_OK	0x10	/* allow use of public filehandle */
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate  * RPC_ALL is an or of all above bits to be used with "don't care"
2157c478bd9Sstevel@tonic-gate  * nfsv4 ops. The flags of an nfsv4 request is the bit-AND of the
2167c478bd9Sstevel@tonic-gate  * per-op flags.
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate #define	RPC_ALL	(RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_AVOIDWORK|RPC_PUBLICFH_OK)
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST
2227c478bd9Sstevel@tonic-gate struct ex_vol_rename {
2237c478bd9Sstevel@tonic-gate 	nfs_fh4_fmt_t vrn_fh_fmt;
2247c478bd9Sstevel@tonic-gate 	struct ex_vol_rename *vrn_next;
2257c478bd9Sstevel@tonic-gate };
2267c478bd9Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */
2277c478bd9Sstevel@tonic-gate 
2283ccecb66SThomas Haynes /*
22971da0c32SMarcel Telka  * An auth cache client entry.  This is the umbrella structure and contains all
23071da0c32SMarcel Telka  * related auth_cache entries in the authc_tree AVL tree.
23171da0c32SMarcel Telka  */
23271da0c32SMarcel Telka struct auth_cache_clnt {
23371da0c32SMarcel Telka 	avl_node_t		authc_link;
23471da0c32SMarcel Telka 	struct netbuf		authc_addr;	/* address of the client */
23571da0c32SMarcel Telka 	krwlock_t		authc_lock;	/* protects authc_tree */
23671da0c32SMarcel Telka 	avl_tree_t		authc_tree;	/* auth_cache entries */
23771da0c32SMarcel Telka };
23871da0c32SMarcel Telka 
23971da0c32SMarcel Telka /*
24071da0c32SMarcel Telka  * An auth cache entry can exist in 6 states.
24171da0c32SMarcel Telka  *
24271da0c32SMarcel Telka  * A NEW entry was recently allocated and added to the cache.  It does not
24371da0c32SMarcel Telka  * contain the valid auth state yet.
2443ccecb66SThomas Haynes  *
24571da0c32SMarcel Telka  * A WAITING entry is one which is actively engaging the user land mountd code
24671da0c32SMarcel Telka  * to authenticate or re-authenticate it.  The auth state might not be valid
24771da0c32SMarcel Telka  * yet.  The other threads should wait on auth_cv until the retrieving thread
24871da0c32SMarcel Telka  * finishes the retrieval and changes the auth cache entry to FRESH, or NEW (in
24971da0c32SMarcel Telka  * a case this entry had no valid auth state yet).
2503ccecb66SThomas Haynes  *
25171da0c32SMarcel Telka  * A REFRESHING entry is one which is actively engaging the user land mountd
25271da0c32SMarcel Telka  * code to re-authenticate the cache entry.  There is currently no other thread
25371da0c32SMarcel Telka  * waiting for the results of the refresh.
2543ccecb66SThomas Haynes  *
25571da0c32SMarcel Telka  * A FRESH entry is one which is valid (it is either newly retrieved or has
25671da0c32SMarcel Telka  * been refreshed at least once).
2573ccecb66SThomas Haynes  *
25871da0c32SMarcel Telka  * A STALE entry is one which has been detected to be too old.  The transition
25971da0c32SMarcel Telka  * from FRESH to STALE prevents multiple threads from submitting refresh
26071da0c32SMarcel Telka  * requests.
2613ccecb66SThomas Haynes  *
26271da0c32SMarcel Telka  * An INVALID entry is one which was either STALE or REFRESHING and was deleted
26371da0c32SMarcel Telka  * out of the encapsulating exi.  Since we can't delete it yet, we mark it as
26471da0c32SMarcel Telka  * INVALID, which lets the refresh thread know not to work on it and free it
26571da0c32SMarcel Telka  * instead.
26671da0c32SMarcel Telka  *
26771da0c32SMarcel Telka  * Note that the auth state of the entry is valid, even if the entry is STALE.
26871da0c32SMarcel Telka  * Just as you can eat stale bread, you can consume a stale cache entry. The
26971da0c32SMarcel Telka  * only time the contents change could be during the transition from REFRESHING
27071da0c32SMarcel Telka  * or WAITING to FRESH.
27171da0c32SMarcel Telka  *
27271da0c32SMarcel Telka  * Valid state transitions:
27371da0c32SMarcel Telka  *
27471da0c32SMarcel Telka  *          alloc
27571da0c32SMarcel Telka  *            |
27671da0c32SMarcel Telka  *            v
27771da0c32SMarcel Telka  *         +-----+
27871da0c32SMarcel Telka  *    +--->| NEW |------>free
27971da0c32SMarcel Telka  *    |    +-----+
28071da0c32SMarcel Telka  *    |       |
28171da0c32SMarcel Telka  *    |       v
28271da0c32SMarcel Telka  *    |  +---------+
28371da0c32SMarcel Telka  *    +<-| WAITING |
28471da0c32SMarcel Telka  *    ^  +---------+
28571da0c32SMarcel Telka  *    |       |
28671da0c32SMarcel Telka  *    |       v
28771da0c32SMarcel Telka  *    |       +<--------------------------+<---------------+
28871da0c32SMarcel Telka  *    |       |                           ^                |
28971da0c32SMarcel Telka  *    |       v                           |                |
29071da0c32SMarcel Telka  *    |   +-------+    +-------+    +------------+    +---------+
29171da0c32SMarcel Telka  *    +---| FRESH |--->| STALE |--->| REFRESHING |--->| WAITING |
29271da0c32SMarcel Telka  *        +-------+    +-------+    +------------+    +---------+
29371da0c32SMarcel Telka  *            |            |              |
29471da0c32SMarcel Telka  *            |            v              |
29571da0c32SMarcel Telka  *            v       +---------+         |
29671da0c32SMarcel Telka  *          free<-----| INVALID |<--------+
29771da0c32SMarcel Telka  *                    +---------+
2983ccecb66SThomas Haynes  */
2993ccecb66SThomas Haynes typedef enum auth_state {
3003ccecb66SThomas Haynes 	NFS_AUTH_FRESH,
3013ccecb66SThomas Haynes 	NFS_AUTH_STALE,
3023ccecb66SThomas Haynes 	NFS_AUTH_REFRESHING,
30371da0c32SMarcel Telka 	NFS_AUTH_INVALID,
30471da0c32SMarcel Telka 	NFS_AUTH_NEW,
30571da0c32SMarcel Telka 	NFS_AUTH_WAITING
3063ccecb66SThomas Haynes } auth_state_t;
3073ccecb66SThomas Haynes 
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate  * An authorization cache entry
3103ccecb66SThomas Haynes  *
3113ccecb66SThomas Haynes  * Either the state in auth_state will protect the
3123ccecb66SThomas Haynes  * contents or auth_lock must be held.
3137c478bd9Sstevel@tonic-gate  */
3147c478bd9Sstevel@tonic-gate struct auth_cache {
31571da0c32SMarcel Telka 	avl_node_t		auth_link;
31671da0c32SMarcel Telka 	struct auth_cache_clnt	*auth_clnt;
3177c478bd9Sstevel@tonic-gate 	int			auth_flavor;
31812fb3699SMarcel Telka 	cred_t			*auth_clnt_cred;
3195cb0d679SMarcel Telka 	uid_t			auth_srv_uid;
3205cb0d679SMarcel Telka 	gid_t			auth_srv_gid;
32189621fe1SMarcel Telka 	uint_t			auth_srv_ngids;
32289621fe1SMarcel Telka 	gid_t			*auth_srv_gids;
3237c478bd9Sstevel@tonic-gate 	int			auth_access;
3247c478bd9Sstevel@tonic-gate 	time_t			auth_time;
3253ccecb66SThomas Haynes 	time_t			auth_freshness;
3263ccecb66SThomas Haynes 	auth_state_t		auth_state;
3273ccecb66SThomas Haynes 	kmutex_t		auth_lock;
32871da0c32SMarcel Telka 	kcondvar_t		auth_cv;
3297c478bd9Sstevel@tonic-gate };
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate #define	AUTH_TABLESIZE	32
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate  * Structure containing log file meta-data.
3357c478bd9Sstevel@tonic-gate  */
3367c478bd9Sstevel@tonic-gate struct log_file {
3377c478bd9Sstevel@tonic-gate 	unsigned int	lf_flags;	/* flags (see below) */
3387c478bd9Sstevel@tonic-gate 	int		lf_writers;	/* outstanding writers */
3397c478bd9Sstevel@tonic-gate 	int		lf_refcnt;	/* references to this struct */
3407c478bd9Sstevel@tonic-gate 	caddr_t		lf_path;	/* buffer file location */
3417c478bd9Sstevel@tonic-gate 	vnode_t		*lf_vp;		/* vnode for the buffer file */
3427c478bd9Sstevel@tonic-gate 	kmutex_t	lf_lock;
3437c478bd9Sstevel@tonic-gate 	kcondvar_t	lf_cv_waiters;
3447c478bd9Sstevel@tonic-gate };
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate /*
3477c478bd9Sstevel@tonic-gate  * log_file and log_buffer flags.
3487c478bd9Sstevel@tonic-gate  */
3497c478bd9Sstevel@tonic-gate #define	L_WAITING	0x01		/* flush of in-core data to stable */
3507c478bd9Sstevel@tonic-gate 					/* storage in progress */
3517c478bd9Sstevel@tonic-gate #define	L_PRINTED	0x02		/* error message printed to console */
3527c478bd9Sstevel@tonic-gate #define	L_ERROR		0x04		/* error condition detected */
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate  * The logging buffer information.
3567c478bd9Sstevel@tonic-gate  * This structure may be shared by multiple exportinfo structures,
3577c478bd9Sstevel@tonic-gate  * if they share the same buffer file.
3587c478bd9Sstevel@tonic-gate  * This structure contains the basic information about the buffer, such
3597c478bd9Sstevel@tonic-gate  * as it's location in the filesystem.
3607c478bd9Sstevel@tonic-gate  *
3617c478bd9Sstevel@tonic-gate  * 'lb_lock' protects all the fields in this structure except for 'lb_path',
3627c478bd9Sstevel@tonic-gate  * and 'lb_next'.
3637c478bd9Sstevel@tonic-gate  * 'lb_path' is a write-once/read-many field which needs no locking, it is
3647c478bd9Sstevel@tonic-gate  * set before the structure is linked to any exportinfo structure.
3657c478bd9Sstevel@tonic-gate  * 'lb_next' is protected by the log_buffer_list_lock.
3667c478bd9Sstevel@tonic-gate  */
3677c478bd9Sstevel@tonic-gate struct log_buffer {
3687c478bd9Sstevel@tonic-gate 	unsigned int	lb_flags;	/* L_ONLIST set? */
3697c478bd9Sstevel@tonic-gate 	int		lb_refcnt;	/* references to this struct */
3707c478bd9Sstevel@tonic-gate 	unsigned int	lb_rec_id;	/* used to generate unique id */
3717c478bd9Sstevel@tonic-gate 	caddr_t		lb_path;	/* buffer file pathname */
3727c478bd9Sstevel@tonic-gate 	struct log_file	*lb_logfile;	/* points to log_file structure */
3737c478bd9Sstevel@tonic-gate 	kmutex_t	lb_lock;
3747c478bd9Sstevel@tonic-gate 	struct log_buffer	*lb_next;
3757c478bd9Sstevel@tonic-gate 	kcondvar_t	lb_cv_waiters;
3767c478bd9Sstevel@tonic-gate 	caddr_t		lb_records;	/* linked list of records to write */
3777c478bd9Sstevel@tonic-gate 	int		lb_num_recs;	/* # of records to write */
3787c478bd9Sstevel@tonic-gate 	ssize_t		lb_size_queued; /* number of bytes queued for write */
3797c478bd9Sstevel@tonic-gate };
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate #define	LOG_BUFFER_HOLD(lbp)	{ \
3827c478bd9Sstevel@tonic-gate 	mutex_enter(&(lbp)->lb_lock); \
3837c478bd9Sstevel@tonic-gate 	(lbp)->lb_refcnt++; \
3847c478bd9Sstevel@tonic-gate 	mutex_exit(&(lbp)->lb_lock); \
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate #define	LOG_BUFFER_RELE(lbp)	{ \
3887c478bd9Sstevel@tonic-gate 	log_buffer_rele(lbp); \
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate 
391b89a8333Snatalie li - Sun Microsystems - Irvine United States /*
392b89a8333Snatalie li - Sun Microsystems - Irvine United States  * Structure for character set conversion mapping based on client address.
393b89a8333Snatalie li - Sun Microsystems - Irvine United States  */
394b89a8333Snatalie li - Sun Microsystems - Irvine United States struct charset_cache {
395b89a8333Snatalie li - Sun Microsystems - Irvine United States 	struct charset_cache *next;
396b89a8333Snatalie li - Sun Microsystems - Irvine United States 	kiconv_t	inbound;
397b89a8333Snatalie li - Sun Microsystems - Irvine United States 	kiconv_t	outbound;
398b89a8333Snatalie li - Sun Microsystems - Irvine United States 	struct sockaddr	client_addr;
399b89a8333Snatalie li - Sun Microsystems - Irvine United States };
400b89a8333Snatalie li - Sun Microsystems - Irvine United States 
401992d2facSpf /* Forward declarations */
402992d2facSpf struct exportinfo;
403992d2facSpf struct exp_visible;
4042f172c55SRobert Thurlow struct svc_req;
405992d2facSpf 
406992d2facSpf /*
407992d2facSpf  * Treenodes are used to build tree representing every node which is part
4083f238301SPavel Filipensky  * of nfs server pseudo namespace. They are connected with both exportinfo
4093f238301SPavel Filipensky  * and exp_visible struct. They were introduced to avoid lookup of ".."
4103f238301SPavel Filipensky  * in the underlying file system during unshare, which was failing if the
4113f238301SPavel Filipensky  * file system was forcibly unmounted or if the directory was removed.
4123f238301SPavel Filipensky  * One exp_visible_t can be shared via several treenode_t, i.e.
4133f238301SPavel Filipensky  * different tree_vis can point to the same exp_visible_t.
4143f238301SPavel Filipensky  * This will happen if some directory is on two different shared paths:
4153f238301SPavel Filipensky  * E.g. after share /tmp/a/b1 and share /tmp/a/b2 there will be two treenodes
4163f238301SPavel Filipensky  * corresponding to /tmp/a and both will have same value in tree_vis.
417992d2facSpf  *
418992d2facSpf  *
419992d2facSpf  *
420992d2facSpf  *     NEW DATA STRUCT         ORIGINAL DATA STRUCT
421992d2facSpf  *
422992d2facSpf  * ns_root +---+               +----------+
423992d2facSpf  *         | / |               |PSEUDO EXP|-->+---+   +---+   +---+
424992d2facSpf  *         +---+---------  ----+----------+   | a |-->| k |-->| b |
425992d2facSpf  *          /\                                +---+   +---+   +---+
426992d2facSpf  *         /  \                                .       .       .
427992d2facSpf  *     +---+...\.........  .....................       .       .
428992d2facSpf  *    *| a |    \              +----------+            .       .
429992d2facSpf  *     +---+-----\-------  ----|REAL EXP a|            .       .
430992d2facSpf  *       /        \            +----------+            .       .
431992d2facSpf  *      /        +===+...  .............................       .
432992d2facSpf  *     /        *| k |         +----------+                    .
433992d2facSpf  *    /          +===+---  ----|REAL EXP k|                    .
434992d2facSpf  *   /                         +----------+                    .
435992d2facSpf  *  +===+................  .....................................
436992d2facSpf  * *| b |                      +----------+
437992d2facSpf  *  +===+----------------  ----|REAL EXP b|-->+---+
438992d2facSpf  *     \                       +----------+   | d |
439992d2facSpf  *     +===+.............  ...................+---+
440992d2facSpf  *     | d |                   +----------+
441992d2facSpf  *     +===+-------------  ----|PSEUDO EXP|-->+---+   +---+
442992d2facSpf  *     /                       +----------+   | e |-->| g |
443992d2facSpf  * +---+.................  ...................+---+   +---+
444992d2facSpf  * | e |                                              .
445992d2facSpf  * +---+                                              .
446992d2facSpf  *    \                                               .
447992d2facSpf  *    +---+..............  ............................
448992d2facSpf  *   *| g |                    +----------+
449992d2facSpf  *    +---+--------------  ----|REAL EXP g|
450992d2facSpf  *                             +----------+
451992d2facSpf  *
452992d2facSpf  *
453992d2facSpf  *
454992d2facSpf  * +===+               +---+                    +---+
455992d2facSpf  * | b |..mountpoint   | e |..directory/file   *| a |..node is shared
456992d2facSpf  * +===+  (VROOT)      +---+                    +---+
457992d2facSpf  *
458992d2facSpf  *
459992d2facSpf  * Bi-directional interconnect:
460992d2facSpf  * treenode_t::tree_exi ---------  exportinfo_t::exi_tree
4613f238301SPavel Filipensky  * One-way direction connection:
4623f238301SPavel Filipensky  * treenode_t::tree_vis .........> exp_visible_t
463992d2facSpf  */
464c076b414SPavel Filipensky /* Access to treenode_t is under protection of exported_lock RW_LOCK */
465992d2facSpf typedef struct treenode {
466992d2facSpf 	/* support for generic n-ary trees */
467992d2facSpf 	struct treenode *tree_parent;
468992d2facSpf 	struct treenode *tree_child_first;
469992d2facSpf 	struct treenode *tree_sibling; /* next sibling */
470992d2facSpf 	/* private, nfs specific part */
471992d2facSpf 	struct exportinfo  *tree_exi;
472992d2facSpf 	struct exp_visible *tree_vis;
473992d2facSpf } treenode_t;
474992d2facSpf 
475992d2facSpf /*
476*0dfe541eSEvan Layton  * Now that we have links to chase, we can get the zone rootvp just from
477*0dfe541eSEvan Layton  * an export.  No current-zone-context needed.
478*0dfe541eSEvan Layton  */
479*0dfe541eSEvan Layton #define	EXI_TO_ZONEROOTVP(exi) ((exi)->exi_ne->exi_root->exi_vp)
480*0dfe541eSEvan Layton 
481*0dfe541eSEvan Layton /*
482*0dfe541eSEvan Layton  * TREE_ROOT checks if the node corresponds to a filesystem root or
483*0dfe541eSEvan Layton  * the zone's root directory.
484992d2facSpf  * TREE_EXPORTED checks if the node is explicitly shared
485992d2facSpf  */
486992d2facSpf 
487992d2facSpf #define	TREE_ROOT(t) \
488*0dfe541eSEvan Layton 	((t)->tree_exi != NULL && \
489*0dfe541eSEvan Layton 	(((t)->tree_exi->exi_vp->v_flag & VROOT) || \
490*0dfe541eSEvan Layton 	VN_CMP(EXI_TO_ZONEROOTVP((t)->tree_exi), (t)->tree_exi->exi_vp)))
491992d2facSpf 
492992d2facSpf #define	TREE_EXPORTED(t) \
493992d2facSpf 	((t)->tree_exi && !PSEUDO((t)->tree_exi))
494992d2facSpf 
4950616fd7fSPavel Filipensky #define	EXPTABLESIZE   256
4960616fd7fSPavel Filipensky 
4970616fd7fSPavel Filipensky struct exp_hash {
4980616fd7fSPavel Filipensky 	struct exportinfo	*prev;  /* ptr to the previous exportinfo */
4990616fd7fSPavel Filipensky 	struct exportinfo	*next;  /* ptr to the next exportinfo */
5000616fd7fSPavel Filipensky 	struct exportinfo	**bckt; /* backpointer to the hash bucket */
5010616fd7fSPavel Filipensky };
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate /*
5047c478bd9Sstevel@tonic-gate  * A node associated with an export entry on the
5057c478bd9Sstevel@tonic-gate  * list of exported filesystems.
5067c478bd9Sstevel@tonic-gate  *
5077c478bd9Sstevel@tonic-gate  * exi_count+exi_lock protects an individual exportinfo from being freed
5087c478bd9Sstevel@tonic-gate  * when in use.
5093ccecb66SThomas Haynes  *
5107c478bd9Sstevel@tonic-gate  * You must have the writer lock on exported_lock to add/delete an exportinfo
5117c478bd9Sstevel@tonic-gate  * structure to/from the list.
5127c478bd9Sstevel@tonic-gate  *
5137c478bd9Sstevel@tonic-gate  * exi_volatile_dev maps to VSW_VOLATILEDEV.  It means that the
5147c478bd9Sstevel@tonic-gate  * underlying fs devno can change on each mount.  When set, the server
5157c478bd9Sstevel@tonic-gate  * should not use va_fsid for a GETATTR(FATTR4_FSID) reply.  It must
5167c478bd9Sstevel@tonic-gate  * use exi_fsid because it is guaranteed to be persistent.  This isn't
5177c478bd9Sstevel@tonic-gate  * in any way related to NFS4 volatile filehandles.
51871da0c32SMarcel Telka  *
51971da0c32SMarcel Telka  * The exi_cache_lock protects the exi_cache AVL trees.
5207c478bd9Sstevel@tonic-gate  */
5217c478bd9Sstevel@tonic-gate struct exportinfo {
5227c478bd9Sstevel@tonic-gate 	struct exportdata	exi_export;
5237c478bd9Sstevel@tonic-gate 	fsid_t			exi_fsid;
5247c478bd9Sstevel@tonic-gate 	struct fid		exi_fid;
5250616fd7fSPavel Filipensky 	struct exp_hash		fid_hash;
5260616fd7fSPavel Filipensky 	struct exp_hash		path_hash;
527992d2facSpf 	struct treenode		*exi_tree;
5287c478bd9Sstevel@tonic-gate 	fhandle_t		exi_fh;
5297c478bd9Sstevel@tonic-gate 	krwlock_t		exi_cache_lock;
5307c478bd9Sstevel@tonic-gate 	kmutex_t		exi_lock;
5317c478bd9Sstevel@tonic-gate 	uint_t			exi_count;
532*0dfe541eSEvan Layton 	zoneid_t		exi_zoneid;
5337c478bd9Sstevel@tonic-gate 	vnode_t			*exi_vp;
5347c478bd9Sstevel@tonic-gate 	vnode_t			*exi_dvp;
53571da0c32SMarcel Telka 	avl_tree_t		*exi_cache[AUTH_TABLESIZE];
5367c478bd9Sstevel@tonic-gate 	struct log_buffer	*exi_logbuffer;
5377c478bd9Sstevel@tonic-gate 	struct exp_visible	*exi_visible;
538b89a8333Snatalie li - Sun Microsystems - Irvine United States 	struct charset_cache	*exi_charset;
5397c478bd9Sstevel@tonic-gate 	unsigned		exi_volatile_dev:1;
5402f172c55SRobert Thurlow 	unsigned		exi_moved:1;
541*0dfe541eSEvan Layton 	int			exi_id;
542*0dfe541eSEvan Layton 	avl_node_t		exi_id_link;
543*0dfe541eSEvan Layton 	/*
544*0dfe541eSEvan Layton 	 * Soft-reference/backpointer to zone's nfs_export_t.
545*0dfe541eSEvan Layton 	 * This allows us access to the zone's rootvp (stored in
546*0dfe541eSEvan Layton 	 * exi_ne->exi_root->exi_vp) even if the current thread isn't in
547*0dfe541eSEvan Layton 	 * same-zone context.
548*0dfe541eSEvan Layton 	 */
549*0dfe541eSEvan Layton 	struct nfs_export	*exi_ne;
5507c478bd9Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST
5517c478bd9Sstevel@tonic-gate 	uint32_t		exi_volatile_id;
5527c478bd9Sstevel@tonic-gate 	struct ex_vol_rename	*exi_vol_rename;
5537c478bd9Sstevel@tonic-gate 	kmutex_t		exi_vol_rename_lock;
554*0dfe541eSEvan Layton #endif /* VOLATILE_FH_TEST -- keep last! */
5557c478bd9Sstevel@tonic-gate };
5567c478bd9Sstevel@tonic-gate 
557af9f9769Sjasmith typedef struct exportinfo exportinfo_t;
558af9f9769Sjasmith typedef struct exportdata exportdata_t;
559af9f9769Sjasmith typedef struct secinfo secinfo_t;
560af9f9769Sjasmith 
5617c478bd9Sstevel@tonic-gate /*
5627c478bd9Sstevel@tonic-gate  * exp_visible is a visible list per filesystem. It is for filesystems
5637c478bd9Sstevel@tonic-gate  * that may need a limited view of its contents. A pseudo export and
5647c478bd9Sstevel@tonic-gate  * a real export at the mount point (VROOT) which has a subtree shared
5657c478bd9Sstevel@tonic-gate  * has a visible list.
5667c478bd9Sstevel@tonic-gate  *
5674a695956SMarcel Telka  * The exi_visible field is NULL for normal, non-pseudo filesystems
5687c478bd9Sstevel@tonic-gate  * which do not have any subtree exported. If the field is non-null,
5697c478bd9Sstevel@tonic-gate  * it points to a list of visible entries, identified by vis_fid and/or
5707c478bd9Sstevel@tonic-gate  * vis_ino. The presence of a "visible" list means that if this export
5717c478bd9Sstevel@tonic-gate  * can only have a limited view, it can only view the entries in the
5727c478bd9Sstevel@tonic-gate  * exp_visible list. The directories in the fid list comprise paths that
5737c478bd9Sstevel@tonic-gate  * lead to exported directories.
5747c478bd9Sstevel@tonic-gate  *
5757c478bd9Sstevel@tonic-gate  * The vis_count field records the number of paths in this filesystem
5767c478bd9Sstevel@tonic-gate  * that use this directory. The vis_exported field is non-zero if the
5777c478bd9Sstevel@tonic-gate  * entry is an exported directory (leaf node).
578c076b414SPavel Filipensky  *
579c076b414SPavel Filipensky  * exp_visible itself is not reference counted. Each exp_visible is
580c076b414SPavel Filipensky  * referenced twice:
581c076b414SPavel Filipensky  * 1) from treenode::tree_vis
582c076b414SPavel Filipensky  * 2) linked from exportinfo::exi_visible
583c076b414SPavel Filipensky  * The 'owner' of exp_visible is the exportinfo structure. exp_visible should
584c076b414SPavel Filipensky  * be always freed only from exportinfo_t, never from treenode::tree_vis.
5857c478bd9Sstevel@tonic-gate  */
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate struct exp_visible {
5887c478bd9Sstevel@tonic-gate 	vnode_t			*vis_vp;
5897c478bd9Sstevel@tonic-gate 	fid_t			vis_fid;
5907c478bd9Sstevel@tonic-gate 	u_longlong_t		vis_ino;
5917c478bd9Sstevel@tonic-gate 	int			vis_count;
5927c478bd9Sstevel@tonic-gate 	int			vis_exported;
5937c478bd9Sstevel@tonic-gate 	struct exp_visible	*vis_next;
594af9f9769Sjasmith 	struct secinfo		*vis_secinfo;
595af9f9769Sjasmith 	int			vis_seccnt;
5964a695956SMarcel Telka 	timespec_t		vis_change;
5977c478bd9Sstevel@tonic-gate };
598af9f9769Sjasmith typedef struct exp_visible exp_visible_t;
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate #define	PSEUDO(exi)	((exi)->exi_export.ex_flags & EX_PSEUDO)
6010616fd7fSPavel Filipensky #define	EXP_LINKED(exi)	((exi)->fid_hash.bckt != NULL)
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate #define	EQFSID(fsidp1, fsidp2)	\
6047c478bd9Sstevel@tonic-gate 	(((fsidp1)->val[0] == (fsidp2)->val[0]) && \
6057c478bd9Sstevel@tonic-gate 	    ((fsidp1)->val[1] == (fsidp2)->val[1]))
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate #define	EQFID(fidp1, fidp2)	\
6087c478bd9Sstevel@tonic-gate 	((fidp1)->fid_len == (fidp2)->fid_len && \
6097c46fb7fSek 	    bcmp((char *)(fidp1)->fid_data, (char *)(fidp2)->fid_data, \
6107c478bd9Sstevel@tonic-gate 	    (uint_t)(fidp1)->fid_len) == 0)
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate #define	exportmatch(exi, fsid, fid)	\
6137c478bd9Sstevel@tonic-gate 	(EQFSID(&(exi)->exi_fsid, (fsid)) && EQFID(&(exi)->exi_fid, (fid)))
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate /*
6167c478bd9Sstevel@tonic-gate  * Returns true iff exported filesystem is read-only to the given host.
6177c478bd9Sstevel@tonic-gate  *
6187c478bd9Sstevel@tonic-gate  * Note:  this macro should be as fast as possible since it's called
6197c478bd9Sstevel@tonic-gate  * on each NFS modification request.
6207c478bd9Sstevel@tonic-gate  */
6215cb0d679SMarcel Telka #define	rdonly(ro, vp)	((ro) || vn_is_readonly(vp))
6225cb0d679SMarcel Telka #define	rdonly4(req, cs)  \
6235cb0d679SMarcel Telka 	(vn_is_readonly((cs)->vp) || \
6245cb0d679SMarcel Telka 	    (nfsauth4_access((cs)->exi, (cs)->vp, (req), (cs)->basecr, NULL, \
62589621fe1SMarcel Telka 	    NULL, NULL, NULL) & (NFSAUTH_RO | NFSAUTH_LIMITED)))
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate extern int	nfsauth4_access(struct exportinfo *, vnode_t *,
62889621fe1SMarcel Telka     struct svc_req *, cred_t *, uid_t *, gid_t *, uint_t *, gid_t **);
6297c478bd9Sstevel@tonic-gate extern int	nfsauth4_secinfo_access(struct exportinfo *,
63089621fe1SMarcel Telka     struct svc_req *, int, int, cred_t *);
63171da0c32SMarcel Telka extern int	nfsauth_cache_clnt_compar(const void *, const void *);
6327c478bd9Sstevel@tonic-gate extern int	nfs_fhbcmp(char *, char *, int);
633*0dfe541eSEvan Layton extern void	nfs_exportinit(void);
6347c478bd9Sstevel@tonic-gate extern void	nfs_exportfini(void);
635*0dfe541eSEvan Layton extern void	nfs_export_zone_init(nfs_globals_t *);
636*0dfe541eSEvan Layton extern void	nfs_export_zone_fini(nfs_globals_t *);
637*0dfe541eSEvan Layton extern void	nfs_export_zone_shutdown(nfs_globals_t *);
638*0dfe541eSEvan Layton extern int	nfs_export_get_rootfh(nfs_globals_t *);
6395cb0d679SMarcel Telka extern int	chk_clnt_sec(struct exportinfo *, struct svc_req *);
6407c478bd9Sstevel@tonic-gate extern int	makefh(fhandle_t *, struct vnode *, struct exportinfo *);
6417c478bd9Sstevel@tonic-gate extern int	makefh_ol(fhandle_t *, struct exportinfo *, uint_t);
6427c478bd9Sstevel@tonic-gate extern int	makefh3(nfs_fh3 *, struct vnode *, struct exportinfo *);
6437c478bd9Sstevel@tonic-gate extern int	makefh3_ol(nfs_fh3 *, struct exportinfo *, uint_t);
6447c478bd9Sstevel@tonic-gate extern vnode_t *nfs_fhtovp(fhandle_t *, struct exportinfo *);
6457c478bd9Sstevel@tonic-gate extern vnode_t *nfs3_fhtovp(nfs_fh3 *, struct exportinfo *);
6467c478bd9Sstevel@tonic-gate extern struct	exportinfo *checkexport(fsid_t *, struct fid *);
6475cb0d679SMarcel Telka extern struct	exportinfo *checkexport4(fsid_t *, struct fid *, vnode_t *);
6483ccecb66SThomas Haynes extern void	exi_hold(struct exportinfo *);
6497c478bd9Sstevel@tonic-gate extern void	exi_rele(struct exportinfo *);
6507c478bd9Sstevel@tonic-gate extern struct exportinfo *nfs_vptoexi(vnode_t *, vnode_t *, cred_t *, int *,
6517c478bd9Sstevel@tonic-gate     int *, bool_t);
6527c478bd9Sstevel@tonic-gate extern int	nfs_check_vpexi(vnode_t *, vnode_t *, cred_t *,
6537c478bd9Sstevel@tonic-gate 			struct exportinfo **);
654*0dfe541eSEvan Layton extern vnode_t *untraverse(vnode_t *, vnode_t *);
6552f172c55SRobert Thurlow extern int	vn_is_nfs_reparse(vnode_t *, cred_t *);
6562f172c55SRobert Thurlow extern int	client_is_downrev(struct svc_req *);
6572f172c55SRobert Thurlow extern char    *build_symlink(vnode_t *, cred_t *, size_t *);
6587c478bd9Sstevel@tonic-gate 
659*0dfe541eSEvan Layton extern fhandle_t nullfh2;	/* for comparing V2 filehandles */
660*0dfe541eSEvan Layton 
661*0dfe541eSEvan Layton typedef struct nfs_export {
662*0dfe541eSEvan Layton 	/* Root of nfs pseudo namespace */
663*0dfe541eSEvan Layton 	treenode_t *ns_root;
664*0dfe541eSEvan Layton 
665*0dfe541eSEvan Layton 	nfs_globals_t		*ne_globals;	/* "up" pointer */
666*0dfe541eSEvan Layton 
667*0dfe541eSEvan Layton 	struct exportinfo *exptable_path_hash[PKP_HASH_SIZE];
668*0dfe541eSEvan Layton 	struct exportinfo *exptable[EXPTABLESIZE];
669*0dfe541eSEvan Layton 
670*0dfe541eSEvan Layton 	/*
671*0dfe541eSEvan Layton 	 * Read/Write lock that protects the exportinfo list.  This lock
672*0dfe541eSEvan Layton 	 * must be held when searching or modifiying the exportinfo list.
673*0dfe541eSEvan Layton 	 */
674*0dfe541eSEvan Layton 	krwlock_t exported_lock;
675*0dfe541eSEvan Layton 
676*0dfe541eSEvan Layton 	/* "public" and default (root) location for public filehandle */
677*0dfe541eSEvan Layton 	struct exportinfo *exi_public;
678*0dfe541eSEvan Layton 	struct exportinfo *exi_root;
679*0dfe541eSEvan Layton 	/* For checking default public file handle */
680*0dfe541eSEvan Layton 	fid_t exi_rootfid;
681*0dfe541eSEvan Layton 	/* For comparing V2 filehandles */
682*0dfe541eSEvan Layton 	fhandle_t nullfh2;
683*0dfe541eSEvan Layton 
684*0dfe541eSEvan Layton 	/* The change attribute value of the root of nfs pseudo namespace */
685*0dfe541eSEvan Layton 	timespec_t ns_root_change;
686*0dfe541eSEvan Layton } nfs_export_t;
687*0dfe541eSEvan Layton 
6887c478bd9Sstevel@tonic-gate /*
6897c478bd9Sstevel@tonic-gate  * Functions that handle the NFSv4 server namespace
6907c478bd9Sstevel@tonic-gate  */
6913f238301SPavel Filipensky extern exportinfo_t *vis2exi(treenode_t *);
6927c478bd9Sstevel@tonic-gate extern int	treeclimb_export(struct exportinfo *);
693*0dfe541eSEvan Layton extern void	treeclimb_unexport(nfs_export_t *, struct exportinfo *);
6947c478bd9Sstevel@tonic-gate extern int	nfs_visible(struct exportinfo *, vnode_t *, int *);
6954a695956SMarcel Telka extern int	nfs_visible_inode(struct exportinfo *, ino64_t,
696*0dfe541eSEvan Layton 		    struct exp_visible **);
6977c478bd9Sstevel@tonic-gate extern int	has_visible(struct exportinfo *, vnode_t *);
6987c478bd9Sstevel@tonic-gate extern void	free_visible(struct exp_visible *);
6997c478bd9Sstevel@tonic-gate extern int	nfs_exported(struct exportinfo *, vnode_t *);
700*0dfe541eSEvan Layton extern struct exportinfo *pseudo_exportfs(nfs_export_t *, vnode_t *, fid_t *,
701*0dfe541eSEvan Layton 		    struct exp_visible *, struct exportdata *);
7025cb0d679SMarcel Telka extern int	vop_fid_pseudo(vnode_t *, fid_t *);
7037c478bd9Sstevel@tonic-gate extern int	nfs4_vget_pseudo(struct exportinfo *, vnode_t **, fid_t *);
7044a695956SMarcel Telka extern bool_t	nfs_visible_change(struct exportinfo *, vnode_t *,
705*0dfe541eSEvan Layton 		    timespec_t *);
706*0dfe541eSEvan Layton extern void	tree_update_change(nfs_export_t *, treenode_t *, timespec_t *);
707*0dfe541eSEvan Layton extern void	rfs4_clean_state_exi(nfs_export_t *, struct exportinfo *);
708*0dfe541eSEvan Layton 
7097c478bd9Sstevel@tonic-gate /*
7107c478bd9Sstevel@tonic-gate  * Functions that handle the NFSv4 server namespace security flavors
7117c478bd9Sstevel@tonic-gate  * information.
7127c478bd9Sstevel@tonic-gate  */
7137c478bd9Sstevel@tonic-gate extern void	srv_secinfo_exp2pseu(struct exportdata *, struct exportdata *);
714af9f9769Sjasmith extern void	srv_secinfo_list_free(struct secinfo *, int);
7157c478bd9Sstevel@tonic-gate 
716*0dfe541eSEvan Layton extern nfs_export_t *nfs_get_export();
717*0dfe541eSEvan Layton extern void	export_link(nfs_export_t *, struct exportinfo *);
718*0dfe541eSEvan Layton extern void	export_unlink(nfs_export_t *, struct exportinfo *);
719*0dfe541eSEvan Layton 
7207c478bd9Sstevel@tonic-gate /*
721*0dfe541eSEvan Layton  * exi_id support
7227c478bd9Sstevel@tonic-gate  */
723*0dfe541eSEvan Layton extern kmutex_t  nfs_exi_id_lock;
724*0dfe541eSEvan Layton extern avl_tree_t exi_id_tree;
725*0dfe541eSEvan Layton extern int exi_id_get_next(void);
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate /*
7287c478bd9Sstevel@tonic-gate  * Two macros for identifying public filehandles.
7297c478bd9Sstevel@tonic-gate  * A v2 public filehandle is 32 zero bytes.
7307c478bd9Sstevel@tonic-gate  * A v3 public filehandle is zero length.
7317c478bd9Sstevel@tonic-gate  */
7327c478bd9Sstevel@tonic-gate #define	PUBLIC_FH2(fh) \
7337c478bd9Sstevel@tonic-gate 	((fh)->fh_fsid.val[1] == 0 && \
7347c478bd9Sstevel@tonic-gate 	bcmp((fh), &nullfh2, sizeof (fhandle_t)) == 0)
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate #define	PUBLIC_FH3(fh) \
7377c478bd9Sstevel@tonic-gate 	((fh)->fh3_length == 0)
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate extern int	makefh4(nfs_fh4 *, struct vnode *, struct exportinfo *);
7407c478bd9Sstevel@tonic-gate extern vnode_t *nfs4_fhtovp(nfs_fh4 *, struct exportinfo *, nfsstat4 *);
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate #endif
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate #endif	/* _NFS_EXPORT_H */
749