1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 #ifndef _NFS_EXPORT_H 30 #define _NFS_EXPORT_H 31 32 #pragma ident "%Z%%M% %I% %E% SMI" 33 34 #include <nfs/nfs_sec.h> 35 #include <nfs/auth.h> 36 #include <sys/vnode.h> 37 #include <nfs/nfs4.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /* 44 * nfs pseudo flavor number is owned by IANA. Need to make sure the 45 * Solaris specific NFS_FLAVOR_NOMAP number will not overlap with any 46 * new IANA defined pseudo flavor numbers. The chance for the overlap 47 * is very small since the growth of new flavor numbers is expected 48 * to be limited. 49 */ 50 #define NFS_FLAVOR_NOMAP 999999 /* no nfs flavor mapping */ 51 52 /* 53 * As duplicate flavors can be passed into exportfs in the arguments, we 54 * allocate a cleaned up array with non duplicate flavors on the stack. 55 * So we need to know how much to allocate. 56 */ 57 #define MAX_FLAVORS 6 /* none, sys, dh, krb5, krb5i krb5p */ 58 59 /* 60 * Note: exported_lock is currently used to ensure the integrity of 61 * the secinfo fields. 62 */ 63 struct secinfo { 64 seconfig_t s_secinfo; /* /etc/nfssec.conf entry */ 65 unsigned int s_flags; /* flags (see below) */ 66 int32_t s_refcnt; /* reference count for tracking */ 67 /* how many children (self included) */ 68 /* use this flavor. */ 69 int s_window; /* window */ 70 int s_rootcnt; /* count of root names */ 71 caddr_t *s_rootnames; /* array of root names */ 72 /* they are strings for AUTH_DES and */ 73 /* rpc_gss_principal_t for RPCSEC_GSS */ 74 }; 75 76 #ifdef _SYSCALL32 77 struct secinfo32 { 78 seconfig32_t s_secinfo; /* /etc/nfssec.conf entry */ 79 uint32_t s_flags; /* flags (see below) */ 80 int32_t s_refcnt; /* reference count for tracking */ 81 /* how many children (self included) */ 82 /* use this flavor. */ 83 int32_t s_window; /* window */ 84 int32_t s_rootcnt; /* count of root names */ 85 caddr32_t s_rootnames; /* array of root names */ 86 /* they are strings for AUTH_DES and */ 87 /* rpc_gss_principal_t for RPCSEC_GSS */ 88 }; 89 #endif /* _SYSCALL32 */ 90 91 /* 92 * security negotiation related 93 */ 94 95 #define SEC_QUERY 0x01 /* query sec modes */ 96 97 struct sec_ol { 98 int sec_flags; /* security nego flags */ 99 uint_t sec_index; /* index into sec flavor array */ 100 }; 101 102 /* 103 * Per-mode flags (secinfo.s_flags) 104 */ 105 #define M_RO 0x01 /* exported ro to all */ 106 #define M_ROL 0x02 /* exported ro to all listed */ 107 #define M_RW 0x04 /* exported rw to all */ 108 #define M_RWL 0x08 /* exported ro to all listed */ 109 #define M_ROOT 0x10 /* root list is defined */ 110 #define M_4SEC_EXPORTED 0x20 /* this is an explicitly shared flavor */ 111 112 /* invalid secinfo reference count */ 113 #define SEC_REF_INVALID(p) ((p)->s_refcnt < 1) 114 115 /* last secinfo reference */ 116 #define SEC_REF_LAST(p) ((p)->s_refcnt == 1) 117 118 /* sec flavor explicitly shared for the exported node */ 119 #define SEC_REF_EXPORTED(p) ((p)->s_flags & M_4SEC_EXPORTED) 120 121 /* the only reference count left is for referring itself */ 122 #define SEC_REF_SELF(p) (SEC_REF_LAST(p) && SEC_REF_EXPORTED(p)) 123 124 /* 125 * The export information passed to exportfs() (Version 2) 126 */ 127 #define EX_CURRENT_VERSION 2 /* current version of exportdata struct */ 128 129 struct exportdata { 130 int ex_version; /* structure version */ 131 char *ex_path; /* exported path */ 132 size_t ex_pathlen; /* path length */ 133 int ex_flags; /* flags */ 134 unsigned int ex_anon; /* uid for unauthenticated requests */ 135 int ex_seccnt; /* count of security modes */ 136 struct secinfo *ex_secinfo; /* security mode info */ 137 char *ex_index; /* index file for public filesystem */ 138 char *ex_log_buffer; /* path to logging buffer file */ 139 size_t ex_log_bufferlen; /* buffer file path len */ 140 char *ex_tag; /* tag used to identify log config */ 141 size_t ex_taglen; /* tag length */ 142 }; 143 144 #ifdef _SYSCALL32 145 struct exportdata32 { 146 int32_t ex_version; /* structure version */ 147 caddr32_t ex_path; /* exported path */ 148 int32_t ex_pathlen; /* path length */ 149 int32_t ex_flags; /* flags */ 150 uint32_t ex_anon; /* uid for unauthenticated requests */ 151 int32_t ex_seccnt; /* count of security modes */ 152 caddr32_t ex_secinfo; /* security mode info */ 153 caddr32_t ex_index; /* index file for public filesystem */ 154 caddr32_t ex_log_buffer; /* path to logging buffer file */ 155 int32_t ex_log_bufferlen; /* buffer file path len */ 156 caddr32_t ex_tag; /* tag used to identify log config */ 157 int32_t ex_taglen; /* tag length */ 158 }; 159 #endif /* _SYSCALL32 */ 160 161 /* 162 * exported vfs flags. 163 */ 164 165 #define EX_NOSUID 0x01 /* exported with unsetable set[ug]ids */ 166 #define EX_ACLOK 0x02 /* exported with maximal access if acl exists */ 167 #define EX_PUBLIC 0x04 /* exported with public filehandle */ 168 #define EX_NOSUB 0x08 /* no nfs_getfh or MCL below export point */ 169 #define EX_INDEX 0x10 /* exported with index file specified */ 170 #define EX_LOG 0x20 /* logging enabled */ 171 #define EX_LOG_ALLOPS 0x40 /* logging of all RPC operations enabled */ 172 /* by default only operations which affect */ 173 /* transaction logging are enabled */ 174 #define EX_PSEUDO 0x80 /* pseudo filesystem export */ 175 #ifdef VOLATILE_FH_TEST 176 #define EX_VOLFH 0x100 /* XXX nfsv4 fh may expire anytime */ 177 #define EX_VOLRNM 0x200 /* XXX nfsv4 fh expire at rename */ 178 #define EX_VOLMIG 0x400 /* XXX nfsv4 fh expire at migration */ 179 #define EX_NOEXPOPEN 0x800 /* XXX nfsv4 fh no expire with open */ 180 #endif /* VOLATILE_FH_TEST */ 181 182 #ifdef _KERNEL 183 184 #define RPC_IDEMPOTENT 0x1 /* idempotent or not */ 185 /* 186 * Be very careful about which NFS procedures get the RPC_ALLOWANON bit. 187 * Right now, it this bit is on, we ignore the results of per NFS request 188 * access control. 189 */ 190 #define RPC_ALLOWANON 0x2 /* allow anonymous access */ 191 #define RPC_MAPRESP 0x4 /* use mapped response buffer */ 192 #define RPC_AVOIDWORK 0x8 /* do work avoidance for dups */ 193 #define RPC_PUBLICFH_OK 0x10 /* allow use of public filehandle */ 194 195 /* 196 * RPC_ALL is an or of all above bits to be used with "don't care" 197 * nfsv4 ops. The flags of an nfsv4 request is the bit-AND of the 198 * per-op flags. 199 */ 200 #define RPC_ALL (RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_AVOIDWORK|RPC_PUBLICFH_OK) 201 202 203 #ifdef VOLATILE_FH_TEST 204 struct ex_vol_rename { 205 nfs_fh4_fmt_t vrn_fh_fmt; 206 struct ex_vol_rename *vrn_next; 207 }; 208 #endif /* VOLATILE_FH_TEST */ 209 210 /* 211 * An authorization cache entry 212 */ 213 struct auth_cache { 214 struct netbuf auth_addr; 215 int auth_flavor; 216 int auth_access; 217 time_t auth_time; 218 struct auth_cache *auth_next; 219 }; 220 221 #define AUTH_TABLESIZE 32 222 223 /* 224 * Structure containing log file meta-data. 225 */ 226 struct log_file { 227 unsigned int lf_flags; /* flags (see below) */ 228 int lf_writers; /* outstanding writers */ 229 int lf_refcnt; /* references to this struct */ 230 caddr_t lf_path; /* buffer file location */ 231 vnode_t *lf_vp; /* vnode for the buffer file */ 232 kmutex_t lf_lock; 233 kcondvar_t lf_cv_waiters; 234 }; 235 236 /* 237 * log_file and log_buffer flags. 238 */ 239 #define L_WAITING 0x01 /* flush of in-core data to stable */ 240 /* storage in progress */ 241 #define L_PRINTED 0x02 /* error message printed to console */ 242 #define L_ERROR 0x04 /* error condition detected */ 243 244 /* 245 * The logging buffer information. 246 * This structure may be shared by multiple exportinfo structures, 247 * if they share the same buffer file. 248 * This structure contains the basic information about the buffer, such 249 * as it's location in the filesystem. 250 * 251 * 'lb_lock' protects all the fields in this structure except for 'lb_path', 252 * and 'lb_next'. 253 * 'lb_path' is a write-once/read-many field which needs no locking, it is 254 * set before the structure is linked to any exportinfo structure. 255 * 'lb_next' is protected by the log_buffer_list_lock. 256 */ 257 struct log_buffer { 258 unsigned int lb_flags; /* L_ONLIST set? */ 259 int lb_refcnt; /* references to this struct */ 260 unsigned int lb_rec_id; /* used to generate unique id */ 261 caddr_t lb_path; /* buffer file pathname */ 262 struct log_file *lb_logfile; /* points to log_file structure */ 263 kmutex_t lb_lock; 264 struct log_buffer *lb_next; 265 kcondvar_t lb_cv_waiters; 266 caddr_t lb_records; /* linked list of records to write */ 267 int lb_num_recs; /* # of records to write */ 268 ssize_t lb_size_queued; /* number of bytes queued for write */ 269 }; 270 271 #define LOG_BUFFER_HOLD(lbp) { \ 272 mutex_enter(&(lbp)->lb_lock); \ 273 (lbp)->lb_refcnt++; \ 274 mutex_exit(&(lbp)->lb_lock); \ 275 } 276 277 #define LOG_BUFFER_RELE(lbp) { \ 278 log_buffer_rele(lbp); \ 279 } 280 281 /* Forward declarations */ 282 struct exportinfo; 283 struct exp_visible; 284 285 /* 286 * Treenodes are used to build tree representing every node which is part 287 * of nfs server pseudo namespace. 288 * This tree is interconnected with both exportinfo and exp_visible struct. 289 * When there is a need to walk the namespace (either starting in 290 * exportinfo or in exp_visible) we first make a step aside (to the left), 291 * walk up or down as needed, and then we step back (to the right). 292 * 293 * 294 * 295 * NEW DATA STRUCT ORIGINAL DATA STRUCT 296 * 297 * ns_root +---+ +----------+ 298 * | / | |PSEUDO EXP|-->+---+ +---+ +---+ 299 * +---+--------- ----+----------+ | a |-->| k |-->| b | 300 * /\ +---+ +---+ +---+ 301 * / \ . . . 302 * +---+...\......... ..................... . . 303 * *| a | \ +----------+ . . 304 * +---+-----\------- ----|REAL EXP a| . . 305 * / \ +----------+ . . 306 * / +===+... ............................. . 307 * / *| k | +----------+ . 308 * / +===+--- ----|REAL EXP k| . 309 * / +----------+ . 310 * +===+................ ..................................... 311 * *| b | +----------+ 312 * +===+---------------- ----|REAL EXP b|-->+---+ 313 * \ +----------+ | d | 314 * +===+............. ...................+---+ 315 * | d | +----------+ 316 * +===+------------- ----|PSEUDO EXP|-->+---+ +---+ 317 * / +----------+ | e |-->| g | 318 * +---+................. ...................+---+ +---+ 319 * | e | . 320 * +---+ . 321 * \ . 322 * +---+.............. ............................ 323 * *| g | +----------+ 324 * +---+-------------- ----|REAL EXP g| 325 * +----------+ 326 * 327 * 328 * 329 * +===+ +---+ +---+ 330 * | b |..mountpoint | e |..directory/file *| a |..node is shared 331 * +===+ (VROOT) +---+ +---+ 332 * 333 * 334 * Bi-directional interconnect: 335 * 336 * treenode_t::tree_exi --------- exportinfo_t::exi_tree 337 * treenode_t::tree_vis ......... exp_visible_t::vis_tree 338 */ 339 /* Access to treenodei_t is under under protection of exported_lock RW_LOCK */ 340 typedef struct treenode { 341 /* support for generic n-ary trees */ 342 struct treenode *tree_parent; 343 struct treenode *tree_child_first; 344 struct treenode *tree_sibling; /* next sibling */ 345 /* private, nfs specific part */ 346 struct exportinfo *tree_exi; 347 struct exp_visible *tree_vis; 348 } treenode_t; 349 350 /* 351 * TREE_ROOT checks if the node corresponds to a filesystem root 352 * TREE_EXPORTED checks if the node is explicitly shared 353 */ 354 355 #define TREE_ROOT(t) \ 356 ((t)->tree_exi && (t)->tree_exi->exi_vp->v_flag & VROOT) 357 358 #define TREE_EXPORTED(t) \ 359 ((t)->tree_exi && !PSEUDO((t)->tree_exi)) 360 361 /* Root of nfs pseudo namespace */ 362 treenode_t *ns_root; 363 364 #define EXPTABLESIZE 16 365 366 /* 367 * A node associated with an export entry on the 368 * list of exported filesystems. 369 * 370 * exi_count+exi_lock protects an individual exportinfo from being freed 371 * when in use. 372 * You must have the writer lock on exported_lock to add/delete an exportinfo 373 * structure to/from the list. 374 * 375 * exi_volatile_dev maps to VSW_VOLATILEDEV. It means that the 376 * underlying fs devno can change on each mount. When set, the server 377 * should not use va_fsid for a GETATTR(FATTR4_FSID) reply. It must 378 * use exi_fsid because it is guaranteed to be persistent. This isn't 379 * in any way related to NFS4 volatile filehandles. 380 */ 381 struct exportinfo { 382 struct exportdata exi_export; 383 fsid_t exi_fsid; 384 struct fid exi_fid; 385 struct exportinfo *exi_hash; 386 struct treenode *exi_tree; 387 fhandle_t exi_fh; 388 krwlock_t exi_cache_lock; 389 kmutex_t exi_lock; 390 uint_t exi_count; 391 vnode_t *exi_vp; 392 vnode_t *exi_dvp; 393 struct auth_cache *exi_cache[AUTH_TABLESIZE]; 394 struct log_buffer *exi_logbuffer; 395 struct exp_visible *exi_visible; 396 unsigned exi_volatile_dev:1; 397 #ifdef VOLATILE_FH_TEST 398 uint32_t exi_volatile_id; 399 struct ex_vol_rename *exi_vol_rename; 400 kmutex_t exi_vol_rename_lock; 401 #endif /* VOLATILE_FH_TEST */ 402 }; 403 404 typedef struct exportinfo exportinfo_t; 405 typedef struct exportdata exportdata_t; 406 typedef struct secinfo secinfo_t; 407 408 /* 409 * exp_visible is a visible list per filesystem. It is for filesystems 410 * that may need a limited view of its contents. A pseudo export and 411 * a real export at the mount point (VROOT) which has a subtree shared 412 * has a visible list. 413 * 414 * The exi_visible field is NULL for normal, non=pseudo filesystems 415 * which do not have any subtree exported. If the field is non-null, 416 * it points to a list of visible entries, identified by vis_fid and/or 417 * vis_ino. The presence of a "visible" list means that if this export 418 * can only have a limited view, it can only view the entries in the 419 * exp_visible list. The directories in the fid list comprise paths that 420 * lead to exported directories. 421 * 422 * The vis_count field records the number of paths in this filesystem 423 * that use this directory. The vis_exported field is non-zero if the 424 * entry is an exported directory (leaf node). 425 */ 426 427 struct exp_visible { 428 vnode_t *vis_vp; 429 fid_t vis_fid; 430 u_longlong_t vis_ino; 431 int vis_count; 432 int vis_exported; 433 struct exp_visible *vis_next; 434 struct treenode *vis_tree; 435 struct secinfo *vis_secinfo; 436 int vis_seccnt; 437 }; 438 typedef struct exp_visible exp_visible_t; 439 440 #define PSEUDO(exi) ((exi)->exi_export.ex_flags & EX_PSEUDO) 441 442 #define EQFSID(fsidp1, fsidp2) \ 443 (((fsidp1)->val[0] == (fsidp2)->val[0]) && \ 444 ((fsidp1)->val[1] == (fsidp2)->val[1])) 445 446 #define EQFID(fidp1, fidp2) \ 447 ((fidp1)->fid_len == (fidp2)->fid_len && \ 448 bcmp((char *)(fidp1)->fid_data, (char *)(fidp2)->fid_data, \ 449 (uint_t)(fidp1)->fid_len) == 0) 450 451 #define exportmatch(exi, fsid, fid) \ 452 (EQFSID(&(exi)->exi_fsid, (fsid)) && EQFID(&(exi)->exi_fid, (fid))) 453 454 /* 455 * Returns true iff exported filesystem is read-only to the given host. 456 * 457 * Note: this macro should be as fast as possible since it's called 458 * on each NFS modification request. 459 */ 460 #define rdonly(exi, req) (nfsauth_access(exi, req) & NFSAUTH_RO) 461 #define rdonly4(exi, vp, req) \ 462 (vn_is_readonly(vp) || \ 463 (nfsauth4_access(exi, vp, req) & (NFSAUTH_RO | NFSAUTH_LIMITED))) 464 465 extern int nfsauth4_access(struct exportinfo *, vnode_t *, 466 struct svc_req *); 467 extern int nfsauth4_secinfo_access(struct exportinfo *, 468 struct svc_req *, int, int); 469 extern int nfs_fhhash(fsid_t *, fid_t *); 470 extern int nfs_fhbcmp(char *, char *, int); 471 extern int nfs_exportinit(void); 472 extern void nfs_exportfini(void); 473 extern int chk_clnt_sec(struct exportinfo *, struct svc_req *req); 474 extern int makefh(fhandle_t *, struct vnode *, struct exportinfo *); 475 extern int makefh_ol(fhandle_t *, struct exportinfo *, uint_t); 476 extern int makefh3(nfs_fh3 *, struct vnode *, struct exportinfo *); 477 extern int makefh3_ol(nfs_fh3 *, struct exportinfo *, uint_t); 478 extern vnode_t *nfs_fhtovp(fhandle_t *, struct exportinfo *); 479 extern vnode_t *nfs3_fhtovp(nfs_fh3 *, struct exportinfo *); 480 extern vnode_t *lm_fhtovp(fhandle_t *fh); 481 extern vnode_t *lm_nfs3_fhtovp(nfs_fh3 *fh); 482 extern struct exportinfo *checkexport(fsid_t *, struct fid *); 483 extern struct exportinfo *checkexport4(fsid_t *, struct fid *, vnode_t *vp); 484 extern void exi_rele(struct exportinfo *); 485 extern struct exportinfo *nfs_vptoexi(vnode_t *, vnode_t *, cred_t *, int *, 486 int *, bool_t); 487 extern int nfs_check_vpexi(vnode_t *, vnode_t *, cred_t *, 488 struct exportinfo **); 489 extern void export_link(struct exportinfo *); 490 extern int export_unlink(fsid_t *, fid_t *, vnode_t *, 491 struct exportinfo **); 492 extern vnode_t *untraverse(vnode_t *); 493 494 /* 495 * Functions that handle the NFSv4 server namespace 496 */ 497 extern exportinfo_t *vis2exi(struct exp_visible *); 498 extern int treeclimb_export(struct exportinfo *); 499 extern void treeclimb_unexport(struct exportinfo *); 500 extern int nfs_visible(struct exportinfo *, vnode_t *, int *); 501 extern int nfs_visible_inode(struct exportinfo *, ino64_t, int *); 502 extern int has_visible(struct exportinfo *, vnode_t *); 503 extern void free_visible(struct exp_visible *); 504 extern int nfs_exported(struct exportinfo *, vnode_t *); 505 extern int pseudo_exportfs(vnode_t *, struct exp_visible *, 506 struct exportdata *, struct exportinfo **); 507 extern int vop_fid_pseudo(vnode_t *, fid_t *fidp); 508 extern int nfs4_vget_pseudo(struct exportinfo *, vnode_t **, fid_t *); 509 /* 510 * Functions that handle the NFSv4 server namespace security flavors 511 * information. 512 */ 513 extern void srv_secinfo_exp2pseu(struct exportdata *, struct exportdata *); 514 extern void srv_secinfo_list_free(struct secinfo *, int); 515 516 /* 517 * "public" and default (root) location for public filehandle 518 */ 519 extern struct exportinfo *exi_public, *exi_root; 520 extern fhandle_t nullfh2; /* for comparing V2 filehandles */ 521 extern krwlock_t exported_lock; 522 extern struct exportinfo *exptable[]; 523 524 /* 525 * Two macros for identifying public filehandles. 526 * A v2 public filehandle is 32 zero bytes. 527 * A v3 public filehandle is zero length. 528 */ 529 #define PUBLIC_FH2(fh) \ 530 ((fh)->fh_fsid.val[1] == 0 && \ 531 bcmp((fh), &nullfh2, sizeof (fhandle_t)) == 0) 532 533 #define PUBLIC_FH3(fh) \ 534 ((fh)->fh3_length == 0) 535 536 extern int makefh4(nfs_fh4 *, struct vnode *, struct exportinfo *); 537 extern vnode_t *nfs4_fhtovp(nfs_fh4 *, struct exportinfo *, nfsstat4 *); 538 539 #endif /* _KERNEL */ 540 541 #ifdef __cplusplus 542 } 543 #endif 544 545 #endif /* _NFS_EXPORT_H */ 546