nfsargs.h revision 36503
1238104Sdes/*
2238104Sdes * Copyright (c) 1989, 1993, 1995
3238104Sdes *	The Regents of the University of California.  All rights reserved.
4238104Sdes *
5238104Sdes * This code is derived from software contributed to Berkeley by
6238104Sdes * Rick Macklem at The University of Guelph.
7238104Sdes *
8238104Sdes * Redistribution and use in source and binary forms, with or without
9238104Sdes * modification, are permitted provided that the following conditions
10238104Sdes * are met:
11238104Sdes * 1. Redistributions of source code must retain the above copyright
12238104Sdes *    notice, this list of conditions and the following disclaimer.
13238104Sdes * 2. Redistributions in binary form must reproduce the above copyright
14238104Sdes *    notice, this list of conditions and the following disclaimer in the
15238104Sdes *    documentation and/or other materials provided with the distribution.
16238104Sdes * 3. All advertising materials mentioning features or use of this software
17238104Sdes *    must display the following acknowledgement:
18238104Sdes *	This product includes software developed by the University of
19238104Sdes *	California, Berkeley and its contributors.
20238104Sdes * 4. Neither the name of the University nor the names of its contributors
21238104Sdes *    may be used to endorse or promote products derived from this software
22238104Sdes *    without specific prior written permission.
23238104Sdes *
24238104Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25238104Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26246854Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27238104Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28238104Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29238104Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30238104Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31238104Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32238104Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33238104Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34238104Sdes * SUCH DAMAGE.
35238104Sdes *
36238104Sdes *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
37238104Sdes * $Id: nfs.h,v 1.36 1998/05/24 14:41:47 peter Exp $
38238104Sdes */
39238104Sdes
40238104Sdes#ifndef _NFS_NFS_H_
41238104Sdes#define _NFS_NFS_H_
42238104Sdes
43238104Sdes/*
44238104Sdes * Tunable constants for nfs
45246854Sdes */
46238104Sdes
47238104Sdes#define	NFS_MAXIOVEC	34
48238104Sdes#define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
49238104Sdes#define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
50238104Sdes#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
51238104Sdes#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
52238104Sdes#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
53238104Sdes#define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
54238104Sdes#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
55238104Sdes#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
56238104Sdes#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
57238104Sdes#define	NFS_MAXGRPS	16		/* Max. size of groups list */
58238104Sdes#ifndef NFS_MINATTRTIMO
59238104Sdes#define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
60238104Sdes#endif
61238104Sdes#ifndef NFS_MAXATTRTIMO
62238104Sdes#define	NFS_MAXATTRTIMO 60
63238104Sdes#endif
64238104Sdes#ifndef NFS_MINDIRATTRTIMO
65246854Sdes#define	NFS_MINDIRATTRTIMO 30		/* VDIR attrib cache timeout in sec */
66238104Sdes#endif
67238104Sdes#ifndef NFS_MAXDIRATTRTIMO
68238104Sdes#define	NFS_MAXDIRATTRTIMO 60
69238104Sdes#endif
70246854Sdes#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
71238104Sdes#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
72238104Sdes#define NFS_READDIRSIZE	8192		/* Def. readdir size */
73238104Sdes#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
74238104Sdes#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
75238104Sdes#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
76238104Sdes#define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runnable */
77238104Sdes#define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
78246854Sdes#ifndef NFS_GATHERDELAY
79238104Sdes#define NFS_GATHERDELAY		10	/* Default write gather delay (msec) */
80246854Sdes#endif
81246854Sdes#define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
82238104Sdes#ifdef KERNEL
83238104Sdes#define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
84238104Sdes#endif
85238104Sdes
86246854Sdes/*
87246854Sdes * Oddballs
88238104Sdes */
89238104Sdes#define	NMOD(a)		((a) % nfs_asyncdaemons)
90238104Sdes#define NFS_CMPFH(n, f, s) \
91238104Sdes	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
92238104Sdes#define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
93238104Sdes#define NFS_SRVMAXDATA(n) \
94238104Sdes		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
95238104Sdes		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
96238104Sdes
97238104Sdes/*
98238104Sdes * XXX
99238104Sdes * The B_INVAFTERWRITE flag should be set to whatever is required by the
100238104Sdes * buffer cache code to say "Invalidate the block after it is written back".
101238104Sdes */
102238104Sdes#define	B_INVAFTERWRITE	B_NOCACHE
103238104Sdes
104238104Sdes/*
105238104Sdes * The IO_METASYNC flag should be implemented for local file systems.
106238104Sdes * (Until then, it is nothin at all.)
107238104Sdes */
108238104Sdes#ifndef IO_METASYNC
109238104Sdes#define IO_METASYNC	0
110238104Sdes#endif
111238104Sdes
112238104Sdes/*
113238104Sdes * Expected allocation sizes for major data structures. If the actual size
114238104Sdes * of the structure exceeds these sizes, then malloc() will be allocating
115238104Sdes * almost twice the memory required. This is used in nfs_init() to warn
116238104Sdes * the sysadmin that the size of a structure should be reduced.
117238104Sdes * (These sizes are always a power of 2. If the kernel malloc() changes
118238104Sdes *  to one that does not allocate space in powers of 2 size, then this all
119238104Sdes *  becomes bunk!)
120238104Sdes */
121238104Sdes#define NFS_SVCALLOC	256
122238104Sdes#define NFS_UIDALLOC	128
123238104Sdes
124238104Sdes/*
125238104Sdes * Arguments to mount NFS
126238104Sdes */
127238104Sdes#define NFS_ARGSVERSION	3		/* change when nfs_args changes */
128238104Sdesstruct nfs_args {
129238104Sdes	int		version;	/* args structure version number */
130238104Sdes	struct sockaddr	*addr;		/* file server address */
131238104Sdes	int		addrlen;	/* length of address */
132238104Sdes	int		sotype;		/* Socket type */
133238104Sdes	int		proto;		/* and Protocol */
134238104Sdes	u_char		*fh;		/* File handle to be mounted */
135238104Sdes	int		fhsize;		/* Size, in bytes, of fh */
136238104Sdes	int		flags;		/* flags */
137238104Sdes	int		wsize;		/* write size in bytes */
138238104Sdes	int		rsize;		/* read size in bytes */
139238104Sdes	int		readdirsize;	/* readdir size in bytes */
140238104Sdes	int		timeo;		/* initial timeout in .1 secs */
141238104Sdes	int		retrans;	/* times to retry send */
142238104Sdes	int		maxgrouplist;	/* Max. size of group list */
143238104Sdes	int		readahead;	/* # of blocks to readahead */
144238104Sdes	int		leaseterm;	/* Term (sec) of lease */
145238104Sdes	int		deadthresh;	/* Retrans threshold */
146238104Sdes	char		*hostname;	/* server's name */
147246854Sdes	int		acregmin;	/* cache attrs for reg files min time */
148238104Sdes	int		acregmax;	/* cache attrs for reg files max time */
149238104Sdes	int		acdirmin;	/* cache attrs for dirs min time */
150238104Sdes	int		acdirmax;	/* cache attrs for dirs max time */
151238104Sdes};
152238104Sdes
153238104Sdes/*
154238104Sdes * NFS mount option flags
155238104Sdes */
156238104Sdes#define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
157246854Sdes#define	NFSMNT_WSIZE		0x00000002  /* set write size */
158238104Sdes#define	NFSMNT_RSIZE		0x00000004  /* set read size */
159238104Sdes#define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
160238104Sdes#define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
161238104Sdes#define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
162238104Sdes#define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
163238104Sdes#define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
164238104Sdes#define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
165238104Sdes#define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
166238104Sdes#define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
167238104Sdes#define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
168238104Sdes#define	NFSMNT_LEASETERM	0x00001000  /* set lease term (nqnfs) */
169238104Sdes#define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
170238104Sdes#define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
171238104Sdes#define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
172238104Sdes#define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
173238104Sdes#define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
174238104Sdes#define	NFSMNT_ACREGMIN		0x00040000
175238104Sdes#define	NFSMNT_ACREGMAX		0x00080000
176246854Sdes#define	NFSMNT_ACDIRMIN		0x00100000
177246854Sdes#define	NFSMNT_ACDIRMAX		0x00200000
178246854Sdes
179246854Sdes#define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
180238104Sdes#define NFSSTA_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
181238104Sdes#define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
182238104Sdes#define	NFSSTA_MNTD		0x00200000  /* Mnt server for mnt point */
183246854Sdes#define	NFSSTA_DISMINPROG	0x00400000  /* Dismount in progress */
184238104Sdes#define	NFSSTA_DISMNT		0x00800000  /* Dismounted */
185238104Sdes#define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
186238104Sdes#define	NFSSTA_WANTSND		0x02000000  /* Want above */
187246854Sdes#define	NFSSTA_RCVLOCK		0x04000000  /* Rcv socket lock */
188238104Sdes#define	NFSSTA_WANTRCV		0x08000000  /* Want above */
189246854Sdes#define	NFSSTA_WAITAUTH		0x10000000  /* Wait for authentication */
190246854Sdes#define	NFSSTA_HASAUTH		0x20000000  /* Has authenticator */
191246854Sdes#define	NFSSTA_WANTAUTH		0x40000000  /* Wants an authenticator */
192246854Sdes#define	NFSSTA_AUTHERR		0x80000000  /* Authentication error */
193238104Sdes
194238104Sdes/*
195238104Sdes * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
196238104Sdes * should ever try and use it.
197238104Sdes */
198238104Sdesstruct nfsd_args {
199238104Sdes	int	sock;		/* Socket to serve */
200238104Sdes	caddr_t	name;		/* Client addr for connection based sockets */
201238104Sdes	int	namelen;	/* Length of name */
202238104Sdes};
203238104Sdes
204246854Sdesstruct nfsd_srvargs {
205238104Sdes	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
206238104Sdes	uid_t		nsd_uid;	/* Effective uid mapped to cred */
207238104Sdes	u_long		nsd_haddr;	/* Ip address of client */
208238104Sdes	struct ucred	nsd_cr;		/* Cred. uid maps to */
209238104Sdes	int		nsd_authlen;	/* Length of auth string (ret) */
210238104Sdes	u_char		*nsd_authstr;	/* Auth string (ret) */
211238104Sdes	int		nsd_verflen;	/* and the verfier */
212238104Sdes	u_char		*nsd_verfstr;
213238104Sdes	struct timeval	nsd_timestamp;	/* timestamp from verifier */
214238104Sdes	u_long		nsd_ttl;	/* credential ttl (sec) */
215246854Sdes	NFSKERBKEY_T	nsd_key;	/* Session key */
216238104Sdes};
217238104Sdes
218238104Sdesstruct nfsd_cargs {
219238104Sdes	char		*ncd_dirp;	/* Mount dir path */
220238104Sdes	uid_t		ncd_authuid;	/* Effective uid */
221238104Sdes	int		ncd_authtype;	/* Type of authenticator */
222238104Sdes	int		ncd_authlen;	/* Length of authenticator string */
223238104Sdes	u_char		*ncd_authstr;	/* Authenticator string */
224238104Sdes	int		ncd_verflen;	/* and the verifier */
225238104Sdes	u_char		*ncd_verfstr;
226238104Sdes	NFSKERBKEY_T	ncd_key;	/* Session key */
227238104Sdes};
228238104Sdes
229238104Sdes/*
230238104Sdes * XXX to allow amd to include nfs.h without nfsproto.h
231238104Sdes */
232238104Sdes#ifdef NFS_NPROCS
233238104Sdes/*
234238104Sdes * Stats structure
235238104Sdes */
236238104Sdesstruct nfsstats {
237238104Sdes	int	attrcache_hits;
238238104Sdes	int	attrcache_misses;
239238104Sdes	int	lookupcache_hits;
240238104Sdes	int	lookupcache_misses;
241238104Sdes	int	direofcache_hits;
242238104Sdes	int	direofcache_misses;
243238104Sdes	int	biocache_reads;
244238104Sdes	int	read_bios;
245246854Sdes	int	read_physios;
246238104Sdes	int	biocache_writes;
247238104Sdes	int	write_bios;
248246854Sdes	int	write_physios;
249238104Sdes	int	biocache_readlinks;
250238104Sdes	int	readlink_bios;
251238104Sdes	int	biocache_readdirs;
252238104Sdes	int	readdir_bios;
253238104Sdes	int	rpccnt[NFS_NPROCS];
254238104Sdes	int	rpcretries;
255238104Sdes	int	srvrpccnt[NFS_NPROCS];
256238104Sdes	int	srvrpc_errs;
257238104Sdes	int	srv_errs;
258238104Sdes	int	rpcrequests;
259238104Sdes	int	rpctimeouts;
260238104Sdes	int	rpcunexpected;
261238104Sdes	int	rpcinvalid;
262238104Sdes	int	srvcache_inproghits;
263238104Sdes	int	srvcache_idemdonehits;
264238104Sdes	int	srvcache_nonidemdonehits;
265238104Sdes	int	srvcache_misses;
266238104Sdes	int	srvnqnfs_leases;
267238104Sdes	int	srvnqnfs_maxleases;
268238104Sdes	int	srvnqnfs_getleases;
269238104Sdes	int	srvvop_writes;
270238104Sdes};
271238104Sdes#endif
272238104Sdes
273238104Sdes/*
274238104Sdes * Flags for nfssvc() system call.
275238104Sdes */
276238104Sdes#define	NFSSVC_BIOD	0x002
277238104Sdes#define	NFSSVC_NFSD	0x004
278238104Sdes#define	NFSSVC_ADDSOCK	0x008
279238104Sdes#define	NFSSVC_AUTHIN	0x010
280238104Sdes#define	NFSSVC_GOTAUTH	0x040
281238104Sdes#define	NFSSVC_AUTHINFAIL 0x080
282238104Sdes#define	NFSSVC_MNTD	0x100
283238104Sdes
284238104Sdes/*
285238104Sdes * fs.nfs sysctl(3) identifiers
286238104Sdes */
287238104Sdes#define NFS_NFSSTATS	1		/* struct: struct nfsstats */
288238104Sdes#define NFS_NFSPRIVPORT	2		/* int: prohibit nfs to resvports */
289238104Sdes
290238104Sdes#define FS_NFS_NAMES { \
291238104Sdes		       { 0, 0 }, \
292238104Sdes		       { "nfsstats", CTLTYPE_STRUCT }, \
293238104Sdes		       { "nfsprivport", CTLTYPE_INT }, \
294238104Sdes}
295238104Sdes
296238104Sdes#ifdef KERNEL
297238104Sdes
298238104Sdes#ifdef MALLOC_DECLARE
299238104SdesMALLOC_DECLARE(M_NFSREQ);
300238104SdesMALLOC_DECLARE(M_NFSDIROFF);
301238104SdesMALLOC_DECLARE(M_NFSRVDESC);
302238104SdesMALLOC_DECLARE(M_NFSUID);
303238104SdesMALLOC_DECLARE(M_NQLEASE);
304238104SdesMALLOC_DECLARE(M_NFSD);
305238104SdesMALLOC_DECLARE(M_NFSBIGFH);
306238104SdesMALLOC_DECLARE(M_NFSHASH);
307238104Sdes#endif
308238104Sdes
309238104Sdes#ifdef ZONE_INTERRUPT
310238104Sdesextern vm_zone_t nfsmount_zone;
311238104Sdes#endif
312238104Sdes
313238104Sdesstruct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
314238104Sdes
315238104Sdes/*
316238104Sdes * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
317238104Sdes * What should be in this set is open to debate, but I believe that since
318238104Sdes * I/O system calls on ufs are never interrupted by signals the set should
319238104Sdes * be minimal. My reasoning is that many current programs that use signals
320238104Sdes * such as SIGALRM will not expect file I/O system calls to be interrupted
321238104Sdes * by them and break.
322238104Sdes */
323238104Sdes#define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
324238104Sdes			 sigmask(SIGHUP)|sigmask(SIGQUIT))
325238104Sdes
326238104Sdes/*
327238104Sdes * Socket errors ignored for connectionless sockets??
328238104Sdes * For now, ignore them all
329238104Sdes */
330238104Sdes#define	NFSIGNORE_SOERROR(s, e) \
331238104Sdes		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
332238104Sdes		((s) & PR_CONNREQUIRED) == 0)
333238104Sdes
334238104Sdes/*
335238104Sdes * Nfs outstanding request list element
336238104Sdes */
337238104Sdesstruct nfsreq {
338238104Sdes	TAILQ_ENTRY(nfsreq) r_chain;
339246854Sdes	struct mbuf	*r_mreq;
340238104Sdes	struct mbuf	*r_mrep;
341238104Sdes	struct mbuf	*r_md;
342238104Sdes	caddr_t		r_dpos;
343238104Sdes	struct nfsmount *r_nmp;
344238104Sdes	struct vnode	*r_vp;
345238104Sdes	u_long		r_xid;
346238104Sdes	int		r_flags;	/* flags on request, see below */
347238104Sdes	int		r_retry;	/* max retransmission count */
348238104Sdes	int		r_rexmit;	/* current retrans count */
349238104Sdes	int		r_timer;	/* tick counter on reply */
350238104Sdes	u_int32_t	r_procnum;	/* NFS procedure number */
351238104Sdes	int		r_rtt;		/* RTT for rpc */
352238104Sdes	struct proc	*r_procp;	/* Proc that did I/O system call */
353238104Sdes};
354238104Sdes
355238104Sdes/*
356238104Sdes * Queue head for nfsreq's
357238104Sdes */
358238104Sdesextern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
359238104Sdes
360238104Sdes/* Flag values for r_flags */
361238104Sdes#define R_TIMING	0x01		/* timing request (in mntp) */
362238104Sdes#define R_SENT		0x02		/* request has been sent */
363238104Sdes#define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
364238104Sdes#define	R_INTR		0x08		/* intr mnt, signal pending */
365238104Sdes#define	R_SOCKERR	0x10		/* Fatal error on socket */
366238104Sdes#define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
367238104Sdes#define	R_MUSTRESEND	0x40		/* Must resend request */
368238104Sdes#define	R_GETONEREP	0x80		/* Probe for one reply only */
369238104Sdes
370238104Sdes/*
371238104Sdes * A list of nfssvc_sock structures is maintained with all the sockets
372246854Sdes * that require service by the nfsd.
373246854Sdes * The nfsuid structs hang off of the nfssvc_sock structs in both lru
374238104Sdes * and uid hash lists.
375238104Sdes */
376238104Sdes#ifndef NFS_UIDHASHSIZ
377238104Sdes#define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
378238104Sdes#endif
379238104Sdes#define	NUIDHASH(sock, uid) \
380238104Sdes	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
381238104Sdes#ifndef NFS_WDELAYHASHSIZ
382238104Sdes#define	NFS_WDELAYHASHSIZ 16	/* and with this */
383238104Sdes#endif
384238104Sdes#define	NWDELAYHASH(sock, f) \
385238104Sdes	(&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
386238104Sdes#ifndef NFS_MUIDHASHSIZ
387238104Sdes#define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
388238104Sdes#endif
389238104Sdes#define	NMUIDHASH(nmp, uid) \
390238104Sdes	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
391238104Sdes#define	NFSNOHASH(fhsum) \
392238104Sdes	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
393238104Sdes
394238104Sdes/*
395238104Sdes * Network address hash list element
396238104Sdes */
397238104Sdesunion nethostaddr {
398238104Sdes	u_long had_inetaddr;
399238104Sdes	struct sockaddr *had_nam;
400238104Sdes};
401238104Sdes
402238104Sdesstruct nfsuid {
403238104Sdes	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
404238104Sdes	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
405238104Sdes	int		nu_flag;	/* Flags */
406238104Sdes	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
407238104Sdes	struct ucred	nu_cr;		/* Cred uid mapped to */
408238104Sdes	int		nu_expire;	/* Expiry time (sec) */
409238104Sdes	struct timeval	nu_timestamp;	/* Kerb. timestamp */
410238104Sdes	u_long		nu_nickname;	/* Nickname on server */
411238104Sdes	NFSKERBKEY_T	nu_key;		/* and session key */
412238104Sdes};
413238104Sdes
414238104Sdes#define	nu_inetaddr	nu_haddr.had_inetaddr
415238104Sdes#define	nu_nam		nu_haddr.had_nam
416238104Sdes/* Bits for nu_flag */
417238104Sdes#define	NU_INETADDR	0x1
418238104Sdes#define NU_NAM		0x2
419238104Sdes#define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
420238104Sdes
421238104Sdesstruct nfsrv_rec {
422238104Sdes	STAILQ_ENTRY(nfsrv_rec) nr_link;
423238104Sdes	struct sockaddr	*nr_address;
424238104Sdes	struct mbuf	*nr_packet;
425238104Sdes};
426238104Sdes
427238104Sdesstruct nfssvc_sock {
428238104Sdes	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
429238104Sdes	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
430238104Sdes	struct file	*ns_fp;
431238104Sdes	struct socket	*ns_so;
432238104Sdes	struct sockaddr	*ns_nam;
433238104Sdes	struct mbuf	*ns_raw;
434238104Sdes	struct mbuf	*ns_rawend;
435238104Sdes	STAILQ_HEAD(, nfsrv_rec) ns_rec;
436238104Sdes	struct mbuf	*ns_frag;
437238104Sdes	int		ns_flag;
438238104Sdes	int		ns_solock;
439238104Sdes	int		ns_cc;
440238104Sdes	int		ns_reclen;
441238104Sdes	int		ns_numuids;
442238104Sdes	u_long		ns_sref;
443238104Sdes	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
444238104Sdes	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
445238104Sdes	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
446238104Sdes};
447238104Sdes
448238104Sdes/* Bits for "ns_flag" */
449238104Sdes#define	SLP_VALID	0x01
450238104Sdes#define	SLP_DOREC	0x02
451238104Sdes#define	SLP_NEEDQ	0x04
452238104Sdes#define	SLP_DISCONN	0x08
453238104Sdes#define	SLP_GETSTREAM	0x10
454238104Sdes#define	SLP_LASTFRAG	0x20
455238104Sdes#define SLP_ALLFLAGS	0xff
456238104Sdes
457238104Sdesextern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
458238104Sdesextern int nfssvc_sockhead_flag;
459246854Sdes#define	SLP_INIT	0x01
460238104Sdes#define	SLP_WANTINIT	0x02
461238104Sdes
462238104Sdes/*
463238104Sdes * One of these structures is allocated for each nfsd.
464238104Sdes */
465238104Sdesstruct nfsd {
466238104Sdes	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
467238104Sdes	int		nfsd_flag;	/* NFSD_ flags */
468238104Sdes	struct nfssvc_sock *nfsd_slp;	/* Current socket */
469238104Sdes	int		nfsd_authlen;	/* Authenticator len */
470238104Sdes	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
471238104Sdes	int		nfsd_verflen;	/* and the Verifier */
472238104Sdes	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
473238104Sdes	struct proc	*nfsd_procp;	/* Proc ptr */
474238104Sdes	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
475238104Sdes};
476238104Sdes
477238104Sdes/* Bits for "nfsd_flag" */
478246854Sdes#define	NFSD_WAITING	0x01
479246854Sdes#define	NFSD_REQINPROG	0x02
480246854Sdes#define	NFSD_NEEDAUTH	0x04
481246854Sdes#define	NFSD_AUTHFAIL	0x08
482246854Sdes
483246854Sdes/*
484238104Sdes * This structure is used by the server for describing each request.
485238104Sdes * Some fields are used only when write request gathering is performed.
486246854Sdes */
487246854Sdesstruct nfsrv_descript {
488246854Sdes	u_quad_t		nd_time;	/* Write deadline (usec) */
489246854Sdes	off_t			nd_off;		/* Start byte offset */
490246854Sdes	off_t			nd_eoff;	/* and end byte offset */
491246854Sdes	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
492238104Sdes	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
493238104Sdes	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
494246854Sdes	struct mbuf		*nd_mrep;	/* Request mbuf list */
495246854Sdes	struct mbuf		*nd_md;		/* Current dissect mbuf */
496246854Sdes	struct mbuf		*nd_mreq;	/* Reply mbuf list */
497246854Sdes	struct sockaddr		*nd_nam;	/* and socket addr */
498246854Sdes	struct sockaddr		*nd_nam2;	/* return socket addr */
499246854Sdes	caddr_t			nd_dpos;	/* Current dissect pos */
500238104Sdes	u_int32_t		nd_procnum;	/* RPC # */
501238104Sdes	int			nd_stable;	/* storage type */
502246854Sdes	int			nd_flag;	/* nd_flag */
503246854Sdes	int			nd_len;		/* Length of this write */
504246854Sdes	int			nd_repstat;	/* Reply status */
505246854Sdes	u_long			nd_retxid;	/* Reply xid */
506246854Sdes	u_long			nd_duration;	/* Lease duration */
507246854Sdes	struct timeval		nd_starttime;	/* Time RPC initiated */
508238104Sdes	fhandle_t		nd_fh;		/* File handle */
509238104Sdes	struct ucred		nd_cr;		/* Credentials */
510246854Sdes};
511246854Sdes
512246854Sdes/* Bits for "nd_flag" */
513246854Sdes#define	ND_READ		LEASE_READ
514246854Sdes#define ND_WRITE	LEASE_WRITE
515246854Sdes#define ND_CHECK	0x04
516238104Sdes#define ND_LEASE	(ND_READ | ND_WRITE | ND_CHECK)
517238104Sdes#define ND_NFSV3	0x08
518246854Sdes#define ND_NQNFS	0x10
519246854Sdes#define ND_KERBNICK	0x20
520246854Sdes#define ND_KERBFULL	0x40
521246854Sdes#define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
522246854Sdes
523246854Sdesextern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
524238104Sdesextern int nfsd_head_flag;
525238104Sdes#define	NFSD_CHECKSLP	0x01
526246854Sdes
527246854Sdes/*
528246854Sdes * These macros compare nfsrv_descript structures.
529246854Sdes */
530246854Sdes#define NFSW_CONTIG(o, n) \
531246854Sdes		((o)->nd_eoff >= (n)->nd_off && \
532238104Sdes		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
533238104Sdes
534246854Sdes#define NFSW_SAMECRED(o, n) \
535246854Sdes	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
536246854Sdes 	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
537246854Sdes		sizeof (struct ucred)))
538246854Sdes
539246854Sdes/*
540246854Sdes * Defines for WebNFS
541238104Sdes */
542238104Sdes
543246854Sdes#define WEBNFS_ESC_CHAR		'%'
544246854Sdes#define WEBNFS_SPECCHAR_START	0x80
545246854Sdes
546246854Sdes#define WEBNFS_NATIVE_CHAR	0x80
547246854Sdes/*
548246854Sdes * ..
549238104Sdes * Possibly more here in the future.
550238104Sdes */
551246854Sdes
552246854Sdes/*
553246854Sdes * Macro for converting escape characters in WebNFS pathnames.
554246854Sdes * Should really be in libkern.
555246854Sdes */
556246854Sdes
557238104Sdes#define HEXTOC(c) \
558238104Sdes	((c) >= 'a' ? ((c) - ('a' - 10)) : \
559246854Sdes	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
560246854Sdes#define HEXSTRTOI(p) \
561246854Sdes	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
562246854Sdes
563246854Sdes#ifdef NFS_DEBUG
564246854Sdes
565238104Sdesextern int nfs_debug;
566238104Sdes#define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
567246854Sdes#define NFS_DEBUG_WG		2 /* server write gathering */
568246854Sdes#define NFS_DEBUG_RC		4 /* server request caching */
569246854Sdes
570246854Sdes#define NFS_DPF(cat, args)					\
571246854Sdes	do {							\
572246854Sdes		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
573238104Sdes	} while (0)
574238104Sdes
575246854Sdes#else
576246854Sdes
577246854Sdes#define NFS_DPF(cat, args)
578246854Sdes
579246854Sdes#endif
580246854Sdes
581238104Sdesu_quad_t nfs_curusec __P((void));
582238104Sdesint	nfs_init __P((struct vfsconf *vfsp));
583246854Sdesint	nfs_reply __P((struct nfsreq *));
584246854Sdesint	nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
585246854Sdesint	nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *,
586246854Sdes		      struct nfsreq *));
587246854Sdesint	nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *,
588246854Sdes			 int, int, u_quad_t *, struct mbuf **, struct mbuf **,
589238104Sdes			 caddr_t *));
590238104Sdesint	nfs_sndlock __P((int *, int *, struct nfsreq *));
591246854Sdesvoid	nfs_sndunlock __P((int *, int *));
592246854Sdesint	nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
593246854Sdesint	nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *,
594246854Sdes			   int));
595246854Sdesint	nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *));
596246854Sdesint	nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *,
597238104Sdes			  int *));
598238104Sdesint	nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *));
599246854Sdesint	nfs_asyncio __P((struct buf *, struct ucred *));
600246854Sdesint	nfs_doio __P((struct buf *, struct ucred *, struct proc *));
601246854Sdesint	nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *));
602246854Sdesint	nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *));
603246854Sdesint	nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *));
604246854Sdesint	nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
605238104Sdesvoid	nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *,
606238104Sdes			   struct nfs_fattr *));
607246854Sdesvoid	nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int,
608246854Sdes			 struct vattr *, struct mbuf **, char **));
609246854Sdesvoid	nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *,
610246854Sdes				struct mbuf **, char **));
611246854Sdesint	netaddr_match __P((int, union nethostaddr *, struct sockaddr *));
612246854Sdesint	nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *,
613246854Sdes			 struct ucred *, struct mbuf **, struct mbuf **,
614238104Sdes			 caddr_t *));
615238104Sdesint	nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *,
616246854Sdes			       struct vattr *));
617246854Sdesint	nfs_namei __P((struct nameidata *, fhandle_t *, int,
618246854Sdes		       struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
619246854Sdes		       caddr_t *, struct vnode **, struct proc *, int, int));
620246854Sdesvoid	nfsm_adj __P((struct mbuf *, int, int));
621246854Sdesint	nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *));
622238104Sdesvoid	nfsrv_initcache __P((void));
623238104Sdesint	nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *,
624246854Sdes			 char **, int *, char *, int *, NFSKERBKEY_T));
625246854Sdesint	nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **,
626246854Sdes			     int *, char *, int));
627246854Sdesint	nfs_savenickauth __P((struct nfsmount *, struct ucred *, int,
628246854Sdes			      NFSKERBKEY_T, struct mbuf **, char **,
629246854Sdes			      struct mbuf *));
630238104Sdesint	nfs_adv __P((struct mbuf **, caddr_t *, int, int));
631238104Sdesvoid	nfs_nhinit __P((void));
632246854Sdesvoid	nfs_timer __P((void*));
633246854Sdesu_long	nfs_hash __P((nfsfh_t *, int));
634246854Sdesint	nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *,
635246854Sdes			 struct nfsrv_descript **));
636246854Sdesint	nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *,
637246854Sdes			    struct mbuf **));
638238104Sdesvoid	nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *));
639238104Sdesvoid	nfsrv_cleancache __P((void));
640246854Sdesint	nfs_connect __P((struct nfsmount *, struct nfsreq *));
641246854Sdesvoid	nfs_disconnect __P((struct nfsmount *));
642246854Sdesint	nfs_getattrcache __P((struct vnode *, struct vattr *));
643246854Sdesint	nfsm_strtmbuf __P((struct mbuf **, char **, char *, long));
644246854Sdesint	nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *,
645246854Sdes			 int));
646238104Sdesint	nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *));
647238104Sdesvoid	nfsrv_init __P((int));
648246854Sdesvoid	nfs_clearcommit __P((struct mount *));
649246854Sdesint	nfsrv_errmap __P((struct nfsrv_descript *, int));
650246854Sdesvoid	nfsrvw_sort __P((gid_t *, int));
651246854Sdesvoid	nfsrv_setcred __P((struct ucred *, struct ucred *));
652246854Sdesint	nfs_writebp __P((struct buf *, int));
653246854Sdesint	nfsrv_object_create __P((struct vnode *));
654246854Sdesvoid	nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
655238104Sdesint	nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
656238104Sdes			       struct proc *, struct mbuf **));
657246854Sdesint	nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
658246854Sdes			struct proc *p));
659246854Sdes
660246854Sdesint	nfsrv3_access __P((struct nfsrv_descript *nfsd,
661246854Sdes			   struct nfssvc_sock *slp,
662246854Sdes			   struct proc *procp, struct mbuf **mrq));
663238104Sdesint	nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
664238104Sdes			  struct proc *procp, struct mbuf **mrq));
665246854Sdesint	nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
666246854Sdes			  struct proc *procp, struct mbuf **mrq));
667246854Sdesint	nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *,
668246854Sdes			  struct nfssvc_sock *, struct sockaddr *, int *,
669246854Sdes			  int, int));
670246854Sdesint	nfsrv_setpublicfs __P((struct mount *, struct netexport *,
671238104Sdes			       struct export_args *));
672238104Sdesint	nfs_ispublicfh __P((fhandle_t *));
673246854Sdesint	nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
674246854Sdes			  struct proc *procp, struct mbuf **mrq));
675246854Sdesint	nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
676246854Sdes			   struct proc *procp, struct mbuf **mrq));
677246854Sdesint	nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
678246854Sdes			struct proc *procp, struct mbuf **mrq));
679246854Sdesint	nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
680246854Sdes			  struct proc *procp, struct mbuf **mrq));
681238104Sdesint	nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
682238104Sdes			 struct proc *procp, struct mbuf **mrq));
683246854Sdesint	nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
684246854Sdes			 struct proc *procp, struct mbuf **mrq));
685246854Sdesint	nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
686246854Sdes			struct proc *procp, struct mbuf **mrq));
687246854Sdesint	nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
688246854Sdes			struct proc *procp, struct mbuf **mrq));
689246854Sdesint	nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
690246854Sdes			    struct nfssvc_sock *slp, struct proc *procp,
691246854Sdes			    struct mbuf **mrq));
692246854Sdesint	nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
693246854Sdes			struct proc *procp, struct mbuf **mrq));
694246854Sdesint	nfsrv_readdir __P((struct nfsrv_descript *nfsd,
695246854Sdes			   struct nfssvc_sock *slp,
696246854Sdes			   struct proc *procp, struct mbuf **mrq));
697246854Sdesint	nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
698238104Sdes			       struct nfssvc_sock *slp, struct proc *procp,
699246854Sdes			       struct mbuf **mrq));
700246854Sdesint	nfsrv_readlink __P((struct nfsrv_descript *nfsd,
701246854Sdes			    struct nfssvc_sock *slp, struct proc *procp,
702246854Sdes			    struct mbuf **mrq));
703246854Sdesint	nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
704246854Sdes			  struct proc *procp, struct mbuf **mrq));
705246854Sdesint	nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
706246854Sdes			  struct proc *procp, struct mbuf **mrq));
707246854Sdesint	nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
708246854Sdes			 struct proc *procp, struct mbuf **mrq));
709246854Sdesint	nfsrv_setattr __P((struct nfsrv_descript *nfsd,
710246854Sdes			   struct nfssvc_sock *slp,
711246854Sdes			   struct proc *procp, struct mbuf **mrq));
712246854Sdesint	nfsrv_statfs __P((struct nfsrv_descript *nfsd,
713246854Sdes			  struct nfssvc_sock *slp,
714246854Sdes			  struct proc *procp, struct mbuf **mrq));
715246854Sdesint	nfsrv_symlink __P((struct nfsrv_descript *nfsd,
716246854Sdes			   struct nfssvc_sock *slp,
717246854Sdes			   struct proc *procp, struct mbuf **mrq));
718238104Sdesint	nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
719238104Sdes			 struct proc *procp, struct mbuf **mrq));
720246854Sdesvoid	nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag));
721246854Sdesvoid	nfsrv_slpderef __P((struct nfssvc_sock *slp));
722246854Sdes#endif	/* KERNEL */
723238104Sdes
724238104Sdes#endif
725246854Sdes