1 /* 2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ 29 /* 30 * Copyright (c) 1989, 1993, 1995 31 * The Regents of the University of California. All rights reserved. 32 * 33 * This code is derived from software contributed to Berkeley by 34 * Rick Macklem at The University of Guelph. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. All advertising materials mentioning features or use of this software 45 * must display the following acknowledgement: 46 * This product includes software developed by the University of 47 * California, Berkeley and its contributors. 48 * 4. Neither the name of the University nor the names of its contributors 49 * may be used to endorse or promote products derived from this software 50 * without specific prior written permission. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * SUCH DAMAGE. 63 * 64 * @(#)nfs.h 8.4 (Berkeley) 5/1/95 65 * FreeBSD-Id: nfs.h,v 1.32 1997/10/12 20:25:38 phk Exp $ 66 */ 67 68 #ifndef _NFS_NFS_H_ 69 #define _NFS_NFS_H_ 70 71 #include <sys/appleapiopts.h> 72 #include <sys/cdefs.h> 73 #include <sys/socket.h> 74 #include <sys/mount.h> 75 #include <sys/ioccom.h> 76 77 #ifdef KERNEL 78 #include <sys/vnode.h> 79 #include <sys/user.h> 80 #include <net/radix.h> 81 #include <kern/locks.h> 82 #include <kern/lock_group.h> 83 #endif 84 85 #include <nfs/rpcv2.h> 86 #include <nfs/nfsproto.h> 87 88 #ifdef __APPLE_API_PRIVATE 89 /* 90 * Tunable constants for nfs 91 */ 92 93 #define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */ 94 #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ 95 extern int nfs_ticks; 96 #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 97 #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 98 #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 99 #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 100 #define NFS_MAXREXMIT 100 /* Stop counting after this many */ 101 #define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 102 #define NFS_TRYLATERDEL 4 /* Initial try later delay (sec) */ 103 #define NFS_MAXGRPS 16U /* Max. size of groups list */ 104 #define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ 105 #define NFS_MAXATTRTIMO 60 106 #define NFS_MINDIRATTRTIMO 5 /* directory attribute cache timeout in sec */ 107 #define NFS_MAXDIRATTRTIMO 60 108 #define NFS_MAXPORT 0xffff 109 #define NFS_IOSIZE (1024 * 1024) /* suggested I/O size */ 110 #define NFS_RWSIZE 32768 /* Def. read/write data size <= 32K */ 111 #define NFS_WSIZE NFS_RWSIZE /* Def. write data size <= 32K */ 112 #define NFS_RSIZE NFS_RWSIZE /* Def. read data size <= 32K */ 113 #define NFS_DGRAM_WSIZE 8192 /* UDP Def. write data size <= 8K */ 114 #define NFS_DGRAM_RSIZE 8192 /* UDP Def. read data size <= 8K */ 115 #define NFS_READDIRSIZE 32768 /* Def. readdir size */ 116 #define NFS_DEFRAHEAD 16 /* Def. read ahead # blocks */ 117 #define NFS_MAXRAHEAD 128 /* Max. read ahead # blocks */ 118 #define NFS_DEFMAXASYNCWRITES 128 /* Def. max # concurrent async write RPCs */ 119 #define NFS_DEFASYNCTHREAD 16 /* Def. # nfsiod threads */ 120 #define NFS_MAXASYNCTHREAD 64 /* max # nfsiod threads */ 121 #define NFS_ASYNCTHREADMAXIDLE 60 /* Seconds before idle nfsiods are reaped */ 122 #define NFS_DEFSTATFSRATELIMIT 10 /* Def. max # statfs RPCs per second */ 123 #define NFS_REQUESTDELAY 10 /* ms interval to check request queue */ 124 #define NFSRV_MAXWGATHERDELAY 100 /* Max. write gather delay (msec) */ 125 #ifndef NFSRV_WGATHERDELAY 126 #define NFSRV_WGATHERDELAY 1 /* Default write gather delay (msec) */ 127 #endif 128 #define NFS_DIRBLKSIZ 4096 /* size of NFS directory buffers */ 129 #if defined(KERNEL) && !defined(DIRBLKSIZ) 130 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 131 /* can't be larger than NFS_FABLKSIZE */ 132 #endif 133 134 /* default values for unresponsive mount timeouts */ 135 #define NFS_TPRINTF_INITIAL_DELAY 5 136 #define NFS_TPRINTF_DELAY 30 137 138 /* NFS client mount timeouts */ 139 #define NFS_MOUNT_TIMEOUT 30 140 #define NFS_MOUNT_QUICK_TIMEOUT 8 141 142 /* 143 * Oddballs 144 */ 145 #define NFS_CMPFH(n, f, s) \ 146 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) 147 #define NFSRV_NDMAXDATA(n) \ 148 (((n)->nd_vers == NFS_VER3) ? (((n)->nd_nam2) ? \ 149 NFS_MAXDGRAMDATA : NFSRV_MAXDATA) : NFS_V2MAXDATA) 150 #define NFS_PORT_INVALID(port) \ 151 (((port) > NFS_MAXPORT) || ((port) < 0)) 152 153 /* 154 * The IO_METASYNC flag should be implemented for local file systems. 155 * (Until then, it is nothin at all.) 156 */ 157 #ifndef IO_METASYNC 158 #define IO_METASYNC 0 159 #endif 160 161 /* 162 * Expected allocation sizes for major data structures. If the actual size 163 * of the structure exceeds these sizes, then malloc() will be allocating 164 * almost twice the memory required. This is used in nfs_init() to warn 165 * the sysadmin that the size of a structure should be reduced. 166 * (These sizes are always a power of 2. If the kernel malloc() changes 167 * to one that does not allocate space in powers of 2 size, then this all 168 * becomes bunk!). 169 * Note that some of these structures come out of their own nfs zones. 170 */ 171 #define NFS_NODEALLOC 1024 172 #define NFS_MNTALLOC 1024 173 #define NFS_SVCALLOC 512 174 175 #define NFS_ARGSVERSION_XDR 88 /* NFS mount args are in XDR format */ 176 177 #define NFS_XDRARGS_VERSION_0 0 178 #define NFS_MATTR_BITMAP_LEN 2 /* length of mount attributes bitmap */ 179 #define NFS_MFLAG_BITMAP_LEN 1 /* length of mount flags bitmap */ 180 181 /* NFS mount attributes */ 182 #define NFS_MATTR_FLAGS 0 /* mount flags (NFS_MATTR_*) */ 183 #define NFS_MATTR_NFS_VERSION 1 /* NFS protocol version */ 184 #define NFS_MATTR_NFS_MINOR_VERSION 2 /* NFS protocol minor version */ 185 #define NFS_MATTR_READ_SIZE 3 /* READ RPC size */ 186 #define NFS_MATTR_WRITE_SIZE 4 /* WRITE RPC size */ 187 #define NFS_MATTR_READDIR_SIZE 5 /* READDIR RPC size */ 188 #define NFS_MATTR_READAHEAD 6 /* block readahead count */ 189 #define NFS_MATTR_ATTRCACHE_REG_MIN 7 /* minimum attribute cache time */ 190 #define NFS_MATTR_ATTRCACHE_REG_MAX 8 /* maximum attribute cache time */ 191 #define NFS_MATTR_ATTRCACHE_DIR_MIN 9 /* minimum attribute cache time for dirs */ 192 #define NFS_MATTR_ATTRCACHE_DIR_MAX 10 /* maximum attribute cache time for dirs */ 193 #define NFS_MATTR_LOCK_MODE 11 /* advisory file locking mode (NFS_LOCK_MODE_*) */ 194 #define NFS_MATTR_SECURITY 12 /* RPC security flavors to use */ 195 #define NFS_MATTR_MAX_GROUP_LIST 13 /* max # of RPC AUTH_SYS groups */ 196 #define NFS_MATTR_SOCKET_TYPE 14 /* socket transport type as a netid-like string */ 197 #define NFS_MATTR_NFS_PORT 15 /* port # to use for NFS protocol */ 198 #define NFS_MATTR_MOUNT_PORT 16 /* port # to use for MOUNT protocol */ 199 #define NFS_MATTR_REQUEST_TIMEOUT 17 /* initial RPC request timeout value */ 200 #define NFS_MATTR_SOFT_RETRY_COUNT 18 /* max RPC retransmissions for soft mounts */ 201 #define NFS_MATTR_DEAD_TIMEOUT 19 /* how long until unresponsive mount is considered dead */ 202 #define NFS_MATTR_FH 20 /* file handle for mount directory */ 203 #define NFS_MATTR_FS_LOCATIONS 21 /* list of locations for the file system */ 204 #define NFS_MATTR_MNTFLAGS 22 /* VFS mount flags (MNT_*) */ 205 #define NFS_MATTR_MNTFROM 23 /* fixed string to use for "f_mntfromname" */ 206 #define NFS_MATTR_REALM 24 /* Realm to authenticate with */ 207 #define NFS_MATTR_PRINCIPAL 25 /* GSS principal to authenticate with */ 208 #define NFS_MATTR_SVCPRINCIPAL 26 /* GSS principal to authenticate to, the server principal */ 209 #define NFS_MATTR_NFS_VERSION_RANGE 27 /* Packed version range to try */ 210 #define NFS_MATTR_KERB_ETYPE 28 /* Enctype to use for kerberos mounts */ 211 #define NFS_MATTR_LOCAL_NFS_PORT 29 /* Unix domain socket for NFS protocol */ 212 #define NFS_MATTR_LOCAL_MOUNT_PORT 30 /* Unix domain socket for MOUNT protocol */ 213 #define NFS_MATTR_SET_MOUNT_OWNER 31 /* Set owner of mount point */ 214 #define NFS_MATTR_READLINK_NOCACHE 32 /* Readlink nocache mode */ 215 216 /* NFS mount flags */ 217 #define NFS_MFLAG_SOFT 0 /* soft mount (requests fail if unresponsive) */ 218 #define NFS_MFLAG_INTR 1 /* allow operations to be interrupted */ 219 #define NFS_MFLAG_RESVPORT 2 /* use a reserved port */ 220 #define NFS_MFLAG_NOCONNECT 3 /* don't connect the socket (UDP) */ 221 #define NFS_MFLAG_DUMBTIMER 4 /* don't estimate RTT dynamically */ 222 #define NFS_MFLAG_CALLUMNT 5 /* call MOUNTPROC_UMNT on unmount */ 223 #define NFS_MFLAG_RDIRPLUS 6 /* request additional info when reading directories */ 224 #define NFS_MFLAG_NONEGNAMECACHE 7 /* don't do negative name caching */ 225 #define NFS_MFLAG_MUTEJUKEBOX 8 /* don't treat jukebox errors as unresponsive */ 226 #define NFS_MFLAG_EPHEMERAL 9 /* ephemeral (mirror) mount */ 227 #define NFS_MFLAG_NOCALLBACK 10 /* don't provide callback RPC service */ 228 #define NFS_MFLAG_NAMEDATTR 11 /* don't use named attributes */ 229 #define NFS_MFLAG_NOACL 12 /* don't support ACLs */ 230 #define NFS_MFLAG_ACLONLY 13 /* only support ACLs - not mode */ 231 #define NFS_MFLAG_NFC 14 /* send NFC strings */ 232 #define NFS_MFLAG_NOQUOTA 15 /* don't support QUOTA requests */ 233 #define NFS_MFLAG_MNTUDP 16 /* MOUNT protocol should use UDP */ 234 #define NFS_MFLAG_MNTQUICK 17 /* use short timeouts while mounting */ 235 #define NFS_MFLAG_NOOPAQUE_AUTH 19 /* don't make the mount AUTH_OPAQUE. Used by V3 */ 236 237 /* Macros for packing and unpacking packed versions */ 238 #define PVER2MAJOR(M) ((uint32_t)(((M) >> 16) & 0xffff)) 239 #define PVER2MINOR(m) ((uint32_t)((m) & 0xffff)) 240 #define VER2PVER(M, m) ((uint32_t)((M) << 16) | ((m) & 0xffff)) 241 242 /* NFS advisory file locking modes */ 243 #define NFS_LOCK_MODE_ENABLED 0 /* advisory file locking enabled */ 244 #define NFS_LOCK_MODE_DISABLED 1 /* do not support advisory file locking */ 245 #define NFS_LOCK_MODE_LOCAL 2 /* perform advisory file locking locally */ 246 247 #define NFS_STRLEN_INT(str) \ 248 (int)strnlen(str, INT_MAX) 249 #define NFS_UIO_ADDIOV(a_uio, a_baseaddr, a_length) \ 250 assert(a_length <= UINT32_MAX); uio_addiov(a_uio, a_baseaddr, (uint32_t)(a_length)); 251 #define NFS_BZERO(off, bytes) \ 252 do { \ 253 uint32_t bytes32 = bytes > UINT32_MAX ? UINT32_MAX : (uint32_t)(bytes); \ 254 bzero(off, bytes32); \ 255 if (bytes > UINT32_MAX) { \ 256 bzero(off + bytes32, (uint32_t)(bytes - UINT32_MAX)); \ 257 } \ 258 } while(0); 259 #define NFS_ZFREE(zone, ptr) \ 260 do { \ 261 if ((ptr)) { \ 262 zfree((zone), (ptr)); \ 263 (ptr) = NULL; \ 264 } \ 265 } while (0); \ 266 267 /* Supported encryption types for kerberos session keys */ 268 typedef enum nfs_supported_kerberos_etypes { 269 NFS_DES3_CBC_SHA1_KD = 16, 270 NFS_AES128_CTS_HMAC_SHA1_96 = 17, 271 NFS_AES256_CTS_HMAC_SHA1_96 = 18 272 } nfs_supported_kerberos_etypes; 273 274 /* Structure to hold an array of kerberos enctypes to allow on a mount */ 275 #define NFS_MAX_ETYPES 3 276 struct nfs_etype { 277 uint32_t count; 278 uint32_t selected; /* index in etypes that is being used. Set to count if nothing has been selected */ 279 nfs_supported_kerberos_etypes etypes[NFS_MAX_ETYPES]; 280 }; 281 282 /* 283 * Old-style arguments to mount NFS 284 */ 285 #define NFS_ARGSVERSION 6 /* change when nfs_args changes */ 286 struct nfs_args { 287 int version; /* args structure version number */ 288 #ifdef KERNEL 289 user32_addr_t addr; /* file server address */ 290 #else 291 struct sockaddr *addr; /* file server address */ 292 #endif 293 uint8_t addrlen; /* length of address */ 294 int sotype; /* Socket type */ 295 int proto; /* and Protocol */ 296 #ifdef KERNEL 297 user32_addr_t fh; /* File handle to be mounted */ 298 #else 299 u_char *fh; /* File handle to be mounted */ 300 #endif 301 int fhsize; /* Size, in bytes, of fh */ 302 int flags; /* flags */ 303 int wsize; /* write size in bytes */ 304 int rsize; /* read size in bytes */ 305 int readdirsize; /* readdir size in bytes */ 306 int timeo; /* initial timeout in .1 secs */ 307 int retrans; /* times to retry send */ 308 int maxgrouplist; /* Max. size of group list */ 309 int readahead; /* # of blocks to readahead */ 310 int leaseterm; /* obsolete: Term (sec) of lease */ 311 int deadthresh; /* obsolete: Retrans threshold */ 312 #ifdef KERNEL 313 user32_addr_t hostname; /* server's name */ 314 #else 315 char *hostname; /* server's name */ 316 #endif 317 /* NFS_ARGSVERSION 3 ends here */ 318 int acregmin; /* reg file min attr cache timeout */ 319 int acregmax; /* reg file max attr cache timeout */ 320 int acdirmin; /* dir min attr cache timeout */ 321 int acdirmax; /* dir max attr cache timeout */ 322 /* NFS_ARGSVERSION 4 ends here */ 323 uint32_t auth; /* security mechanism flavor */ 324 /* NFS_ARGSVERSION 5 ends here */ 325 uint32_t deadtimeout; /* secs until unresponsive mount considered dead */ 326 }; 327 328 /* incremental size additions in each version of nfs_args */ 329 #define NFS_ARGSVERSION4_INCSIZE (4 * sizeof(int)) 330 #define NFS_ARGSVERSION5_INCSIZE (sizeof(uint32_t)) 331 #define NFS_ARGSVERSION6_INCSIZE (sizeof(uint32_t)) 332 333 #ifdef KERNEL 334 /* LP64 version of nfs_args. all pointers and longs 335 * grow when we're dealing with a 64-bit process. 336 * WARNING - keep in sync with nfs_args 337 */ 338 struct user_nfs_args { 339 int version; /* args structure version number */ 340 user_addr_t addr __attribute((aligned(8))); /* file server address */ 341 uint8_t addrlen; /* length of address */ 342 int sotype; /* Socket type */ 343 int proto; /* and Protocol */ 344 user_addr_t fh __attribute((aligned(8))); /* File handle to be mounted */ 345 int fhsize; /* Size, in bytes, of fh */ 346 int flags; /* flags */ 347 int wsize; /* write size in bytes */ 348 int rsize; /* read size in bytes */ 349 int readdirsize; /* readdir size in bytes */ 350 int timeo; /* initial timeout in .1 secs */ 351 int retrans; /* times to retry send */ 352 int maxgrouplist; /* Max. size of group list */ 353 int readahead; /* # of blocks to readahead */ 354 int leaseterm; /* obsolete: Term (sec) of lease */ 355 int deadthresh; /* obsolete: Retrans threshold */ 356 user_addr_t hostname __attribute((aligned(8))); /* server's name */ 357 /* NFS_ARGSVERSION 3 ends here */ 358 int acregmin; /* reg file min attr cache timeout */ 359 int acregmax; /* reg file max attr cache timeout */ 360 int acdirmin; /* dir min attr cache timeout */ 361 int acdirmax; /* dir max attr cache timeout */ 362 /* NFS_ARGSVERSION 4 ends here */ 363 uint32_t auth; /* security mechanism flavor */ 364 /* NFS_ARGSVERSION 5 ends here */ 365 uint32_t deadtimeout; /* secs until unresponsive mount considered dead */ 366 }; 367 #endif // KERNEL 368 369 /* 370 * Old-style NFS mount option flags 371 */ 372 #define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */ 373 #define NFSMNT_WSIZE 0x00000002 /* set write size */ 374 #define NFSMNT_RSIZE 0x00000004 /* set read size */ 375 #define NFSMNT_TIMEO 0x00000008 /* set initial timeout */ 376 #define NFSMNT_RETRANS 0x00000010 /* set number of request retries */ 377 #define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */ 378 #define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */ 379 #define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */ 380 #define NFSMNT_NONEGNAMECACHE 0x00000100 /* Don't do negative name caching */ 381 #define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */ 382 #define NFSMNT_NFSV4 0x00000400 /* Use NFS Version 4 protocol */ 383 #define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */ 384 #define NFSMNT_DEADTIMEOUT 0x00001000 /* unmount after a period of unresponsiveness */ 385 #define NFSMNT_READAHEAD 0x00002000 /* set read ahead */ 386 #define NFSMNT_CALLUMNT 0x00004000 /* call MOUNTPROC_UMNT on unmount */ 387 #define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */ 388 #define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */ 389 #define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */ 390 #define NFSMNT_NOLOCKS 0x00040000 /* don't support file locking */ 391 #define NFSMNT_LOCALLOCKS 0x00080000 /* do file locking locally on client */ 392 #define NFSMNT_ACREGMIN 0x00100000 /* reg min attr cache timeout */ 393 #define NFSMNT_ACREGMAX 0x00200000 /* reg max attr cache timeout */ 394 #define NFSMNT_ACDIRMIN 0x00400000 /* dir min attr cache timeout */ 395 #define NFSMNT_ACDIRMAX 0x00800000 /* dir max attr cache timeout */ 396 #define NFSMNT_SECFLAVOR 0x01000000 /* Use security flavor */ 397 #define NFSMNT_SECSYSOK 0x02000000 /* Server can support auth sys */ 398 #define NFSMNT_MUTEJUKEBOX 0x04000000 /* don't treat jukebox errors as unresponsive */ 399 #define NFSMNT_NOQUOTA 0x08000000 /* don't support QUOTA requests */ 400 401 402 /* 403 * fs.nfs sysctl(3) NFS_MOUNTINFO defines 404 */ 405 #define NFS_MOUNT_INFO_VERSION 0 /* nfsstat mount information version */ 406 #define NFS_MIATTR_BITMAP_LEN 1 /* length of mount info attributes bitmap */ 407 #define NFS_MIFLAG_BITMAP_LEN 1 /* length of mount info flags bitmap */ 408 409 /* NFS mount info attributes */ 410 #define NFS_MIATTR_FLAGS 0 /* mount info flags bitmap (MIFLAG_*) */ 411 #define NFS_MIATTR_ORIG_ARGS 1 /* original mount args passed into mount call */ 412 #define NFS_MIATTR_CUR_ARGS 2 /* current mount args values */ 413 #define NFS_MIATTR_CUR_LOC_INDEX 3 /* current fs location index */ 414 415 /* NFS mount info flags */ 416 #define NFS_MIFLAG_DEAD 0 /* mount is dead */ 417 #define NFS_MIFLAG_NOTRESP 1 /* server is unresponsive */ 418 #define NFS_MIFLAG_RECOVERY 2 /* mount in recovery */ 419 420 421 /* 422 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd 423 * should ever try and use it. 424 */ 425 struct nfsd_args { 426 int sock; /* Socket to serve */ 427 #ifdef KERNEL 428 user32_addr_t name; /* Client addr for connection based sockets */ 429 #else 430 caddr_t name; /* Client addr for connection based sockets */ 431 #endif 432 int namelen; /* Length of name */ 433 }; 434 435 #ifdef KERNEL 436 /* LP64 version of nfsd_args. all pointers and longs 437 * grow when we're dealing with a 64-bit process. 438 * WARNING - keep in sync with nfsd_args 439 */ 440 struct user_nfsd_args { 441 int sock; /* Socket to serve */ 442 user_addr_t name __attribute((aligned(8))); /* Client addr for connection based sockets */ 443 int namelen; /* Length of name */ 444 }; 445 446 #endif // KERNEL 447 448 /* 449 * NFS Server File Handle structures 450 */ 451 452 /* NFS export handle identifies which NFS export */ 453 #define NFS_FH_VERSION 0x4e580000 /* 'NX00' */ 454 struct nfs_exphandle { 455 uint32_t nxh_version; /* data structure version */ 456 uint32_t nxh_fsid; /* File System Export ID */ 457 uint32_t nxh_expid; /* Export ID */ 458 uint16_t nxh_flags; /* export handle flags */ 459 uint8_t nxh_reserved; /* future use */ 460 uint32_t nxh_fidlen; /* length of File ID */ 461 }; 462 463 /* nxh_flags */ 464 #define NXHF_INVALIDFH 0x0001 /* file handle is invalid */ 465 466 #define NFS_MAX_FID_SIZE (NFS_MAX_FH_SIZE - sizeof(struct nfs_exphandle)) 467 #define NFSV4_MAX_FID_SIZE (NFSV4_MAX_FH_SIZE - sizeof(struct nfs_exphandle)) 468 #define NFSV3_MAX_FID_SIZE (NFSV3_MAX_FH_SIZE - sizeof(struct nfs_exphandle)) 469 #define NFSV2_MAX_FID_SIZE (NFSV2_MAX_FH_SIZE - sizeof(struct nfs_exphandle)) 470 471 /* NFS server internal view of fhandle_t */ 472 /* The first sizeof(fhandle_t) bytes must match what goes into fhandle_t. */ 473 /* (fhp is used to allow use of an external buffer) */ 474 struct nfs_filehandle { 475 uint32_t nfh_len; /* total length of file handle */ 476 struct nfs_exphandle nfh_xh; /* export handle */ 477 unsigned char nfh_fid[NFS_MAX_FID_SIZE]; /* File ID */ 478 unsigned char *nfh_fhp; /* pointer to file handle */ 479 }; 480 481 /* 482 * NFS export data structures 483 */ 484 485 /* Structure to hold an array of security flavors */ 486 #define NX_MAX_SEC_FLAVORS 5 487 struct nfs_sec { 488 int count; 489 uint32_t flavors[NX_MAX_SEC_FLAVORS]; 490 }; 491 492 struct nfs_export_net_args { 493 uint32_t nxna_flags; /* export flags */ 494 struct xucred nxna_cred; /* mapped credential for root/all user */ 495 struct sockaddr_storage nxna_addr; /* net address to which exported */ 496 struct sockaddr_storage nxna_mask; /* mask for net address */ 497 struct nfs_sec nxna_sec; /* security mechanism flavors */ 498 }; 499 500 struct nfs_export_args { 501 uint32_t nxa_fsid; /* export FS ID */ 502 uint32_t nxa_expid; /* export ID */ 503 #ifdef KERNEL 504 user32_addr_t nxa_fspath; /* export FS path */ 505 user32_addr_t nxa_exppath; /* export sub-path */ 506 #else 507 char *nxa_fspath; /* export FS path */ 508 char *nxa_exppath; /* export sub-path */ 509 #endif 510 uint32_t nxa_flags; /* export arg flags */ 511 uint32_t nxa_netcount; /* #entries in ex_nets array */ 512 #ifdef KERNEL 513 user32_addr_t nxa_nets; /* array of net args */ 514 #else 515 struct nfs_export_net_args *nxa_nets; /* array of net args */ 516 #endif 517 }; 518 519 #ifdef KERNEL 520 /* LP64 version of export_args */ 521 522 struct user_nfs_export_args { 523 uint32_t nxa_fsid; /* export FS ID */ 524 uint32_t nxa_expid; /* export ID */ 525 user_addr_t nxa_fspath; /* export FS path */ 526 user_addr_t nxa_exppath; /* export sub-path */ 527 uint32_t nxa_flags; /* export arg flags */ 528 uint32_t nxa_netcount; /* #entries in ex_nets array */ 529 user_addr_t nxa_nets; /* array of net args */ 530 }; 531 532 #endif /* KERNEL */ 533 534 /* nfs export arg flags */ 535 #define NXA_DELETE 0x0001 /* delete the specified export(s) */ 536 #define NXA_ADD 0x0002 /* add the specified export(s) */ 537 #define NXA_REPLACE 0x0003 /* delete and add the specified export(s) */ 538 #define NXA_DELETE_ALL 0x0004 /* delete all exports */ 539 #define NXA_OFFLINE 0x0008 /* export is offline */ 540 #define NXA_CHECK 0x0010 /* check if exportable */ 541 542 /* export option flags */ 543 #define NX_READONLY 0x0001 /* exported read-only */ 544 #define NX_DEFAULTEXPORT 0x0002 /* exported to the world */ 545 #define NX_MAPROOT 0x0004 /* map root access to anon credential */ 546 #define NX_MAPALL 0x0008 /* map all access to anon credential */ 547 #define NX_32BITCLIENTS 0x0020 /* restrict directory cookies to 32 bits */ 548 #define NX_OFFLINE 0x0040 /* export is offline */ 549 #define NX_MANGLEDNAMES 0x0080 /* export will return mangled names for names > 255 bytes */ 550 551 /* 552 * fs.nfs sysctl(3) export stats record structures 553 */ 554 #define NFS_EXPORT_STAT_REC_VERSION 1 /* export stat record version */ 555 #define NFS_USER_STAT_REC_VERSION 1 /* active user list record version */ 556 557 /* descriptor describing following records */ 558 struct nfs_export_stat_desc { 559 uint32_t rec_vers; /* version of export stat records */ 560 uint64_t rec_count; /* total record count */ 561 }__attribute__((__packed__)); 562 563 /* export stat record containing path and stat counters */ 564 struct nfs_export_stat_rec { 565 char path[RPCMNT_PATHLEN + 1]; 566 uint64_t ops; /* Count of NFS Requests received for this export */ 567 uint64_t bytes_read; /* Count of bytes read from this export */ 568 uint64_t bytes_written; /* Count of bytes written to this export */ 569 }__attribute__((__packed__)); 570 571 /* Active user list stat buffer descriptor */ 572 struct nfs_user_stat_desc { 573 uint32_t rec_vers; /* version of active user stat records */ 574 uint32_t rec_count; /* total record count */ 575 }__attribute__((__packed__)); 576 577 /* Active user list user stat record format */ 578 struct nfs_user_stat_user_rec { 579 u_char rec_type; 580 uid_t uid; 581 struct sockaddr_storage sock; 582 uint64_t ops; 583 uint64_t bytes_read; 584 uint64_t bytes_written; 585 time_t tm_start; 586 time_t tm_last; 587 }__attribute__((__packed__)); 588 589 /* Active user list path record format */ 590 struct nfs_user_stat_path_rec { 591 u_char rec_type; 592 char path[RPCMNT_PATHLEN + 1]; 593 }__attribute__((__packed__)); 594 595 /* Defines for rec_type field of 596 * nfs_user_stat_rec & nfs_user_stat_rec 597 * data structures 598 */ 599 #define NFS_USER_STAT_USER_REC 0 600 #define NFS_USER_STAT_PATH_REC 1 601 602 603 #ifdef XNU_KERNEL_PRIVATE 604 struct nfs_exportfs; 605 606 struct nfs_export_options { 607 uint32_t nxo_flags; /* export options */ 608 kauth_cred_t nxo_cred; /* mapped credential */ 609 struct nfs_sec nxo_sec; /* security mechanism flavors */ 610 }; 611 612 /* Network address lookup element and individual export options */ 613 struct nfs_netopt { 614 struct radix_node no_rnodes[2]; /* radix tree glue */ 615 struct nfs_export_options no_opt; /* export options */ 616 struct sockaddr *no_addr; /* net address to which exported */ 617 struct sockaddr *no_mask; /* mask for net address */ 618 }; 619 620 /* statistic counters for each exported directory 621 * 622 * Since 64-bit atomic operations are not available on 32-bit platforms, 623 * 64-bit counters are implemented using 32-bit integers and 32-bit 624 * atomic operations 625 */ 626 typedef struct nfsstatcount64 { 627 uint32_t hi; 628 uint32_t lo; 629 } nfsstatcount64; 630 631 struct nfs_export_stat_counters { 632 struct nfsstatcount64 ops; /* Count of NFS Requests received for this export */ 633 struct nfsstatcount64 bytes_read; /* Count of bytes read from this export */ 634 struct nfsstatcount64 bytes_written; /* Count of bytes written to his export */ 635 }; 636 637 /* Macro for updating nfs export stat counters */ 638 #define NFSStatAdd64(PTR, VAL) \ 639 do { \ 640 uint32_t NFSSA_OldValue = \ 641 OSAddAtomic((VAL), &(PTR)->lo); \ 642 if ((NFSSA_OldValue + (VAL)) < NFSSA_OldValue) \ 643 OSAddAtomic(1, &(PTR)->hi); \ 644 } while (0) 645 646 /* Some defines for dealing with active user list stats */ 647 #define NFSRV_USER_STAT_DEF_MAX_NODES 1024 /* default active user list size limit */ 648 #define NFSRV_USER_STAT_DEF_IDLE_SEC 7200 /* default idle seconds (node no longer considered active) */ 649 650 /* active user list globals */ 651 extern uint32_t nfsrv_user_stat_enabled; /* enable/disable active user list */ 652 extern uint32_t nfsrv_user_stat_node_count; /* current count of user stat nodes */ 653 extern uint32_t nfsrv_user_stat_max_idle_sec; /* idle seconds (node no longer considered active) */ 654 extern uint32_t nfsrv_user_stat_max_nodes; /* active user list size limit */ 655 extern lck_grp_t nfsrv_active_user_mutex_group; 656 657 /* An active user node represented in the kernel */ 658 struct nfs_user_stat_node { 659 TAILQ_ENTRY(nfs_user_stat_node) lru_link; 660 LIST_ENTRY(nfs_user_stat_node) hash_link; 661 uid_t uid; 662 struct sockaddr_storage sock; 663 uint64_t ops; 664 uint64_t bytes_read; 665 uint64_t bytes_written; 666 time_t tm_start; 667 time_t tm_last; 668 }; 669 670 /* Hash table for active user nodes */ 671 #define NFS_USER_STAT_HASH_SIZE 16 /* MUST be a power of 2 */ 672 #define NFS_USER_STAT_HASH(userhashtbl, uid) \ 673 &((userhashtbl)[(uid) & (NFS_USER_STAT_HASH_SIZE - 1)]) 674 675 TAILQ_HEAD(nfs_user_stat_lru_head, nfs_user_stat_node); 676 LIST_HEAD(nfs_user_stat_hashtbl_head, nfs_user_stat_node); 677 678 /* Active user list data structure */ 679 /* One per exported directory */ 680 struct nfs_active_user_list { 681 struct nfs_user_stat_lru_head user_lru; 682 struct nfs_user_stat_hashtbl_head user_hashtbl[NFS_USER_STAT_HASH_SIZE]; 683 uint32_t node_count; 684 lck_mtx_t user_mutex; 685 }; 686 687 688 /* Network export information */ 689 /* one of these for each exported directory */ 690 struct nfs_export { 691 LIST_ENTRY(nfs_export) nx_next; /* FS export list */ 692 LIST_ENTRY(nfs_export) nx_hash; /* export hash chain */ 693 struct nfs_export *nx_parent; /* parent export */ 694 uint32_t nx_id; /* export ID */ 695 uint32_t nx_flags; /* export flags */ 696 struct nfs_exportfs *nx_fs; /* exported file system */ 697 char *nx_path; /* exported file system sub-path */ 698 struct nfs_filehandle nx_fh; /* export root file handle */ 699 struct nfs_export_options nx_defopt; /* default options */ 700 uint32_t nx_expcnt; /* # exports in table */ 701 struct radix_node_head *nx_rtable[AF_MAX + 1]; /* table of exports (netopts) */ 702 struct nfs_export_stat_counters nx_stats; /* statistic counters for this exported directory */ 703 struct nfs_active_user_list nx_user_list; /* Active User List for this exported directory */ 704 struct timeval nx_exptime; /* time of export for write verifier */ 705 }; 706 707 /* NFS exported file system info */ 708 /* one of these for each exported file system */ 709 struct nfs_exportfs { 710 LIST_ENTRY(nfs_exportfs) nxfs_next; /* exported file system list */ 711 uint32_t nxfs_id; /* exported file system ID */ 712 char *nxfs_path; /* exported file system path */ 713 LIST_HEAD(, nfs_export) nxfs_exports; /* list of exports for this file system */ 714 }; 715 716 extern LIST_HEAD(nfsrv_expfs_list, nfs_exportfs) nfsrv_exports; 717 extern lck_rw_t nfsrv_export_rwlock; // lock for export data structures 718 #define NFSRVEXPHASHSZ 64 719 #define NFSRVEXPHASHVAL(FSID, EXPID) \ 720 (((FSID) >> 24) ^ ((FSID) >> 16) ^ ((FSID) >> 8) ^ (EXPID)) 721 #define NFSRVEXPHASH(FSID, EXPID) \ 722 (&nfsrv_export_hashtbl[NFSRVEXPHASHVAL((FSID),(EXPID)) & nfsrv_export_hash]) 723 extern LIST_HEAD(nfsrv_export_hashhead, nfs_export) * nfsrv_export_hashtbl; 724 extern u_long nfsrv_export_hash; 725 726 #if CONFIG_FSE 727 /* 728 * NFS server file mod fsevents 729 */ 730 struct nfsrv_fmod { 731 LIST_ENTRY(nfsrv_fmod) fm_link; 732 vnode_t fm_vp; 733 struct vfs_context fm_context; 734 uint64_t fm_deadline; 735 }; 736 737 #define NFSRVFMODHASHSZ 128 738 #define NFSRVFMODHASH(vp) (((uintptr_t) vp) & nfsrv_fmod_hash) 739 extern LIST_HEAD(nfsrv_fmod_hashhead, nfsrv_fmod) * nfsrv_fmod_hashtbl; 740 extern u_long nfsrv_fmod_hash; 741 extern lck_mtx_t nfsrv_fmod_mutex; 742 extern int nfsrv_fmod_pending, nfsrv_fsevents_enabled; 743 #endif 744 745 extern int nfsrv_async, nfsrv_export_hash_size, 746 nfsrv_reqcache_size, nfsrv_sock_max_rec_queue_length; 747 extern uint32_t nfsrv_gss_context_ttl; 748 extern struct nfsrvstats nfsrvstats; 749 #define NFS_UC_Q_DEBUG 750 #ifdef NFS_UC_Q_DEBUG 751 extern int nfsrv_uc_use_proxy; 752 extern uint32_t nfsrv_uc_queue_limit; 753 extern uint32_t nfsrv_uc_queue_max_seen; 754 extern volatile uint32_t nfsrv_uc_queue_count; 755 #endif 756 757 #endif // XNU_KERNEL_PRIVATE 758 759 /* 760 * XXX to allow amd to include nfs.h without nfsproto.h 761 */ 762 #ifdef NFS_NPROCS 763 /* 764 * Stats structure 765 */ 766 struct nfsclntstats { 767 uint64_t attrcache_hits; 768 uint64_t attrcache_misses; 769 uint64_t lookupcache_hits; 770 uint64_t lookupcache_misses; 771 uint64_t direofcache_hits; 772 uint64_t direofcache_misses; 773 uint64_t biocache_reads; 774 uint64_t read_bios; 775 uint64_t read_physios; 776 uint64_t biocache_writes; 777 uint64_t write_bios; 778 uint64_t write_physios; 779 uint64_t biocache_readlinks; 780 uint64_t readlink_bios; 781 uint64_t biocache_readdirs; 782 uint64_t readdir_bios; 783 uint64_t rpccntv3[NFS_NPROCS]; 784 uint64_t opcntv4[NFS_OP_COUNT]; 785 uint64_t rpcretries; 786 uint64_t rpcrequests; 787 uint64_t rpctimeouts; 788 uint64_t rpcunexpected; 789 uint64_t rpcinvalid; 790 uint64_t pageins; 791 uint64_t pageouts; 792 }; 793 794 struct nfsrvstats { 795 uint64_t srvrpccntv3[NFS_NPROCS]; 796 uint64_t srvrpc_errs; 797 uint64_t srv_errs; 798 uint64_t srvcache_inproghits; 799 uint64_t srvcache_idemdonehits; 800 uint64_t srvcache_nonidemdonehits; 801 uint64_t srvcache_misses; 802 uint64_t srvvop_writes; 803 }; 804 805 #endif 806 807 /* 808 * Flags for nfssvc() system call. 809 */ 810 #define NFSSVC_NFSD 0x004 811 #define NFSSVC_ADDSOCK 0x008 812 #define NFSSVC_EXPORTSTATS 0x010 /* gets exported directory stats */ 813 #define NFSSVC_USERSTATS 0x020 /* gets exported directory active user stats */ 814 #define NFSSVC_USERCOUNT 0x040 /* gets current count of active nfs users */ 815 #define NFSSVC_ZEROSTATS 0x080 /* zero nfs server statistics */ 816 #define NFSSVC_SRVSTATS 0x100 /* struct: struct nfsrvstats */ 817 #define NFSSVC_EXPORT 0x200 818 819 /* 820 * The structure that lockd hands the kernel for each lock answer. 821 */ 822 #define LOCKD_ANS_VERSION 2 823 struct lockd_ans { 824 int la_version; /* lockd_ans version */ 825 int la_errno; /* return status */ 826 u_int64_t la_xid; /* unique message transaction ID */ 827 int la_flags; /* answer flags */ 828 pid_t la_pid; /* pid of lock requester/owner */ 829 off_t la_start; /* lock starting offset */ 830 off_t la_len; /* lock length */ 831 int la_fh_len; /* The file handle length. */ 832 u_int8_t la_fh[NFSV3_MAX_FH_SIZE];/* The file handle. */ 833 }; 834 835 /* 836 * The structure that lockd hands the kernel for each notify. 837 */ 838 #define LOCKD_NOTIFY_VERSION 1 839 struct lockd_notify { 840 int ln_version; /* lockd_notify version */ 841 int ln_flags; /* notify flags */ 842 int ln_pad; /* (for alignment) */ 843 int ln_addrcount; /* # of addresss */ 844 struct sockaddr_storage *ln_addr; /* List of addresses. */ 845 }; 846 847 #include <sys/_types/_guid_t.h> /* for guid_t below */ 848 #define MAXIDNAMELEN 1024 849 struct nfs_testmapid { 850 uint32_t ntm_lookup; /* lookup name 2 id or id 2 name */ 851 uint32_t ntm_grpflag; /* Is this a group or user maping */ 852 uint32_t ntm_id; /* id to map or return */ 853 uint32_t pad; 854 guid_t ntm_guid; /* intermidiate guid used in conversion */ 855 char ntm_name[MAXIDNAMELEN]; /* name to map or return */ 856 }; 857 858 #define NTM_ID2NAME 0 859 #define NTM_NAME2ID 1 860 #define NTM_NAME2GUID 2 861 #define NTM_GUID2NAME 3 862 863 /* 864 * Flags for nfsclnt() system call. 865 */ 866 #define NFSCLNT_LOCKDANS _IOW('n', 101, struct lockd_ans) 867 #define NFSCLNT_LOCKDNOTIFY _IOW('n', 102, struct lockd_notify) 868 #define NFSCLNT_TESTIDMAP _IOWR('n', 103, struct nfs_testmapid) 869 870 /* nfsclnt() system call character device */ 871 #define NFSCLNT_DEVICE "nfsclnt" 872 873 /* nfsclnt() system call */ 874 int nfsclnt(unsigned long request, void *argstructp); 875 876 /* 877 * fs.nfs sysctl(3) identifiers 878 */ 879 #define NFS_NFSSTATS 1 /* struct: struct nfsclntstats */ 880 #define NFS_MOUNTINFO 6 /* gets information about an NFS mount */ 881 #define NFS_NFSZEROSTATS 7 /* zero nfs client statistics */ 882 883 #ifndef NFS_WDELAYHASHSIZ 884 #define NFS_WDELAYHASHSIZ 16 /* and with this */ 885 #endif 886 887 #ifdef KERNEL_PRIVATE 888 889 /* NFS hooks */ 890 891 /* NFS hooks in struct */ 892 struct nfs_hooks_in { 893 int (*f_vinvalbuf)(vnode_t, int, vfs_context_t, int); 894 int (*f_buf_page_inval)(vnode_t, off_t); 895 }; 896 897 /* NFS hooks out struct */ 898 struct nfs_hooks_out { 899 void * (*f_get_bsdthreadtask_info)(thread_t); 900 }; 901 902 /* NFS hooks registration functions */ 903 void nfs_register_hooks(struct nfs_hooks_in *, struct nfs_hooks_out *); 904 void nfs_unregister_hooks(void); 905 906 #ifdef XNU_KERNEL_PRIVATE 907 908 /* NFS hooks wrappers */ 909 int nfs_vinvalbuf(vnode_t, int, vfs_context_t, int); 910 int nfs_buf_page_inval(vnode_t, off_t); 911 912 #endif /* XNU_KERNEL_PRIVATE */ 913 914 /* Debug support */ 915 #define __NFS_DEBUG_LEVEL(dbgctl) ((dbgctl) & 0xf) 916 #define __NFS_DEBUG_FACILITY(dbgctl) (((dbgctl) >> 4) & 0xfff) 917 #define __NFS_DEBUG_FLAGS(dbgctl) (((dbgctl) >> 16) & 0xf) 918 #define __NFS_DEBUG_VALUE(dbgctl) (((dbgctl) >> 20) & 0xfff) 919 #define __NFS_IS_DBG(dbgctl, fac, lev) (__builtin_expect((__NFS_DEBUG_FACILITY(dbgctl) & (fac)) && ((lev) <= __NFS_DEBUG_LEVEL(dbgctl)), 0)) 920 #define __NFS_DBG(dbgctl, fac, lev, fmt, ...) nfs_printf((dbgctl), (fac), (lev), "%s: %d: " fmt, __func__, __LINE__, ## __VA_ARGS__) 921 void nfs_printf(unsigned int, unsigned int, unsigned int, const char *, ...) __printflike(4, 5); 922 void nfs_dump_mbuf(const char *, int, const char *, mbuf_t); 923 924 /* 925 * NFS mbuf chain structure used for managing the building/dissection of RPCs 926 */ 927 struct nfsm_chain { 928 mbuf_t nmc_mhead; /* mbuf chain head */ 929 mbuf_t nmc_mcur; /* current mbuf */ 930 caddr_t nmc_ptr; /* pointer into current mbuf */ 931 size_t nmc_left; /* bytes remaining in current mbuf */ 932 uint32_t nmc_flags; /* flags for this nfsm_chain */ 933 }; 934 #define NFSM_CHAIN_FLAG_ADD_CLUSTERS 0x1 /* always add mbuf clusters */ 935 936 extern size_t nfs_mbuf_mhlen, nfs_mbuf_minclsize; 937 938 /* 939 * Each retransmission of an RPCSEC_GSS request 940 * has an additional sequence number. 941 */ 942 struct gss_seq { 943 SLIST_ENTRY(gss_seq) gss_seqnext; 944 uint32_t gss_seqnum; 945 }; 946 947 #endif /* KERNEL_PRIVATE */ 948 949 #ifdef XNU_KERNEL_PRIVATE 950 951 extern uint32_t nfsrv_debug_ctl; 952 953 /* Server debug support */ 954 #define NFSRV_FAC_GSS 0x001 955 #define NFSRV_FAC_SRV 0x002 956 #define NFSRV_DEBUG_LEVEL __NFS_DEBUG_LEVEL(nfsrv_debug_ctl) 957 #define NFSRV_DEBUG_FACILITY __NFS_DEBUG_FACILITY(nfsrv_debug_ctl) 958 #define NFSRV_DEBUG_FLAGS __NFS_DEBUG_FLAGS(nfsrv_debug_ctl) 959 #define NFSRV_DEBUG_VALUE __NFS_DEBUG_VALUE(nfsrv_debug_ctl) 960 #define NFSRV_IS_DBG(fac, lev) __NFS_IS_DBG(nfsrv_debug_ctl, fac, lev) 961 #define NFSRV_DBG(fac, lev, fmt, ...) __NFS_DBG(nfsrv_debug_ctl, fac, lev, fmt, ## __VA_ARGS__) 962 963 #ifdef MALLOC_DECLARE 964 MALLOC_DECLARE(M_NFSD); 965 #endif 966 967 struct nameidata; 968 struct nfsrv_uc_arg; 969 970 /* 971 * One nfsrv_sock structure is maintained for each socket the 972 * server is servicing requests on. 973 */ 974 struct nfsrv_sock { 975 TAILQ_ENTRY(nfsrv_sock) ns_chain; /* List of all nfsrv_sock's */ 976 TAILQ_ENTRY(nfsrv_sock) ns_svcq; /* List of sockets needing servicing */ 977 TAILQ_ENTRY(nfsrv_sock) ns_wgq; /* List of sockets with a pending write gather */ 978 struct nfsrv_uc_arg *ns_ua; /* Opaque pointer to upcall */ 979 lck_rw_t ns_rwlock; /* lock for most fields */ 980 socket_t ns_so; 981 mbuf_t ns_nam; 982 mbuf_t ns_raw; 983 mbuf_t ns_rawend; 984 mbuf_t ns_rec; 985 mbuf_t ns_recend; 986 mbuf_t ns_frag; 987 int ns_flag; 988 int ns_sotype; 989 size_t ns_cc; 990 size_t ns_reclen; 991 int ns_reccnt; 992 u_int32_t ns_sref; 993 time_t ns_timestamp; /* socket timestamp */ 994 lck_mtx_t ns_wgmutex; /* mutex for write gather fields */ 995 time_t ns_wgtime; /* next Write deadline (usec) */ 996 LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */ 997 LIST_HEAD(nfsrv_wg_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ]; 998 }; 999 1000 /* Bits for "ns_flag" */ 1001 #define SLP_VALID 0x0001 /* nfs sock valid */ 1002 #define SLP_DOREC 0x0002 /* nfs sock has received data to process */ 1003 #define SLP_NEEDQ 0x0004 /* network socket has data to receive */ 1004 #define SLP_DISCONN 0x0008 /* socket needs to be zapped */ 1005 #define SLP_GETSTREAM 0x0010 /* currently in nfsrv_getstream() */ 1006 #define SLP_LASTFRAG 0x0020 /* on last fragment of RPC record */ 1007 #define SLP_DOWRITES 0x0040 /* nfs sock has gathered writes to service */ 1008 #define SLP_WORKTODO 0x004e /* mask of all "work to do" flags */ 1009 #define SLP_ALLFLAGS 0x007f 1010 #define SLP_WAITQ 0x4000 /* nfs sock is on the wait queue */ 1011 #define SLP_WORKQ 0x8000 /* nfs sock is on the work queue */ 1012 #define SLP_QUEUED 0xc000 /* nfs sock is on a queue */ 1013 1014 #define SLPNOLIST ((struct nfsrv_sock *)0xdeadbeef) /* sentinel value for sockets not in the nfsrv_sockwg list */ 1015 1016 extern struct nfsrv_sock *nfsrv_udpsock, *nfsrv_udp6sock; 1017 1018 /* 1019 * global NFS server socket lists: 1020 * 1021 * nfsrv_socklist - list of all sockets (ns_chain) 1022 * nfsrv_sockwait - sockets w/new data waiting to be worked on (ns_svcq) 1023 * nfsrv_sockwork - sockets being worked on which may have more work to do (ns_svcq) 1024 * nfsrv_sockwg - sockets with pending write gather input (ns_wgq) 1025 */ 1026 extern TAILQ_HEAD(nfsrv_sockhead, nfsrv_sock) nfsrv_socklist, nfsrv_sockwg, 1027 nfsrv_sockwait, nfsrv_sockwork; 1028 1029 /* lock groups for nfsrv_sock's */ 1030 extern lck_grp_t nfsrv_slp_rwlock_group; 1031 extern lck_grp_t nfsrv_slp_mutex_group; 1032 1033 /* 1034 * One of these structures is allocated for each nfsd. 1035 */ 1036 struct nfsd { 1037 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */ 1038 TAILQ_ENTRY(nfsd) nfsd_queue; /* List of waiting nfsd's */ 1039 int nfsd_flag; /* NFSD_ flags */ 1040 struct nfsrv_sock *nfsd_slp; /* Current socket */ 1041 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */ 1042 }; 1043 1044 /* Bits for "nfsd_flag" */ 1045 #define NFSD_WAITING 0x01 1046 #define NFSD_REQINPROG 0x02 1047 1048 /* 1049 * This structure is used by the server for describing each request. 1050 * Some fields are used only when write request gathering is performed. 1051 */ 1052 struct nfsrv_descript { 1053 time_t nd_time; /* Write deadline (usec) */ 1054 off_t nd_off; /* Start byte offset */ 1055 off_t nd_eoff; /* and end byte offset */ 1056 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */ 1057 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */ 1058 LIST_HEAD(, nfsrv_descript) nd_coalesce; /* coalesced writes */ 1059 struct nfsm_chain nd_nmreq; /* Request mbuf chain */ 1060 mbuf_t nd_mrep; /* Reply mbuf list (WG) */ 1061 mbuf_t nd_nam; /* and socket addr */ 1062 mbuf_t nd_nam2; /* return socket addr */ 1063 u_int32_t nd_procnum; /* RPC # */ 1064 int nd_stable; /* storage type */ 1065 int nd_vers; /* NFS version */ 1066 int nd_len; /* Length of this write */ 1067 int nd_repstat; /* Reply status */ 1068 u_int32_t nd_retxid; /* Reply xid */ 1069 struct timeval nd_starttime; /* Time RPC initiated */ 1070 struct nfs_filehandle nd_fh; /* File handle */ 1071 uint32_t nd_sec; /* Security flavor */ 1072 struct nfs_gss_svc_ctx *nd_gss_context;/* RPCSEC_GSS context */ 1073 uint32_t nd_gss_seqnum; /* RPCSEC_GSS seq num */ 1074 mbuf_t nd_gss_mb; /* RPCSEC_GSS results mbuf */ 1075 kauth_cred_t nd_cr; /* Credentials */ 1076 }; 1077 1078 extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head, nfsd_queue; 1079 1080 typedef int (*nfsrv_proc_t)(struct nfsrv_descript *, struct nfsrv_sock *, 1081 vfs_context_t, mbuf_t *); 1082 1083 /* mutex for nfs server */ 1084 extern lck_mtx_t nfsd_mutex; 1085 extern int nfsd_thread_count, nfsd_thread_max; 1086 1087 /* nfs timer call structures */ 1088 extern thread_call_t nfsrv_idlesock_timer_call; 1089 #if CONFIG_FSE 1090 extern thread_call_t nfsrv_fmod_timer_call; 1091 #endif 1092 1093 __BEGIN_DECLS 1094 1095 nfstype vtonfs_type(enum vtype, int); 1096 enum vtype nfstov_type(nfstype, int); 1097 int vtonfsv2_mode(enum vtype, mode_t); 1098 1099 void nfs_mbuf_init(void); 1100 1101 int nfs_sockaddr_cmp(struct sockaddr *, struct sockaddr *); 1102 1103 void nfsrv_active_user_list_reclaim(void); 1104 void nfsrv_cleancache(void); 1105 void nfsrv_cleanup(void); 1106 int nfsrv_credcheck(struct nfsrv_descript *, vfs_context_t, struct nfs_export *, 1107 struct nfs_export_options *); 1108 void nfsrv_idlesock_timer(void *, void *); 1109 int nfsrv_dorec(struct nfsrv_sock *, struct nfsd *, struct nfsrv_descript **); 1110 int nfsrv_errmap(struct nfsrv_descript *, int); 1111 int nfsrv_export(struct user_nfs_export_args *, vfs_context_t); 1112 int nfsrv_fhmatch(struct nfs_filehandle *, struct nfs_filehandle *); 1113 int nfsrv_fhtovp(struct nfs_filehandle *, struct nfsrv_descript *, vnode_t *, 1114 struct nfs_export **, struct nfs_export_options **); 1115 int nfsrv_check_exports_allow_address(mbuf_t); 1116 #if CONFIG_FSE 1117 void nfsrv_fmod_timer(void *, void *); 1118 #endif 1119 int nfsrv_getcache(struct nfsrv_descript *, struct nfsrv_sock *, mbuf_t *); 1120 void nfsrv_group_sort(gid_t *, int); 1121 void nfsrv_init(void); 1122 void nfsrv_initcache(void); 1123 int nfsrv_is_initialized(void); 1124 int nfsrv_namei(struct nfsrv_descript *, vfs_context_t, struct nameidata *, 1125 struct nfs_filehandle *, vnode_t *, 1126 struct nfs_export **, struct nfs_export_options **); 1127 void nfsrv_rcv(socket_t, void *, int); 1128 void nfsrv_rcv_locked(socket_t, struct nfsrv_sock *, int); 1129 int nfsrv_rephead(struct nfsrv_descript *, struct nfsrv_sock *, struct nfsm_chain *, size_t); 1130 int nfsrv_send(struct nfsrv_sock *, mbuf_t, mbuf_t); 1131 void nfsrv_updatecache(struct nfsrv_descript *, int, mbuf_t); 1132 void nfsrv_update_user_stat(struct nfs_export *, struct nfsrv_descript *, uid_t, u_int, u_int, u_int); 1133 int nfsrv_vptofh(struct nfs_export *, int, struct nfs_filehandle *, 1134 vnode_t, vfs_context_t, struct nfs_filehandle *); 1135 void nfsrv_wakenfsd(struct nfsrv_sock *); 1136 void nfsrv_wg_timer(void *, void *); 1137 int nfsrv_writegather(struct nfsrv_descript **, struct nfsrv_sock *, 1138 vfs_context_t, mbuf_t *); 1139 1140 int nfsrv_access(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1141 int nfsrv_commit(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1142 int nfsrv_create(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1143 int nfsrv_fsinfo(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1144 int nfsrv_getattr(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1145 int nfsrv_link(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1146 int nfsrv_lookup(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1147 int nfsrv_mkdir(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1148 int nfsrv_mknod(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1149 int nfsrv_noop(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1150 int nfsrv_null(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1151 int nfsrv_pathconf(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1152 int nfsrv_read(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1153 int nfsrv_readdir(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1154 int nfsrv_readdirplus(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1155 int nfsrv_readlink(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1156 int nfsrv_remove(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1157 int nfsrv_rename(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1158 int nfsrv_rmdir(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1159 int nfsrv_setattr(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1160 int nfsrv_statfs(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1161 int nfsrv_symlink(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1162 int nfsrv_write(struct nfsrv_descript *, struct nfsrv_sock *, vfs_context_t, mbuf_t *); 1163 1164 void nfs_interval_timer_start(thread_call_t, time_t); 1165 1166 /* socket upcall interfaces */ 1167 void nfsrv_uc_init(void); 1168 void nfsrv_uc_cleanup(void); 1169 void nfsrv_uc_addsock(struct nfsrv_sock *, int); 1170 void nfsrv_uc_dequeue(struct nfsrv_sock *); 1171 1172 #include <kern/kalloc.h> 1173 1174 extern zone_t nfsrv_descript_zone; 1175 1176 __END_DECLS 1177 #endif /* XNU_KERNEL_PRIVATE */ 1178 1179 #endif /* __APPLE_API_PRIVATE */ 1180 1181 #endif 1182