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