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