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