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