xref: /netbsd/sys/fs/nfs/common/nfs.h (revision a2a6649f)
1 /*	$NetBSD: nfs.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $	*/
2 /*-
3  * Copyright (c) 1989, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Rick Macklem at The University of Guelph.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * FreeBSD: head/sys/fs/nfs/nfs.h 291527 2015-11-30 21:54:27Z rmacklem
34  * $NetBSD: nfs.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $
35  */
36 
37 #ifndef _NFS_NFS_H_
38 #define	_NFS_NFS_H_
39 /*
40  * Tunable constants for nfs
41  */
42 
43 #define	NFS_MAXIOVEC	34
44 #define	NFS_TICKINTVL	500		/* Desired time for a tick (msec) */
45 #define	NFS_HZ		(hz / nfscl_ticks) /* Ticks/sec */
46 #define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
47 #define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
48 #define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
49 #define	NFS_TCPTIMEO	300		/* TCP timeout */
50 #define	NFS_MAXRCVTIMEO	60		/* 1 minute in seconds */
51 #define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
52 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
53 #define	NFSV4_CALLBACKTIMEO (2 * NFS_HZ) /* Timeout in ticks */
54 #define	NFSV4_CALLBACKRETRY 5		/* Number of retries before failure */
55 #define	NFSV4_SLOTS	64		/* Number of slots, fore channel */
56 #define	NFSV4_CBSLOTS	8		/* Number of slots, back channel */
57 #define	NFSV4_CBRETRYCNT 4		/* # of CBRecall retries upon err */
58 #define	NFSV4_UPCALLTIMEO (15 * NFS_HZ)	/* Timeout in ticks for upcalls */
59 					/* to gssd or nfsuserd */
60 #define	NFSV4_UPCALLRETRY 4		/* Number of retries before failure */
61 #define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
62 #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
63 #define	NFS_RETRANS_TCP	2		/* Num of retrans for TCP soft mounts */
64 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
65 #define	NFS_TRYLATERDEL	15		/* Maximum delay timeout (sec) */
66 #ifndef NFS_REMOVETIMEO
67 #define	NFS_REMOVETIMEO 15  /* # sec to wait for delegret in local syscall */
68 #endif
69 #ifndef NFS_MINATTRTIMO
70 #define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
71 #endif
72 #ifndef NFS_MAXATTRTIMO
73 #define	NFS_MAXATTRTIMO 60
74 #endif
75 #if 0	/* Defined in NetBSD in machine/param.h */
76 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
77 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
78 #endif
79 #define	NFS_READDIRSIZE	8192		/* Def. readdir size */
80 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
81 #define	NFS_MAXRAHEAD	16		/* Max. read ahead # blocks */
82 #define	NFS_MAXASYNCDAEMON 	64	/* Max. number async_daemons runnable */
83 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
84 #ifndef	NFSRV_LEASE
85 #define	NFSRV_LEASE		120	/* Lease time in seconds for V4 */
86 #endif					/* assigned to nfsrv_lease */
87 #ifndef NFSRV_STALELEASE
88 #define	NFSRV_STALELEASE	(5 * nfsrv_lease)
89 #endif
90 #ifndef NFSRV_MOULDYLEASE
91 #define	NFSRV_MOULDYLEASE	604800	/* One week (in sec) */
92 #endif
93 #ifndef NFSCLIENTHASHSIZE
94 #define	NFSCLIENTHASHSIZE	20	/* Size of server client hash table */
95 #endif
96 #ifndef NFSLOCKHASHSIZE
97 #define	NFSLOCKHASHSIZE		20	/* Size of server nfslock hash table */
98 #endif
99 #ifndef NFSSESSIONHASHSIZE
100 #define	NFSSESSIONHASHSIZE	20	/* Size of server session hash table */
101 #endif
102 #define	NFSSTATEHASHSIZE	10	/* Size of server stateid hash table */
103 #ifndef	NFSCLDELEGHIGHWATER
104 #define	NFSCLDELEGHIGHWATER	10000	/* limit for client delegations */
105 #endif
106 #ifndef	NFSCLLAYOUTHIGHWATER
107 #define	NFSCLLAYOUTHIGHWATER	10000	/* limit for client pNFS layouts */
108 #endif
109 #ifndef NFSNOOPEN			/* Inactive open owner (sec) */
110 #define	NFSNOOPEN		120
111 #endif
112 #define	NFSRV_LEASEDELTA	15	/* # of seconds to delay beyond lease */
113 #define	NFS_IDMAXSIZE		4	/* max sizeof (in_addr_t) */
114 #ifndef NFSRVCACHE_UDPTIMEOUT
115 #define	NFSRVCACHE_UDPTIMEOUT	30	/* # of sec to hold cached rpcs(udp) */
116 #endif
117 #ifndef NFSRVCACHE_UDPHIGHWATER
118 #define	NFSRVCACHE_UDPHIGHWATER	500	/* Max # of udp cache entries */
119 #endif
120 #ifndef NFSRVCACHE_TCPTIMEOUT
121 #define	NFSRVCACHE_TCPTIMEOUT	(3600*12) /*#of sec to hold cached rpcs(tcp) */
122 #endif
123 #ifndef	NFSRVCACHE_FLOODLEVEL
124 #define	NFSRVCACHE_FLOODLEVEL	16384	/* Very high water mark for cache */
125 #endif
126 #ifndef	NFSRV_CLIENTHIGHWATER
127 #define	NFSRV_CLIENTHIGHWATER	1000
128 #endif
129 #ifndef	NFSRV_MAXDUMPLIST
130 #define	NFSRV_MAXDUMPLIST	10000
131 #endif
132 #ifndef NFS_ACCESSCACHESIZE
133 #define	NFS_ACCESSCACHESIZE	8
134 #endif
135 #define	NFSV4_CBPORT	7745		/* Callback port for testing */
136 
137 /*
138  * This macro defines the high water mark for issuing V4 delegations.
139  * (It is currently set at a conservative 20% of nfsrv_v4statelimit. This
140  *  may want to increase when clients can make more effective use of
141  *  delegations.)
142  */
143 #define	NFSRV_V4DELEGLIMIT(c) (((c) * 5) > nfsrv_v4statelimit)
144 
145 #define	NFS_READDIRBLKSIZ	DIRBLKSIZ	/* Minimal nm_readdirsize */
146 
147 /*
148  * Oddballs
149  */
150 #define	NFS_CMPFH(n, f, s) 						\
151     ((n)->n_fhp->nfh_len == (s) && !NFSBCMP((n)->n_fhp->nfh_fh, (void *)(f), (s)))
152 #define	NFSRV_CMPFH(nf, ns, f, s) 					\
153 	((ns) == (s) && !NFSBCMP((void *)(nf), (void *)(f), (s)))
154 #define	NFS_CMPTIME(t1, t2) 						\
155 	((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec == (t2).tv_nsec)
156 #define	NFS_SETTIME(t) do { 						\
157 	(t).tv_sec = time.tv_sec; (t).tv_nsec = 1000 * time.tv_usec; } while (0)
158 #define	NFS_SRVMAXDATA(n) 						\
159 		(((n)->nd_flag & (ND_NFSV3 | ND_NFSV4)) ? 		\
160 		 NFS_SRVMAXIO : NFS_V2MAXDATA)
161 #define	NFS64BITSSET	0xffffffffffffffffull
162 #define	NFS64BITSMINUS1	0xfffffffffffffffeull
163 
164 /*
165  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd, mount_nfs
166  * and nfsloaduser should ever try and use it.
167  */
168 struct nfsd_addsock_args {
169 	int	sock;		/* Socket to serve */
170 	char	*name;		/* Client addr for connection based sockets */
171 	int	namelen;	/* Length of name */
172 };
173 
174 /*
175  * nfsd argument for new krpc.
176  */
177 struct nfsd_nfsd_args {
178 	const char *principal;	/* GSS-API service principal name */
179 	int	minthreads;	/* minimum service thread count */
180 	int	maxthreads;	/* maximum service thread count */
181 };
182 
183 /*
184  * Arguments for use by the callback daemon.
185  */
186 struct nfsd_nfscbd_args {
187 	const char *principal;	/* GSS-API service principal name */
188 };
189 
190 struct nfscbd_args {
191 	int	sock;		/* Socket to serve */
192 	char	*name;		/* Client addr for connection based sockets */
193 	int	namelen;	/* Length of name */
194 	u_short	port;		/* Port# for callbacks */
195 };
196 
197 struct nfsd_idargs {
198 	int		nid_flag;	/* Flags (see below) */
199 	uid_t		nid_uid;	/* user/group id */
200 	gid_t		nid_gid;
201 	int		nid_usermax;	/* Upper bound on user name cache */
202 	int		nid_usertimeout;/* User name timeout (minutes) */
203 	u_char		*nid_name;	/* Name */
204 	int		nid_namelen;	/* and its length */
205 	gid_t		*nid_grps;	/* and the list */
206 	int		nid_ngroup;	/* Size of groups list */
207 };
208 
209 struct nfsd_oidargs {
210 	int		nid_flag;	/* Flags (see below) */
211 	uid_t		nid_uid;	/* user/group id */
212 	gid_t		nid_gid;
213 	int		nid_usermax;	/* Upper bound on user name cache */
214 	int		nid_usertimeout;/* User name timeout (minutes) */
215 	u_char		*nid_name;	/* Name */
216 	int		nid_namelen;	/* and its length */
217 };
218 
219 struct nfsd_clid {
220 	int		nclid_idlen;	/* Length of client id */
221 	u_char		nclid_id[NFSV4_OPAQUELIMIT]; /* and name */
222 };
223 
224 struct nfsd_dumplist {
225 	int		ndl_size;	/* Number of elements */
226 	void		*ndl_list;	/* and the list of elements */
227 };
228 
229 struct nfsd_dumpclients {
230 	u_int32_t	ndcl_flags;		/* LCL_xxx flags */
231 	u_int32_t	ndcl_nopenowners;	/* Number of openowners */
232 	u_int32_t	ndcl_nopens;		/* and opens */
233 	u_int32_t	ndcl_nlockowners;	/* and of lockowners */
234 	u_int32_t	ndcl_nlocks;		/* and of locks */
235 	u_int32_t	ndcl_ndelegs;		/* and of delegations */
236 	u_int32_t	ndcl_nolddelegs;	/* and old delegations */
237 	sa_family_t	ndcl_addrfam;		/* Callback address */
238 	union {
239 		struct in_addr sin_addr;
240 		struct in6_addr sin6_addr;
241 	} ndcl_cbaddr;
242 	struct nfsd_clid ndcl_clid;	/* and client id */
243 };
244 
245 struct nfsd_dumplocklist {
246 	char		*ndllck_fname;	/* File Name */
247 	int		ndllck_size;	/* Number of elements */
248 	void		*ndllck_list;	/* and the list of elements */
249 };
250 
251 struct nfsd_dumplocks {
252 	u_int32_t	ndlck_flags;		/* state flags NFSLCK_xxx */
253 	nfsv4stateid_t	ndlck_stateid;		/* stateid */
254 	u_int64_t	ndlck_first;		/* lock byte range */
255 	u_int64_t	ndlck_end;
256 	struct nfsd_clid ndlck_owner;		/* Owner of open/lock */
257 	sa_family_t	ndlck_addrfam;		/* Callback address */
258 	union {
259 		struct in_addr sin_addr;
260 		struct in6_addr sin6_addr;
261 	} ndlck_cbaddr;
262 	struct nfsd_clid ndlck_clid;	/* and client id */
263 };
264 
265 /*
266  * Structure for referral information.
267  */
268 struct nfsreferral {
269 	u_char		*nfr_srvlist;	/* List of servers */
270 	int		nfr_srvcnt;	/* number of servers */
271 	vnode_t		nfr_vp;	/* vnode for referral */
272 	u_int32_t	nfr_dfileno;	/* assigned dir inode# */
273 };
274 
275 /*
276  * Flags for lc_flags and opsflags for nfsrv_getclient().
277  */
278 #define	LCL_NEEDSCONFIRM	0x00000001
279 #define	LCL_DONTCLEAN		0x00000002
280 #define	LCL_WAKEUPWANTED	0x00000004
281 #define	LCL_TCPCALLBACK		0x00000008
282 #define	LCL_CALLBACKSON		0x00000010
283 #define	LCL_INDEXNOTOK		0x00000020
284 #define	LCL_STAMPEDSTABLE	0x00000040
285 #define	LCL_EXPIREIT		0x00000080
286 #define	LCL_CBDOWN		0x00000100
287 #define	LCL_KERBV		0x00000400
288 #define	LCL_NAME		0x00000800
289 #define	LCL_NEEDSCBNULL		0x00001000
290 #define	LCL_GSSINTEGRITY	0x00002000
291 #define	LCL_GSSPRIVACY		0x00004000
292 #define	LCL_ADMINREVOKED	0x00008000
293 #define	LCL_RECLAIMCOMPLETE	0x00010000
294 #define	LCL_NFSV41		0x00020000
295 
296 #define	LCL_GSS		LCL_KERBV	/* Or of all mechs */
297 
298 /*
299  * Bits for flags in nfslock and nfsstate.
300  * The access, deny, NFSLCK_READ and NFSLCK_WRITE bits must be defined as
301  * below, in the correct order, so the shifts work for tests.
302  */
303 #define	NFSLCK_READACCESS	0x00000001
304 #define	NFSLCK_WRITEACCESS	0x00000002
305 #define	NFSLCK_ACCESSBITS	(NFSLCK_READACCESS | NFSLCK_WRITEACCESS)
306 #define	NFSLCK_SHIFT		2
307 #define	NFSLCK_READDENY		0x00000004
308 #define	NFSLCK_WRITEDENY	0x00000008
309 #define	NFSLCK_DENYBITS		(NFSLCK_READDENY | NFSLCK_WRITEDENY)
310 #define	NFSLCK_SHAREBITS 						\
311     (NFSLCK_READACCESS|NFSLCK_WRITEACCESS|NFSLCK_READDENY|NFSLCK_WRITEDENY)
312 #define	NFSLCK_LOCKSHIFT	4
313 #define	NFSLCK_READ		0x00000010
314 #define	NFSLCK_WRITE		0x00000020
315 #define	NFSLCK_BLOCKING		0x00000040
316 #define	NFSLCK_RECLAIM		0x00000080
317 #define	NFSLCK_OPENTOLOCK	0x00000100
318 #define	NFSLCK_TEST		0x00000200
319 #define	NFSLCK_LOCK		0x00000400
320 #define	NFSLCK_UNLOCK		0x00000800
321 #define	NFSLCK_OPEN		0x00001000
322 #define	NFSLCK_CLOSE		0x00002000
323 #define	NFSLCK_CHECK		0x00004000
324 #define	NFSLCK_RELEASE		0x00008000
325 #define	NFSLCK_NEEDSCONFIRM	0x00010000
326 #define	NFSLCK_CONFIRM		0x00020000
327 #define	NFSLCK_DOWNGRADE	0x00040000
328 #define	NFSLCK_DELEGREAD	0x00080000
329 #define	NFSLCK_DELEGWRITE	0x00100000
330 #define	NFSLCK_DELEGCUR		0x00200000
331 #define	NFSLCK_DELEGPREV	0x00400000
332 #define	NFSLCK_OLDDELEG		0x00800000
333 #define	NFSLCK_DELEGRECALL	0x01000000
334 #define	NFSLCK_SETATTR		0x02000000
335 #define	NFSLCK_DELEGPURGE	0x04000000
336 #define	NFSLCK_DELEGRETURN	0x08000000
337 #define	NFSLCK_WANTWDELEG	0x10000000
338 #define	NFSLCK_WANTRDELEG	0x20000000
339 #define	NFSLCK_WANTNODELEG	0x40000000
340 #define	NFSLCK_WANTBITS							\
341     (NFSLCK_WANTWDELEG | NFSLCK_WANTRDELEG | NFSLCK_WANTNODELEG)
342 
343 /* And bits for nid_flag */
344 #define	NFSID_INITIALIZE	0x0001
345 #define	NFSID_ADDUID		0x0002
346 #define	NFSID_DELUID		0x0004
347 #define	NFSID_ADDUSERNAME	0x0008
348 #define	NFSID_DELUSERNAME	0x0010
349 #define	NFSID_ADDGID		0x0020
350 #define	NFSID_DELGID		0x0040
351 #define	NFSID_ADDGROUPNAME	0x0080
352 #define	NFSID_DELGROUPNAME	0x0100
353 
354 /*
355  * fs.nfs sysctl(3) identifiers
356  */
357 #define	NFS_NFSSTATS	1		/* struct: struct nfsstats */
358 
359 /*
360  * Here is the definition of the attribute bits array and macros that
361  * manipulate it.
362  * THE MACROS MUST BE MANUALLY MODIFIED IF NFSATTRBIT_MAXWORDS CHANGES!!
363  * It is (NFSATTRBIT_MAX + 31) / 32.
364  */
365 #define	NFSATTRBIT_MAXWORDS	3
366 
367 typedef struct {
368 	u_int32_t bits[NFSATTRBIT_MAXWORDS];
369 } nfsattrbit_t;
370 
371 #define	NFSZERO_ATTRBIT(b) do {						\
372 	(b)->bits[0] = 0;						\
373 	(b)->bits[1] = 0;						\
374 	(b)->bits[2] = 0;						\
375 } while (0)
376 
377 #define	NFSSET_ATTRBIT(t, f) do {					\
378 	(t)->bits[0] = (f)->bits[0];			 		\
379 	(t)->bits[1] = (f)->bits[1];					\
380 	(t)->bits[2] = (f)->bits[2];					\
381 } while (0)
382 
383 #define	NFSSETSUPP_ATTRBIT(b) do { 					\
384 	(b)->bits[0] = NFSATTRBIT_SUPP0; 				\
385 	(b)->bits[1] = (NFSATTRBIT_SUPP1 | NFSATTRBIT_SUPPSETONLY);	\
386 	(b)->bits[2] = NFSATTRBIT_SUPP2;				\
387 } while (0)
388 
389 #define	NFSISSET_ATTRBIT(b, p)	((b)->bits[(p) / 32] & (1 << ((p) % 32)))
390 #define	NFSSETBIT_ATTRBIT(b, p)	((b)->bits[(p) / 32] |= (1 << ((p) % 32)))
391 #define	NFSCLRBIT_ATTRBIT(b, p)	((b)->bits[(p) / 32] &= ~(1 << ((p) % 32)))
392 
393 #define	NFSCLRALL_ATTRBIT(b, a)	do { 					\
394 	(b)->bits[0] &= ~((a)->bits[0]);	 			\
395 	(b)->bits[1] &= ~((a)->bits[1]);	 			\
396 	(b)->bits[2] &= ~((a)->bits[2]);				\
397 } while (0)
398 
399 #define	NFSCLRNOT_ATTRBIT(b, a)	do { 					\
400 	(b)->bits[0] &= ((a)->bits[0]);		 			\
401 	(b)->bits[1] &= ((a)->bits[1]);		 			\
402 	(b)->bits[2] &= ((a)->bits[2]);		 			\
403 } while (0)
404 
405 #define	NFSCLRNOTFILLABLE_ATTRBIT(b) do { 				\
406 	(b)->bits[0] &= NFSATTRBIT_SUPP0;	 			\
407 	(b)->bits[1] &= NFSATTRBIT_SUPP1;				\
408 	(b)->bits[2] &= NFSATTRBIT_SUPP2;				\
409 } while (0)
410 
411 #define	NFSCLRNOTSETABLE_ATTRBIT(b) do { 				\
412 	(b)->bits[0] &= NFSATTRBIT_SETABLE0;	 			\
413 	(b)->bits[1] &= NFSATTRBIT_SETABLE1;				\
414 	(b)->bits[2] &= NFSATTRBIT_SETABLE2;				\
415 } while (0)
416 
417 #define	NFSNONZERO_ATTRBIT(b)	((b)->bits[0] || (b)->bits[1] || (b)->bits[2])
418 #define	NFSEQUAL_ATTRBIT(b, p)	((b)->bits[0] == (p)->bits[0] &&	\
419 	(b)->bits[1] == (p)->bits[1] && (b)->bits[2] == (p)->bits[2])
420 
421 #define	NFSGETATTR_ATTRBIT(b) do { 					\
422 	(b)->bits[0] = NFSATTRBIT_GETATTR0;	 			\
423 	(b)->bits[1] = NFSATTRBIT_GETATTR1;				\
424 	(b)->bits[2] = NFSATTRBIT_GETATTR2;				\
425 } while (0)
426 
427 #define	NFSWCCATTR_ATTRBIT(b) do { 					\
428 	(b)->bits[0] = NFSATTRBIT_WCCATTR0;	 			\
429 	(b)->bits[1] = NFSATTRBIT_WCCATTR1;				\
430 	(b)->bits[2] = NFSATTRBIT_WCCATTR2;				\
431 } while (0)
432 
433 #define	NFSWRITEGETATTR_ATTRBIT(b) do { 				\
434 	(b)->bits[0] = NFSATTRBIT_WRITEGETATTR0;			\
435 	(b)->bits[1] = NFSATTRBIT_WRITEGETATTR1;			\
436 	(b)->bits[2] = NFSATTRBIT_WRITEGETATTR2;			\
437 } while (0)
438 
439 #define	NFSCBGETATTR_ATTRBIT(b, c) do { 				\
440 	(c)->bits[0] = ((b)->bits[0] & NFSATTRBIT_CBGETATTR0);		\
441 	(c)->bits[1] = ((b)->bits[1] & NFSATTRBIT_CBGETATTR1);		\
442 	(c)->bits[2] = ((b)->bits[2] & NFSATTRBIT_CBGETATTR2);		\
443 } while (0)
444 
445 #define	NFSPATHCONF_GETATTRBIT(b) do { 					\
446 	(b)->bits[0] = NFSGETATTRBIT_PATHCONF0;		 		\
447 	(b)->bits[1] = NFSGETATTRBIT_PATHCONF1;				\
448 	(b)->bits[2] = NFSGETATTRBIT_PATHCONF2;				\
449 } while (0)
450 
451 #define	NFSSTATFS_GETATTRBIT(b)	do { 					\
452 	(b)->bits[0] = NFSGETATTRBIT_STATFS0;	 			\
453 	(b)->bits[1] = NFSGETATTRBIT_STATFS1;				\
454 	(b)->bits[2] = NFSGETATTRBIT_STATFS2;				\
455 } while (0)
456 
457 #define	NFSISSETSTATFS_ATTRBIT(b) 					\
458 		(((b)->bits[0] & NFSATTRBIT_STATFS0) || 		\
459 		 ((b)->bits[1] & NFSATTRBIT_STATFS1) ||			\
460 		 ((b)->bits[2] & NFSATTRBIT_STATFS2))
461 
462 #define	NFSCLRSTATFS_ATTRBIT(b)	do { 					\
463 	(b)->bits[0] &= ~NFSATTRBIT_STATFS0;	 			\
464 	(b)->bits[1] &= ~NFSATTRBIT_STATFS1;				\
465 	(b)->bits[2] &= ~NFSATTRBIT_STATFS2;				\
466 } while (0)
467 
468 #define	NFSREADDIRPLUS_ATTRBIT(b) do { 					\
469 	(b)->bits[0] = NFSATTRBIT_READDIRPLUS0;		 		\
470 	(b)->bits[1] = NFSATTRBIT_READDIRPLUS1;				\
471 	(b)->bits[2] = NFSATTRBIT_READDIRPLUS2;				\
472 } while (0)
473 
474 #define	NFSREFERRAL_ATTRBIT(b) do { 					\
475 	(b)->bits[0] = NFSATTRBIT_REFERRAL0;		 		\
476 	(b)->bits[1] = NFSATTRBIT_REFERRAL1;				\
477 	(b)->bits[2] = NFSATTRBIT_REFERRAL2;				\
478 } while (0)
479 
480 /*
481  * Store uid, gid creds that were used when the stateid was acquired.
482  * The RPC layer allows NFS_MAXGRPS + 1 groups to go out on the wire,
483  * so that's how many gets stored here.
484  */
485 struct nfscred {
486 	uid_t 		nfsc_uid;
487 	gid_t		nfsc_groups[NFS_MAXGRPS + 1];
488 	int		nfsc_ngroups;
489 };
490 
491 /*
492  * Constants that define the file handle for the V4 root directory.
493  * (The FSID must never be used by other file systems that are exported.)
494  */
495 #define	NFSV4ROOT_FSID0		((int32_t) -1)
496 #define	NFSV4ROOT_FSID1		((int32_t) -1)
497 #define	NFSV4ROOT_REFERRAL	((int32_t) -2)
498 #define	NFSV4ROOT_INO		2	/* It's traditional */
499 #define	NFSV4ROOT_GEN		1
500 
501 /*
502  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
503  * What should be in this set is open to debate, but I believe that since
504  * I/O system calls on ufs are never interrupted by signals the set should
505  * be minimal. My reasoning is that many current programs that use signals
506  * such as SIGALRM will not expect file I/O system calls to be interrupted
507  * by them and break.
508  */
509 #if defined(_KERNEL) || defined(KERNEL)
510 
511 struct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
512 
513 /*
514  * Socket errors ignored for connectionless sockets?
515  * For now, ignore them all
516  */
517 #define	NFSIGNORE_SOERROR(s, e) 					\
518 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
519 		((s) & PR_CONNREQUIRED) == 0)
520 
521 
522 /*
523  * This structure holds socket information for a connection. Used by the
524  * client and the server for callbacks.
525  */
526 struct nfssockreq {
527 	NFSSOCKADDR_T	nr_nam;
528 	int		nr_sotype;
529 	int		nr_soproto;
530 	int		nr_soflags;
531 	struct ucred	*nr_cred;
532 	int		nr_lock;
533 	NFSMUTEX_T	nr_mtx;
534 	u_int32_t	nr_prog;
535 	u_int32_t	nr_vers;
536 	struct __rpc_client *nr_client;
537 	AUTH		*nr_auth;
538 };
539 
540 /*
541  * And associated nr_lock bits.
542  */
543 #define	NFSR_SNDLOCK		0x01
544 #define	NFSR_WANTSND		0x02
545 #define	NFSR_RCVLOCK		0x04
546 #define	NFSR_WANTRCV		0x08
547 #define	NFSR_RESERVEDPORT	0x10
548 #define	NFSR_LOCALHOST		0x20
549 
550 /*
551  * Queue head for nfsreq's
552  */
553 TAILQ_HEAD(nfsreqhead, nfsreq);
554 
555 /* This is the only nfsreq R_xxx flag still used. */
556 #define	R_DONTRECOVER	0x00000100	/* don't initiate recovery when this
557 					   rpc gets a stale state reply */
558 
559 /*
560  * Network address hash list element
561  */
562 union nethostaddr {
563 	struct in_addr	had_inet;
564 	struct in6_addr had_inet6;
565 };
566 
567 /*
568  * Structure of list of mechanisms.
569  */
570 struct nfsgss_mechlist {
571 	int	len;
572 	const u_char	*str;
573 	int	totlen;
574 };
575 #define	KERBV_MECH	0	/* position in list */
576 
577 /*
578  * This structure is used by the server for describing each request.
579  */
580 struct nfsrv_descript {
581 	mbuf_t			nd_mrep;	/* Request mbuf list */
582 	mbuf_t			nd_md;		/* Current dissect mbuf */
583 	mbuf_t			nd_mreq;	/* Reply mbuf list */
584 	mbuf_t			nd_mb;		/* Current build mbuf */
585 	NFSSOCKADDR_T		nd_nam;		/* and socket addr */
586 	NFSSOCKADDR_T		nd_nam2;	/* return socket addr */
587 	char			*nd_dpos;	/* Current dissect pos */
588 	char			*nd_bpos;	/* Current build pos */
589 	u_int16_t		nd_procnum;	/* RPC # */
590 	u_int32_t		nd_flag;	/* nd_flag */
591 	u_int32_t		nd_repstat;	/* Reply status */
592 	int			*nd_errp;	/* Pointer to ret status */
593 	u_int32_t		nd_retxid;	/* Reply xid */
594 	struct nfsrvcache	*nd_rp;		/* Assoc. cache entry */
595 	fhandle_t		nd_fh;		/* File handle */
596 	struct ucred		*nd_cred;	/* Credentials */
597 	uid_t			nd_saveduid;	/* Saved uid */
598 	u_int64_t		nd_sockref;	/* Rcv socket ref# */
599 	u_int64_t		nd_compref;	/* Compound RPC ref# */
600 	time_t			nd_tcpconntime;	/* Time TCP connection est. */
601 	nfsquad_t		nd_clientid;	/* Implied clientid */
602 	int			nd_gssnamelen;	/* principal name length */
603 	char			*nd_gssname;	/* principal name */
604 	uint32_t		*nd_slotseq;	/* ptr to slot seq# in req */
605 	uint8_t			nd_sessionid[NFSX_V4SESSIONID];	/* Session id */
606 	uint32_t		nd_slotid;	/* Slotid for this RPC */
607 	SVCXPRT			*nd_xprt;	/* Server RPC handle */
608 };
609 
610 #define	nd_princlen	nd_gssnamelen
611 #define	nd_principal	nd_gssname
612 
613 /* Bits for "nd_flag" */
614 #define	ND_DONTSAVEREPLY 	0x00000001
615 #define	ND_SAVEREPLY		0x00000002
616 #define	ND_NFSV2		0x00000004
617 #define	ND_NFSV3		0x00000008
618 #define	ND_NFSV4		0x00000010
619 #define	ND_KERBV		0x00000020
620 #define	ND_GSSINTEGRITY		0x00000040
621 #define	ND_GSSPRIVACY		0x00000080
622 #define	ND_WINDOWVERF		0x00000100
623 #define	ND_GSSINITREPLY		0x00000200
624 #define	ND_STREAMSOCK		0x00000400
625 #define	ND_PUBLOOKUP		0x00000800
626 #define	ND_USEGSSNAME		0x00001000
627 #define	ND_SAMETCPCONN		0x00002000
628 #define	ND_IMPLIEDCLID		0x00004000
629 #define	ND_NOMOREDATA		0x00008000
630 #define	ND_V4WCCATTR		0x00010000
631 #define	ND_NFSCB		0x00020000
632 #define	ND_AUTHNONE		0x00040000
633 #define	ND_EXAUTHSYS		0x00080000
634 #define	ND_EXGSS		0x00100000
635 #define	ND_EXGSSINTEGRITY	0x00200000
636 #define	ND_EXGSSPRIVACY		0x00400000
637 #define	ND_INCRSEQID		0x00800000
638 #define	ND_NFSCL		0x01000000
639 #define	ND_NFSV41		0x02000000
640 #define	ND_HASSEQUENCE		0x04000000
641 #define	ND_CACHETHIS		0x08000000
642 #define	ND_LASTOP		0x10000000
643 
644 /*
645  * ND_GSS should be the "or" of all GSS type authentications.
646  */
647 #define	ND_GSS		(ND_KERBV)
648 
649 struct nfsv4_opflag {
650 	int	retfh;
651 	int	needscfh;
652 	int	savereply;
653 	int	modifyfs;
654 	int	lktype;
655 	int	needsseq;
656 };
657 
658 /*
659  * Flags used to indicate what to do w.r.t. seqid checking.
660  */
661 #define	NFSRVSEQID_FIRST	0x01
662 #define	NFSRVSEQID_LAST		0x02
663 #define	NFSRVSEQID_OPEN		0x04
664 
665 /*
666  * assign a doubly linked list to a new head
667  * and prepend one list into another.
668  */
669 #define	LIST_NEWHEAD(nhead, ohead, field) do { 				\
670 	if (((nhead)->lh_first = (ohead)->lh_first) != NULL) 		\
671 		(ohead)->lh_first->field.le_prev = &(nhead)->lh_first; 	\
672 	(ohead)->lh_first = NULL; 					\
673     } while (0)
674 
675 #define	LIST_PREPEND(head, phead, lelm, field) do {			\
676 	if ((head)->lh_first != NULL) {					\
677 		(lelm)->field.le_next = (head)->lh_first;		\
678 		(lelm)->field.le_next->field.le_prev =			\
679 		    &(lelm)->field.le_next;				\
680 	}								\
681 	(head)->lh_first = (phead)->lh_first;				\
682 	(head)->lh_first->field.le_prev = &(head)->lh_first;		\
683     } while (0)
684 
685 /*
686  * File handle structure for client. Malloc'd to the correct length with
687  * malloc type M_NFSFH.
688  */
689 struct nfsfh {
690 	u_int16_t	nfh_len;	/* Length of file handle */
691 	u_int8_t	nfh_fh[1];	/* and the file handle */
692 };
693 
694 /*
695  * File handle structure for server. The NFSRV_MAXFH constant is
696  * set in nfsdport.h. I use a 32bit length, so that alignment is
697  * preserved.
698  */
699 struct nfsrvfh {
700 	u_int32_t	nfsrvfh_len;
701 	u_int8_t	nfsrvfh_data[NFSRV_MAXFH];
702 };
703 
704 /*
705  * This structure is used for sleep locks on the NFSv4 nfsd threads and
706  * NFSv4 client data structures.
707  */
708 struct nfsv4lock {
709 	u_int32_t	nfslock_usecnt;
710 	u_int8_t	nfslock_lock;
711 };
712 #define	NFSV4LOCK_LOCK		0x01
713 #define	NFSV4LOCK_LOCKWANTED	0x02
714 #define	NFSV4LOCK_WANTED	0x04
715 
716 /*
717  * Values for the override argument for nfsvno_accchk().
718  */
719 #define	NFSACCCHK_NOOVERRIDE		0
720 #define	NFSACCCHK_ALLOWROOT		1
721 #define	NFSACCCHK_ALLOWOWNER		2
722 
723 /*
724  * and values for the vpislocked argument for nfsvno_accchk().
725  */
726 #define	NFSACCCHK_VPNOTLOCKED		0
727 #define	NFSACCCHK_VPISLOCKED		1
728 
729 /*
730  * Slot for the NFSv4.1 Sequence Op.
731  */
732 struct nfsslot {
733 	int		nfssl_inprog;
734 	uint32_t	nfssl_seq;
735 	struct mbuf	*nfssl_reply;
736 };
737 
738 #endif	/* _KERNEL */
739 
740 #endif	/* _NFS_NFS_H */
741