nfs.h revision 192000
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: head/sys/fs/nfs/nfs.h 192000 2009-05-11 19:37:05Z 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	10		/* 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_CBRETRYCNT 4		/* # of CBRecall retries upon err */
54#define	NFSV4_UPCALLTIMEO (15 * NFS_HZ)	/* Timeout in ticks for upcalls */
55					/* to gssd or nfsuserd */
56#define	NFSV4_UPCALLRETRY 4		/* Number of retries before failure */
57#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
58#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
59#define	NFS_MAXGRPS	16		/* Max. size of groups list */
60#define	NFS_TRYLATERDEL	15		/* Maximum delay timeout (sec) */
61#ifndef NFS_REMOVETIMEO
62#define	NFS_REMOVETIMEO 15  /* # sec to wait for delegret in local syscall */
63#endif
64#ifndef NFS_MINATTRTIMO
65#define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
66#endif
67#ifndef NFS_MAXATTRTIMO
68#define	NFS_MAXATTRTIMO 60
69#endif
70#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
71#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
72#define	NFS_READDIRSIZE	8192		/* Def. readdir size */
73#define	NFS_DEFRAHEAD	0		/* Def. read ahead # blocks */
74#define	NFS_MAXRAHEAD	32		/* Max. read ahead # blocks */
75#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
76#ifndef	NFSRV_LEASE
77#define	NFSRV_LEASE		120	/* Lease time in seconds for V4 */
78#endif					/* assigned to nfsrv_lease */
79#ifndef NFSRV_STALELEASE
80#define	NFSRV_STALELEASE	(5 * nfsrv_lease)
81#endif
82#ifndef NFSRV_MOULDYLEASE
83#define	NFSRV_MOULDYLEASE	604800	/* One week (in sec) */
84#endif
85#ifndef NFSCLIENTHASHSIZE
86#define	NFSCLIENTHASHSIZE	20	/* Size of server client hash table */
87#endif
88#ifndef NFSLOCKHASHSIZE
89#define	NFSLOCKHASHSIZE		20	/* Size of server nfslock hash table */
90#endif
91#define	NFSSTATEHASHSIZE	10	/* Size of server stateid hash table */
92#ifndef NFSUSERHASHSIZE
93#define	NFSUSERHASHSIZE		30	/* Size of user id hash table */
94#endif
95#ifndef NFSGROUPHASHSIZE
96#define	NFSGROUPHASHSIZE	5	/* Size of group id hash table */
97#endif
98#ifndef	NFSCLDELEGHIGHWATER
99#define	NFSCLDELEGHIGHWATER	10000	/* limit for client delegations */
100#endif
101#ifndef NFSNOOPEN			/* Inactive open owner (sec) */
102#define	NFSNOOPEN		120
103#endif
104#define	NFSRV_LEASEDELTA	15	/* # of seconds to delay beyond lease */
105#define	NFS_IDMAXSIZE		4	/* max sizeof (in_addr_t) */
106#ifndef NFSRVCACHE_UDPTIMEOUT
107#define	NFSRVCACHE_UDPTIMEOUT	30	/* # of sec to hold cached rpcs(udp) */
108#endif
109#ifndef NFSRVCACHE_UDPHIGHWATER
110#define	NFSRVCACHE_UDPHIGHWATER	500	/* Max # of udp cache entries */
111#endif
112#ifndef NFSRVCACHE_TCPTIMEOUT
113#define	NFSRVCACHE_TCPTIMEOUT	(3600*12) /*#of sec to hold cached rpcs(tcp) */
114#endif
115#ifndef	NFSRVCACHE_FLOODLEVEL
116#define	NFSRVCACHE_FLOODLEVEL	16384	/* Very high water mark for cache */
117#endif
118#ifndef	NFSRV_CLIENTHIGHWATER
119#define	NFSRV_CLIENTHIGHWATER	1000
120#endif
121#ifndef	NFSRV_MAXDUMPLIST
122#define	NFSRV_MAXDUMPLIST	10000
123#endif
124#ifndef NFS_ACCESSCACHESIZE
125#define	NFS_ACCESSCACHESIZE	8
126#endif
127#define	NFSV4_CBPORT	7745		/* Callback port for testing */
128
129/*
130 * This macro defines the high water mark for issuing V4 delegations.
131 * (It is currently set at a conservative 20% of NFSRV_V4STATELIMIT. This
132 *  may want to increase when clients can make more effective use of
133 *  delegations.)
134 */
135#define	NFSRV_V4DELEGLIMIT(c) (((c) * 5) > NFSRV_V4STATELIMIT)
136
137#define	NFS_READDIRBLKSIZ	DIRBLKSIZ	/* Minimal nm_readdirsize */
138
139/*
140 * Oddballs
141 */
142#define	NFS_CMPFH(n, f, s) 						\
143    ((n)->n_fhp->nfh_len == (s) && !NFSBCMP((n)->n_fhp->nfh_fh, (caddr_t)(f), (s)))
144#define	NFSRV_CMPFH(nf, ns, f, s) 					\
145	((ns) == (s) && !NFSBCMP((caddr_t)(nf), (caddr_t)(f), (s)))
146#define	NFS_CMPTIME(t1, t2) 						\
147	((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec == (t2).tv_nsec)
148#define	NFS_SETTIME(t) do { 						\
149	(t).tv_sec = time.tv_sec; (t).tv_nsec = 1000 * time.tv_usec; } while (0)
150#define	NFS_SRVMAXDATA(n) 						\
151		(((n)->nd_flag & (ND_NFSV3 | ND_NFSV4)) ? 		\
152		 NFS_MAXDATA : NFS_V2MAXDATA)
153#define	NFS64BITSSET	0xffffffffffffffffull
154#define	NFS64BITSMINUS1	0xfffffffffffffffeull
155
156/*
157 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd, mount_nfs
158 * and nfsloaduser should ever try and use it.
159 */
160struct nfsd_addsock_args {
161	int	sock;		/* Socket to serve */
162	caddr_t	name;		/* Client addr for connection based sockets */
163	int	namelen;	/* Length of name */
164};
165
166/*
167 * nfsd argument for new krpc.
168 */
169struct nfsd_nfsd_args {
170	const char *principal;	/* GSS-API service principal name */
171	int	minthreads;	/* minimum service thread count */
172	int	maxthreads;	/* maximum service thread count */
173};
174
175/*
176 * Arguments for use by the callback daemon.
177 */
178struct nfsd_nfscbd_args {
179	const char *principal;	/* GSS-API service principal name */
180};
181
182struct nfscbd_args {
183	int	sock;		/* Socket to serve */
184	caddr_t	name;		/* Client addr for connection based sockets */
185	int	namelen;	/* Length of name */
186	u_short	port;		/* Port# for callbacks */
187};
188
189struct nfsd_idargs {
190	int		nid_flag;	/* Flags (see below) */
191	uid_t		nid_uid;	/* user/group id */
192	gid_t		nid_gid;
193	int		nid_usermax;	/* Upper bound on user name cache */
194	int		nid_usertimeout;/* User name timeout (minutes) */
195	u_char		*nid_name;	/* Name */
196	int		nid_namelen;	/* and its length */
197};
198
199struct nfsd_clid {
200	int		nclid_idlen;	/* Length of client id */
201	u_char		nclid_id[NFSV4_OPAQUELIMIT]; /* and name */
202};
203
204struct nfsd_dumplist {
205	int		ndl_size;	/* Number of elements */
206	void		*ndl_list;	/* and the list of elements */
207};
208
209struct nfsd_dumpclients {
210	u_int32_t	ndcl_flags;		/* LCL_xxx flags */
211	u_int32_t	ndcl_nopenowners;	/* Number of openowners */
212	u_int32_t	ndcl_nopens;		/* and opens */
213	u_int32_t	ndcl_nlockowners;	/* and of lockowners */
214	u_int32_t	ndcl_nlocks;		/* and of locks */
215	u_int32_t	ndcl_ndelegs;		/* and of delegations */
216	u_int32_t	ndcl_nolddelegs;	/* and old delegations */
217	sa_family_t	ndcl_addrfam;		/* Callback address */
218	union {
219		struct in_addr sin_addr;
220		struct in6_addr sin6_addr;
221	} ndcl_cbaddr;
222	struct nfsd_clid ndcl_clid;	/* and client id */
223};
224
225struct nfsd_dumplocklist {
226	char		*ndllck_fname;	/* File Name */
227	int		ndllck_size;	/* Number of elements */
228	void		*ndllck_list;	/* and the list of elements */
229};
230
231struct nfsd_dumplocks {
232	u_int32_t	ndlck_flags;		/* state flags NFSLCK_xxx */
233	nfsv4stateid_t	ndlck_stateid;		/* stateid */
234	u_int64_t	ndlck_first;		/* lock byte range */
235	u_int64_t	ndlck_end;
236	struct nfsd_clid ndlck_owner;		/* Owner of open/lock */
237	sa_family_t	ndlck_addrfam;		/* Callback address */
238	union {
239		struct in_addr sin_addr;
240		struct in6_addr sin6_addr;
241	} ndlck_cbaddr;
242	struct nfsd_clid ndlck_clid;	/* and client id */
243};
244
245/*
246 * Structure for referral information.
247 */
248struct nfsreferral {
249	u_char		*nfr_srvlist;	/* List of servers */
250	int		nfr_srvcnt;	/* number of servers */
251	vnode_t		nfr_vp;	/* vnode for referral */
252	u_int32_t	nfr_dfileno;	/* assigned dir inode# */
253};
254
255/*
256 * Flags for lc_flags and opsflags for nfsrv_getclient().
257 */
258#define	LCL_NEEDSCONFIRM	0x00000001
259#define	LCL_DONTCLEAN		0x00000002
260#define	LCL_WAKEUPWANTED	0x00000004
261#define	LCL_TCPCALLBACK		0x00000008
262#define	LCL_CALLBACKSON		0x00000010
263#define	LCL_INDEXNOTOK		0x00000020
264#define	LCL_STAMPEDSTABLE	0x00000040
265#define	LCL_EXPIREIT		0x00000080
266#define	LCL_CBDOWN		0x00000100
267#define	LCL_KERBV		0x00000400
268#define	LCL_NAME		0x00000800
269#define	LCL_NEEDSCBNULL		0x00001000
270#define	LCL_GSSINTEGRITY	0x00002000
271#define	LCL_GSSPRIVACY		0x00004000
272#define	LCL_ADMINREVOKED	0x00008000
273
274#define	LCL_GSS		LCL_KERBV	/* Or of all mechs */
275
276/*
277 * Bits for flags in nfslock and nfsstate.
278 * The access, deny, NFSLCK_READ and NFSLCK_WRITE bits must be defined as
279 * below, in the correct order, so the shifts work for tests.
280 */
281#define	NFSLCK_READACCESS	0x00000001
282#define	NFSLCK_WRITEACCESS	0x00000002
283#define	NFSLCK_ACCESSBITS	(NFSLCK_READACCESS | NFSLCK_WRITEACCESS)
284#define	NFSLCK_SHIFT		2
285#define	NFSLCK_READDENY		0x00000004
286#define	NFSLCK_WRITEDENY	0x00000008
287#define	NFSLCK_DENYBITS		(NFSLCK_READDENY | NFSLCK_WRITEDENY)
288#define	NFSLCK_SHAREBITS 						\
289    (NFSLCK_READACCESS|NFSLCK_WRITEACCESS|NFSLCK_READDENY|NFSLCK_WRITEDENY)
290#define	NFSLCK_LOCKSHIFT	4
291#define	NFSLCK_READ		0x00000010
292#define	NFSLCK_WRITE		0x00000020
293#define	NFSLCK_BLOCKING		0x00000040
294#define	NFSLCK_RECLAIM		0x00000080
295#define	NFSLCK_OPENTOLOCK	0x00000100
296#define	NFSLCK_TEST		0x00000200
297#define	NFSLCK_LOCK		0x00000400
298#define	NFSLCK_UNLOCK		0x00000800
299#define	NFSLCK_OPEN		0x00001000
300#define	NFSLCK_CLOSE		0x00002000
301#define	NFSLCK_CHECK		0x00004000
302#define	NFSLCK_RELEASE		0x00008000
303#define	NFSLCK_NEEDSCONFIRM	0x00010000
304#define	NFSLCK_CONFIRM		0x00020000
305#define	NFSLCK_DOWNGRADE	0x00040000
306#define	NFSLCK_DELEGREAD	0x00080000
307#define	NFSLCK_DELEGWRITE	0x00100000
308#define	NFSLCK_DELEGCUR		0x00200000
309#define	NFSLCK_DELEGPREV	0x00400000
310#define	NFSLCK_OLDDELEG		0x00800000
311#define	NFSLCK_DELEGRECALL	0x01000000
312#define	NFSLCK_SETATTR		0x02000000
313#define	NFSLCK_DELEGPURGE	0x04000000
314#define	NFSLCK_DELEGRETURN	0x08000000
315
316/* And bits for nid_flag */
317#define	NFSID_INITIALIZE	0x0001
318#define	NFSID_ADDUID		0x0002
319#define	NFSID_DELUID		0x0004
320#define	NFSID_ADDUSERNAME	0x0008
321#define	NFSID_DELUSERNAME	0x0010
322#define	NFSID_ADDGID		0x0020
323#define	NFSID_DELGID		0x0040
324#define	NFSID_ADDGROUPNAME	0x0080
325#define	NFSID_DELGROUPNAME	0x0100
326
327/*
328 * Stats structure
329 */
330struct nfsstats {
331	int	attrcache_hits;
332	int	attrcache_misses;
333	int	lookupcache_hits;
334	int	lookupcache_misses;
335	int	direofcache_hits;
336	int	direofcache_misses;
337	int	accesscache_hits;
338	int	accesscache_misses;
339	int	biocache_reads;
340	int	read_bios;
341	int	read_physios;
342	int	biocache_writes;
343	int	write_bios;
344	int	write_physios;
345	int	biocache_readlinks;
346	int	readlink_bios;
347	int	biocache_readdirs;
348	int	readdir_bios;
349	int	rpccnt[NFS_NPROCS];
350	int	rpcretries;
351	int	srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS];
352	int	srvrpc_errs;
353	int	srv_errs;
354	int	rpcrequests;
355	int	rpctimeouts;
356	int	rpcunexpected;
357	int	rpcinvalid;
358	int	srvcache_inproghits;
359	int	srvcache_idemdonehits;
360	int	srvcache_nonidemdonehits;
361	int	srvcache_misses;
362	int	srvcache_tcppeak;
363	int	srvcache_size;
364	int	srvclients;
365	int	srvopenowners;
366	int	srvopens;
367	int	srvlockowners;
368	int	srvlocks;
369	int	srvdelegates;
370	int	cbrpccnt[NFSV4OP_CBNOPS];
371	int	clopenowners;
372	int	clopens;
373	int	cllockowners;
374	int	cllocks;
375	int	cldelegates;
376	int	cllocalopenowners;
377	int	cllocalopens;
378	int	cllocallockowners;
379	int	cllocallocks;
380};
381
382/*
383 * fs.nfs sysctl(3) identifiers
384 */
385#define	NFS_NFSSTATS	1		/* struct: struct nfsstats */
386
387#define	FS_NFS_NAMES { 							\
388		       { 0, 0 }, 					\
389		       { "nfsstats", CTLTYPE_STRUCT }, 			\
390}
391
392/*
393 * Here is the definition of the attribute bits array and macros that
394 * manipulate it.
395 * THE MACROS MUST BE MANUALLY MODIFIED IF NFSATTRBIT_MAXWORDS CHANGES!!
396 * It is (NFSATTRBIT_MAX + 31) / 32.
397 */
398#define	NFSATTRBIT_MAXWORDS	2
399
400typedef struct {
401	u_int32_t bits[NFSATTRBIT_MAXWORDS];
402} nfsattrbit_t;
403
404#define	NFSZERO_ATTRBIT(b) do { (b)->bits[0] = 0; (b)->bits[1] = 0; } while (0)
405#define	NFSSET_ATTRBIT(t, f) do { (t)->bits[0] = (f)->bits[0]; 		\
406				  (t)->bits[1] = (f)->bits[1]; } while (0)
407#define	NFSSETSUPP_ATTRBIT(b) do { 					\
408	(b)->bits[0] = NFSATTRBIT_SUPP0; 				\
409	(b)->bits[1] = (NFSATTRBIT_SUPP1 | NFSATTRBIT_SUPPSETONLY); } while (0)
410#define	NFSISSET_ATTRBIT(b, p)	((b)->bits[(p) / 32] & (1 << ((p) % 32)))
411#define	NFSSETBIT_ATTRBIT(b, p)	((b)->bits[(p) / 32] |= (1 << ((p) % 32)))
412#define	NFSCLRBIT_ATTRBIT(b, p)	((b)->bits[(p) / 32] &= ~(1 << ((p) % 32)))
413#define	NFSCLRALL_ATTRBIT(b, a)	do { 					\
414		(b)->bits[0] &= ~((a)->bits[0]); 			\
415		(b)->bits[1] &= ~((a)->bits[1]); 			\
416		} while (0)
417#define	NFSCLRNOT_ATTRBIT(b, a)	do { 					\
418		(b)->bits[0] &= ((a)->bits[0]); 			\
419		(b)->bits[1] &= ((a)->bits[1]); 			\
420		} while (0)
421#define	NFSCLRNOTFILLABLE_ATTRBIT(b) do { 				\
422		(b)->bits[0] &= NFSATTRBIT_SUPP0; 			\
423		(b)->bits[1] &= NFSATTRBIT_SUPP1; } while (0)
424#define	NFSCLRNOTSETABLE_ATTRBIT(b) do { 				\
425		(b)->bits[0] &= NFSATTRBIT_SETABLE0; 			\
426		(b)->bits[1] &= NFSATTRBIT_SETABLE1; } while (0)
427#define	NFSNONZERO_ATTRBIT(b)	((b)->bits[0] || (b)->bits[1])
428#define	NFSEQUAL_ATTRBIT(b, p)						\
429	((b)->bits[0] == (p)->bits[0] && (b)->bits[1] == (p)->bits[1])
430#define	NFSGETATTR_ATTRBIT(b) do { 					\
431		(b)->bits[0] = NFSATTRBIT_GETATTR0; 			\
432		(b)->bits[1] = NFSATTRBIT_GETATTR1; } while (0)
433#define	NFSWCCATTR_ATTRBIT(b) do { 					\
434		(b)->bits[0] = NFSATTRBIT_WCCATTR0; 			\
435		(b)->bits[1] = NFSATTRBIT_WCCATTR1; } while (0)
436#define	NFSWRITEGETATTR_ATTRBIT(b) do { 				\
437		(b)->bits[0] = NFSATTRBIT_WRITEGETATTR0;		\
438		(b)->bits[1] = NFSATTRBIT_WRITEGETATTR1; } while (0)
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); } while (0)
442#define	NFSPATHCONF_GETATTRBIT(b) do { 					\
443		(b)->bits[0] = NFSGETATTRBIT_PATHCONF0; 		\
444		(b)->bits[1] = NFSGETATTRBIT_PATHCONF1; } while (0)
445#define	NFSSTATFS_GETATTRBIT(b)	do { 					\
446		(b)->bits[0] = NFSGETATTRBIT_STATFS0; 			\
447		(b)->bits[1] = NFSGETATTRBIT_STATFS1; } while (0)
448#define	NFSISSETSTATFS_ATTRBIT(b) 					\
449		(((b)->bits[0] & NFSATTRBIT_STATFS0) || 		\
450		 ((b)->bits[1] & NFSATTRBIT_STATFS1))
451#define	NFSCLRSTATFS_ATTRBIT(b)	do { 					\
452		(b)->bits[0] &= ~NFSATTRBIT_STATFS0; 			\
453		(b)->bits[1] &= ~NFSATTRBIT_STATFS1; } while (0)
454#define	NFSREADDIRPLUS_ATTRBIT(b) do { 					\
455		(b)->bits[0] = NFSATTRBIT_READDIRPLUS0; 		\
456		(b)->bits[1] = NFSATTRBIT_READDIRPLUS1; } while (0)
457#define	NFSREFERRAL_ATTRBIT(b) do { 					\
458		(b)->bits[0] = NFSATTRBIT_REFERRAL0;	 		\
459		(b)->bits[1] = NFSATTRBIT_REFERRAL1; } while (0)
460
461/*
462 * Store uid, gid creds that handle maps to.
463 * Since some BSDen define cr_gid as cr_groups[0], I'll just keep them
464 * all in nfsc_groups[NGROUPS + 1].
465 */
466struct nfscred {
467	uid_t 		nfsc_uid;
468	gid_t		nfsc_groups[NGROUPS + 1];
469	int		nfsc_ngroups;
470};
471
472/*
473 * Constants that define the file handle for the V4 root directory.
474 * (The FSID must never be used by other file systems that are exported.)
475 */
476#define	NFSV4ROOT_FSID0		((int32_t) -1)
477#define	NFSV4ROOT_FSID1		((int32_t) -1)
478#define	NFSV4ROOT_REFERRAL	((int32_t) -2)
479#define	NFSV4ROOT_INO		2	/* It's traditional */
480#define	NFSV4ROOT_GEN		1
481
482/*
483 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
484 * What should be in this set is open to debate, but I believe that since
485 * I/O system calls on ufs are never interrupted by signals the set should
486 * be minimal. My reasoning is that many current programs that use signals
487 * such as SIGALRM will not expect file I/O system calls to be interrupted
488 * by them and break.
489 */
490#if defined(_KERNEL) || defined(KERNEL)
491
492struct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
493
494/*
495 * Socket errors ignored for connectionless sockets?
496 * For now, ignore them all
497 */
498#define	NFSIGNORE_SOERROR(s, e) 					\
499		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
500		((s) & PR_CONNREQUIRED) == 0)
501
502
503/*
504 * This structure holds socket information for a connection. Used by the
505 * client and the server for callbacks.
506 */
507struct nfssockreq {
508	NFSSOCKADDR_T	nr_nam;
509	int		nr_sotype;
510	int		nr_soproto;
511	int		nr_soflags;
512	struct ucred	*nr_cred;
513	int		nr_lock;
514	NFSMUTEX_T	nr_mtx;
515	u_int32_t	nr_prog;
516	u_int32_t	nr_vers;
517	struct __rpc_client *nr_client;
518};
519
520/*
521 * And associated nr_lock bits.
522 */
523#define	NFSR_SNDLOCK		0x01
524#define	NFSR_WANTSND		0x02
525#define	NFSR_RCVLOCK		0x04
526#define	NFSR_WANTRCV		0x08
527#define	NFSR_RESERVEDPORT	0x10
528#define	NFSR_LOCALHOST		0x20
529
530/*
531 * Queue head for nfsreq's
532 */
533TAILQ_HEAD(nfsreqhead, nfsreq);
534
535/* First 8 R_xxx flags defined in rpc/rpcclnt.h, the rest are here */
536#define	R_DONTRECOVER	0x00000100	/* don't initiate recovery when this
537					   rpc gets a stale state reply */
538
539/*
540 * Network address hash list element
541 */
542union nethostaddr {
543	struct in_addr	had_inet;
544	struct in6_addr had_inet6;
545};
546
547/*
548 * Structure of list of mechanisms.
549 */
550struct nfsgss_mechlist {
551	int	len;
552	const u_char	*str;
553	int	totlen;
554};
555#define	KERBV_MECH	0	/* position in list */
556
557/*
558 * This structure is used by the server for describing each request.
559 */
560struct nfsrv_descript {
561	mbuf_t			nd_mrep;	/* Request mbuf list */
562	mbuf_t			nd_md;		/* Current dissect mbuf */
563	mbuf_t			nd_mreq;	/* Reply mbuf list */
564	mbuf_t			nd_mb;		/* Current build mbuf */
565	NFSSOCKADDR_T		nd_nam;		/* and socket addr */
566	NFSSOCKADDR_T		nd_nam2;	/* return socket addr */
567	caddr_t			nd_dpos;	/* Current dissect pos */
568	caddr_t			nd_bpos;	/* Current build pos */
569	u_int16_t		nd_procnum;	/* RPC # */
570	u_int32_t		nd_flag;	/* nd_flag */
571	u_int32_t		nd_repstat;	/* Reply status */
572	int			*nd_errp;	/* Pointer to ret status */
573	u_int32_t		nd_retxid;	/* Reply xid */
574	struct nfsrvcache	*nd_rp;		/* Assoc. cache entry */
575	struct timeval		nd_starttime;	/* Time RPC initiated */
576	fhandle_t		nd_fh;		/* File handle */
577	struct ucred		*nd_cred;	/* Credentials */
578	uid_t			nd_saveduid;	/* Saved uid */
579	u_int64_t		nd_sockref;	/* Rcv socket ref# */
580	u_int64_t		nd_compref;	/* Compound RPC ref# */
581	time_t			nd_tcpconntime;	/* Time TCP connection est. */
582	nfsquad_t		nd_clientid;	/* Implied clientid */
583	int			nd_credflavor;	/* credential flavor */
584	int			nd_gssnamelen;	/* principal name length */
585	char			*nd_gssname;	/* principal name */
586};
587
588#define	nd_princlen	nd_gssnamelen
589#define	nd_principal	nd_gssname
590
591/* Bits for "nd_flag" */
592#define	ND_DONTSAVEREPLY 	0x00000001
593#define	ND_SAVEREPLY		0x00000002
594#define	ND_NFSV2		0x00000004
595#define	ND_NFSV3		0x00000008
596#define	ND_NFSV4		0x00000010
597#define	ND_KERBV		0x00000020
598#define	ND_GSSINTEGRITY		0x00000040
599#define	ND_GSSPRIVACY		0x00000080
600#define	ND_WINDOWVERF		0x00000100
601#define	ND_GSSINITREPLY		0x00000200
602#define	ND_STREAMSOCK		0x00000400
603#define	ND_PUBLOOKUP		0x00000800
604#define	ND_USEGSSNAME		0x00001000
605#define	ND_SAMETCPCONN		0x00002000
606#define	ND_IMPLIEDCLID		0x00004000
607#define	ND_NOMOREDATA		0x00008000
608#define	ND_V4WCCATTR		0x00010000
609#define	ND_NFSCB		0x00020000
610#define	ND_AUTHNONE		0x00040000
611#define	ND_EXGSSONLY		0x00080000
612#define	ND_INCRSEQID		0x00100000
613
614/*
615 * ND_GSS should be the "or" of all GSS type authentications.
616 */
617#define	ND_GSS		(ND_KERBV)
618
619struct nfsv4_opflag {
620	int	retfh;
621	int	needscfh;
622	int	savereply;
623	int	modifyfs;
624};
625
626/*
627 * Flags used to indicate what to do w.r.t. seqid checking.
628 */
629#define	NFSRVSEQID_FIRST	0x01
630#define	NFSRVSEQID_LAST		0x02
631#define	NFSRVSEQID_OPEN		0x04
632
633/*
634 * MNT_EXGSSONLY is the Or of all the EXGSS bits.
635 */
636#define	MNT_EXGSSONLY		MNT_EXGSSKRB5
637
638/*
639 * assign a doubly linked list to a new head
640 * and prepend one list into another.
641 */
642#define	LIST_NEWHEAD(nhead, ohead, field) do { 				\
643	if (((nhead)->lh_first = (ohead)->lh_first) != NULL) 		\
644		(ohead)->lh_first->field.le_prev = &(nhead)->lh_first; 	\
645	(ohead)->lh_first = NULL; 					\
646    } while (0)
647
648#define	LIST_PREPEND(head, phead, lelm, field) do {			\
649	if ((head)->lh_first != NULL) {					\
650		(lelm)->field.le_next = (head)->lh_first;		\
651		(lelm)->field.le_next->field.le_prev =			\
652		    &(lelm)->field.le_next;				\
653	}								\
654	(head)->lh_first = (phead)->lh_first;				\
655	(head)->lh_first->field.le_prev = &(head)->lh_first;		\
656    } while (0)
657
658/*
659 * File handle structure for client. Malloc'd to the correct length with
660 * malloc type M_NFSFH.
661 */
662struct nfsfh {
663	u_int16_t	nfh_len;	/* Length of file handle */
664	u_int8_t	nfh_fh[1];	/* and the file handle */
665};
666
667/*
668 * File handle structure for server. The NFSRV_MAXFH constant is
669 * set in nfsdport.h. I use a 32bit length, so that alignment is
670 * preserved.
671 */
672struct nfsrvfh {
673	u_int32_t	nfsrvfh_len;
674	u_int8_t	nfsrvfh_data[NFSRV_MAXFH];
675};
676
677/*
678 * This structure is used for sleep locks on the NFSv4 nfsd threads and
679 * NFSv4 client data structures.
680 */
681struct nfsv4lock {
682	u_int32_t	nfslock_usecnt;
683	u_int8_t	nfslock_lock;
684};
685#define	NFSV4LOCK_LOCK		0x01
686#define	NFSV4LOCK_LOCKWANTED	0x02
687#define	NFSV4LOCK_WANTED	0x04
688
689/*
690 * Values for the override argument for nfsvno_accchk().
691 */
692#define	NFSACCCHK_NOOVERRIDE		0
693#define	NFSACCCHK_ALLOWROOT		1
694#define	NFSACCCHK_ALLOWOWNER		2
695
696/*
697 * and values for the vpislocked argument for nfsvno_accchk().
698 */
699#define	NFSACCCHK_VPNOTLOCKED		0
700#define	NFSACCCHK_VPISLOCKED		1
701
702#endif	/* _KERNEL */
703
704#endif	/* _NFS_NFS_H */
705