xref: /freebsd/sys/nfsserver/nfs.h (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993, 1995
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  *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
35  * $FreeBSD$
36  */
37 
38 #ifndef _NFSSERVER_NFS_H_
39 #define _NFSSERVER_NFS_H_
40 
41 #ifdef _KERNEL
42 #include "opt_nfs.h"
43 #endif
44 
45 #include <nfs/nfssvc.h>
46 
47 /*
48  * Tunable constants for nfs
49  */
50 
51 #define NFS_TICKINTVL	10		/* Desired time for a tick (msec) */
52 #define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
53 #define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
54 #define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
55 #define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
56 #define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
57 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
58 #ifndef NFS_GATHERDELAY
59 #define NFS_GATHERDELAY		10	/* Default write gather delay (msec) */
60 #endif
61 #ifdef _KERNEL
62 #define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
63 #endif
64 
65 /*
66  * Oddballs
67  */
68 #define NFS_SRVMAXDATA(n) \
69 		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
70 		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
71 
72 /*
73  * XXX
74  * The B_INVAFTERWRITE flag should be set to whatever is required by the
75  * buffer cache code to say "Invalidate the block after it is written back".
76  */
77 #define	B_INVAFTERWRITE	B_NOCACHE
78 
79 /*
80  * The IO_METASYNC flag should be implemented for local filesystems.
81  * (Until then, it is nothin at all.)
82  */
83 #ifndef IO_METASYNC
84 #define IO_METASYNC	0
85 #endif
86 
87 /* NFS state flags XXX -Wunused */
88 #define	NFSRV_SNDLOCK		0x01000000  /* Send socket lock */
89 #define	NFSRV_WANTSND		0x02000000  /* Want above */
90 
91 /*
92  * Structures for the nfssvc(2) syscall.  Not that anyone but nfsd and
93  * mount_nfs should ever try and use it.
94  */
95 
96 /*
97  * Add a socket to monitor for NFS requests.
98  */
99 struct nfsd_addsock_args {
100 	int	sock;		/* Socket to serve */
101 	caddr_t	name;		/* Client addr for connection based sockets */
102 	int	namelen;	/* Length of name */
103 };
104 
105 /*
106  * Start processing requests.
107  */
108 struct nfsd_nfsd_args {
109 	const char *principal;	/* GSS-API service principal name */
110 	int	minthreads;	/* minimum service thread count */
111 	int	maxthreads;	/* maximum service thread count */
112 };
113 
114 /*
115  * XXX to allow amd to include nfs.h without nfsproto.h
116  */
117 #ifdef NFS_NPROCS
118 #include <nfsserver/nfsrvstats.h>
119 #endif
120 
121 /*
122  * vfs.nfsrv sysctl(3) identifiers
123  */
124 #define NFS_NFSRVSTATS	1		/* struct: struct nfsrvstats */
125 #define NFS_NFSPRIVPORT	2		/* int: prohibit nfs to resvports */
126 
127 #ifdef _KERNEL
128 
129 extern struct mtx nfsd_mtx;
130 #define	NFSD_LOCK_ASSERT()	mtx_assert(&nfsd_mtx, MA_OWNED)
131 #define	NFSD_UNLOCK_ASSERT()	mtx_assert(&nfsd_mtx, MA_NOTOWNED)
132 #define	NFSD_LOCK_DONTCARE()
133 #define	NFSD_LOCK()	mtx_lock(&nfsd_mtx)
134 #define	NFSD_UNLOCK()	mtx_unlock(&nfsd_mtx)
135 
136 #ifdef MALLOC_DECLARE
137 MALLOC_DECLARE(M_NFSRVDESC);
138 MALLOC_DECLARE(M_NFSD);
139 #endif
140 
141 /* Forward declarations */
142 struct nfssvc_sock;
143 struct nfsrv_descript;
144 struct uio;
145 struct vattr;
146 struct nameidata;
147 
148 extern struct callout nfsrv_callout;
149 extern struct nfsrvstats nfsrvstats;
150 
151 extern int	nfsrv_ticks;
152 extern int	nfsrvw_procrastinate;
153 extern int	nfsrvw_procrastinate_v3;
154 extern int 	nfsrv_numnfsd;
155 
156 /* Various values converted to XDR form. */
157 extern u_int32_t nfsrv_nfs_false, nfsrv_nfs_true, nfsrv_nfs_xdrneg1,
158 	nfsrv_nfs_prog;
159 extern u_int32_t nfsrv_rpc_reply, nfsrv_rpc_msgdenied, nfsrv_rpc_mismatch,
160 	nfsrv_rpc_vers;
161 extern u_int32_t nfsrv_rpc_auth_unix, nfsrv_rpc_msgaccepted, nfsrv_rpc_call,
162 	nfsrv_rpc_autherr;
163 
164 /* Procedure table data */
165 extern const int	nfsrvv2_procid[NFS_NPROCS];
166 extern const int	nfsrv_nfsv3_procid[NFS_NPROCS];
167 extern int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
168 		    struct nfssvc_sock *slp, struct mbuf **mreqp);
169 
170 /*
171  * A list of nfssvc_sock structures is maintained with all the sockets
172  * that require service by the nfsd.
173  */
174 #ifndef NFS_WDELAYHASHSIZ
175 #define	NFS_WDELAYHASHSIZ 16	/* and with this */
176 #endif
177 #define	NWDELAYHASH(sock, f) \
178 	(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
179 
180 /*
181  * This structure is used by the server for describing each request.
182  */
183 struct nfsrv_descript {
184 	struct mbuf		*nd_mrep;	/* Request mbuf list */
185 	struct mbuf		*nd_md;		/* Current dissect mbuf */
186 	struct mbuf		*nd_mreq;	/* Reply mbuf list */
187 	struct sockaddr		*nd_nam;	/* and socket addr */
188 	struct sockaddr		*nd_nam2;	/* return socket addr */
189 	caddr_t			nd_dpos;	/* Current dissect pos */
190 	u_int32_t		nd_procnum;	/* RPC # */
191 	int			nd_stable;	/* storage type */
192 	int			nd_flag;	/* nd_flag */
193 	int			nd_repstat;	/* Reply status */
194 	fhandle_t		nd_fh;		/* File handle */
195 	struct ucred		*nd_cr;		/* Credentials */
196 	int			nd_credflavor;	/* Security flavor */
197 };
198 
199 /* Bits for "nd_flag" */
200 #define ND_NFSV3	0x08
201 
202 /*
203  * Defines for WebNFS
204  */
205 
206 #define WEBNFS_ESC_CHAR		'%'
207 #define WEBNFS_SPECCHAR_START	0x80
208 
209 #define WEBNFS_NATIVE_CHAR	0x80
210 /*
211  * ..
212  * Possibly more here in the future.
213  */
214 
215 /*
216  * Macro for converting escape characters in WebNFS pathnames.
217  * Should really be in libkern.
218  */
219 
220 #define HEXTOC(c) \
221 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
222 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
223 #define HEXSTRTOI(p) \
224 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
225 
226 #ifdef NFS_DEBUG
227 
228 extern int nfs_debug;
229 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
230 #define NFS_DEBUG_WG		2 /* server write gathering */
231 #define NFS_DEBUG_RC		4 /* server request caching */
232 
233 #define NFS_DPF(cat, args)					\
234 	do {							\
235 		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
236 	} while (0)
237 
238 #else
239 
240 #define NFS_DPF(cat, args)
241 
242 #endif
243 
244 /*
245  * The following flags can be passed to nfsrv_fhtovp() function.
246  */
247 /* Leave file system busy on success. */
248 #define	NFSRV_FLAG_BUSY		0x01
249 
250 struct mbuf *nfs_rephead(int, struct nfsrv_descript *, int, struct mbuf **,
251 	    caddr_t *);
252 void	nfsm_srvfattr(struct nfsrv_descript *, struct vattr *,
253 	    struct nfs_fattr *);
254 void	nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
255 	    struct vattr *, struct mbuf **, char **);
256 void	nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
257 	    struct mbuf **, char **);
258 int	nfs_namei(struct nameidata *, struct nfsrv_descript *, fhandle_t *,
259 	    int, struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
260 	    caddr_t *, struct vnode **, int, struct vattr *, int *, int);
261 void	nfsm_adj(struct mbuf *, int, int);
262 int	nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
263 void	nfsrv_init(int);
264 int	nfsrv_errmap(struct nfsrv_descript *, int);
265 void	nfsrvw_sort(gid_t *, int);
266 
267 int	nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
268 	    struct mbuf **mrq);
269 int	nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
270 	    struct mbuf **mrq);
271 int	nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
272 	    struct mbuf **mrq);
273 int	nfsrv_fhtovp(fhandle_t *, int, struct vnode **,
274 	    struct nfsrv_descript *, struct nfssvc_sock *, struct sockaddr *,
275 	    int *);
276 int	nfsrv_setpublicfs(struct mount *, struct netexport *,
277 	    struct export_args *);
278 int	nfs_ispublicfh(fhandle_t *);
279 int	nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
280 	    struct mbuf **mrq);
281 int	nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
282 	    struct mbuf **mrq);
283 int	nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
284 	    struct mbuf **mrq);
285 int	nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
286 	    struct mbuf **mrq);
287 int	nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
288 	    struct mbuf **mrq);
289 int	nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
290 	    struct mbuf **mrq);
291 int	nfsrv_noop(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
292 	    struct mbuf **mrq);
293 int	nfsrv_null(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
294 	    struct mbuf **mrq);
295 int	nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
296 	    struct mbuf **mrq);
297 int	nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
298 	    struct mbuf **mrq);
299 int	nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
300 	    struct mbuf **mrq);
301 int	nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
302 	    struct mbuf **mrq);
303 int	nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
304 	    struct mbuf **mrq);
305 int	nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
306 	    struct mbuf **mrq);
307 int	nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
308 	    struct mbuf **mrq);
309 int	nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
310 	    struct mbuf **mrq);
311 int	nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
312 	    struct mbuf **mrq);
313 int	nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
314 	    struct mbuf **mrq);
315 int	nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
316 	    struct mbuf **mrq);
317 int	nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
318 	    struct mbuf **mrq);
319 /*
320  * #ifdef _SYS_SYSPROTO_H_ so that it is only defined when sysproto.h
321  * has been included, so that "struct nfssvc_args" is defined.
322  */
323 #ifdef _SYS_SYSPROTO_H_
324 int nfssvc_nfsserver(struct thread *, struct nfssvc_args *);
325 #endif
326 #endif	/* _KERNEL */
327 
328 #endif
329