nfsargs.h revision 51791
131567Ssef/*
231899Ssef * Copyright (c) 1989, 1993, 1995
331899Ssef *	The Regents of the University of California.  All rights reserved.
431899Ssef *
531899Ssef * This code is derived from software contributed to Berkeley by
631899Ssef * Rick Macklem at The University of Guelph.
731899Ssef *
831899Ssef * Redistribution and use in source and binary forms, with or without
931899Ssef * modification, are permitted provided that the following conditions
1031899Ssef * are met:
1131899Ssef * 1. Redistributions of source code must retain the above copyright
1231899Ssef *    notice, this list of conditions and the following disclaimer.
1331899Ssef * 2. Redistributions in binary form must reproduce the above copyright
1431899Ssef *    notice, this list of conditions and the following disclaimer in the
1531899Ssef *    documentation and/or other materials provided with the distribution.
1631899Ssef * 3. All advertising materials mentioning features or use of this software
1731899Ssef *    must display the following acknowledgement:
1831899Ssef *	This product includes software developed by the University of
1931899Ssef *	California, Berkeley and its contributors.
2031899Ssef * 4. Neither the name of the University nor the names of its contributors
2131899Ssef *    may be used to endorse or promote products derived from this software
2231899Ssef *    without specific prior written permission.
2331899Ssef *
2431899Ssef * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2531899Ssef * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2631899Ssef * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731899Ssef * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2831899Ssef * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2931899Ssef * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3031899Ssef * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3131899Ssef * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3232275Scharnier * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3332275Scharnier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3450477Speter * SUCH DAMAGE.
3532275Scharnier *
3632275Scharnier *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
3731899Ssef * $FreeBSD: head/sys/nfsclient/nfsargs.h 51791 1999-09-29 15:03:48Z marcel $
3831567Ssef */
3931567Ssef
4031567Ssef#ifndef _NFS_NFS_H_
4131567Ssef#define _NFS_NFS_H_
4231567Ssef
4331567Ssef#ifdef KERNEL
4431567Ssef#include "opt_nfs.h"
4585301Sdes#endif
4685301Sdes
4785301Sdes/*
4885301Sdes * Tunable constants for nfs
4985301Sdes */
5085301Sdes
5185301Sdes#define	NFS_MAXIOVEC	34
5285301Sdes#define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
5332275Scharnier#define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
5432275Scharnier#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
5532275Scharnier#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
5631567Ssef#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
5731567Ssef#define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
5831567Ssef#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
5931567Ssef#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
6031567Ssef#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
61101282Smdodd#define	NFS_MAXGRPS	16		/* Max. size of groups list */
6231567Ssef#ifndef NFS_MINATTRTIMO
6331567Ssef#define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
6431567Ssef#endif
6531567Ssef#ifndef NFS_MAXATTRTIMO
6631567Ssef#define	NFS_MAXATTRTIMO 60
6731567Ssef#endif
6831567Ssef#ifndef NFS_MINDIRATTRTIMO
6931567Ssef#define	NFS_MINDIRATTRTIMO 30		/* VDIR attrib cache timeout in sec */
7031567Ssef#endif
7131567Ssef#ifndef NFS_MAXDIRATTRTIMO
7231567Ssef#define	NFS_MAXDIRATTRTIMO 60
7331567Ssef#endif
7431567Ssef#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
7531567Ssef#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
7631567Ssef#define NFS_READDIRSIZE	8192		/* Def. readdir size */
7731567Ssef#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
7831567Ssef#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
7931567Ssef#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
8031567Ssef#define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runnable */
8131567Ssef#define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
8231567Ssef#ifndef NFS_GATHERDELAY
8331567Ssef#define NFS_GATHERDELAY		10	/* Default write gather delay (msec) */
8431567Ssef#endif
8531567Ssef#define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
8631567Ssef#ifdef KERNEL
8731567Ssef#define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
8831567Ssef#endif
8931567Ssef
9031567Ssef/*
91100357Smarkm * Oddballs
9231567Ssef */
9331567Ssef#define	NMOD(a)		((a) % nfs_asyncdaemons)
9431567Ssef#define NFS_CMPFH(n, f, s) \
9531567Ssef	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
9631567Ssef#define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
9731567Ssef#define NFS_SRVMAXDATA(n) \
9831567Ssef		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
9931567Ssef		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
10031567Ssef
10131567Ssef/*
10231567Ssef * XXX
10331567Ssef * The B_INVAFTERWRITE flag should be set to whatever is required by the
10431567Ssef * buffer cache code to say "Invalidate the block after it is written back".
10531567Ssef */
10631567Ssef#define	B_INVAFTERWRITE	B_NOCACHE
10731567Ssef
10831567Ssef/*
10931567Ssef * The IO_METASYNC flag should be implemented for local file systems.
11031567Ssef * (Until then, it is nothin at all.)
11131567Ssef */
11231567Ssef#ifndef IO_METASYNC
11331567Ssef#define IO_METASYNC	0
114101282Smdodd#endif
11531567Ssef
11631567Ssef/*
11731567Ssef * Expected allocation sizes for major data structures. If the actual size
11831567Ssef * of the structure exceeds these sizes, then malloc() will be allocating
11931567Ssef * almost twice the memory required. This is used in nfs_init() to warn
12031567Ssef * the sysadmin that the size of a structure should be reduced.
12131567Ssef * (These sizes are always a power of 2. If the kernel malloc() changes
122101282Smdodd *  to one that does not allocate space in powers of 2 size, then this all
123101282Smdodd *  becomes bunk!)
12431567Ssef */
12531567Ssef#define NFS_SVCALLOC	256
126101282Smdodd#define NFS_UIDALLOC	128
12731567Ssef
12831567Ssef/*
129101282Smdodd * Arguments to mount NFS
13031567Ssef */
13131567Ssef#define NFS_ARGSVERSION	3		/* change when nfs_args changes */
13231567Ssefstruct nfs_args {
13331567Ssef	int		version;	/* args structure version number */
13431567Ssef	struct sockaddr	*addr;		/* file server address */
13531567Ssef	int		addrlen;	/* length of address */
13631567Ssef	int		sotype;		/* Socket type */
13731567Ssef	int		proto;		/* and Protocol */
13831567Ssef	u_char		*fh;		/* File handle to be mounted */
13931567Ssef	int		fhsize;		/* Size, in bytes, of fh */
14031567Ssef	int		flags;		/* flags */
14131567Ssef	int		wsize;		/* write size in bytes */
14231567Ssef	int		rsize;		/* read size in bytes */
14331567Ssef	int		readdirsize;	/* readdir size in bytes */
14431567Ssef	int		timeo;		/* initial timeout in .1 secs */
14531567Ssef	int		retrans;	/* times to retry send */
14631567Ssef	int		maxgrouplist;	/* Max. size of group list */
14731567Ssef	int		readahead;	/* # of blocks to readahead */
14831567Ssef	int		leaseterm;	/* Term (sec) of lease */
14931567Ssef	int		deadthresh;	/* Retrans threshold */
15031567Ssef	char		*hostname;	/* server's name */
15131567Ssef	int		acregmin;	/* cache attrs for reg files min time */
15231567Ssef	int		acregmax;	/* cache attrs for reg files max time */
15331567Ssef	int		acdirmin;	/* cache attrs for dirs min time */
15431567Ssef	int		acdirmax;	/* cache attrs for dirs max time */
15531567Ssef};
15631567Ssef
15731567Ssef/*
15831567Ssef * NFS mount option flags
15931567Ssef */
160101282Smdodd#define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
16131567Ssef#define	NFSMNT_WSIZE		0x00000002  /* set write size */
16231567Ssef#define	NFSMNT_RSIZE		0x00000004  /* set read size */
163101283Smdodd#define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
164101283Smdodd#define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
165101283Smdodd#define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
166101283Smdodd#define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
167101283Smdodd#define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
168101283Smdodd#define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
169101283Smdodd#define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
170101283Smdodd#define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
17131567Ssef#define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
17231567Ssef#define	NFSMNT_LEASETERM	0x00001000  /* set lease term (nqnfs) */
17331567Ssef#define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
17431567Ssef#define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
17531567Ssef#define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
17631567Ssef#define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
17731567Ssef#define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
17831567Ssef#define	NFSMNT_ACREGMIN		0x00040000
17931567Ssef#define	NFSMNT_ACREGMAX		0x00080000
18031567Ssef#define	NFSMNT_ACDIRMIN		0x00100000
18131567Ssef#define	NFSMNT_ACDIRMAX		0x00200000
18231567Ssef
18331567Ssef#define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
184101282Smdodd#define NFSSTA_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
18531567Ssef#define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
18631567Ssef#define	NFSSTA_MNTD		0x00200000  /* Mnt server for mnt point */
18731567Ssef#define	NFSSTA_DISMINPROG	0x00400000  /* Dismount in progress */
18831567Ssef#define	NFSSTA_DISMNT		0x00800000  /* Dismounted */
18931567Ssef#define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
19031567Ssef#define	NFSSTA_WANTSND		0x02000000  /* Want above */
19131567Ssef#define	NFSSTA_RCVLOCK		0x04000000  /* Rcv socket lock */
19231567Ssef#define	NFSSTA_WANTRCV		0x08000000  /* Want above */
19331567Ssef#define	NFSSTA_WAITAUTH		0x10000000  /* Wait for authentication */
19431567Ssef#define	NFSSTA_HASAUTH		0x20000000  /* Has authenticator */
19531567Ssef#define	NFSSTA_WANTAUTH		0x40000000  /* Wants an authenticator */
19631567Ssef#define	NFSSTA_AUTHERR		0x80000000  /* Authentication error */
19731567Ssef
19831567Ssef/*
19931567Ssef * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
20031567Ssef * should ever try and use it.
20131567Ssef */
20231567Ssefstruct nfsd_args {
20331567Ssef	int	sock;		/* Socket to serve */
20431567Ssef	caddr_t	name;		/* Client addr for connection based sockets */
20531567Ssef	int	namelen;	/* Length of name */
20631567Ssef};
20731567Ssef
20831567Ssefstruct nfsd_srvargs {
20931567Ssef	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
21031567Ssef	uid_t		nsd_uid;	/* Effective uid mapped to cred */
21131567Ssef	u_int32_t	nsd_haddr;	/* Ip address of client */
21231567Ssef	struct ucred	nsd_cr;		/* Cred. uid maps to */
21331567Ssef	int		nsd_authlen;	/* Length of auth string (ret) */
21431567Ssef	u_char		*nsd_authstr;	/* Auth string (ret) */
21531567Ssef	int		nsd_verflen;	/* and the verfier */
21631567Ssef	u_char		*nsd_verfstr;
21731567Ssef	struct timeval	nsd_timestamp;	/* timestamp from verifier */
21831567Ssef	u_int32_t	nsd_ttl;	/* credential ttl (sec) */
21931567Ssef	NFSKERBKEY_T	nsd_key;	/* Session key */
22031567Ssef};
22131567Ssef
22231567Ssefstruct nfsd_cargs {
22331567Ssef	char		*ncd_dirp;	/* Mount dir path */
22431567Ssef	uid_t		ncd_authuid;	/* Effective uid */
225101282Smdodd	int		ncd_authtype;	/* Type of authenticator */
22631567Ssef	int		ncd_authlen;	/* Length of authenticator string */
22731567Ssef	u_char		*ncd_authstr;	/* Authenticator string */
22831567Ssef	int		ncd_verflen;	/* and the verifier */
22931567Ssef	u_char		*ncd_verfstr;
23031567Ssef	NFSKERBKEY_T	ncd_key;	/* Session key */
23131567Ssef};
23231567Ssef
23331567Ssef/*
23431567Ssef * XXX to allow amd to include nfs.h without nfsproto.h
23531567Ssef */
236101282Smdodd#ifdef NFS_NPROCS
23731567Ssef/*
23831567Ssef * Stats structure
23931567Ssef */
24031567Ssefstruct nfsstats {
24131567Ssef	int	attrcache_hits;
24231567Ssef	int	attrcache_misses;
24331567Ssef	int	lookupcache_hits;
24431567Ssef	int	lookupcache_misses;
24531567Ssef	int	direofcache_hits;
24631567Ssef	int	direofcache_misses;
24731567Ssef	int	biocache_reads;
24831567Ssef	int	read_bios;
249101282Smdodd	int	read_physios;
250101282Smdodd	int	biocache_writes;
25131567Ssef	int	write_bios;
25231567Ssef	int	write_physios;
25331567Ssef	int	biocache_readlinks;
25431567Ssef	int	readlink_bios;
25531567Ssef	int	biocache_readdirs;
25631567Ssef	int	readdir_bios;
25731567Ssef	int	rpccnt[NFS_NPROCS];
258101282Smdodd	int	rpcretries;
259101282Smdodd	int	srvrpccnt[NFS_NPROCS];
26031567Ssef	int	srvrpc_errs;
26131567Ssef	int	srv_errs;
262101282Smdodd	int	rpcrequests;
26331567Ssef	int	rpctimeouts;
26431567Ssef	int	rpcunexpected;
265101282Smdodd	int	rpcinvalid;
26631567Ssef	int	srvcache_inproghits;
26731567Ssef	int	srvcache_idemdonehits;
26831567Ssef	int	srvcache_nonidemdonehits;
269101282Smdodd	int	srvcache_misses;
270101282Smdodd	int	srvnqnfs_leases;
27131567Ssef	int	srvnqnfs_maxleases;
272101282Smdodd	int	srvnqnfs_getleases;
27331567Ssef	int	srvvop_writes;
27431567Ssef};
27531567Ssef#endif
27631567Ssef
27731567Ssef/*
27831567Ssef * Flags for nfssvc() system call.
27931567Ssef */
28031567Ssef#define	NFSSVC_BIOD	0x002
28131567Ssef#define	NFSSVC_NFSD	0x004
28231567Ssef#define	NFSSVC_ADDSOCK	0x008
28331567Ssef#define	NFSSVC_AUTHIN	0x010
28431567Ssef#define	NFSSVC_GOTAUTH	0x040
28537453Sbde#define	NFSSVC_AUTHINFAIL 0x080
28631567Ssef#define	NFSSVC_MNTD	0x100
28731567Ssef
28831567Ssef/*
28931567Ssef * fs.nfs sysctl(3) identifiers
29031567Ssef */
29131567Ssef#define NFS_NFSSTATS	1		/* struct: struct nfsstats */
29231567Ssef#define NFS_NFSPRIVPORT	2		/* int: prohibit nfs to resvports */
29331567Ssef
29431567Ssef#define FS_NFS_NAMES { \
29531567Ssef		       { 0, 0 }, \
29631567Ssef		       { "nfsstats", CTLTYPE_STRUCT }, \
29731567Ssef		       { "nfsprivport", CTLTYPE_INT }, \
29831567Ssef}
29931567Ssef
30031567Ssef#ifdef KERNEL
30137453Sbde
30231567Ssef#ifdef MALLOC_DECLARE
30331567SsefMALLOC_DECLARE(M_NFSREQ);
30431567SsefMALLOC_DECLARE(M_NFSDIROFF);
30531567SsefMALLOC_DECLARE(M_NFSRVDESC);
30631567SsefMALLOC_DECLARE(M_NFSUID);
30731567SsefMALLOC_DECLARE(M_NQLEASE);
30831567SsefMALLOC_DECLARE(M_NFSD);
30931567SsefMALLOC_DECLARE(M_NFSBIGFH);
31031567SsefMALLOC_DECLARE(M_NFSHASH);
31131567Ssef#endif
31231567Ssef
31331567Ssef#ifdef ZONE_INTERRUPT
31431567Ssefextern vm_zone_t nfsmount_zone;
315101282Smdodd#endif
31631567Ssef
31731567Ssefextern struct callout_handle nfs_timer_handle;
318101282Smdodd
31931567Ssefstruct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
320
321/*
322 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
323 * What should be in this set is open to debate, but I believe that since
324 * I/O system calls on ufs are never interrupted by signals the set should
325 * be minimal. My reasoning is that many current programs that use signals
326 * such as SIGALRM will not expect file I/O system calls to be interrupted
327 * by them and break.
328 */
329#define	NFSINT_SIGMASK(set) 						\
330	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
331	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
332	 SIGISMEMBER(set, SIGQUIT))
333
334/*
335 * Socket errors ignored for connectionless sockets??
336 * For now, ignore them all
337 */
338#define	NFSIGNORE_SOERROR(s, e) \
339		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
340		((s) & PR_CONNREQUIRED) == 0)
341
342/*
343 * Nfs outstanding request list element
344 */
345struct nfsreq {
346	TAILQ_ENTRY(nfsreq) r_chain;
347	struct mbuf	*r_mreq;
348	struct mbuf	*r_mrep;
349	struct mbuf	*r_md;
350	caddr_t		r_dpos;
351	struct nfsmount *r_nmp;
352	struct vnode	*r_vp;
353	u_int32_t	r_xid;
354	int		r_flags;	/* flags on request, see below */
355	int		r_retry;	/* max retransmission count */
356	int		r_rexmit;	/* current retrans count */
357	int		r_timer;	/* tick counter on reply */
358	u_int32_t	r_procnum;	/* NFS procedure number */
359	int		r_rtt;		/* RTT for rpc */
360	struct proc	*r_procp;	/* Proc that did I/O system call */
361};
362
363/*
364 * Queue head for nfsreq's
365 */
366extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
367
368/* Flag values for r_flags */
369#define R_TIMING	0x01		/* timing request (in mntp) */
370#define R_SENT		0x02		/* request has been sent */
371#define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
372#define	R_INTR		0x08		/* intr mnt, signal pending */
373#define	R_SOCKERR	0x10		/* Fatal error on socket */
374#define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
375#define	R_MUSTRESEND	0x40		/* Must resend request */
376#define	R_GETONEREP	0x80		/* Probe for one reply only */
377
378/*
379 * A list of nfssvc_sock structures is maintained with all the sockets
380 * that require service by the nfsd.
381 * The nfsuid structs hang off of the nfssvc_sock structs in both lru
382 * and uid hash lists.
383 */
384#ifndef NFS_UIDHASHSIZ
385#define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
386#endif
387#define	NUIDHASH(sock, uid) \
388	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
389#ifndef NFS_WDELAYHASHSIZ
390#define	NFS_WDELAYHASHSIZ 16	/* and with this */
391#endif
392#define	NWDELAYHASH(sock, f) \
393	(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
394#ifndef NFS_MUIDHASHSIZ
395#define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
396#endif
397#define	NMUIDHASH(nmp, uid) \
398	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
399#define	NFSNOHASH(fhsum) \
400	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
401
402/*
403 * Network address hash list element
404 */
405union nethostaddr {
406	u_int32_t had_inetaddr;
407	struct sockaddr *had_nam;
408};
409
410struct nfsuid {
411	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
412	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
413	int		nu_flag;	/* Flags */
414	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
415	struct ucred	nu_cr;		/* Cred uid mapped to */
416	int		nu_expire;	/* Expiry time (sec) */
417	struct timeval	nu_timestamp;	/* Kerb. timestamp */
418	u_int32_t	nu_nickname;	/* Nickname on server */
419	NFSKERBKEY_T	nu_key;		/* and session key */
420};
421
422#define	nu_inetaddr	nu_haddr.had_inetaddr
423#define	nu_nam		nu_haddr.had_nam
424/* Bits for nu_flag */
425#define	NU_INETADDR	0x1
426#define NU_NAM		0x2
427#define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
428
429struct nfsrv_rec {
430	STAILQ_ENTRY(nfsrv_rec) nr_link;
431	struct sockaddr	*nr_address;
432	struct mbuf	*nr_packet;
433};
434
435struct nfssvc_sock {
436	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
437	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
438	struct file	*ns_fp;
439	struct socket	*ns_so;
440	struct sockaddr	*ns_nam;
441	struct mbuf	*ns_raw;
442	struct mbuf	*ns_rawend;
443	STAILQ_HEAD(, nfsrv_rec) ns_rec;
444	struct mbuf	*ns_frag;
445	int		ns_flag;
446	int		ns_solock;
447	int		ns_cc;
448	int		ns_reclen;
449	int		ns_numuids;
450	u_int32_t	ns_sref;
451	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
452	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
453	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
454};
455
456/* Bits for "ns_flag" */
457#define	SLP_VALID	0x01
458#define	SLP_DOREC	0x02
459#define	SLP_NEEDQ	0x04
460#define	SLP_DISCONN	0x08
461#define	SLP_GETSTREAM	0x10
462#define	SLP_LASTFRAG	0x20
463#define SLP_ALLFLAGS	0xff
464
465extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
466extern int nfssvc_sockhead_flag;
467#define	SLP_INIT	0x01
468#define	SLP_WANTINIT	0x02
469
470/*
471 * One of these structures is allocated for each nfsd.
472 */
473struct nfsd {
474	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
475	int		nfsd_flag;	/* NFSD_ flags */
476	struct nfssvc_sock *nfsd_slp;	/* Current socket */
477	int		nfsd_authlen;	/* Authenticator len */
478	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
479	int		nfsd_verflen;	/* and the Verifier */
480	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
481	struct proc	*nfsd_procp;	/* Proc ptr */
482	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
483};
484
485/* Bits for "nfsd_flag" */
486#define	NFSD_WAITING	0x01
487#define	NFSD_REQINPROG	0x02
488#define	NFSD_NEEDAUTH	0x04
489#define	NFSD_AUTHFAIL	0x08
490
491/*
492 * This structure is used by the server for describing each request.
493 * Some fields are used only when write request gathering is performed.
494 */
495struct nfsrv_descript {
496	u_quad_t		nd_time;	/* Write deadline (usec) */
497	off_t			nd_off;		/* Start byte offset */
498	off_t			nd_eoff;	/* and end byte offset */
499	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
500	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
501	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
502	struct mbuf		*nd_mrep;	/* Request mbuf list */
503	struct mbuf		*nd_md;		/* Current dissect mbuf */
504	struct mbuf		*nd_mreq;	/* Reply mbuf list */
505	struct sockaddr		*nd_nam;	/* and socket addr */
506	struct sockaddr		*nd_nam2;	/* return socket addr */
507	caddr_t			nd_dpos;	/* Current dissect pos */
508	u_int32_t		nd_procnum;	/* RPC # */
509	int			nd_stable;	/* storage type */
510	int			nd_flag;	/* nd_flag */
511	int			nd_len;		/* Length of this write */
512	int			nd_repstat;	/* Reply status */
513	u_int32_t		nd_retxid;	/* Reply xid */
514	u_int32_t		nd_duration;	/* Lease duration */
515	struct timeval		nd_starttime;	/* Time RPC initiated */
516	fhandle_t		nd_fh;		/* File handle */
517	struct ucred		nd_cr;		/* Credentials */
518};
519
520/* Bits for "nd_flag" */
521#define	ND_READ		LEASE_READ
522#define ND_WRITE	LEASE_WRITE
523#define ND_CHECK	0x04
524#define ND_LEASE	(ND_READ | ND_WRITE | ND_CHECK)
525#define ND_NFSV3	0x08
526#define ND_NQNFS	0x10
527#define ND_KERBNICK	0x20
528#define ND_KERBFULL	0x40
529#define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
530
531extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
532extern int nfsd_head_flag;
533#define	NFSD_CHECKSLP	0x01
534
535/*
536 * These macros compare nfsrv_descript structures.
537 */
538#define NFSW_CONTIG(o, n) \
539		((o)->nd_eoff >= (n)->nd_off && \
540		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
541
542#define NFSW_SAMECRED(o, n) \
543	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
544 	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
545		sizeof (struct ucred)))
546
547/*
548 * Defines for WebNFS
549 */
550
551#define WEBNFS_ESC_CHAR		'%'
552#define WEBNFS_SPECCHAR_START	0x80
553
554#define WEBNFS_NATIVE_CHAR	0x80
555/*
556 * ..
557 * Possibly more here in the future.
558 */
559
560/*
561 * Macro for converting escape characters in WebNFS pathnames.
562 * Should really be in libkern.
563 */
564
565#define HEXTOC(c) \
566	((c) >= 'a' ? ((c) - ('a' - 10)) : \
567	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
568#define HEXSTRTOI(p) \
569	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
570
571#ifdef NFS_DEBUG
572
573extern int nfs_debug;
574#define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
575#define NFS_DEBUG_WG		2 /* server write gathering */
576#define NFS_DEBUG_RC		4 /* server request caching */
577
578#define NFS_DPF(cat, args)					\
579	do {							\
580		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
581	} while (0)
582
583#else
584
585#define NFS_DPF(cat, args)
586
587#endif
588
589u_quad_t nfs_curusec __P((void));
590int	nfs_init __P((struct vfsconf *vfsp));
591int	nfs_uninit __P((struct vfsconf *vfsp));
592int	nfs_reply __P((struct nfsreq *));
593int	nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
594int	nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *,
595		      struct nfsreq *));
596int	nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *,
597			 int, int, u_quad_t *, struct mbuf **, struct mbuf **,
598			 caddr_t *));
599int	nfs_sndlock __P((struct nfsreq *));
600void	nfs_sndunlock __P((struct nfsreq *));
601int	nfs_slplock __P((struct nfssvc_sock *, int));
602void	nfs_slpunlock __P((struct nfssvc_sock *));
603int	nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
604int	nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *,
605			   int));
606int	nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *));
607int	nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *,
608			  int *));
609int	nfs_commit __P((struct vnode *vp, u_quad_t offset, int cnt,
610			struct ucred *cred, struct proc *procp));
611int	nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *));
612int	nfs_asyncio __P((struct buf *, struct ucred *, struct proc *));
613int	nfs_doio __P((struct buf *, struct ucred *, struct proc *));
614int	nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *));
615int	nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *));
616int	nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *));
617int	nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
618void	nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *,
619			   struct nfs_fattr *));
620void	nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int,
621			 struct vattr *, struct mbuf **, char **));
622void	nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *,
623				struct mbuf **, char **));
624int	netaddr_match __P((int, union nethostaddr *, struct sockaddr *));
625int	nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *,
626			 struct ucred *, struct mbuf **, struct mbuf **,
627			 caddr_t *));
628int	nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *,
629			       struct vattr *));
630int	nfs_namei __P((struct nameidata *, fhandle_t *, int,
631		       struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
632		       caddr_t *, struct vnode **, struct proc *, int, int));
633void	nfsm_adj __P((struct mbuf *, int, int));
634int	nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *));
635void	nfsrv_initcache __P((void));
636int	nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *,
637			 char **, int *, char *, int *, NFSKERBKEY_T));
638int	nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **,
639			     int *, char *, int));
640int	nfs_savenickauth __P((struct nfsmount *, struct ucred *, int,
641			      NFSKERBKEY_T, struct mbuf **, char **,
642			      struct mbuf *));
643int	nfs_adv __P((struct mbuf **, caddr_t *, int, int));
644void	nfs_nhinit __P((void));
645void	nfs_timer __P((void*));
646u_long	nfs_hash __P((nfsfh_t *, int));
647int	nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *,
648			 struct nfsrv_descript **));
649int	nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *,
650			    struct mbuf **));
651void	nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *));
652void	nfsrv_cleancache __P((void));
653int	nfs_connect __P((struct nfsmount *, struct nfsreq *));
654void	nfs_disconnect __P((struct nfsmount *));
655void	nfs_safedisconnect __P((struct nfsmount *));
656int	nfs_getattrcache __P((struct vnode *, struct vattr *));
657int	nfsm_strtmbuf __P((struct mbuf **, char **, const char *, long));
658int	nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *));
659int	nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *));
660void	nfsrv_init __P((int));
661void	nfs_clearcommit __P((struct mount *));
662int	nfsrv_errmap __P((struct nfsrv_descript *, int));
663void	nfsrvw_sort __P((gid_t *, int));
664void	nfsrv_setcred __P((struct ucred *, struct ucred *));
665int	nfs_writebp __P((struct buf *, int, struct proc *));
666int	nfsrv_object_create __P((struct vnode *));
667void	nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
668int	nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
669			       struct proc *, struct mbuf **));
670int	nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
671			struct proc *p));
672
673int	nfsrv3_access __P((struct nfsrv_descript *nfsd,
674			   struct nfssvc_sock *slp,
675			   struct proc *procp, struct mbuf **mrq));
676int	nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
677			  struct proc *procp, struct mbuf **mrq));
678int	nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
679			  struct proc *procp, struct mbuf **mrq));
680int	nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *,
681			  struct nfssvc_sock *, struct sockaddr *, int *,
682			  int, int));
683int	nfsrv_setpublicfs __P((struct mount *, struct netexport *,
684			       struct export_args *));
685int	nfs_ispublicfh __P((fhandle_t *));
686int	nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
687			  struct proc *procp, struct mbuf **mrq));
688int	nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
689			   struct proc *procp, struct mbuf **mrq));
690int	nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
691			struct proc *procp, struct mbuf **mrq));
692int	nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
693			  struct proc *procp, struct mbuf **mrq));
694int	nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
695			 struct proc *procp, struct mbuf **mrq));
696int	nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
697			 struct proc *procp, struct mbuf **mrq));
698int	nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
699			struct proc *procp, struct mbuf **mrq));
700int	nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
701			struct proc *procp, struct mbuf **mrq));
702int	nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
703			    struct nfssvc_sock *slp, struct proc *procp,
704			    struct mbuf **mrq));
705int	nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
706			struct proc *procp, struct mbuf **mrq));
707int	nfsrv_readdir __P((struct nfsrv_descript *nfsd,
708			   struct nfssvc_sock *slp,
709			   struct proc *procp, struct mbuf **mrq));
710int	nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
711			       struct nfssvc_sock *slp, struct proc *procp,
712			       struct mbuf **mrq));
713int	nfsrv_readlink __P((struct nfsrv_descript *nfsd,
714			    struct nfssvc_sock *slp, struct proc *procp,
715			    struct mbuf **mrq));
716int	nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
717			  struct proc *procp, struct mbuf **mrq));
718int	nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
719			  struct proc *procp, struct mbuf **mrq));
720int	nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
721			 struct proc *procp, struct mbuf **mrq));
722int	nfsrv_setattr __P((struct nfsrv_descript *nfsd,
723			   struct nfssvc_sock *slp,
724			   struct proc *procp, struct mbuf **mrq));
725int	nfsrv_statfs __P((struct nfsrv_descript *nfsd,
726			  struct nfssvc_sock *slp,
727			  struct proc *procp, struct mbuf **mrq));
728int	nfsrv_symlink __P((struct nfsrv_descript *nfsd,
729			   struct nfssvc_sock *slp,
730			   struct proc *procp, struct mbuf **mrq));
731int	nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
732			 struct proc *procp, struct mbuf **mrq));
733void	nfsrv_rcv __P((struct socket *so, void *arg, int waitflag));
734void	nfsrv_slpderef __P((struct nfssvc_sock *slp));
735#endif	/* KERNEL */
736
737#endif
738