319struct uio; struct buf; struct vattr; struct nameidata; /* XXX */ 320 321/* 322 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 323 * What should be in this set is open to debate, but I believe that since 324 * I/O system calls on ufs are never interrupted by signals the set should 325 * be minimal. My reasoning is that many current programs that use signals 326 * such as SIGALRM will not expect file I/O system calls to be interrupted 327 * by them and break. 328 */ 329#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 330 sigmask(SIGHUP)|sigmask(SIGQUIT)) 331 332/* 333 * Socket errors ignored for connectionless sockets?? 334 * For now, ignore them all 335 */ 336#define NFSIGNORE_SOERROR(s, e) \ 337 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 338 ((s) & PR_CONNREQUIRED) == 0) 339 340/* 341 * Nfs outstanding request list element 342 */ 343struct nfsreq { 344 TAILQ_ENTRY(nfsreq) r_chain; 345 struct mbuf *r_mreq; 346 struct mbuf *r_mrep; 347 struct mbuf *r_md; 348 caddr_t r_dpos; 349 struct nfsmount *r_nmp; 350 struct vnode *r_vp; 351 u_long r_xid; 352 int r_flags; /* flags on request, see below */ 353 int r_retry; /* max retransmission count */ 354 int r_rexmit; /* current retrans count */ 355 int r_timer; /* tick counter on reply */ 356 u_int32_t r_procnum; /* NFS procedure number */ 357 int r_rtt; /* RTT for rpc */ 358 struct proc *r_procp; /* Proc that did I/O system call */ 359}; 360 361/* 362 * Queue head for nfsreq's 363 */ 364extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq; 365 366/* Flag values for r_flags */ 367#define R_TIMING 0x01 /* timing request (in mntp) */ 368#define R_SENT 0x02 /* request has been sent */ 369#define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 370#define R_INTR 0x08 /* intr mnt, signal pending */ 371#define R_SOCKERR 0x10 /* Fatal error on socket */ 372#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 373#define R_MUSTRESEND 0x40 /* Must resend request */ 374#define R_GETONEREP 0x80 /* Probe for one reply only */ 375 376/* 377 * A list of nfssvc_sock structures is maintained with all the sockets 378 * that require service by the nfsd. 379 * The nfsuid structs hang off of the nfssvc_sock structs in both lru 380 * and uid hash lists. 381 */ 382#ifndef NFS_UIDHASHSIZ 383#define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */ 384#endif 385#define NUIDHASH(sock, uid) \ 386 (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ]) 387#ifndef NFS_WDELAYHASHSIZ 388#define NFS_WDELAYHASHSIZ 16 /* and with this */ 389#endif 390#define NWDELAYHASH(sock, f) \ 391 (&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ]) 392#ifndef NFS_MUIDHASHSIZ 393#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */ 394#endif 395#define NMUIDHASH(nmp, uid) \ 396 (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ]) 397#define NFSNOHASH(fhsum) \ 398 (&nfsnodehashtbl[(fhsum) & nfsnodehash]) 399 400struct nfsuid { 401 TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */ 402 LIST_ENTRY(nfsuid) nu_hash; /* Hash list */ 403 int nu_flag; /* Flags */ 404 union nethostaddr nu_haddr; /* Host addr. for dgram sockets */ 405 struct ucred nu_cr; /* Cred uid mapped to */ 406 int nu_expire; /* Expiry time (sec) */ 407 struct timeval nu_timestamp; /* Kerb. timestamp */ 408 u_long nu_nickname; /* Nickname on server */ 409 NFSKERBKEY_T nu_key; /* and session key */ 410}; 411 412#define nu_inetaddr nu_haddr.had_inetaddr 413#define nu_nam nu_haddr.had_nam 414/* Bits for nu_flag */ 415#define NU_INETADDR 0x1 416#define NU_NAM 0x2 417#define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO) 418 419struct nfsrv_rec { 420 STAILQ_ENTRY(nfsrv_rec) nr_link; 421 struct sockaddr *nr_address; 422 struct mbuf *nr_packet; 423}; 424 425struct nfssvc_sock { 426 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ 427 TAILQ_HEAD(, nfsuid) ns_uidlruhead; 428 struct file *ns_fp; 429 struct socket *ns_so; 430 struct sockaddr *ns_nam; 431 struct mbuf *ns_raw; 432 struct mbuf *ns_rawend; 433 STAILQ_HEAD(, nfsrv_rec) ns_rec; 434 struct mbuf *ns_frag; 435 int ns_flag; 436 int ns_solock; 437 int ns_cc; 438 int ns_reclen; 439 int ns_numuids; 440 u_long ns_sref; 441 LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */ 442 LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ]; 443 LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ]; 444}; 445 446/* Bits for "ns_flag" */ 447#define SLP_VALID 0x01 448#define SLP_DOREC 0x02 449#define SLP_NEEDQ 0x04 450#define SLP_DISCONN 0x08 451#define SLP_GETSTREAM 0x10 452#define SLP_LASTFRAG 0x20 453#define SLP_ALLFLAGS 0xff 454 455extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead; 456extern int nfssvc_sockhead_flag; 457#define SLP_INIT 0x01 458#define SLP_WANTINIT 0x02 459 460/* 461 * One of these structures is allocated for each nfsd. 462 */ 463struct nfsd { 464 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */ 465 int nfsd_flag; /* NFSD_ flags */ 466 struct nfssvc_sock *nfsd_slp; /* Current socket */ 467 int nfsd_authlen; /* Authenticator len */ 468 u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */ 469 int nfsd_verflen; /* and the Verifier */ 470 u_char nfsd_verfstr[RPCVERF_MAXSIZ]; 471 struct proc *nfsd_procp; /* Proc ptr */ 472 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */ 473}; 474 475/* Bits for "nfsd_flag" */ 476#define NFSD_WAITING 0x01 477#define NFSD_REQINPROG 0x02 478#define NFSD_NEEDAUTH 0x04 479#define NFSD_AUTHFAIL 0x08 480 481/* 482 * This structure is used by the server for describing each request. 483 * Some fields are used only when write request gathering is performed. 484 */ 485struct nfsrv_descript { 486 u_quad_t nd_time; /* Write deadline (usec) */ 487 off_t nd_off; /* Start byte offset */ 488 off_t nd_eoff; /* and end byte offset */ 489 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */ 490 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */ 491 LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */ 492 struct mbuf *nd_mrep; /* Request mbuf list */ 493 struct mbuf *nd_md; /* Current dissect mbuf */ 494 struct mbuf *nd_mreq; /* Reply mbuf list */ 495 struct sockaddr *nd_nam; /* and socket addr */ 496 struct sockaddr *nd_nam2; /* return socket addr */ 497 caddr_t nd_dpos; /* Current dissect pos */ 498 u_int32_t nd_procnum; /* RPC # */ 499 int nd_stable; /* storage type */ 500 int nd_flag; /* nd_flag */ 501 int nd_len; /* Length of this write */ 502 int nd_repstat; /* Reply status */ 503 u_long nd_retxid; /* Reply xid */ 504 u_long nd_duration; /* Lease duration */ 505 struct timeval nd_starttime; /* Time RPC initiated */ 506 fhandle_t nd_fh; /* File handle */ 507 struct ucred nd_cr; /* Credentials */ 508}; 509 510/* Bits for "nd_flag" */ 511#define ND_READ LEASE_READ 512#define ND_WRITE LEASE_WRITE 513#define ND_CHECK 0x04 514#define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK) 515#define ND_NFSV3 0x08 516#define ND_NQNFS 0x10 517#define ND_KERBNICK 0x20 518#define ND_KERBFULL 0x40 519#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL) 520 521extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head; 522extern int nfsd_head_flag; 523#define NFSD_CHECKSLP 0x01 524 525/* 526 * These macros compare nfsrv_descript structures. 527 */ 528#define NFSW_CONTIG(o, n) \ 529 ((o)->nd_eoff >= (n)->nd_off && \ 530 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH)) 531 532#define NFSW_SAMECRED(o, n) \ 533 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \ 534 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \ 535 sizeof (struct ucred))) 536 537/* 538 * Defines for WebNFS 539 */ 540 541#define WEBNFS_ESC_CHAR '%' 542#define WEBNFS_SPECCHAR_START 0x80 543 544#define WEBNFS_NATIVE_CHAR 0x80 545/* 546 * .. 547 * Possibly more here in the future. 548 */ 549 550/* 551 * Macro for converting escape characters in WebNFS pathnames. 552 * Should really be in libkern. 553 */ 554 555#define HEXTOC(c) \ 556 ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 557 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 558#define HEXSTRTOI(p) \ 559 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 560 561#ifdef NFS_DEBUG 562 563extern int nfs_debug; 564#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 565#define NFS_DEBUG_WG 2 /* server write gathering */ 566#define NFS_DEBUG_RC 4 /* server request caching */ 567 568#define NFS_DPF(cat, args) \ 569 do { \ 570 if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 571 } while (0) 572 573#else 574 575#define NFS_DPF(cat, args) 576 577#endif 578 579u_quad_t nfs_curusec __P((void)); 580int nfs_init __P((struct vfsconf *vfsp)); 581int nfs_reply __P((struct nfsreq *)); 582int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int)); 583int nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *, 584 struct nfsreq *)); 585int nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *, 586 int, int, u_quad_t *, struct mbuf **, struct mbuf **, 587 caddr_t *)); 588int nfs_sndlock __P((int *, int *, struct nfsreq *)); 589void nfs_sndunlock __P((int *, int *)); 590int nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *)); 591int nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *, 592 int)); 593int nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *)); 594int nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *, 595 int *)); 596int nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *)); 597int nfs_asyncio __P((struct buf *, struct ucred *)); 598int nfs_doio __P((struct buf *, struct ucred *, struct proc *)); 599int nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *)); 600int nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *)); 601int nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *)); 602int nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *)); 603void nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *, 604 struct nfs_fattr *)); 605void nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int, 606 struct vattr *, struct mbuf **, char **)); 607void nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *, 608 struct mbuf **, char **)); 609int netaddr_match __P((int, union nethostaddr *, struct sockaddr *)); 610int nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *, 611 struct ucred *, struct mbuf **, struct mbuf **, 612 caddr_t *)); 613int nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *, 614 struct vattr *)); 615int nfs_namei __P((struct nameidata *, fhandle_t *, int, 616 struct nfssvc_sock *, struct sockaddr *, struct mbuf **, 617 caddr_t *, struct vnode **, struct proc *, int, int)); 618void nfsm_adj __P((struct mbuf *, int, int)); 619int nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *)); 620void nfsrv_initcache __P((void)); 621int nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *, 622 char **, int *, char *, int *, NFSKERBKEY_T)); 623int nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **, 624 int *, char *, int)); 625int nfs_savenickauth __P((struct nfsmount *, struct ucred *, int, 626 NFSKERBKEY_T, struct mbuf **, char **, 627 struct mbuf *)); 628int nfs_adv __P((struct mbuf **, caddr_t *, int, int)); 629void nfs_nhinit __P((void)); 630void nfs_timer __P((void*)); 631u_long nfs_hash __P((nfsfh_t *, int)); 632int nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *, 633 struct nfsrv_descript **)); 634int nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *, 635 struct mbuf **)); 636void nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *)); 637void nfsrv_cleancache __P((void)); 638int nfs_connect __P((struct nfsmount *, struct nfsreq *)); 639void nfs_disconnect __P((struct nfsmount *)); 640int nfs_getattrcache __P((struct vnode *, struct vattr *)); 641int nfsm_strtmbuf __P((struct mbuf **, char **, char *, long)); 642int nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *, 643 int)); 644int nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *)); 645void nfsrv_init __P((int)); 646void nfs_clearcommit __P((struct mount *)); 647int nfsrv_errmap __P((struct nfsrv_descript *, int)); 648void nfsrvw_sort __P((gid_t *, int)); 649void nfsrv_setcred __P((struct ucred *, struct ucred *)); 650int nfs_writebp __P((struct buf *, int)); 651int nfsrv_object_create __P((struct vnode *)); 652void nfsrv_wakenfsd __P((struct nfssvc_sock *slp)); 653int nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *, 654 struct proc *, struct mbuf **)); 655int nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *, 656 struct proc *p)); 657 658int nfsrv3_access __P((struct nfsrv_descript *nfsd, 659 struct nfssvc_sock *slp, 660 struct proc *procp, struct mbuf **mrq)); 661int nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 662 struct proc *procp, struct mbuf **mrq)); 663int nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 664 struct proc *procp, struct mbuf **mrq)); 665int nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *, 666 struct nfssvc_sock *, struct sockaddr *, int *, 667 int, int)); 668int nfsrv_setpublicfs __P((struct mount *, struct netexport *, 669 struct export_args *)); 670int nfs_ispublicfh __P((fhandle_t *)); 671int nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 672 struct proc *procp, struct mbuf **mrq)); 673int nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 674 struct proc *procp, struct mbuf **mrq)); 675int nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 676 struct proc *procp, struct mbuf **mrq)); 677int nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 678 struct proc *procp, struct mbuf **mrq)); 679int nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 680 struct proc *procp, struct mbuf **mrq)); 681int nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 682 struct proc *procp, struct mbuf **mrq)); 683int nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 684 struct proc *procp, struct mbuf **mrq)); 685int nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 686 struct proc *procp, struct mbuf **mrq)); 687int nfsrv_pathconf __P((struct nfsrv_descript *nfsd, 688 struct nfssvc_sock *slp, struct proc *procp, 689 struct mbuf **mrq)); 690int nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 691 struct proc *procp, struct mbuf **mrq)); 692int nfsrv_readdir __P((struct nfsrv_descript *nfsd, 693 struct nfssvc_sock *slp, 694 struct proc *procp, struct mbuf **mrq)); 695int nfsrv_readdirplus __P((struct nfsrv_descript *nfsd, 696 struct nfssvc_sock *slp, struct proc *procp, 697 struct mbuf **mrq)); 698int nfsrv_readlink __P((struct nfsrv_descript *nfsd, 699 struct nfssvc_sock *slp, struct proc *procp, 700 struct mbuf **mrq)); 701int nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 702 struct proc *procp, struct mbuf **mrq)); 703int nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 704 struct proc *procp, struct mbuf **mrq)); 705int nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 706 struct proc *procp, struct mbuf **mrq)); 707int nfsrv_setattr __P((struct nfsrv_descript *nfsd, 708 struct nfssvc_sock *slp, 709 struct proc *procp, struct mbuf **mrq)); 710int nfsrv_statfs __P((struct nfsrv_descript *nfsd, 711 struct nfssvc_sock *slp, 712 struct proc *procp, struct mbuf **mrq)); 713int nfsrv_symlink __P((struct nfsrv_descript *nfsd, 714 struct nfssvc_sock *slp, 715 struct proc *procp, struct mbuf **mrq)); 716int nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 717 struct proc *procp, struct mbuf **mrq)); 718void nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag)); 719void nfsrv_slpderef __P((struct nfssvc_sock *slp)); 720#endif /* KERNEL */ 721 722#endif
| 321struct uio; struct buf; struct vattr; struct nameidata; /* XXX */ 322 323/* 324 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 325 * What should be in this set is open to debate, but I believe that since 326 * I/O system calls on ufs are never interrupted by signals the set should 327 * be minimal. My reasoning is that many current programs that use signals 328 * such as SIGALRM will not expect file I/O system calls to be interrupted 329 * by them and break. 330 */ 331#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 332 sigmask(SIGHUP)|sigmask(SIGQUIT)) 333 334/* 335 * Socket errors ignored for connectionless sockets?? 336 * For now, ignore them all 337 */ 338#define NFSIGNORE_SOERROR(s, e) \ 339 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 340 ((s) & PR_CONNREQUIRED) == 0) 341 342/* 343 * Nfs outstanding request list element 344 */ 345struct nfsreq { 346 TAILQ_ENTRY(nfsreq) r_chain; 347 struct mbuf *r_mreq; 348 struct mbuf *r_mrep; 349 struct mbuf *r_md; 350 caddr_t r_dpos; 351 struct nfsmount *r_nmp; 352 struct vnode *r_vp; 353 u_long r_xid; 354 int r_flags; /* flags on request, see below */ 355 int r_retry; /* max retransmission count */ 356 int r_rexmit; /* current retrans count */ 357 int r_timer; /* tick counter on reply */ 358 u_int32_t r_procnum; /* NFS procedure number */ 359 int r_rtt; /* RTT for rpc */ 360 struct proc *r_procp; /* Proc that did I/O system call */ 361}; 362 363/* 364 * Queue head for nfsreq's 365 */ 366extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq; 367 368/* Flag values for r_flags */ 369#define R_TIMING 0x01 /* timing request (in mntp) */ 370#define R_SENT 0x02 /* request has been sent */ 371#define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 372#define R_INTR 0x08 /* intr mnt, signal pending */ 373#define R_SOCKERR 0x10 /* Fatal error on socket */ 374#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 375#define R_MUSTRESEND 0x40 /* Must resend request */ 376#define R_GETONEREP 0x80 /* Probe for one reply only */ 377 378/* 379 * A list of nfssvc_sock structures is maintained with all the sockets 380 * that require service by the nfsd. 381 * The nfsuid structs hang off of the nfssvc_sock structs in both lru 382 * and uid hash lists. 383 */ 384#ifndef NFS_UIDHASHSIZ 385#define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */ 386#endif 387#define NUIDHASH(sock, uid) \ 388 (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ]) 389#ifndef NFS_WDELAYHASHSIZ 390#define NFS_WDELAYHASHSIZ 16 /* and with this */ 391#endif 392#define NWDELAYHASH(sock, f) \ 393 (&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ]) 394#ifndef NFS_MUIDHASHSIZ 395#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */ 396#endif 397#define NMUIDHASH(nmp, uid) \ 398 (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ]) 399#define NFSNOHASH(fhsum) \ 400 (&nfsnodehashtbl[(fhsum) & nfsnodehash]) 401 402struct nfsuid { 403 TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */ 404 LIST_ENTRY(nfsuid) nu_hash; /* Hash list */ 405 int nu_flag; /* Flags */ 406 union nethostaddr nu_haddr; /* Host addr. for dgram sockets */ 407 struct ucred nu_cr; /* Cred uid mapped to */ 408 int nu_expire; /* Expiry time (sec) */ 409 struct timeval nu_timestamp; /* Kerb. timestamp */ 410 u_long nu_nickname; /* Nickname on server */ 411 NFSKERBKEY_T nu_key; /* and session key */ 412}; 413 414#define nu_inetaddr nu_haddr.had_inetaddr 415#define nu_nam nu_haddr.had_nam 416/* Bits for nu_flag */ 417#define NU_INETADDR 0x1 418#define NU_NAM 0x2 419#define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO) 420 421struct nfsrv_rec { 422 STAILQ_ENTRY(nfsrv_rec) nr_link; 423 struct sockaddr *nr_address; 424 struct mbuf *nr_packet; 425}; 426 427struct nfssvc_sock { 428 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ 429 TAILQ_HEAD(, nfsuid) ns_uidlruhead; 430 struct file *ns_fp; 431 struct socket *ns_so; 432 struct sockaddr *ns_nam; 433 struct mbuf *ns_raw; 434 struct mbuf *ns_rawend; 435 STAILQ_HEAD(, nfsrv_rec) ns_rec; 436 struct mbuf *ns_frag; 437 int ns_flag; 438 int ns_solock; 439 int ns_cc; 440 int ns_reclen; 441 int ns_numuids; 442 u_long ns_sref; 443 LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */ 444 LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ]; 445 LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ]; 446}; 447 448/* Bits for "ns_flag" */ 449#define SLP_VALID 0x01 450#define SLP_DOREC 0x02 451#define SLP_NEEDQ 0x04 452#define SLP_DISCONN 0x08 453#define SLP_GETSTREAM 0x10 454#define SLP_LASTFRAG 0x20 455#define SLP_ALLFLAGS 0xff 456 457extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead; 458extern int nfssvc_sockhead_flag; 459#define SLP_INIT 0x01 460#define SLP_WANTINIT 0x02 461 462/* 463 * One of these structures is allocated for each nfsd. 464 */ 465struct nfsd { 466 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */ 467 int nfsd_flag; /* NFSD_ flags */ 468 struct nfssvc_sock *nfsd_slp; /* Current socket */ 469 int nfsd_authlen; /* Authenticator len */ 470 u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */ 471 int nfsd_verflen; /* and the Verifier */ 472 u_char nfsd_verfstr[RPCVERF_MAXSIZ]; 473 struct proc *nfsd_procp; /* Proc ptr */ 474 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */ 475}; 476 477/* Bits for "nfsd_flag" */ 478#define NFSD_WAITING 0x01 479#define NFSD_REQINPROG 0x02 480#define NFSD_NEEDAUTH 0x04 481#define NFSD_AUTHFAIL 0x08 482 483/* 484 * This structure is used by the server for describing each request. 485 * Some fields are used only when write request gathering is performed. 486 */ 487struct nfsrv_descript { 488 u_quad_t nd_time; /* Write deadline (usec) */ 489 off_t nd_off; /* Start byte offset */ 490 off_t nd_eoff; /* and end byte offset */ 491 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */ 492 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */ 493 LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */ 494 struct mbuf *nd_mrep; /* Request mbuf list */ 495 struct mbuf *nd_md; /* Current dissect mbuf */ 496 struct mbuf *nd_mreq; /* Reply mbuf list */ 497 struct sockaddr *nd_nam; /* and socket addr */ 498 struct sockaddr *nd_nam2; /* return socket addr */ 499 caddr_t nd_dpos; /* Current dissect pos */ 500 u_int32_t nd_procnum; /* RPC # */ 501 int nd_stable; /* storage type */ 502 int nd_flag; /* nd_flag */ 503 int nd_len; /* Length of this write */ 504 int nd_repstat; /* Reply status */ 505 u_long nd_retxid; /* Reply xid */ 506 u_long nd_duration; /* Lease duration */ 507 struct timeval nd_starttime; /* Time RPC initiated */ 508 fhandle_t nd_fh; /* File handle */ 509 struct ucred nd_cr; /* Credentials */ 510}; 511 512/* Bits for "nd_flag" */ 513#define ND_READ LEASE_READ 514#define ND_WRITE LEASE_WRITE 515#define ND_CHECK 0x04 516#define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK) 517#define ND_NFSV3 0x08 518#define ND_NQNFS 0x10 519#define ND_KERBNICK 0x20 520#define ND_KERBFULL 0x40 521#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL) 522 523extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head; 524extern int nfsd_head_flag; 525#define NFSD_CHECKSLP 0x01 526 527/* 528 * These macros compare nfsrv_descript structures. 529 */ 530#define NFSW_CONTIG(o, n) \ 531 ((o)->nd_eoff >= (n)->nd_off && \ 532 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH)) 533 534#define NFSW_SAMECRED(o, n) \ 535 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \ 536 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \ 537 sizeof (struct ucred))) 538 539/* 540 * Defines for WebNFS 541 */ 542 543#define WEBNFS_ESC_CHAR '%' 544#define WEBNFS_SPECCHAR_START 0x80 545 546#define WEBNFS_NATIVE_CHAR 0x80 547/* 548 * .. 549 * Possibly more here in the future. 550 */ 551 552/* 553 * Macro for converting escape characters in WebNFS pathnames. 554 * Should really be in libkern. 555 */ 556 557#define HEXTOC(c) \ 558 ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 559 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 560#define HEXSTRTOI(p) \ 561 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 562 563#ifdef NFS_DEBUG 564 565extern int nfs_debug; 566#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 567#define NFS_DEBUG_WG 2 /* server write gathering */ 568#define NFS_DEBUG_RC 4 /* server request caching */ 569 570#define NFS_DPF(cat, args) \ 571 do { \ 572 if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 573 } while (0) 574 575#else 576 577#define NFS_DPF(cat, args) 578 579#endif 580 581u_quad_t nfs_curusec __P((void)); 582int nfs_init __P((struct vfsconf *vfsp)); 583int nfs_reply __P((struct nfsreq *)); 584int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int)); 585int nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *, 586 struct nfsreq *)); 587int nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *, 588 int, int, u_quad_t *, struct mbuf **, struct mbuf **, 589 caddr_t *)); 590int nfs_sndlock __P((int *, int *, struct nfsreq *)); 591void nfs_sndunlock __P((int *, int *)); 592int nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *)); 593int nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *, 594 int)); 595int nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *)); 596int nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *, 597 int *)); 598int nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *)); 599int nfs_asyncio __P((struct buf *, struct ucred *)); 600int nfs_doio __P((struct buf *, struct ucred *, struct proc *)); 601int nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *)); 602int nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *)); 603int nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *)); 604int nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *)); 605void nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *, 606 struct nfs_fattr *)); 607void nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int, 608 struct vattr *, struct mbuf **, char **)); 609void nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *, 610 struct mbuf **, char **)); 611int netaddr_match __P((int, union nethostaddr *, struct sockaddr *)); 612int nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *, 613 struct ucred *, struct mbuf **, struct mbuf **, 614 caddr_t *)); 615int nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *, 616 struct vattr *)); 617int nfs_namei __P((struct nameidata *, fhandle_t *, int, 618 struct nfssvc_sock *, struct sockaddr *, struct mbuf **, 619 caddr_t *, struct vnode **, struct proc *, int, int)); 620void nfsm_adj __P((struct mbuf *, int, int)); 621int nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *)); 622void nfsrv_initcache __P((void)); 623int nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *, 624 char **, int *, char *, int *, NFSKERBKEY_T)); 625int nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **, 626 int *, char *, int)); 627int nfs_savenickauth __P((struct nfsmount *, struct ucred *, int, 628 NFSKERBKEY_T, struct mbuf **, char **, 629 struct mbuf *)); 630int nfs_adv __P((struct mbuf **, caddr_t *, int, int)); 631void nfs_nhinit __P((void)); 632void nfs_timer __P((void*)); 633u_long nfs_hash __P((nfsfh_t *, int)); 634int nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *, 635 struct nfsrv_descript **)); 636int nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *, 637 struct mbuf **)); 638void nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *)); 639void nfsrv_cleancache __P((void)); 640int nfs_connect __P((struct nfsmount *, struct nfsreq *)); 641void nfs_disconnect __P((struct nfsmount *)); 642int nfs_getattrcache __P((struct vnode *, struct vattr *)); 643int nfsm_strtmbuf __P((struct mbuf **, char **, char *, long)); 644int nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *, 645 int)); 646int nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *)); 647void nfsrv_init __P((int)); 648void nfs_clearcommit __P((struct mount *)); 649int nfsrv_errmap __P((struct nfsrv_descript *, int)); 650void nfsrvw_sort __P((gid_t *, int)); 651void nfsrv_setcred __P((struct ucred *, struct ucred *)); 652int nfs_writebp __P((struct buf *, int)); 653int nfsrv_object_create __P((struct vnode *)); 654void nfsrv_wakenfsd __P((struct nfssvc_sock *slp)); 655int nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *, 656 struct proc *, struct mbuf **)); 657int nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *, 658 struct proc *p)); 659 660int nfsrv3_access __P((struct nfsrv_descript *nfsd, 661 struct nfssvc_sock *slp, 662 struct proc *procp, struct mbuf **mrq)); 663int nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 664 struct proc *procp, struct mbuf **mrq)); 665int nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 666 struct proc *procp, struct mbuf **mrq)); 667int nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *, 668 struct nfssvc_sock *, struct sockaddr *, int *, 669 int, int)); 670int nfsrv_setpublicfs __P((struct mount *, struct netexport *, 671 struct export_args *)); 672int nfs_ispublicfh __P((fhandle_t *)); 673int nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 674 struct proc *procp, struct mbuf **mrq)); 675int nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 676 struct proc *procp, struct mbuf **mrq)); 677int nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 678 struct proc *procp, struct mbuf **mrq)); 679int nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 680 struct proc *procp, struct mbuf **mrq)); 681int nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 682 struct proc *procp, struct mbuf **mrq)); 683int nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 684 struct proc *procp, struct mbuf **mrq)); 685int nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 686 struct proc *procp, struct mbuf **mrq)); 687int nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 688 struct proc *procp, struct mbuf **mrq)); 689int nfsrv_pathconf __P((struct nfsrv_descript *nfsd, 690 struct nfssvc_sock *slp, struct proc *procp, 691 struct mbuf **mrq)); 692int nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 693 struct proc *procp, struct mbuf **mrq)); 694int nfsrv_readdir __P((struct nfsrv_descript *nfsd, 695 struct nfssvc_sock *slp, 696 struct proc *procp, struct mbuf **mrq)); 697int nfsrv_readdirplus __P((struct nfsrv_descript *nfsd, 698 struct nfssvc_sock *slp, struct proc *procp, 699 struct mbuf **mrq)); 700int nfsrv_readlink __P((struct nfsrv_descript *nfsd, 701 struct nfssvc_sock *slp, struct proc *procp, 702 struct mbuf **mrq)); 703int nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 704 struct proc *procp, struct mbuf **mrq)); 705int nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 706 struct proc *procp, struct mbuf **mrq)); 707int nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 708 struct proc *procp, struct mbuf **mrq)); 709int nfsrv_setattr __P((struct nfsrv_descript *nfsd, 710 struct nfssvc_sock *slp, 711 struct proc *procp, struct mbuf **mrq)); 712int nfsrv_statfs __P((struct nfsrv_descript *nfsd, 713 struct nfssvc_sock *slp, 714 struct proc *procp, struct mbuf **mrq)); 715int nfsrv_symlink __P((struct nfsrv_descript *nfsd, 716 struct nfssvc_sock *slp, 717 struct proc *procp, struct mbuf **mrq)); 718int nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 719 struct proc *procp, struct mbuf **mrq)); 720void nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag)); 721void nfsrv_slpderef __P((struct nfssvc_sock *slp)); 722#endif /* KERNEL */ 723 724#endif
|