xref: /titanic_50/usr/src/uts/common/fs/nfs/nfs_server.c (revision 408aef6a222bf32dc7e66db1ff562316a425ee72)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *	Copyright (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
28  *	All rights reserved.
29  *	Use is subject to license terms.
30  */
31 
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/systm.h>
35 #include <sys/cred.h>
36 #include <sys/proc.h>
37 #include <sys/user.h>
38 #include <sys/buf.h>
39 #include <sys/vfs.h>
40 #include <sys/vnode.h>
41 #include <sys/pathname.h>
42 #include <sys/uio.h>
43 #include <sys/file.h>
44 #include <sys/stat.h>
45 #include <sys/errno.h>
46 #include <sys/socket.h>
47 #include <sys/sysmacros.h>
48 #include <sys/siginfo.h>
49 #include <sys/tiuser.h>
50 #include <sys/statvfs.h>
51 #include <sys/stream.h>
52 #include <sys/strsubr.h>
53 #include <sys/stropts.h>
54 #include <sys/timod.h>
55 #include <sys/t_kuser.h>
56 #include <sys/kmem.h>
57 #include <sys/kstat.h>
58 #include <sys/dirent.h>
59 #include <sys/cmn_err.h>
60 #include <sys/debug.h>
61 #include <sys/unistd.h>
62 #include <sys/vtrace.h>
63 #include <sys/mode.h>
64 #include <sys/acl.h>
65 #include <sys/sdt.h>
66 
67 #include <rpc/types.h>
68 #include <rpc/auth.h>
69 #include <rpc/auth_unix.h>
70 #include <rpc/auth_des.h>
71 #include <rpc/svc.h>
72 #include <rpc/xdr.h>
73 
74 #include <nfs/nfs.h>
75 #include <nfs/export.h>
76 #include <nfs/nfssys.h>
77 #include <nfs/nfs_clnt.h>
78 #include <nfs/nfs_acl.h>
79 #include <nfs/nfs_log.h>
80 #include <nfs/nfs_cmd.h>
81 #include <nfs/lm.h>
82 #include <nfs/nfs_dispatch.h>
83 #include <nfs/nfs4_drc.h>
84 
85 #include <sys/modctl.h>
86 #include <sys/cladm.h>
87 #include <sys/clconf.h>
88 
89 #define	MAXHOST 32
90 const char *kinet_ntop6(uchar_t *, char *, size_t);
91 
92 /*
93  * Module linkage information.
94  */
95 
96 static struct modlmisc modlmisc = {
97 	&mod_miscops, "NFS server module"
98 };
99 
100 static struct modlinkage modlinkage = {
101 	MODREV_1, (void *)&modlmisc, NULL
102 };
103 
104 char _depends_on[] = "misc/klmmod";
105 
106 int
107 _init(void)
108 {
109 	int status;
110 
111 	if ((status = nfs_srvinit()) != 0) {
112 		cmn_err(CE_WARN, "_init: nfs_srvinit failed");
113 		return (status);
114 	}
115 
116 	status = mod_install((struct modlinkage *)&modlinkage);
117 	if (status != 0) {
118 		/*
119 		 * Could not load module, cleanup previous
120 		 * initialization work.
121 		 */
122 		nfs_srvfini();
123 	}
124 
125 	/*
126 	 * Initialise some placeholders for nfssys() calls. These have
127 	 * to be declared by the nfs module, since that handles nfssys()
128 	 * calls - also used by NFS clients - but are provided by this
129 	 * nfssrv module. These also then serve as confirmation to the
130 	 * relevant code in nfs that nfssrv has been loaded, as they're
131 	 * initially NULL.
132 	 */
133 	nfs_srv_quiesce_func = nfs_srv_quiesce_all;
134 	nfs_srv_dss_func = rfs4_dss_setpaths;
135 
136 	/* setup DSS paths here; must be done before initial server startup */
137 	rfs4_dss_paths = rfs4_dss_oldpaths = NULL;
138 
139 	return (status);
140 }
141 
142 int
143 _fini()
144 {
145 	return (EBUSY);
146 }
147 
148 int
149 _info(struct modinfo *modinfop)
150 {
151 	return (mod_info(&modlinkage, modinfop));
152 }
153 
154 /*
155  * PUBLICFH_CHECK() checks if the dispatch routine supports
156  * RPC_PUBLICFH_OK, if the filesystem is exported public, and if the
157  * incoming request is using the public filehandle. The check duplicates
158  * the exportmatch() call done in checkexport(), and we should consider
159  * modifying those routines to avoid the duplication. For now, we optimize
160  * by calling exportmatch() only after checking that the dispatch routine
161  * supports RPC_PUBLICFH_OK, and if the filesystem is explicitly exported
162  * public (i.e., not the placeholder).
163  */
164 #define	PUBLICFH_CHECK(disp, exi, fsid, xfid) \
165 		((disp->dis_flags & RPC_PUBLICFH_OK) && \
166 		((exi->exi_export.ex_flags & EX_PUBLIC) || \
167 		(exi == exi_public && exportmatch(exi_root, \
168 		fsid, xfid))))
169 
170 static void	nfs_srv_shutdown_all(int);
171 static void	rfs4_server_start(int);
172 static void	nullfree(void);
173 static void	rfs_dispatch(struct svc_req *, SVCXPRT *);
174 static void	acl_dispatch(struct svc_req *, SVCXPRT *);
175 static void	common_dispatch(struct svc_req *, SVCXPRT *,
176 		rpcvers_t, rpcvers_t, char *,
177 		struct rpc_disptable *);
178 static void	hanfsv4_failover(void);
179 static	int	checkauth(struct exportinfo *, struct svc_req *, cred_t *, int,
180 			bool_t);
181 static char	*client_name(struct svc_req *req);
182 static char	*client_addr(struct svc_req *req, char *buf);
183 extern	int	sec_svc_getcred(struct svc_req *, cred_t *cr, char **, int *);
184 extern	bool_t	sec_svc_inrootlist(int, caddr_t, int, caddr_t *);
185 
186 #define	NFSLOG_COPY_NETBUF(exi, xprt, nb)	{		\
187 	(nb)->maxlen = (xprt)->xp_rtaddr.maxlen;		\
188 	(nb)->len = (xprt)->xp_rtaddr.len;			\
189 	(nb)->buf = kmem_alloc((nb)->len, KM_SLEEP);		\
190 	bcopy((xprt)->xp_rtaddr.buf, (nb)->buf, (nb)->len);	\
191 	}
192 
193 /*
194  * Public Filehandle common nfs routines
195  */
196 static int	MCLpath(char **);
197 static void	URLparse(char *);
198 
199 /*
200  * NFS callout table.
201  * This table is used by svc_getreq() to dispatch a request with
202  * a given prog/vers pair to an appropriate service provider
203  * dispatch routine.
204  *
205  * NOTE: ordering is relied upon below when resetting the version min/max
206  * for NFS_PROGRAM.  Careful, if this is ever changed.
207  */
208 static SVC_CALLOUT __nfs_sc_clts[] = {
209 	{ NFS_PROGRAM,	   NFS_VERSMIN,	    NFS_VERSMAX,	rfs_dispatch },
210 	{ NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,	acl_dispatch }
211 };
212 
213 static SVC_CALLOUT_TABLE nfs_sct_clts = {
214 	sizeof (__nfs_sc_clts) / sizeof (__nfs_sc_clts[0]), FALSE,
215 	__nfs_sc_clts
216 };
217 
218 static SVC_CALLOUT __nfs_sc_cots[] = {
219 	{ NFS_PROGRAM,	   NFS_VERSMIN,	    NFS_VERSMAX,	rfs_dispatch },
220 	{ NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,	acl_dispatch }
221 };
222 
223 static SVC_CALLOUT_TABLE nfs_sct_cots = {
224 	sizeof (__nfs_sc_cots) / sizeof (__nfs_sc_cots[0]), FALSE, __nfs_sc_cots
225 };
226 
227 static SVC_CALLOUT __nfs_sc_rdma[] = {
228 	{ NFS_PROGRAM,	   NFS_VERSMIN,	    NFS_VERSMAX,	rfs_dispatch },
229 	{ NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,	acl_dispatch }
230 };
231 
232 static SVC_CALLOUT_TABLE nfs_sct_rdma = {
233 	sizeof (__nfs_sc_rdma) / sizeof (__nfs_sc_rdma[0]), FALSE, __nfs_sc_rdma
234 };
235 rpcvers_t nfs_versmin = NFS_VERSMIN_DEFAULT;
236 rpcvers_t nfs_versmax = NFS_VERSMAX_DEFAULT;
237 
238 /*
239  * Used to track the state of the server so that initialization
240  * can be done properly.
241  */
242 typedef enum {
243 	NFS_SERVER_STOPPED,	/* server state destroyed */
244 	NFS_SERVER_STOPPING,	/* server state being destroyed */
245 	NFS_SERVER_RUNNING,
246 	NFS_SERVER_QUIESCED,	/* server state preserved */
247 	NFS_SERVER_OFFLINE	/* server pool offline */
248 } nfs_server_running_t;
249 
250 static nfs_server_running_t nfs_server_upordown;
251 static kmutex_t nfs_server_upordown_lock;
252 static	kcondvar_t nfs_server_upordown_cv;
253 
254 /*
255  * DSS: distributed stable storage
256  * lists of all DSS paths: current, and before last warmstart
257  */
258 nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
259 
260 int rfs4_dispatch(struct rpcdisp *, struct svc_req *, SVCXPRT *, char *);
261 bool_t rfs4_minorvers_mismatch(struct svc_req *, SVCXPRT *, void *);
262 
263 /*
264  * RDMA wait variables.
265  */
266 static kcondvar_t rdma_wait_cv;
267 static kmutex_t rdma_wait_mutex;
268 
269 /*
270  * Will be called at the point the server pool is being unregistered
271  * from the pool list. From that point onwards, the pool is waiting
272  * to be drained and as such the server state is stale and pertains
273  * to the old instantiation of the NFS server pool.
274  */
275 void
276 nfs_srv_offline(void)
277 {
278 	mutex_enter(&nfs_server_upordown_lock);
279 	if (nfs_server_upordown == NFS_SERVER_RUNNING) {
280 		nfs_server_upordown = NFS_SERVER_OFFLINE;
281 	}
282 	mutex_exit(&nfs_server_upordown_lock);
283 }
284 
285 /*
286  * Will be called at the point the server pool is being destroyed so
287  * all transports have been closed and no service threads are in
288  * existence.
289  *
290  * If we quiesce the server, we're shutting it down without destroying the
291  * server state. This allows it to warm start subsequently.
292  */
293 void
294 nfs_srv_stop_all(void)
295 {
296 	int quiesce = 0;
297 	nfs_srv_shutdown_all(quiesce);
298 }
299 
300 /*
301  * This alternative shutdown routine can be requested via nfssys()
302  */
303 void
304 nfs_srv_quiesce_all(void)
305 {
306 	int quiesce = 1;
307 	nfs_srv_shutdown_all(quiesce);
308 }
309 
310 static void
311 nfs_srv_shutdown_all(int quiesce) {
312 	mutex_enter(&nfs_server_upordown_lock);
313 	if (quiesce) {
314 		if (nfs_server_upordown == NFS_SERVER_RUNNING ||
315 			nfs_server_upordown == NFS_SERVER_OFFLINE) {
316 			nfs_server_upordown = NFS_SERVER_QUIESCED;
317 			cv_signal(&nfs_server_upordown_cv);
318 
319 			/* reset DSS state, for subsequent warm restart */
320 			rfs4_dss_numnewpaths = 0;
321 			rfs4_dss_newpaths = NULL;
322 
323 			cmn_err(CE_NOTE, "nfs_server: server is now quiesced; "
324 			    "NFSv4 state has been preserved");
325 		}
326 	} else {
327 		if (nfs_server_upordown == NFS_SERVER_OFFLINE) {
328 			nfs_server_upordown = NFS_SERVER_STOPPING;
329 			mutex_exit(&nfs_server_upordown_lock);
330 			rfs4_state_fini();
331 			rfs4_fini_drc(nfs4_drc);
332 			mutex_enter(&nfs_server_upordown_lock);
333 			nfs_server_upordown = NFS_SERVER_STOPPED;
334 			cv_signal(&nfs_server_upordown_cv);
335 		}
336 	}
337 	mutex_exit(&nfs_server_upordown_lock);
338 }
339 
340 static int
341 nfs_srv_set_sc_versions(struct file *fp, SVC_CALLOUT_TABLE **sctpp,
342 			rpcvers_t versmin, rpcvers_t versmax)
343 {
344 	struct strioctl strioc;
345 	struct T_info_ack tinfo;
346 	int		error, retval;
347 
348 	/*
349 	 * Find out what type of transport this is.
350 	 */
351 	strioc.ic_cmd = TI_GETINFO;
352 	strioc.ic_timout = -1;
353 	strioc.ic_len = sizeof (tinfo);
354 	strioc.ic_dp = (char *)&tinfo;
355 	tinfo.PRIM_type = T_INFO_REQ;
356 
357 	error = strioctl(fp->f_vnode, I_STR, (intptr_t)&strioc, 0, K_TO_K,
358 	    CRED(), &retval);
359 	if (error || retval)
360 		return (error);
361 
362 	/*
363 	 * Based on our query of the transport type...
364 	 *
365 	 * Reset the min/max versions based on the caller's request
366 	 * NOTE: This assumes that NFS_PROGRAM is first in the array!!
367 	 * And the second entry is the NFS_ACL_PROGRAM.
368 	 */
369 	switch (tinfo.SERV_type) {
370 	case T_CLTS:
371 		if (versmax == NFS_V4)
372 			return (EINVAL);
373 		__nfs_sc_clts[0].sc_versmin = versmin;
374 		__nfs_sc_clts[0].sc_versmax = versmax;
375 		__nfs_sc_clts[1].sc_versmin = versmin;
376 		__nfs_sc_clts[1].sc_versmax = versmax;
377 		*sctpp = &nfs_sct_clts;
378 		break;
379 	case T_COTS:
380 	case T_COTS_ORD:
381 		__nfs_sc_cots[0].sc_versmin = versmin;
382 		__nfs_sc_cots[0].sc_versmax = versmax;
383 		/* For the NFS_ACL program, check the max version */
384 		if (versmax > NFS_ACL_VERSMAX)
385 			versmax = NFS_ACL_VERSMAX;
386 		__nfs_sc_cots[1].sc_versmin = versmin;
387 		__nfs_sc_cots[1].sc_versmax = versmax;
388 		*sctpp = &nfs_sct_cots;
389 		break;
390 	default:
391 		error = EINVAL;
392 	}
393 
394 	return (error);
395 }
396 
397 /*
398  * NFS Server system call.
399  * Does all of the work of running a NFS server.
400  * uap->fd is the fd of an open transport provider
401  */
402 int
403 nfs_svc(struct nfs_svc_args *arg, model_t model)
404 {
405 	file_t *fp;
406 	SVCMASTERXPRT *xprt;
407 	int error;
408 	int readsize;
409 	char buf[KNC_STRSIZE];
410 	size_t len;
411 	STRUCT_HANDLE(nfs_svc_args, uap);
412 	struct netbuf addrmask;
413 	SVC_CALLOUT_TABLE *sctp = NULL;
414 
415 #ifdef lint
416 	model = model;		/* STRUCT macros don't always refer to it */
417 #endif
418 
419 	STRUCT_SET_HANDLE(uap, model, arg);
420 
421 	/* Check privileges in nfssys() */
422 
423 	if ((fp = getf(STRUCT_FGET(uap, fd))) == NULL)
424 		return (EBADF);
425 
426 	/*
427 	 * Set read buffer size to rsize
428 	 * and add room for RPC headers.
429 	 */
430 	readsize = nfs3tsize() + (RPC_MAXDATASIZE - NFS_MAXDATA);
431 	if (readsize < RPC_MAXDATASIZE)
432 		readsize = RPC_MAXDATASIZE;
433 
434 	error = copyinstr((const char *)STRUCT_FGETP(uap, netid), buf,
435 	    KNC_STRSIZE, &len);
436 	if (error) {
437 		releasef(STRUCT_FGET(uap, fd));
438 		return (error);
439 	}
440 
441 	addrmask.len = STRUCT_FGET(uap, addrmask.len);
442 	addrmask.maxlen = STRUCT_FGET(uap, addrmask.maxlen);
443 	addrmask.buf = kmem_alloc(addrmask.maxlen, KM_SLEEP);
444 	error = copyin(STRUCT_FGETP(uap, addrmask.buf), addrmask.buf,
445 	    addrmask.len);
446 	if (error) {
447 		releasef(STRUCT_FGET(uap, fd));
448 		kmem_free(addrmask.buf, addrmask.maxlen);
449 		return (error);
450 	}
451 
452 	nfs_versmin = STRUCT_FGET(uap, versmin);
453 	nfs_versmax = STRUCT_FGET(uap, versmax);
454 
455 	/* Double check the vers min/max ranges */
456 	if ((nfs_versmin > nfs_versmax) ||
457 	    (nfs_versmin < NFS_VERSMIN) ||
458 	    (nfs_versmax > NFS_VERSMAX)) {
459 		nfs_versmin = NFS_VERSMIN_DEFAULT;
460 		nfs_versmax = NFS_VERSMAX_DEFAULT;
461 	}
462 
463 	if (error =
464 	    nfs_srv_set_sc_versions(fp, &sctp, nfs_versmin, nfs_versmax)) {
465 		releasef(STRUCT_FGET(uap, fd));
466 		kmem_free(addrmask.buf, addrmask.maxlen);
467 		return (error);
468 	}
469 
470 	/* Initialize nfsv4 server */
471 	if (nfs_versmax == (rpcvers_t)NFS_V4)
472 		rfs4_server_start(STRUCT_FGET(uap, delegation));
473 
474 	/* Create a transport handle. */
475 	error = svc_tli_kcreate(fp, readsize, buf, &addrmask, &xprt,
476 	    sctp, NULL, NFS_SVCPOOL_ID, TRUE);
477 
478 	if (error)
479 		kmem_free(addrmask.buf, addrmask.maxlen);
480 
481 	releasef(STRUCT_FGET(uap, fd));
482 
483 	/* HA-NFSv4: save the cluster nodeid */
484 	if (cluster_bootflags & CLUSTER_BOOTED)
485 		lm_global_nlmid = clconf_get_nodeid();
486 
487 	return (error);
488 }
489 
490 static void
491 rfs4_server_start(int nfs4_srv_delegation)
492 {
493 	/*
494 	 * Determine if the server has previously been "started" and
495 	 * if not, do the per instance initialization
496 	 */
497 	mutex_enter(&nfs_server_upordown_lock);
498 
499 	if (nfs_server_upordown != NFS_SERVER_RUNNING) {
500 		/* Do we need to stop and wait on the previous server? */
501 		while (nfs_server_upordown == NFS_SERVER_STOPPING ||
502 		    nfs_server_upordown == NFS_SERVER_OFFLINE)
503 			cv_wait(&nfs_server_upordown_cv,
504 			    &nfs_server_upordown_lock);
505 
506 		if (nfs_server_upordown != NFS_SERVER_RUNNING) {
507 			(void) svc_pool_control(NFS_SVCPOOL_ID,
508 			    SVCPSET_UNREGISTER_PROC, (void *)&nfs_srv_offline);
509 			(void) svc_pool_control(NFS_SVCPOOL_ID,
510 			    SVCPSET_SHUTDOWN_PROC, (void *)&nfs_srv_stop_all);
511 
512 			/* is this an nfsd warm start? */
513 			if (nfs_server_upordown == NFS_SERVER_QUIESCED) {
514 				cmn_err(CE_NOTE, "nfs_server: "
515 				    "server was previously quiesced; "
516 				    "existing NFSv4 state will be re-used");
517 
518 				/*
519 				 * HA-NFSv4: this is also the signal
520 				 * that a Resource Group failover has
521 				 * occurred.
522 				 */
523 				if (cluster_bootflags & CLUSTER_BOOTED)
524 					hanfsv4_failover();
525 			} else {
526 				/* cold start */
527 				rfs4_state_init();
528 				nfs4_drc = rfs4_init_drc(nfs4_drc_max,
529 				    nfs4_drc_hash);
530 			}
531 
532 			/*
533 			 * Check to see if delegation is to be
534 			 * enabled at the server
535 			 */
536 			if (nfs4_srv_delegation != FALSE)
537 				rfs4_set_deleg_policy(SRV_NORMAL_DELEGATE);
538 
539 			nfs_server_upordown = NFS_SERVER_RUNNING;
540 		}
541 		cv_signal(&nfs_server_upordown_cv);
542 	}
543 	mutex_exit(&nfs_server_upordown_lock);
544 }
545 
546 /*
547  * If RDMA device available,
548  * start RDMA listener.
549  */
550 int
551 rdma_start(struct rdma_svc_args *rsa)
552 {
553 	int error;
554 	rdma_xprt_group_t started_rdma_xprts;
555 
556 	/* Double check the vers min/max ranges */
557 	if ((rsa->nfs_versmin > rsa->nfs_versmax) ||
558 	    (rsa->nfs_versmin < NFS_VERSMIN) ||
559 	    (rsa->nfs_versmax > NFS_VERSMAX)) {
560 		rsa->nfs_versmin = NFS_VERSMIN_DEFAULT;
561 		rsa->nfs_versmax = NFS_VERSMAX_DEFAULT;
562 	}
563 	nfs_versmin = rsa->nfs_versmin;
564 	nfs_versmax = rsa->nfs_versmax;
565 
566 	/* Set the versions in the callout table */
567 	__nfs_sc_rdma[0].sc_versmin = rsa->nfs_versmin;
568 	__nfs_sc_rdma[0].sc_versmax = rsa->nfs_versmax;
569 	/* For the NFS_ACL program, check the max version */
570 	__nfs_sc_rdma[1].sc_versmin = rsa->nfs_versmin;
571 	if (rsa->nfs_versmax > NFS_ACL_VERSMAX)
572 		__nfs_sc_rdma[1].sc_versmax = NFS_ACL_VERSMAX;
573 	else
574 		__nfs_sc_rdma[1].sc_versmax = rsa->nfs_versmax;
575 
576 	/* Initialize nfsv4 server */
577 	if (rsa->nfs_versmax == (rpcvers_t)NFS_V4)
578 		rfs4_server_start(rsa->delegation);
579 
580 	started_rdma_xprts.rtg_count = 0;
581 	started_rdma_xprts.rtg_listhead = NULL;
582 	started_rdma_xprts.rtg_poolid = rsa->poolid;
583 	error = svc_rdma_kcreate(rsa->netid, &nfs_sct_rdma, rsa->poolid,
584 	    &started_rdma_xprts);
585 
586 	if (error == 0) {
587 		mutex_enter(&rdma_wait_mutex);
588 		if (!cv_wait_sig(&rdma_wait_cv, &rdma_wait_mutex)) {
589 			rdma_stop(started_rdma_xprts);
590 		}
591 		mutex_exit(&rdma_wait_mutex);
592 	}
593 
594 	return (error);
595 }
596 
597 /* ARGSUSED */
598 void
599 rpc_null(caddr_t *argp, caddr_t *resp)
600 {
601 }
602 
603 /* ARGSUSED */
604 void
605 rpc_null_v3(caddr_t *argp, caddr_t *resp, struct exportinfo *exi,
606     struct svc_req *req, cred_t *cr)
607 {
608 	DTRACE_NFSV3_3(op__null__start, struct svc_req *, req,
609 	    cred_t *, cr, vnode_t *, NULL);
610 	DTRACE_NFSV3_3(op__null__done, struct svc_req *, req,
611 	    cred_t *, cr, vnode_t *, NULL);
612 }
613 
614 /* ARGSUSED */
615 static void
616 rfs_error(caddr_t *argp, caddr_t *resp)
617 {
618 	/* return (EOPNOTSUPP); */
619 }
620 
621 static void
622 nullfree(void)
623 {
624 }
625 
626 static char *rfscallnames_v2[] = {
627 	"RFS2_NULL",
628 	"RFS2_GETATTR",
629 	"RFS2_SETATTR",
630 	"RFS2_ROOT",
631 	"RFS2_LOOKUP",
632 	"RFS2_READLINK",
633 	"RFS2_READ",
634 	"RFS2_WRITECACHE",
635 	"RFS2_WRITE",
636 	"RFS2_CREATE",
637 	"RFS2_REMOVE",
638 	"RFS2_RENAME",
639 	"RFS2_LINK",
640 	"RFS2_SYMLINK",
641 	"RFS2_MKDIR",
642 	"RFS2_RMDIR",
643 	"RFS2_READDIR",
644 	"RFS2_STATFS"
645 };
646 
647 static struct rpcdisp rfsdisptab_v2[] = {
648 	/*
649 	 * NFS VERSION 2
650 	 */
651 
652 	/* RFS_NULL = 0 */
653 	{rpc_null,
654 	    xdr_void, NULL_xdrproc_t, 0,
655 	    xdr_void, NULL_xdrproc_t, 0,
656 	    nullfree, RPC_IDEMPOTENT,
657 	    0},
658 
659 	/* RFS_GETATTR = 1 */
660 	{rfs_getattr,
661 	    xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
662 	    xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
663 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
664 	    rfs_getattr_getfh},
665 
666 	/* RFS_SETATTR = 2 */
667 	{rfs_setattr,
668 	    xdr_saargs, NULL_xdrproc_t, sizeof (struct nfssaargs),
669 	    xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
670 	    nullfree, RPC_MAPRESP,
671 	    rfs_setattr_getfh},
672 
673 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
674 	{rfs_error,
675 	    xdr_void, NULL_xdrproc_t, 0,
676 	    xdr_void, NULL_xdrproc_t, 0,
677 	    nullfree, RPC_IDEMPOTENT,
678 	    0},
679 
680 	/* RFS_LOOKUP = 4 */
681 	{rfs_lookup,
682 	    xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
683 	    xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
684 	    nullfree, RPC_IDEMPOTENT|RPC_MAPRESP|RPC_PUBLICFH_OK,
685 	    rfs_lookup_getfh},
686 
687 	/* RFS_READLINK = 5 */
688 	{rfs_readlink,
689 	    xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
690 	    xdr_rdlnres, NULL_xdrproc_t, sizeof (struct nfsrdlnres),
691 	    rfs_rlfree, RPC_IDEMPOTENT,
692 	    rfs_readlink_getfh},
693 
694 	/* RFS_READ = 6 */
695 	{rfs_read,
696 	    xdr_readargs, NULL_xdrproc_t, sizeof (struct nfsreadargs),
697 	    xdr_rdresult, NULL_xdrproc_t, sizeof (struct nfsrdresult),
698 	    rfs_rdfree, RPC_IDEMPOTENT,
699 	    rfs_read_getfh},
700 
701 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
702 	{rfs_error,
703 	    xdr_void, NULL_xdrproc_t, 0,
704 	    xdr_void, NULL_xdrproc_t, 0,
705 	    nullfree, RPC_IDEMPOTENT,
706 	    0},
707 
708 	/* RFS_WRITE = 8 */
709 	{rfs_write,
710 	    xdr_writeargs, NULL_xdrproc_t, sizeof (struct nfswriteargs),
711 	    xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
712 	    nullfree, RPC_MAPRESP,
713 	    rfs_write_getfh},
714 
715 	/* RFS_CREATE = 9 */
716 	{rfs_create,
717 	    xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
718 	    xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
719 	    nullfree, RPC_MAPRESP,
720 	    rfs_create_getfh},
721 
722 	/* RFS_REMOVE = 10 */
723 	{rfs_remove,
724 	    xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
725 #ifdef _LITTLE_ENDIAN
726 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
727 #else
728 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
729 #endif
730 	    nullfree, RPC_MAPRESP,
731 	    rfs_remove_getfh},
732 
733 	/* RFS_RENAME = 11 */
734 	{rfs_rename,
735 	    xdr_rnmargs, NULL_xdrproc_t, sizeof (struct nfsrnmargs),
736 #ifdef _LITTLE_ENDIAN
737 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
738 #else
739 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
740 #endif
741 	    nullfree, RPC_MAPRESP,
742 	    rfs_rename_getfh},
743 
744 	/* RFS_LINK = 12 */
745 	{rfs_link,
746 	    xdr_linkargs, NULL_xdrproc_t, sizeof (struct nfslinkargs),
747 #ifdef _LITTLE_ENDIAN
748 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
749 #else
750 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
751 #endif
752 	    nullfree, RPC_MAPRESP,
753 	    rfs_link_getfh},
754 
755 	/* RFS_SYMLINK = 13 */
756 	{rfs_symlink,
757 	    xdr_slargs, NULL_xdrproc_t, sizeof (struct nfsslargs),
758 #ifdef _LITTLE_ENDIAN
759 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
760 #else
761 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
762 #endif
763 	    nullfree, RPC_MAPRESP,
764 	    rfs_symlink_getfh},
765 
766 	/* RFS_MKDIR = 14 */
767 	{rfs_mkdir,
768 	    xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
769 	    xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
770 	    nullfree, RPC_MAPRESP,
771 	    rfs_mkdir_getfh},
772 
773 	/* RFS_RMDIR = 15 */
774 	{rfs_rmdir,
775 	    xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
776 #ifdef _LITTLE_ENDIAN
777 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
778 #else
779 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
780 #endif
781 	    nullfree, RPC_MAPRESP,
782 	    rfs_rmdir_getfh},
783 
784 	/* RFS_READDIR = 16 */
785 	{rfs_readdir,
786 	    xdr_rddirargs, NULL_xdrproc_t, sizeof (struct nfsrddirargs),
787 	    xdr_putrddirres, NULL_xdrproc_t, sizeof (struct nfsrddirres),
788 	    rfs_rddirfree, RPC_IDEMPOTENT,
789 	    rfs_readdir_getfh},
790 
791 	/* RFS_STATFS = 17 */
792 	{rfs_statfs,
793 	    xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
794 	    xdr_statfs, xdr_faststatfs, sizeof (struct nfsstatfs),
795 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
796 	    rfs_statfs_getfh},
797 };
798 
799 static char *rfscallnames_v3[] = {
800 	"RFS3_NULL",
801 	"RFS3_GETATTR",
802 	"RFS3_SETATTR",
803 	"RFS3_LOOKUP",
804 	"RFS3_ACCESS",
805 	"RFS3_READLINK",
806 	"RFS3_READ",
807 	"RFS3_WRITE",
808 	"RFS3_CREATE",
809 	"RFS3_MKDIR",
810 	"RFS3_SYMLINK",
811 	"RFS3_MKNOD",
812 	"RFS3_REMOVE",
813 	"RFS3_RMDIR",
814 	"RFS3_RENAME",
815 	"RFS3_LINK",
816 	"RFS3_READDIR",
817 	"RFS3_READDIRPLUS",
818 	"RFS3_FSSTAT",
819 	"RFS3_FSINFO",
820 	"RFS3_PATHCONF",
821 	"RFS3_COMMIT"
822 };
823 
824 static struct rpcdisp rfsdisptab_v3[] = {
825 	/*
826 	 * NFS VERSION 3
827 	 */
828 
829 	/* RFS_NULL = 0 */
830 	{rpc_null_v3,
831 	    xdr_void, NULL_xdrproc_t, 0,
832 	    xdr_void, NULL_xdrproc_t, 0,
833 	    nullfree, RPC_IDEMPOTENT,
834 	    0},
835 
836 	/* RFS3_GETATTR = 1 */
837 	{rfs3_getattr,
838 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (GETATTR3args),
839 	    xdr_GETATTR3res, NULL_xdrproc_t, sizeof (GETATTR3res),
840 	    nullfree, (RPC_IDEMPOTENT | RPC_ALLOWANON),
841 	    rfs3_getattr_getfh},
842 
843 	/* RFS3_SETATTR = 2 */
844 	{rfs3_setattr,
845 	    xdr_SETATTR3args, NULL_xdrproc_t, sizeof (SETATTR3args),
846 	    xdr_SETATTR3res, NULL_xdrproc_t, sizeof (SETATTR3res),
847 	    nullfree, 0,
848 	    rfs3_setattr_getfh},
849 
850 	/* RFS3_LOOKUP = 3 */
851 	{rfs3_lookup,
852 	    xdr_diropargs3, NULL_xdrproc_t, sizeof (LOOKUP3args),
853 	    xdr_LOOKUP3res, NULL_xdrproc_t, sizeof (LOOKUP3res),
854 	    nullfree, (RPC_IDEMPOTENT | RPC_PUBLICFH_OK),
855 	    rfs3_lookup_getfh},
856 
857 	/* RFS3_ACCESS = 4 */
858 	{rfs3_access,
859 	    xdr_ACCESS3args, NULL_xdrproc_t, sizeof (ACCESS3args),
860 	    xdr_ACCESS3res, NULL_xdrproc_t, sizeof (ACCESS3res),
861 	    nullfree, RPC_IDEMPOTENT,
862 	    rfs3_access_getfh},
863 
864 	/* RFS3_READLINK = 5 */
865 	{rfs3_readlink,
866 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (READLINK3args),
867 	    xdr_READLINK3res, NULL_xdrproc_t, sizeof (READLINK3res),
868 	    rfs3_readlink_free, RPC_IDEMPOTENT,
869 	    rfs3_readlink_getfh},
870 
871 	/* RFS3_READ = 6 */
872 	{rfs3_read,
873 	    xdr_READ3args, NULL_xdrproc_t, sizeof (READ3args),
874 	    xdr_READ3res, NULL_xdrproc_t, sizeof (READ3res),
875 	    rfs3_read_free, RPC_IDEMPOTENT,
876 	    rfs3_read_getfh},
877 
878 	/* RFS3_WRITE = 7 */
879 	{rfs3_write,
880 	    xdr_WRITE3args, NULL_xdrproc_t, sizeof (WRITE3args),
881 	    xdr_WRITE3res, NULL_xdrproc_t, sizeof (WRITE3res),
882 	    nullfree, 0,
883 	    rfs3_write_getfh},
884 
885 	/* RFS3_CREATE = 8 */
886 	{rfs3_create,
887 	    xdr_CREATE3args, NULL_xdrproc_t, sizeof (CREATE3args),
888 	    xdr_CREATE3res, NULL_xdrproc_t, sizeof (CREATE3res),
889 	    nullfree, 0,
890 	    rfs3_create_getfh},
891 
892 	/* RFS3_MKDIR = 9 */
893 	{rfs3_mkdir,
894 	    xdr_MKDIR3args, NULL_xdrproc_t, sizeof (MKDIR3args),
895 	    xdr_MKDIR3res, NULL_xdrproc_t, sizeof (MKDIR3res),
896 	    nullfree, 0,
897 	    rfs3_mkdir_getfh},
898 
899 	/* RFS3_SYMLINK = 10 */
900 	{rfs3_symlink,
901 	    xdr_SYMLINK3args, NULL_xdrproc_t, sizeof (SYMLINK3args),
902 	    xdr_SYMLINK3res, NULL_xdrproc_t, sizeof (SYMLINK3res),
903 	    nullfree, 0,
904 	    rfs3_symlink_getfh},
905 
906 	/* RFS3_MKNOD = 11 */
907 	{rfs3_mknod,
908 	    xdr_MKNOD3args, NULL_xdrproc_t, sizeof (MKNOD3args),
909 	    xdr_MKNOD3res, NULL_xdrproc_t, sizeof (MKNOD3res),
910 	    nullfree, 0,
911 	    rfs3_mknod_getfh},
912 
913 	/* RFS3_REMOVE = 12 */
914 	{rfs3_remove,
915 	    xdr_diropargs3, NULL_xdrproc_t, sizeof (REMOVE3args),
916 	    xdr_REMOVE3res, NULL_xdrproc_t, sizeof (REMOVE3res),
917 	    nullfree, 0,
918 	    rfs3_remove_getfh},
919 
920 	/* RFS3_RMDIR = 13 */
921 	{rfs3_rmdir,
922 	    xdr_diropargs3, NULL_xdrproc_t, sizeof (RMDIR3args),
923 	    xdr_RMDIR3res, NULL_xdrproc_t, sizeof (RMDIR3res),
924 	    nullfree, 0,
925 	    rfs3_rmdir_getfh},
926 
927 	/* RFS3_RENAME = 14 */
928 	{rfs3_rename,
929 	    xdr_RENAME3args, NULL_xdrproc_t, sizeof (RENAME3args),
930 	    xdr_RENAME3res, NULL_xdrproc_t, sizeof (RENAME3res),
931 	    nullfree, 0,
932 	    rfs3_rename_getfh},
933 
934 	/* RFS3_LINK = 15 */
935 	{rfs3_link,
936 	    xdr_LINK3args, NULL_xdrproc_t, sizeof (LINK3args),
937 	    xdr_LINK3res, NULL_xdrproc_t, sizeof (LINK3res),
938 	    nullfree, 0,
939 	    rfs3_link_getfh},
940 
941 	/* RFS3_READDIR = 16 */
942 	{rfs3_readdir,
943 	    xdr_READDIR3args, NULL_xdrproc_t, sizeof (READDIR3args),
944 	    xdr_READDIR3res, NULL_xdrproc_t, sizeof (READDIR3res),
945 	    rfs3_readdir_free, RPC_IDEMPOTENT,
946 	    rfs3_readdir_getfh},
947 
948 	/* RFS3_READDIRPLUS = 17 */
949 	{rfs3_readdirplus,
950 	    xdr_READDIRPLUS3args, NULL_xdrproc_t, sizeof (READDIRPLUS3args),
951 	    xdr_READDIRPLUS3res, NULL_xdrproc_t, sizeof (READDIRPLUS3res),
952 	    rfs3_readdirplus_free, RPC_AVOIDWORK,
953 	    rfs3_readdirplus_getfh},
954 
955 	/* RFS3_FSSTAT = 18 */
956 	{rfs3_fsstat,
957 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSSTAT3args),
958 	    xdr_FSSTAT3res, NULL_xdrproc_t, sizeof (FSSTAT3res),
959 	    nullfree, RPC_IDEMPOTENT,
960 	    rfs3_fsstat_getfh},
961 
962 	/* RFS3_FSINFO = 19 */
963 	{rfs3_fsinfo,
964 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSINFO3args),
965 	    xdr_FSINFO3res, NULL_xdrproc_t, sizeof (FSINFO3res),
966 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON,
967 	    rfs3_fsinfo_getfh},
968 
969 	/* RFS3_PATHCONF = 20 */
970 	{rfs3_pathconf,
971 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (PATHCONF3args),
972 	    xdr_PATHCONF3res, NULL_xdrproc_t, sizeof (PATHCONF3res),
973 	    nullfree, RPC_IDEMPOTENT,
974 	    rfs3_pathconf_getfh},
975 
976 	/* RFS3_COMMIT = 21 */
977 	{rfs3_commit,
978 	    xdr_COMMIT3args, NULL_xdrproc_t, sizeof (COMMIT3args),
979 	    xdr_COMMIT3res, NULL_xdrproc_t, sizeof (COMMIT3res),
980 	    nullfree, RPC_IDEMPOTENT,
981 	    rfs3_commit_getfh},
982 };
983 
984 static char *rfscallnames_v4[] = {
985 	"RFS4_NULL",
986 	"RFS4_COMPOUND",
987 	"RFS4_NULL",
988 	"RFS4_NULL",
989 	"RFS4_NULL",
990 	"RFS4_NULL",
991 	"RFS4_NULL",
992 	"RFS4_NULL",
993 	"RFS4_CREATE"
994 };
995 
996 static struct rpcdisp rfsdisptab_v4[] = {
997 	/*
998 	 * NFS VERSION 4
999 	 */
1000 
1001 	/* RFS_NULL = 0 */
1002 	{rpc_null,
1003 	    xdr_void, NULL_xdrproc_t, 0,
1004 	    xdr_void, NULL_xdrproc_t, 0,
1005 	    nullfree, RPC_IDEMPOTENT, 0},
1006 
1007 	/* RFS4_compound = 1 */
1008 	{rfs4_compound,
1009 	    xdr_COMPOUND4args_srv, NULL_xdrproc_t, sizeof (COMPOUND4args),
1010 	    xdr_COMPOUND4res_srv, NULL_xdrproc_t, sizeof (COMPOUND4res),
1011 	    rfs4_compound_free, 0, 0},
1012 };
1013 
1014 union rfs_args {
1015 	/*
1016 	 * NFS VERSION 2
1017 	 */
1018 
1019 	/* RFS_NULL = 0 */
1020 
1021 	/* RFS_GETATTR = 1 */
1022 	fhandle_t nfs2_getattr_args;
1023 
1024 	/* RFS_SETATTR = 2 */
1025 	struct nfssaargs nfs2_setattr_args;
1026 
1027 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1028 
1029 	/* RFS_LOOKUP = 4 */
1030 	struct nfsdiropargs nfs2_lookup_args;
1031 
1032 	/* RFS_READLINK = 5 */
1033 	fhandle_t nfs2_readlink_args;
1034 
1035 	/* RFS_READ = 6 */
1036 	struct nfsreadargs nfs2_read_args;
1037 
1038 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1039 
1040 	/* RFS_WRITE = 8 */
1041 	struct nfswriteargs nfs2_write_args;
1042 
1043 	/* RFS_CREATE = 9 */
1044 	struct nfscreatargs nfs2_create_args;
1045 
1046 	/* RFS_REMOVE = 10 */
1047 	struct nfsdiropargs nfs2_remove_args;
1048 
1049 	/* RFS_RENAME = 11 */
1050 	struct nfsrnmargs nfs2_rename_args;
1051 
1052 	/* RFS_LINK = 12 */
1053 	struct nfslinkargs nfs2_link_args;
1054 
1055 	/* RFS_SYMLINK = 13 */
1056 	struct nfsslargs nfs2_symlink_args;
1057 
1058 	/* RFS_MKDIR = 14 */
1059 	struct nfscreatargs nfs2_mkdir_args;
1060 
1061 	/* RFS_RMDIR = 15 */
1062 	struct nfsdiropargs nfs2_rmdir_args;
1063 
1064 	/* RFS_READDIR = 16 */
1065 	struct nfsrddirargs nfs2_readdir_args;
1066 
1067 	/* RFS_STATFS = 17 */
1068 	fhandle_t nfs2_statfs_args;
1069 
1070 	/*
1071 	 * NFS VERSION 3
1072 	 */
1073 
1074 	/* RFS_NULL = 0 */
1075 
1076 	/* RFS3_GETATTR = 1 */
1077 	GETATTR3args nfs3_getattr_args;
1078 
1079 	/* RFS3_SETATTR = 2 */
1080 	SETATTR3args nfs3_setattr_args;
1081 
1082 	/* RFS3_LOOKUP = 3 */
1083 	LOOKUP3args nfs3_lookup_args;
1084 
1085 	/* RFS3_ACCESS = 4 */
1086 	ACCESS3args nfs3_access_args;
1087 
1088 	/* RFS3_READLINK = 5 */
1089 	READLINK3args nfs3_readlink_args;
1090 
1091 	/* RFS3_READ = 6 */
1092 	READ3args nfs3_read_args;
1093 
1094 	/* RFS3_WRITE = 7 */
1095 	WRITE3args nfs3_write_args;
1096 
1097 	/* RFS3_CREATE = 8 */
1098 	CREATE3args nfs3_create_args;
1099 
1100 	/* RFS3_MKDIR = 9 */
1101 	MKDIR3args nfs3_mkdir_args;
1102 
1103 	/* RFS3_SYMLINK = 10 */
1104 	SYMLINK3args nfs3_symlink_args;
1105 
1106 	/* RFS3_MKNOD = 11 */
1107 	MKNOD3args nfs3_mknod_args;
1108 
1109 	/* RFS3_REMOVE = 12 */
1110 	REMOVE3args nfs3_remove_args;
1111 
1112 	/* RFS3_RMDIR = 13 */
1113 	RMDIR3args nfs3_rmdir_args;
1114 
1115 	/* RFS3_RENAME = 14 */
1116 	RENAME3args nfs3_rename_args;
1117 
1118 	/* RFS3_LINK = 15 */
1119 	LINK3args nfs3_link_args;
1120 
1121 	/* RFS3_READDIR = 16 */
1122 	READDIR3args nfs3_readdir_args;
1123 
1124 	/* RFS3_READDIRPLUS = 17 */
1125 	READDIRPLUS3args nfs3_readdirplus_args;
1126 
1127 	/* RFS3_FSSTAT = 18 */
1128 	FSSTAT3args nfs3_fsstat_args;
1129 
1130 	/* RFS3_FSINFO = 19 */
1131 	FSINFO3args nfs3_fsinfo_args;
1132 
1133 	/* RFS3_PATHCONF = 20 */
1134 	PATHCONF3args nfs3_pathconf_args;
1135 
1136 	/* RFS3_COMMIT = 21 */
1137 	COMMIT3args nfs3_commit_args;
1138 
1139 	/*
1140 	 * NFS VERSION 4
1141 	 */
1142 
1143 	/* RFS_NULL = 0 */
1144 
1145 	/* COMPUND = 1 */
1146 	COMPOUND4args nfs4_compound_args;
1147 };
1148 
1149 union rfs_res {
1150 	/*
1151 	 * NFS VERSION 2
1152 	 */
1153 
1154 	/* RFS_NULL = 0 */
1155 
1156 	/* RFS_GETATTR = 1 */
1157 	struct nfsattrstat nfs2_getattr_res;
1158 
1159 	/* RFS_SETATTR = 2 */
1160 	struct nfsattrstat nfs2_setattr_res;
1161 
1162 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1163 
1164 	/* RFS_LOOKUP = 4 */
1165 	struct nfsdiropres nfs2_lookup_res;
1166 
1167 	/* RFS_READLINK = 5 */
1168 	struct nfsrdlnres nfs2_readlink_res;
1169 
1170 	/* RFS_READ = 6 */
1171 	struct nfsrdresult nfs2_read_res;
1172 
1173 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1174 
1175 	/* RFS_WRITE = 8 */
1176 	struct nfsattrstat nfs2_write_res;
1177 
1178 	/* RFS_CREATE = 9 */
1179 	struct nfsdiropres nfs2_create_res;
1180 
1181 	/* RFS_REMOVE = 10 */
1182 	enum nfsstat nfs2_remove_res;
1183 
1184 	/* RFS_RENAME = 11 */
1185 	enum nfsstat nfs2_rename_res;
1186 
1187 	/* RFS_LINK = 12 */
1188 	enum nfsstat nfs2_link_res;
1189 
1190 	/* RFS_SYMLINK = 13 */
1191 	enum nfsstat nfs2_symlink_res;
1192 
1193 	/* RFS_MKDIR = 14 */
1194 	struct nfsdiropres nfs2_mkdir_res;
1195 
1196 	/* RFS_RMDIR = 15 */
1197 	enum nfsstat nfs2_rmdir_res;
1198 
1199 	/* RFS_READDIR = 16 */
1200 	struct nfsrddirres nfs2_readdir_res;
1201 
1202 	/* RFS_STATFS = 17 */
1203 	struct nfsstatfs nfs2_statfs_res;
1204 
1205 	/*
1206 	 * NFS VERSION 3
1207 	 */
1208 
1209 	/* RFS_NULL = 0 */
1210 
1211 	/* RFS3_GETATTR = 1 */
1212 	GETATTR3res nfs3_getattr_res;
1213 
1214 	/* RFS3_SETATTR = 2 */
1215 	SETATTR3res nfs3_setattr_res;
1216 
1217 	/* RFS3_LOOKUP = 3 */
1218 	LOOKUP3res nfs3_lookup_res;
1219 
1220 	/* RFS3_ACCESS = 4 */
1221 	ACCESS3res nfs3_access_res;
1222 
1223 	/* RFS3_READLINK = 5 */
1224 	READLINK3res nfs3_readlink_res;
1225 
1226 	/* RFS3_READ = 6 */
1227 	READ3res nfs3_read_res;
1228 
1229 	/* RFS3_WRITE = 7 */
1230 	WRITE3res nfs3_write_res;
1231 
1232 	/* RFS3_CREATE = 8 */
1233 	CREATE3res nfs3_create_res;
1234 
1235 	/* RFS3_MKDIR = 9 */
1236 	MKDIR3res nfs3_mkdir_res;
1237 
1238 	/* RFS3_SYMLINK = 10 */
1239 	SYMLINK3res nfs3_symlink_res;
1240 
1241 	/* RFS3_MKNOD = 11 */
1242 	MKNOD3res nfs3_mknod_res;
1243 
1244 	/* RFS3_REMOVE = 12 */
1245 	REMOVE3res nfs3_remove_res;
1246 
1247 	/* RFS3_RMDIR = 13 */
1248 	RMDIR3res nfs3_rmdir_res;
1249 
1250 	/* RFS3_RENAME = 14 */
1251 	RENAME3res nfs3_rename_res;
1252 
1253 	/* RFS3_LINK = 15 */
1254 	LINK3res nfs3_link_res;
1255 
1256 	/* RFS3_READDIR = 16 */
1257 	READDIR3res nfs3_readdir_res;
1258 
1259 	/* RFS3_READDIRPLUS = 17 */
1260 	READDIRPLUS3res nfs3_readdirplus_res;
1261 
1262 	/* RFS3_FSSTAT = 18 */
1263 	FSSTAT3res nfs3_fsstat_res;
1264 
1265 	/* RFS3_FSINFO = 19 */
1266 	FSINFO3res nfs3_fsinfo_res;
1267 
1268 	/* RFS3_PATHCONF = 20 */
1269 	PATHCONF3res nfs3_pathconf_res;
1270 
1271 	/* RFS3_COMMIT = 21 */
1272 	COMMIT3res nfs3_commit_res;
1273 
1274 	/*
1275 	 * NFS VERSION 4
1276 	 */
1277 
1278 	/* RFS_NULL = 0 */
1279 
1280 	/* RFS4_COMPOUND = 1 */
1281 	COMPOUND4res nfs4_compound_res;
1282 
1283 };
1284 
1285 static struct rpc_disptable rfs_disptable[] = {
1286 	{sizeof (rfsdisptab_v2) / sizeof (rfsdisptab_v2[0]),
1287 	    rfscallnames_v2,
1288 	    &rfsproccnt_v2_ptr, rfsdisptab_v2},
1289 	{sizeof (rfsdisptab_v3) / sizeof (rfsdisptab_v3[0]),
1290 	    rfscallnames_v3,
1291 	    &rfsproccnt_v3_ptr, rfsdisptab_v3},
1292 	{sizeof (rfsdisptab_v4) / sizeof (rfsdisptab_v4[0]),
1293 	    rfscallnames_v4,
1294 	    &rfsproccnt_v4_ptr, rfsdisptab_v4},
1295 };
1296 
1297 /*
1298  * If nfs_portmon is set, then clients are required to use privileged
1299  * ports (ports < IPPORT_RESERVED) in order to get NFS services.
1300  *
1301  * N.B.: this attempt to carry forward the already ill-conceived notion
1302  * of privileged ports for TCP/UDP is really quite ineffectual.  Not only
1303  * is it transport-dependent, it's laughably easy to spoof.  If you're
1304  * really interested in security, you must start with secure RPC instead.
1305  */
1306 static int nfs_portmon = 0;
1307 
1308 #ifdef DEBUG
1309 static int cred_hits = 0;
1310 static int cred_misses = 0;
1311 #endif
1312 
1313 
1314 #ifdef DEBUG
1315 /*
1316  * Debug code to allow disabling of rfs_dispatch() use of
1317  * fastxdrargs() and fastxdrres() calls for testing purposes.
1318  */
1319 static int rfs_no_fast_xdrargs = 0;
1320 static int rfs_no_fast_xdrres = 0;
1321 #endif
1322 
1323 union acl_args {
1324 	/*
1325 	 * ACL VERSION 2
1326 	 */
1327 
1328 	/* ACL2_NULL = 0 */
1329 
1330 	/* ACL2_GETACL = 1 */
1331 	GETACL2args acl2_getacl_args;
1332 
1333 	/* ACL2_SETACL = 2 */
1334 	SETACL2args acl2_setacl_args;
1335 
1336 	/* ACL2_GETATTR = 3 */
1337 	GETATTR2args acl2_getattr_args;
1338 
1339 	/* ACL2_ACCESS = 4 */
1340 	ACCESS2args acl2_access_args;
1341 
1342 	/* ACL2_GETXATTRDIR = 5 */
1343 	GETXATTRDIR2args acl2_getxattrdir_args;
1344 
1345 	/*
1346 	 * ACL VERSION 3
1347 	 */
1348 
1349 	/* ACL3_NULL = 0 */
1350 
1351 	/* ACL3_GETACL = 1 */
1352 	GETACL3args acl3_getacl_args;
1353 
1354 	/* ACL3_SETACL = 2 */
1355 	SETACL3args acl3_setacl;
1356 
1357 	/* ACL3_GETXATTRDIR = 3 */
1358 	GETXATTRDIR3args acl3_getxattrdir_args;
1359 
1360 };
1361 
1362 union acl_res {
1363 	/*
1364 	 * ACL VERSION 2
1365 	 */
1366 
1367 	/* ACL2_NULL = 0 */
1368 
1369 	/* ACL2_GETACL = 1 */
1370 	GETACL2res acl2_getacl_res;
1371 
1372 	/* ACL2_SETACL = 2 */
1373 	SETACL2res acl2_setacl_res;
1374 
1375 	/* ACL2_GETATTR = 3 */
1376 	GETATTR2res acl2_getattr_res;
1377 
1378 	/* ACL2_ACCESS = 4 */
1379 	ACCESS2res acl2_access_res;
1380 
1381 	/* ACL2_GETXATTRDIR = 5 */
1382 	GETXATTRDIR2args acl2_getxattrdir_res;
1383 
1384 	/*
1385 	 * ACL VERSION 3
1386 	 */
1387 
1388 	/* ACL3_NULL = 0 */
1389 
1390 	/* ACL3_GETACL = 1 */
1391 	GETACL3res acl3_getacl_res;
1392 
1393 	/* ACL3_SETACL = 2 */
1394 	SETACL3res acl3_setacl_res;
1395 
1396 	/* ACL3_GETXATTRDIR = 3 */
1397 	GETXATTRDIR3res acl3_getxattrdir_res;
1398 
1399 };
1400 
1401 static bool_t
1402 auth_tooweak(struct svc_req *req, char *res)
1403 {
1404 
1405 	if (req->rq_vers == NFS_VERSION && req->rq_proc == RFS_LOOKUP) {
1406 		struct nfsdiropres *dr = (struct nfsdiropres *)res;
1407 		if (dr->dr_status == WNFSERR_CLNT_FLAVOR)
1408 			return (TRUE);
1409 	} else if (req->rq_vers == NFS_V3 && req->rq_proc == NFSPROC3_LOOKUP) {
1410 		LOOKUP3res *resp = (LOOKUP3res *)res;
1411 		if (resp->status == WNFSERR_CLNT_FLAVOR)
1412 			return (TRUE);
1413 	}
1414 	return (FALSE);
1415 }
1416 
1417 
1418 static void
1419 common_dispatch(struct svc_req *req, SVCXPRT *xprt, rpcvers_t min_vers,
1420 		rpcvers_t max_vers, char *pgmname,
1421 		struct rpc_disptable *disptable)
1422 {
1423 	int which;
1424 	rpcvers_t vers;
1425 	char *args;
1426 	union {
1427 			union rfs_args ra;
1428 			union acl_args aa;
1429 		} args_buf;
1430 	char *res;
1431 	union {
1432 			union rfs_res rr;
1433 			union acl_res ar;
1434 		} res_buf;
1435 	struct rpcdisp *disp = NULL;
1436 	int dis_flags = 0;
1437 	cred_t *cr;
1438 	int error = 0;
1439 	int anon_ok;
1440 	struct exportinfo *exi = NULL;
1441 	unsigned int nfslog_rec_id;
1442 	int dupstat;
1443 	struct dupreq *dr;
1444 	int authres;
1445 	bool_t publicfh_ok = FALSE;
1446 	enum_t auth_flavor;
1447 	bool_t dupcached = FALSE;
1448 	struct netbuf	nb;
1449 	bool_t logging_enabled = FALSE;
1450 	struct exportinfo *nfslog_exi = NULL;
1451 	char **procnames;
1452 	char cbuf[INET6_ADDRSTRLEN];	/* to hold both IPv4 and IPv6 addr */
1453 
1454 	vers = req->rq_vers;
1455 
1456 	if (vers < min_vers || vers > max_vers) {
1457 		svcerr_progvers(req->rq_xprt, min_vers, max_vers);
1458 		error++;
1459 		cmn_err(CE_NOTE, "%s: bad version number %u", pgmname, vers);
1460 		goto done;
1461 	}
1462 	vers -= min_vers;
1463 
1464 	which = req->rq_proc;
1465 	if (which < 0 || which >= disptable[(int)vers].dis_nprocs) {
1466 		svcerr_noproc(req->rq_xprt);
1467 		error++;
1468 		goto done;
1469 	}
1470 
1471 	(*(disptable[(int)vers].dis_proccntp))[which].value.ui64++;
1472 
1473 	disp = &disptable[(int)vers].dis_table[which];
1474 	procnames = disptable[(int)vers].dis_procnames;
1475 
1476 	auth_flavor = req->rq_cred.oa_flavor;
1477 
1478 	/*
1479 	 * Deserialize into the args struct.
1480 	 */
1481 	args = (char *)&args_buf;
1482 
1483 #ifdef DEBUG
1484 	if (rfs_no_fast_xdrargs || (auth_flavor == RPCSEC_GSS) ||
1485 	    disp->dis_fastxdrargs == NULL_xdrproc_t ||
1486 	    !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1487 #else
1488 	if ((auth_flavor == RPCSEC_GSS) ||
1489 	    disp->dis_fastxdrargs == NULL_xdrproc_t ||
1490 	    !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1491 #endif
1492 	{
1493 		bzero(args, disp->dis_argsz);
1494 		if (!SVC_GETARGS(xprt, disp->dis_xdrargs, args)) {
1495 			error++;
1496 			/*
1497 			 * Check if we are outside our capabilities.
1498 			 */
1499 			if (rfs4_minorvers_mismatch(req, xprt, (void *)args))
1500 				goto done;
1501 
1502 			svcerr_decode(xprt);
1503 			cmn_err(CE_NOTE,
1504 			    "Failed to decode arguments for %s version %u "
1505 			    "procedure %s client %s%s",
1506 			    pgmname, vers + min_vers, procnames[which],
1507 			    client_name(req), client_addr(req, cbuf));
1508 			goto done;
1509 		}
1510 	}
1511 
1512 	/*
1513 	 * If Version 4 use that specific dispatch function.
1514 	 */
1515 	if (req->rq_vers == 4) {
1516 		error += rfs4_dispatch(disp, req, xprt, args);
1517 		goto done;
1518 	}
1519 
1520 	dis_flags = disp->dis_flags;
1521 
1522 	/*
1523 	 * Find export information and check authentication,
1524 	 * setting the credential if everything is ok.
1525 	 */
1526 	if (disp->dis_getfh != NULL) {
1527 		void *fh;
1528 		fsid_t *fsid;
1529 		fid_t *fid, *xfid;
1530 		fhandle_t *fh2;
1531 		nfs_fh3 *fh3;
1532 
1533 		fh = (*disp->dis_getfh)(args);
1534 		switch (req->rq_vers) {
1535 		case NFS_VERSION:
1536 			fh2 = (fhandle_t *)fh;
1537 			fsid = &fh2->fh_fsid;
1538 			fid = (fid_t *)&fh2->fh_len;
1539 			xfid = (fid_t *)&fh2->fh_xlen;
1540 			break;
1541 		case NFS_V3:
1542 			fh3 = (nfs_fh3 *)fh;
1543 			fsid = &fh3->fh3_fsid;
1544 			fid = FH3TOFIDP(fh3);
1545 			xfid = FH3TOXFIDP(fh3);
1546 			break;
1547 		}
1548 
1549 		/*
1550 		 * Fix for bug 1038302 - corbin
1551 		 * There is a problem here if anonymous access is
1552 		 * disallowed.  If the current request is part of the
1553 		 * client's mount process for the requested filesystem,
1554 		 * then it will carry root (uid 0) credentials on it, and
1555 		 * will be denied by checkauth if that client does not
1556 		 * have explicit root=0 permission.  This will cause the
1557 		 * client's mount operation to fail.  As a work-around,
1558 		 * we check here to see if the request is a getattr or
1559 		 * statfs operation on the exported vnode itself, and
1560 		 * pass a flag to checkauth with the result of this test.
1561 		 *
1562 		 * The filehandle refers to the mountpoint itself if
1563 		 * the fh_data and fh_xdata portions of the filehandle
1564 		 * are equal.
1565 		 *
1566 		 * Added anon_ok argument to checkauth().
1567 		 */
1568 
1569 		if ((dis_flags & RPC_ALLOWANON) && EQFID(fid, xfid))
1570 			anon_ok = 1;
1571 		else
1572 			anon_ok = 0;
1573 
1574 		cr = xprt->xp_cred;
1575 		ASSERT(cr != NULL);
1576 #ifdef DEBUG
1577 		if (crgetref(cr) != 1) {
1578 			crfree(cr);
1579 			cr = crget();
1580 			xprt->xp_cred = cr;
1581 			cred_misses++;
1582 		} else
1583 			cred_hits++;
1584 #else
1585 		if (crgetref(cr) != 1) {
1586 			crfree(cr);
1587 			cr = crget();
1588 			xprt->xp_cred = cr;
1589 		}
1590 #endif
1591 
1592 		exi = checkexport(fsid, xfid);
1593 
1594 		if (exi != NULL) {
1595 			publicfh_ok = PUBLICFH_CHECK(disp, exi, fsid, xfid);
1596 
1597 			/*
1598 			 * Don't allow non-V4 clients access
1599 			 * to pseudo exports
1600 			 */
1601 			if (PSEUDO(exi)) {
1602 				svcerr_weakauth(xprt);
1603 				error++;
1604 				goto done;
1605 			}
1606 
1607 			authres = checkauth(exi, req, cr, anon_ok, publicfh_ok);
1608 			/*
1609 			 * authres >  0: authentication OK - proceed
1610 			 * authres == 0: authentication weak - return error
1611 			 * authres <  0: authentication timeout - drop
1612 			 */
1613 			if (authres <= 0) {
1614 				if (authres == 0) {
1615 					svcerr_weakauth(xprt);
1616 					error++;
1617 				}
1618 				goto done;
1619 			}
1620 
1621 			/* check to see if we might need charmap */
1622 			if (exi->exi_export.ex_flags & EX_CHARMAP) {
1623 				struct sockaddr *ca;
1624 				ca =  (struct sockaddr *)
1625 				    svc_getrpccaller(req->rq_xprt)->buf;
1626 				(void) nfscmd_charmap(exi, ca);
1627 			}
1628 		}
1629 	} else
1630 		cr = NULL;
1631 
1632 	if ((dis_flags & RPC_MAPRESP) && (auth_flavor != RPCSEC_GSS)) {
1633 		res = (char *)SVC_GETRES(xprt, disp->dis_ressz);
1634 		if (res == NULL)
1635 			res = (char *)&res_buf;
1636 	} else
1637 		res = (char *)&res_buf;
1638 
1639 	if (!(dis_flags & RPC_IDEMPOTENT)) {
1640 		dupstat = SVC_DUP_EXT(xprt, req, res, disp->dis_ressz, &dr,
1641 		    &dupcached);
1642 
1643 		switch (dupstat) {
1644 		case DUP_ERROR:
1645 			svcerr_systemerr(xprt);
1646 			error++;
1647 			goto done;
1648 			/* NOTREACHED */
1649 		case DUP_INPROGRESS:
1650 			if (res != (char *)&res_buf)
1651 				SVC_FREERES(xprt);
1652 			error++;
1653 			goto done;
1654 			/* NOTREACHED */
1655 		case DUP_NEW:
1656 		case DUP_DROP:
1657 			curthread->t_flag |= T_DONTPEND;
1658 
1659 			(*disp->dis_proc)(args, res, exi, req, cr);
1660 
1661 			curthread->t_flag &= ~T_DONTPEND;
1662 			if (curthread->t_flag & T_WOULDBLOCK) {
1663 				curthread->t_flag &= ~T_WOULDBLOCK;
1664 				SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1665 				    disp->dis_ressz, DUP_DROP);
1666 				if (res != (char *)&res_buf)
1667 					SVC_FREERES(xprt);
1668 				error++;
1669 				goto done;
1670 			}
1671 			if (dis_flags & RPC_AVOIDWORK) {
1672 				SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1673 				    disp->dis_ressz, DUP_DROP);
1674 			} else {
1675 				SVC_DUPDONE_EXT(xprt, dr, res,
1676 				    disp->dis_resfree == nullfree ? NULL :
1677 				    disp->dis_resfree,
1678 				    disp->dis_ressz, DUP_DONE);
1679 				dupcached = TRUE;
1680 			}
1681 			break;
1682 		case DUP_DONE:
1683 			break;
1684 		}
1685 
1686 	} else {
1687 		curthread->t_flag |= T_DONTPEND;
1688 
1689 		(*disp->dis_proc)(args, res, exi, req, cr);
1690 
1691 		curthread->t_flag &= ~T_DONTPEND;
1692 		if (curthread->t_flag & T_WOULDBLOCK) {
1693 			curthread->t_flag &= ~T_WOULDBLOCK;
1694 			if (res != (char *)&res_buf)
1695 				SVC_FREERES(xprt);
1696 			error++;
1697 			goto done;
1698 		}
1699 	}
1700 
1701 	if (auth_tooweak(req, res)) {
1702 		svcerr_weakauth(xprt);
1703 		error++;
1704 		goto done;
1705 	}
1706 
1707 	/*
1708 	 * Check to see if logging has been enabled on the server.
1709 	 * If so, then obtain the export info struct to be used for
1710 	 * the later writing of the log record.  This is done for
1711 	 * the case that a lookup is done across a non-logged public
1712 	 * file system.
1713 	 */
1714 	if (nfslog_buffer_list != NULL) {
1715 		nfslog_exi = nfslog_get_exi(exi, req, res, &nfslog_rec_id);
1716 		/*
1717 		 * Is logging enabled?
1718 		 */
1719 		logging_enabled = (nfslog_exi != NULL);
1720 
1721 		/*
1722 		 * Copy the netbuf for logging purposes, before it is
1723 		 * freed by svc_sendreply().
1724 		 */
1725 		if (logging_enabled) {
1726 			NFSLOG_COPY_NETBUF(nfslog_exi, xprt, &nb);
1727 			/*
1728 			 * If RPC_MAPRESP flag set (i.e. in V2 ops) the
1729 			 * res gets copied directly into the mbuf and
1730 			 * may be freed soon after the sendreply. So we
1731 			 * must copy it here to a safe place...
1732 			 */
1733 			if (res != (char *)&res_buf) {
1734 				bcopy(res, (char *)&res_buf, disp->dis_ressz);
1735 			}
1736 		}
1737 	}
1738 
1739 	/*
1740 	 * Serialize and send results struct
1741 	 */
1742 #ifdef DEBUG
1743 	if (rfs_no_fast_xdrres == 0 && res != (char *)&res_buf)
1744 #else
1745 	if (res != (char *)&res_buf)
1746 #endif
1747 	{
1748 		if (!svc_sendreply(xprt, disp->dis_fastxdrres, res)) {
1749 			cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1750 			error++;
1751 		}
1752 	} else {
1753 		if (!svc_sendreply(xprt, disp->dis_xdrres, res)) {
1754 			cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1755 			error++;
1756 		}
1757 	}
1758 
1759 	/*
1760 	 * Log if needed
1761 	 */
1762 	if (logging_enabled) {
1763 		nfslog_write_record(nfslog_exi, req, args, (char *)&res_buf,
1764 		    cr, &nb, nfslog_rec_id, NFSLOG_ONE_BUFFER);
1765 		exi_rele(nfslog_exi);
1766 		kmem_free((&nb)->buf, (&nb)->len);
1767 	}
1768 
1769 	/*
1770 	 * Free results struct. With the addition of NFS V4 we can
1771 	 * have non-idempotent procedures with functions.
1772 	 */
1773 	if (disp->dis_resfree != nullfree && dupcached == FALSE) {
1774 		(*disp->dis_resfree)(res);
1775 	}
1776 
1777 done:
1778 	/*
1779 	 * Free arguments struct
1780 	 */
1781 	if (disp) {
1782 		if (!SVC_FREEARGS(xprt, disp->dis_xdrargs, args)) {
1783 			cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1784 			error++;
1785 		}
1786 	} else {
1787 		if (!SVC_FREEARGS(xprt, (xdrproc_t)0, (caddr_t)0)) {
1788 			cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1789 			error++;
1790 		}
1791 	}
1792 
1793 	if (exi != NULL)
1794 		exi_rele(exi);
1795 
1796 	global_svstat_ptr[req->rq_vers][NFS_BADCALLS].value.ui64 += error;
1797 
1798 	global_svstat_ptr[req->rq_vers][NFS_CALLS].value.ui64++;
1799 }
1800 
1801 static void
1802 rfs_dispatch(struct svc_req *req, SVCXPRT *xprt)
1803 {
1804 	common_dispatch(req, xprt, NFS_VERSMIN, NFS_VERSMAX,
1805 	    "NFS", rfs_disptable);
1806 }
1807 
1808 static char *aclcallnames_v2[] = {
1809 	"ACL2_NULL",
1810 	"ACL2_GETACL",
1811 	"ACL2_SETACL",
1812 	"ACL2_GETATTR",
1813 	"ACL2_ACCESS",
1814 	"ACL2_GETXATTRDIR"
1815 };
1816 
1817 static struct rpcdisp acldisptab_v2[] = {
1818 	/*
1819 	 * ACL VERSION 2
1820 	 */
1821 
1822 	/* ACL2_NULL = 0 */
1823 	{rpc_null,
1824 	    xdr_void, NULL_xdrproc_t, 0,
1825 	    xdr_void, NULL_xdrproc_t, 0,
1826 	    nullfree, RPC_IDEMPOTENT,
1827 	    0},
1828 
1829 	/* ACL2_GETACL = 1 */
1830 	{acl2_getacl,
1831 	    xdr_GETACL2args, xdr_fastGETACL2args, sizeof (GETACL2args),
1832 	    xdr_GETACL2res, NULL_xdrproc_t, sizeof (GETACL2res),
1833 	    acl2_getacl_free, RPC_IDEMPOTENT,
1834 	    acl2_getacl_getfh},
1835 
1836 	/* ACL2_SETACL = 2 */
1837 	{acl2_setacl,
1838 	    xdr_SETACL2args, NULL_xdrproc_t, sizeof (SETACL2args),
1839 #ifdef _LITTLE_ENDIAN
1840 	    xdr_SETACL2res, xdr_fastSETACL2res, sizeof (SETACL2res),
1841 #else
1842 	    xdr_SETACL2res, NULL_xdrproc_t, sizeof (SETACL2res),
1843 #endif
1844 	    nullfree, RPC_MAPRESP,
1845 	    acl2_setacl_getfh},
1846 
1847 	/* ACL2_GETATTR = 3 */
1848 	{acl2_getattr,
1849 	    xdr_GETATTR2args, xdr_fastGETATTR2args, sizeof (GETATTR2args),
1850 #ifdef _LITTLE_ENDIAN
1851 	    xdr_GETATTR2res, xdr_fastGETATTR2res, sizeof (GETATTR2res),
1852 #else
1853 	    xdr_GETATTR2res, NULL_xdrproc_t, sizeof (GETATTR2res),
1854 #endif
1855 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
1856 	    acl2_getattr_getfh},
1857 
1858 	/* ACL2_ACCESS = 4 */
1859 	{acl2_access,
1860 	    xdr_ACCESS2args, xdr_fastACCESS2args, sizeof (ACCESS2args),
1861 #ifdef _LITTLE_ENDIAN
1862 	    xdr_ACCESS2res, xdr_fastACCESS2res, sizeof (ACCESS2res),
1863 #else
1864 	    xdr_ACCESS2res, NULL_xdrproc_t, sizeof (ACCESS2res),
1865 #endif
1866 	    nullfree, RPC_IDEMPOTENT|RPC_MAPRESP,
1867 	    acl2_access_getfh},
1868 
1869 	/* ACL2_GETXATTRDIR = 5 */
1870 	{acl2_getxattrdir,
1871 	    xdr_GETXATTRDIR2args, NULL_xdrproc_t, sizeof (GETXATTRDIR2args),
1872 	    xdr_GETXATTRDIR2res, NULL_xdrproc_t, sizeof (GETXATTRDIR2res),
1873 	    nullfree, RPC_IDEMPOTENT,
1874 	    acl2_getxattrdir_getfh},
1875 };
1876 
1877 static char *aclcallnames_v3[] = {
1878 	"ACL3_NULL",
1879 	"ACL3_GETACL",
1880 	"ACL3_SETACL",
1881 	"ACL3_GETXATTRDIR"
1882 };
1883 
1884 static struct rpcdisp acldisptab_v3[] = {
1885 	/*
1886 	 * ACL VERSION 3
1887 	 */
1888 
1889 	/* ACL3_NULL = 0 */
1890 	{rpc_null,
1891 	    xdr_void, NULL_xdrproc_t, 0,
1892 	    xdr_void, NULL_xdrproc_t, 0,
1893 	    nullfree, RPC_IDEMPOTENT,
1894 	    0},
1895 
1896 	/* ACL3_GETACL = 1 */
1897 	{acl3_getacl,
1898 	    xdr_GETACL3args, NULL_xdrproc_t, sizeof (GETACL3args),
1899 	    xdr_GETACL3res, NULL_xdrproc_t, sizeof (GETACL3res),
1900 	    acl3_getacl_free, RPC_IDEMPOTENT,
1901 	    acl3_getacl_getfh},
1902 
1903 	/* ACL3_SETACL = 2 */
1904 	{acl3_setacl,
1905 	    xdr_SETACL3args, NULL_xdrproc_t, sizeof (SETACL3args),
1906 	    xdr_SETACL3res, NULL_xdrproc_t, sizeof (SETACL3res),
1907 	    nullfree, 0,
1908 	    acl3_setacl_getfh},
1909 
1910 	/* ACL3_GETXATTRDIR = 3 */
1911 	{acl3_getxattrdir,
1912 	    xdr_GETXATTRDIR3args, NULL_xdrproc_t, sizeof (GETXATTRDIR3args),
1913 	    xdr_GETXATTRDIR3res, NULL_xdrproc_t, sizeof (GETXATTRDIR3res),
1914 	    nullfree, RPC_IDEMPOTENT,
1915 	    acl3_getxattrdir_getfh},
1916 };
1917 
1918 static struct rpc_disptable acl_disptable[] = {
1919 	{sizeof (acldisptab_v2) / sizeof (acldisptab_v2[0]),
1920 		aclcallnames_v2,
1921 		&aclproccnt_v2_ptr, acldisptab_v2},
1922 	{sizeof (acldisptab_v3) / sizeof (acldisptab_v3[0]),
1923 		aclcallnames_v3,
1924 		&aclproccnt_v3_ptr, acldisptab_v3},
1925 };
1926 
1927 static void
1928 acl_dispatch(struct svc_req *req, SVCXPRT *xprt)
1929 {
1930 	common_dispatch(req, xprt, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,
1931 	    "ACL", acl_disptable);
1932 }
1933 
1934 int
1935 checkwin(int flavor, int window, struct svc_req *req)
1936 {
1937 	struct authdes_cred *adc;
1938 
1939 	switch (flavor) {
1940 	case AUTH_DES:
1941 		adc = (struct authdes_cred *)req->rq_clntcred;
1942 		if (adc->adc_fullname.window > window)
1943 			return (0);
1944 		break;
1945 
1946 	default:
1947 		break;
1948 	}
1949 	return (1);
1950 }
1951 
1952 
1953 /*
1954  * checkauth() will check the access permission against the export
1955  * information.  Then map root uid/gid to appropriate uid/gid.
1956  *
1957  * This routine is used by NFS V3 and V2 code.
1958  */
1959 static int
1960 checkauth(struct exportinfo *exi, struct svc_req *req, cred_t *cr, int anon_ok,
1961     bool_t publicfh_ok)
1962 {
1963 	int i, nfsflavor, rpcflavor, stat, access;
1964 	struct secinfo *secp;
1965 	caddr_t principal;
1966 	char buf[INET6_ADDRSTRLEN]; /* to hold both IPv4 and IPv6 addr */
1967 	int anon_res = 0;
1968 
1969 	/*
1970 	 *	Check for privileged port number
1971 	 *	N.B.:  this assumes that we know the format of a netbuf.
1972 	 */
1973 	if (nfs_portmon) {
1974 		struct sockaddr *ca;
1975 		ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
1976 
1977 		if (ca == NULL)
1978 			return (0);
1979 
1980 		if ((ca->sa_family == AF_INET &&
1981 		    ntohs(((struct sockaddr_in *)ca)->sin_port) >=
1982 		    IPPORT_RESERVED) ||
1983 		    (ca->sa_family == AF_INET6 &&
1984 		    ntohs(((struct sockaddr_in6 *)ca)->sin6_port) >=
1985 		    IPPORT_RESERVED)) {
1986 			cmn_err(CE_NOTE,
1987 			    "nfs_server: client %s%ssent NFS request from "
1988 			    "unprivileged port",
1989 			    client_name(req), client_addr(req, buf));
1990 			return (0);
1991 		}
1992 	}
1993 
1994 	/*
1995 	 *  return 1 on success or 0 on failure
1996 	 */
1997 	stat = sec_svc_getcred(req, cr, &principal, &nfsflavor);
1998 
1999 	/*
2000 	 * A failed AUTH_UNIX svc_get_cred() implies we couldn't set
2001 	 * the credentials; below we map that to anonymous.
2002 	 */
2003 	if (!stat && nfsflavor != AUTH_UNIX) {
2004 		cmn_err(CE_NOTE,
2005 		    "nfs_server: couldn't get unix cred for %s",
2006 		    client_name(req));
2007 		return (0);
2008 	}
2009 
2010 	/*
2011 	 * Short circuit checkauth() on operations that support the
2012 	 * public filehandle, and if the request for that operation
2013 	 * is using the public filehandle. Note that we must call
2014 	 * sec_svc_getcred() first so that xp_cookie is set to the
2015 	 * right value. Normally xp_cookie is just the RPC flavor
2016 	 * of the the request, but in the case of RPCSEC_GSS it
2017 	 * could be a pseudo flavor.
2018 	 */
2019 	if (publicfh_ok)
2020 		return (1);
2021 
2022 	rpcflavor = req->rq_cred.oa_flavor;
2023 	/*
2024 	 * Check if the auth flavor is valid for this export
2025 	 */
2026 	access = nfsauth_access(exi, req);
2027 	if (access & NFSAUTH_DROP)
2028 		return (-1);	/* drop the request */
2029 
2030 	if (access & NFSAUTH_DENIED) {
2031 		/*
2032 		 * If anon_ok == 1 and we got NFSAUTH_DENIED, it was
2033 		 * probably due to the flavor not matching during the
2034 		 * the mount attempt. So map the flavor to AUTH_NONE
2035 		 * so that the credentials get mapped to the anonymous
2036 		 * user.
2037 		 */
2038 		if (anon_ok == 1)
2039 			rpcflavor = AUTH_NONE;
2040 		else
2041 			return (0);	/* deny access */
2042 
2043 	} else if (access & NFSAUTH_MAPNONE) {
2044 		/*
2045 		 * Access was granted even though the flavor mismatched
2046 		 * because AUTH_NONE was one of the exported flavors.
2047 		 */
2048 		rpcflavor = AUTH_NONE;
2049 
2050 	} else if (access & NFSAUTH_WRONGSEC) {
2051 		/*
2052 		 * NFSAUTH_WRONGSEC is used for NFSv4. If we get here,
2053 		 * it means a client ignored the list of allowed flavors
2054 		 * returned via the MOUNT protocol. So we just disallow it!
2055 		 */
2056 		return (0);
2057 	}
2058 
2059 	switch (rpcflavor) {
2060 	case AUTH_NONE:
2061 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2062 		    exi->exi_export.ex_anon);
2063 		(void) crsetgroups(cr, 0, NULL);
2064 		break;
2065 
2066 	case AUTH_UNIX:
2067 		if (!stat || crgetuid(cr) == 0 && !(access & NFSAUTH_ROOT)) {
2068 			anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2069 			    exi->exi_export.ex_anon);
2070 			(void) crsetgroups(cr, 0, NULL);
2071 		} else if (!stat || crgetuid(cr) == 0 &&
2072 		    access & NFSAUTH_ROOT) {
2073 			/*
2074 			 * It is root, so apply rootid to get real UID
2075 			 * Find the secinfo structure.  We should be able
2076 			 * to find it by the time we reach here.
2077 			 * nfsauth_access() has done the checking.
2078 			 */
2079 			secp = NULL;
2080 			for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2081 				struct secinfo *sptr;
2082 				sptr = &exi->exi_export.ex_secinfo[i];
2083 				if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2084 					secp = sptr;
2085 					break;
2086 				}
2087 			}
2088 			if (secp != NULL) {
2089 				(void) crsetugid(cr, secp->s_rootid,
2090 				    secp->s_rootid);
2091 				(void) crsetgroups(cr, 0, NULL);
2092 			}
2093 		}
2094 		break;
2095 
2096 	case AUTH_DES:
2097 	case RPCSEC_GSS:
2098 		/*
2099 		 *  Find the secinfo structure.  We should be able
2100 		 *  to find it by the time we reach here.
2101 		 *  nfsauth_access() has done the checking.
2102 		 */
2103 		secp = NULL;
2104 		for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2105 			if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2106 			    nfsflavor) {
2107 				secp = &exi->exi_export.ex_secinfo[i];
2108 				break;
2109 			}
2110 		}
2111 
2112 		if (!secp) {
2113 			cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2114 			    "no secinfo data for flavor %d",
2115 			    client_name(req), client_addr(req, buf),
2116 			    nfsflavor);
2117 			return (0);
2118 		}
2119 
2120 		if (!checkwin(rpcflavor, secp->s_window, req)) {
2121 			cmn_err(CE_NOTE,
2122 			    "nfs_server: client %s%sused invalid "
2123 			    "auth window value",
2124 			    client_name(req), client_addr(req, buf));
2125 			return (0);
2126 		}
2127 
2128 		/*
2129 		 * Map root principals listed in the share's root= list to root,
2130 		 * and map any others principals that were mapped to root by RPC
2131 		 * to anon.
2132 		 */
2133 		if (principal && sec_svc_inrootlist(rpcflavor, principal,
2134 		    secp->s_rootcnt, secp->s_rootnames)) {
2135 			if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2136 				return (1);
2137 
2138 
2139 			(void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2140 
2141 			/*
2142 			 * NOTE: If and when kernel-land privilege tracing is
2143 			 * added this may have to be replaced with code that
2144 			 * retrieves root's supplementary groups (e.g., using
2145 			 * kgss_get_group_info().  In the meantime principals
2146 			 * mapped to uid 0 get all privileges, so setting cr's
2147 			 * supplementary groups for them does nothing.
2148 			 */
2149 			(void) crsetgroups(cr, 0, NULL);
2150 
2151 			return (1);
2152 		}
2153 
2154 		/*
2155 		 * Not a root princ, or not in root list, map UID 0/nobody to
2156 		 * the anon ID for the share.  (RPC sets cr's UIDs and GIDs to
2157 		 * UID_NOBODY and GID_NOBODY, respectively.)
2158 		 */
2159 		if (crgetuid(cr) != 0 &&
2160 		    (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2161 			return (1);
2162 
2163 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2164 		    exi->exi_export.ex_anon);
2165 		(void) crsetgroups(cr, 0, NULL);
2166 		break;
2167 	default:
2168 		return (0);
2169 	} /* switch on rpcflavor */
2170 
2171 	/*
2172 	 * Even if anon access is disallowed via ex_anon == -1, we allow
2173 	 * this access if anon_ok is set.  So set creds to the default
2174 	 * "nobody" id.
2175 	 */
2176 	if (anon_res != 0) {
2177 		if (anon_ok == 0) {
2178 			cmn_err(CE_NOTE,
2179 			    "nfs_server: client %s%ssent wrong "
2180 			    "authentication for %s",
2181 			    client_name(req), client_addr(req, buf),
2182 			    exi->exi_export.ex_path ?
2183 			    exi->exi_export.ex_path : "?");
2184 			return (0);
2185 		}
2186 
2187 		if (crsetugid(cr, UID_NOBODY, GID_NOBODY) != 0)
2188 			return (0);
2189 	}
2190 
2191 	return (1);
2192 }
2193 
2194 /*
2195  * returns 0 on failure, -1 on a drop, -2 on wrong security flavor,
2196  * and 1 on success
2197  */
2198 int
2199 checkauth4(struct compound_state *cs, struct svc_req *req)
2200 {
2201 	int i, rpcflavor, access;
2202 	struct secinfo *secp;
2203 	char buf[MAXHOST + 1];
2204 	int anon_res = 0, nfsflavor;
2205 	struct exportinfo *exi;
2206 	cred_t	*cr;
2207 	caddr_t	principal;
2208 
2209 	exi = cs->exi;
2210 	cr = cs->cr;
2211 	principal = cs->principal;
2212 	nfsflavor = cs->nfsflavor;
2213 
2214 	ASSERT(cr != NULL);
2215 
2216 	rpcflavor = req->rq_cred.oa_flavor;
2217 	cs->access &= ~CS_ACCESS_LIMITED;
2218 
2219 	/*
2220 	 * Check the access right per auth flavor on the vnode of
2221 	 * this export for the given request.
2222 	 */
2223 	access = nfsauth4_access(cs->exi, cs->vp, req);
2224 
2225 	if (access & NFSAUTH_WRONGSEC)
2226 		return (-2);	/* no access for this security flavor */
2227 
2228 	if (access & NFSAUTH_DROP)
2229 		return (-1);	/* drop the request */
2230 
2231 	if (access & NFSAUTH_DENIED) {
2232 
2233 		if (exi->exi_export.ex_seccnt > 0)
2234 			return (0);	/* deny access */
2235 
2236 	} else if (access & NFSAUTH_LIMITED) {
2237 
2238 		cs->access |= CS_ACCESS_LIMITED;
2239 
2240 	} else if (access & NFSAUTH_MAPNONE) {
2241 		/*
2242 		 * Access was granted even though the flavor mismatched
2243 		 * because AUTH_NONE was one of the exported flavors.
2244 		 */
2245 		rpcflavor = AUTH_NONE;
2246 	}
2247 
2248 	/*
2249 	 * XXX probably need to redo some of it for nfsv4?
2250 	 * return 1 on success or 0 on failure
2251 	 */
2252 
2253 	switch (rpcflavor) {
2254 	case AUTH_NONE:
2255 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2256 		    exi->exi_export.ex_anon);
2257 		(void) crsetgroups(cr, 0, NULL);
2258 		break;
2259 
2260 	case AUTH_UNIX:
2261 		if (crgetuid(cr) == 0 && !(access & NFSAUTH_ROOT)) {
2262 			anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2263 			    exi->exi_export.ex_anon);
2264 			(void) crsetgroups(cr, 0, NULL);
2265 		} else if (crgetuid(cr) == 0 && access & NFSAUTH_ROOT) {
2266 			/*
2267 			 * It is root, so apply rootid to get real UID
2268 			 * Find the secinfo structure.  We should be able
2269 			 * to find it by the time we reach here.
2270 			 * nfsauth_access() has done the checking.
2271 			 */
2272 			secp = NULL;
2273 			for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2274 				struct secinfo *sptr;
2275 				sptr = &exi->exi_export.ex_secinfo[i];
2276 				if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2277 					secp = &exi->exi_export.ex_secinfo[i];
2278 					break;
2279 				}
2280 			}
2281 			if (secp != NULL) {
2282 				(void) crsetugid(cr, secp->s_rootid,
2283 				    secp->s_rootid);
2284 				(void) crsetgroups(cr, 0, NULL);
2285 			}
2286 		}
2287 		break;
2288 
2289 	default:
2290 		/*
2291 		 *  Find the secinfo structure.  We should be able
2292 		 *  to find it by the time we reach here.
2293 		 *  nfsauth_access() has done the checking.
2294 		 */
2295 		secp = NULL;
2296 		for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2297 			if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2298 			    nfsflavor) {
2299 				secp = &exi->exi_export.ex_secinfo[i];
2300 				break;
2301 			}
2302 		}
2303 
2304 		if (!secp) {
2305 			cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2306 			    "no secinfo data for flavor %d",
2307 			    client_name(req), client_addr(req, buf),
2308 			    nfsflavor);
2309 			return (0);
2310 		}
2311 
2312 		if (!checkwin(rpcflavor, secp->s_window, req)) {
2313 			cmn_err(CE_NOTE,
2314 			    "nfs_server: client %s%sused invalid "
2315 			    "auth window value",
2316 			    client_name(req), client_addr(req, buf));
2317 			return (0);
2318 		}
2319 
2320 		/*
2321 		 * Map root principals listed in the share's root= list to root,
2322 		 * and map any others principals that were mapped to root by RPC
2323 		 * to anon. If not going to anon, set to rootid (root_mapping).
2324 		 */
2325 		if (principal && sec_svc_inrootlist(rpcflavor, principal,
2326 		    secp->s_rootcnt, secp->s_rootnames)) {
2327 			if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2328 				return (1);
2329 
2330 			(void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2331 
2332 			/*
2333 			 * NOTE: If and when kernel-land privilege tracing is
2334 			 * added this may have to be replaced with code that
2335 			 * retrieves root's supplementary groups (e.g., using
2336 			 * kgss_get_group_info().  In the meantime principals
2337 			 * mapped to uid 0 get all privileges, so setting cr's
2338 			 * supplementary groups for them does nothing.
2339 			 */
2340 			(void) crsetgroups(cr, 0, NULL);
2341 
2342 			return (1);
2343 		}
2344 
2345 		/*
2346 		 * Not a root princ, or not in root list, map UID 0/nobody to
2347 		 * the anon ID for the share.  (RPC sets cr's UIDs and GIDs to
2348 		 * UID_NOBODY and GID_NOBODY, respectively.)
2349 		 */
2350 		if (crgetuid(cr) != 0 &&
2351 		    (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2352 			return (1);
2353 
2354 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2355 		    exi->exi_export.ex_anon);
2356 		(void) crsetgroups(cr, 0, NULL);
2357 		break;
2358 	} /* switch on rpcflavor */
2359 
2360 	/*
2361 	 * Even if anon access is disallowed via ex_anon == -1, we allow
2362 	 * this access if anon_ok is set.  So set creds to the default
2363 	 * "nobody" id.
2364 	 */
2365 
2366 	if (anon_res != 0) {
2367 		cmn_err(CE_NOTE,
2368 		    "nfs_server: client %s%ssent wrong "
2369 		    "authentication for %s",
2370 		    client_name(req), client_addr(req, buf),
2371 		    exi->exi_export.ex_path ?
2372 		    exi->exi_export.ex_path : "?");
2373 		return (0);
2374 	}
2375 
2376 	return (1);
2377 }
2378 
2379 
2380 static char *
2381 client_name(struct svc_req *req)
2382 {
2383 	char *hostname = NULL;
2384 
2385 	/*
2386 	 * If it's a Unix cred then use the
2387 	 * hostname from the credential.
2388 	 */
2389 	if (req->rq_cred.oa_flavor == AUTH_UNIX) {
2390 		hostname = ((struct authunix_parms *)
2391 		    req->rq_clntcred)->aup_machname;
2392 	}
2393 	if (hostname == NULL)
2394 		hostname = "";
2395 
2396 	return (hostname);
2397 }
2398 
2399 static char *
2400 client_addr(struct svc_req *req, char *buf)
2401 {
2402 	struct sockaddr *ca;
2403 	uchar_t *b;
2404 	char *frontspace = "";
2405 
2406 	/*
2407 	 * We assume we are called in tandem with client_name and the
2408 	 * format string looks like "...client %s%sblah blah..."
2409 	 *
2410 	 * If it's a Unix cred then client_name returned
2411 	 * a host name, so we need insert a space between host name
2412 	 * and IP address.
2413 	 */
2414 	if (req->rq_cred.oa_flavor == AUTH_UNIX)
2415 		frontspace = " ";
2416 
2417 	/*
2418 	 * Convert the caller's IP address to a dotted string
2419 	 */
2420 	ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2421 
2422 	if (ca->sa_family == AF_INET) {
2423 		b = (uchar_t *)&((struct sockaddr_in *)ca)->sin_addr;
2424 		(void) sprintf(buf, "%s(%d.%d.%d.%d) ", frontspace,
2425 		    b[0] & 0xFF, b[1] & 0xFF, b[2] & 0xFF, b[3] & 0xFF);
2426 	} else if (ca->sa_family == AF_INET6) {
2427 		struct sockaddr_in6 *sin6;
2428 		sin6 = (struct sockaddr_in6 *)ca;
2429 		(void) kinet_ntop6((uchar_t *)&sin6->sin6_addr,
2430 		    buf, INET6_ADDRSTRLEN);
2431 
2432 	} else {
2433 
2434 		/*
2435 		 * No IP address to print. If there was a host name
2436 		 * printed, then we print a space.
2437 		 */
2438 		(void) sprintf(buf, frontspace);
2439 	}
2440 
2441 	return (buf);
2442 }
2443 
2444 /*
2445  * NFS Server initialization routine.  This routine should only be called
2446  * once.  It performs the following tasks:
2447  *	- Call sub-initialization routines (localize access to variables)
2448  *	- Initialize all locks
2449  *	- initialize the version 3 write verifier
2450  */
2451 int
2452 nfs_srvinit(void)
2453 {
2454 	int error;
2455 
2456 	error = nfs_exportinit();
2457 	if (error != 0)
2458 		return (error);
2459 	error = rfs4_srvrinit();
2460 	if (error != 0) {
2461 		nfs_exportfini();
2462 		return (error);
2463 	}
2464 	rfs_srvrinit();
2465 	rfs3_srvrinit();
2466 	nfsauth_init();
2467 
2468 	/* Init the stuff to control start/stop */
2469 	nfs_server_upordown = NFS_SERVER_STOPPED;
2470 	mutex_init(&nfs_server_upordown_lock, NULL, MUTEX_DEFAULT, NULL);
2471 	cv_init(&nfs_server_upordown_cv, NULL, CV_DEFAULT, NULL);
2472 	mutex_init(&rdma_wait_mutex, NULL, MUTEX_DEFAULT, NULL);
2473 	cv_init(&rdma_wait_cv, NULL, CV_DEFAULT, NULL);
2474 
2475 	return (0);
2476 }
2477 
2478 /*
2479  * NFS Server finalization routine. This routine is called to cleanup the
2480  * initialization work previously performed if the NFS server module could
2481  * not be loaded correctly.
2482  */
2483 void
2484 nfs_srvfini(void)
2485 {
2486 	nfsauth_fini();
2487 	rfs3_srvrfini();
2488 	rfs_srvrfini();
2489 	nfs_exportfini();
2490 
2491 	mutex_destroy(&nfs_server_upordown_lock);
2492 	cv_destroy(&nfs_server_upordown_cv);
2493 	mutex_destroy(&rdma_wait_mutex);
2494 	cv_destroy(&rdma_wait_cv);
2495 }
2496 
2497 /*
2498  * Set up an iovec array of up to cnt pointers.
2499  */
2500 
2501 void
2502 mblk_to_iov(mblk_t *m, int cnt, struct iovec *iovp)
2503 {
2504 	while (m != NULL && cnt-- > 0) {
2505 		iovp->iov_base = (caddr_t)m->b_rptr;
2506 		iovp->iov_len = (m->b_wptr - m->b_rptr);
2507 		iovp++;
2508 		m = m->b_cont;
2509 	}
2510 }
2511 
2512 /*
2513  * Common code between NFS Version 2 and NFS Version 3 for the public
2514  * filehandle multicomponent lookups.
2515  */
2516 
2517 /*
2518  * Public filehandle evaluation of a multi-component lookup, following
2519  * symbolic links, if necessary. This may result in a vnode in another
2520  * filesystem, which is OK as long as the other filesystem is exported.
2521  *
2522  * Note that the exi will be set either to NULL or a new reference to the
2523  * exportinfo struct that corresponds to the vnode of the multi-component path.
2524  * It is the callers responsibility to release this reference.
2525  */
2526 int
2527 rfs_publicfh_mclookup(char *p, vnode_t *dvp, cred_t *cr, vnode_t **vpp,
2528     struct exportinfo **exi, struct sec_ol *sec)
2529 {
2530 	int pathflag;
2531 	vnode_t *mc_dvp = NULL;
2532 	vnode_t *realvp;
2533 	int error;
2534 
2535 	*exi = NULL;
2536 
2537 	/*
2538 	 * check if the given path is a url or native path. Since p is
2539 	 * modified by MCLpath(), it may be empty after returning from
2540 	 * there, and should be checked.
2541 	 */
2542 	if ((pathflag = MCLpath(&p)) == -1)
2543 		return (EIO);
2544 
2545 	/*
2546 	 * If pathflag is SECURITY_QUERY, turn the SEC_QUERY bit
2547 	 * on in sec->sec_flags. This bit will later serve as an
2548 	 * indication in makefh_ol() or makefh3_ol() to overload the
2549 	 * filehandle to contain the sec modes used by the server for
2550 	 * the path.
2551 	 */
2552 	if (pathflag == SECURITY_QUERY) {
2553 		if ((sec->sec_index = (uint_t)(*p)) > 0) {
2554 			sec->sec_flags |= SEC_QUERY;
2555 			p++;
2556 			if ((pathflag = MCLpath(&p)) == -1)
2557 				return (EIO);
2558 		} else {
2559 			cmn_err(CE_NOTE,
2560 			    "nfs_server: invalid security index %d, "
2561 			    "violating WebNFS SNEGO protocol.", sec->sec_index);
2562 			return (EIO);
2563 		}
2564 	}
2565 
2566 	if (p[0] == '\0') {
2567 		error = ENOENT;
2568 		goto publicfh_done;
2569 	}
2570 
2571 	error = rfs_pathname(p, &mc_dvp, vpp, dvp, cr, pathflag);
2572 
2573 	/*
2574 	 * If name resolves to "/" we get EINVAL since we asked for
2575 	 * the vnode of the directory that the file is in. Try again
2576 	 * with NULL directory vnode.
2577 	 */
2578 	if (error == EINVAL) {
2579 		error = rfs_pathname(p, NULL, vpp, dvp, cr, pathflag);
2580 		if (!error) {
2581 			ASSERT(*vpp != NULL);
2582 			if ((*vpp)->v_type == VDIR) {
2583 				VN_HOLD(*vpp);
2584 				mc_dvp = *vpp;
2585 			} else {
2586 				/*
2587 				 * This should not happen, the filesystem is
2588 				 * in an inconsistent state. Fail the lookup
2589 				 * at this point.
2590 				 */
2591 				VN_RELE(*vpp);
2592 				error = EINVAL;
2593 			}
2594 		}
2595 	}
2596 
2597 	if (error)
2598 		goto publicfh_done;
2599 
2600 	if (*vpp == NULL) {
2601 		error = ENOENT;
2602 		goto publicfh_done;
2603 	}
2604 
2605 	ASSERT(mc_dvp != NULL);
2606 	ASSERT(*vpp != NULL);
2607 
2608 	if ((*vpp)->v_type == VDIR) {
2609 		do {
2610 			/*
2611 			 * *vpp may be an AutoFS node, so we perform
2612 			 * a VOP_ACCESS() to trigger the mount of the intended
2613 			 * filesystem, so we can perform the lookup in the
2614 			 * intended filesystem.
2615 			 */
2616 			(void) VOP_ACCESS(*vpp, 0, 0, cr, NULL);
2617 
2618 			/*
2619 			 * If vnode is covered, get the
2620 			 * the topmost vnode.
2621 			 */
2622 			if (vn_mountedvfs(*vpp) != NULL) {
2623 				error = traverse(vpp);
2624 				if (error) {
2625 					VN_RELE(*vpp);
2626 					goto publicfh_done;
2627 				}
2628 			}
2629 
2630 			if (VOP_REALVP(*vpp, &realvp, NULL) == 0 &&
2631 			    realvp != *vpp) {
2632 				/*
2633 				 * If realvp is different from *vpp
2634 				 * then release our reference on *vpp, so that
2635 				 * the export access check be performed on the
2636 				 * real filesystem instead.
2637 				 */
2638 				VN_HOLD(realvp);
2639 				VN_RELE(*vpp);
2640 				*vpp = realvp;
2641 			} else {
2642 				break;
2643 			}
2644 		/* LINTED */
2645 		} while (TRUE);
2646 
2647 		/*
2648 		 * Let nfs_vptexi() figure what the real parent is.
2649 		 */
2650 		VN_RELE(mc_dvp);
2651 		mc_dvp = NULL;
2652 
2653 	} else {
2654 		/*
2655 		 * If vnode is covered, get the
2656 		 * the topmost vnode.
2657 		 */
2658 		if (vn_mountedvfs(mc_dvp) != NULL) {
2659 			error = traverse(&mc_dvp);
2660 			if (error) {
2661 				VN_RELE(*vpp);
2662 				goto publicfh_done;
2663 			}
2664 		}
2665 
2666 		if (VOP_REALVP(mc_dvp, &realvp, NULL) == 0 &&
2667 		    realvp != mc_dvp) {
2668 			/*
2669 			 * *vpp is a file, obtain realvp of the parent
2670 			 * directory vnode.
2671 			 */
2672 			VN_HOLD(realvp);
2673 			VN_RELE(mc_dvp);
2674 			mc_dvp = realvp;
2675 		}
2676 	}
2677 
2678 	/*
2679 	 * The pathname may take us from the public filesystem to another.
2680 	 * If that's the case then just set the exportinfo to the new export
2681 	 * and build filehandle for it. Thanks to per-access checking there's
2682 	 * no security issues with doing this. If the client is not allowed
2683 	 * access to this new export then it will get an access error when it
2684 	 * tries to use the filehandle
2685 	 */
2686 	if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2687 		VN_RELE(*vpp);
2688 		goto publicfh_done;
2689 	}
2690 
2691 	/*
2692 	 * Not allowed access to pseudo exports.
2693 	 */
2694 	if (PSEUDO(*exi)) {
2695 		error = ENOENT;
2696 		VN_RELE(*vpp);
2697 		goto publicfh_done;
2698 	}
2699 
2700 	/*
2701 	 * Do a lookup for the index file. We know the index option doesn't
2702 	 * allow paths through handling in the share command, so mc_dvp will
2703 	 * be the parent for the index file vnode, if its present. Use
2704 	 * temporary pointers to preserve and reuse the vnode pointers of the
2705 	 * original directory in case there's no index file. Note that the
2706 	 * index file is a native path, and should not be interpreted by
2707 	 * the URL parser in rfs_pathname()
2708 	 */
2709 	if (((*exi)->exi_export.ex_flags & EX_INDEX) &&
2710 	    ((*vpp)->v_type == VDIR) && (pathflag == URLPATH)) {
2711 		vnode_t *tvp, *tmc_dvp;	/* temporary vnode pointers */
2712 
2713 		tmc_dvp = mc_dvp;
2714 		mc_dvp = tvp = *vpp;
2715 
2716 		error = rfs_pathname((*exi)->exi_export.ex_index, NULL, vpp,
2717 		    mc_dvp, cr, NATIVEPATH);
2718 
2719 		if (error == ENOENT) {
2720 			*vpp = tvp;
2721 			mc_dvp = tmc_dvp;
2722 			error = 0;
2723 		} else {	/* ok or error other than ENOENT */
2724 			if (tmc_dvp)
2725 				VN_RELE(tmc_dvp);
2726 			if (error)
2727 				goto publicfh_done;
2728 
2729 			/*
2730 			 * Found a valid vp for index "filename". Sanity check
2731 			 * for odd case where a directory is provided as index
2732 			 * option argument and leads us to another filesystem
2733 			 */
2734 
2735 			/* Release the reference on the old exi value */
2736 			ASSERT(*exi != NULL);
2737 			exi_rele(*exi);
2738 
2739 			if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2740 				VN_RELE(*vpp);
2741 				goto publicfh_done;
2742 			}
2743 		}
2744 	}
2745 
2746 publicfh_done:
2747 	if (mc_dvp)
2748 		VN_RELE(mc_dvp);
2749 
2750 	return (error);
2751 }
2752 
2753 /*
2754  * Evaluate a multi-component path
2755  */
2756 int
2757 rfs_pathname(
2758 	char *path,			/* pathname to evaluate */
2759 	vnode_t **dirvpp,		/* ret for ptr to parent dir vnode */
2760 	vnode_t **compvpp,		/* ret for ptr to component vnode */
2761 	vnode_t *startdvp,		/* starting vnode */
2762 	cred_t *cr,			/* user's credential */
2763 	int pathflag)			/* flag to identify path, e.g. URL */
2764 {
2765 	char namebuf[TYPICALMAXPATHLEN];
2766 	struct pathname pn;
2767 	int error;
2768 
2769 	/*
2770 	 * If pathname starts with '/', then set startdvp to root.
2771 	 */
2772 	if (*path == '/') {
2773 		while (*path == '/')
2774 			path++;
2775 
2776 		startdvp = rootdir;
2777 	}
2778 
2779 	error = pn_get_buf(path, UIO_SYSSPACE, &pn, namebuf, sizeof (namebuf));
2780 	if (error == 0) {
2781 		/*
2782 		 * Call the URL parser for URL paths to modify the original
2783 		 * string to handle any '%' encoded characters that exist.
2784 		 * Done here to avoid an extra bcopy in the lookup.
2785 		 * We need to be careful about pathlen's. We know that
2786 		 * rfs_pathname() is called with a non-empty path. However,
2787 		 * it could be emptied due to the path simply being all /'s,
2788 		 * which is valid to proceed with the lookup, or due to the
2789 		 * URL parser finding an encoded null character at the
2790 		 * beginning of path which should not proceed with the lookup.
2791 		 */
2792 		if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2793 			URLparse(pn.pn_path);
2794 			if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0)
2795 				return (ENOENT);
2796 		}
2797 		VN_HOLD(startdvp);
2798 		error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2799 		    rootdir, startdvp, cr);
2800 	}
2801 	if (error == ENAMETOOLONG) {
2802 		/*
2803 		 * This thread used a pathname > TYPICALMAXPATHLEN bytes long.
2804 		 */
2805 		if (error = pn_get(path, UIO_SYSSPACE, &pn))
2806 			return (error);
2807 		if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2808 			URLparse(pn.pn_path);
2809 			if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0) {
2810 				pn_free(&pn);
2811 				return (ENOENT);
2812 			}
2813 		}
2814 		VN_HOLD(startdvp);
2815 		error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2816 		    rootdir, startdvp, cr);
2817 		pn_free(&pn);
2818 	}
2819 
2820 	return (error);
2821 }
2822 
2823 /*
2824  * Adapt the multicomponent lookup path depending on the pathtype
2825  */
2826 static int
2827 MCLpath(char **path)
2828 {
2829 	unsigned char c = (unsigned char)**path;
2830 
2831 	/*
2832 	 * If the MCL path is between 0x20 and 0x7E (graphic printable
2833 	 * character of the US-ASCII coded character set), its a URL path,
2834 	 * per RFC 1738.
2835 	 */
2836 	if (c >= 0x20 && c <= 0x7E)
2837 		return (URLPATH);
2838 
2839 	/*
2840 	 * If the first octet of the MCL path is not an ASCII character
2841 	 * then it must be interpreted as a tag value that describes the
2842 	 * format of the remaining octets of the MCL path.
2843 	 *
2844 	 * If the first octet of the MCL path is 0x81 it is a query
2845 	 * for the security info.
2846 	 */
2847 	switch (c) {
2848 	case 0x80:	/* native path, i.e. MCL via mount protocol */
2849 		(*path)++;
2850 		return (NATIVEPATH);
2851 	case 0x81:	/* security query */
2852 		(*path)++;
2853 		return (SECURITY_QUERY);
2854 	default:
2855 		return (-1);
2856 	}
2857 }
2858 
2859 #define	fromhex(c)  ((c >= '0' && c <= '9') ? (c - '0') : \
2860 			((c >= 'A' && c <= 'F') ? (c - 'A' + 10) :\
2861 			((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : 0)))
2862 
2863 /*
2864  * The implementation of URLparse guarantees that the final string will
2865  * fit in the original one. Replaces '%' occurrences followed by 2 characters
2866  * with its corresponding hexadecimal character.
2867  */
2868 static void
2869 URLparse(char *str)
2870 {
2871 	char *p, *q;
2872 
2873 	p = q = str;
2874 	while (*p) {
2875 		*q = *p;
2876 		if (*p++ == '%') {
2877 			if (*p) {
2878 				*q = fromhex(*p) * 16;
2879 				p++;
2880 				if (*p) {
2881 					*q += fromhex(*p);
2882 					p++;
2883 				}
2884 			}
2885 		}
2886 		q++;
2887 	}
2888 	*q = '\0';
2889 }
2890 
2891 
2892 /*
2893  * Get the export information for the lookup vnode, and verify its
2894  * useable.
2895  */
2896 int
2897 nfs_check_vpexi(vnode_t *mc_dvp, vnode_t *vp, cred_t *cr,
2898     struct exportinfo **exi)
2899 {
2900 	int walk;
2901 	int error = 0;
2902 
2903 	*exi = nfs_vptoexi(mc_dvp, vp, cr, &walk, NULL, FALSE);
2904 	if (*exi == NULL)
2905 		error = EACCES;
2906 	else {
2907 		/*
2908 		 * If nosub is set for this export then
2909 		 * a lookup relative to the public fh
2910 		 * must not terminate below the
2911 		 * exported directory.
2912 		 */
2913 		if ((*exi)->exi_export.ex_flags & EX_NOSUB && walk > 0)
2914 			error = EACCES;
2915 	}
2916 
2917 	return (error);
2918 }
2919 
2920 /*
2921  * Do the main work of handling HA-NFSv4 Resource Group failover on
2922  * Sun Cluster.
2923  * We need to detect whether any RG admin paths have been added or removed,
2924  * and adjust resources accordingly.
2925  * Currently we're using a very inefficient algorithm, ~ 2 * O(n**2). In
2926  * order to scale, the list and array of paths need to be held in more
2927  * suitable data structures.
2928  */
2929 static void
2930 hanfsv4_failover(void)
2931 {
2932 	int i, start_grace, numadded_paths = 0;
2933 	char **added_paths = NULL;
2934 	rfs4_dss_path_t *dss_path;
2935 
2936 	/*
2937 	 * Note: currently, rfs4_dss_pathlist cannot be NULL, since
2938 	 * it will always include an entry for NFS4_DSS_VAR_DIR. If we
2939 	 * make the latter dynamically specified too, the following will
2940 	 * need to be adjusted.
2941 	 */
2942 
2943 	/*
2944 	 * First, look for removed paths: RGs that have been failed-over
2945 	 * away from this node.
2946 	 * Walk the "currently-serving" rfs4_dss_pathlist and, for each
2947 	 * path, check if it is on the "passed-in" rfs4_dss_newpaths array
2948 	 * from nfsd. If not, that RG path has been removed.
2949 	 *
2950 	 * Note that nfsd has sorted rfs4_dss_newpaths for us, and removed
2951 	 * any duplicates.
2952 	 */
2953 	dss_path = rfs4_dss_pathlist;
2954 	do {
2955 		int found = 0;
2956 		char *path = dss_path->path;
2957 
2958 		/* used only for non-HA so may not be removed */
2959 		if (strcmp(path, NFS4_DSS_VAR_DIR) == 0) {
2960 			dss_path = dss_path->next;
2961 			continue;
2962 		}
2963 
2964 		for (i = 0; i < rfs4_dss_numnewpaths; i++) {
2965 			int cmpret;
2966 			char *newpath = rfs4_dss_newpaths[i];
2967 
2968 			/*
2969 			 * Since nfsd has sorted rfs4_dss_newpaths for us,
2970 			 * once the return from strcmp is negative we know
2971 			 * we've passed the point where "path" should be,
2972 			 * and can stop searching: "path" has been removed.
2973 			 */
2974 			cmpret = strcmp(path, newpath);
2975 			if (cmpret < 0)
2976 				break;
2977 			if (cmpret == 0) {
2978 				found = 1;
2979 				break;
2980 			}
2981 		}
2982 
2983 		if (found == 0) {
2984 			unsigned index = dss_path->index;
2985 			rfs4_servinst_t *sip = dss_path->sip;
2986 			rfs4_dss_path_t *path_next = dss_path->next;
2987 
2988 			/*
2989 			 * This path has been removed.
2990 			 * We must clear out the servinst reference to
2991 			 * it, since it's now owned by another
2992 			 * node: we should not attempt to touch it.
2993 			 */
2994 			ASSERT(dss_path == sip->dss_paths[index]);
2995 			sip->dss_paths[index] = NULL;
2996 
2997 			/* remove from "currently-serving" list, and destroy */
2998 			remque(dss_path);
2999 			/* allow for NUL */
3000 			kmem_free(dss_path->path, strlen(dss_path->path) + 1);
3001 			kmem_free(dss_path, sizeof (rfs4_dss_path_t));
3002 
3003 			dss_path = path_next;
3004 		} else {
3005 			/* path was found; not removed */
3006 			dss_path = dss_path->next;
3007 		}
3008 	} while (dss_path != rfs4_dss_pathlist);
3009 
3010 	/*
3011 	 * Now, look for added paths: RGs that have been failed-over
3012 	 * to this node.
3013 	 * Walk the "passed-in" rfs4_dss_newpaths array from nfsd and,
3014 	 * for each path, check if it is on the "currently-serving"
3015 	 * rfs4_dss_pathlist. If not, that RG path has been added.
3016 	 *
3017 	 * Note: we don't do duplicate detection here; nfsd does that for us.
3018 	 *
3019 	 * Note: numadded_paths <= rfs4_dss_numnewpaths, which gives us
3020 	 * an upper bound for the size needed for added_paths[numadded_paths].
3021 	 */
3022 
3023 	/* probably more space than we need, but guaranteed to be enough */
3024 	if (rfs4_dss_numnewpaths > 0) {
3025 		size_t sz = rfs4_dss_numnewpaths * sizeof (char *);
3026 		added_paths = kmem_zalloc(sz, KM_SLEEP);
3027 	}
3028 
3029 	/* walk the "passed-in" rfs4_dss_newpaths array from nfsd */
3030 	for (i = 0; i < rfs4_dss_numnewpaths; i++) {
3031 		int found = 0;
3032 		char *newpath = rfs4_dss_newpaths[i];
3033 
3034 		dss_path = rfs4_dss_pathlist;
3035 		do {
3036 			char *path = dss_path->path;
3037 
3038 			/* used only for non-HA */
3039 			if (strcmp(path, NFS4_DSS_VAR_DIR) == 0) {
3040 				dss_path = dss_path->next;
3041 				continue;
3042 			}
3043 
3044 			if (strncmp(path, newpath, strlen(path)) == 0) {
3045 				found = 1;
3046 				break;
3047 			}
3048 
3049 			dss_path = dss_path->next;
3050 		} while (dss_path != rfs4_dss_pathlist);
3051 
3052 		if (found == 0) {
3053 			added_paths[numadded_paths] = newpath;
3054 			numadded_paths++;
3055 		}
3056 	}
3057 
3058 	/* did we find any added paths? */
3059 	if (numadded_paths > 0) {
3060 		/* create a new server instance, and start its grace period */
3061 		start_grace = 1;
3062 		rfs4_servinst_create(start_grace, numadded_paths, added_paths);
3063 
3064 		/* read in the stable storage state from these paths */
3065 		rfs4_dss_readstate(numadded_paths, added_paths);
3066 
3067 		/*
3068 		 * Multiple failovers during a grace period will cause
3069 		 * clients of the same resource group to be partitioned
3070 		 * into different server instances, with different
3071 		 * grace periods.  Since clients of the same resource
3072 		 * group must be subject to the same grace period,
3073 		 * we need to reset all currently active grace periods.
3074 		 */
3075 		rfs4_grace_reset_all();
3076 	}
3077 
3078 	if (rfs4_dss_numnewpaths > 0)
3079 		kmem_free(added_paths, rfs4_dss_numnewpaths * sizeof (char *));
3080 }
3081