nfs_nfsiod.c revision 75631
1/*
2 * Copyright (c) 1989, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 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_syscalls.c	8.5 (Berkeley) 3/30/95
37 * $FreeBSD: head/sys/nfsclient/nfs_nfsiod.c 75631 2001-04-17 20:45:23Z alfred $
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/sysproto.h>
43#include <sys/kernel.h>
44#include <sys/sysctl.h>
45#include <sys/file.h>
46#include <sys/filedesc.h>
47#include <sys/vnode.h>
48#include <sys/malloc.h>
49#include <sys/mount.h>
50#include <sys/proc.h>
51#include <sys/bio.h>
52#include <sys/buf.h>
53#include <sys/mbuf.h>
54#include <sys/socket.h>
55#include <sys/socketvar.h>
56#include <sys/domain.h>
57#include <sys/protosw.h>
58#include <sys/namei.h>
59#include <sys/fcntl.h>
60#include <sys/lockf.h>
61
62#include <netinet/in.h>
63#include <netinet/tcp.h>
64#include <nfs/xdr_subs.h>
65#include <nfs/rpcv2.h>
66#include <nfs/nfsproto.h>
67#include <nfs/nfs.h>
68#include <nfs/nfsm_subs.h>
69#include <nfs/nfsrvcache.h>
70#include <nfs/nfsmount.h>
71#include <nfs/nfsnode.h>
72#include <nfs/nqnfs.h>
73#include <nfs/nfsrtt.h>
74#include <nfs/nfs_lock.h>
75
76static MALLOC_DEFINE(M_NFSSVC, "NFS srvsock", "Nfs server structure");
77
78/* Global defs. */
79extern int32_t (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *nd,
80					    struct nfssvc_sock *slp,
81					    struct proc *procp,
82					    struct mbuf **mreqp));
83extern int nfs_numasync;
84extern time_t nqnfsstarttime;
85extern int nqsrv_writeslack;
86extern int nfsrtton;
87extern struct nfsstats nfsstats;
88extern int nfsrvw_procrastinate;
89extern int nfsrvw_procrastinate_v3;
90static int nuidhash_max = NFS_MAXUIDHASH;
91
92#ifndef NFS_NOSERVER
93static void	nfsrv_zapsock __P((struct nfssvc_sock *slp));
94#endif
95static int	nfssvc_iod __P((struct proc *));
96
97#define	TRUE	1
98#define	FALSE	0
99
100static int nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
101
102SYSCTL_DECL(_vfs_nfs);
103
104#ifndef NFS_NOSERVER
105int nfsd_waiting = 0;
106static struct nfsdrt nfsdrt;
107static int nfs_numnfsd = 0;
108static int notstarted = 1;
109static int modify_flag = 0;
110static void	nfsd_rt __P((int sotype, struct nfsrv_descript *nd,
111			     int cacherep));
112static int	nfssvc_addsock __P((struct file *, struct sockaddr *,
113				    struct proc *));
114static int	nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *));
115
116static int nfs_privport = 0;
117SYSCTL_INT(_vfs_nfs, NFS_NFSPRIVPORT, nfs_privport, CTLFLAG_RW, &nfs_privport, 0, "");
118SYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay, CTLFLAG_RW, &nfsrvw_procrastinate, 0, "");
119SYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay_v3, CTLFLAG_RW, &nfsrvw_procrastinate_v3, 0, "");
120
121/*
122 * NFS server system calls
123 */
124
125#endif /* NFS_NOSERVER */
126/*
127 * Nfs server psuedo system call for the nfsd's
128 * Based on the flag value it either:
129 * - adds a socket to the selection list
130 * - remains in the kernel as an nfsd
131 * - remains in the kernel as an nfsiod
132 */
133#ifndef _SYS_SYSPROTO_H_
134struct nfssvc_args {
135	int flag;
136	caddr_t argp;
137};
138#endif
139int
140nfssvc(p, uap)
141	struct proc *p;
142	register struct nfssvc_args *uap;
143{
144#ifndef NFS_NOSERVER
145	struct nameidata nd;
146	struct file *fp;
147	struct sockaddr *nam;
148	struct nfsd_args nfsdarg;
149	struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs;
150	struct nfsd_cargs ncd;
151	struct nfsd *nfsd;
152	struct nfssvc_sock *slp;
153	struct nfsuid *nuidp;
154	struct nfsmount *nmp;
155#endif /* NFS_NOSERVER */
156	int error;
157
158	if ((uap->flag & NFSSVC_LOCKDANS) != 0) {
159		struct lockd_ans la;
160
161		error = copyin(uap->argp, &la, sizeof(la));
162		return (error != 0 ? error : nfslockdans(p, &la));
163	}
164	/*
165	 * Must be super user
166	 */
167	error = suser(p);
168	if(error)
169		return (error);
170	while (nfssvc_sockhead_flag & SLP_INIT) {
171		 nfssvc_sockhead_flag |= SLP_WANTINIT;
172		(void) tsleep((caddr_t)&nfssvc_sockhead, PSOCK, "nfsd init", 0);
173	}
174	if (uap->flag & NFSSVC_BIOD)
175		error = nfssvc_iod(p);
176#ifdef NFS_NOSERVER
177	else
178		error = ENXIO;
179#else /* !NFS_NOSERVER */
180	else if (uap->flag & NFSSVC_MNTD) {
181		error = copyin(uap->argp, (caddr_t)&ncd, sizeof (ncd));
182		if (error)
183			return (error);
184		NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
185			ncd.ncd_dirp, p);
186		error = namei(&nd);
187		if (error)
188			return (error);
189		NDFREE(&nd, NDF_ONLY_PNBUF);
190		if ((nd.ni_vp->v_flag & VROOT) == 0)
191			error = EINVAL;
192		nmp = VFSTONFS(nd.ni_vp->v_mount);
193		vput(nd.ni_vp);
194		if (error)
195			return (error);
196		if ((nmp->nm_state & NFSSTA_MNTD) &&
197			(uap->flag & NFSSVC_GOTAUTH) == 0)
198			return (0);
199		nmp->nm_state |= NFSSTA_MNTD;
200		error = nqnfs_clientd(nmp, p->p_ucred, &ncd, uap->flag,
201			uap->argp, p);
202	} else if (uap->flag & NFSSVC_ADDSOCK) {
203		error = copyin(uap->argp, (caddr_t)&nfsdarg, sizeof(nfsdarg));
204		if (error)
205			return (error);
206		error = holdsock(p->p_fd, nfsdarg.sock, &fp);
207		if (error)
208			return (error);
209		/*
210		 * Get the client address for connected sockets.
211		 */
212		if (nfsdarg.name == NULL || nfsdarg.namelen == 0)
213			nam = (struct sockaddr *)0;
214		else {
215			error = getsockaddr(&nam, nfsdarg.name,
216					    nfsdarg.namelen);
217			if (error) {
218				fdrop(fp, p);
219				return (error);
220			}
221		}
222		error = nfssvc_addsock(fp, nam, p);
223		fdrop(fp, p);
224	} else {
225		error = copyin(uap->argp, (caddr_t)nsd, sizeof (*nsd));
226		if (error)
227			return (error);
228		if ((uap->flag & NFSSVC_AUTHIN) &&
229		    ((nfsd = nsd->nsd_nfsd)) != NULL &&
230		    (nfsd->nfsd_slp->ns_flag & SLP_VALID)) {
231			slp = nfsd->nfsd_slp;
232
233			/*
234			 * First check to see if another nfsd has already
235			 * added this credential.
236			 */
237			for (nuidp = NUIDHASH(slp,nsd->nsd_cr.cr_uid)->lh_first;
238			    nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
239				if (nuidp->nu_cr.cr_uid == nsd->nsd_cr.cr_uid &&
240				    (!nfsd->nfsd_nd->nd_nam2 ||
241				     netaddr_match(NU_NETFAM(nuidp),
242				     &nuidp->nu_haddr, nfsd->nfsd_nd->nd_nam2)))
243					break;
244			}
245			if (nuidp) {
246			    nfsrv_setcred(&nuidp->nu_cr,&nfsd->nfsd_nd->nd_cr);
247			    nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
248			} else {
249			    /*
250			     * Nope, so we will.
251			     */
252			    if (slp->ns_numuids < nuidhash_max) {
253				slp->ns_numuids++;
254				nuidp = (struct nfsuid *)
255				   malloc(sizeof (struct nfsuid), M_NFSUID,
256					M_WAITOK);
257			    } else
258				nuidp = (struct nfsuid *)0;
259			    if ((slp->ns_flag & SLP_VALID) == 0) {
260				if (nuidp)
261				    free((caddr_t)nuidp, M_NFSUID);
262			    } else {
263				if (nuidp == (struct nfsuid *)0) {
264				    nuidp = slp->ns_uidlruhead.tqh_first;
265				    LIST_REMOVE(nuidp, nu_hash);
266				    TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
267					nu_lru);
268				    if (nuidp->nu_flag & NU_NAM)
269					FREE(nuidp->nu_nam, M_SONAME);
270			        }
271				nuidp->nu_flag = 0;
272				bzero(&nuidp->nu_cr, sizeof(nuidp->nu_cr));
273				nuidp->nu_cr.cr_uid = nsd->nsd_cr.cr_uid;
274				nuidp->nu_cr.cr_ngroups =
275				  nsd->nsd_cr.cr_ngroups;
276				bcopy(nsd->nsd_cr.cr_groups,
277				  nuidp->nu_cr.cr_groups,
278				  sizeof(nuidp->nu_cr.cr_groups));
279				if (nuidp->nu_cr.cr_ngroups > NGROUPS)
280				    nuidp->nu_cr.cr_ngroups = NGROUPS;
281				nuidp->nu_cr.cr_ref = 1;
282				nuidp->nu_timestamp = nsd->nsd_timestamp;
283				nuidp->nu_expire = time_second + nsd->nsd_ttl;
284				/*
285				 * and save the session key in nu_key.
286				 */
287				bcopy(nsd->nsd_key, nuidp->nu_key,
288				    sizeof (nsd->nsd_key));
289				if (nfsd->nfsd_nd->nd_nam2) {
290				    struct sockaddr_in *saddr;
291
292				    saddr = (struct sockaddr_in *)
293					    nfsd->nfsd_nd->nd_nam2;
294				    switch (saddr->sin_family) {
295				    case AF_INET:
296					nuidp->nu_flag |= NU_INETADDR;
297					nuidp->nu_inetaddr =
298					     saddr->sin_addr.s_addr;
299					break;
300				    case AF_ISO:
301				    default:
302					nuidp->nu_flag |= NU_NAM;
303					nuidp->nu_nam =
304						dup_sockaddr(nfsd->nfsd_nd->
305							     nd_nam2, 1);
306					break;
307				    };
308				}
309				TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
310					nu_lru);
311				LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
312					nuidp, nu_hash);
313				nfsrv_setcred(&nuidp->nu_cr,
314				    &nfsd->nfsd_nd->nd_cr);
315				nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
316			    }
317			}
318		}
319		if ((uap->flag & NFSSVC_AUTHINFAIL) && (nfsd = nsd->nsd_nfsd))
320			nfsd->nfsd_flag |= NFSD_AUTHFAIL;
321		error = nfssvc_nfsd(nsd, uap->argp, p);
322	}
323#endif /* NFS_NOSERVER */
324	if (error == EINTR || error == ERESTART)
325		error = 0;
326	return (error);
327}
328
329#ifndef NFS_NOSERVER
330/*
331 * Adds a socket to the list for servicing by nfsds.
332 */
333static int
334nfssvc_addsock(fp, mynam, p)
335	struct file *fp;
336	struct sockaddr *mynam;
337	struct proc *p;
338{
339	register int siz;
340	register struct nfssvc_sock *slp;
341	register struct socket *so;
342	int error, s;
343
344	so = (struct socket *)fp->f_data;
345#if 0
346	tslp = (struct nfssvc_sock *)0;
347	/*
348	 * Add it to the list, as required.
349	 */
350	if (so->so_proto->pr_protocol == IPPROTO_UDP) {
351		tslp = nfs_udpsock;
352		if (tslp->ns_flag & SLP_VALID) {
353			if (mynam != NULL)
354				FREE(mynam, M_SONAME);
355			return (EPERM);
356		}
357	}
358#endif
359	if (so->so_type == SOCK_STREAM)
360		siz = NFS_MAXPACKET + sizeof (u_long);
361	else
362		siz = NFS_MAXPACKET;
363	error = soreserve(so, siz, siz);
364	if (error) {
365		if (mynam != NULL)
366			FREE(mynam, M_SONAME);
367		return (error);
368	}
369
370	/*
371	 * Set protocol specific options { for now TCP only } and
372	 * reserve some space. For datagram sockets, this can get called
373	 * repeatedly for the same socket, but that isn't harmful.
374	 */
375	if (so->so_type == SOCK_STREAM) {
376		struct sockopt sopt;
377		int val;
378
379		bzero(&sopt, sizeof sopt);
380		sopt.sopt_level = SOL_SOCKET;
381		sopt.sopt_name = SO_KEEPALIVE;
382		sopt.sopt_val = &val;
383		sopt.sopt_valsize = sizeof val;
384		val = 1;
385		sosetopt(so, &sopt);
386	}
387	if (so->so_proto->pr_domain->dom_family == AF_INET &&
388	    so->so_proto->pr_protocol == IPPROTO_TCP) {
389		struct sockopt sopt;
390		int val;
391
392		bzero(&sopt, sizeof sopt);
393		sopt.sopt_level = IPPROTO_TCP;
394		sopt.sopt_name = TCP_NODELAY;
395		sopt.sopt_val = &val;
396		sopt.sopt_valsize = sizeof val;
397		val = 1;
398		sosetopt(so, &sopt);
399	}
400	so->so_rcv.sb_flags &= ~SB_NOINTR;
401	so->so_rcv.sb_timeo = 0;
402	so->so_snd.sb_flags &= ~SB_NOINTR;
403	so->so_snd.sb_timeo = 0;
404
405	slp = (struct nfssvc_sock *)
406		malloc(sizeof (struct nfssvc_sock), M_NFSSVC,
407		M_WAITOK | M_ZERO);
408	STAILQ_INIT(&slp->ns_rec);
409	TAILQ_INIT(&slp->ns_uidlruhead);
410	TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
411
412	slp->ns_so = so;
413	slp->ns_nam = mynam;
414	fp->f_count++;
415	slp->ns_fp = fp;
416	s = splnet();
417	so->so_upcallarg = (caddr_t)slp;
418	so->so_upcall = nfsrv_rcv;
419	so->so_rcv.sb_flags |= SB_UPCALL;
420	slp->ns_flag = (SLP_VALID | SLP_NEEDQ);
421	nfsrv_wakenfsd(slp);
422	splx(s);
423	return (0);
424}
425
426/*
427 * Called by nfssvc() for nfsds. Just loops around servicing rpc requests
428 * until it is killed by a signal.
429 */
430static int
431nfssvc_nfsd(nsd, argp, p)
432	struct nfsd_srvargs *nsd;
433	caddr_t argp;
434	struct proc *p;
435{
436	register int siz;
437	register struct nfssvc_sock *slp;
438	struct nfsd *nfsd = nsd->nsd_nfsd;
439	struct nfsrv_descript *nd = NULL;
440	struct mbuf *m, *mreq;
441	int error = 0, cacherep, s, sotype, writes_todo;
442	int procrastinate;
443	u_quad_t cur_usec;
444
445#ifndef nolint
446	cacherep = RC_DOIT;
447	writes_todo = 0;
448#endif
449	if (nfsd == (struct nfsd *)0) {
450		nsd->nsd_nfsd = nfsd = (struct nfsd *)
451			malloc(sizeof (struct nfsd), M_NFSD, M_WAITOK | M_ZERO);
452		s = splnet();
453		nfsd->nfsd_procp = p;
454		TAILQ_INSERT_TAIL(&nfsd_head, nfsd, nfsd_chain);
455		nfs_numnfsd++;
456	} else
457		s = splnet();
458
459	/*
460	 * Loop getting rpc requests until SIGKILL.
461	 */
462	for (;;) {
463		if ((nfsd->nfsd_flag & NFSD_REQINPROG) == 0) {
464			while (nfsd->nfsd_slp == (struct nfssvc_sock *)0 &&
465			    (nfsd_head_flag & NFSD_CHECKSLP) == 0) {
466				nfsd->nfsd_flag |= NFSD_WAITING;
467				nfsd_waiting++;
468				error = tsleep((caddr_t)nfsd, PSOCK | PCATCH,
469				    "nfsd", 0);
470				nfsd_waiting--;
471				if (error)
472					goto done;
473			}
474			if (nfsd->nfsd_slp == (struct nfssvc_sock *)0 &&
475			    (nfsd_head_flag & NFSD_CHECKSLP) != 0) {
476				for (slp = nfssvc_sockhead.tqh_first; slp != 0;
477				    slp = slp->ns_chain.tqe_next) {
478				    if ((slp->ns_flag & (SLP_VALID | SLP_DOREC))
479					== (SLP_VALID | SLP_DOREC)) {
480					    slp->ns_flag &= ~SLP_DOREC;
481					    slp->ns_sref++;
482					    nfsd->nfsd_slp = slp;
483					    break;
484				    }
485				}
486				if (slp == 0)
487					nfsd_head_flag &= ~NFSD_CHECKSLP;
488			}
489			if ((slp = nfsd->nfsd_slp) == (struct nfssvc_sock *)0)
490				continue;
491			if (slp->ns_flag & SLP_VALID) {
492				if (slp->ns_flag & SLP_DISCONN)
493					nfsrv_zapsock(slp);
494				else if (slp->ns_flag & SLP_NEEDQ) {
495					slp->ns_flag &= ~SLP_NEEDQ;
496					(void) nfs_slplock(slp, 1);
497					nfsrv_rcv(slp->ns_so, (caddr_t)slp,
498						M_TRYWAIT);
499					nfs_slpunlock(slp);
500				}
501				error = nfsrv_dorec(slp, nfsd, &nd);
502				cur_usec = nfs_curusec();
503				if (error && slp->ns_tq.lh_first &&
504				    slp->ns_tq.lh_first->nd_time <= cur_usec) {
505					error = 0;
506					cacherep = RC_DOIT;
507					writes_todo = 1;
508				} else
509					writes_todo = 0;
510				nfsd->nfsd_flag |= NFSD_REQINPROG;
511			}
512		} else {
513			error = 0;
514			slp = nfsd->nfsd_slp;
515		}
516		if (error || (slp->ns_flag & SLP_VALID) == 0) {
517			if (nd) {
518				free((caddr_t)nd, M_NFSRVDESC);
519				nd = NULL;
520			}
521			nfsd->nfsd_slp = (struct nfssvc_sock *)0;
522			nfsd->nfsd_flag &= ~NFSD_REQINPROG;
523			nfsrv_slpderef(slp);
524			continue;
525		}
526		splx(s);
527		sotype = slp->ns_so->so_type;
528		if (nd) {
529		    getmicrotime(&nd->nd_starttime);
530		    if (nd->nd_nam2)
531			nd->nd_nam = nd->nd_nam2;
532		    else
533			nd->nd_nam = slp->ns_nam;
534
535		    /*
536		     * Check to see if authorization is needed.
537		     */
538		    if (nfsd->nfsd_flag & NFSD_NEEDAUTH) {
539			nfsd->nfsd_flag &= ~NFSD_NEEDAUTH;
540			nsd->nsd_haddr =
541				((struct sockaddr_in *)
542				 nd->nd_nam)->sin_addr.s_addr;
543			nsd->nsd_authlen = nfsd->nfsd_authlen;
544			nsd->nsd_verflen = nfsd->nfsd_verflen;
545			if (!copyout(nfsd->nfsd_authstr,nsd->nsd_authstr,
546				nfsd->nfsd_authlen) &&
547			    !copyout(nfsd->nfsd_verfstr, nsd->nsd_verfstr,
548				nfsd->nfsd_verflen) &&
549			    !copyout((caddr_t)nsd, argp, sizeof (*nsd)))
550			    return (ENEEDAUTH);
551			cacherep = RC_DROPIT;
552		    } else
553			cacherep = nfsrv_getcache(nd, slp, &mreq);
554
555		    /*
556		     * Check for just starting up for NQNFS and send
557		     * fake "try again later" replies to the NQNFS clients.
558		     */
559		    if (notstarted && nqnfsstarttime <= time_second) {
560			if (modify_flag) {
561				nqnfsstarttime = time_second + nqsrv_writeslack;
562				modify_flag = 0;
563			} else
564				notstarted = 0;
565		    }
566		    if (notstarted) {
567			if ((nd->nd_flag & ND_NQNFS) == 0)
568				cacherep = RC_DROPIT;
569			else if (nd->nd_procnum != NFSPROC_WRITE) {
570				nd->nd_procnum = NFSPROC_NOOP;
571				nd->nd_repstat = NQNFS_TRYLATER;
572				cacherep = RC_DOIT;
573			} else
574				modify_flag = 1;
575		    } else if (nfsd->nfsd_flag & NFSD_AUTHFAIL) {
576			nfsd->nfsd_flag &= ~NFSD_AUTHFAIL;
577			nd->nd_procnum = NFSPROC_NOOP;
578			nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
579			cacherep = RC_DOIT;
580		    } else if (nfs_privport) {
581			/* Check if source port is privileged */
582			u_short port;
583			struct sockaddr *nam = nd->nd_nam;
584			struct sockaddr_in *sin;
585
586			sin = (struct sockaddr_in *)nam;
587			port = ntohs(sin->sin_port);
588			if (port >= IPPORT_RESERVED &&
589			    nd->nd_procnum != NFSPROC_NULL) {
590			    nd->nd_procnum = NFSPROC_NOOP;
591			    nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
592			    cacherep = RC_DOIT;
593			    printf("NFS request from unprivileged port (%s:%d)\n",
594				   inet_ntoa(sin->sin_addr), port);
595			}
596		    }
597
598		}
599
600		/*
601		 * Loop to get all the write rpc relies that have been
602		 * gathered together.
603		 */
604		do {
605		    switch (cacherep) {
606		    case RC_DOIT:
607			if (nd && (nd->nd_flag & ND_NFSV3))
608			    procrastinate = nfsrvw_procrastinate_v3;
609			else
610			    procrastinate = nfsrvw_procrastinate;
611			if (writes_todo || (nd->nd_procnum == NFSPROC_WRITE &&
612			    procrastinate > 0 && !notstarted))
613			    error = nfsrv_writegather(&nd, slp,
614				nfsd->nfsd_procp, &mreq);
615			else
616			    error = (*(nfsrv3_procs[nd->nd_procnum]))(nd,
617				slp, nfsd->nfsd_procp, &mreq);
618			if (mreq == NULL)
619				break;
620			if (error != 0 && error != NFSERR_RETVOID) {
621				if (nd->nd_procnum != NQNFSPROC_VACATED)
622					nfsstats.srv_errs++;
623				nfsrv_updatecache(nd, FALSE, mreq);
624				if (nd->nd_nam2)
625					FREE(nd->nd_nam2, M_SONAME);
626				break;
627			}
628			nfsstats.srvrpccnt[nd->nd_procnum]++;
629			nfsrv_updatecache(nd, TRUE, mreq);
630			nd->nd_mrep = (struct mbuf *)0;
631		    case RC_REPLY:
632			m = mreq;
633			siz = 0;
634			while (m) {
635				siz += m->m_len;
636				m = m->m_next;
637			}
638			if (siz <= 0 || siz > NFS_MAXPACKET) {
639				printf("mbuf siz=%d\n",siz);
640				panic("Bad nfs svc reply");
641			}
642			m = mreq;
643			m->m_pkthdr.len = siz;
644			m->m_pkthdr.rcvif = (struct ifnet *)0;
645			/*
646			 * For stream protocols, prepend a Sun RPC
647			 * Record Mark.
648			 */
649			if (sotype == SOCK_STREAM) {
650				M_PREPEND(m, NFSX_UNSIGNED, M_TRYWAIT);
651				*mtod(m, u_int32_t *) = htonl(0x80000000 | siz);
652			}
653			if (slp->ns_so->so_proto->pr_flags & PR_CONNREQUIRED)
654				(void) nfs_slplock(slp, 1);
655			if (slp->ns_flag & SLP_VALID)
656			    error = nfs_send(slp->ns_so, nd->nd_nam2, m, NULL);
657			else {
658			    error = EPIPE;
659			    m_freem(m);
660			}
661			if (nfsrtton)
662				nfsd_rt(sotype, nd, cacherep);
663			if (nd->nd_nam2)
664				FREE(nd->nd_nam2, M_SONAME);
665			if (nd->nd_mrep)
666				m_freem(nd->nd_mrep);
667			if (error == EPIPE)
668				nfsrv_zapsock(slp);
669			if (slp->ns_so->so_proto->pr_flags & PR_CONNREQUIRED)
670				nfs_slpunlock(slp);
671			if (error == EINTR || error == ERESTART) {
672				free((caddr_t)nd, M_NFSRVDESC);
673				nfsrv_slpderef(slp);
674				s = splnet();
675				goto done;
676			}
677			break;
678		    case RC_DROPIT:
679			if (nfsrtton)
680				nfsd_rt(sotype, nd, cacherep);
681			m_freem(nd->nd_mrep);
682			if (nd->nd_nam2)
683				FREE(nd->nd_nam2, M_SONAME);
684			break;
685		    };
686		    if (nd) {
687			FREE((caddr_t)nd, M_NFSRVDESC);
688			nd = NULL;
689		    }
690
691		    /*
692		     * Check to see if there are outstanding writes that
693		     * need to be serviced.
694		     */
695		    cur_usec = nfs_curusec();
696		    s = splsoftclock();
697		    if (slp->ns_tq.lh_first &&
698			slp->ns_tq.lh_first->nd_time <= cur_usec) {
699			cacherep = RC_DOIT;
700			writes_todo = 1;
701		    } else
702			writes_todo = 0;
703		    splx(s);
704		} while (writes_todo);
705		s = splnet();
706		if (nfsrv_dorec(slp, nfsd, &nd)) {
707			nfsd->nfsd_flag &= ~NFSD_REQINPROG;
708			nfsd->nfsd_slp = NULL;
709			nfsrv_slpderef(slp);
710		}
711	}
712done:
713	TAILQ_REMOVE(&nfsd_head, nfsd, nfsd_chain);
714	splx(s);
715	free((caddr_t)nfsd, M_NFSD);
716	nsd->nsd_nfsd = (struct nfsd *)0;
717	if (--nfs_numnfsd == 0)
718		nfsrv_init(TRUE);	/* Reinitialize everything */
719	return (error);
720}
721
722/*
723 * Shut down a socket associated with an nfssvc_sock structure.
724 * Should be called with the send lock set, if required.
725 * The trick here is to increment the sref at the start, so that the nfsds
726 * will stop using it and clear ns_flag at the end so that it will not be
727 * reassigned during cleanup.
728 */
729static void
730nfsrv_zapsock(slp)
731	register struct nfssvc_sock *slp;
732{
733	register struct nfsuid *nuidp, *nnuidp;
734	register struct nfsrv_descript *nwp, *nnwp;
735	struct socket *so;
736	struct file *fp;
737	struct nfsrv_rec *rec;
738	int s;
739
740	slp->ns_flag &= ~SLP_ALLFLAGS;
741	fp = slp->ns_fp;
742	if (fp) {
743		slp->ns_fp = (struct file *)0;
744		so = slp->ns_so;
745		so->so_rcv.sb_flags &= ~SB_UPCALL;
746		so->so_upcall = NULL;
747		so->so_upcallarg = NULL;
748		soshutdown(so, 2);
749		closef(fp, (struct proc *)0);
750		if (slp->ns_nam)
751			FREE(slp->ns_nam, M_SONAME);
752		m_freem(slp->ns_raw);
753		while ((rec = STAILQ_FIRST(&slp->ns_rec)) != NULL) {
754			STAILQ_REMOVE_HEAD(&slp->ns_rec, nr_link);
755			if (rec->nr_address)
756				FREE(rec->nr_address, M_SONAME);
757			m_freem(rec->nr_packet);
758			free(rec, M_NFSRVDESC);
759		}
760		for (nuidp = slp->ns_uidlruhead.tqh_first; nuidp != 0;
761		    nuidp = nnuidp) {
762			nnuidp = nuidp->nu_lru.tqe_next;
763			LIST_REMOVE(nuidp, nu_hash);
764			TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
765			if (nuidp->nu_flag & NU_NAM)
766				FREE(nuidp->nu_nam, M_SONAME);
767			free((caddr_t)nuidp, M_NFSUID);
768		}
769		s = splsoftclock();
770		for (nwp = slp->ns_tq.lh_first; nwp; nwp = nnwp) {
771			nnwp = nwp->nd_tq.le_next;
772			LIST_REMOVE(nwp, nd_tq);
773			free((caddr_t)nwp, M_NFSRVDESC);
774		}
775		LIST_INIT(&slp->ns_tq);
776		splx(s);
777	}
778}
779
780/*
781 * Derefence a server socket structure. If it has no more references and
782 * is no longer valid, you can throw it away.
783 */
784void
785nfsrv_slpderef(slp)
786	register struct nfssvc_sock *slp;
787{
788	if (--(slp->ns_sref) == 0 && (slp->ns_flag & SLP_VALID) == 0) {
789		TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
790		free((caddr_t)slp, M_NFSSVC);
791	}
792}
793
794/*
795 * Lock a socket against others.
796 */
797int
798nfs_slplock(slp, wait)
799	register struct nfssvc_sock *slp;
800	int wait;
801{
802	int *statep = &slp->ns_solock;
803
804	if (!wait && (*statep & NFSSTA_SNDLOCK))
805		return(0);	/* already locked, fail */
806	while (*statep & NFSSTA_SNDLOCK) {
807		*statep |= NFSSTA_WANTSND;
808		(void) tsleep((caddr_t)statep, PZERO - 1, "nfsslplck", 0);
809	}
810	*statep |= NFSSTA_SNDLOCK;
811	return (1);
812}
813
814/*
815 * Unlock the stream socket for others.
816 */
817void
818nfs_slpunlock(slp)
819	register struct nfssvc_sock *slp;
820{
821	int *statep = &slp->ns_solock;
822
823	if ((*statep & NFSSTA_SNDLOCK) == 0)
824		panic("nfs slpunlock");
825	*statep &= ~NFSSTA_SNDLOCK;
826	if (*statep & NFSSTA_WANTSND) {
827		*statep &= ~NFSSTA_WANTSND;
828		wakeup((caddr_t)statep);
829	}
830}
831
832/*
833 * Initialize the data structures for the server.
834 * Handshake with any new nfsds starting up to avoid any chance of
835 * corruption.
836 */
837void
838nfsrv_init(terminating)
839	int terminating;
840{
841	register struct nfssvc_sock *slp, *nslp;
842
843	if (nfssvc_sockhead_flag & SLP_INIT)
844		panic("nfsd init");
845	nfssvc_sockhead_flag |= SLP_INIT;
846	if (terminating) {
847		for (slp = nfssvc_sockhead.tqh_first; slp != 0; slp = nslp) {
848			nslp = slp->ns_chain.tqe_next;
849			if (slp->ns_flag & SLP_VALID)
850				nfsrv_zapsock(slp);
851			TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
852			free((caddr_t)slp, M_NFSSVC);
853		}
854		nfsrv_cleancache();	/* And clear out server cache */
855	} else
856		nfs_pub.np_valid = 0;
857
858	TAILQ_INIT(&nfssvc_sockhead);
859	nfssvc_sockhead_flag &= ~SLP_INIT;
860	if (nfssvc_sockhead_flag & SLP_WANTINIT) {
861		nfssvc_sockhead_flag &= ~SLP_WANTINIT;
862		wakeup((caddr_t)&nfssvc_sockhead);
863	}
864
865	TAILQ_INIT(&nfsd_head);
866	nfsd_head_flag &= ~NFSD_CHECKSLP;
867
868#if 0
869	nfs_udpsock = (struct nfssvc_sock *)
870	    malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK | M_ZERO);
871	STAILQ_INIT(&nfs_udpsock->ns_rec);
872	TAILQ_INIT(&nfs_udpsock->ns_uidlruhead);
873	TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain);
874
875	nfs_cltpsock = (struct nfssvc_sock *)
876	    malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK | M_ZERO);
877	STAILQ_INIT(&nfs_cltpsock->ns_rec);
878	TAILQ_INIT(&nfs_cltpsock->ns_uidlruhead);
879	TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain);
880#endif
881}
882
883/*
884 * Add entries to the server monitor log.
885 */
886static void
887nfsd_rt(sotype, nd, cacherep)
888	int sotype;
889	register struct nfsrv_descript *nd;
890	int cacherep;
891{
892	register struct drt *rt;
893
894	rt = &nfsdrt.drt[nfsdrt.pos];
895	if (cacherep == RC_DOIT)
896		rt->flag = 0;
897	else if (cacherep == RC_REPLY)
898		rt->flag = DRT_CACHEREPLY;
899	else
900		rt->flag = DRT_CACHEDROP;
901	if (sotype == SOCK_STREAM)
902		rt->flag |= DRT_TCP;
903	if (nd->nd_flag & ND_NQNFS)
904		rt->flag |= DRT_NQNFS;
905	else if (nd->nd_flag & ND_NFSV3)
906		rt->flag |= DRT_NFSV3;
907	rt->proc = nd->nd_procnum;
908	if (nd->nd_nam->sa_family == AF_INET)
909	    rt->ipadr = ((struct sockaddr_in *)nd->nd_nam)->sin_addr.s_addr;
910	else
911	    rt->ipadr = INADDR_ANY;
912	rt->resptime = nfs_curusec() - (nd->nd_starttime.tv_sec * 1000000 + nd->nd_starttime.tv_usec);
913	getmicrotime(&rt->tstamp);
914	nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
915}
916#endif /* NFS_NOSERVER */
917
918static int nfs_defect = 0;
919SYSCTL_INT(_vfs_nfs, OID_AUTO, defect, CTLFLAG_RW, &nfs_defect, 0, "");
920
921/*
922 * Asynchronous I/O daemons for client nfs.
923 * They do read-ahead and write-behind operations on the block I/O cache.
924 * Never returns unless it fails or gets killed.
925 */
926static int
927nfssvc_iod(p)
928	struct proc *p;
929{
930	register struct buf *bp;
931	register int i, myiod;
932	struct nfsmount *nmp;
933	int error = 0;
934
935	/*
936	 * Assign my position or return error if too many already running
937	 */
938	myiod = -1;
939	for (i = 0; i < NFS_MAXASYNCDAEMON; i++)
940		if (nfs_asyncdaemon[i] == 0) {
941			nfs_asyncdaemon[i]++;
942			myiod = i;
943			break;
944		}
945	if (myiod == -1)
946		return (EBUSY);
947	nfs_numasync++;
948	/*
949	 * Just loop around doin our stuff until SIGKILL
950	 */
951	for (;;) {
952	    while (((nmp = nfs_iodmount[myiod]) == NULL
953		    || nmp->nm_bufq.tqh_first == NULL)
954		   && error == 0) {
955		if (nmp)
956		    nmp->nm_bufqiods--;
957		nfs_iodwant[myiod] = p;
958		nfs_iodmount[myiod] = NULL;
959		error = tsleep((caddr_t)&nfs_iodwant[myiod],
960			PWAIT | PCATCH, "nfsidl", 0);
961	    }
962	    if (error) {
963		nfs_asyncdaemon[myiod] = 0;
964		if (nmp)
965		    nmp->nm_bufqiods--;
966		nfs_iodwant[myiod] = NULL;
967		nfs_iodmount[myiod] = NULL;
968		nfs_numasync--;
969		return (error);
970	    }
971	    while ((bp = nmp->nm_bufq.tqh_first) != NULL) {
972		/* Take one off the front of the list */
973		TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist);
974		nmp->nm_bufqlen--;
975		if (nmp->nm_bufqwant && nmp->nm_bufqlen <= nfs_numasync) {
976		    nmp->nm_bufqwant = FALSE;
977		    wakeup(&nmp->nm_bufq);
978		}
979		if (bp->b_iocmd == BIO_READ)
980		    (void) nfs_doio(bp, bp->b_rcred, (struct proc *)0);
981		else
982		    (void) nfs_doio(bp, bp->b_wcred, (struct proc *)0);
983		/*
984		 * If there are more than one iod on this mount, then defect
985		 * so that the iods can be shared out fairly between the mounts
986		 */
987		if (nfs_defect && nmp->nm_bufqiods > 1) {
988		    NFS_DPF(ASYNCIO,
989			    ("nfssvc_iod: iod %d defecting from mount %p\n",
990			     myiod, nmp));
991		    nfs_iodmount[myiod] = NULL;
992		    nmp->nm_bufqiods--;
993		    break;
994		}
995	    }
996	}
997}
998
999
1000/*
1001 * Get an authorization string for the uid by having the mount_nfs sitting
1002 * on this mount point porpous out of the kernel and do it.
1003 */
1004int
1005nfs_getauth(nmp, rep, cred, auth_str, auth_len, verf_str, verf_len, key)
1006	register struct nfsmount *nmp;
1007	struct nfsreq *rep;
1008	struct ucred *cred;
1009	char **auth_str;
1010	int *auth_len;
1011	char *verf_str;
1012	int *verf_len;
1013	NFSKERBKEY_T key;		/* return session key */
1014{
1015	int error = 0;
1016
1017	while ((nmp->nm_state & NFSSTA_WAITAUTH) == 0) {
1018		nmp->nm_state |= NFSSTA_WANTAUTH;
1019		(void) tsleep((caddr_t)&nmp->nm_authtype, PSOCK,
1020			"nfsauth1", 2 * hz);
1021		error = nfs_sigintr(nmp, rep, rep->r_procp);
1022		if (error) {
1023			nmp->nm_state &= ~NFSSTA_WANTAUTH;
1024			return (error);
1025		}
1026	}
1027	nmp->nm_state &= ~(NFSSTA_WAITAUTH | NFSSTA_WANTAUTH);
1028	nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK);
1029	nmp->nm_authlen = RPCAUTH_MAXSIZ;
1030	nmp->nm_verfstr = verf_str;
1031	nmp->nm_verflen = *verf_len;
1032	nmp->nm_authuid = cred->cr_uid;
1033	wakeup((caddr_t)&nmp->nm_authstr);
1034
1035	/*
1036	 * And wait for mount_nfs to do its stuff.
1037	 */
1038	while ((nmp->nm_state & NFSSTA_HASAUTH) == 0 && error == 0) {
1039		(void) tsleep((caddr_t)&nmp->nm_authlen, PSOCK,
1040			"nfsauth2", 2 * hz);
1041		error = nfs_sigintr(nmp, rep, rep->r_procp);
1042	}
1043	if (nmp->nm_state & NFSSTA_AUTHERR) {
1044		nmp->nm_state &= ~NFSSTA_AUTHERR;
1045		error = EAUTH;
1046	}
1047	if (error)
1048		free((caddr_t)*auth_str, M_TEMP);
1049	else {
1050		*auth_len = nmp->nm_authlen;
1051		*verf_len = nmp->nm_verflen;
1052		bcopy((caddr_t)nmp->nm_key, (caddr_t)key, sizeof (key));
1053	}
1054	nmp->nm_state &= ~NFSSTA_HASAUTH;
1055	nmp->nm_state |= NFSSTA_WAITAUTH;
1056	if (nmp->nm_state & NFSSTA_WANTAUTH) {
1057		nmp->nm_state &= ~NFSSTA_WANTAUTH;
1058		wakeup((caddr_t)&nmp->nm_authtype);
1059	}
1060	return (error);
1061}
1062
1063/*
1064 * Get a nickname authenticator and verifier.
1065 */
1066int
1067nfs_getnickauth(nmp, cred, auth_str, auth_len, verf_str, verf_len)
1068	struct nfsmount *nmp;
1069	struct ucred *cred;
1070	char **auth_str;
1071	int *auth_len;
1072	char *verf_str;
1073	int verf_len;
1074{
1075	register struct nfsuid *nuidp;
1076	register u_int32_t *nickp, *verfp;
1077	struct timeval ktvin, ktvout;
1078
1079#ifdef DIAGNOSTIC
1080	if (verf_len < (4 * NFSX_UNSIGNED))
1081		panic("nfs_getnickauth verf too small");
1082#endif
1083	for (nuidp = NMUIDHASH(nmp, cred->cr_uid)->lh_first;
1084	    nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
1085		if (nuidp->nu_cr.cr_uid == cred->cr_uid)
1086			break;
1087	}
1088	if (!nuidp || nuidp->nu_expire < time_second)
1089		return (EACCES);
1090
1091	/*
1092	 * Move to the end of the lru list (end of lru == most recently used).
1093	 */
1094	TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru);
1095	TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, nu_lru);
1096
1097	nickp = (u_int32_t *)malloc(2 * NFSX_UNSIGNED, M_TEMP, M_WAITOK);
1098	*nickp++ = txdr_unsigned(RPCAKN_NICKNAME);
1099	*nickp = txdr_unsigned(nuidp->nu_nickname);
1100	*auth_str = (char *)nickp;
1101	*auth_len = 2 * NFSX_UNSIGNED;
1102
1103	/*
1104	 * Now we must encrypt the verifier and package it up.
1105	 */
1106	verfp = (u_int32_t *)verf_str;
1107	*verfp++ = txdr_unsigned(RPCAKN_NICKNAME);
1108	if (time_second > nuidp->nu_timestamp.tv_sec ||
1109	    (time_second == nuidp->nu_timestamp.tv_sec &&
1110	     time_second > nuidp->nu_timestamp.tv_usec))
1111		getmicrotime(&nuidp->nu_timestamp);
1112	else
1113		nuidp->nu_timestamp.tv_usec++;
1114	ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec);
1115	ktvin.tv_usec = txdr_unsigned(nuidp->nu_timestamp.tv_usec);
1116
1117	/*
1118	 * Now encrypt the timestamp verifier in ecb mode using the session
1119	 * key.
1120	 */
1121#ifdef NFSKERB
1122	XXX
1123#endif
1124
1125	*verfp++ = ktvout.tv_sec;
1126	*verfp++ = ktvout.tv_usec;
1127	*verfp = 0;
1128	return (0);
1129}
1130
1131/*
1132 * Save the current nickname in a hash list entry on the mount point.
1133 */
1134int
1135nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep)
1136	register struct nfsmount *nmp;
1137	struct ucred *cred;
1138	int len;
1139	NFSKERBKEY_T key;
1140	struct mbuf **mdp;
1141	char **dposp;
1142	struct mbuf *mrep;
1143{
1144	register struct nfsuid *nuidp;
1145	register u_int32_t *tl;
1146	register int32_t t1;
1147	struct mbuf *md = *mdp;
1148	struct timeval ktvin, ktvout;
1149	u_int32_t nick;
1150	char *dpos = *dposp, *cp2;
1151	int deltasec, error = 0;
1152
1153	if (len == (3 * NFSX_UNSIGNED)) {
1154		nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
1155		ktvin.tv_sec = *tl++;
1156		ktvin.tv_usec = *tl++;
1157		nick = fxdr_unsigned(u_int32_t, *tl);
1158
1159		/*
1160		 * Decrypt the timestamp in ecb mode.
1161		 */
1162#ifdef NFSKERB
1163		XXX
1164#endif
1165		ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec);
1166		ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec);
1167		deltasec = time_second - ktvout.tv_sec;
1168		if (deltasec < 0)
1169			deltasec = -deltasec;
1170		/*
1171		 * If ok, add it to the hash list for the mount point.
1172		 */
1173		if (deltasec <= NFS_KERBCLOCKSKEW) {
1174			if (nmp->nm_numuids < nuidhash_max) {
1175				nmp->nm_numuids++;
1176				nuidp = (struct nfsuid *)
1177				   malloc(sizeof (struct nfsuid), M_NFSUID,
1178					M_WAITOK);
1179			} else {
1180				nuidp = nmp->nm_uidlruhead.tqh_first;
1181				LIST_REMOVE(nuidp, nu_hash);
1182				TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp,
1183					nu_lru);
1184			}
1185			nuidp->nu_flag = 0;
1186			nuidp->nu_cr.cr_uid = cred->cr_uid;
1187			nuidp->nu_expire = time_second + NFS_KERBTTL;
1188			nuidp->nu_timestamp = ktvout;
1189			nuidp->nu_nickname = nick;
1190			bcopy(key, nuidp->nu_key, sizeof (key));
1191			TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp,
1192				nu_lru);
1193			LIST_INSERT_HEAD(NMUIDHASH(nmp, cred->cr_uid),
1194				nuidp, nu_hash);
1195		}
1196	} else
1197		nfsm_adv(nfsm_rndup(len));
1198nfsmout:
1199	*mdp = md;
1200	*dposp = dpos;
1201	return (error);
1202}
1203