17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51cc55349Srmesta * Common Development and Distribution License (the "License"). 61cc55349Srmesta * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*3f238301SPavel Filipensky * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _NFS_EXPORT_H 307c478bd9Sstevel@tonic-gate #define _NFS_EXPORT_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <nfs/nfs_sec.h> 331cc55349Srmesta #include <nfs/auth.h> 347c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 357c478bd9Sstevel@tonic-gate #include <nfs/nfs4.h> 36b89a8333Snatalie li - Sun Microsystems - Irvine United States #include <sys/kiconv.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * nfs pseudo flavor number is owned by IANA. Need to make sure the 447c478bd9Sstevel@tonic-gate * Solaris specific NFS_FLAVOR_NOMAP number will not overlap with any 457c478bd9Sstevel@tonic-gate * new IANA defined pseudo flavor numbers. The chance for the overlap 467c478bd9Sstevel@tonic-gate * is very small since the growth of new flavor numbers is expected 477c478bd9Sstevel@tonic-gate * to be limited. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate #define NFS_FLAVOR_NOMAP 999999 /* no nfs flavor mapping */ 507c478bd9Sstevel@tonic-gate 518a429e7eSms /* 528a429e7eSms * As duplicate flavors can be passed into exportfs in the arguments, we 538a429e7eSms * allocate a cleaned up array with non duplicate flavors on the stack. 548a429e7eSms * So we need to know how much to allocate. 558a429e7eSms */ 568a429e7eSms #define MAX_FLAVORS 6 /* none, sys, dh, krb5, krb5i krb5p */ 578a429e7eSms 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * Note: exported_lock is currently used to ensure the integrity of 607c478bd9Sstevel@tonic-gate * the secinfo fields. 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate struct secinfo { 637c478bd9Sstevel@tonic-gate seconfig_t s_secinfo; /* /etc/nfssec.conf entry */ 647c478bd9Sstevel@tonic-gate unsigned int s_flags; /* flags (see below) */ 658a429e7eSms int32_t s_refcnt; /* reference count for tracking */ 667c478bd9Sstevel@tonic-gate /* how many children (self included) */ 677c478bd9Sstevel@tonic-gate /* use this flavor. */ 687c478bd9Sstevel@tonic-gate int s_window; /* window */ 69b89a8333Snatalie li - Sun Microsystems - Irvine United States uint_t s_rootid; /* UID to use for authorized roots */ 707c478bd9Sstevel@tonic-gate int s_rootcnt; /* count of root names */ 717c478bd9Sstevel@tonic-gate caddr_t *s_rootnames; /* array of root names */ 727c478bd9Sstevel@tonic-gate /* they are strings for AUTH_DES and */ 737c478bd9Sstevel@tonic-gate /* rpc_gss_principal_t for RPCSEC_GSS */ 747c478bd9Sstevel@tonic-gate }; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 777c478bd9Sstevel@tonic-gate struct secinfo32 { 787c478bd9Sstevel@tonic-gate seconfig32_t s_secinfo; /* /etc/nfssec.conf entry */ 797c478bd9Sstevel@tonic-gate uint32_t s_flags; /* flags (see below) */ 808a429e7eSms int32_t s_refcnt; /* reference count for tracking */ 817c478bd9Sstevel@tonic-gate /* how many children (self included) */ 827c478bd9Sstevel@tonic-gate /* use this flavor. */ 837c478bd9Sstevel@tonic-gate int32_t s_window; /* window */ 84b89a8333Snatalie li - Sun Microsystems - Irvine United States uint32_t s_rootid; /* UID to use for authorized roots */ 857c478bd9Sstevel@tonic-gate int32_t s_rootcnt; /* count of root names */ 867c478bd9Sstevel@tonic-gate caddr32_t s_rootnames; /* array of root names */ 877c478bd9Sstevel@tonic-gate /* they are strings for AUTH_DES and */ 887c478bd9Sstevel@tonic-gate /* rpc_gss_principal_t for RPCSEC_GSS */ 897c478bd9Sstevel@tonic-gate }; 907c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * security negotiation related 947c478bd9Sstevel@tonic-gate */ 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #define SEC_QUERY 0x01 /* query sec modes */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate struct sec_ol { 997c478bd9Sstevel@tonic-gate int sec_flags; /* security nego flags */ 1007c478bd9Sstevel@tonic-gate uint_t sec_index; /* index into sec flavor array */ 1017c478bd9Sstevel@tonic-gate }; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Per-mode flags (secinfo.s_flags) 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate #define M_RO 0x01 /* exported ro to all */ 1077c478bd9Sstevel@tonic-gate #define M_ROL 0x02 /* exported ro to all listed */ 1087c478bd9Sstevel@tonic-gate #define M_RW 0x04 /* exported rw to all */ 1097c478bd9Sstevel@tonic-gate #define M_RWL 0x08 /* exported ro to all listed */ 1107c478bd9Sstevel@tonic-gate #define M_ROOT 0x10 /* root list is defined */ 1117c478bd9Sstevel@tonic-gate #define M_4SEC_EXPORTED 0x20 /* this is an explicitly shared flavor */ 112b89a8333Snatalie li - Sun Microsystems - Irvine United States #define M_NONE 0x40 /* none list is defined */ 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* invalid secinfo reference count */ 1157c478bd9Sstevel@tonic-gate #define SEC_REF_INVALID(p) ((p)->s_refcnt < 1) 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* last secinfo reference */ 1187c478bd9Sstevel@tonic-gate #define SEC_REF_LAST(p) ((p)->s_refcnt == 1) 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* sec flavor explicitly shared for the exported node */ 1217c478bd9Sstevel@tonic-gate #define SEC_REF_EXPORTED(p) ((p)->s_flags & M_4SEC_EXPORTED) 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* the only reference count left is for referring itself */ 1247c478bd9Sstevel@tonic-gate #define SEC_REF_SELF(p) (SEC_REF_LAST(p) && SEC_REF_EXPORTED(p)) 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * The export information passed to exportfs() (Version 2) 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate #define EX_CURRENT_VERSION 2 /* current version of exportdata struct */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate struct exportdata { 1327c478bd9Sstevel@tonic-gate int ex_version; /* structure version */ 1337c478bd9Sstevel@tonic-gate char *ex_path; /* exported path */ 1347c478bd9Sstevel@tonic-gate size_t ex_pathlen; /* path length */ 1357c478bd9Sstevel@tonic-gate int ex_flags; /* flags */ 1367c478bd9Sstevel@tonic-gate unsigned int ex_anon; /* uid for unauthenticated requests */ 1377c478bd9Sstevel@tonic-gate int ex_seccnt; /* count of security modes */ 1387c478bd9Sstevel@tonic-gate struct secinfo *ex_secinfo; /* security mode info */ 1397c478bd9Sstevel@tonic-gate char *ex_index; /* index file for public filesystem */ 1407c478bd9Sstevel@tonic-gate char *ex_log_buffer; /* path to logging buffer file */ 1417c478bd9Sstevel@tonic-gate size_t ex_log_bufferlen; /* buffer file path len */ 1427c478bd9Sstevel@tonic-gate char *ex_tag; /* tag used to identify log config */ 1437c478bd9Sstevel@tonic-gate size_t ex_taglen; /* tag length */ 1447c478bd9Sstevel@tonic-gate }; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 1477c478bd9Sstevel@tonic-gate struct exportdata32 { 1487c478bd9Sstevel@tonic-gate int32_t ex_version; /* structure version */ 1497c478bd9Sstevel@tonic-gate caddr32_t ex_path; /* exported path */ 1507c478bd9Sstevel@tonic-gate int32_t ex_pathlen; /* path length */ 1517c478bd9Sstevel@tonic-gate int32_t ex_flags; /* flags */ 1527c478bd9Sstevel@tonic-gate uint32_t ex_anon; /* uid for unauthenticated requests */ 1537c478bd9Sstevel@tonic-gate int32_t ex_seccnt; /* count of security modes */ 1547c478bd9Sstevel@tonic-gate caddr32_t ex_secinfo; /* security mode info */ 1557c478bd9Sstevel@tonic-gate caddr32_t ex_index; /* index file for public filesystem */ 1567c478bd9Sstevel@tonic-gate caddr32_t ex_log_buffer; /* path to logging buffer file */ 1577c478bd9Sstevel@tonic-gate int32_t ex_log_bufferlen; /* buffer file path len */ 1587c478bd9Sstevel@tonic-gate caddr32_t ex_tag; /* tag used to identify log config */ 1597c478bd9Sstevel@tonic-gate int32_t ex_taglen; /* tag length */ 1607c478bd9Sstevel@tonic-gate }; 1617c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * exported vfs flags. 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate #define EX_NOSUID 0x01 /* exported with unsetable set[ug]ids */ 1687c478bd9Sstevel@tonic-gate #define EX_ACLOK 0x02 /* exported with maximal access if acl exists */ 1697c478bd9Sstevel@tonic-gate #define EX_PUBLIC 0x04 /* exported with public filehandle */ 1707c478bd9Sstevel@tonic-gate #define EX_NOSUB 0x08 /* no nfs_getfh or MCL below export point */ 1717c478bd9Sstevel@tonic-gate #define EX_INDEX 0x10 /* exported with index file specified */ 1727c478bd9Sstevel@tonic-gate #define EX_LOG 0x20 /* logging enabled */ 1737c478bd9Sstevel@tonic-gate #define EX_LOG_ALLOPS 0x40 /* logging of all RPC operations enabled */ 1747c478bd9Sstevel@tonic-gate /* by default only operations which affect */ 1757c478bd9Sstevel@tonic-gate /* transaction logging are enabled */ 1767c478bd9Sstevel@tonic-gate #define EX_PSEUDO 0x80 /* pseudo filesystem export */ 1777c478bd9Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST 1787c478bd9Sstevel@tonic-gate #define EX_VOLFH 0x100 /* XXX nfsv4 fh may expire anytime */ 1797c478bd9Sstevel@tonic-gate #define EX_VOLRNM 0x200 /* XXX nfsv4 fh expire at rename */ 1807c478bd9Sstevel@tonic-gate #define EX_VOLMIG 0x400 /* XXX nfsv4 fh expire at migration */ 1817c478bd9Sstevel@tonic-gate #define EX_NOEXPOPEN 0x800 /* XXX nfsv4 fh no expire with open */ 1827c478bd9Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */ 1837c478bd9Sstevel@tonic-gate 184b89a8333Snatalie li - Sun Microsystems - Irvine United States #define EX_CHARMAP 0x1000 /* NFS may need a character set conversion */ 1856764e83bSVallish Vaidyeshwara #define EX_NOACLFAB 0x2000 /* If set, NFSv2 and v3 servers doesn't */ 1866764e83bSVallish Vaidyeshwara /* fabricate ACL for VOP_GETSECATTR OTW call */ 187b89a8333Snatalie li - Sun Microsystems - Irvine United States 1887c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #define RPC_IDEMPOTENT 0x1 /* idempotent or not */ 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Be very careful about which NFS procedures get the RPC_ALLOWANON bit. 1937c478bd9Sstevel@tonic-gate * Right now, it this bit is on, we ignore the results of per NFS request 1947c478bd9Sstevel@tonic-gate * access control. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate #define RPC_ALLOWANON 0x2 /* allow anonymous access */ 1977c478bd9Sstevel@tonic-gate #define RPC_MAPRESP 0x4 /* use mapped response buffer */ 1987c478bd9Sstevel@tonic-gate #define RPC_AVOIDWORK 0x8 /* do work avoidance for dups */ 1997c478bd9Sstevel@tonic-gate #define RPC_PUBLICFH_OK 0x10 /* allow use of public filehandle */ 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * RPC_ALL is an or of all above bits to be used with "don't care" 2037c478bd9Sstevel@tonic-gate * nfsv4 ops. The flags of an nfsv4 request is the bit-AND of the 2047c478bd9Sstevel@tonic-gate * per-op flags. 2057c478bd9Sstevel@tonic-gate */ 2067c478bd9Sstevel@tonic-gate #define RPC_ALL (RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_AVOIDWORK|RPC_PUBLICFH_OK) 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST 2107c478bd9Sstevel@tonic-gate struct ex_vol_rename { 2117c478bd9Sstevel@tonic-gate nfs_fh4_fmt_t vrn_fh_fmt; 2127c478bd9Sstevel@tonic-gate struct ex_vol_rename *vrn_next; 2137c478bd9Sstevel@tonic-gate }; 2147c478bd9Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */ 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate /* 2177c478bd9Sstevel@tonic-gate * An authorization cache entry 2187c478bd9Sstevel@tonic-gate */ 2197c478bd9Sstevel@tonic-gate struct auth_cache { 2207c478bd9Sstevel@tonic-gate struct netbuf auth_addr; 2217c478bd9Sstevel@tonic-gate int auth_flavor; 2227c478bd9Sstevel@tonic-gate int auth_access; 2237c478bd9Sstevel@tonic-gate time_t auth_time; 2247c478bd9Sstevel@tonic-gate struct auth_cache *auth_next; 2257c478bd9Sstevel@tonic-gate }; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate #define AUTH_TABLESIZE 32 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * Structure containing log file meta-data. 2317c478bd9Sstevel@tonic-gate */ 2327c478bd9Sstevel@tonic-gate struct log_file { 2337c478bd9Sstevel@tonic-gate unsigned int lf_flags; /* flags (see below) */ 2347c478bd9Sstevel@tonic-gate int lf_writers; /* outstanding writers */ 2357c478bd9Sstevel@tonic-gate int lf_refcnt; /* references to this struct */ 2367c478bd9Sstevel@tonic-gate caddr_t lf_path; /* buffer file location */ 2377c478bd9Sstevel@tonic-gate vnode_t *lf_vp; /* vnode for the buffer file */ 2387c478bd9Sstevel@tonic-gate kmutex_t lf_lock; 2397c478bd9Sstevel@tonic-gate kcondvar_t lf_cv_waiters; 2407c478bd9Sstevel@tonic-gate }; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* 2437c478bd9Sstevel@tonic-gate * log_file and log_buffer flags. 2447c478bd9Sstevel@tonic-gate */ 2457c478bd9Sstevel@tonic-gate #define L_WAITING 0x01 /* flush of in-core data to stable */ 2467c478bd9Sstevel@tonic-gate /* storage in progress */ 2477c478bd9Sstevel@tonic-gate #define L_PRINTED 0x02 /* error message printed to console */ 2487c478bd9Sstevel@tonic-gate #define L_ERROR 0x04 /* error condition detected */ 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate /* 2517c478bd9Sstevel@tonic-gate * The logging buffer information. 2527c478bd9Sstevel@tonic-gate * This structure may be shared by multiple exportinfo structures, 2537c478bd9Sstevel@tonic-gate * if they share the same buffer file. 2547c478bd9Sstevel@tonic-gate * This structure contains the basic information about the buffer, such 2557c478bd9Sstevel@tonic-gate * as it's location in the filesystem. 2567c478bd9Sstevel@tonic-gate * 2577c478bd9Sstevel@tonic-gate * 'lb_lock' protects all the fields in this structure except for 'lb_path', 2587c478bd9Sstevel@tonic-gate * and 'lb_next'. 2597c478bd9Sstevel@tonic-gate * 'lb_path' is a write-once/read-many field which needs no locking, it is 2607c478bd9Sstevel@tonic-gate * set before the structure is linked to any exportinfo structure. 2617c478bd9Sstevel@tonic-gate * 'lb_next' is protected by the log_buffer_list_lock. 2627c478bd9Sstevel@tonic-gate */ 2637c478bd9Sstevel@tonic-gate struct log_buffer { 2647c478bd9Sstevel@tonic-gate unsigned int lb_flags; /* L_ONLIST set? */ 2657c478bd9Sstevel@tonic-gate int lb_refcnt; /* references to this struct */ 2667c478bd9Sstevel@tonic-gate unsigned int lb_rec_id; /* used to generate unique id */ 2677c478bd9Sstevel@tonic-gate caddr_t lb_path; /* buffer file pathname */ 2687c478bd9Sstevel@tonic-gate struct log_file *lb_logfile; /* points to log_file structure */ 2697c478bd9Sstevel@tonic-gate kmutex_t lb_lock; 2707c478bd9Sstevel@tonic-gate struct log_buffer *lb_next; 2717c478bd9Sstevel@tonic-gate kcondvar_t lb_cv_waiters; 2727c478bd9Sstevel@tonic-gate caddr_t lb_records; /* linked list of records to write */ 2737c478bd9Sstevel@tonic-gate int lb_num_recs; /* # of records to write */ 2747c478bd9Sstevel@tonic-gate ssize_t lb_size_queued; /* number of bytes queued for write */ 2757c478bd9Sstevel@tonic-gate }; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate #define LOG_BUFFER_HOLD(lbp) { \ 2787c478bd9Sstevel@tonic-gate mutex_enter(&(lbp)->lb_lock); \ 2797c478bd9Sstevel@tonic-gate (lbp)->lb_refcnt++; \ 2807c478bd9Sstevel@tonic-gate mutex_exit(&(lbp)->lb_lock); \ 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate #define LOG_BUFFER_RELE(lbp) { \ 2847c478bd9Sstevel@tonic-gate log_buffer_rele(lbp); \ 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate 287b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 288b89a8333Snatalie li - Sun Microsystems - Irvine United States * Structure for character set conversion mapping based on client address. 289b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 290b89a8333Snatalie li - Sun Microsystems - Irvine United States struct charset_cache { 291b89a8333Snatalie li - Sun Microsystems - Irvine United States struct charset_cache *next; 292b89a8333Snatalie li - Sun Microsystems - Irvine United States kiconv_t inbound; 293b89a8333Snatalie li - Sun Microsystems - Irvine United States kiconv_t outbound; 294b89a8333Snatalie li - Sun Microsystems - Irvine United States struct sockaddr client_addr; 295b89a8333Snatalie li - Sun Microsystems - Irvine United States }; 296b89a8333Snatalie li - Sun Microsystems - Irvine United States 297992d2facSpf /* Forward declarations */ 298992d2facSpf struct exportinfo; 299992d2facSpf struct exp_visible; 3002f172c55SRobert Thurlow struct svc_req; 301992d2facSpf 302992d2facSpf /* 303992d2facSpf * Treenodes are used to build tree representing every node which is part 304*3f238301SPavel Filipensky * of nfs server pseudo namespace. They are connected with both exportinfo 305*3f238301SPavel Filipensky * and exp_visible struct. They were introduced to avoid lookup of ".." 306*3f238301SPavel Filipensky * in the underlying file system during unshare, which was failing if the 307*3f238301SPavel Filipensky * file system was forcibly unmounted or if the directory was removed. 308*3f238301SPavel Filipensky * One exp_visible_t can be shared via several treenode_t, i.e. 309*3f238301SPavel Filipensky * different tree_vis can point to the same exp_visible_t. 310*3f238301SPavel Filipensky * This will happen if some directory is on two different shared paths: 311*3f238301SPavel Filipensky * E.g. after share /tmp/a/b1 and share /tmp/a/b2 there will be two treenodes 312*3f238301SPavel Filipensky * corresponding to /tmp/a and both will have same value in tree_vis. 313992d2facSpf * 314992d2facSpf * 315992d2facSpf * 316992d2facSpf * NEW DATA STRUCT ORIGINAL DATA STRUCT 317992d2facSpf * 318992d2facSpf * ns_root +---+ +----------+ 319992d2facSpf * | / | |PSEUDO EXP|-->+---+ +---+ +---+ 320992d2facSpf * +---+--------- ----+----------+ | a |-->| k |-->| b | 321992d2facSpf * /\ +---+ +---+ +---+ 322992d2facSpf * / \ . . . 323992d2facSpf * +---+...\......... ..................... . . 324992d2facSpf * *| a | \ +----------+ . . 325992d2facSpf * +---+-----\------- ----|REAL EXP a| . . 326992d2facSpf * / \ +----------+ . . 327992d2facSpf * / +===+... ............................. . 328992d2facSpf * / *| k | +----------+ . 329992d2facSpf * / +===+--- ----|REAL EXP k| . 330992d2facSpf * / +----------+ . 331992d2facSpf * +===+................ ..................................... 332992d2facSpf * *| b | +----------+ 333992d2facSpf * +===+---------------- ----|REAL EXP b|-->+---+ 334992d2facSpf * \ +----------+ | d | 335992d2facSpf * +===+............. ...................+---+ 336992d2facSpf * | d | +----------+ 337992d2facSpf * +===+------------- ----|PSEUDO EXP|-->+---+ +---+ 338992d2facSpf * / +----------+ | e |-->| g | 339992d2facSpf * +---+................. ...................+---+ +---+ 340992d2facSpf * | e | . 341992d2facSpf * +---+ . 342992d2facSpf * \ . 343992d2facSpf * +---+.............. ............................ 344992d2facSpf * *| g | +----------+ 345992d2facSpf * +---+-------------- ----|REAL EXP g| 346992d2facSpf * +----------+ 347992d2facSpf * 348992d2facSpf * 349992d2facSpf * 350992d2facSpf * +===+ +---+ +---+ 351992d2facSpf * | b |..mountpoint | e |..directory/file *| a |..node is shared 352992d2facSpf * +===+ (VROOT) +---+ +---+ 353992d2facSpf * 354992d2facSpf * 355992d2facSpf * Bi-directional interconnect: 356992d2facSpf * treenode_t::tree_exi --------- exportinfo_t::exi_tree 357*3f238301SPavel Filipensky * One-way direction connection: 358*3f238301SPavel Filipensky * treenode_t::tree_vis .........> exp_visible_t 359992d2facSpf */ 360c076b414SPavel Filipensky /* Access to treenode_t is under protection of exported_lock RW_LOCK */ 361992d2facSpf typedef struct treenode { 362992d2facSpf /* support for generic n-ary trees */ 363992d2facSpf struct treenode *tree_parent; 364992d2facSpf struct treenode *tree_child_first; 365992d2facSpf struct treenode *tree_sibling; /* next sibling */ 366992d2facSpf /* private, nfs specific part */ 367992d2facSpf struct exportinfo *tree_exi; 368992d2facSpf struct exp_visible *tree_vis; 369992d2facSpf } treenode_t; 370992d2facSpf 371992d2facSpf /* 372992d2facSpf * TREE_ROOT checks if the node corresponds to a filesystem root 373992d2facSpf * TREE_EXPORTED checks if the node is explicitly shared 374992d2facSpf */ 375992d2facSpf 376992d2facSpf #define TREE_ROOT(t) \ 377992d2facSpf ((t)->tree_exi && (t)->tree_exi->exi_vp->v_flag & VROOT) 378992d2facSpf 379992d2facSpf #define TREE_EXPORTED(t) \ 380992d2facSpf ((t)->tree_exi && !PSEUDO((t)->tree_exi)) 381992d2facSpf 382992d2facSpf /* Root of nfs pseudo namespace */ 383c076b414SPavel Filipensky extern treenode_t *ns_root; 384992d2facSpf 3857c478bd9Sstevel@tonic-gate #define EXPTABLESIZE 16 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * A node associated with an export entry on the 3897c478bd9Sstevel@tonic-gate * list of exported filesystems. 3907c478bd9Sstevel@tonic-gate * 3917c478bd9Sstevel@tonic-gate * exi_count+exi_lock protects an individual exportinfo from being freed 3927c478bd9Sstevel@tonic-gate * when in use. 3937c478bd9Sstevel@tonic-gate * You must have the writer lock on exported_lock to add/delete an exportinfo 3947c478bd9Sstevel@tonic-gate * structure to/from the list. 3957c478bd9Sstevel@tonic-gate * 3967c478bd9Sstevel@tonic-gate * exi_volatile_dev maps to VSW_VOLATILEDEV. It means that the 3977c478bd9Sstevel@tonic-gate * underlying fs devno can change on each mount. When set, the server 3987c478bd9Sstevel@tonic-gate * should not use va_fsid for a GETATTR(FATTR4_FSID) reply. It must 3997c478bd9Sstevel@tonic-gate * use exi_fsid because it is guaranteed to be persistent. This isn't 4007c478bd9Sstevel@tonic-gate * in any way related to NFS4 volatile filehandles. 4017c478bd9Sstevel@tonic-gate */ 4027c478bd9Sstevel@tonic-gate struct exportinfo { 4037c478bd9Sstevel@tonic-gate struct exportdata exi_export; 4047c478bd9Sstevel@tonic-gate fsid_t exi_fsid; 4057c478bd9Sstevel@tonic-gate struct fid exi_fid; 4067c478bd9Sstevel@tonic-gate struct exportinfo *exi_hash; 407992d2facSpf struct treenode *exi_tree; 4087c478bd9Sstevel@tonic-gate fhandle_t exi_fh; 4097c478bd9Sstevel@tonic-gate krwlock_t exi_cache_lock; 4107c478bd9Sstevel@tonic-gate kmutex_t exi_lock; 4117c478bd9Sstevel@tonic-gate uint_t exi_count; 4127c478bd9Sstevel@tonic-gate vnode_t *exi_vp; 4137c478bd9Sstevel@tonic-gate vnode_t *exi_dvp; 4147c478bd9Sstevel@tonic-gate struct auth_cache *exi_cache[AUTH_TABLESIZE]; 4157c478bd9Sstevel@tonic-gate struct log_buffer *exi_logbuffer; 4167c478bd9Sstevel@tonic-gate struct exp_visible *exi_visible; 417b89a8333Snatalie li - Sun Microsystems - Irvine United States struct charset_cache *exi_charset; 4187c478bd9Sstevel@tonic-gate unsigned exi_volatile_dev:1; 4192f172c55SRobert Thurlow unsigned exi_moved:1; 4207c478bd9Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST 4217c478bd9Sstevel@tonic-gate uint32_t exi_volatile_id; 4227c478bd9Sstevel@tonic-gate struct ex_vol_rename *exi_vol_rename; 4237c478bd9Sstevel@tonic-gate kmutex_t exi_vol_rename_lock; 4247c478bd9Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */ 4257c478bd9Sstevel@tonic-gate }; 4267c478bd9Sstevel@tonic-gate 427af9f9769Sjasmith typedef struct exportinfo exportinfo_t; 428af9f9769Sjasmith typedef struct exportdata exportdata_t; 429af9f9769Sjasmith typedef struct secinfo secinfo_t; 430af9f9769Sjasmith 4317c478bd9Sstevel@tonic-gate /* 4327c478bd9Sstevel@tonic-gate * exp_visible is a visible list per filesystem. It is for filesystems 4337c478bd9Sstevel@tonic-gate * that may need a limited view of its contents. A pseudo export and 4347c478bd9Sstevel@tonic-gate * a real export at the mount point (VROOT) which has a subtree shared 4357c478bd9Sstevel@tonic-gate * has a visible list. 4367c478bd9Sstevel@tonic-gate * 4377c478bd9Sstevel@tonic-gate * The exi_visible field is NULL for normal, non=pseudo filesystems 4387c478bd9Sstevel@tonic-gate * which do not have any subtree exported. If the field is non-null, 4397c478bd9Sstevel@tonic-gate * it points to a list of visible entries, identified by vis_fid and/or 4407c478bd9Sstevel@tonic-gate * vis_ino. The presence of a "visible" list means that if this export 4417c478bd9Sstevel@tonic-gate * can only have a limited view, it can only view the entries in the 4427c478bd9Sstevel@tonic-gate * exp_visible list. The directories in the fid list comprise paths that 4437c478bd9Sstevel@tonic-gate * lead to exported directories. 4447c478bd9Sstevel@tonic-gate * 4457c478bd9Sstevel@tonic-gate * The vis_count field records the number of paths in this filesystem 4467c478bd9Sstevel@tonic-gate * that use this directory. The vis_exported field is non-zero if the 4477c478bd9Sstevel@tonic-gate * entry is an exported directory (leaf node). 448c076b414SPavel Filipensky * 449c076b414SPavel Filipensky * exp_visible itself is not reference counted. Each exp_visible is 450c076b414SPavel Filipensky * referenced twice: 451c076b414SPavel Filipensky * 1) from treenode::tree_vis 452c076b414SPavel Filipensky * 2) linked from exportinfo::exi_visible 453c076b414SPavel Filipensky * The 'owner' of exp_visible is the exportinfo structure. exp_visible should 454c076b414SPavel Filipensky * be always freed only from exportinfo_t, never from treenode::tree_vis. 4557c478bd9Sstevel@tonic-gate */ 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate struct exp_visible { 4587c478bd9Sstevel@tonic-gate vnode_t *vis_vp; 4597c478bd9Sstevel@tonic-gate fid_t vis_fid; 4607c478bd9Sstevel@tonic-gate u_longlong_t vis_ino; 4617c478bd9Sstevel@tonic-gate int vis_count; 4627c478bd9Sstevel@tonic-gate int vis_exported; 4637c478bd9Sstevel@tonic-gate struct exp_visible *vis_next; 464af9f9769Sjasmith struct secinfo *vis_secinfo; 465af9f9769Sjasmith int vis_seccnt; 4667c478bd9Sstevel@tonic-gate }; 467af9f9769Sjasmith typedef struct exp_visible exp_visible_t; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate #define PSEUDO(exi) ((exi)->exi_export.ex_flags & EX_PSEUDO) 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate #define EQFSID(fsidp1, fsidp2) \ 4727c478bd9Sstevel@tonic-gate (((fsidp1)->val[0] == (fsidp2)->val[0]) && \ 4737c478bd9Sstevel@tonic-gate ((fsidp1)->val[1] == (fsidp2)->val[1])) 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate #define EQFID(fidp1, fidp2) \ 4767c478bd9Sstevel@tonic-gate ((fidp1)->fid_len == (fidp2)->fid_len && \ 4777c46fb7fSek bcmp((char *)(fidp1)->fid_data, (char *)(fidp2)->fid_data, \ 4787c478bd9Sstevel@tonic-gate (uint_t)(fidp1)->fid_len) == 0) 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate #define exportmatch(exi, fsid, fid) \ 4817c478bd9Sstevel@tonic-gate (EQFSID(&(exi)->exi_fsid, (fsid)) && EQFID(&(exi)->exi_fid, (fid))) 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate /* 4847c478bd9Sstevel@tonic-gate * Returns true iff exported filesystem is read-only to the given host. 4857c478bd9Sstevel@tonic-gate * 4867c478bd9Sstevel@tonic-gate * Note: this macro should be as fast as possible since it's called 4877c478bd9Sstevel@tonic-gate * on each NFS modification request. 4887c478bd9Sstevel@tonic-gate */ 4897c478bd9Sstevel@tonic-gate #define rdonly(exi, req) (nfsauth_access(exi, req) & NFSAUTH_RO) 4907c478bd9Sstevel@tonic-gate #define rdonly4(exi, vp, req) \ 4917c478bd9Sstevel@tonic-gate (vn_is_readonly(vp) || \ 4927c478bd9Sstevel@tonic-gate (nfsauth4_access(exi, vp, req) & (NFSAUTH_RO | NFSAUTH_LIMITED))) 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate extern int nfsauth4_access(struct exportinfo *, vnode_t *, 4957c478bd9Sstevel@tonic-gate struct svc_req *); 4967c478bd9Sstevel@tonic-gate extern int nfsauth4_secinfo_access(struct exportinfo *, 4977c478bd9Sstevel@tonic-gate struct svc_req *, int, int); 4987c478bd9Sstevel@tonic-gate extern int nfs_fhhash(fsid_t *, fid_t *); 4997c478bd9Sstevel@tonic-gate extern int nfs_fhbcmp(char *, char *, int); 5007c478bd9Sstevel@tonic-gate extern int nfs_exportinit(void); 5017c478bd9Sstevel@tonic-gate extern void nfs_exportfini(void); 5027c478bd9Sstevel@tonic-gate extern int chk_clnt_sec(struct exportinfo *, struct svc_req *req); 5037c478bd9Sstevel@tonic-gate extern int makefh(fhandle_t *, struct vnode *, struct exportinfo *); 5047c478bd9Sstevel@tonic-gate extern int makefh_ol(fhandle_t *, struct exportinfo *, uint_t); 5057c478bd9Sstevel@tonic-gate extern int makefh3(nfs_fh3 *, struct vnode *, struct exportinfo *); 5067c478bd9Sstevel@tonic-gate extern int makefh3_ol(nfs_fh3 *, struct exportinfo *, uint_t); 5077c478bd9Sstevel@tonic-gate extern vnode_t *nfs_fhtovp(fhandle_t *, struct exportinfo *); 5087c478bd9Sstevel@tonic-gate extern vnode_t *nfs3_fhtovp(nfs_fh3 *, struct exportinfo *); 5097c478bd9Sstevel@tonic-gate extern vnode_t *lm_fhtovp(fhandle_t *fh); 5107c478bd9Sstevel@tonic-gate extern vnode_t *lm_nfs3_fhtovp(nfs_fh3 *fh); 5117c478bd9Sstevel@tonic-gate extern struct exportinfo *checkexport(fsid_t *, struct fid *); 5127c478bd9Sstevel@tonic-gate extern struct exportinfo *checkexport4(fsid_t *, struct fid *, vnode_t *vp); 5137c478bd9Sstevel@tonic-gate extern void exi_rele(struct exportinfo *); 5147c478bd9Sstevel@tonic-gate extern struct exportinfo *nfs_vptoexi(vnode_t *, vnode_t *, cred_t *, int *, 5157c478bd9Sstevel@tonic-gate int *, bool_t); 5167c478bd9Sstevel@tonic-gate extern int nfs_check_vpexi(vnode_t *, vnode_t *, cred_t *, 5177c478bd9Sstevel@tonic-gate struct exportinfo **); 5187c478bd9Sstevel@tonic-gate extern void export_link(struct exportinfo *); 5197c478bd9Sstevel@tonic-gate extern int export_unlink(fsid_t *, fid_t *, vnode_t *, 5207c478bd9Sstevel@tonic-gate struct exportinfo **); 5217c478bd9Sstevel@tonic-gate extern vnode_t *untraverse(vnode_t *); 5222f172c55SRobert Thurlow extern int vn_is_nfs_reparse(vnode_t *, cred_t *); 5232f172c55SRobert Thurlow extern int client_is_downrev(struct svc_req *); 5242f172c55SRobert Thurlow extern char *build_symlink(vnode_t *, cred_t *, size_t *); 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate /* 5277c478bd9Sstevel@tonic-gate * Functions that handle the NFSv4 server namespace 5287c478bd9Sstevel@tonic-gate */ 529*3f238301SPavel Filipensky extern exportinfo_t *vis2exi(treenode_t *); 5307c478bd9Sstevel@tonic-gate extern int treeclimb_export(struct exportinfo *); 531992d2facSpf extern void treeclimb_unexport(struct exportinfo *); 5327c478bd9Sstevel@tonic-gate extern int nfs_visible(struct exportinfo *, vnode_t *, int *); 5337c478bd9Sstevel@tonic-gate extern int nfs_visible_inode(struct exportinfo *, ino64_t, int *); 5347c478bd9Sstevel@tonic-gate extern int has_visible(struct exportinfo *, vnode_t *); 5357c478bd9Sstevel@tonic-gate extern void free_visible(struct exp_visible *); 5367c478bd9Sstevel@tonic-gate extern int nfs_exported(struct exportinfo *, vnode_t *); 5377c478bd9Sstevel@tonic-gate extern int pseudo_exportfs(vnode_t *, struct exp_visible *, 538992d2facSpf struct exportdata *, struct exportinfo **); 5397c478bd9Sstevel@tonic-gate extern int vop_fid_pseudo(vnode_t *, fid_t *fidp); 5407c478bd9Sstevel@tonic-gate extern int nfs4_vget_pseudo(struct exportinfo *, vnode_t **, fid_t *); 5417c478bd9Sstevel@tonic-gate /* 5427c478bd9Sstevel@tonic-gate * Functions that handle the NFSv4 server namespace security flavors 5437c478bd9Sstevel@tonic-gate * information. 5447c478bd9Sstevel@tonic-gate */ 5457c478bd9Sstevel@tonic-gate extern void srv_secinfo_exp2pseu(struct exportdata *, struct exportdata *); 546af9f9769Sjasmith extern void srv_secinfo_list_free(struct secinfo *, int); 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate /* 5497c478bd9Sstevel@tonic-gate * "public" and default (root) location for public filehandle 5507c478bd9Sstevel@tonic-gate */ 5517c478bd9Sstevel@tonic-gate extern struct exportinfo *exi_public, *exi_root; 5527c478bd9Sstevel@tonic-gate extern fhandle_t nullfh2; /* for comparing V2 filehandles */ 5537c478bd9Sstevel@tonic-gate extern krwlock_t exported_lock; 5547c478bd9Sstevel@tonic-gate extern struct exportinfo *exptable[]; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate /* 5577c478bd9Sstevel@tonic-gate * Two macros for identifying public filehandles. 5587c478bd9Sstevel@tonic-gate * A v2 public filehandle is 32 zero bytes. 5597c478bd9Sstevel@tonic-gate * A v3 public filehandle is zero length. 5607c478bd9Sstevel@tonic-gate */ 5617c478bd9Sstevel@tonic-gate #define PUBLIC_FH2(fh) \ 5627c478bd9Sstevel@tonic-gate ((fh)->fh_fsid.val[1] == 0 && \ 5637c478bd9Sstevel@tonic-gate bcmp((fh), &nullfh2, sizeof (fhandle_t)) == 0) 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate #define PUBLIC_FH3(fh) \ 5667c478bd9Sstevel@tonic-gate ((fh)->fh3_length == 0) 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate extern int makefh4(nfs_fh4 *, struct vnode *, struct exportinfo *); 5697c478bd9Sstevel@tonic-gate extern vnode_t *nfs4_fhtovp(nfs_fh4 *, struct exportinfo *, nfsstat4 *); 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate #ifdef __cplusplus 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate #endif 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate #endif /* _NFS_EXPORT_H */ 578