10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52140Srmesta * Common Development and Distribution License (the "License"). 62140Srmesta * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 2212081SThomas.Haynes@Sun.COM * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 260Sstevel@tonic-gate /* All Rights Reserved */ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #ifndef _NFS_EXPORT_H 290Sstevel@tonic-gate #define _NFS_EXPORT_H 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <nfs/nfs_sec.h> 322140Srmesta #include <nfs/auth.h> 330Sstevel@tonic-gate #include <sys/vnode.h> 340Sstevel@tonic-gate #include <nfs/nfs4.h> 357961SNatalie.Li@Sun.COM #include <sys/kiconv.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef __cplusplus 380Sstevel@tonic-gate extern "C" { 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * nfs pseudo flavor number is owned by IANA. Need to make sure the 430Sstevel@tonic-gate * Solaris specific NFS_FLAVOR_NOMAP number will not overlap with any 440Sstevel@tonic-gate * new IANA defined pseudo flavor numbers. The chance for the overlap 450Sstevel@tonic-gate * is very small since the growth of new flavor numbers is expected 460Sstevel@tonic-gate * to be limited. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate #define NFS_FLAVOR_NOMAP 999999 /* no nfs flavor mapping */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 512060Sms193421 * As duplicate flavors can be passed into exportfs in the arguments, we 522060Sms193421 * allocate a cleaned up array with non duplicate flavors on the stack. 532060Sms193421 * So we need to know how much to allocate. 542060Sms193421 */ 552060Sms193421 #define MAX_FLAVORS 6 /* none, sys, dh, krb5, krb5i krb5p */ 562060Sms193421 572060Sms193421 /* 580Sstevel@tonic-gate * Note: exported_lock is currently used to ensure the integrity of 590Sstevel@tonic-gate * the secinfo fields. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate struct secinfo { 620Sstevel@tonic-gate seconfig_t s_secinfo; /* /etc/nfssec.conf entry */ 630Sstevel@tonic-gate unsigned int s_flags; /* flags (see below) */ 642060Sms193421 int32_t s_refcnt; /* reference count for tracking */ 650Sstevel@tonic-gate /* how many children (self included) */ 660Sstevel@tonic-gate /* use this flavor. */ 670Sstevel@tonic-gate int s_window; /* window */ 687961SNatalie.Li@Sun.COM uint_t s_rootid; /* UID to use for authorized roots */ 690Sstevel@tonic-gate int s_rootcnt; /* count of root names */ 700Sstevel@tonic-gate caddr_t *s_rootnames; /* array of root names */ 710Sstevel@tonic-gate /* they are strings for AUTH_DES and */ 720Sstevel@tonic-gate /* rpc_gss_principal_t for RPCSEC_GSS */ 730Sstevel@tonic-gate }; 740Sstevel@tonic-gate 750Sstevel@tonic-gate #ifdef _SYSCALL32 760Sstevel@tonic-gate struct secinfo32 { 770Sstevel@tonic-gate seconfig32_t s_secinfo; /* /etc/nfssec.conf entry */ 780Sstevel@tonic-gate uint32_t s_flags; /* flags (see below) */ 792060Sms193421 int32_t s_refcnt; /* reference count for tracking */ 800Sstevel@tonic-gate /* how many children (self included) */ 810Sstevel@tonic-gate /* use this flavor. */ 820Sstevel@tonic-gate int32_t s_window; /* window */ 837961SNatalie.Li@Sun.COM uint32_t s_rootid; /* UID to use for authorized roots */ 840Sstevel@tonic-gate int32_t s_rootcnt; /* count of root names */ 850Sstevel@tonic-gate caddr32_t s_rootnames; /* array of root names */ 860Sstevel@tonic-gate /* they are strings for AUTH_DES and */ 870Sstevel@tonic-gate /* rpc_gss_principal_t for RPCSEC_GSS */ 880Sstevel@tonic-gate }; 890Sstevel@tonic-gate #endif /* _SYSCALL32 */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * security negotiation related 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate 950Sstevel@tonic-gate #define SEC_QUERY 0x01 /* query sec modes */ 960Sstevel@tonic-gate 970Sstevel@tonic-gate struct sec_ol { 980Sstevel@tonic-gate int sec_flags; /* security nego flags */ 990Sstevel@tonic-gate uint_t sec_index; /* index into sec flavor array */ 1000Sstevel@tonic-gate }; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * Per-mode flags (secinfo.s_flags) 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate #define M_RO 0x01 /* exported ro to all */ 1060Sstevel@tonic-gate #define M_ROL 0x02 /* exported ro to all listed */ 1070Sstevel@tonic-gate #define M_RW 0x04 /* exported rw to all */ 1080Sstevel@tonic-gate #define M_RWL 0x08 /* exported ro to all listed */ 1090Sstevel@tonic-gate #define M_ROOT 0x10 /* root list is defined */ 1100Sstevel@tonic-gate #define M_4SEC_EXPORTED 0x20 /* this is an explicitly shared flavor */ 1117961SNatalie.Li@Sun.COM #define M_NONE 0x40 /* none list is defined */ 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* invalid secinfo reference count */ 1140Sstevel@tonic-gate #define SEC_REF_INVALID(p) ((p)->s_refcnt < 1) 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* last secinfo reference */ 1170Sstevel@tonic-gate #define SEC_REF_LAST(p) ((p)->s_refcnt == 1) 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate /* sec flavor explicitly shared for the exported node */ 1200Sstevel@tonic-gate #define SEC_REF_EXPORTED(p) ((p)->s_flags & M_4SEC_EXPORTED) 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* the only reference count left is for referring itself */ 1230Sstevel@tonic-gate #define SEC_REF_SELF(p) (SEC_REF_LAST(p) && SEC_REF_EXPORTED(p)) 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* 1260Sstevel@tonic-gate * The export information passed to exportfs() (Version 2) 1270Sstevel@tonic-gate */ 1280Sstevel@tonic-gate #define EX_CURRENT_VERSION 2 /* current version of exportdata struct */ 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate struct exportdata { 1310Sstevel@tonic-gate int ex_version; /* structure version */ 1320Sstevel@tonic-gate char *ex_path; /* exported path */ 1330Sstevel@tonic-gate size_t ex_pathlen; /* path length */ 1340Sstevel@tonic-gate int ex_flags; /* flags */ 1350Sstevel@tonic-gate unsigned int ex_anon; /* uid for unauthenticated requests */ 1360Sstevel@tonic-gate int ex_seccnt; /* count of security modes */ 1370Sstevel@tonic-gate struct secinfo *ex_secinfo; /* security mode info */ 1380Sstevel@tonic-gate char *ex_index; /* index file for public filesystem */ 1390Sstevel@tonic-gate char *ex_log_buffer; /* path to logging buffer file */ 1400Sstevel@tonic-gate size_t ex_log_bufferlen; /* buffer file path len */ 1410Sstevel@tonic-gate char *ex_tag; /* tag used to identify log config */ 1420Sstevel@tonic-gate size_t ex_taglen; /* tag length */ 1430Sstevel@tonic-gate }; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate #ifdef _SYSCALL32 1460Sstevel@tonic-gate struct exportdata32 { 1470Sstevel@tonic-gate int32_t ex_version; /* structure version */ 1480Sstevel@tonic-gate caddr32_t ex_path; /* exported path */ 1490Sstevel@tonic-gate int32_t ex_pathlen; /* path length */ 1500Sstevel@tonic-gate int32_t ex_flags; /* flags */ 1510Sstevel@tonic-gate uint32_t ex_anon; /* uid for unauthenticated requests */ 1520Sstevel@tonic-gate int32_t ex_seccnt; /* count of security modes */ 1530Sstevel@tonic-gate caddr32_t ex_secinfo; /* security mode info */ 1540Sstevel@tonic-gate caddr32_t ex_index; /* index file for public filesystem */ 1550Sstevel@tonic-gate caddr32_t ex_log_buffer; /* path to logging buffer file */ 1560Sstevel@tonic-gate int32_t ex_log_bufferlen; /* buffer file path len */ 1570Sstevel@tonic-gate caddr32_t ex_tag; /* tag used to identify log config */ 1580Sstevel@tonic-gate int32_t ex_taglen; /* tag length */ 1590Sstevel@tonic-gate }; 1600Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* 1630Sstevel@tonic-gate * exported vfs flags. 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate #define EX_NOSUID 0x01 /* exported with unsetable set[ug]ids */ 1670Sstevel@tonic-gate #define EX_ACLOK 0x02 /* exported with maximal access if acl exists */ 1680Sstevel@tonic-gate #define EX_PUBLIC 0x04 /* exported with public filehandle */ 1690Sstevel@tonic-gate #define EX_NOSUB 0x08 /* no nfs_getfh or MCL below export point */ 1700Sstevel@tonic-gate #define EX_INDEX 0x10 /* exported with index file specified */ 1710Sstevel@tonic-gate #define EX_LOG 0x20 /* logging enabled */ 1720Sstevel@tonic-gate #define EX_LOG_ALLOPS 0x40 /* logging of all RPC operations enabled */ 1730Sstevel@tonic-gate /* by default only operations which affect */ 1740Sstevel@tonic-gate /* transaction logging are enabled */ 1750Sstevel@tonic-gate #define EX_PSEUDO 0x80 /* pseudo filesystem export */ 1760Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST 1770Sstevel@tonic-gate #define EX_VOLFH 0x100 /* XXX nfsv4 fh may expire anytime */ 1780Sstevel@tonic-gate #define EX_VOLRNM 0x200 /* XXX nfsv4 fh expire at rename */ 1790Sstevel@tonic-gate #define EX_VOLMIG 0x400 /* XXX nfsv4 fh expire at migration */ 1800Sstevel@tonic-gate #define EX_NOEXPOPEN 0x800 /* XXX nfsv4 fh no expire with open */ 1810Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */ 1820Sstevel@tonic-gate 1837961SNatalie.Li@Sun.COM #define EX_CHARMAP 0x1000 /* NFS may need a character set conversion */ 18411323SVallish.Vaidyeshwara@Sun.COM #define EX_NOACLFAB 0x2000 /* If set, NFSv2 and v3 servers doesn't */ 18511323SVallish.Vaidyeshwara@Sun.COM /* fabricate ACL for VOP_GETSECATTR OTW call */ 1867961SNatalie.Li@Sun.COM 1870Sstevel@tonic-gate #ifdef _KERNEL 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #define RPC_IDEMPOTENT 0x1 /* idempotent or not */ 1900Sstevel@tonic-gate /* 1910Sstevel@tonic-gate * Be very careful about which NFS procedures get the RPC_ALLOWANON bit. 1920Sstevel@tonic-gate * Right now, it this bit is on, we ignore the results of per NFS request 1930Sstevel@tonic-gate * access control. 1940Sstevel@tonic-gate */ 1950Sstevel@tonic-gate #define RPC_ALLOWANON 0x2 /* allow anonymous access */ 1960Sstevel@tonic-gate #define RPC_MAPRESP 0x4 /* use mapped response buffer */ 1970Sstevel@tonic-gate #define RPC_AVOIDWORK 0x8 /* do work avoidance for dups */ 1980Sstevel@tonic-gate #define RPC_PUBLICFH_OK 0x10 /* allow use of public filehandle */ 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* 2010Sstevel@tonic-gate * RPC_ALL is an or of all above bits to be used with "don't care" 2020Sstevel@tonic-gate * nfsv4 ops. The flags of an nfsv4 request is the bit-AND of the 2030Sstevel@tonic-gate * per-op flags. 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate #define RPC_ALL (RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_AVOIDWORK|RPC_PUBLICFH_OK) 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST 2090Sstevel@tonic-gate struct ex_vol_rename { 2100Sstevel@tonic-gate nfs_fh4_fmt_t vrn_fh_fmt; 2110Sstevel@tonic-gate struct ex_vol_rename *vrn_next; 2120Sstevel@tonic-gate }; 2130Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */ 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate /* 21612081SThomas.Haynes@Sun.COM * An auth cache entry can exist in 4 active states, with the inactive 21712081SThomas.Haynes@Sun.COM * state being indicated by no entry in the cache. 21812081SThomas.Haynes@Sun.COM * 21912081SThomas.Haynes@Sun.COM * A FRESH entry is one which is either new or has been refreshed at 22012081SThomas.Haynes@Sun.COM * least once. 22112081SThomas.Haynes@Sun.COM * 22212081SThomas.Haynes@Sun.COM * A STALE entry is one which has been detected to be too old. The 22312081SThomas.Haynes@Sun.COM * transistion from FRESH to STALE prevents multiple threads from 22412081SThomas.Haynes@Sun.COM * submitting refresh requests. 22512081SThomas.Haynes@Sun.COM * 22612081SThomas.Haynes@Sun.COM * A REFRESHING entry is one which is actively engaging the user land 22712081SThomas.Haynes@Sun.COM * mountd code to re-authenticate the cache entry. 22812081SThomas.Haynes@Sun.COM * 22912081SThomas.Haynes@Sun.COM * An INVALID entry was one which was either STALE or REFRESHING 23012081SThomas.Haynes@Sun.COM * and was deleted out of the encapsulating exi. Since we can't 23112081SThomas.Haynes@Sun.COM * delete it yet, we mark it as INVALID, which lets the refreshq 23212081SThomas.Haynes@Sun.COM * know not to work on it. 23312081SThomas.Haynes@Sun.COM * 23412081SThomas.Haynes@Sun.COM * Note that the auth state of the entry is always valid, even if the 23512081SThomas.Haynes@Sun.COM * entry is STALE. Just as you can eat stale bread, you can consume 23612081SThomas.Haynes@Sun.COM * a stale cache entry. The only time the contents change could be 23712081SThomas.Haynes@Sun.COM * during the transistion from REFRESHING to FRESH. 23812081SThomas.Haynes@Sun.COM */ 23912081SThomas.Haynes@Sun.COM typedef enum auth_state { 24012081SThomas.Haynes@Sun.COM NFS_AUTH_FRESH, 24112081SThomas.Haynes@Sun.COM NFS_AUTH_STALE, 24212081SThomas.Haynes@Sun.COM NFS_AUTH_REFRESHING, 24312081SThomas.Haynes@Sun.COM NFS_AUTH_INVALID 24412081SThomas.Haynes@Sun.COM } auth_state_t; 24512081SThomas.Haynes@Sun.COM 24612081SThomas.Haynes@Sun.COM /* 2470Sstevel@tonic-gate * An authorization cache entry 24812081SThomas.Haynes@Sun.COM * 24912081SThomas.Haynes@Sun.COM * Either the state in auth_state will protect the 25012081SThomas.Haynes@Sun.COM * contents or auth_lock must be held. 2510Sstevel@tonic-gate */ 2520Sstevel@tonic-gate struct auth_cache { 2530Sstevel@tonic-gate struct netbuf auth_addr; 2540Sstevel@tonic-gate int auth_flavor; 2550Sstevel@tonic-gate int auth_access; 2560Sstevel@tonic-gate time_t auth_time; 25712081SThomas.Haynes@Sun.COM time_t auth_freshness; 25812081SThomas.Haynes@Sun.COM auth_state_t auth_state; 25912081SThomas.Haynes@Sun.COM char *auth_netid; 26012081SThomas.Haynes@Sun.COM kmutex_t auth_lock; 2610Sstevel@tonic-gate struct auth_cache *auth_next; 2620Sstevel@tonic-gate }; 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate #define AUTH_TABLESIZE 32 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * Structure containing log file meta-data. 2680Sstevel@tonic-gate */ 2690Sstevel@tonic-gate struct log_file { 2700Sstevel@tonic-gate unsigned int lf_flags; /* flags (see below) */ 2710Sstevel@tonic-gate int lf_writers; /* outstanding writers */ 2720Sstevel@tonic-gate int lf_refcnt; /* references to this struct */ 2730Sstevel@tonic-gate caddr_t lf_path; /* buffer file location */ 2740Sstevel@tonic-gate vnode_t *lf_vp; /* vnode for the buffer file */ 2750Sstevel@tonic-gate kmutex_t lf_lock; 2760Sstevel@tonic-gate kcondvar_t lf_cv_waiters; 2770Sstevel@tonic-gate }; 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate /* 2800Sstevel@tonic-gate * log_file and log_buffer flags. 2810Sstevel@tonic-gate */ 2820Sstevel@tonic-gate #define L_WAITING 0x01 /* flush of in-core data to stable */ 2830Sstevel@tonic-gate /* storage in progress */ 2840Sstevel@tonic-gate #define L_PRINTED 0x02 /* error message printed to console */ 2850Sstevel@tonic-gate #define L_ERROR 0x04 /* error condition detected */ 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate /* 2880Sstevel@tonic-gate * The logging buffer information. 2890Sstevel@tonic-gate * This structure may be shared by multiple exportinfo structures, 2900Sstevel@tonic-gate * if they share the same buffer file. 2910Sstevel@tonic-gate * This structure contains the basic information about the buffer, such 2920Sstevel@tonic-gate * as it's location in the filesystem. 2930Sstevel@tonic-gate * 2940Sstevel@tonic-gate * 'lb_lock' protects all the fields in this structure except for 'lb_path', 2950Sstevel@tonic-gate * and 'lb_next'. 2960Sstevel@tonic-gate * 'lb_path' is a write-once/read-many field which needs no locking, it is 2970Sstevel@tonic-gate * set before the structure is linked to any exportinfo structure. 2980Sstevel@tonic-gate * 'lb_next' is protected by the log_buffer_list_lock. 2990Sstevel@tonic-gate */ 3000Sstevel@tonic-gate struct log_buffer { 3010Sstevel@tonic-gate unsigned int lb_flags; /* L_ONLIST set? */ 3020Sstevel@tonic-gate int lb_refcnt; /* references to this struct */ 3030Sstevel@tonic-gate unsigned int lb_rec_id; /* used to generate unique id */ 3040Sstevel@tonic-gate caddr_t lb_path; /* buffer file pathname */ 3050Sstevel@tonic-gate struct log_file *lb_logfile; /* points to log_file structure */ 3060Sstevel@tonic-gate kmutex_t lb_lock; 3070Sstevel@tonic-gate struct log_buffer *lb_next; 3080Sstevel@tonic-gate kcondvar_t lb_cv_waiters; 3090Sstevel@tonic-gate caddr_t lb_records; /* linked list of records to write */ 3100Sstevel@tonic-gate int lb_num_recs; /* # of records to write */ 3110Sstevel@tonic-gate ssize_t lb_size_queued; /* number of bytes queued for write */ 3120Sstevel@tonic-gate }; 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate #define LOG_BUFFER_HOLD(lbp) { \ 3150Sstevel@tonic-gate mutex_enter(&(lbp)->lb_lock); \ 3160Sstevel@tonic-gate (lbp)->lb_refcnt++; \ 3170Sstevel@tonic-gate mutex_exit(&(lbp)->lb_lock); \ 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate #define LOG_BUFFER_RELE(lbp) { \ 3210Sstevel@tonic-gate log_buffer_rele(lbp); \ 3220Sstevel@tonic-gate } 3230Sstevel@tonic-gate 3247961SNatalie.Li@Sun.COM /* 3257961SNatalie.Li@Sun.COM * Structure for character set conversion mapping based on client address. 3267961SNatalie.Li@Sun.COM */ 3277961SNatalie.Li@Sun.COM struct charset_cache { 3287961SNatalie.Li@Sun.COM struct charset_cache *next; 3297961SNatalie.Li@Sun.COM kiconv_t inbound; 3307961SNatalie.Li@Sun.COM kiconv_t outbound; 3317961SNatalie.Li@Sun.COM struct sockaddr client_addr; 3327961SNatalie.Li@Sun.COM }; 3337961SNatalie.Li@Sun.COM 3346236Spf199842 /* Forward declarations */ 3356236Spf199842 struct exportinfo; 3366236Spf199842 struct exp_visible; 33711291SRobert.Thurlow@Sun.COM struct svc_req; 3386236Spf199842 3396236Spf199842 /* 3406236Spf199842 * Treenodes are used to build tree representing every node which is part 34111796SPavel.Filipensky@Sun.COM * of nfs server pseudo namespace. They are connected with both exportinfo 34211796SPavel.Filipensky@Sun.COM * and exp_visible struct. They were introduced to avoid lookup of ".." 34311796SPavel.Filipensky@Sun.COM * in the underlying file system during unshare, which was failing if the 34411796SPavel.Filipensky@Sun.COM * file system was forcibly unmounted or if the directory was removed. 34511796SPavel.Filipensky@Sun.COM * One exp_visible_t can be shared via several treenode_t, i.e. 34611796SPavel.Filipensky@Sun.COM * different tree_vis can point to the same exp_visible_t. 34711796SPavel.Filipensky@Sun.COM * This will happen if some directory is on two different shared paths: 34811796SPavel.Filipensky@Sun.COM * E.g. after share /tmp/a/b1 and share /tmp/a/b2 there will be two treenodes 34911796SPavel.Filipensky@Sun.COM * corresponding to /tmp/a and both will have same value in tree_vis. 3506236Spf199842 * 3516236Spf199842 * 3526236Spf199842 * 3536236Spf199842 * NEW DATA STRUCT ORIGINAL DATA STRUCT 3546236Spf199842 * 3556236Spf199842 * ns_root +---+ +----------+ 3566236Spf199842 * | / | |PSEUDO EXP|-->+---+ +---+ +---+ 3576236Spf199842 * +---+--------- ----+----------+ | a |-->| k |-->| b | 3586236Spf199842 * /\ +---+ +---+ +---+ 3596236Spf199842 * / \ . . . 3606236Spf199842 * +---+...\......... ..................... . . 3616236Spf199842 * *| a | \ +----------+ . . 3626236Spf199842 * +---+-----\------- ----|REAL EXP a| . . 3636236Spf199842 * / \ +----------+ . . 3646236Spf199842 * / +===+... ............................. . 3656236Spf199842 * / *| k | +----------+ . 3666236Spf199842 * / +===+--- ----|REAL EXP k| . 3676236Spf199842 * / +----------+ . 3686236Spf199842 * +===+................ ..................................... 3696236Spf199842 * *| b | +----------+ 3706236Spf199842 * +===+---------------- ----|REAL EXP b|-->+---+ 3716236Spf199842 * \ +----------+ | d | 3726236Spf199842 * +===+............. ...................+---+ 3736236Spf199842 * | d | +----------+ 3746236Spf199842 * +===+------------- ----|PSEUDO EXP|-->+---+ +---+ 3756236Spf199842 * / +----------+ | e |-->| g | 3766236Spf199842 * +---+................. ...................+---+ +---+ 3776236Spf199842 * | e | . 3786236Spf199842 * +---+ . 3796236Spf199842 * \ . 3806236Spf199842 * +---+.............. ............................ 3816236Spf199842 * *| g | +----------+ 3826236Spf199842 * +---+-------------- ----|REAL EXP g| 3836236Spf199842 * +----------+ 3846236Spf199842 * 3856236Spf199842 * 3866236Spf199842 * 3876236Spf199842 * +===+ +---+ +---+ 3886236Spf199842 * | b |..mountpoint | e |..directory/file *| a |..node is shared 3896236Spf199842 * +===+ (VROOT) +---+ +---+ 3906236Spf199842 * 3916236Spf199842 * 3926236Spf199842 * Bi-directional interconnect: 3936236Spf199842 * treenode_t::tree_exi --------- exportinfo_t::exi_tree 39411796SPavel.Filipensky@Sun.COM * One-way direction connection: 39511796SPavel.Filipensky@Sun.COM * treenode_t::tree_vis .........> exp_visible_t 3966236Spf199842 */ 3979654SPavel.Filipensky@Sun.COM /* Access to treenode_t is under protection of exported_lock RW_LOCK */ 3986236Spf199842 typedef struct treenode { 3996236Spf199842 /* support for generic n-ary trees */ 4006236Spf199842 struct treenode *tree_parent; 4016236Spf199842 struct treenode *tree_child_first; 4026236Spf199842 struct treenode *tree_sibling; /* next sibling */ 4036236Spf199842 /* private, nfs specific part */ 4046236Spf199842 struct exportinfo *tree_exi; 4056236Spf199842 struct exp_visible *tree_vis; 4066236Spf199842 } treenode_t; 4076236Spf199842 4086236Spf199842 /* 4096236Spf199842 * TREE_ROOT checks if the node corresponds to a filesystem root 4106236Spf199842 * TREE_EXPORTED checks if the node is explicitly shared 4116236Spf199842 */ 4126236Spf199842 4136236Spf199842 #define TREE_ROOT(t) \ 4146236Spf199842 ((t)->tree_exi && (t)->tree_exi->exi_vp->v_flag & VROOT) 4156236Spf199842 4166236Spf199842 #define TREE_EXPORTED(t) \ 4176236Spf199842 ((t)->tree_exi && !PSEUDO((t)->tree_exi)) 4186236Spf199842 4196236Spf199842 /* Root of nfs pseudo namespace */ 4209654SPavel.Filipensky@Sun.COM extern treenode_t *ns_root; 4216236Spf199842 422*12679SPavel.Filipensky@Sun.COM #define EXPTABLESIZE 256 423*12679SPavel.Filipensky@Sun.COM 424*12679SPavel.Filipensky@Sun.COM struct exp_hash { 425*12679SPavel.Filipensky@Sun.COM struct exportinfo *prev; /* ptr to the previous exportinfo */ 426*12679SPavel.Filipensky@Sun.COM struct exportinfo *next; /* ptr to the next exportinfo */ 427*12679SPavel.Filipensky@Sun.COM struct exportinfo **bckt; /* backpointer to the hash bucket */ 428*12679SPavel.Filipensky@Sun.COM }; 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * A node associated with an export entry on the 4320Sstevel@tonic-gate * list of exported filesystems. 4330Sstevel@tonic-gate * 4340Sstevel@tonic-gate * exi_count+exi_lock protects an individual exportinfo from being freed 4350Sstevel@tonic-gate * when in use. 43612081SThomas.Haynes@Sun.COM * 4370Sstevel@tonic-gate * You must have the writer lock on exported_lock to add/delete an exportinfo 4380Sstevel@tonic-gate * structure to/from the list. 4390Sstevel@tonic-gate * 4400Sstevel@tonic-gate * exi_volatile_dev maps to VSW_VOLATILEDEV. It means that the 4410Sstevel@tonic-gate * underlying fs devno can change on each mount. When set, the server 4420Sstevel@tonic-gate * should not use va_fsid for a GETATTR(FATTR4_FSID) reply. It must 4430Sstevel@tonic-gate * use exi_fsid because it is guaranteed to be persistent. This isn't 4440Sstevel@tonic-gate * in any way related to NFS4 volatile filehandles. 4450Sstevel@tonic-gate */ 4460Sstevel@tonic-gate struct exportinfo { 4470Sstevel@tonic-gate struct exportdata exi_export; 4480Sstevel@tonic-gate fsid_t exi_fsid; 4490Sstevel@tonic-gate struct fid exi_fid; 450*12679SPavel.Filipensky@Sun.COM struct exp_hash fid_hash; 451*12679SPavel.Filipensky@Sun.COM struct exp_hash path_hash; 4526236Spf199842 struct treenode *exi_tree; 4530Sstevel@tonic-gate fhandle_t exi_fh; 4540Sstevel@tonic-gate krwlock_t exi_cache_lock; 4550Sstevel@tonic-gate kmutex_t exi_lock; 4560Sstevel@tonic-gate uint_t exi_count; 4570Sstevel@tonic-gate vnode_t *exi_vp; 4580Sstevel@tonic-gate vnode_t *exi_dvp; 4590Sstevel@tonic-gate struct auth_cache *exi_cache[AUTH_TABLESIZE]; 4600Sstevel@tonic-gate struct log_buffer *exi_logbuffer; 4610Sstevel@tonic-gate struct exp_visible *exi_visible; 4627961SNatalie.Li@Sun.COM struct charset_cache *exi_charset; 4630Sstevel@tonic-gate unsigned exi_volatile_dev:1; 46411291SRobert.Thurlow@Sun.COM unsigned exi_moved:1; 4650Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST 4660Sstevel@tonic-gate uint32_t exi_volatile_id; 4670Sstevel@tonic-gate struct ex_vol_rename *exi_vol_rename; 4680Sstevel@tonic-gate kmutex_t exi_vol_rename_lock; 4690Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */ 4700Sstevel@tonic-gate }; 4710Sstevel@tonic-gate 4724871Sjasmith typedef struct exportinfo exportinfo_t; 4734871Sjasmith typedef struct exportdata exportdata_t; 4744871Sjasmith typedef struct secinfo secinfo_t; 4754871Sjasmith 4760Sstevel@tonic-gate /* 4770Sstevel@tonic-gate * exp_visible is a visible list per filesystem. It is for filesystems 4780Sstevel@tonic-gate * that may need a limited view of its contents. A pseudo export and 4790Sstevel@tonic-gate * a real export at the mount point (VROOT) which has a subtree shared 4800Sstevel@tonic-gate * has a visible list. 4810Sstevel@tonic-gate * 4820Sstevel@tonic-gate * The exi_visible field is NULL for normal, non=pseudo filesystems 4830Sstevel@tonic-gate * which do not have any subtree exported. If the field is non-null, 4840Sstevel@tonic-gate * it points to a list of visible entries, identified by vis_fid and/or 4850Sstevel@tonic-gate * vis_ino. The presence of a "visible" list means that if this export 4860Sstevel@tonic-gate * can only have a limited view, it can only view the entries in the 4870Sstevel@tonic-gate * exp_visible list. The directories in the fid list comprise paths that 4880Sstevel@tonic-gate * lead to exported directories. 4890Sstevel@tonic-gate * 4900Sstevel@tonic-gate * The vis_count field records the number of paths in this filesystem 4910Sstevel@tonic-gate * that use this directory. The vis_exported field is non-zero if the 4920Sstevel@tonic-gate * entry is an exported directory (leaf node). 4939654SPavel.Filipensky@Sun.COM * 4949654SPavel.Filipensky@Sun.COM * exp_visible itself is not reference counted. Each exp_visible is 4959654SPavel.Filipensky@Sun.COM * referenced twice: 4969654SPavel.Filipensky@Sun.COM * 1) from treenode::tree_vis 4979654SPavel.Filipensky@Sun.COM * 2) linked from exportinfo::exi_visible 4989654SPavel.Filipensky@Sun.COM * The 'owner' of exp_visible is the exportinfo structure. exp_visible should 4999654SPavel.Filipensky@Sun.COM * be always freed only from exportinfo_t, never from treenode::tree_vis. 5000Sstevel@tonic-gate */ 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate struct exp_visible { 5030Sstevel@tonic-gate vnode_t *vis_vp; 5040Sstevel@tonic-gate fid_t vis_fid; 5050Sstevel@tonic-gate u_longlong_t vis_ino; 5060Sstevel@tonic-gate int vis_count; 5070Sstevel@tonic-gate int vis_exported; 5080Sstevel@tonic-gate struct exp_visible *vis_next; 5094871Sjasmith struct secinfo *vis_secinfo; 5104871Sjasmith int vis_seccnt; 5110Sstevel@tonic-gate }; 5124871Sjasmith typedef struct exp_visible exp_visible_t; 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate #define PSEUDO(exi) ((exi)->exi_export.ex_flags & EX_PSEUDO) 515*12679SPavel.Filipensky@Sun.COM #define EXP_LINKED(exi) ((exi)->fid_hash.bckt != NULL) 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate #define EQFSID(fsidp1, fsidp2) \ 5180Sstevel@tonic-gate (((fsidp1)->val[0] == (fsidp2)->val[0]) && \ 5190Sstevel@tonic-gate ((fsidp1)->val[1] == (fsidp2)->val[1])) 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate #define EQFID(fidp1, fidp2) \ 5220Sstevel@tonic-gate ((fidp1)->fid_len == (fidp2)->fid_len && \ 523806Sek110237 bcmp((char *)(fidp1)->fid_data, (char *)(fidp2)->fid_data, \ 5240Sstevel@tonic-gate (uint_t)(fidp1)->fid_len) == 0) 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate #define exportmatch(exi, fsid, fid) \ 5270Sstevel@tonic-gate (EQFSID(&(exi)->exi_fsid, (fsid)) && EQFID(&(exi)->exi_fid, (fid))) 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate /* 5300Sstevel@tonic-gate * Returns true iff exported filesystem is read-only to the given host. 5310Sstevel@tonic-gate * 5320Sstevel@tonic-gate * Note: this macro should be as fast as possible since it's called 5330Sstevel@tonic-gate * on each NFS modification request. 5340Sstevel@tonic-gate */ 5350Sstevel@tonic-gate #define rdonly(exi, req) (nfsauth_access(exi, req) & NFSAUTH_RO) 5360Sstevel@tonic-gate #define rdonly4(exi, vp, req) \ 5370Sstevel@tonic-gate (vn_is_readonly(vp) || \ 5380Sstevel@tonic-gate (nfsauth4_access(exi, vp, req) & (NFSAUTH_RO | NFSAUTH_LIMITED))) 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate extern int nfsauth4_access(struct exportinfo *, vnode_t *, 5410Sstevel@tonic-gate struct svc_req *); 5420Sstevel@tonic-gate extern int nfsauth4_secinfo_access(struct exportinfo *, 5430Sstevel@tonic-gate struct svc_req *, int, int); 5440Sstevel@tonic-gate extern int nfs_fhbcmp(char *, char *, int); 5450Sstevel@tonic-gate extern int nfs_exportinit(void); 5460Sstevel@tonic-gate extern void nfs_exportfini(void); 5470Sstevel@tonic-gate extern int chk_clnt_sec(struct exportinfo *, struct svc_req *req); 5480Sstevel@tonic-gate extern int makefh(fhandle_t *, struct vnode *, struct exportinfo *); 5490Sstevel@tonic-gate extern int makefh_ol(fhandle_t *, struct exportinfo *, uint_t); 5500Sstevel@tonic-gate extern int makefh3(nfs_fh3 *, struct vnode *, struct exportinfo *); 5510Sstevel@tonic-gate extern int makefh3_ol(nfs_fh3 *, struct exportinfo *, uint_t); 5520Sstevel@tonic-gate extern vnode_t *nfs_fhtovp(fhandle_t *, struct exportinfo *); 5530Sstevel@tonic-gate extern vnode_t *nfs3_fhtovp(nfs_fh3 *, struct exportinfo *); 5540Sstevel@tonic-gate extern vnode_t *lm_fhtovp(fhandle_t *fh); 5550Sstevel@tonic-gate extern vnode_t *lm_nfs3_fhtovp(nfs_fh3 *fh); 5560Sstevel@tonic-gate extern struct exportinfo *checkexport(fsid_t *, struct fid *); 5570Sstevel@tonic-gate extern struct exportinfo *checkexport4(fsid_t *, struct fid *, vnode_t *vp); 55812081SThomas.Haynes@Sun.COM extern void exi_hold(struct exportinfo *); 5590Sstevel@tonic-gate extern void exi_rele(struct exportinfo *); 5600Sstevel@tonic-gate extern struct exportinfo *nfs_vptoexi(vnode_t *, vnode_t *, cred_t *, int *, 5610Sstevel@tonic-gate int *, bool_t); 5620Sstevel@tonic-gate extern int nfs_check_vpexi(vnode_t *, vnode_t *, cred_t *, 5630Sstevel@tonic-gate struct exportinfo **); 5640Sstevel@tonic-gate extern void export_link(struct exportinfo *); 565*12679SPavel.Filipensky@Sun.COM extern void export_unlink(struct exportinfo *); 5660Sstevel@tonic-gate extern vnode_t *untraverse(vnode_t *); 56711291SRobert.Thurlow@Sun.COM extern int vn_is_nfs_reparse(vnode_t *, cred_t *); 56811291SRobert.Thurlow@Sun.COM extern int client_is_downrev(struct svc_req *); 56911291SRobert.Thurlow@Sun.COM extern char *build_symlink(vnode_t *, cred_t *, size_t *); 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate /* 5720Sstevel@tonic-gate * Functions that handle the NFSv4 server namespace 5730Sstevel@tonic-gate */ 57411796SPavel.Filipensky@Sun.COM extern exportinfo_t *vis2exi(treenode_t *); 5750Sstevel@tonic-gate extern int treeclimb_export(struct exportinfo *); 5766236Spf199842 extern void treeclimb_unexport(struct exportinfo *); 5770Sstevel@tonic-gate extern int nfs_visible(struct exportinfo *, vnode_t *, int *); 5780Sstevel@tonic-gate extern int nfs_visible_inode(struct exportinfo *, ino64_t, int *); 5790Sstevel@tonic-gate extern int has_visible(struct exportinfo *, vnode_t *); 5800Sstevel@tonic-gate extern void free_visible(struct exp_visible *); 5810Sstevel@tonic-gate extern int nfs_exported(struct exportinfo *, vnode_t *); 582*12679SPavel.Filipensky@Sun.COM extern struct exportinfo *pseudo_exportfs(vnode_t *, fid_t *, 583*12679SPavel.Filipensky@Sun.COM struct exp_visible *, struct exportdata *); 5840Sstevel@tonic-gate extern int vop_fid_pseudo(vnode_t *, fid_t *fidp); 5850Sstevel@tonic-gate extern int nfs4_vget_pseudo(struct exportinfo *, vnode_t **, fid_t *); 5860Sstevel@tonic-gate /* 5870Sstevel@tonic-gate * Functions that handle the NFSv4 server namespace security flavors 5880Sstevel@tonic-gate * information. 5890Sstevel@tonic-gate */ 5900Sstevel@tonic-gate extern void srv_secinfo_exp2pseu(struct exportdata *, struct exportdata *); 5914871Sjasmith extern void srv_secinfo_list_free(struct secinfo *, int); 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate /* 5940Sstevel@tonic-gate * "public" and default (root) location for public filehandle 5950Sstevel@tonic-gate */ 5960Sstevel@tonic-gate extern struct exportinfo *exi_public, *exi_root; 5970Sstevel@tonic-gate extern fhandle_t nullfh2; /* for comparing V2 filehandles */ 5980Sstevel@tonic-gate extern krwlock_t exported_lock; 5990Sstevel@tonic-gate extern struct exportinfo *exptable[]; 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /* 6020Sstevel@tonic-gate * Two macros for identifying public filehandles. 6030Sstevel@tonic-gate * A v2 public filehandle is 32 zero bytes. 6040Sstevel@tonic-gate * A v3 public filehandle is zero length. 6050Sstevel@tonic-gate */ 6060Sstevel@tonic-gate #define PUBLIC_FH2(fh) \ 6070Sstevel@tonic-gate ((fh)->fh_fsid.val[1] == 0 && \ 6080Sstevel@tonic-gate bcmp((fh), &nullfh2, sizeof (fhandle_t)) == 0) 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate #define PUBLIC_FH3(fh) \ 6110Sstevel@tonic-gate ((fh)->fh3_length == 0) 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate extern int makefh4(nfs_fh4 *, struct vnode *, struct exportinfo *); 6140Sstevel@tonic-gate extern vnode_t *nfs4_fhtovp(nfs_fh4 *, struct exportinfo *, nfsstat4 *); 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate #endif /* _KERNEL */ 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate #ifdef __cplusplus 6190Sstevel@tonic-gate } 6200Sstevel@tonic-gate #endif 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate #endif /* _NFS_EXPORT_H */ 623