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