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