xref: /freebsd/sys/nfsclient/nfsargs.h (revision 7f3dea244c40159a41ab22da77a434d7c5b5e85a)
1 /*
2  * Copyright (c) 1989, 1993, 1995
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  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the University of
19  *	California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
37  * $Id: nfs.h,v 1.46 1999/05/02 23:56:23 alc Exp $
38  */
39 
40 #ifndef _NFS_NFS_H_
41 #define _NFS_NFS_H_
42 
43 #ifdef KERNEL
44 #include "opt_nfs.h"
45 #endif
46 
47 /*
48  * Tunable constants for nfs
49  */
50 
51 #define	NFS_MAXIOVEC	34
52 #define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
53 #define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
54 #define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
55 #define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
56 #define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
57 #define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
58 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
59 #define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
60 #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
61 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
62 #ifndef NFS_MINATTRTIMO
63 #define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
64 #endif
65 #ifndef NFS_MAXATTRTIMO
66 #define	NFS_MAXATTRTIMO 60
67 #endif
68 #ifndef NFS_MINDIRATTRTIMO
69 #define	NFS_MINDIRATTRTIMO 30		/* VDIR attrib cache timeout in sec */
70 #endif
71 #ifndef NFS_MAXDIRATTRTIMO
72 #define	NFS_MAXDIRATTRTIMO 60
73 #endif
74 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
75 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
76 #define NFS_READDIRSIZE	8192		/* Def. readdir size */
77 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
78 #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
79 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
80 #define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runnable */
81 #define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
82 #ifndef NFS_GATHERDELAY
83 #define NFS_GATHERDELAY		10	/* Default write gather delay (msec) */
84 #endif
85 #define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
86 #ifdef KERNEL
87 #define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
88 #endif
89 
90 /*
91  * Oddballs
92  */
93 #define	NMOD(a)		((a) % nfs_asyncdaemons)
94 #define NFS_CMPFH(n, f, s) \
95 	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
96 #define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
97 #define NFS_SRVMAXDATA(n) \
98 		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
99 		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
100 
101 /*
102  * XXX
103  * The B_INVAFTERWRITE flag should be set to whatever is required by the
104  * buffer cache code to say "Invalidate the block after it is written back".
105  */
106 #define	B_INVAFTERWRITE	B_NOCACHE
107 
108 /*
109  * The IO_METASYNC flag should be implemented for local file systems.
110  * (Until then, it is nothin at all.)
111  */
112 #ifndef IO_METASYNC
113 #define IO_METASYNC	0
114 #endif
115 
116 /*
117  * Expected allocation sizes for major data structures. If the actual size
118  * of the structure exceeds these sizes, then malloc() will be allocating
119  * almost twice the memory required. This is used in nfs_init() to warn
120  * the sysadmin that the size of a structure should be reduced.
121  * (These sizes are always a power of 2. If the kernel malloc() changes
122  *  to one that does not allocate space in powers of 2 size, then this all
123  *  becomes bunk!)
124  */
125 #define NFS_SVCALLOC	256
126 #define NFS_UIDALLOC	128
127 
128 /*
129  * Arguments to mount NFS
130  */
131 #define NFS_ARGSVERSION	3		/* change when nfs_args changes */
132 struct nfs_args {
133 	int		version;	/* args structure version number */
134 	struct sockaddr	*addr;		/* file server address */
135 	int		addrlen;	/* length of address */
136 	int		sotype;		/* Socket type */
137 	int		proto;		/* and Protocol */
138 	u_char		*fh;		/* File handle to be mounted */
139 	int		fhsize;		/* Size, in bytes, of fh */
140 	int		flags;		/* flags */
141 	int		wsize;		/* write size in bytes */
142 	int		rsize;		/* read size in bytes */
143 	int		readdirsize;	/* readdir size in bytes */
144 	int		timeo;		/* initial timeout in .1 secs */
145 	int		retrans;	/* times to retry send */
146 	int		maxgrouplist;	/* Max. size of group list */
147 	int		readahead;	/* # of blocks to readahead */
148 	int		leaseterm;	/* Term (sec) of lease */
149 	int		deadthresh;	/* Retrans threshold */
150 	char		*hostname;	/* server's name */
151 	int		acregmin;	/* cache attrs for reg files min time */
152 	int		acregmax;	/* cache attrs for reg files max time */
153 	int		acdirmin;	/* cache attrs for dirs min time */
154 	int		acdirmax;	/* cache attrs for dirs max time */
155 };
156 
157 /*
158  * NFS mount option flags
159  */
160 #define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
161 #define	NFSMNT_WSIZE		0x00000002  /* set write size */
162 #define	NFSMNT_RSIZE		0x00000004  /* set read size */
163 #define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
164 #define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
165 #define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
166 #define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
167 #define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
168 #define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
169 #define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
170 #define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
171 #define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
172 #define	NFSMNT_LEASETERM	0x00001000  /* set lease term (nqnfs) */
173 #define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
174 #define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
175 #define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
176 #define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
177 #define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
178 #define	NFSMNT_ACREGMIN		0x00040000
179 #define	NFSMNT_ACREGMAX		0x00080000
180 #define	NFSMNT_ACDIRMIN		0x00100000
181 #define	NFSMNT_ACDIRMAX		0x00200000
182 
183 #define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
184 #define NFSSTA_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
185 #define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
186 #define	NFSSTA_MNTD		0x00200000  /* Mnt server for mnt point */
187 #define	NFSSTA_DISMINPROG	0x00400000  /* Dismount in progress */
188 #define	NFSSTA_DISMNT		0x00800000  /* Dismounted */
189 #define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
190 #define	NFSSTA_WANTSND		0x02000000  /* Want above */
191 #define	NFSSTA_RCVLOCK		0x04000000  /* Rcv socket lock */
192 #define	NFSSTA_WANTRCV		0x08000000  /* Want above */
193 #define	NFSSTA_WAITAUTH		0x10000000  /* Wait for authentication */
194 #define	NFSSTA_HASAUTH		0x20000000  /* Has authenticator */
195 #define	NFSSTA_WANTAUTH		0x40000000  /* Wants an authenticator */
196 #define	NFSSTA_AUTHERR		0x80000000  /* Authentication error */
197 
198 /*
199  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
200  * should ever try and use it.
201  */
202 struct nfsd_args {
203 	int	sock;		/* Socket to serve */
204 	caddr_t	name;		/* Client addr for connection based sockets */
205 	int	namelen;	/* Length of name */
206 };
207 
208 struct nfsd_srvargs {
209 	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
210 	uid_t		nsd_uid;	/* Effective uid mapped to cred */
211 	u_int32_t	nsd_haddr;	/* Ip address of client */
212 	struct ucred	nsd_cr;		/* Cred. uid maps to */
213 	int		nsd_authlen;	/* Length of auth string (ret) */
214 	u_char		*nsd_authstr;	/* Auth string (ret) */
215 	int		nsd_verflen;	/* and the verfier */
216 	u_char		*nsd_verfstr;
217 	struct timeval	nsd_timestamp;	/* timestamp from verifier */
218 	u_int32_t	nsd_ttl;	/* credential ttl (sec) */
219 	NFSKERBKEY_T	nsd_key;	/* Session key */
220 };
221 
222 struct nfsd_cargs {
223 	char		*ncd_dirp;	/* Mount dir path */
224 	uid_t		ncd_authuid;	/* Effective uid */
225 	int		ncd_authtype;	/* Type of authenticator */
226 	int		ncd_authlen;	/* Length of authenticator string */
227 	u_char		*ncd_authstr;	/* Authenticator string */
228 	int		ncd_verflen;	/* and the verifier */
229 	u_char		*ncd_verfstr;
230 	NFSKERBKEY_T	ncd_key;	/* Session key */
231 };
232 
233 /*
234  * XXX to allow amd to include nfs.h without nfsproto.h
235  */
236 #ifdef NFS_NPROCS
237 /*
238  * Stats structure
239  */
240 struct nfsstats {
241 	int	attrcache_hits;
242 	int	attrcache_misses;
243 	int	lookupcache_hits;
244 	int	lookupcache_misses;
245 	int	direofcache_hits;
246 	int	direofcache_misses;
247 	int	biocache_reads;
248 	int	read_bios;
249 	int	read_physios;
250 	int	biocache_writes;
251 	int	write_bios;
252 	int	write_physios;
253 	int	biocache_readlinks;
254 	int	readlink_bios;
255 	int	biocache_readdirs;
256 	int	readdir_bios;
257 	int	rpccnt[NFS_NPROCS];
258 	int	rpcretries;
259 	int	srvrpccnt[NFS_NPROCS];
260 	int	srvrpc_errs;
261 	int	srv_errs;
262 	int	rpcrequests;
263 	int	rpctimeouts;
264 	int	rpcunexpected;
265 	int	rpcinvalid;
266 	int	srvcache_inproghits;
267 	int	srvcache_idemdonehits;
268 	int	srvcache_nonidemdonehits;
269 	int	srvcache_misses;
270 	int	srvnqnfs_leases;
271 	int	srvnqnfs_maxleases;
272 	int	srvnqnfs_getleases;
273 	int	srvvop_writes;
274 };
275 #endif
276 
277 /*
278  * Flags for nfssvc() system call.
279  */
280 #define	NFSSVC_BIOD	0x002
281 #define	NFSSVC_NFSD	0x004
282 #define	NFSSVC_ADDSOCK	0x008
283 #define	NFSSVC_AUTHIN	0x010
284 #define	NFSSVC_GOTAUTH	0x040
285 #define	NFSSVC_AUTHINFAIL 0x080
286 #define	NFSSVC_MNTD	0x100
287 
288 /*
289  * fs.nfs sysctl(3) identifiers
290  */
291 #define NFS_NFSSTATS	1		/* struct: struct nfsstats */
292 #define NFS_NFSPRIVPORT	2		/* int: prohibit nfs to resvports */
293 
294 #define FS_NFS_NAMES { \
295 		       { 0, 0 }, \
296 		       { "nfsstats", CTLTYPE_STRUCT }, \
297 		       { "nfsprivport", CTLTYPE_INT }, \
298 }
299 
300 #ifdef KERNEL
301 
302 #ifdef MALLOC_DECLARE
303 MALLOC_DECLARE(M_NFSREQ);
304 MALLOC_DECLARE(M_NFSDIROFF);
305 MALLOC_DECLARE(M_NFSRVDESC);
306 MALLOC_DECLARE(M_NFSUID);
307 MALLOC_DECLARE(M_NQLEASE);
308 MALLOC_DECLARE(M_NFSD);
309 MALLOC_DECLARE(M_NFSBIGFH);
310 MALLOC_DECLARE(M_NFSHASH);
311 #endif
312 
313 #ifdef ZONE_INTERRUPT
314 extern vm_zone_t nfsmount_zone;
315 #endif
316 
317 extern struct callout_handle nfs_timer_handle;
318 
319 struct 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	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
330 			 sigmask(SIGHUP)|sigmask(SIGQUIT))
331 
332 /*
333  * Socket errors ignored for connectionless sockets??
334  * For now, ignore them all
335  */
336 #define	NFSIGNORE_SOERROR(s, e) \
337 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
338 		((s) & PR_CONNREQUIRED) == 0)
339 
340 /*
341  * Nfs outstanding request list element
342  */
343 struct nfsreq {
344 	TAILQ_ENTRY(nfsreq) r_chain;
345 	struct mbuf	*r_mreq;
346 	struct mbuf	*r_mrep;
347 	struct mbuf	*r_md;
348 	caddr_t		r_dpos;
349 	struct nfsmount *r_nmp;
350 	struct vnode	*r_vp;
351 	u_int32_t	r_xid;
352 	int		r_flags;	/* flags on request, see below */
353 	int		r_retry;	/* max retransmission count */
354 	int		r_rexmit;	/* current retrans count */
355 	int		r_timer;	/* tick counter on reply */
356 	u_int32_t	r_procnum;	/* NFS procedure number */
357 	int		r_rtt;		/* RTT for rpc */
358 	struct proc	*r_procp;	/* Proc that did I/O system call */
359 };
360 
361 /*
362  * Queue head for nfsreq's
363  */
364 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
365 
366 /* Flag values for r_flags */
367 #define R_TIMING	0x01		/* timing request (in mntp) */
368 #define R_SENT		0x02		/* request has been sent */
369 #define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
370 #define	R_INTR		0x08		/* intr mnt, signal pending */
371 #define	R_SOCKERR	0x10		/* Fatal error on socket */
372 #define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
373 #define	R_MUSTRESEND	0x40		/* Must resend request */
374 #define	R_GETONEREP	0x80		/* Probe for one reply only */
375 
376 /*
377  * A list of nfssvc_sock structures is maintained with all the sockets
378  * that require service by the nfsd.
379  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
380  * and uid hash lists.
381  */
382 #ifndef NFS_UIDHASHSIZ
383 #define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
384 #endif
385 #define	NUIDHASH(sock, uid) \
386 	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
387 #ifndef NFS_WDELAYHASHSIZ
388 #define	NFS_WDELAYHASHSIZ 16	/* and with this */
389 #endif
390 #define	NWDELAYHASH(sock, f) \
391 	(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
392 #ifndef NFS_MUIDHASHSIZ
393 #define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
394 #endif
395 #define	NMUIDHASH(nmp, uid) \
396 	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
397 #define	NFSNOHASH(fhsum) \
398 	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
399 
400 /*
401  * Network address hash list element
402  */
403 union nethostaddr {
404 	u_int32_t had_inetaddr;
405 	struct sockaddr *had_nam;
406 };
407 
408 struct nfsuid {
409 	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
410 	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
411 	int		nu_flag;	/* Flags */
412 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
413 	struct ucred	nu_cr;		/* Cred uid mapped to */
414 	int		nu_expire;	/* Expiry time (sec) */
415 	struct timeval	nu_timestamp;	/* Kerb. timestamp */
416 	u_int32_t	nu_nickname;	/* Nickname on server */
417 	NFSKERBKEY_T	nu_key;		/* and session key */
418 };
419 
420 #define	nu_inetaddr	nu_haddr.had_inetaddr
421 #define	nu_nam		nu_haddr.had_nam
422 /* Bits for nu_flag */
423 #define	NU_INETADDR	0x1
424 #define NU_NAM		0x2
425 #define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
426 
427 struct nfsrv_rec {
428 	STAILQ_ENTRY(nfsrv_rec) nr_link;
429 	struct sockaddr	*nr_address;
430 	struct mbuf	*nr_packet;
431 };
432 
433 struct nfssvc_sock {
434 	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
435 	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
436 	struct file	*ns_fp;
437 	struct socket	*ns_so;
438 	struct sockaddr	*ns_nam;
439 	struct mbuf	*ns_raw;
440 	struct mbuf	*ns_rawend;
441 	STAILQ_HEAD(, nfsrv_rec) ns_rec;
442 	struct mbuf	*ns_frag;
443 	int		ns_flag;
444 	int		ns_solock;
445 	int		ns_cc;
446 	int		ns_reclen;
447 	int		ns_numuids;
448 	u_int32_t	ns_sref;
449 	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
450 	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
451 	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
452 };
453 
454 /* Bits for "ns_flag" */
455 #define	SLP_VALID	0x01
456 #define	SLP_DOREC	0x02
457 #define	SLP_NEEDQ	0x04
458 #define	SLP_DISCONN	0x08
459 #define	SLP_GETSTREAM	0x10
460 #define	SLP_LASTFRAG	0x20
461 #define SLP_ALLFLAGS	0xff
462 
463 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
464 extern int nfssvc_sockhead_flag;
465 #define	SLP_INIT	0x01
466 #define	SLP_WANTINIT	0x02
467 
468 /*
469  * One of these structures is allocated for each nfsd.
470  */
471 struct nfsd {
472 	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
473 	int		nfsd_flag;	/* NFSD_ flags */
474 	struct nfssvc_sock *nfsd_slp;	/* Current socket */
475 	int		nfsd_authlen;	/* Authenticator len */
476 	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
477 	int		nfsd_verflen;	/* and the Verifier */
478 	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
479 	struct proc	*nfsd_procp;	/* Proc ptr */
480 	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
481 };
482 
483 /* Bits for "nfsd_flag" */
484 #define	NFSD_WAITING	0x01
485 #define	NFSD_REQINPROG	0x02
486 #define	NFSD_NEEDAUTH	0x04
487 #define	NFSD_AUTHFAIL	0x08
488 
489 /*
490  * This structure is used by the server for describing each request.
491  * Some fields are used only when write request gathering is performed.
492  */
493 struct nfsrv_descript {
494 	u_quad_t		nd_time;	/* Write deadline (usec) */
495 	off_t			nd_off;		/* Start byte offset */
496 	off_t			nd_eoff;	/* and end byte offset */
497 	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
498 	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
499 	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
500 	struct mbuf		*nd_mrep;	/* Request mbuf list */
501 	struct mbuf		*nd_md;		/* Current dissect mbuf */
502 	struct mbuf		*nd_mreq;	/* Reply mbuf list */
503 	struct sockaddr		*nd_nam;	/* and socket addr */
504 	struct sockaddr		*nd_nam2;	/* return socket addr */
505 	caddr_t			nd_dpos;	/* Current dissect pos */
506 	u_int32_t		nd_procnum;	/* RPC # */
507 	int			nd_stable;	/* storage type */
508 	int			nd_flag;	/* nd_flag */
509 	int			nd_len;		/* Length of this write */
510 	int			nd_repstat;	/* Reply status */
511 	u_int32_t		nd_retxid;	/* Reply xid */
512 	u_int32_t		nd_duration;	/* Lease duration */
513 	struct timeval		nd_starttime;	/* Time RPC initiated */
514 	fhandle_t		nd_fh;		/* File handle */
515 	struct ucred		nd_cr;		/* Credentials */
516 };
517 
518 /* Bits for "nd_flag" */
519 #define	ND_READ		LEASE_READ
520 #define ND_WRITE	LEASE_WRITE
521 #define ND_CHECK	0x04
522 #define ND_LEASE	(ND_READ | ND_WRITE | ND_CHECK)
523 #define ND_NFSV3	0x08
524 #define ND_NQNFS	0x10
525 #define ND_KERBNICK	0x20
526 #define ND_KERBFULL	0x40
527 #define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
528 
529 extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
530 extern int nfsd_head_flag;
531 #define	NFSD_CHECKSLP	0x01
532 
533 /*
534  * These macros compare nfsrv_descript structures.
535  */
536 #define NFSW_CONTIG(o, n) \
537 		((o)->nd_eoff >= (n)->nd_off && \
538 		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
539 
540 #define NFSW_SAMECRED(o, n) \
541 	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
542  	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
543 		sizeof (struct ucred)))
544 
545 /*
546  * Defines for WebNFS
547  */
548 
549 #define WEBNFS_ESC_CHAR		'%'
550 #define WEBNFS_SPECCHAR_START	0x80
551 
552 #define WEBNFS_NATIVE_CHAR	0x80
553 /*
554  * ..
555  * Possibly more here in the future.
556  */
557 
558 /*
559  * Macro for converting escape characters in WebNFS pathnames.
560  * Should really be in libkern.
561  */
562 
563 #define HEXTOC(c) \
564 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
565 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
566 #define HEXSTRTOI(p) \
567 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
568 
569 #ifdef NFS_DEBUG
570 
571 extern int nfs_debug;
572 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
573 #define NFS_DEBUG_WG		2 /* server write gathering */
574 #define NFS_DEBUG_RC		4 /* server request caching */
575 
576 #define NFS_DPF(cat, args)					\
577 	do {							\
578 		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
579 	} while (0)
580 
581 #else
582 
583 #define NFS_DPF(cat, args)
584 
585 #endif
586 
587 u_quad_t nfs_curusec __P((void));
588 int	nfs_init __P((struct vfsconf *vfsp));
589 int	nfs_uninit __P((struct vfsconf *vfsp));
590 int	nfs_reply __P((struct nfsreq *));
591 int	nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
592 int	nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *,
593 		      struct nfsreq *));
594 int	nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *,
595 			 int, int, u_quad_t *, struct mbuf **, struct mbuf **,
596 			 caddr_t *));
597 int	nfs_sndlock __P((struct nfsreq *));
598 void	nfs_sndunlock __P((struct nfsreq *));
599 int	nfs_slplock __P((struct nfssvc_sock *, int));
600 void	nfs_slpunlock __P((struct nfssvc_sock *));
601 int	nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
602 int	nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *,
603 			   int));
604 int	nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *));
605 int	nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *,
606 			  int *));
607 int	nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *));
608 int	nfs_asyncio __P((struct buf *, struct ucred *, struct proc *));
609 int	nfs_doio __P((struct buf *, struct ucred *, struct proc *));
610 int	nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *));
611 int	nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *));
612 int	nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *));
613 int	nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
614 void	nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *,
615 			   struct nfs_fattr *));
616 void	nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int,
617 			 struct vattr *, struct mbuf **, char **));
618 void	nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *,
619 				struct mbuf **, char **));
620 int	netaddr_match __P((int, union nethostaddr *, struct sockaddr *));
621 int	nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *,
622 			 struct ucred *, struct mbuf **, struct mbuf **,
623 			 caddr_t *));
624 int	nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *,
625 			       struct vattr *));
626 int	nfs_namei __P((struct nameidata *, fhandle_t *, int,
627 		       struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
628 		       caddr_t *, struct vnode **, struct proc *, int, int));
629 void	nfsm_adj __P((struct mbuf *, int, int));
630 int	nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *));
631 void	nfsrv_initcache __P((void));
632 int	nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *,
633 			 char **, int *, char *, int *, NFSKERBKEY_T));
634 int	nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **,
635 			     int *, char *, int));
636 int	nfs_savenickauth __P((struct nfsmount *, struct ucred *, int,
637 			      NFSKERBKEY_T, struct mbuf **, char **,
638 			      struct mbuf *));
639 int	nfs_adv __P((struct mbuf **, caddr_t *, int, int));
640 void	nfs_nhinit __P((void));
641 void	nfs_timer __P((void*));
642 u_long	nfs_hash __P((nfsfh_t *, int));
643 int	nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *,
644 			 struct nfsrv_descript **));
645 int	nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *,
646 			    struct mbuf **));
647 void	nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *));
648 void	nfsrv_cleancache __P((void));
649 int	nfs_connect __P((struct nfsmount *, struct nfsreq *));
650 void	nfs_disconnect __P((struct nfsmount *));
651 void	nfs_safedisconnect __P((struct nfsmount *));
652 int	nfs_getattrcache __P((struct vnode *, struct vattr *));
653 int	nfsm_strtmbuf __P((struct mbuf **, char **, const char *, long));
654 int	nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *));
655 int	nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *));
656 void	nfsrv_init __P((int));
657 void	nfs_clearcommit __P((struct mount *));
658 int	nfsrv_errmap __P((struct nfsrv_descript *, int));
659 void	nfsrvw_sort __P((gid_t *, int));
660 void	nfsrv_setcred __P((struct ucred *, struct ucred *));
661 int	nfs_writebp __P((struct buf *, int, struct proc *));
662 int	nfsrv_object_create __P((struct vnode *));
663 void	nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
664 int	nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
665 			       struct proc *, struct mbuf **));
666 int	nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
667 			struct proc *p));
668 
669 int	nfsrv3_access __P((struct nfsrv_descript *nfsd,
670 			   struct nfssvc_sock *slp,
671 			   struct proc *procp, struct mbuf **mrq));
672 int	nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
673 			  struct proc *procp, struct mbuf **mrq));
674 int	nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
675 			  struct proc *procp, struct mbuf **mrq));
676 int	nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *,
677 			  struct nfssvc_sock *, struct sockaddr *, int *,
678 			  int, int));
679 int	nfsrv_setpublicfs __P((struct mount *, struct netexport *,
680 			       struct export_args *));
681 int	nfs_ispublicfh __P((fhandle_t *));
682 int	nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
683 			  struct proc *procp, struct mbuf **mrq));
684 int	nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
685 			   struct proc *procp, struct mbuf **mrq));
686 int	nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
687 			struct proc *procp, struct mbuf **mrq));
688 int	nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
689 			  struct proc *procp, struct mbuf **mrq));
690 int	nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
691 			 struct proc *procp, struct mbuf **mrq));
692 int	nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
693 			 struct proc *procp, struct mbuf **mrq));
694 int	nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
695 			struct proc *procp, struct mbuf **mrq));
696 int	nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
697 			struct proc *procp, struct mbuf **mrq));
698 int	nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
699 			    struct nfssvc_sock *slp, struct proc *procp,
700 			    struct mbuf **mrq));
701 int	nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
702 			struct proc *procp, struct mbuf **mrq));
703 int	nfsrv_readdir __P((struct nfsrv_descript *nfsd,
704 			   struct nfssvc_sock *slp,
705 			   struct proc *procp, struct mbuf **mrq));
706 int	nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
707 			       struct nfssvc_sock *slp, struct proc *procp,
708 			       struct mbuf **mrq));
709 int	nfsrv_readlink __P((struct nfsrv_descript *nfsd,
710 			    struct nfssvc_sock *slp, struct proc *procp,
711 			    struct mbuf **mrq));
712 int	nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
713 			  struct proc *procp, struct mbuf **mrq));
714 int	nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
715 			  struct proc *procp, struct mbuf **mrq));
716 int	nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
717 			 struct proc *procp, struct mbuf **mrq));
718 int	nfsrv_setattr __P((struct nfsrv_descript *nfsd,
719 			   struct nfssvc_sock *slp,
720 			   struct proc *procp, struct mbuf **mrq));
721 int	nfsrv_statfs __P((struct nfsrv_descript *nfsd,
722 			  struct nfssvc_sock *slp,
723 			  struct proc *procp, struct mbuf **mrq));
724 int	nfsrv_symlink __P((struct nfsrv_descript *nfsd,
725 			   struct nfssvc_sock *slp,
726 			   struct proc *procp, struct mbuf **mrq));
727 int	nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
728 			 struct proc *procp, struct mbuf **mrq));
729 void	nfsrv_rcv __P((struct socket *so, void *arg, int waitflag));
730 void	nfsrv_slpderef __P((struct nfssvc_sock *slp));
731 #endif	/* KERNEL */
732 
733 #endif
734