1e3d3490rmacklem/*-
24736ccfpfg * SPDX-License-Identifier: BSD-3-Clause
34736ccfpfg *
4e3d3490rmacklem * Copyright (c) 1989, 1993
5e3d3490rmacklem *	The Regents of the University of California.  All rights reserved.
6e3d3490rmacklem *
7e3d3490rmacklem * This code is derived from software contributed to Berkeley by
8e3d3490rmacklem * Rick Macklem at The University of Guelph.
9e3d3490rmacklem *
10e3d3490rmacklem * Redistribution and use in source and binary forms, with or without
11e3d3490rmacklem * modification, are permitted provided that the following conditions
12e3d3490rmacklem * are met:
13e3d3490rmacklem * 1. Redistributions of source code must retain the above copyright
14e3d3490rmacklem *    notice, this list of conditions and the following disclaimer.
15e3d3490rmacklem * 2. Redistributions in binary form must reproduce the above copyright
16e3d3490rmacklem *    notice, this list of conditions and the following disclaimer in the
17e3d3490rmacklem *    documentation and/or other materials provided with the distribution.
187e6cabdimp * 3. Neither the name of the University nor the names of its contributors
19e3d3490rmacklem *    may be used to endorse or promote products derived from this software
20e3d3490rmacklem *    without specific prior written permission.
21e3d3490rmacklem *
22e3d3490rmacklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23e3d3490rmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24e3d3490rmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25e3d3490rmacklem * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26e3d3490rmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27e3d3490rmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28e3d3490rmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29e3d3490rmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30e3d3490rmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31e3d3490rmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32e3d3490rmacklem * SUCH DAMAGE.
33e3d3490rmacklem *
34e3d3490rmacklem * $FreeBSD$
35e3d3490rmacklem */
36e3d3490rmacklem
37e3d3490rmacklem#ifndef _NFS_NFS_H_
38e3d3490rmacklem#define	_NFS_NFS_H_
39e3d3490rmacklem/*
40e3d3490rmacklem * Tunable constants for nfs
41e3d3490rmacklem */
42e3d3490rmacklem
43e3d3490rmacklem#define	NFS_MAXIOVEC	34
44d9f6c6fmav#define	NFS_TICKINTVL	500		/* Desired time for a tick (msec) */
45e3d3490rmacklem#define	NFS_HZ		(hz / nfscl_ticks) /* Ticks/sec */
46e3d3490rmacklem#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
47e3d3490rmacklem#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
48e3d3490rmacklem#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
49e3d3490rmacklem#define	NFS_TCPTIMEO	300		/* TCP timeout */
50e3d3490rmacklem#define	NFS_MAXRCVTIMEO	60		/* 1 minute in seconds */
51e3d3490rmacklem#define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
52e3d3490rmacklem#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
53e3d3490rmacklem#define	NFSV4_CALLBACKTIMEO (2 * NFS_HZ) /* Timeout in ticks */
54e3d3490rmacklem#define	NFSV4_CALLBACKRETRY 5		/* Number of retries before failure */
558c4948brmacklem#define	NFSV4_SLOTS	64		/* Number of slots, fore channel */
568c4948brmacklem#define	NFSV4_CBSLOTS	8		/* Number of slots, back channel */
57e3d3490rmacklem#define	NFSV4_CBRETRYCNT 4		/* # of CBRecall retries upon err */
58e3d3490rmacklem#define	NFSV4_UPCALLTIMEO (15 * NFS_HZ)	/* Timeout in ticks for upcalls */
59e3d3490rmacklem					/* to gssd or nfsuserd */
60e3d3490rmacklem#define	NFSV4_UPCALLRETRY 4		/* Number of retries before failure */
61e3d3490rmacklem#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
62e3d3490rmacklem#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
632599955rmacklem#define	NFS_RETRANS_TCP	2		/* Num of retrans for TCP soft mounts */
64e3d3490rmacklem#define	NFS_MAXGRPS	16		/* Max. size of groups list */
65e3d3490rmacklem#define	NFS_TRYLATERDEL	15		/* Maximum delay timeout (sec) */
66e3d3490rmacklem#ifndef NFS_REMOVETIMEO
67e3d3490rmacklem#define	NFS_REMOVETIMEO 15  /* # sec to wait for delegret in local syscall */
68e3d3490rmacklem#endif
69e3d3490rmacklem#ifndef NFS_MINATTRTIMO
70e3d3490rmacklem#define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
71e3d3490rmacklem#endif
72e3d3490rmacklem#ifndef NFS_MAXATTRTIMO
73e3d3490rmacklem#define	NFS_MAXATTRTIMO 60
74e3d3490rmacklem#endif
75e3d3490rmacklem#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
76e3d3490rmacklem#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
77e3d3490rmacklem#define	NFS_READDIRSIZE	8192		/* Def. readdir size */
7889d7244rmacklem#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
7989d7244rmacklem#define	NFS_MAXRAHEAD	16		/* Max. read ahead # blocks */
8089d7244rmacklem#define	NFS_MAXASYNCDAEMON 	64	/* Max. number async_daemons runnable */
81e3d3490rmacklem#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
82e3d3490rmacklem#ifndef	NFSRV_LEASE
83e3d3490rmacklem#define	NFSRV_LEASE		120	/* Lease time in seconds for V4 */
84e3d3490rmacklem#endif					/* assigned to nfsrv_lease */
85e3d3490rmacklem#ifndef NFSRV_STALELEASE
86e3d3490rmacklem#define	NFSRV_STALELEASE	(5 * nfsrv_lease)
87e3d3490rmacklem#endif
88e3d3490rmacklem#ifndef NFSRV_MOULDYLEASE
89e3d3490rmacklem#define	NFSRV_MOULDYLEASE	604800	/* One week (in sec) */
90e3d3490rmacklem#endif
91e3d3490rmacklem#ifndef NFSCLIENTHASHSIZE
92e3d3490rmacklem#define	NFSCLIENTHASHSIZE	20	/* Size of server client hash table */
93e3d3490rmacklem#endif
94e3d3490rmacklem#ifndef NFSLOCKHASHSIZE
95e3d3490rmacklem#define	NFSLOCKHASHSIZE		20	/* Size of server nfslock hash table */
96e3d3490rmacklem#endif
978c4948brmacklem#ifndef NFSSESSIONHASHSIZE
988c4948brmacklem#define	NFSSESSIONHASHSIZE	20	/* Size of server session hash table */
998c4948brmacklem#endif
100e3d3490rmacklem#define	NFSSTATEHASHSIZE	10	/* Size of server stateid hash table */
10177f312drmacklem#define	NFSLAYOUTHIGHWATER	1000000	/* Upper limit for # of layouts */
102e3d3490rmacklem#ifndef	NFSCLDELEGHIGHWATER
103e3d3490rmacklem#define	NFSCLDELEGHIGHWATER	10000	/* limit for client delegations */
104e3d3490rmacklem#endif
105c82d891rmacklem#ifndef	NFSCLLAYOUTHIGHWATER
106c82d891rmacklem#define	NFSCLLAYOUTHIGHWATER	10000	/* limit for client pNFS layouts */
107c82d891rmacklem#endif
108e3d3490rmacklem#ifndef NFSNOOPEN			/* Inactive open owner (sec) */
109e3d3490rmacklem#define	NFSNOOPEN		120
110e3d3490rmacklem#endif
111e3d3490rmacklem#define	NFSRV_LEASEDELTA	15	/* # of seconds to delay beyond lease */
112e3d3490rmacklem#define	NFS_IDMAXSIZE		4	/* max sizeof (in_addr_t) */
113e3d3490rmacklem#ifndef NFSRVCACHE_UDPTIMEOUT
114e3d3490rmacklem#define	NFSRVCACHE_UDPTIMEOUT	30	/* # of sec to hold cached rpcs(udp) */
115e3d3490rmacklem#endif
116e3d3490rmacklem#ifndef NFSRVCACHE_UDPHIGHWATER
117e3d3490rmacklem#define	NFSRVCACHE_UDPHIGHWATER	500	/* Max # of udp cache entries */
118e3d3490rmacklem#endif
119e3d3490rmacklem#ifndef NFSRVCACHE_TCPTIMEOUT
120e3d3490rmacklem#define	NFSRVCACHE_TCPTIMEOUT	(3600*12) /*#of sec to hold cached rpcs(tcp) */
121e3d3490rmacklem#endif
122e3d3490rmacklem#ifndef	NFSRVCACHE_FLOODLEVEL
123e3d3490rmacklem#define	NFSRVCACHE_FLOODLEVEL	16384	/* Very high water mark for cache */
124e3d3490rmacklem#endif
125e3d3490rmacklem#ifndef	NFSRV_CLIENTHIGHWATER
126e3d3490rmacklem#define	NFSRV_CLIENTHIGHWATER	1000
127e3d3490rmacklem#endif
128e3d3490rmacklem#ifndef	NFSRV_MAXDUMPLIST
129e3d3490rmacklem#define	NFSRV_MAXDUMPLIST	10000
130e3d3490rmacklem#endif
131e3d3490rmacklem#ifndef NFS_ACCESSCACHESIZE
132e3d3490rmacklem#define	NFS_ACCESSCACHESIZE	8
133e3d3490rmacklem#endif
134e3d3490rmacklem#define	NFSV4_CBPORT	7745		/* Callback port for testing */
135e3d3490rmacklem
136e3d3490rmacklem/*
137e3d3490rmacklem * This macro defines the high water mark for issuing V4 delegations.
1387c550carmacklem * (It is currently set at a conservative 20% of nfsrv_v4statelimit. This
139e3d3490rmacklem *  may want to increase when clients can make more effective use of
140e3d3490rmacklem *  delegations.)
141e3d3490rmacklem */
1427c550carmacklem#define	NFSRV_V4DELEGLIMIT(c) (((c) * 5) > nfsrv_v4statelimit)
143e3d3490rmacklem
144e3d3490rmacklem#define	NFS_READDIRBLKSIZ	DIRBLKSIZ	/* Minimal nm_readdirsize */
145e3d3490rmacklem
146e3d3490rmacklem/*
147e3d3490rmacklem * Oddballs
148e3d3490rmacklem */
149e3d3490rmacklem#define	NFS_CMPFH(n, f, s) 						\
150e3d3490rmacklem    ((n)->n_fhp->nfh_len == (s) && !NFSBCMP((n)->n_fhp->nfh_fh, (caddr_t)(f), (s)))
151e3d3490rmacklem#define	NFSRV_CMPFH(nf, ns, f, s) 					\
152e3d3490rmacklem	((ns) == (s) && !NFSBCMP((caddr_t)(nf), (caddr_t)(f), (s)))
153e3d3490rmacklem#define	NFS_CMPTIME(t1, t2) 						\
154e3d3490rmacklem	((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec == (t2).tv_nsec)
155e3d3490rmacklem#define	NFS_SETTIME(t) do { 						\
156e3d3490rmacklem	(t).tv_sec = time.tv_sec; (t).tv_nsec = 1000 * time.tv_usec; } while (0)
157e3d3490rmacklem#define	NFS_SRVMAXDATA(n) 						\
158e3d3490rmacklem		(((n)->nd_flag & (ND_NFSV3 | ND_NFSV4)) ? 		\
159b4d8a8drmacklem		 NFS_SRVMAXIO : NFS_V2MAXDATA)
160e3d3490rmacklem#define	NFS64BITSSET	0xffffffffffffffffull
161e3d3490rmacklem#define	NFS64BITSMINUS1	0xfffffffffffffffeull
162e3d3490rmacklem
163e3d3490rmacklem/*
164e3d3490rmacklem * Structures for the nfssvc(2) syscall. Not that anyone but nfsd, mount_nfs
165e3d3490rmacklem * and nfsloaduser should ever try and use it.
166e3d3490rmacklem */
167292f29frmacklemstruct nfsd_addsock_args {
168e3d3490rmacklem	int	sock;		/* Socket to serve */
169e3d3490rmacklem	caddr_t	name;		/* Client addr for connection based sockets */
170e3d3490rmacklem	int	namelen;	/* Length of name */
171e3d3490rmacklem};
172e3d3490rmacklem
173e3d3490rmacklem/*
174e3d3490rmacklem * nfsd argument for new krpc.
17577f312drmacklem * (New version supports pNFS, indicated by NFSSVC_NEWSTRUCT flag.)
176e3d3490rmacklem */
177e3d3490rmacklemstruct nfsd_nfsd_args {
178e3d3490rmacklem	const char *principal;	/* GSS-API service principal name */
179e3d3490rmacklem	int	minthreads;	/* minimum service thread count */
180e3d3490rmacklem	int	maxthreads;	/* maximum service thread count */
18177f312drmacklem	int	version;	/* Allow multiple variants */
18277f312drmacklem	char	*addr;		/* pNFS DS addresses */
18377f312drmacklem	int	addrlen;	/* Length of addrs */
18477f312drmacklem	char	*dnshost;	/* DNS names for DS addresses */
18577f312drmacklem	int	dnshostlen;	/* Length of DNS names */
18677f312drmacklem	char	*dspath;	/* DS Mount path on MDS */
18777f312drmacklem	int	dspathlen;	/* Length of DS Mount path on MDS */
18859f9a88rmacklem	char	*mdspath;	/* MDS mount for DS path on MDS */
18959f9a88rmacklem	int	mdspathlen;	/* Length of MDS mount for DS path on MDS */
19077f312drmacklem	int	mirrorcnt;	/* Number of mirrors to create on DSs */
191e3d3490rmacklem};
192e3d3490rmacklem
193e3d3490rmacklem/*
1945df6d95rmacklem * NFSDEV_MAXMIRRORS - Maximum level of mirroring for a DS.
1955df6d95rmacklem * (Most will only put files on two DSs, but this setting allows up to 4.)
196e8aa017rmacklem * NFSDEV_MAXVERS - maximum number of NFS versions supported by Flex File.
197e8aa017rmacklem */
198e8aa017rmacklem#define	NFSDEV_MAXMIRRORS	4
199e8aa017rmacklem#define	NFSDEV_MAXVERS		4
200e8aa017rmacklem
20177f312drmacklemstruct nfsd_pnfsd_args {
20277f312drmacklem	int	op;		/* Which pNFSd op to perform. */
20377f312drmacklem	char	*mdspath;	/* Path of MDS file. */
20477f312drmacklem	char	*dspath;	/* Path of recovered DS mounted on dir. */
20577f312drmacklem	char	*curdspath;	/* Path of current DS mounted on dir. */
20677f312drmacklem};
20777f312drmacklem
20877f312drmacklem#define	PNFSDOP_DELDSSERVER	1
20977f312drmacklem#define	PNFSDOP_COPYMR		2
2102af903crmacklem#define	PNFSDOP_FORCEDELDS	3
21177f312drmacklem
21277f312drmacklem/* Old version. */
21377f312drmacklemstruct nfsd_nfsd_oargs {
21477f312drmacklem	const char *principal;	/* GSS-API service principal name */
21577f312drmacklem	int	minthreads;	/* minimum service thread count */
21677f312drmacklem	int	maxthreads;	/* maximum service thread count */
21777f312drmacklem};
21877f312drmacklem
219e8aa017rmacklem/*
220e3d3490rmacklem * Arguments for use by the callback daemon.
221e3d3490rmacklem */
222e3d3490rmacklemstruct nfsd_nfscbd_args {
223e3d3490rmacklem	const char *principal;	/* GSS-API service principal name */
224e3d3490rmacklem};
225e3d3490rmacklem
226e3d3490rmacklemstruct nfscbd_args {
227e3d3490rmacklem	int	sock;		/* Socket to serve */
228e3d3490rmacklem	caddr_t	name;		/* Client addr for connection based sockets */
229e3d3490rmacklem	int	namelen;	/* Length of name */
230e3d3490rmacklem	u_short	port;		/* Port# for callbacks */
231e3d3490rmacklem};
232e3d3490rmacklem
233e3d3490rmacklemstruct nfsd_idargs {
234e3d3490rmacklem	int		nid_flag;	/* Flags (see below) */
235e3d3490rmacklem	uid_t		nid_uid;	/* user/group id */
236e3d3490rmacklem	gid_t		nid_gid;
237e3d3490rmacklem	int		nid_usermax;	/* Upper bound on user name cache */
238e3d3490rmacklem	int		nid_usertimeout;/* User name timeout (minutes) */
239e3d3490rmacklem	u_char		*nid_name;	/* Name */
240e3d3490rmacklem	int		nid_namelen;	/* and its length */
241493738armacklem	gid_t		*nid_grps;	/* and the list */
242493738armacklem	int		nid_ngroup;	/* Size of groups list */
243493738armacklem};
244493738armacklem
245493738armacklemstruct nfsd_oidargs {
246493738armacklem	int		nid_flag;	/* Flags (see below) */
247493738armacklem	uid_t		nid_uid;	/* user/group id */
248493738armacklem	gid_t		nid_gid;
249493738armacklem	int		nid_usermax;	/* Upper bound on user name cache */
250493738armacklem	int		nid_usertimeout;/* User name timeout (minutes) */
251493738armacklem	u_char		*nid_name;	/* Name */
252493738armacklem	int		nid_namelen;	/* and its length */
253e3d3490rmacklem};
254e3d3490rmacklem
2554bb25earmacklemstruct nfsuserd_args {
2564bb25earmacklem	sa_family_t	nuserd_family;	/* Address family to use */
2574bb25earmacklem	u_short		nuserd_port;	/* Port# */
2584bb25earmacklem};
2594bb25earmacklem
260e3d3490rmacklemstruct nfsd_clid {
261e3d3490rmacklem	int		nclid_idlen;	/* Length of client id */
262e3d3490rmacklem	u_char		nclid_id[NFSV4_OPAQUELIMIT]; /* and name */
263e3d3490rmacklem};
264e3d3490rmacklem
265e3d3490rmacklemstruct nfsd_dumplist {
266e3d3490rmacklem	int		ndl_size;	/* Number of elements */
267e3d3490rmacklem	void		*ndl_list;	/* and the list of elements */
268e3d3490rmacklem};
269e3d3490rmacklem
270e3d3490rmacklemstruct nfsd_dumpclients {
271e3d3490rmacklem	u_int32_t	ndcl_flags;		/* LCL_xxx flags */
272e3d3490rmacklem	u_int32_t	ndcl_nopenowners;	/* Number of openowners */
273e3d3490rmacklem	u_int32_t	ndcl_nopens;		/* and opens */
274e3d3490rmacklem	u_int32_t	ndcl_nlockowners;	/* and of lockowners */
275e3d3490rmacklem	u_int32_t	ndcl_nlocks;		/* and of locks */
276e3d3490rmacklem	u_int32_t	ndcl_ndelegs;		/* and of delegations */
277e3d3490rmacklem	u_int32_t	ndcl_nolddelegs;	/* and old delegations */
278