nfs.h revision 221523
1217044Snwhitehorn/*-
2265871Snwhitehorn * Copyright (c) 1989, 1993
3217044Snwhitehorn *	The Regents of the University of California.  All rights reserved.
4217044Snwhitehorn *
5217044Snwhitehorn * This code is derived from software contributed to Berkeley by
6217044Snwhitehorn * Rick Macklem at The University of Guelph.
7217044Snwhitehorn *
8217044Snwhitehorn * Redistribution and use in source and binary forms, with or without
9217044Snwhitehorn * modification, are permitted provided that the following conditions
10217044Snwhitehorn * are met:
11217044Snwhitehorn * 1. Redistributions of source code must retain the above copyright
12217044Snwhitehorn *    notice, this list of conditions and the following disclaimer.
13217044Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright
14217044Snwhitehorn *    notice, this list of conditions and the following disclaimer in the
15217044Snwhitehorn *    documentation and/or other materials provided with the distribution.
16217044Snwhitehorn * 4. Neither the name of the University nor the names of its contributors
17217044Snwhitehorn *    may be used to endorse or promote products derived from this software
18217044Snwhitehorn *    without specific prior written permission.
19217044Snwhitehorn *
20217044Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21217044Snwhitehorn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22217044Snwhitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23217044Snwhitehorn * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24217044Snwhitehorn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25217044Snwhitehorn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26217044Snwhitehorn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27217044Snwhitehorn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28217044Snwhitehorn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29217044Snwhitehorn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30217044Snwhitehorn * SUCH DAMAGE.
31217044Snwhitehorn *
32217044Snwhitehorn * $FreeBSD: head/sys/fs/nfs/nfs.h 221523 2011-05-06 13:11:50Z mav $
33217044Snwhitehorn */
34217044Snwhitehorn
35217044Snwhitehorn#ifndef _NFS_NFS_H_
36217044Snwhitehorn#define	_NFS_NFS_H_
37217044Snwhitehorn/*
38217044Snwhitehorn * Tunable constants for nfs
39217044Snwhitehorn */
40217044Snwhitehorn
41217044Snwhitehorn#define	NFS_MAXIOVEC	34
42217044Snwhitehorn#define	NFS_TICKINTVL	500		/* Desired time for a tick (msec) */
43217044Snwhitehorn#define	NFS_HZ		(hz / nfscl_ticks) /* Ticks/sec */
44217044Snwhitehorn#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
45265871Snwhitehorn#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
46265871Snwhitehorn#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
47265871Snwhitehorn#define	NFS_TCPTIMEO	300		/* TCP timeout */
48217044Snwhitehorn#define	NFS_MAXRCVTIMEO	60		/* 1 minute in seconds */
49217044Snwhitehorn#define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
50217044Snwhitehorn#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
51217044Snwhitehorn#define	NFSV4_CALLBACKTIMEO (2 * NFS_HZ) /* Timeout in ticks */
52217044Snwhitehorn#define	NFSV4_CALLBACKRETRY 5		/* Number of retries before failure */
53217044Snwhitehorn#define	NFSV4_CBRETRYCNT 4		/* # of CBRecall retries upon err */
54217044Snwhitehorn#define	NFSV4_UPCALLTIMEO (15 * NFS_HZ)	/* Timeout in ticks for upcalls */
55217044Snwhitehorn					/* to gssd or nfsuserd */
56217044Snwhitehorn#define	NFSV4_UPCALLRETRY 4		/* Number of retries before failure */
57217044Snwhitehorn#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
58217044Snwhitehorn#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
59265871Snwhitehorn#define	NFS_RETRANS_TCP	2		/* Num of retrans for TCP soft mounts */
60265871Snwhitehorn#define	NFS_MAXGRPS	16		/* Max. size of groups list */
61217044Snwhitehorn#define	NFS_TRYLATERDEL	15		/* Maximum delay timeout (sec) */
62217044Snwhitehorn#ifndef NFS_REMOVETIMEO
63217044Snwhitehorn#define	NFS_REMOVETIMEO 15  /* # sec to wait for delegret in local syscall */
64265871Snwhitehorn#endif
65217044Snwhitehorn#ifndef NFS_MINATTRTIMO
66228689Snwhitehorn#define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
67228689Snwhitehorn#endif
68228689Snwhitehorn#ifndef NFS_MAXATTRTIMO
69228689Snwhitehorn#define	NFS_MAXATTRTIMO 60
70228689Snwhitehorn#endif
71228689Snwhitehorn#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
72217044Snwhitehorn#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
73217044Snwhitehorn#define	NFS_READDIRSIZE	8192		/* Def. readdir size */
74265871Snwhitehorn#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
75265871Snwhitehorn#define	NFS_MAXRAHEAD	16		/* Max. read ahead # blocks */
76265871Snwhitehorn#define	NFS_MAXASYNCDAEMON 	64	/* Max. number async_daemons runnable */
77265871Snwhitehorn#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
78265871Snwhitehorn#ifndef	NFSRV_LEASE
79270411Sdumbbell#define	NFSRV_LEASE		120	/* Lease time in seconds for V4 */
80268895Snwhitehorn#endif					/* assigned to nfsrv_lease */
81268895Snwhitehorn#ifndef NFSRV_STALELEASE
82265871Snwhitehorn#define	NFSRV_STALELEASE	(5 * nfsrv_lease)
83265871Snwhitehorn#endif
84217044Snwhitehorn#ifndef NFSRV_MOULDYLEASE
85217044Snwhitehorn#define	NFSRV_MOULDYLEASE	604800	/* One week (in sec) */
86265871Snwhitehorn#endif
87217044Snwhitehorn#ifndef NFSCLIENTHASHSIZE
88217044Snwhitehorn#define	NFSCLIENTHASHSIZE	20	/* Size of server client hash table */
89217044Snwhitehorn#endif
90265871Snwhitehorn#ifndef NFSLOCKHASHSIZE
91217044Snwhitehorn#define	NFSLOCKHASHSIZE		20	/* Size of server nfslock hash table */
92217044Snwhitehorn#endif
93217044Snwhitehorn#define	NFSSTATEHASHSIZE	10	/* Size of server stateid hash table */
94217044Snwhitehorn#ifndef NFSUSERHASHSIZE
95217044Snwhitehorn#define	NFSUSERHASHSIZE		30	/* Size of user id hash table */
96217044Snwhitehorn#endif
97217044Snwhitehorn#ifndef NFSGROUPHASHSIZE
98217044Snwhitehorn#define	NFSGROUPHASHSIZE	5	/* Size of group id hash table */
99217044Snwhitehorn#endif
100217044Snwhitehorn#ifndef	NFSCLDELEGHIGHWATER
101217044Snwhitehorn#define	NFSCLDELEGHIGHWATER	10000	/* limit for client delegations */
102217044Snwhitehorn#endif
103217044Snwhitehorn#ifndef NFSNOOPEN			/* Inactive open owner (sec) */
104217044Snwhitehorn#define	NFSNOOPEN		120
105217044Snwhitehorn#endif
106217044Snwhitehorn#define	NFSRV_LEASEDELTA	15	/* # of seconds to delay beyond lease */
107217044Snwhitehorn#define	NFS_IDMAXSIZE		4	/* max sizeof (in_addr_t) */
108217044Snwhitehorn#ifndef NFSRVCACHE_UDPTIMEOUT
109217044Snwhitehorn#define	NFSRVCACHE_UDPTIMEOUT	30	/* # of sec to hold cached rpcs(udp) */
110217044Snwhitehorn#endif
111217044Snwhitehorn#ifndef NFSRVCACHE_UDPHIGHWATER
112217044Snwhitehorn#define	NFSRVCACHE_UDPHIGHWATER	500	/* Max # of udp cache entries */
113217044Snwhitehorn#endif
114217044Snwhitehorn#ifndef NFSRVCACHE_TCPTIMEOUT
115217044Snwhitehorn#define	NFSRVCACHE_TCPTIMEOUT	(3600*12) /*#of sec to hold cached rpcs(tcp) */
116265871Snwhitehorn#endif
117217044Snwhitehorn#ifndef	NFSRVCACHE_FLOODLEVEL
118217044Snwhitehorn#define	NFSRVCACHE_FLOODLEVEL	16384	/* Very high water mark for cache */
119265871Snwhitehorn#endif
120217044Snwhitehorn#ifndef	NFSRV_CLIENTHIGHWATER
121217044Snwhitehorn#define	NFSRV_CLIENTHIGHWATER	1000
122217044Snwhitehorn#endif
123217044Snwhitehorn#ifndef	NFSRV_MAXDUMPLIST
124217044Snwhitehorn#define	NFSRV_MAXDUMPLIST	10000
125228689Snwhitehorn#endif
126217044Snwhitehorn#ifndef NFS_ACCESSCACHESIZE
127217044Snwhitehorn#define	NFS_ACCESSCACHESIZE	8
128228689Snwhitehorn#endif
129228689Snwhitehorn#define	NFSV4_CBPORT	7745		/* Callback port for testing */
130217044Snwhitehorn
131217044Snwhitehorn/*
132217044Snwhitehorn * This macro defines the high water mark for issuing V4 delegations.
133217044Snwhitehorn * (It is currently set at a conservative 20% of NFSRV_V4STATELIMIT. This
134217044Snwhitehorn *  may want to increase when clients can make more effective use of
135217044Snwhitehorn *  delegations.)
136217044Snwhitehorn */
137217044Snwhitehorn#define	NFSRV_V4DELEGLIMIT(c) (((c) * 5) > NFSRV_V4STATELIMIT)
138217044Snwhitehorn
139217044Snwhitehorn#define	NFS_READDIRBLKSIZ	DIRBLKSIZ	/* Minimal nm_readdirsize */
140217044Snwhitehorn
141265871Snwhitehorn/*
142265871Snwhitehorn * Oddballs
143265871Snwhitehorn */
144265871Snwhitehorn#define	NFS_CMPFH(n, f, s) 						\
145265871Snwhitehorn    ((n)->n_fhp->nfh_len == (s) && !NFSBCMP((n)->n_fhp->nfh_fh, (caddr_t)(f), (s)))
146217044Snwhitehorn#define	NFSRV_CMPFH(nf, ns, f, s) 					\
147228689Snwhitehorn	((ns) == (s) && !NFSBCMP((caddr_t)(nf), (caddr_t)(f), (s)))
148217044Snwhitehorn#define	NFS_CMPTIME(t1, t2) 						\
149228689Snwhitehorn	((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec == (t2).tv_nsec)
150217044Snwhitehorn#define	NFS_SETTIME(t) do { 						\
151217044Snwhitehorn	(t).tv_sec = time.tv_sec; (t).tv_nsec = 1000 * time.tv_usec; } while (0)
152265871Snwhitehorn#define	NFS_SRVMAXDATA(n) 						\
153217044Snwhitehorn		(((n)->nd_flag & (ND_NFSV3 | ND_NFSV4)) ? 		\
154217044Snwhitehorn		 NFS_MAXDATA : NFS_V2MAXDATA)
155217044Snwhitehorn#define	NFS64BITSSET	0xffffffffffffffffull
156217044Snwhitehorn#define	NFS64BITSMINUS1	0xfffffffffffffffeull
157217044Snwhitehorn
158217044Snwhitehorn/*
159265871Snwhitehorn * Structures for the nfssvc(2) syscall. Not that anyone but nfsd, mount_nfs
160217044Snwhitehorn * and nfsloaduser should ever try and use it.
161217044Snwhitehorn */
162217044Snwhitehornstruct nfsd_addsock_args {
163265871Snwhitehorn	int	sock;		/* Socket to serve */
164265871Snwhitehorn	caddr_t	name;		/* Client addr for connection based sockets */
165217044Snwhitehorn	int	namelen;	/* Length of name */
166265871Snwhitehorn};
167265871Snwhitehorn
168265871Snwhitehorn/*
169265871Snwhitehorn * nfsd argument for new krpc.
170265871Snwhitehorn */
171265871Snwhitehornstruct nfsd_nfsd_args {
172265871Snwhitehorn	const char *principal;	/* GSS-API service principal name */
173217044Snwhitehorn	int	minthreads;	/* minimum service thread count */
174217044Snwhitehorn	int	maxthreads;	/* maximum service thread count */
175265871Snwhitehorn};
176217044Snwhitehorn
177217044Snwhitehorn/*
178265871Snwhitehorn * Arguments for use by the callback daemon.
179217044Snwhitehorn */
180265871Snwhitehornstruct nfsd_nfscbd_args {
181269791Sdumbbell	const char *principal;	/* GSS-API service principal name */
182269791Sdumbbell};
183217044Snwhitehorn
184265871Snwhitehornstruct nfscbd_args {
185228689Snwhitehorn	int	sock;		/* Socket to serve */
186228689Snwhitehorn	caddr_t	name;		/* Client addr for connection based sockets */
187228689Snwhitehorn	int	namelen;	/* Length of name */
188228689Snwhitehorn	u_short	port;		/* Port# for callbacks */
189228689Snwhitehorn};
190265871Snwhitehorn
191269620Snwhitehornstruct nfsd_idargs {
192217044Snwhitehorn	int		nid_flag;	/* Flags (see below) */
193265871Snwhitehorn	uid_t		nid_uid;	/* user/group id */
194217044Snwhitehorn	gid_t		nid_gid;
195217044Snwhitehorn	int		nid_usermax;	/* Upper bound on user name cache */
196	int		nid_usertimeout;/* User name timeout (minutes) */
197	u_char		*nid_name;	/* Name */
198	int		nid_namelen;	/* and its length */
199};
200
201struct nfsd_clid {
202	int		nclid_idlen;	/* Length of client id */
203	u_char		nclid_id[NFSV4_OPAQUELIMIT]; /* and name */
204};
205
206struct nfsd_dumplist {
207	int		ndl_size;	/* Number of elements */
208	void		*ndl_list;	/* and the list of elements */
209};
210
211struct nfsd_dumpclients {
212	u_int32_t	ndcl_flags;		/* LCL_xxx flags */
213	u_int32_t	ndcl_nopenowners;	/* Number of openowners */
214	u_int32_t	ndcl_nopens;		/* and opens */
215	u_int32_t	ndcl_nlockowners;	/* and of lockowners */
216	u_int32_t	ndcl_nlocks;		/* and of locks */
217	u_int32_t	ndcl_ndelegs;		/* and of delegations */
218	u_int32_t	ndcl_nolddelegs;	/* and old delegations */
219	sa_family_t	ndcl_addrfam;		/* Callback address */
220	union {
221		struct in_addr sin_addr;
222		struct in6_addr sin6_addr;
223	} ndcl_cbaddr;
224	struct nfsd_clid ndcl_clid;	/* and client id */
225};
226
227struct nfsd_dumplocklist {
228	char		*ndllck_fname;	/* File Name */
229	int		ndllck_size;	/* Number of elements */
230	void		*ndllck_list;	/* and the list of elements */
231};
232
233struct nfsd_dumplocks {
234	u_int32_t	ndlck_flags;		/* state flags NFSLCK_xxx */
235	nfsv4stateid_t	ndlck_stateid;		/* stateid */
236	u_int64_t	ndlck_first;		/* lock byte range */
237	u_int64_t	ndlck_end;
238	struct nfsd_clid ndlck_owner;		/* Owner of open/lock */
239	sa_family_t	ndlck_addrfam;		/* Callback address */
240	union {
241		struct in_addr sin_addr;
242		struct in6_addr sin6_addr;
243	} ndlck_cbaddr;
244	struct nfsd_clid ndlck_clid;	/* and client id */
245};
246
247/*
248 * Structure for referral information.
249 */
250struct nfsreferral {
251	u_char		*nfr_srvlist;	/* List of servers */
252	int		nfr_srvcnt;	/* number of servers */
253	vnode_t		nfr_vp;	/* vnode for referral */
254	u_int32_t	nfr_dfileno;	/* assigned dir inode# */
255};
256
257/*
258 * Flags for lc_flags and opsflags for nfsrv_getclient().
259 */
260#define	LCL_NEEDSCONFIRM	0x00000001
261#define	LCL_DONTCLEAN		0x00000002
262#define	LCL_WAKEUPWANTED	0x00000004
263#define	LCL_TCPCALLBACK		0x00000008
264#define	LCL_CALLBACKSON		0x00000010
265#define	LCL_INDEXNOTOK		0x00000020
266#define	LCL_STAMPEDSTABLE	0x00000040
267#define	LCL_EXPIREIT		0x00000080
268#define	LCL_CBDOWN		0x00000100
269#define	LCL_KERBV		0x00000400
270#define	LCL_NAME		0x00000800
271#define	LCL_NEEDSCBNULL		0x00001000
272#define	LCL_GSSINTEGRITY	0x00002000
273#define	LCL_GSSPRIVACY		0x00004000
274#define	LCL_ADMINREVOKED	0x00008000
275
276#define	LCL_GSS		LCL_KERBV	/* Or of all mechs */
277
278/*
279 * Bits for flags in nfslock and nfsstate.
280 * The access, deny, NFSLCK_READ and NFSLCK_WRITE bits must be defined as
281 * below, in the correct order, so the shifts work for tests.
282 */
283#define	NFSLCK_READACCESS	0x00000001
284#define	NFSLCK_WRITEACCESS	0x00000002
285#define	NFSLCK_ACCESSBITS	(NFSLCK_READACCESS | NFSLCK_WRITEACCESS)
286#define	NFSLCK_SHIFT		2
287#define	NFSLCK_READDENY		0x00000004
288#define	NFSLCK_WRITEDENY	0x00000008
289#define	NFSLCK_DENYBITS		(NFSLCK_READDENY | NFSLCK_WRITEDENY)
290#define	NFSLCK_SHAREBITS 						\
291    (NFSLCK_READACCESS|NFSLCK_WRITEACCESS|NFSLCK_READDENY|NFSLCK_WRITEDENY)
292#define	NFSLCK_LOCKSHIFT	4
293#define	NFSLCK_READ		0x00000010
294#define	NFSLCK_WRITE		0x00000020
295#define	NFSLCK_BLOCKING		0x00000040
296#define	NFSLCK_RECLAIM		0x00000080
297#define	NFSLCK_OPENTOLOCK	0x00000100
298#define	NFSLCK_TEST		0x00000200
299#define	NFSLCK_LOCK		0x00000400
300#define	NFSLCK_UNLOCK		0x00000800
301#define	NFSLCK_OPEN		0x00001000
302#define	NFSLCK_CLOSE		0x00002000
303#define	NFSLCK_CHECK		0x00004000
304#define	NFSLCK_RELEASE		0x00008000
305#define	NFSLCK_NEEDSCONFIRM	0x00010000
306#define	NFSLCK_CONFIRM		0x00020000
307#define	NFSLCK_DOWNGRADE	0x00040000
308#define	NFSLCK_DELEGREAD	0x00080000
309#define	NFSLCK_DELEGWRITE	0x00100000
310#define	NFSLCK_DELEGCUR		0x00200000
311#define	NFSLCK_DELEGPREV	0x00400000
312#define	NFSLCK_OLDDELEG		0x00800000
313#define	NFSLCK_DELEGRECALL	0x01000000
314#define	NFSLCK_SETATTR		0x02000000
315#define	NFSLCK_DELEGPURGE	0x04000000
316#define	NFSLCK_DELEGRETURN	0x08000000
317
318/* And bits for nid_flag */
319#define	NFSID_INITIALIZE	0x0001
320#define	NFSID_ADDUID		0x0002
321#define	NFSID_DELUID		0x0004
322#define	NFSID_ADDUSERNAME	0x0008
323#define	NFSID_DELUSERNAME	0x0010
324#define	NFSID_ADDGID		0x0020
325#define	NFSID_DELGID		0x0040
326#define	NFSID_ADDGROUPNAME	0x0080
327#define	NFSID_DELGROUPNAME	0x0100
328
329/*
330 * fs.nfs sysctl(3) identifiers
331 */
332#define	NFS_NFSSTATS	1		/* struct: struct nfsstats */
333
334#define	FS_NFS_NAMES { 							\
335		       { 0, 0 }, 					\
336		       { "nfsstats", CTLTYPE_STRUCT }, 			\
337}
338
339/*
340 * Here is the definition of the attribute bits array and macros that
341 * manipulate it.
342 * THE MACROS MUST BE MANUALLY MODIFIED IF NFSATTRBIT_MAXWORDS CHANGES!!
343 * It is (NFSATTRBIT_MAX + 31) / 32.
344 */
345#define	NFSATTRBIT_MAXWORDS	2
346
347typedef struct {
348	u_int32_t bits[NFSATTRBIT_MAXWORDS];
349} nfsattrbit_t;
350
351#define	NFSZERO_ATTRBIT(b) do { (b)->bits[0] = 0; (b)->bits[1] = 0; } while (0)
352#define	NFSSET_ATTRBIT(t, f) do { (t)->bits[0] = (f)->bits[0]; 		\
353				  (t)->bits[1] = (f)->bits[1]; } while (0)
354#define	NFSSETSUPP_ATTRBIT(b) do { 					\
355	(b)->bits[0] = NFSATTRBIT_SUPP0; 				\
356	(b)->bits[1] = (NFSATTRBIT_SUPP1 | NFSATTRBIT_SUPPSETONLY); } while (0)
357#define	NFSISSET_ATTRBIT(b, p)	((b)->bits[(p) / 32] & (1 << ((p) % 32)))
358#define	NFSSETBIT_ATTRBIT(b, p)	((b)->bits[(p) / 32] |= (1 << ((p) % 32)))
359#define	NFSCLRBIT_ATTRBIT(b, p)	((b)->bits[(p) / 32] &= ~(1 << ((p) % 32)))
360#define	NFSCLRALL_ATTRBIT(b, a)	do { 					\
361		(b)->bits[0] &= ~((a)->bits[0]); 			\
362		(b)->bits[1] &= ~((a)->bits[1]); 			\
363		} while (0)
364#define	NFSCLRNOT_ATTRBIT(b, a)	do { 					\
365		(b)->bits[0] &= ((a)->bits[0]); 			\
366		(b)->bits[1] &= ((a)->bits[1]); 			\
367		} while (0)
368#define	NFSCLRNOTFILLABLE_ATTRBIT(b) do { 				\
369		(b)->bits[0] &= NFSATTRBIT_SUPP0; 			\
370		(b)->bits[1] &= NFSATTRBIT_SUPP1; } while (0)
371#define	NFSCLRNOTSETABLE_ATTRBIT(b) do { 				\
372		(b)->bits[0] &= NFSATTRBIT_SETABLE0; 			\
373		(b)->bits[1] &= NFSATTRBIT_SETABLE1; } while (0)
374#define	NFSNONZERO_ATTRBIT(b)	((b)->bits[0] || (b)->bits[1])
375#define	NFSEQUAL_ATTRBIT(b, p)						\
376	((b)->bits[0] == (p)->bits[0] && (b)->bits[1] == (p)->bits[1])
377#define	NFSGETATTR_ATTRBIT(b) do { 					\
378		(b)->bits[0] = NFSATTRBIT_GETATTR0; 			\
379		(b)->bits[1] = NFSATTRBIT_GETATTR1; } while (0)
380#define	NFSWCCATTR_ATTRBIT(b) do { 					\
381		(b)->bits[0] = NFSATTRBIT_WCCATTR0; 			\
382		(b)->bits[1] = NFSATTRBIT_WCCATTR1; } while (0)
383#define	NFSWRITEGETATTR_ATTRBIT(b) do { 				\
384		(b)->bits[0] = NFSATTRBIT_WRITEGETATTR0;		\
385		(b)->bits[1] = NFSATTRBIT_WRITEGETATTR1; } while (0)
386#define	NFSCBGETATTR_ATTRBIT(b, c) do { 				\
387	(c)->bits[0] = ((b)->bits[0] & NFSATTRBIT_CBGETATTR0); 		\
388	(c)->bits[1] = ((b)->bits[1] & NFSATTRBIT_CBGETATTR1); } while (0)
389#define	NFSPATHCONF_GETATTRBIT(b) do { 					\
390		(b)->bits[0] = NFSGETATTRBIT_PATHCONF0; 		\
391		(b)->bits[1] = NFSGETATTRBIT_PATHCONF1; } while (0)
392#define	NFSSTATFS_GETATTRBIT(b)	do { 					\
393		(b)->bits[0] = NFSGETATTRBIT_STATFS0; 			\
394		(b)->bits[1] = NFSGETATTRBIT_STATFS1; } while (0)
395#define	NFSISSETSTATFS_ATTRBIT(b) 					\
396		(((b)->bits[0] & NFSATTRBIT_STATFS0) || 		\
397		 ((b)->bits[1] & NFSATTRBIT_STATFS1))
398#define	NFSCLRSTATFS_ATTRBIT(b)	do { 					\
399		(b)->bits[0] &= ~NFSATTRBIT_STATFS0; 			\
400		(b)->bits[1] &= ~NFSATTRBIT_STATFS1; } while (0)
401#define	NFSREADDIRPLUS_ATTRBIT(b) do { 					\
402		(b)->bits[0] = NFSATTRBIT_READDIRPLUS0; 		\
403		(b)->bits[1] = NFSATTRBIT_READDIRPLUS1; } while (0)
404#define	NFSREFERRAL_ATTRBIT(b) do { 					\
405		(b)->bits[0] = NFSATTRBIT_REFERRAL0;	 		\
406		(b)->bits[1] = NFSATTRBIT_REFERRAL1; } while (0)
407
408/*
409 * Store uid, gid creds that were used when the stateid was acquired.
410 * The RPC layer allows NFS_MAXGRPS + 1 groups to go out on the wire,
411 * so that's how many gets stored here.
412 */
413struct nfscred {
414	uid_t 		nfsc_uid;
415	gid_t		nfsc_groups[NFS_MAXGRPS + 1];
416	int		nfsc_ngroups;
417};
418
419/*
420 * Constants that define the file handle for the V4 root directory.
421 * (The FSID must never be used by other file systems that are exported.)
422 */
423#define	NFSV4ROOT_FSID0		((int32_t) -1)
424#define	NFSV4ROOT_FSID1		((int32_t) -1)
425#define	NFSV4ROOT_REFERRAL	((int32_t) -2)
426#define	NFSV4ROOT_INO		2	/* It's traditional */
427#define	NFSV4ROOT_GEN		1
428
429/*
430 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
431 * What should be in this set is open to debate, but I believe that since
432 * I/O system calls on ufs are never interrupted by signals the set should
433 * be minimal. My reasoning is that many current programs that use signals
434 * such as SIGALRM will not expect file I/O system calls to be interrupted
435 * by them and break.
436 */
437#if defined(_KERNEL) || defined(KERNEL)
438
439struct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
440
441/*
442 * Socket errors ignored for connectionless sockets?
443 * For now, ignore them all
444 */
445#define	NFSIGNORE_SOERROR(s, e) 					\
446		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
447		((s) & PR_CONNREQUIRED) == 0)
448
449
450/*
451 * This structure holds socket information for a connection. Used by the
452 * client and the server for callbacks.
453 */
454struct nfssockreq {
455	NFSSOCKADDR_T	nr_nam;
456	int		nr_sotype;
457	int		nr_soproto;
458	int		nr_soflags;
459	struct ucred	*nr_cred;
460	int		nr_lock;
461	NFSMUTEX_T	nr_mtx;
462	u_int32_t	nr_prog;
463	u_int32_t	nr_vers;
464	struct __rpc_client *nr_client;
465};
466
467/*
468 * And associated nr_lock bits.
469 */
470#define	NFSR_SNDLOCK		0x01
471#define	NFSR_WANTSND		0x02
472#define	NFSR_RCVLOCK		0x04
473#define	NFSR_WANTRCV		0x08
474#define	NFSR_RESERVEDPORT	0x10
475#define	NFSR_LOCALHOST		0x20
476
477/*
478 * Queue head for nfsreq's
479 */
480TAILQ_HEAD(nfsreqhead, nfsreq);
481
482/* This is the only nfsreq R_xxx flag still used. */
483#define	R_DONTRECOVER	0x00000100	/* don't initiate recovery when this
484					   rpc gets a stale state reply */
485
486/*
487 * Network address hash list element
488 */
489union nethostaddr {
490	struct in_addr	had_inet;
491	struct in6_addr had_inet6;
492};
493
494/*
495 * Structure of list of mechanisms.
496 */
497struct nfsgss_mechlist {
498	int	len;
499	const u_char	*str;
500	int	totlen;
501};
502#define	KERBV_MECH	0	/* position in list */
503
504/*
505 * This structure is used by the server for describing each request.
506 */
507struct nfsrv_descript {
508	mbuf_t			nd_mrep;	/* Request mbuf list */
509	mbuf_t			nd_md;		/* Current dissect mbuf */
510	mbuf_t			nd_mreq;	/* Reply mbuf list */
511	mbuf_t			nd_mb;		/* Current build mbuf */
512	NFSSOCKADDR_T		nd_nam;		/* and socket addr */
513	NFSSOCKADDR_T		nd_nam2;	/* return socket addr */
514	caddr_t			nd_dpos;	/* Current dissect pos */
515	caddr_t			nd_bpos;	/* Current build pos */
516	u_int16_t		nd_procnum;	/* RPC # */
517	u_int32_t		nd_flag;	/* nd_flag */
518	u_int32_t		nd_repstat;	/* Reply status */
519	int			*nd_errp;	/* Pointer to ret status */
520	u_int32_t		nd_retxid;	/* Reply xid */
521	struct nfsrvcache	*nd_rp;		/* Assoc. cache entry */
522	struct timeval		nd_starttime;	/* Time RPC initiated */
523	fhandle_t		nd_fh;		/* File handle */
524	struct ucred		*nd_cred;	/* Credentials */
525	uid_t			nd_saveduid;	/* Saved uid */
526	u_int64_t		nd_sockref;	/* Rcv socket ref# */
527	u_int64_t		nd_compref;	/* Compound RPC ref# */
528	time_t			nd_tcpconntime;	/* Time TCP connection est. */
529	nfsquad_t		nd_clientid;	/* Implied clientid */
530	int			nd_gssnamelen;	/* principal name length */
531	char			*nd_gssname;	/* principal name */
532};
533
534#define	nd_princlen	nd_gssnamelen
535#define	nd_principal	nd_gssname
536
537/* Bits for "nd_flag" */
538#define	ND_DONTSAVEREPLY 	0x00000001
539#define	ND_SAVEREPLY		0x00000002
540#define	ND_NFSV2		0x00000004
541#define	ND_NFSV3		0x00000008
542#define	ND_NFSV4		0x00000010
543#define	ND_KERBV		0x00000020
544#define	ND_GSSINTEGRITY		0x00000040
545#define	ND_GSSPRIVACY		0x00000080
546#define	ND_WINDOWVERF		0x00000100
547#define	ND_GSSINITREPLY		0x00000200
548#define	ND_STREAMSOCK		0x00000400
549#define	ND_PUBLOOKUP		0x00000800
550#define	ND_USEGSSNAME		0x00001000
551#define	ND_SAMETCPCONN		0x00002000
552#define	ND_IMPLIEDCLID		0x00004000
553#define	ND_NOMOREDATA		0x00008000
554#define	ND_V4WCCATTR		0x00010000
555#define	ND_NFSCB		0x00020000
556#define	ND_AUTHNONE		0x00040000
557#define	ND_EXAUTHSYS		0x00080000
558#define	ND_EXGSS		0x00100000
559#define	ND_EXGSSINTEGRITY	0x00200000
560#define	ND_EXGSSPRIVACY		0x00400000
561#define	ND_INCRSEQID		0x00800000
562
563/*
564 * ND_GSS should be the "or" of all GSS type authentications.
565 */
566#define	ND_GSS		(ND_KERBV)
567
568struct nfsv4_opflag {
569	int	retfh;
570	int	needscfh;
571	int	savereply;
572	int	modifyfs;
573	int	lktype;
574};
575
576/*
577 * Flags used to indicate what to do w.r.t. seqid checking.
578 */
579#define	NFSRVSEQID_FIRST	0x01
580#define	NFSRVSEQID_LAST		0x02
581#define	NFSRVSEQID_OPEN		0x04
582
583/*
584 * assign a doubly linked list to a new head
585 * and prepend one list into another.
586 */
587#define	LIST_NEWHEAD(nhead, ohead, field) do { 				\
588	if (((nhead)->lh_first = (ohead)->lh_first) != NULL) 		\
589		(ohead)->lh_first->field.le_prev = &(nhead)->lh_first; 	\
590	(ohead)->lh_first = NULL; 					\
591    } while (0)
592
593#define	LIST_PREPEND(head, phead, lelm, field) do {			\
594	if ((head)->lh_first != NULL) {					\
595		(lelm)->field.le_next = (head)->lh_first;		\
596		(lelm)->field.le_next->field.le_prev =			\
597		    &(lelm)->field.le_next;				\
598	}								\
599	(head)->lh_first = (phead)->lh_first;				\
600	(head)->lh_first->field.le_prev = &(head)->lh_first;		\
601    } while (0)
602
603/*
604 * File handle structure for client. Malloc'd to the correct length with
605 * malloc type M_NFSFH.
606 */
607struct nfsfh {
608	u_int16_t	nfh_len;	/* Length of file handle */
609	u_int8_t	nfh_fh[1];	/* and the file handle */
610};
611
612/*
613 * File handle structure for server. The NFSRV_MAXFH constant is
614 * set in nfsdport.h. I use a 32bit length, so that alignment is
615 * preserved.
616 */
617struct nfsrvfh {
618	u_int32_t	nfsrvfh_len;
619	u_int8_t	nfsrvfh_data[NFSRV_MAXFH];
620};
621
622/*
623 * This structure is used for sleep locks on the NFSv4 nfsd threads and
624 * NFSv4 client data structures.
625 */
626struct nfsv4lock {
627	u_int32_t	nfslock_usecnt;
628	u_int8_t	nfslock_lock;
629};
630#define	NFSV4LOCK_LOCK		0x01
631#define	NFSV4LOCK_LOCKWANTED	0x02
632#define	NFSV4LOCK_WANTED	0x04
633
634/*
635 * Values for the override argument for nfsvno_accchk().
636 */
637#define	NFSACCCHK_NOOVERRIDE		0
638#define	NFSACCCHK_ALLOWROOT		1
639#define	NFSACCCHK_ALLOWOWNER		2
640
641/*
642 * and values for the vpislocked argument for nfsvno_accchk().
643 */
644#define	NFSACCCHK_VPNOTLOCKED		0
645#define	NFSACCCHK_VPISLOCKED		1
646
647#endif	/* _KERNEL */
648
649#endif	/* _NFS_NFS_H */
650