]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/nfs/nfs.h
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / sys / fs / nfs / nfs.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Rick Macklem at The University of Guelph.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  */
36
37 #ifndef _NFS_NFS_H_
38 #define _NFS_NFS_H_
39 /*
40  * Tunable constants for nfs
41  */
42
43 #define NFS_MAXIOVEC    34
44 #define NFS_TICKINTVL   500             /* Desired time for a tick (msec) */
45 #define NFS_HZ          (hz / nfscl_ticks) /* Ticks/sec */
46 #define NFS_TIMEO       (1 * NFS_HZ)    /* Default timeout = 1 second */
47 #define NFS_MINTIMEO    (1 * NFS_HZ)    /* Min timeout to use */
48 #define NFS_MAXTIMEO    (60 * NFS_HZ)   /* Max timeout to backoff to */
49 #define NFS_TCPTIMEO    300             /* TCP timeout */
50 #define NFS_MAXRCVTIMEO 60              /* 1 minute in seconds */
51 #define NFS_MINIDEMTIMEO (5 * NFS_HZ)   /* Min timeout for non-idempotent ops*/
52 #define NFS_MAXREXMIT   100             /* Stop counting after this many */
53 #define NFSV4_CALLBACKTIMEO (2 * NFS_HZ) /* Timeout in ticks */
54 #define NFSV4_CALLBACKRETRY 5           /* Number of retries before failure */
55 #define NFSV4_SLOTS     64              /* Number of slots, fore channel */
56 #define NFSV4_CBSLOTS   8               /* Number of slots, back channel */
57 #define NFSV4_CBRETRYCNT 4              /* # of CBRecall retries upon err */
58 #define NFSV4_UPCALLTIMEO (15 * NFS_HZ) /* Timeout in ticks for upcalls */
59                                         /* to gssd or nfsuserd */
60 #define NFSV4_UPCALLRETRY 4             /* Number of retries before failure */
61 #define NFS_MAXWINDOW   1024            /* Max number of outstanding requests */
62 #define NFS_RETRANS     10              /* Num of retrans for soft mounts */
63 #define NFS_RETRANS_TCP 2               /* Num of retrans for TCP soft mounts */
64 #define NFS_MAXGRPS     16              /* Max. size of groups list */
65 #define NFS_TRYLATERDEL 15              /* Maximum delay timeout (sec) */
66 #ifndef NFS_REMOVETIMEO
67 #define NFS_REMOVETIMEO 15  /* # sec to wait for delegret in local syscall */
68 #endif
69 #ifndef NFS_MINATTRTIMO
70 #define NFS_MINATTRTIMO 5               /* Attribute cache timeout in sec */
71 #endif
72 #ifndef NFS_MAXATTRTIMO
73 #define NFS_MAXATTRTIMO 60
74 #endif
75 #define NFS_WSIZE       8192            /* Def. write data size <= 8192 */
76 #define NFS_RSIZE       8192            /* Def. read data size <= 8192 */
77 #define NFS_READDIRSIZE 8192            /* Def. readdir size */
78 #define NFS_DEFRAHEAD   1               /* Def. read ahead # blocks */
79 #define NFS_MAXRAHEAD   16              /* Max. read ahead # blocks */
80 #define NFS_MAXASYNCDAEMON      64      /* Max. number async_daemons runnable */
81 #define NFS_MAXUIDHASH  64              /* Max. # of hashed uid entries/mp */
82 #ifndef NFSRV_LEASE
83 #define NFSRV_LEASE             120     /* Lease time in seconds for V4 */
84 #endif                                  /* assigned to nfsrv_lease */
85 #ifndef NFSRV_STALELEASE
86 #define NFSRV_STALELEASE        (5 * nfsrv_lease)
87 #endif
88 #ifndef NFSRV_MOULDYLEASE
89 #define NFSRV_MOULDYLEASE       604800  /* One week (in sec) */
90 #endif
91 #ifndef NFSCLIENTHASHSIZE
92 #define NFSCLIENTHASHSIZE       20      /* Size of server client hash table */
93 #endif
94 #ifndef NFSLOCKHASHSIZE
95 #define NFSLOCKHASHSIZE         20      /* Size of server nfslock hash table */
96 #endif
97 #ifndef NFSSESSIONHASHSIZE
98 #define NFSSESSIONHASHSIZE      20      /* Size of server session hash table */
99 #endif
100 #define NFSSTATEHASHSIZE        10      /* Size of server stateid hash table */
101 #define NFSLAYOUTHIGHWATER      1000000 /* Upper limit for # of layouts */
102 #ifndef NFSCLDELEGHIGHWATER
103 #define NFSCLDELEGHIGHWATER     10000   /* limit for client delegations */
104 #endif
105 #ifndef NFSCLLAYOUTHIGHWATER
106 #define NFSCLLAYOUTHIGHWATER    10000   /* limit for client pNFS layouts */
107 #endif
108 #ifndef NFSNOOPEN                       /* Inactive open owner (sec) */
109 #define NFSNOOPEN               120
110 #endif
111 #define NFSRV_LEASEDELTA        15      /* # of seconds to delay beyond lease */
112 #define NFS_IDMAXSIZE           4       /* max sizeof (in_addr_t) */
113 #ifndef NFSRVCACHE_UDPTIMEOUT
114 #define NFSRVCACHE_UDPTIMEOUT   30      /* # of sec to hold cached rpcs(udp) */
115 #endif
116 #ifndef NFSRVCACHE_UDPHIGHWATER
117 #define NFSRVCACHE_UDPHIGHWATER 500     /* Max # of udp cache entries */
118 #endif
119 #ifndef NFSRVCACHE_TCPTIMEOUT
120 #define NFSRVCACHE_TCPTIMEOUT   (3600*12) /*#of sec to hold cached rpcs(tcp) */
121 #endif
122 #ifndef NFSRVCACHE_FLOODLEVEL
123 #define NFSRVCACHE_FLOODLEVEL   16384   /* Very high water mark for cache */
124 #endif
125 #ifndef NFSRV_CLIENTHIGHWATER
126 #define NFSRV_CLIENTHIGHWATER   1000
127 #endif
128 #ifndef NFSRV_MAXDUMPLIST
129 #define NFSRV_MAXDUMPLIST       10000
130 #endif
131 #ifndef NFS_ACCESSCACHESIZE
132 #define NFS_ACCESSCACHESIZE     8
133 #endif
134 #define NFSV4_CBPORT    7745            /* Callback port for testing */
135
136 /*
137  * This macro defines the high water mark for issuing V4 delegations.
138  * (It is currently set at a conservative 20% of nfsrv_v4statelimit. This
139  *  may want to increase when clients can make more effective use of
140  *  delegations.)
141  */
142 #define NFSRV_V4DELEGLIMIT(c) (((c) * 5) > nfsrv_v4statelimit)
143
144 #define NFS_READDIRBLKSIZ       DIRBLKSIZ       /* Minimal nm_readdirsize */
145
146 /*
147  * Oddballs
148  */
149 #define NFS_CMPFH(n, f, s)                                              \
150     ((n)->n_fhp->nfh_len == (s) && !NFSBCMP((n)->n_fhp->nfh_fh, (caddr_t)(f), (s)))
151 #define NFSRV_CMPFH(nf, ns, f, s)                                       \
152         ((ns) == (s) && !NFSBCMP((caddr_t)(nf), (caddr_t)(f), (s)))
153 #define NFS_CMPTIME(t1, t2)                                             \
154         ((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec == (t2).tv_nsec)
155 #define NFS_SETTIME(t) do {                                             \
156         (t).tv_sec = time.tv_sec; (t).tv_nsec = 1000 * time.tv_usec; } while (0)
157 #define NFS_SRVMAXDATA(n)                                               \
158                 (((n)->nd_flag & (ND_NFSV3 | ND_NFSV4)) ?               \
159                  NFS_SRVMAXIO : NFS_V2MAXDATA)
160 #define NFS64BITSSET    0xffffffffffffffffull
161 #define NFS64BITSMINUS1 0xfffffffffffffffeull
162
163 /*
164  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd, mount_nfs
165  * and nfsloaduser should ever try and use it.
166  */
167 struct nfsd_addsock_args {
168         int     sock;           /* Socket to serve */
169         caddr_t name;           /* Client addr for connection based sockets */
170         int     namelen;        /* Length of name */
171 };
172
173 /*
174  * nfsd argument for new krpc.
175  * (New version supports pNFS, indicated by NFSSVC_NEWSTRUCT flag.)
176  */
177 struct nfsd_nfsd_args {
178         const char *principal;  /* GSS-API service principal name */
179         int     minthreads;     /* minimum service thread count */
180         int     maxthreads;     /* maximum service thread count */
181         int     version;        /* Allow multiple variants */
182         char    *addr;          /* pNFS DS addresses */
183         int     addrlen;        /* Length of addrs */
184         char    *dnshost;       /* DNS names for DS addresses */
185         int     dnshostlen;     /* Length of DNS names */
186         char    *dspath;        /* DS Mount path on MDS */
187         int     dspathlen;      /* Length of DS Mount path on MDS */
188         int     mirrorcnt;      /* Number of mirrors to create on DSs */
189 };
190
191 /*
192  * NFSDEV_MAXMIRRORS - Maximum level of mirroring for a DS.
193  * (Most will only put files on two DSs, but this setting allows up to 4.)
194  * NFSDEV_MAXVERS - maximum number of NFS versions supported by Flex File.
195  */
196 #define NFSDEV_MAXMIRRORS       4
197 #define NFSDEV_MAXVERS          4
198
199 struct nfsd_pnfsd_args {
200         int     op;             /* Which pNFSd op to perform. */
201         char    *mdspath;       /* Path of MDS file. */
202         char    *dspath;        /* Path of recovered DS mounted on dir. */
203         char    *curdspath;     /* Path of current DS mounted on dir. */
204 };
205
206 #define PNFSDOP_DELDSSERVER     1
207 #define PNFSDOP_COPYMR          2
208
209 /* Old version. */
210 struct nfsd_nfsd_oargs {
211         const char *principal;  /* GSS-API service principal name */
212         int     minthreads;     /* minimum service thread count */
213         int     maxthreads;     /* maximum service thread count */
214 };
215
216 /*
217  * Arguments for use by the callback daemon.
218  */
219 struct nfsd_nfscbd_args {
220         const char *principal;  /* GSS-API service principal name */
221 };
222
223 struct nfscbd_args {
224         int     sock;           /* Socket to serve */
225         caddr_t name;           /* Client addr for connection based sockets */
226         int     namelen;        /* Length of name */
227         u_short port;           /* Port# for callbacks */
228 };
229
230 struct nfsd_idargs {
231         int             nid_flag;       /* Flags (see below) */
232         uid_t           nid_uid;        /* user/group id */
233         gid_t           nid_gid;
234         int             nid_usermax;    /* Upper bound on user name cache */
235         int             nid_usertimeout;/* User name timeout (minutes) */
236         u_char          *nid_name;      /* Name */
237         int             nid_namelen;    /* and its length */
238         gid_t           *nid_grps;      /* and the list */
239         int             nid_ngroup;     /* Size of groups list */
240 };
241
242 struct nfsd_oidargs {
243         int             nid_flag;       /* Flags (see below) */
244         uid_t           nid_uid;        /* user/group id */
245         gid_t           nid_gid;
246         int             nid_usermax;    /* Upper bound on user name cache */
247         int             nid_usertimeout;/* User name timeout (minutes) */
248         u_char          *nid_name;      /* Name */
249         int             nid_namelen;    /* and its length */
250 };
251
252 struct nfsd_clid {
253         int             nclid_idlen;    /* Length of client id */
254         u_char          nclid_id[NFSV4_OPAQUELIMIT]; /* and name */
255 };
256
257 struct nfsd_dumplist {
258         int             ndl_size;       /* Number of elements */
259         void            *ndl_list;      /* and the list of elements */
260 };
261
262 struct nfsd_dumpclients {
263         u_int32_t       ndcl_flags;             /* LCL_xxx flags */
264         u_int32_t       ndcl_nopenowners;       /* Number of openowners */
265         u_int32_t       ndcl_nopens;            /* and opens */
266         u_int32_t       ndcl_nlockowners;       /* and of lockowners */
267         u_int32_t       ndcl_nlocks;            /* and of locks */
268         u_int32_t       ndcl_ndelegs;           /* and of delegations */
269         u_int32_t       ndcl_nolddelegs;        /* and old delegations */
270         sa_family_t     ndcl_addrfam;           /* Callback address */
271         union {
272                 struct in_addr sin_addr;
273                 struct in6_addr sin6_addr;
274         } ndcl_cbaddr;
275         struct nfsd_clid ndcl_clid;     /* and client id */
276 };
277
278 struct nfsd_dumplocklist {
279         char            *ndllck_fname;  /* File Name */
280         int             ndllck_size;    /* Number of elements */
281         void            *ndllck_list;   /* and the list of elements */
282 };
283
284 struct nfsd_dumplocks {
285         u_int32_t       ndlck_flags;            /* state flags NFSLCK_xxx */
286         nfsv4stateid_t  ndlck_stateid;          /* stateid */
287         u_int64_t       ndlck_first;            /* lock byte range */
288         u_int64_t       ndlck_end;
289         struct nfsd_clid ndlck_owner;           /* Owner of open/lock */
290         sa_family_t     ndlck_addrfam;          /* Callback address */
291         union {
292                 struct in_addr sin_addr;
293                 struct in6_addr sin6_addr;
294         } ndlck_cbaddr;
295         struct nfsd_clid ndlck_clid;    /* and client id */
296 };
297
298 /*
299  * Structure for referral information.
300  */
301 struct nfsreferral {
302         u_char          *nfr_srvlist;   /* List of servers */
303         int             nfr_srvcnt;     /* number of servers */
304         vnode_t         nfr_vp; /* vnode for referral */
305         uint64_t        nfr_dfileno;    /* assigned dir inode# */
306 };
307
308 /*
309  * Flags for lc_flags and opsflags for nfsrv_getclient().
310  */
311 #define LCL_NEEDSCONFIRM        0x00000001
312 #define LCL_DONTCLEAN           0x00000002
313 #define LCL_WAKEUPWANTED        0x00000004
314 #define LCL_TCPCALLBACK         0x00000008
315 #define LCL_CALLBACKSON         0x00000010
316 #define LCL_INDEXNOTOK          0x00000020
317 #define LCL_STAMPEDSTABLE       0x00000040
318 #define LCL_EXPIREIT            0x00000080
319 #define LCL_CBDOWN              0x00000100
320 #define LCL_KERBV               0x00000400
321 #define LCL_NAME                0x00000800
322 #define LCL_NEEDSCBNULL         0x00001000
323 #define LCL_GSSINTEGRITY        0x00002000
324 #define LCL_GSSPRIVACY          0x00004000
325 #define LCL_ADMINREVOKED        0x00008000
326 #define LCL_RECLAIMCOMPLETE     0x00010000
327 #define LCL_NFSV41              0x00020000
328 #define LCL_DONEBINDCONN        0x00040000
329
330 #define LCL_GSS         LCL_KERBV       /* Or of all mechs */
331
332 /*
333  * Bits for flags in nfslock and nfsstate.
334  * The access, deny, NFSLCK_READ and NFSLCK_WRITE bits must be defined as
335  * below, in the correct order, so the shifts work for tests.
336  */
337 #define NFSLCK_READACCESS       0x00000001
338 #define NFSLCK_WRITEACCESS      0x00000002
339 #define NFSLCK_ACCESSBITS       (NFSLCK_READACCESS | NFSLCK_WRITEACCESS)
340 #define NFSLCK_SHIFT            2
341 #define NFSLCK_READDENY         0x00000004
342 #define NFSLCK_WRITEDENY        0x00000008
343 #define NFSLCK_DENYBITS         (NFSLCK_READDENY | NFSLCK_WRITEDENY)
344 #define NFSLCK_SHAREBITS                                                \
345     (NFSLCK_READACCESS|NFSLCK_WRITEACCESS|NFSLCK_READDENY|NFSLCK_WRITEDENY)
346 #define NFSLCK_LOCKSHIFT        4
347 #define NFSLCK_READ             0x00000010
348 #define NFSLCK_WRITE            0x00000020
349 #define NFSLCK_BLOCKING         0x00000040
350 #define NFSLCK_RECLAIM          0x00000080
351 #define NFSLCK_OPENTOLOCK       0x00000100
352 #define NFSLCK_TEST             0x00000200
353 #define NFSLCK_LOCK             0x00000400
354 #define NFSLCK_UNLOCK           0x00000800
355 #define NFSLCK_OPEN             0x00001000
356 #define NFSLCK_CLOSE            0x00002000
357 #define NFSLCK_CHECK            0x00004000
358 #define NFSLCK_RELEASE          0x00008000
359 #define NFSLCK_NEEDSCONFIRM     0x00010000
360 #define NFSLCK_CONFIRM          0x00020000
361 #define NFSLCK_DOWNGRADE        0x00040000
362 #define NFSLCK_DELEGREAD        0x00080000
363 #define NFSLCK_DELEGWRITE       0x00100000
364 #define NFSLCK_DELEGCUR         0x00200000
365 #define NFSLCK_DELEGPREV        0x00400000
366 #define NFSLCK_OLDDELEG         0x00800000
367 #define NFSLCK_DELEGRECALL      0x01000000
368 #define NFSLCK_SETATTR          0x02000000
369 #define NFSLCK_DELEGPURGE       0x04000000
370 #define NFSLCK_DELEGRETURN      0x08000000
371 #define NFSLCK_WANTWDELEG       0x10000000
372 #define NFSLCK_WANTRDELEG       0x20000000
373 #define NFSLCK_WANTNODELEG      0x40000000
374 #define NFSLCK_WANTBITS                                                 \
375     (NFSLCK_WANTWDELEG | NFSLCK_WANTRDELEG | NFSLCK_WANTNODELEG)
376
377 /* And bits for nid_flag */
378 #define NFSID_INITIALIZE        0x0001
379 #define NFSID_ADDUID            0x0002
380 #define NFSID_DELUID            0x0004
381 #define NFSID_ADDUSERNAME       0x0008
382 #define NFSID_DELUSERNAME       0x0010
383 #define NFSID_ADDGID            0x0020
384 #define NFSID_DELGID            0x0040
385 #define NFSID_ADDGROUPNAME      0x0080
386 #define NFSID_DELGROUPNAME      0x0100
387
388 /*
389  * fs.nfs sysctl(3) identifiers
390  */
391 #define NFS_NFSSTATS    1               /* struct: struct nfsstats */
392
393 /*
394  * Here is the definition of the attribute bits array and macros that
395  * manipulate it.
396  * THE MACROS MUST BE MANUALLY MODIFIED IF NFSATTRBIT_MAXWORDS CHANGES!!
397  * It is (NFSATTRBIT_MAX + 31) / 32.
398  */
399 #define NFSATTRBIT_MAXWORDS     3
400
401 typedef struct {
402         u_int32_t bits[NFSATTRBIT_MAXWORDS];
403 } nfsattrbit_t;
404
405 #define NFSZERO_ATTRBIT(b) do {                                         \
406         (b)->bits[0] = 0;                                               \
407         (b)->bits[1] = 0;                                               \
408         (b)->bits[2] = 0;                                               \
409 } while (0)
410
411 #define NFSSET_ATTRBIT(t, f) do {                                       \
412         (t)->bits[0] = (f)->bits[0];                                    \
413         (t)->bits[1] = (f)->bits[1];                                    \
414         (t)->bits[2] = (f)->bits[2];                                    \
415 } while (0)
416
417 #define NFSSETSUPP_ATTRBIT(b) do {                                      \
418         (b)->bits[0] = NFSATTRBIT_SUPP0;                                \
419         (b)->bits[1] = (NFSATTRBIT_SUPP1 | NFSATTRBIT_SUPPSETONLY);     \
420         (b)->bits[2] = NFSATTRBIT_SUPP2;                                \
421 } while (0)
422
423 #define NFSISSET_ATTRBIT(b, p)  ((b)->bits[(p) / 32] & (1 << ((p) % 32)))
424 #define NFSSETBIT_ATTRBIT(b, p) ((b)->bits[(p) / 32] |= (1 << ((p) % 32)))
425 #define NFSCLRBIT_ATTRBIT(b, p) ((b)->bits[(p) / 32] &= ~(1 << ((p) % 32)))
426
427 #define NFSCLRALL_ATTRBIT(b, a) do {                                    \
428         (b)->bits[0] &= ~((a)->bits[0]);                                \
429         (b)->bits[1] &= ~((a)->bits[1]);                                \
430         (b)->bits[2] &= ~((a)->bits[2]);                                \
431 } while (0)
432
433 #define NFSCLRNOT_ATTRBIT(b, a) do {                                    \
434         (b)->bits[0] &= ((a)->bits[0]);                                 \
435         (b)->bits[1] &= ((a)->bits[1]);                                 \
436         (b)->bits[2] &= ((a)->bits[2]);                                 \
437 } while (0)
438
439 #define NFSCLRNOTFILLABLE_ATTRBIT(b) do {                               \
440         (b)->bits[0] &= NFSATTRBIT_SUPP0;                               \
441         (b)->bits[1] &= NFSATTRBIT_SUPP1;                               \
442         (b)->bits[2] &= NFSATTRBIT_SUPP2;                               \
443 } while (0)
444
445 #define NFSCLRNOTSETABLE_ATTRBIT(b) do {                                \
446         (b)->bits[0] &= NFSATTRBIT_SETABLE0;                            \
447         (b)->bits[1] &= NFSATTRBIT_SETABLE1;                            \
448         (b)->bits[2] &= NFSATTRBIT_SETABLE2;                            \
449 } while (0)
450
451 #define NFSNONZERO_ATTRBIT(b)   ((b)->bits[0] || (b)->bits[1] || (b)->bits[2])
452 #define NFSEQUAL_ATTRBIT(b, p)  ((b)->bits[0] == (p)->bits[0] &&        \
453         (b)->bits[1] == (p)->bits[1] && (b)->bits[2] == (p)->bits[2])
454
455 #define NFSGETATTR_ATTRBIT(b) do {                                      \
456         (b)->bits[0] = NFSATTRBIT_GETATTR0;                             \
457         (b)->bits[1] = NFSATTRBIT_GETATTR1;                             \
458         (b)->bits[2] = NFSATTRBIT_GETATTR2;                             \
459 } while (0)
460
461 #define NFSWCCATTR_ATTRBIT(b) do {                                      \
462         (b)->bits[0] = NFSATTRBIT_WCCATTR0;                             \
463         (b)->bits[1] = NFSATTRBIT_WCCATTR1;                             \
464         (b)->bits[2] = NFSATTRBIT_WCCATTR2;                             \
465 } while (0)
466
467 #define NFSWRITEGETATTR_ATTRBIT(b) do {                                 \
468         (b)->bits[0] = NFSATTRBIT_WRITEGETATTR0;                        \
469         (b)->bits[1] = NFSATTRBIT_WRITEGETATTR1;                        \
470         (b)->bits[2] = NFSATTRBIT_WRITEGETATTR2;                        \
471 } while (0)
472
473 #define NFSCBGETATTR_ATTRBIT(b, c) do {                                 \
474         (c)->bits[0] = ((b)->bits[0] & NFSATTRBIT_CBGETATTR0);          \
475         (c)->bits[1] = ((b)->bits[1] & NFSATTRBIT_CBGETATTR1);          \
476         (c)->bits[2] = ((b)->bits[2] & NFSATTRBIT_CBGETATTR2);          \
477 } while (0)
478
479 #define NFSPATHCONF_GETATTRBIT(b) do {                                  \
480         (b)->bits[0] = NFSGETATTRBIT_PATHCONF0;                         \
481         (b)->bits[1] = NFSGETATTRBIT_PATHCONF1;                         \
482         (b)->bits[2] = NFSGETATTRBIT_PATHCONF2;                         \
483 } while (0)
484
485 #define NFSSTATFS_GETATTRBIT(b) do {                                    \
486         (b)->bits[0] = NFSGETATTRBIT_STATFS0;                           \
487         (b)->bits[1] = NFSGETATTRBIT_STATFS1;                           \
488         (b)->bits[2] = NFSGETATTRBIT_STATFS2;                           \
489 } while (0)
490
491 #define NFSISSETSTATFS_ATTRBIT(b)                                       \
492                 (((b)->bits[0] & NFSATTRBIT_STATFS0) ||                 \
493                  ((b)->bits[1] & NFSATTRBIT_STATFS1) ||                 \
494                  ((b)->bits[2] & NFSATTRBIT_STATFS2))
495
496 #define NFSCLRSTATFS_ATTRBIT(b) do {                                    \
497         (b)->bits[0] &= ~NFSATTRBIT_STATFS0;                            \
498         (b)->bits[1] &= ~NFSATTRBIT_STATFS1;                            \
499         (b)->bits[2] &= ~NFSATTRBIT_STATFS2;                            \
500 } while (0)
501
502 #define NFSREADDIRPLUS_ATTRBIT(b) do {                                  \
503         (b)->bits[0] = NFSATTRBIT_READDIRPLUS0;                         \
504         (b)->bits[1] = NFSATTRBIT_READDIRPLUS1;                         \
505         (b)->bits[2] = NFSATTRBIT_READDIRPLUS2;                         \
506 } while (0)
507
508 #define NFSREFERRAL_ATTRBIT(b) do {                                     \
509         (b)->bits[0] = NFSATTRBIT_REFERRAL0;                            \
510         (b)->bits[1] = NFSATTRBIT_REFERRAL1;                            \
511         (b)->bits[2] = NFSATTRBIT_REFERRAL2;                            \
512 } while (0)
513
514 /*
515  * Store uid, gid creds that were used when the stateid was acquired.
516  * The RPC layer allows NFS_MAXGRPS + 1 groups to go out on the wire,
517  * so that's how many gets stored here.
518  */
519 struct nfscred {
520         uid_t           nfsc_uid;
521         gid_t           nfsc_groups[NFS_MAXGRPS + 1];
522         int             nfsc_ngroups;
523 };
524
525 /*
526  * Constants that define the file handle for the V4 root directory.
527  * (The FSID must never be used by other file systems that are exported.)
528  */
529 #define NFSV4ROOT_FSID0         ((int32_t) -1)
530 #define NFSV4ROOT_FSID1         ((int32_t) -1)
531 #define NFSV4ROOT_REFERRAL      ((int32_t) -2)
532 #define NFSV4ROOT_INO           2       /* It's traditional */
533 #define NFSV4ROOT_GEN           1
534
535 /*
536  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
537  * What should be in this set is open to debate, but I believe that since
538  * I/O system calls on ufs are never interrupted by signals the set should
539  * be minimal. My reasoning is that many current programs that use signals
540  * such as SIGALRM will not expect file I/O system calls to be interrupted
541  * by them and break.
542  */
543 #if defined(_KERNEL) || defined(KERNEL)
544
545 struct uio; struct buf; struct vattr; struct nameidata; /* XXX */
546
547 /*
548  * Socket errors ignored for connectionless sockets?
549  * For now, ignore them all
550  */
551 #define NFSIGNORE_SOERROR(s, e)                                         \
552                 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
553                 ((s) & PR_CONNREQUIRED) == 0)
554
555
556 /*
557  * This structure holds socket information for a connection. Used by the
558  * client and the server for callbacks.
559  */
560 struct nfssockreq {
561         NFSSOCKADDR_T   nr_nam;
562         int             nr_sotype;
563         int             nr_soproto;
564         int             nr_soflags;
565         struct ucred    *nr_cred;
566         int             nr_lock;
567         NFSMUTEX_T      nr_mtx;
568         u_int32_t       nr_prog;
569         u_int32_t       nr_vers;
570         struct __rpc_client *nr_client;
571         AUTH            *nr_auth;
572 };
573
574 /*
575  * And associated nr_lock bits.
576  */
577 #define NFSR_SNDLOCK            0x01
578 #define NFSR_WANTSND            0x02
579 #define NFSR_RCVLOCK            0x04
580 #define NFSR_WANTRCV            0x08
581 #define NFSR_RESERVEDPORT       0x10
582 #define NFSR_LOCALHOST          0x20
583
584 /*
585  * Queue head for nfsreq's
586  */
587 TAILQ_HEAD(nfsreqhead, nfsreq);
588
589 /* This is the only nfsreq R_xxx flag still used. */
590 #define R_DONTRECOVER   0x00000100      /* don't initiate recovery when this
591                                            rpc gets a stale state reply */
592
593 /*
594  * Network address hash list element
595  */
596 union nethostaddr {
597         struct in_addr  had_inet;
598         struct in6_addr had_inet6;
599 };
600
601 /*
602  * Structure of list of mechanisms.
603  */
604 struct nfsgss_mechlist {
605         int     len;
606         const u_char    *str;
607         int     totlen;
608 };
609 #define KERBV_MECH      0       /* position in list */
610
611 /*
612  * This structure is used by the server for describing each request.
613  */
614 struct nfsrv_descript {
615         mbuf_t                  nd_mrep;        /* Request mbuf list */
616         mbuf_t                  nd_md;          /* Current dissect mbuf */
617         mbuf_t                  nd_mreq;        /* Reply mbuf list */
618         mbuf_t                  nd_mb;          /* Current build mbuf */
619         NFSSOCKADDR_T           nd_nam;         /* and socket addr */
620         NFSSOCKADDR_T           nd_nam2;        /* return socket addr */
621         caddr_t                 nd_dpos;        /* Current dissect pos */
622         caddr_t                 nd_bpos;        /* Current build pos */
623         u_int64_t               nd_flag;        /* nd_flag */
624         u_int16_t               nd_procnum;     /* RPC # */
625         u_int32_t               nd_repstat;     /* Reply status */
626         int                     *nd_errp;       /* Pointer to ret status */
627         u_int32_t               nd_retxid;      /* Reply xid */
628         struct nfsrvcache       *nd_rp;         /* Assoc. cache entry */
629         fhandle_t               nd_fh;          /* File handle */
630         struct ucred            *nd_cred;       /* Credentials */
631         uid_t                   nd_saveduid;    /* Saved uid */
632         u_int64_t               nd_sockref;     /* Rcv socket ref# */
633         u_int64_t               nd_compref;     /* Compound RPC ref# */
634         time_t                  nd_tcpconntime; /* Time TCP connection est. */
635         nfsquad_t               nd_clientid;    /* Implied clientid */
636         int                     nd_gssnamelen;  /* principal name length */
637         char                    *nd_gssname;    /* principal name */
638         uint32_t                *nd_slotseq;    /* ptr to slot seq# in req */
639         uint8_t                 nd_sessionid[NFSX_V4SESSIONID]; /* Session id */
640         uint32_t                nd_slotid;      /* Slotid for this RPC */
641         SVCXPRT                 *nd_xprt;       /* Server RPC handle */
642         uint32_t                *nd_sequence;   /* Sequence Op. ptr */
643         nfsv4stateid_t          nd_curstateid;  /* Current StateID */
644         nfsv4stateid_t          nd_savedcurstateid; /* Saved Current StateID */
645 };
646
647 #define nd_princlen     nd_gssnamelen
648 #define nd_principal    nd_gssname
649
650 /* Bits for "nd_flag" */
651 #define ND_DONTSAVEREPLY        0x00000001
652 #define ND_SAVEREPLY            0x00000002
653 #define ND_NFSV2                0x00000004
654 #define ND_NFSV3                0x00000008
655 #define ND_NFSV4                0x00000010
656 #define ND_KERBV                0x00000020
657 #define ND_GSSINTEGRITY         0x00000040
658 #define ND_GSSPRIVACY           0x00000080
659 #define ND_WINDOWVERF           0x00000100
660 #define ND_GSSINITREPLY         0x00000200
661 #define ND_STREAMSOCK           0x00000400
662 #define ND_PUBLOOKUP            0x00000800
663 #define ND_USEGSSNAME           0x00001000
664 #define ND_SAMETCPCONN          0x00002000
665 #define ND_IMPLIEDCLID          0x00004000
666 #define ND_NOMOREDATA           0x00008000
667 #define ND_V4WCCATTR            0x00010000
668 #define ND_NFSCB                0x00020000
669 #define ND_AUTHNONE             0x00040000
670 #define ND_EXAUTHSYS            0x00080000
671 #define ND_EXGSS                0x00100000
672 #define ND_EXGSSINTEGRITY       0x00200000
673 #define ND_EXGSSPRIVACY         0x00400000
674 #define ND_INCRSEQID            0x00800000
675 #define ND_NFSCL                0x01000000
676 #define ND_NFSV41               0x02000000
677 #define ND_HASSEQUENCE          0x04000000
678 #define ND_CACHETHIS            0x08000000
679 #define ND_LASTOP               0x10000000
680 #define ND_LOOPBADSESS          0x20000000
681 #define ND_DSSERVER             0x40000000
682 #define ND_CURSTATEID           0x80000000
683 #define ND_SAVEDCURSTATEID      0x100000000
684 #define ND_HASSLOTID            0x200000000
685
686 /*
687  * ND_GSS should be the "or" of all GSS type authentications.
688  */
689 #define ND_GSS          (ND_KERBV)
690
691 struct nfsv4_opflag {
692         int     retfh;
693         int     needscfh;
694         int     savereply;
695         int     modifyfs;
696         int     lktype;
697         int     needsseq;
698         int     loopbadsess;
699 };
700
701 /*
702  * Flags used to indicate what to do w.r.t. seqid checking.
703  */
704 #define NFSRVSEQID_FIRST        0x01
705 #define NFSRVSEQID_LAST         0x02
706 #define NFSRVSEQID_OPEN         0x04
707
708 /*
709  * assign a doubly linked list to a new head
710  * and prepend one list into another.
711  */
712 #define LIST_NEWHEAD(nhead, ohead, field) do {                          \
713         if (((nhead)->lh_first = (ohead)->lh_first) != NULL)            \
714                 (ohead)->lh_first->field.le_prev = &(nhead)->lh_first;  \
715         (ohead)->lh_first = NULL;                                       \
716     } while (0)
717
718 #define LIST_PREPEND(head, phead, lelm, field) do {                     \
719         if ((head)->lh_first != NULL) {                                 \
720                 (lelm)->field.le_next = (head)->lh_first;               \
721                 (lelm)->field.le_next->field.le_prev =                  \
722                     &(lelm)->field.le_next;                             \
723         }                                                               \
724         (head)->lh_first = (phead)->lh_first;                           \
725         (head)->lh_first->field.le_prev = &(head)->lh_first;            \
726     } while (0)
727
728 /*
729  * File handle structure for client. Malloc'd to the correct length with
730  * malloc type M_NFSFH.
731  */
732 struct nfsfh {
733         u_int16_t       nfh_len;        /* Length of file handle */
734         u_int8_t        nfh_fh[1];      /* and the file handle */
735 };
736
737 /*
738  * File handle structure for server. The NFSRV_MAXFH constant is
739  * set in nfsdport.h. I use a 32bit length, so that alignment is
740  * preserved.
741  */
742 struct nfsrvfh {
743         u_int32_t       nfsrvfh_len;
744         u_int8_t        nfsrvfh_data[NFSRV_MAXFH];
745 };
746
747 /*
748  * This structure is used for sleep locks on the NFSv4 nfsd threads and
749  * NFSv4 client data structures.
750  */
751 struct nfsv4lock {
752         u_int32_t       nfslock_usecnt;
753         u_int8_t        nfslock_lock;
754 };
755 #define NFSV4LOCK_LOCK          0x01
756 #define NFSV4LOCK_LOCKWANTED    0x02
757 #define NFSV4LOCK_WANTED        0x04
758
759 /*
760  * Values for the override argument for nfsvno_accchk().
761  */
762 #define NFSACCCHK_NOOVERRIDE            0
763 #define NFSACCCHK_ALLOWROOT             1
764 #define NFSACCCHK_ALLOWOWNER            2
765
766 /*
767  * and values for the vpislocked argument for nfsvno_accchk().
768  */
769 #define NFSACCCHK_VPNOTLOCKED           0
770 #define NFSACCCHK_VPISLOCKED            1
771
772 /*
773  * Slot for the NFSv4.1 Sequence Op.
774  */
775 struct nfsslot {
776         int             nfssl_inprog;
777         uint32_t        nfssl_seq;
778         struct mbuf     *nfssl_reply;
779 };
780
781 #endif  /* _KERNEL */
782
783 #endif  /* _NFS_NFS_H */