2986 nfs: exi refcounter leak at rfs3_lookup
[unleashed.git] / usr / src / uts / common / fs / nfs / nfs_server.c
bloba0abad070078354a488940533509d0e9c53a154f
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
24 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
29 * All rights reserved.
30 * Use is subject to license terms.
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/systm.h>
36 #include <sys/cred.h>
37 #include <sys/proc.h>
38 #include <sys/user.h>
39 #include <sys/buf.h>
40 #include <sys/vfs.h>
41 #include <sys/vnode.h>
42 #include <sys/pathname.h>
43 #include <sys/uio.h>
44 #include <sys/file.h>
45 #include <sys/stat.h>
46 #include <sys/errno.h>
47 #include <sys/socket.h>
48 #include <sys/sysmacros.h>
49 #include <sys/siginfo.h>
50 #include <sys/tiuser.h>
51 #include <sys/statvfs.h>
52 #include <sys/stream.h>
53 #include <sys/strsubr.h>
54 #include <sys/stropts.h>
55 #include <sys/timod.h>
56 #include <sys/t_kuser.h>
57 #include <sys/kmem.h>
58 #include <sys/kstat.h>
59 #include <sys/dirent.h>
60 #include <sys/cmn_err.h>
61 #include <sys/debug.h>
62 #include <sys/unistd.h>
63 #include <sys/vtrace.h>
64 #include <sys/mode.h>
65 #include <sys/acl.h>
66 #include <sys/sdt.h>
68 #include <rpc/types.h>
69 #include <rpc/auth.h>
70 #include <rpc/auth_unix.h>
71 #include <rpc/auth_des.h>
72 #include <rpc/svc.h>
73 #include <rpc/xdr.h>
74 #include <rpc/rpc_rdma.h>
76 #include <nfs/nfs.h>
77 #include <nfs/export.h>
78 #include <nfs/nfssys.h>
79 #include <nfs/nfs_clnt.h>
80 #include <nfs/nfs_acl.h>
81 #include <nfs/nfs_log.h>
82 #include <nfs/nfs_cmd.h>
83 #include <nfs/lm.h>
84 #include <nfs/nfs_dispatch.h>
85 #include <nfs/nfs4_drc.h>
87 #include <sys/modctl.h>
88 #include <sys/cladm.h>
89 #include <sys/clconf.h>
91 #include <sys/tsol/label.h>
93 #define MAXHOST 32
94 const char *kinet_ntop6(uchar_t *, char *, size_t);
97 * Module linkage information.
100 static struct modlmisc modlmisc = {
101 &mod_miscops, "NFS server module"
104 static struct modlinkage modlinkage = {
105 MODREV_1, (void *)&modlmisc, NULL
108 kmem_cache_t *nfs_xuio_cache;
109 int nfs_loaned_buffers = 0;
112 _init(void)
114 int status;
116 if ((status = nfs_srvinit()) != 0) {
117 cmn_err(CE_WARN, "_init: nfs_srvinit failed");
118 return (status);
121 status = mod_install((struct modlinkage *)&modlinkage);
122 if (status != 0) {
124 * Could not load module, cleanup previous
125 * initialization work.
127 nfs_srvfini();
131 * Initialise some placeholders for nfssys() calls. These have
132 * to be declared by the nfs module, since that handles nfssys()
133 * calls - also used by NFS clients - but are provided by this
134 * nfssrv module. These also then serve as confirmation to the
135 * relevant code in nfs that nfssrv has been loaded, as they're
136 * initially NULL.
138 nfs_srv_quiesce_func = nfs_srv_quiesce_all;
139 nfs_srv_dss_func = rfs4_dss_setpaths;
141 /* setup DSS paths here; must be done before initial server startup */
142 rfs4_dss_paths = rfs4_dss_oldpaths = NULL;
144 /* initialize the copy reduction caches */
146 nfs_xuio_cache = kmem_cache_create("nfs_xuio_cache",
147 sizeof (nfs_xuio_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
149 return (status);
153 _fini()
155 return (EBUSY);
159 _info(struct modinfo *modinfop)
161 return (mod_info(&modlinkage, modinfop));
165 * PUBLICFH_CHECK() checks if the dispatch routine supports
166 * RPC_PUBLICFH_OK, if the filesystem is exported public, and if the
167 * incoming request is using the public filehandle. The check duplicates
168 * the exportmatch() call done in checkexport(), and we should consider
169 * modifying those routines to avoid the duplication. For now, we optimize
170 * by calling exportmatch() only after checking that the dispatch routine
171 * supports RPC_PUBLICFH_OK, and if the filesystem is explicitly exported
172 * public (i.e., not the placeholder).
174 #define PUBLICFH_CHECK(disp, exi, fsid, xfid) \
175 ((disp->dis_flags & RPC_PUBLICFH_OK) && \
176 ((exi->exi_export.ex_flags & EX_PUBLIC) || \
177 (exi == exi_public && exportmatch(exi_root, \
178 fsid, xfid))))
180 static void nfs_srv_shutdown_all(int);
181 static void rfs4_server_start(int);
182 static void nullfree(void);
183 static void rfs_dispatch(struct svc_req *, SVCXPRT *);
184 static void acl_dispatch(struct svc_req *, SVCXPRT *);
185 static void common_dispatch(struct svc_req *, SVCXPRT *,
186 rpcvers_t, rpcvers_t, char *,
187 struct rpc_disptable *);
188 static void hanfsv4_failover(void);
189 static int checkauth(struct exportinfo *, struct svc_req *, cred_t *, int,
190 bool_t);
191 static char *client_name(struct svc_req *req);
192 static char *client_addr(struct svc_req *req, char *buf);
193 extern int sec_svc_getcred(struct svc_req *, cred_t *cr, char **, int *);
194 extern bool_t sec_svc_inrootlist(int, caddr_t, int, caddr_t *);
196 #define NFSLOG_COPY_NETBUF(exi, xprt, nb) { \
197 (nb)->maxlen = (xprt)->xp_rtaddr.maxlen; \
198 (nb)->len = (xprt)->xp_rtaddr.len; \
199 (nb)->buf = kmem_alloc((nb)->len, KM_SLEEP); \
200 bcopy((xprt)->xp_rtaddr.buf, (nb)->buf, (nb)->len); \
204 * Public Filehandle common nfs routines
206 static int MCLpath(char **);
207 static void URLparse(char *);
210 * NFS callout table.
211 * This table is used by svc_getreq() to dispatch a request with
212 * a given prog/vers pair to an appropriate service provider
213 * dispatch routine.
215 * NOTE: ordering is relied upon below when resetting the version min/max
216 * for NFS_PROGRAM. Careful, if this is ever changed.
218 static SVC_CALLOUT __nfs_sc_clts[] = {
219 { NFS_PROGRAM, NFS_VERSMIN, NFS_VERSMAX, rfs_dispatch },
220 { NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX, acl_dispatch }
223 static SVC_CALLOUT_TABLE nfs_sct_clts = {
224 sizeof (__nfs_sc_clts) / sizeof (__nfs_sc_clts[0]), FALSE,
225 __nfs_sc_clts
228 static SVC_CALLOUT __nfs_sc_cots[] = {
229 { NFS_PROGRAM, NFS_VERSMIN, NFS_VERSMAX, rfs_dispatch },
230 { NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX, acl_dispatch }
233 static SVC_CALLOUT_TABLE nfs_sct_cots = {
234 sizeof (__nfs_sc_cots) / sizeof (__nfs_sc_cots[0]), FALSE, __nfs_sc_cots
237 static SVC_CALLOUT __nfs_sc_rdma[] = {
238 { NFS_PROGRAM, NFS_VERSMIN, NFS_VERSMAX, rfs_dispatch },
239 { NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX, acl_dispatch }
242 static SVC_CALLOUT_TABLE nfs_sct_rdma = {
243 sizeof (__nfs_sc_rdma) / sizeof (__nfs_sc_rdma[0]), FALSE, __nfs_sc_rdma
245 rpcvers_t nfs_versmin = NFS_VERSMIN_DEFAULT;
246 rpcvers_t nfs_versmax = NFS_VERSMAX_DEFAULT;
249 * Used to track the state of the server so that initialization
250 * can be done properly.
252 typedef enum {
253 NFS_SERVER_STOPPED, /* server state destroyed */
254 NFS_SERVER_STOPPING, /* server state being destroyed */
255 NFS_SERVER_RUNNING,
256 NFS_SERVER_QUIESCED, /* server state preserved */
257 NFS_SERVER_OFFLINE /* server pool offline */
258 } nfs_server_running_t;
260 static nfs_server_running_t nfs_server_upordown;
261 static kmutex_t nfs_server_upordown_lock;
262 static kcondvar_t nfs_server_upordown_cv;
265 * DSS: distributed stable storage
266 * lists of all DSS paths: current, and before last warmstart
268 nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
270 int rfs4_dispatch(struct rpcdisp *, struct svc_req *, SVCXPRT *, char *);
271 bool_t rfs4_minorvers_mismatch(struct svc_req *, SVCXPRT *, void *);
274 * RDMA wait variables.
276 static kcondvar_t rdma_wait_cv;
277 static kmutex_t rdma_wait_mutex;
280 * Will be called at the point the server pool is being unregistered
281 * from the pool list. From that point onwards, the pool is waiting
282 * to be drained and as such the server state is stale and pertains
283 * to the old instantiation of the NFS server pool.
285 void
286 nfs_srv_offline(void)
288 mutex_enter(&nfs_server_upordown_lock);
289 if (nfs_server_upordown == NFS_SERVER_RUNNING) {
290 nfs_server_upordown = NFS_SERVER_OFFLINE;
292 mutex_exit(&nfs_server_upordown_lock);
296 * Will be called at the point the server pool is being destroyed so
297 * all transports have been closed and no service threads are in
298 * existence.
300 * If we quiesce the server, we're shutting it down without destroying the
301 * server state. This allows it to warm start subsequently.
303 void
304 nfs_srv_stop_all(void)
306 int quiesce = 0;
307 nfs_srv_shutdown_all(quiesce);
311 * This alternative shutdown routine can be requested via nfssys()
313 void
314 nfs_srv_quiesce_all(void)
316 int quiesce = 1;
317 nfs_srv_shutdown_all(quiesce);
320 static void
321 nfs_srv_shutdown_all(int quiesce) {
322 mutex_enter(&nfs_server_upordown_lock);
323 if (quiesce) {
324 if (nfs_server_upordown == NFS_SERVER_RUNNING ||
325 nfs_server_upordown == NFS_SERVER_OFFLINE) {
326 nfs_server_upordown = NFS_SERVER_QUIESCED;
327 cv_signal(&nfs_server_upordown_cv);
329 /* reset DSS state, for subsequent warm restart */
330 rfs4_dss_numnewpaths = 0;
331 rfs4_dss_newpaths = NULL;
333 cmn_err(CE_NOTE, "nfs_server: server is now quiesced; "
334 "NFSv4 state has been preserved");
336 } else {
337 if (nfs_server_upordown == NFS_SERVER_OFFLINE) {
338 nfs_server_upordown = NFS_SERVER_STOPPING;
339 mutex_exit(&nfs_server_upordown_lock);
340 rfs4_state_fini();
341 rfs4_fini_drc(nfs4_drc);
342 mutex_enter(&nfs_server_upordown_lock);
343 nfs_server_upordown = NFS_SERVER_STOPPED;
344 cv_signal(&nfs_server_upordown_cv);
347 mutex_exit(&nfs_server_upordown_lock);
350 static int
351 nfs_srv_set_sc_versions(struct file *fp, SVC_CALLOUT_TABLE **sctpp,
352 rpcvers_t versmin, rpcvers_t versmax)
354 struct strioctl strioc;
355 struct T_info_ack tinfo;
356 int error, retval;
359 * Find out what type of transport this is.
361 strioc.ic_cmd = TI_GETINFO;
362 strioc.ic_timout = -1;
363 strioc.ic_len = sizeof (tinfo);
364 strioc.ic_dp = (char *)&tinfo;
365 tinfo.PRIM_type = T_INFO_REQ;
367 error = strioctl(fp->f_vnode, I_STR, (intptr_t)&strioc, 0, K_TO_K,
368 CRED(), &retval);
369 if (error || retval)
370 return (error);
373 * Based on our query of the transport type...
375 * Reset the min/max versions based on the caller's request
376 * NOTE: This assumes that NFS_PROGRAM is first in the array!!
377 * And the second entry is the NFS_ACL_PROGRAM.
379 switch (tinfo.SERV_type) {
380 case T_CLTS:
381 if (versmax == NFS_V4)
382 return (EINVAL);
383 __nfs_sc_clts[0].sc_versmin = versmin;
384 __nfs_sc_clts[0].sc_versmax = versmax;
385 __nfs_sc_clts[1].sc_versmin = versmin;
386 __nfs_sc_clts[1].sc_versmax = versmax;
387 *sctpp = &nfs_sct_clts;
388 break;
389 case T_COTS:
390 case T_COTS_ORD:
391 __nfs_sc_cots[0].sc_versmin = versmin;
392 __nfs_sc_cots[0].sc_versmax = versmax;
393 /* For the NFS_ACL program, check the max version */
394 if (versmax > NFS_ACL_VERSMAX)
395 versmax = NFS_ACL_VERSMAX;
396 __nfs_sc_cots[1].sc_versmin = versmin;
397 __nfs_sc_cots[1].sc_versmax = versmax;
398 *sctpp = &nfs_sct_cots;
399 break;
400 default:
401 error = EINVAL;
404 return (error);
408 * NFS Server system call.
409 * Does all of the work of running a NFS server.
410 * uap->fd is the fd of an open transport provider
413 nfs_svc(struct nfs_svc_args *arg, model_t model)
415 file_t *fp;
416 SVCMASTERXPRT *xprt;
417 int error;
418 int readsize;
419 char buf[KNC_STRSIZE];
420 size_t len;
421 STRUCT_HANDLE(nfs_svc_args, uap);
422 struct netbuf addrmask;
423 SVC_CALLOUT_TABLE *sctp = NULL;
425 #ifdef lint
426 model = model; /* STRUCT macros don't always refer to it */
427 #endif
429 STRUCT_SET_HANDLE(uap, model, arg);
431 /* Check privileges in nfssys() */
433 if ((fp = getf(STRUCT_FGET(uap, fd))) == NULL)
434 return (EBADF);
437 * Set read buffer size to rsize
438 * and add room for RPC headers.
440 readsize = nfs3tsize() + (RPC_MAXDATASIZE - NFS_MAXDATA);
441 if (readsize < RPC_MAXDATASIZE)
442 readsize = RPC_MAXDATASIZE;
444 error = copyinstr((const char *)STRUCT_FGETP(uap, netid), buf,
445 KNC_STRSIZE, &len);
446 if (error) {
447 releasef(STRUCT_FGET(uap, fd));
448 return (error);
451 addrmask.len = STRUCT_FGET(uap, addrmask.len);
452 addrmask.maxlen = STRUCT_FGET(uap, addrmask.maxlen);
453 addrmask.buf = kmem_alloc(addrmask.maxlen, KM_SLEEP);
454 error = copyin(STRUCT_FGETP(uap, addrmask.buf), addrmask.buf,
455 addrmask.len);
456 if (error) {
457 releasef(STRUCT_FGET(uap, fd));
458 kmem_free(addrmask.buf, addrmask.maxlen);
459 return (error);
462 nfs_versmin = STRUCT_FGET(uap, versmin);
463 nfs_versmax = STRUCT_FGET(uap, versmax);
465 /* Double check the vers min/max ranges */
466 if ((nfs_versmin > nfs_versmax) ||
467 (nfs_versmin < NFS_VERSMIN) ||
468 (nfs_versmax > NFS_VERSMAX)) {
469 nfs_versmin = NFS_VERSMIN_DEFAULT;
470 nfs_versmax = NFS_VERSMAX_DEFAULT;
473 if (error =
474 nfs_srv_set_sc_versions(fp, &sctp, nfs_versmin, nfs_versmax)) {
475 releasef(STRUCT_FGET(uap, fd));
476 kmem_free(addrmask.buf, addrmask.maxlen);
477 return (error);
480 /* Initialize nfsv4 server */
481 if (nfs_versmax == (rpcvers_t)NFS_V4)
482 rfs4_server_start(STRUCT_FGET(uap, delegation));
484 /* Create a transport handle. */
485 error = svc_tli_kcreate(fp, readsize, buf, &addrmask, &xprt,
486 sctp, NULL, NFS_SVCPOOL_ID, TRUE);
488 if (error)
489 kmem_free(addrmask.buf, addrmask.maxlen);
491 releasef(STRUCT_FGET(uap, fd));
493 /* HA-NFSv4: save the cluster nodeid */
494 if (cluster_bootflags & CLUSTER_BOOTED)
495 lm_global_nlmid = clconf_get_nodeid();
497 return (error);
500 static void
501 rfs4_server_start(int nfs4_srv_delegation)
504 * Determine if the server has previously been "started" and
505 * if not, do the per instance initialization
507 mutex_enter(&nfs_server_upordown_lock);
509 if (nfs_server_upordown != NFS_SERVER_RUNNING) {
510 /* Do we need to stop and wait on the previous server? */
511 while (nfs_server_upordown == NFS_SERVER_STOPPING ||
512 nfs_server_upordown == NFS_SERVER_OFFLINE)
513 cv_wait(&nfs_server_upordown_cv,
514 &nfs_server_upordown_lock);
516 if (nfs_server_upordown != NFS_SERVER_RUNNING) {
517 (void) svc_pool_control(NFS_SVCPOOL_ID,
518 SVCPSET_UNREGISTER_PROC, (void *)&nfs_srv_offline);
519 (void) svc_pool_control(NFS_SVCPOOL_ID,
520 SVCPSET_SHUTDOWN_PROC, (void *)&nfs_srv_stop_all);
522 /* is this an nfsd warm start? */
523 if (nfs_server_upordown == NFS_SERVER_QUIESCED) {
524 cmn_err(CE_NOTE, "nfs_server: "
525 "server was previously quiesced; "
526 "existing NFSv4 state will be re-used");
529 * HA-NFSv4: this is also the signal
530 * that a Resource Group failover has
531 * occurred.
533 if (cluster_bootflags & CLUSTER_BOOTED)
534 hanfsv4_failover();
535 } else {
536 /* cold start */
537 rfs4_state_init();
538 nfs4_drc = rfs4_init_drc(nfs4_drc_max,
539 nfs4_drc_hash);
543 * Check to see if delegation is to be
544 * enabled at the server
546 if (nfs4_srv_delegation != FALSE)
547 rfs4_set_deleg_policy(SRV_NORMAL_DELEGATE);
549 nfs_server_upordown = NFS_SERVER_RUNNING;
551 cv_signal(&nfs_server_upordown_cv);
553 mutex_exit(&nfs_server_upordown_lock);
557 * If RDMA device available,
558 * start RDMA listener.
561 rdma_start(struct rdma_svc_args *rsa)
563 int error;
564 rdma_xprt_group_t started_rdma_xprts;
565 rdma_stat stat;
566 int svc_state = 0;
568 /* Double check the vers min/max ranges */
569 if ((rsa->nfs_versmin > rsa->nfs_versmax) ||
570 (rsa->nfs_versmin < NFS_VERSMIN) ||
571 (rsa->nfs_versmax > NFS_VERSMAX)) {
572 rsa->nfs_versmin = NFS_VERSMIN_DEFAULT;
573 rsa->nfs_versmax = NFS_VERSMAX_DEFAULT;
575 nfs_versmin = rsa->nfs_versmin;
576 nfs_versmax = rsa->nfs_versmax;
578 /* Set the versions in the callout table */
579 __nfs_sc_rdma[0].sc_versmin = rsa->nfs_versmin;
580 __nfs_sc_rdma[0].sc_versmax = rsa->nfs_versmax;
581 /* For the NFS_ACL program, check the max version */
582 __nfs_sc_rdma[1].sc_versmin = rsa->nfs_versmin;
583 if (rsa->nfs_versmax > NFS_ACL_VERSMAX)
584 __nfs_sc_rdma[1].sc_versmax = NFS_ACL_VERSMAX;
585 else
586 __nfs_sc_rdma[1].sc_versmax = rsa->nfs_versmax;
588 /* Initialize nfsv4 server */
589 if (rsa->nfs_versmax == (rpcvers_t)NFS_V4)
590 rfs4_server_start(rsa->delegation);
592 started_rdma_xprts.rtg_count = 0;
593 started_rdma_xprts.rtg_listhead = NULL;
594 started_rdma_xprts.rtg_poolid = rsa->poolid;
596 restart:
597 error = svc_rdma_kcreate(rsa->netid, &nfs_sct_rdma, rsa->poolid,
598 &started_rdma_xprts);
600 svc_state = !error;
602 while (!error) {
605 * wait till either interrupted by a signal on
606 * nfs service stop/restart or signalled by a
607 * rdma plugin attach/detatch.
610 stat = rdma_kwait();
613 * stop services if running -- either on a HCA detach event
614 * or if the nfs service is stopped/restarted.
617 if ((stat == RDMA_HCA_DETACH || stat == RDMA_INTR) &&
618 svc_state) {
619 rdma_stop(&started_rdma_xprts);
620 svc_state = 0;
624 * nfs service stop/restart, break out of the
625 * wait loop and return;
627 if (stat == RDMA_INTR)
628 return (0);
631 * restart stopped services on a HCA attach event
632 * (if not already running)
635 if ((stat == RDMA_HCA_ATTACH) && (svc_state == 0))
636 goto restart;
639 * loop until a nfs service stop/restart
643 return (error);
646 /* ARGSUSED */
647 void
648 rpc_null(caddr_t *argp, caddr_t *resp)
652 /* ARGSUSED */
653 void
654 rpc_null_v3(caddr_t *argp, caddr_t *resp, struct exportinfo *exi,
655 struct svc_req *req, cred_t *cr)
657 DTRACE_NFSV3_3(op__null__start, struct svc_req *, req,
658 cred_t *, cr, vnode_t *, NULL);
659 DTRACE_NFSV3_3(op__null__done, struct svc_req *, req,
660 cred_t *, cr, vnode_t *, NULL);
663 /* ARGSUSED */
664 static void
665 rfs_error(caddr_t *argp, caddr_t *resp)
667 /* return (EOPNOTSUPP); */
670 static void
671 nullfree(void)
675 static char *rfscallnames_v2[] = {
676 "RFS2_NULL",
677 "RFS2_GETATTR",
678 "RFS2_SETATTR",
679 "RFS2_ROOT",
680 "RFS2_LOOKUP",
681 "RFS2_READLINK",
682 "RFS2_READ",
683 "RFS2_WRITECACHE",
684 "RFS2_WRITE",
685 "RFS2_CREATE",
686 "RFS2_REMOVE",
687 "RFS2_RENAME",
688 "RFS2_LINK",
689 "RFS2_SYMLINK",
690 "RFS2_MKDIR",
691 "RFS2_RMDIR",
692 "RFS2_READDIR",
693 "RFS2_STATFS"
696 static struct rpcdisp rfsdisptab_v2[] = {
698 * NFS VERSION 2
701 /* RFS_NULL = 0 */
702 {rpc_null,
703 xdr_void, NULL_xdrproc_t, 0,
704 xdr_void, NULL_xdrproc_t, 0,
705 nullfree, RPC_IDEMPOTENT,
708 /* RFS_GETATTR = 1 */
709 {rfs_getattr,
710 xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
711 xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
712 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
713 rfs_getattr_getfh},
715 /* RFS_SETATTR = 2 */
716 {rfs_setattr,
717 xdr_saargs, NULL_xdrproc_t, sizeof (struct nfssaargs),
718 xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
719 nullfree, RPC_MAPRESP,
720 rfs_setattr_getfh},
722 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
723 {rfs_error,
724 xdr_void, NULL_xdrproc_t, 0,
725 xdr_void, NULL_xdrproc_t, 0,
726 nullfree, RPC_IDEMPOTENT,
729 /* RFS_LOOKUP = 4 */
730 {rfs_lookup,
731 xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
732 xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
733 nullfree, RPC_IDEMPOTENT|RPC_MAPRESP|RPC_PUBLICFH_OK,
734 rfs_lookup_getfh},
736 /* RFS_READLINK = 5 */
737 {rfs_readlink,
738 xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
739 xdr_rdlnres, NULL_xdrproc_t, sizeof (struct nfsrdlnres),
740 rfs_rlfree, RPC_IDEMPOTENT,
741 rfs_readlink_getfh},
743 /* RFS_READ = 6 */
744 {rfs_read,
745 xdr_readargs, NULL_xdrproc_t, sizeof (struct nfsreadargs),
746 xdr_rdresult, NULL_xdrproc_t, sizeof (struct nfsrdresult),
747 rfs_rdfree, RPC_IDEMPOTENT,
748 rfs_read_getfh},
750 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
751 {rfs_error,
752 xdr_void, NULL_xdrproc_t, 0,
753 xdr_void, NULL_xdrproc_t, 0,
754 nullfree, RPC_IDEMPOTENT,
757 /* RFS_WRITE = 8 */
758 {rfs_write,
759 xdr_writeargs, NULL_xdrproc_t, sizeof (struct nfswriteargs),
760 xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
761 nullfree, RPC_MAPRESP,
762 rfs_write_getfh},
764 /* RFS_CREATE = 9 */
765 {rfs_create,
766 xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
767 xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
768 nullfree, RPC_MAPRESP,
769 rfs_create_getfh},
771 /* RFS_REMOVE = 10 */
772 {rfs_remove,
773 xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
774 #ifdef _LITTLE_ENDIAN
775 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
776 #else
777 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
778 #endif
779 nullfree, RPC_MAPRESP,
780 rfs_remove_getfh},
782 /* RFS_RENAME = 11 */
783 {rfs_rename,
784 xdr_rnmargs, NULL_xdrproc_t, sizeof (struct nfsrnmargs),
785 #ifdef _LITTLE_ENDIAN
786 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
787 #else
788 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
789 #endif
790 nullfree, RPC_MAPRESP,
791 rfs_rename_getfh},
793 /* RFS_LINK = 12 */
794 {rfs_link,
795 xdr_linkargs, NULL_xdrproc_t, sizeof (struct nfslinkargs),
796 #ifdef _LITTLE_ENDIAN
797 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
798 #else
799 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
800 #endif
801 nullfree, RPC_MAPRESP,
802 rfs_link_getfh},
804 /* RFS_SYMLINK = 13 */
805 {rfs_symlink,
806 xdr_slargs, NULL_xdrproc_t, sizeof (struct nfsslargs),
807 #ifdef _LITTLE_ENDIAN
808 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
809 #else
810 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
811 #endif
812 nullfree, RPC_MAPRESP,
813 rfs_symlink_getfh},
815 /* RFS_MKDIR = 14 */
816 {rfs_mkdir,
817 xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
818 xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
819 nullfree, RPC_MAPRESP,
820 rfs_mkdir_getfh},
822 /* RFS_RMDIR = 15 */
823 {rfs_rmdir,
824 xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
825 #ifdef _LITTLE_ENDIAN
826 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
827 #else
828 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
829 #endif
830 nullfree, RPC_MAPRESP,
831 rfs_rmdir_getfh},
833 /* RFS_READDIR = 16 */
834 {rfs_readdir,
835 xdr_rddirargs, NULL_xdrproc_t, sizeof (struct nfsrddirargs),
836 xdr_putrddirres, NULL_xdrproc_t, sizeof (struct nfsrddirres),
837 rfs_rddirfree, RPC_IDEMPOTENT,
838 rfs_readdir_getfh},
840 /* RFS_STATFS = 17 */
841 {rfs_statfs,
842 xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
843 xdr_statfs, xdr_faststatfs, sizeof (struct nfsstatfs),
844 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
845 rfs_statfs_getfh},
848 static char *rfscallnames_v3[] = {
849 "RFS3_NULL",
850 "RFS3_GETATTR",
851 "RFS3_SETATTR",
852 "RFS3_LOOKUP",
853 "RFS3_ACCESS",
854 "RFS3_READLINK",
855 "RFS3_READ",
856 "RFS3_WRITE",
857 "RFS3_CREATE",
858 "RFS3_MKDIR",
859 "RFS3_SYMLINK",
860 "RFS3_MKNOD",
861 "RFS3_REMOVE",
862 "RFS3_RMDIR",
863 "RFS3_RENAME",
864 "RFS3_LINK",
865 "RFS3_READDIR",
866 "RFS3_READDIRPLUS",
867 "RFS3_FSSTAT",
868 "RFS3_FSINFO",
869 "RFS3_PATHCONF",
870 "RFS3_COMMIT"
873 static struct rpcdisp rfsdisptab_v3[] = {
875 * NFS VERSION 3
878 /* RFS_NULL = 0 */
879 {rpc_null_v3,
880 xdr_void, NULL_xdrproc_t, 0,
881 xdr_void, NULL_xdrproc_t, 0,
882 nullfree, RPC_IDEMPOTENT,
885 /* RFS3_GETATTR = 1 */
886 {rfs3_getattr,
887 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (GETATTR3args),
888 xdr_GETATTR3res, NULL_xdrproc_t, sizeof (GETATTR3res),
889 nullfree, (RPC_IDEMPOTENT | RPC_ALLOWANON),
890 rfs3_getattr_getfh},
892 /* RFS3_SETATTR = 2 */
893 {rfs3_setattr,
894 xdr_SETATTR3args, NULL_xdrproc_t, sizeof (SETATTR3args),
895 xdr_SETATTR3res, NULL_xdrproc_t, sizeof (SETATTR3res),
896 nullfree, 0,
897 rfs3_setattr_getfh},
899 /* RFS3_LOOKUP = 3 */
900 {rfs3_lookup,
901 xdr_diropargs3, NULL_xdrproc_t, sizeof (LOOKUP3args),
902 xdr_LOOKUP3res, NULL_xdrproc_t, sizeof (LOOKUP3res),
903 nullfree, (RPC_IDEMPOTENT | RPC_PUBLICFH_OK),
904 rfs3_lookup_getfh},
906 /* RFS3_ACCESS = 4 */
907 {rfs3_access,
908 xdr_ACCESS3args, NULL_xdrproc_t, sizeof (ACCESS3args),
909 xdr_ACCESS3res, NULL_xdrproc_t, sizeof (ACCESS3res),
910 nullfree, RPC_IDEMPOTENT,
911 rfs3_access_getfh},
913 /* RFS3_READLINK = 5 */
914 {rfs3_readlink,
915 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (READLINK3args),
916 xdr_READLINK3res, NULL_xdrproc_t, sizeof (READLINK3res),
917 rfs3_readlink_free, RPC_IDEMPOTENT,
918 rfs3_readlink_getfh},
920 /* RFS3_READ = 6 */
921 {rfs3_read,
922 xdr_READ3args, NULL_xdrproc_t, sizeof (READ3args),
923 xdr_READ3res, NULL_xdrproc_t, sizeof (READ3res),
924 rfs3_read_free, RPC_IDEMPOTENT,
925 rfs3_read_getfh},
927 /* RFS3_WRITE = 7 */
928 {rfs3_write,
929 xdr_WRITE3args, NULL_xdrproc_t, sizeof (WRITE3args),
930 xdr_WRITE3res, NULL_xdrproc_t, sizeof (WRITE3res),
931 nullfree, 0,
932 rfs3_write_getfh},
934 /* RFS3_CREATE = 8 */
935 {rfs3_create,
936 xdr_CREATE3args, NULL_xdrproc_t, sizeof (CREATE3args),
937 xdr_CREATE3res, NULL_xdrproc_t, sizeof (CREATE3res),
938 nullfree, 0,
939 rfs3_create_getfh},
941 /* RFS3_MKDIR = 9 */
942 {rfs3_mkdir,
943 xdr_MKDIR3args, NULL_xdrproc_t, sizeof (MKDIR3args),
944 xdr_MKDIR3res, NULL_xdrproc_t, sizeof (MKDIR3res),
945 nullfree, 0,
946 rfs3_mkdir_getfh},
948 /* RFS3_SYMLINK = 10 */
949 {rfs3_symlink,
950 xdr_SYMLINK3args, NULL_xdrproc_t, sizeof (SYMLINK3args),
951 xdr_SYMLINK3res, NULL_xdrproc_t, sizeof (SYMLINK3res),
952 nullfree, 0,
953 rfs3_symlink_getfh},
955 /* RFS3_MKNOD = 11 */
956 {rfs3_mknod,
957 xdr_MKNOD3args, NULL_xdrproc_t, sizeof (MKNOD3args),
958 xdr_MKNOD3res, NULL_xdrproc_t, sizeof (MKNOD3res),
959 nullfree, 0,
960 rfs3_mknod_getfh},
962 /* RFS3_REMOVE = 12 */
963 {rfs3_remove,
964 xdr_diropargs3, NULL_xdrproc_t, sizeof (REMOVE3args),
965 xdr_REMOVE3res, NULL_xdrproc_t, sizeof (REMOVE3res),
966 nullfree, 0,
967 rfs3_remove_getfh},
969 /* RFS3_RMDIR = 13 */
970 {rfs3_rmdir,
971 xdr_diropargs3, NULL_xdrproc_t, sizeof (RMDIR3args),
972 xdr_RMDIR3res, NULL_xdrproc_t, sizeof (RMDIR3res),
973 nullfree, 0,
974 rfs3_rmdir_getfh},
976 /* RFS3_RENAME = 14 */
977 {rfs3_rename,
978 xdr_RENAME3args, NULL_xdrproc_t, sizeof (RENAME3args),
979 xdr_RENAME3res, NULL_xdrproc_t, sizeof (RENAME3res),
980 nullfree, 0,
981 rfs3_rename_getfh},
983 /* RFS3_LINK = 15 */
984 {rfs3_link,
985 xdr_LINK3args, NULL_xdrproc_t, sizeof (LINK3args),
986 xdr_LINK3res, NULL_xdrproc_t, sizeof (LINK3res),
987 nullfree, 0,
988 rfs3_link_getfh},
990 /* RFS3_READDIR = 16 */
991 {rfs3_readdir,
992 xdr_READDIR3args, NULL_xdrproc_t, sizeof (READDIR3args),
993 xdr_READDIR3res, NULL_xdrproc_t, sizeof (READDIR3res),
994 rfs3_readdir_free, RPC_IDEMPOTENT,
995 rfs3_readdir_getfh},
997 /* RFS3_READDIRPLUS = 17 */
998 {rfs3_readdirplus,
999 xdr_READDIRPLUS3args, NULL_xdrproc_t, sizeof (READDIRPLUS3args),
1000 xdr_READDIRPLUS3res, NULL_xdrproc_t, sizeof (READDIRPLUS3res),
1001 rfs3_readdirplus_free, RPC_AVOIDWORK,
1002 rfs3_readdirplus_getfh},
1004 /* RFS3_FSSTAT = 18 */
1005 {rfs3_fsstat,
1006 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSSTAT3args),
1007 xdr_FSSTAT3res, NULL_xdrproc_t, sizeof (FSSTAT3res),
1008 nullfree, RPC_IDEMPOTENT,
1009 rfs3_fsstat_getfh},
1011 /* RFS3_FSINFO = 19 */
1012 {rfs3_fsinfo,
1013 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSINFO3args),
1014 xdr_FSINFO3res, NULL_xdrproc_t, sizeof (FSINFO3res),
1015 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON,
1016 rfs3_fsinfo_getfh},
1018 /* RFS3_PATHCONF = 20 */
1019 {rfs3_pathconf,
1020 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (PATHCONF3args),
1021 xdr_PATHCONF3res, NULL_xdrproc_t, sizeof (PATHCONF3res),
1022 nullfree, RPC_IDEMPOTENT,
1023 rfs3_pathconf_getfh},
1025 /* RFS3_COMMIT = 21 */
1026 {rfs3_commit,
1027 xdr_COMMIT3args, NULL_xdrproc_t, sizeof (COMMIT3args),
1028 xdr_COMMIT3res, NULL_xdrproc_t, sizeof (COMMIT3res),
1029 nullfree, RPC_IDEMPOTENT,
1030 rfs3_commit_getfh},
1033 static char *rfscallnames_v4[] = {
1034 "RFS4_NULL",
1035 "RFS4_COMPOUND",
1036 "RFS4_NULL",
1037 "RFS4_NULL",
1038 "RFS4_NULL",
1039 "RFS4_NULL",
1040 "RFS4_NULL",
1041 "RFS4_NULL",
1042 "RFS4_CREATE"
1045 static struct rpcdisp rfsdisptab_v4[] = {
1047 * NFS VERSION 4
1050 /* RFS_NULL = 0 */
1051 {rpc_null,
1052 xdr_void, NULL_xdrproc_t, 0,
1053 xdr_void, NULL_xdrproc_t, 0,
1054 nullfree, RPC_IDEMPOTENT, 0},
1056 /* RFS4_compound = 1 */
1057 {rfs4_compound,
1058 xdr_COMPOUND4args_srv, NULL_xdrproc_t, sizeof (COMPOUND4args),
1059 xdr_COMPOUND4res_srv, NULL_xdrproc_t, sizeof (COMPOUND4res),
1060 rfs4_compound_free, 0, 0},
1063 union rfs_args {
1065 * NFS VERSION 2
1068 /* RFS_NULL = 0 */
1070 /* RFS_GETATTR = 1 */
1071 fhandle_t nfs2_getattr_args;
1073 /* RFS_SETATTR = 2 */
1074 struct nfssaargs nfs2_setattr_args;
1076 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1078 /* RFS_LOOKUP = 4 */
1079 struct nfsdiropargs nfs2_lookup_args;
1081 /* RFS_READLINK = 5 */
1082 fhandle_t nfs2_readlink_args;
1084 /* RFS_READ = 6 */
1085 struct nfsreadargs nfs2_read_args;
1087 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1089 /* RFS_WRITE = 8 */
1090 struct nfswriteargs nfs2_write_args;
1092 /* RFS_CREATE = 9 */
1093 struct nfscreatargs nfs2_create_args;
1095 /* RFS_REMOVE = 10 */
1096 struct nfsdiropargs nfs2_remove_args;
1098 /* RFS_RENAME = 11 */
1099 struct nfsrnmargs nfs2_rename_args;
1101 /* RFS_LINK = 12 */
1102 struct nfslinkargs nfs2_link_args;
1104 /* RFS_SYMLINK = 13 */
1105 struct nfsslargs nfs2_symlink_args;
1107 /* RFS_MKDIR = 14 */
1108 struct nfscreatargs nfs2_mkdir_args;
1110 /* RFS_RMDIR = 15 */
1111 struct nfsdiropargs nfs2_rmdir_args;
1113 /* RFS_READDIR = 16 */
1114 struct nfsrddirargs nfs2_readdir_args;
1116 /* RFS_STATFS = 17 */
1117 fhandle_t nfs2_statfs_args;
1120 * NFS VERSION 3
1123 /* RFS_NULL = 0 */
1125 /* RFS3_GETATTR = 1 */
1126 GETATTR3args nfs3_getattr_args;
1128 /* RFS3_SETATTR = 2 */
1129 SETATTR3args nfs3_setattr_args;
1131 /* RFS3_LOOKUP = 3 */
1132 LOOKUP3args nfs3_lookup_args;
1134 /* RFS3_ACCESS = 4 */
1135 ACCESS3args nfs3_access_args;
1137 /* RFS3_READLINK = 5 */
1138 READLINK3args nfs3_readlink_args;
1140 /* RFS3_READ = 6 */
1141 READ3args nfs3_read_args;
1143 /* RFS3_WRITE = 7 */
1144 WRITE3args nfs3_write_args;
1146 /* RFS3_CREATE = 8 */
1147 CREATE3args nfs3_create_args;
1149 /* RFS3_MKDIR = 9 */
1150 MKDIR3args nfs3_mkdir_args;
1152 /* RFS3_SYMLINK = 10 */
1153 SYMLINK3args nfs3_symlink_args;
1155 /* RFS3_MKNOD = 11 */
1156 MKNOD3args nfs3_mknod_args;
1158 /* RFS3_REMOVE = 12 */
1159 REMOVE3args nfs3_remove_args;
1161 /* RFS3_RMDIR = 13 */
1162 RMDIR3args nfs3_rmdir_args;
1164 /* RFS3_RENAME = 14 */
1165 RENAME3args nfs3_rename_args;
1167 /* RFS3_LINK = 15 */
1168 LINK3args nfs3_link_args;
1170 /* RFS3_READDIR = 16 */
1171 READDIR3args nfs3_readdir_args;
1173 /* RFS3_READDIRPLUS = 17 */
1174 READDIRPLUS3args nfs3_readdirplus_args;
1176 /* RFS3_FSSTAT = 18 */
1177 FSSTAT3args nfs3_fsstat_args;
1179 /* RFS3_FSINFO = 19 */
1180 FSINFO3args nfs3_fsinfo_args;
1182 /* RFS3_PATHCONF = 20 */
1183 PATHCONF3args nfs3_pathconf_args;
1185 /* RFS3_COMMIT = 21 */
1186 COMMIT3args nfs3_commit_args;
1189 * NFS VERSION 4
1192 /* RFS_NULL = 0 */
1194 /* COMPUND = 1 */
1195 COMPOUND4args nfs4_compound_args;
1198 union rfs_res {
1200 * NFS VERSION 2
1203 /* RFS_NULL = 0 */
1205 /* RFS_GETATTR = 1 */
1206 struct nfsattrstat nfs2_getattr_res;
1208 /* RFS_SETATTR = 2 */
1209 struct nfsattrstat nfs2_setattr_res;
1211 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1213 /* RFS_LOOKUP = 4 */
1214 struct nfsdiropres nfs2_lookup_res;
1216 /* RFS_READLINK = 5 */
1217 struct nfsrdlnres nfs2_readlink_res;
1219 /* RFS_READ = 6 */
1220 struct nfsrdresult nfs2_read_res;
1222 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1224 /* RFS_WRITE = 8 */
1225 struct nfsattrstat nfs2_write_res;
1227 /* RFS_CREATE = 9 */
1228 struct nfsdiropres nfs2_create_res;
1230 /* RFS_REMOVE = 10 */
1231 enum nfsstat nfs2_remove_res;
1233 /* RFS_RENAME = 11 */
1234 enum nfsstat nfs2_rename_res;
1236 /* RFS_LINK = 12 */
1237 enum nfsstat nfs2_link_res;
1239 /* RFS_SYMLINK = 13 */
1240 enum nfsstat nfs2_symlink_res;
1242 /* RFS_MKDIR = 14 */
1243 struct nfsdiropres nfs2_mkdir_res;
1245 /* RFS_RMDIR = 15 */
1246 enum nfsstat nfs2_rmdir_res;
1248 /* RFS_READDIR = 16 */
1249 struct nfsrddirres nfs2_readdir_res;
1251 /* RFS_STATFS = 17 */
1252 struct nfsstatfs nfs2_statfs_res;
1255 * NFS VERSION 3
1258 /* RFS_NULL = 0 */
1260 /* RFS3_GETATTR = 1 */
1261 GETATTR3res nfs3_getattr_res;
1263 /* RFS3_SETATTR = 2 */
1264 SETATTR3res nfs3_setattr_res;
1266 /* RFS3_LOOKUP = 3 */
1267 LOOKUP3res nfs3_lookup_res;
1269 /* RFS3_ACCESS = 4 */
1270 ACCESS3res nfs3_access_res;
1272 /* RFS3_READLINK = 5 */
1273 READLINK3res nfs3_readlink_res;
1275 /* RFS3_READ = 6 */
1276 READ3res nfs3_read_res;
1278 /* RFS3_WRITE = 7 */
1279 WRITE3res nfs3_write_res;
1281 /* RFS3_CREATE = 8 */
1282 CREATE3res nfs3_create_res;
1284 /* RFS3_MKDIR = 9 */
1285 MKDIR3res nfs3_mkdir_res;
1287 /* RFS3_SYMLINK = 10 */
1288 SYMLINK3res nfs3_symlink_res;
1290 /* RFS3_MKNOD = 11 */
1291 MKNOD3res nfs3_mknod_res;
1293 /* RFS3_REMOVE = 12 */
1294 REMOVE3res nfs3_remove_res;
1296 /* RFS3_RMDIR = 13 */
1297 RMDIR3res nfs3_rmdir_res;
1299 /* RFS3_RENAME = 14 */
1300 RENAME3res nfs3_rename_res;
1302 /* RFS3_LINK = 15 */
1303 LINK3res nfs3_link_res;
1305 /* RFS3_READDIR = 16 */
1306 READDIR3res nfs3_readdir_res;
1308 /* RFS3_READDIRPLUS = 17 */
1309 READDIRPLUS3res nfs3_readdirplus_res;
1311 /* RFS3_FSSTAT = 18 */
1312 FSSTAT3res nfs3_fsstat_res;
1314 /* RFS3_FSINFO = 19 */
1315 FSINFO3res nfs3_fsinfo_res;
1317 /* RFS3_PATHCONF = 20 */
1318 PATHCONF3res nfs3_pathconf_res;
1320 /* RFS3_COMMIT = 21 */
1321 COMMIT3res nfs3_commit_res;
1324 * NFS VERSION 4
1327 /* RFS_NULL = 0 */
1329 /* RFS4_COMPOUND = 1 */
1330 COMPOUND4res nfs4_compound_res;
1334 static struct rpc_disptable rfs_disptable[] = {
1335 {sizeof (rfsdisptab_v2) / sizeof (rfsdisptab_v2[0]),
1336 rfscallnames_v2,
1337 &rfsproccnt_v2_ptr, rfsdisptab_v2},
1338 {sizeof (rfsdisptab_v3) / sizeof (rfsdisptab_v3[0]),
1339 rfscallnames_v3,
1340 &rfsproccnt_v3_ptr, rfsdisptab_v3},
1341 {sizeof (rfsdisptab_v4) / sizeof (rfsdisptab_v4[0]),
1342 rfscallnames_v4,
1343 &rfsproccnt_v4_ptr, rfsdisptab_v4},
1347 * If nfs_portmon is set, then clients are required to use privileged
1348 * ports (ports < IPPORT_RESERVED) in order to get NFS services.
1350 * N.B.: this attempt to carry forward the already ill-conceived notion
1351 * of privileged ports for TCP/UDP is really quite ineffectual. Not only
1352 * is it transport-dependent, it's laughably easy to spoof. If you're
1353 * really interested in security, you must start with secure RPC instead.
1355 static int nfs_portmon = 0;
1357 #ifdef DEBUG
1358 static int cred_hits = 0;
1359 static int cred_misses = 0;
1360 #endif
1363 #ifdef DEBUG
1365 * Debug code to allow disabling of rfs_dispatch() use of
1366 * fastxdrargs() and fastxdrres() calls for testing purposes.
1368 static int rfs_no_fast_xdrargs = 0;
1369 static int rfs_no_fast_xdrres = 0;
1370 #endif
1372 union acl_args {
1374 * ACL VERSION 2
1377 /* ACL2_NULL = 0 */
1379 /* ACL2_GETACL = 1 */
1380 GETACL2args acl2_getacl_args;
1382 /* ACL2_SETACL = 2 */
1383 SETACL2args acl2_setacl_args;
1385 /* ACL2_GETATTR = 3 */
1386 GETATTR2args acl2_getattr_args;
1388 /* ACL2_ACCESS = 4 */
1389 ACCESS2args acl2_access_args;
1391 /* ACL2_GETXATTRDIR = 5 */
1392 GETXATTRDIR2args acl2_getxattrdir_args;
1395 * ACL VERSION 3
1398 /* ACL3_NULL = 0 */
1400 /* ACL3_GETACL = 1 */
1401 GETACL3args acl3_getacl_args;
1403 /* ACL3_SETACL = 2 */
1404 SETACL3args acl3_setacl;
1406 /* ACL3_GETXATTRDIR = 3 */
1407 GETXATTRDIR3args acl3_getxattrdir_args;
1411 union acl_res {
1413 * ACL VERSION 2
1416 /* ACL2_NULL = 0 */
1418 /* ACL2_GETACL = 1 */
1419 GETACL2res acl2_getacl_res;
1421 /* ACL2_SETACL = 2 */
1422 SETACL2res acl2_setacl_res;
1424 /* ACL2_GETATTR = 3 */
1425 GETATTR2res acl2_getattr_res;
1427 /* ACL2_ACCESS = 4 */
1428 ACCESS2res acl2_access_res;
1430 /* ACL2_GETXATTRDIR = 5 */
1431 GETXATTRDIR2args acl2_getxattrdir_res;
1434 * ACL VERSION 3
1437 /* ACL3_NULL = 0 */
1439 /* ACL3_GETACL = 1 */
1440 GETACL3res acl3_getacl_res;
1442 /* ACL3_SETACL = 2 */
1443 SETACL3res acl3_setacl_res;
1445 /* ACL3_GETXATTRDIR = 3 */
1446 GETXATTRDIR3res acl3_getxattrdir_res;
1450 static bool_t
1451 auth_tooweak(struct svc_req *req, char *res)
1454 if (req->rq_vers == NFS_VERSION && req->rq_proc == RFS_LOOKUP) {
1455 struct nfsdiropres *dr = (struct nfsdiropres *)res;
1456 if ((enum wnfsstat)dr->dr_status == WNFSERR_CLNT_FLAVOR)
1457 return (TRUE);
1458 } else if (req->rq_vers == NFS_V3 && req->rq_proc == NFSPROC3_LOOKUP) {
1459 LOOKUP3res *resp = (LOOKUP3res *)res;
1460 if ((enum wnfsstat)resp->status == WNFSERR_CLNT_FLAVOR)
1461 return (TRUE);
1463 return (FALSE);
1467 static void
1468 common_dispatch(struct svc_req *req, SVCXPRT *xprt, rpcvers_t min_vers,
1469 rpcvers_t max_vers, char *pgmname,
1470 struct rpc_disptable *disptable)
1472 int which;
1473 rpcvers_t vers;
1474 char *args;
1475 union {
1476 union rfs_args ra;
1477 union acl_args aa;
1478 } args_buf;
1479 char *res;
1480 union {
1481 union rfs_res rr;
1482 union acl_res ar;
1483 } res_buf;
1484 struct rpcdisp *disp = NULL;
1485 int dis_flags = 0;
1486 cred_t *cr;
1487 int error = 0;
1488 int anon_ok;
1489 struct exportinfo *exi = NULL;
1490 unsigned int nfslog_rec_id;
1491 int dupstat;
1492 struct dupreq *dr;
1493 int authres;
1494 bool_t publicfh_ok = FALSE;
1495 enum_t auth_flavor;
1496 bool_t dupcached = FALSE;
1497 struct netbuf nb;
1498 bool_t logging_enabled = FALSE;
1499 struct exportinfo *nfslog_exi = NULL;
1500 char **procnames;
1501 char cbuf[INET6_ADDRSTRLEN]; /* to hold both IPv4 and IPv6 addr */
1503 vers = req->rq_vers;
1505 if (vers < min_vers || vers > max_vers) {
1506 svcerr_progvers(req->rq_xprt, min_vers, max_vers);
1507 error++;
1508 cmn_err(CE_NOTE, "%s: bad version number %u", pgmname, vers);
1509 goto done;
1511 vers -= min_vers;
1513 which = req->rq_proc;
1514 if (which < 0 || which >= disptable[(int)vers].dis_nprocs) {
1515 svcerr_noproc(req->rq_xprt);
1516 error++;
1517 goto done;
1520 (*(disptable[(int)vers].dis_proccntp))[which].value.ui64++;
1522 disp = &disptable[(int)vers].dis_table[which];
1523 procnames = disptable[(int)vers].dis_procnames;
1525 auth_flavor = req->rq_cred.oa_flavor;
1528 * Deserialize into the args struct.
1530 args = (char *)&args_buf;
1532 #ifdef DEBUG
1533 if (rfs_no_fast_xdrargs || (auth_flavor == RPCSEC_GSS) ||
1534 disp->dis_fastxdrargs == NULL_xdrproc_t ||
1535 !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1536 #else
1537 if ((auth_flavor == RPCSEC_GSS) ||
1538 disp->dis_fastxdrargs == NULL_xdrproc_t ||
1539 !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1540 #endif
1542 bzero(args, disp->dis_argsz);
1543 if (!SVC_GETARGS(xprt, disp->dis_xdrargs, args)) {
1544 error++;
1546 * Check if we are outside our capabilities.
1548 if (rfs4_minorvers_mismatch(req, xprt, (void *)args))
1549 goto done;
1551 svcerr_decode(xprt);
1552 cmn_err(CE_NOTE,
1553 "Failed to decode arguments for %s version %u "
1554 "procedure %s client %s%s",
1555 pgmname, vers + min_vers, procnames[which],
1556 client_name(req), client_addr(req, cbuf));
1557 goto done;
1562 * If Version 4 use that specific dispatch function.
1564 if (req->rq_vers == 4) {
1565 error += rfs4_dispatch(disp, req, xprt, args);
1566 goto done;
1569 dis_flags = disp->dis_flags;
1572 * Find export information and check authentication,
1573 * setting the credential if everything is ok.
1575 if (disp->dis_getfh != NULL) {
1576 void *fh;
1577 fsid_t *fsid;
1578 fid_t *fid, *xfid;
1579 fhandle_t *fh2;
1580 nfs_fh3 *fh3;
1582 fh = (*disp->dis_getfh)(args);
1583 switch (req->rq_vers) {
1584 case NFS_VERSION:
1585 fh2 = (fhandle_t *)fh;
1586 fsid = &fh2->fh_fsid;
1587 fid = (fid_t *)&fh2->fh_len;
1588 xfid = (fid_t *)&fh2->fh_xlen;
1589 break;
1590 case NFS_V3:
1591 fh3 = (nfs_fh3 *)fh;
1592 fsid = &fh3->fh3_fsid;
1593 fid = FH3TOFIDP(fh3);
1594 xfid = FH3TOXFIDP(fh3);
1595 break;
1599 * Fix for bug 1038302 - corbin
1600 * There is a problem here if anonymous access is
1601 * disallowed. If the current request is part of the
1602 * client's mount process for the requested filesystem,
1603 * then it will carry root (uid 0) credentials on it, and
1604 * will be denied by checkauth if that client does not
1605 * have explicit root=0 permission. This will cause the
1606 * client's mount operation to fail. As a work-around,
1607 * we check here to see if the request is a getattr or
1608 * statfs operation on the exported vnode itself, and
1609 * pass a flag to checkauth with the result of this test.
1611 * The filehandle refers to the mountpoint itself if
1612 * the fh_data and fh_xdata portions of the filehandle
1613 * are equal.
1615 * Added anon_ok argument to checkauth().
1618 if ((dis_flags & RPC_ALLOWANON) && EQFID(fid, xfid))
1619 anon_ok = 1;
1620 else
1621 anon_ok = 0;
1623 cr = xprt->xp_cred;
1624 ASSERT(cr != NULL);
1625 #ifdef DEBUG
1626 if (crgetref(cr) != 1) {
1627 crfree(cr);
1628 cr = crget();
1629 xprt->xp_cred = cr;
1630 cred_misses++;
1631 } else
1632 cred_hits++;
1633 #else
1634 if (crgetref(cr) != 1) {
1635 crfree(cr);
1636 cr = crget();
1637 xprt->xp_cred = cr;
1639 #endif
1641 exi = checkexport(fsid, xfid);
1643 if (exi != NULL) {
1644 publicfh_ok = PUBLICFH_CHECK(disp, exi, fsid, xfid);
1647 * Don't allow non-V4 clients access
1648 * to pseudo exports
1650 if (PSEUDO(exi)) {
1651 svcerr_weakauth(xprt);
1652 error++;
1653 goto done;
1656 authres = checkauth(exi, req, cr, anon_ok, publicfh_ok);
1658 * authres > 0: authentication OK - proceed
1659 * authres == 0: authentication weak - return error
1660 * authres < 0: authentication timeout - drop
1662 if (authres <= 0) {
1663 if (authres == 0) {
1664 svcerr_weakauth(xprt);
1665 error++;
1667 goto done;
1670 } else
1671 cr = NULL;
1673 if ((dis_flags & RPC_MAPRESP) && (auth_flavor != RPCSEC_GSS)) {
1674 res = (char *)SVC_GETRES(xprt, disp->dis_ressz);
1675 if (res == NULL)
1676 res = (char *)&res_buf;
1677 } else
1678 res = (char *)&res_buf;
1680 if (!(dis_flags & RPC_IDEMPOTENT)) {
1681 dupstat = SVC_DUP_EXT(xprt, req, res, disp->dis_ressz, &dr,
1682 &dupcached);
1684 switch (dupstat) {
1685 case DUP_ERROR:
1686 svcerr_systemerr(xprt);
1687 error++;
1688 goto done;
1689 /* NOTREACHED */
1690 case DUP_INPROGRESS:
1691 if (res != (char *)&res_buf)
1692 SVC_FREERES(xprt);
1693 error++;
1694 goto done;
1695 /* NOTREACHED */
1696 case DUP_NEW:
1697 case DUP_DROP:
1698 curthread->t_flag |= T_DONTPEND;
1700 (*disp->dis_proc)(args, res, exi, req, cr);
1702 curthread->t_flag &= ~T_DONTPEND;
1703 if (curthread->t_flag & T_WOULDBLOCK) {
1704 curthread->t_flag &= ~T_WOULDBLOCK;
1705 SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1706 disp->dis_ressz, DUP_DROP);
1707 if (res != (char *)&res_buf)
1708 SVC_FREERES(xprt);
1709 error++;
1710 goto done;
1712 if (dis_flags & RPC_AVOIDWORK) {
1713 SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1714 disp->dis_ressz, DUP_DROP);
1715 } else {
1716 SVC_DUPDONE_EXT(xprt, dr, res,
1717 disp->dis_resfree == nullfree ? NULL :
1718 disp->dis_resfree,
1719 disp->dis_ressz, DUP_DONE);
1720 dupcached = TRUE;
1722 break;
1723 case DUP_DONE:
1724 break;
1727 } else {
1728 curthread->t_flag |= T_DONTPEND;
1730 (*disp->dis_proc)(args, res, exi, req, cr);
1732 curthread->t_flag &= ~T_DONTPEND;
1733 if (curthread->t_flag & T_WOULDBLOCK) {
1734 curthread->t_flag &= ~T_WOULDBLOCK;
1735 if (res != (char *)&res_buf)
1736 SVC_FREERES(xprt);
1737 error++;
1738 goto done;
1742 if (auth_tooweak(req, res)) {
1743 svcerr_weakauth(xprt);
1744 error++;
1745 goto done;
1749 * Check to see if logging has been enabled on the server.
1750 * If so, then obtain the export info struct to be used for
1751 * the later writing of the log record. This is done for
1752 * the case that a lookup is done across a non-logged public
1753 * file system.
1755 if (nfslog_buffer_list != NULL) {
1756 nfslog_exi = nfslog_get_exi(exi, req, res, &nfslog_rec_id);
1758 * Is logging enabled?
1760 logging_enabled = (nfslog_exi != NULL);
1763 * Copy the netbuf for logging purposes, before it is
1764 * freed by svc_sendreply().
1766 if (logging_enabled) {
1767 NFSLOG_COPY_NETBUF(nfslog_exi, xprt, &nb);
1769 * If RPC_MAPRESP flag set (i.e. in V2 ops) the
1770 * res gets copied directly into the mbuf and
1771 * may be freed soon after the sendreply. So we
1772 * must copy it here to a safe place...
1774 if (res != (char *)&res_buf) {
1775 bcopy(res, (char *)&res_buf, disp->dis_ressz);
1781 * Serialize and send results struct
1783 #ifdef DEBUG
1784 if (rfs_no_fast_xdrres == 0 && res != (char *)&res_buf)
1785 #else
1786 if (res != (char *)&res_buf)
1787 #endif
1789 if (!svc_sendreply(xprt, disp->dis_fastxdrres, res)) {
1790 cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1791 svcerr_systemerr(xprt);
1792 error++;
1794 } else {
1795 if (!svc_sendreply(xprt, disp->dis_xdrres, res)) {
1796 cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1797 svcerr_systemerr(xprt);
1798 error++;
1803 * Log if needed
1805 if (logging_enabled) {
1806 nfslog_write_record(nfslog_exi, req, args, (char *)&res_buf,
1807 cr, &nb, nfslog_rec_id, NFSLOG_ONE_BUFFER);
1808 exi_rele(nfslog_exi);
1809 kmem_free((&nb)->buf, (&nb)->len);
1813 * Free results struct. With the addition of NFS V4 we can
1814 * have non-idempotent procedures with functions.
1816 if (disp->dis_resfree != nullfree && dupcached == FALSE) {
1817 (*disp->dis_resfree)(res);
1820 done:
1822 * Free arguments struct
1824 if (disp) {
1825 if (!SVC_FREEARGS(xprt, disp->dis_xdrargs, args)) {
1826 cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1827 error++;
1829 } else {
1830 if (!SVC_FREEARGS(xprt, (xdrproc_t)0, (caddr_t)0)) {
1831 cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1832 error++;
1836 if (exi != NULL)
1837 exi_rele(exi);
1839 global_svstat_ptr[req->rq_vers][NFS_BADCALLS].value.ui64 += error;
1841 global_svstat_ptr[req->rq_vers][NFS_CALLS].value.ui64++;
1844 static void
1845 rfs_dispatch(struct svc_req *req, SVCXPRT *xprt)
1847 common_dispatch(req, xprt, NFS_VERSMIN, NFS_VERSMAX,
1848 "NFS", rfs_disptable);
1851 static char *aclcallnames_v2[] = {
1852 "ACL2_NULL",
1853 "ACL2_GETACL",
1854 "ACL2_SETACL",
1855 "ACL2_GETATTR",
1856 "ACL2_ACCESS",
1857 "ACL2_GETXATTRDIR"
1860 static struct rpcdisp acldisptab_v2[] = {
1862 * ACL VERSION 2
1865 /* ACL2_NULL = 0 */
1866 {rpc_null,
1867 xdr_void, NULL_xdrproc_t, 0,
1868 xdr_void, NULL_xdrproc_t, 0,
1869 nullfree, RPC_IDEMPOTENT,
1872 /* ACL2_GETACL = 1 */
1873 {acl2_getacl,
1874 xdr_GETACL2args, xdr_fastGETACL2args, sizeof (GETACL2args),
1875 xdr_GETACL2res, NULL_xdrproc_t, sizeof (GETACL2res),
1876 acl2_getacl_free, RPC_IDEMPOTENT,
1877 acl2_getacl_getfh},
1879 /* ACL2_SETACL = 2 */
1880 {acl2_setacl,
1881 xdr_SETACL2args, NULL_xdrproc_t, sizeof (SETACL2args),
1882 #ifdef _LITTLE_ENDIAN
1883 xdr_SETACL2res, xdr_fastSETACL2res, sizeof (SETACL2res),
1884 #else
1885 xdr_SETACL2res, NULL_xdrproc_t, sizeof (SETACL2res),
1886 #endif
1887 nullfree, RPC_MAPRESP,
1888 acl2_setacl_getfh},
1890 /* ACL2_GETATTR = 3 */
1891 {acl2_getattr,
1892 xdr_GETATTR2args, xdr_fastGETATTR2args, sizeof (GETATTR2args),
1893 #ifdef _LITTLE_ENDIAN
1894 xdr_GETATTR2res, xdr_fastGETATTR2res, sizeof (GETATTR2res),
1895 #else
1896 xdr_GETATTR2res, NULL_xdrproc_t, sizeof (GETATTR2res),
1897 #endif
1898 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
1899 acl2_getattr_getfh},
1901 /* ACL2_ACCESS = 4 */
1902 {acl2_access,
1903 xdr_ACCESS2args, xdr_fastACCESS2args, sizeof (ACCESS2args),
1904 #ifdef _LITTLE_ENDIAN
1905 xdr_ACCESS2res, xdr_fastACCESS2res, sizeof (ACCESS2res),
1906 #else
1907 xdr_ACCESS2res, NULL_xdrproc_t, sizeof (ACCESS2res),
1908 #endif
1909 nullfree, RPC_IDEMPOTENT|RPC_MAPRESP,
1910 acl2_access_getfh},
1912 /* ACL2_GETXATTRDIR = 5 */
1913 {acl2_getxattrdir,
1914 xdr_GETXATTRDIR2args, NULL_xdrproc_t, sizeof (GETXATTRDIR2args),
1915 xdr_GETXATTRDIR2res, NULL_xdrproc_t, sizeof (GETXATTRDIR2res),
1916 nullfree, RPC_IDEMPOTENT,
1917 acl2_getxattrdir_getfh},
1920 static char *aclcallnames_v3[] = {
1921 "ACL3_NULL",
1922 "ACL3_GETACL",
1923 "ACL3_SETACL",
1924 "ACL3_GETXATTRDIR"
1927 static struct rpcdisp acldisptab_v3[] = {
1929 * ACL VERSION 3
1932 /* ACL3_NULL = 0 */
1933 {rpc_null,
1934 xdr_void, NULL_xdrproc_t, 0,
1935 xdr_void, NULL_xdrproc_t, 0,
1936 nullfree, RPC_IDEMPOTENT,
1939 /* ACL3_GETACL = 1 */
1940 {acl3_getacl,
1941 xdr_GETACL3args, NULL_xdrproc_t, sizeof (GETACL3args),
1942 xdr_GETACL3res, NULL_xdrproc_t, sizeof (GETACL3res),
1943 acl3_getacl_free, RPC_IDEMPOTENT,
1944 acl3_getacl_getfh},
1946 /* ACL3_SETACL = 2 */
1947 {acl3_setacl,
1948 xdr_SETACL3args, NULL_xdrproc_t, sizeof (SETACL3args),
1949 xdr_SETACL3res, NULL_xdrproc_t, sizeof (SETACL3res),
1950 nullfree, 0,
1951 acl3_setacl_getfh},
1953 /* ACL3_GETXATTRDIR = 3 */
1954 {acl3_getxattrdir,
1955 xdr_GETXATTRDIR3args, NULL_xdrproc_t, sizeof (GETXATTRDIR3args),
1956 xdr_GETXATTRDIR3res, NULL_xdrproc_t, sizeof (GETXATTRDIR3res),
1957 nullfree, RPC_IDEMPOTENT,
1958 acl3_getxattrdir_getfh},
1961 static struct rpc_disptable acl_disptable[] = {
1962 {sizeof (acldisptab_v2) / sizeof (acldisptab_v2[0]),
1963 aclcallnames_v2,
1964 &aclproccnt_v2_ptr, acldisptab_v2},
1965 {sizeof (acldisptab_v3) / sizeof (acldisptab_v3[0]),
1966 aclcallnames_v3,
1967 &aclproccnt_v3_ptr, acldisptab_v3},
1970 static void
1971 acl_dispatch(struct svc_req *req, SVCXPRT *xprt)
1973 common_dispatch(req, xprt, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,
1974 "ACL", acl_disptable);
1978 checkwin(int flavor, int window, struct svc_req *req)
1980 struct authdes_cred *adc;
1982 switch (flavor) {
1983 case AUTH_DES:
1984 adc = (struct authdes_cred *)req->rq_clntcred;
1985 if (adc->adc_fullname.window > window)
1986 return (0);
1987 break;
1989 default:
1990 break;
1992 return (1);
1997 * checkauth() will check the access permission against the export
1998 * information. Then map root uid/gid to appropriate uid/gid.
2000 * This routine is used by NFS V3 and V2 code.
2002 static int
2003 checkauth(struct exportinfo *exi, struct svc_req *req, cred_t *cr, int anon_ok,
2004 bool_t publicfh_ok)
2006 int i, nfsflavor, rpcflavor, stat, access;
2007 struct secinfo *secp;
2008 caddr_t principal;
2009 char buf[INET6_ADDRSTRLEN]; /* to hold both IPv4 and IPv6 addr */
2010 int anon_res = 0;
2013 * Check for privileged port number
2014 * N.B.: this assumes that we know the format of a netbuf.
2016 if (nfs_portmon) {
2017 struct sockaddr *ca;
2018 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2020 if (ca == NULL)
2021 return (0);
2023 if ((ca->sa_family == AF_INET &&
2024 ntohs(((struct sockaddr_in *)ca)->sin_port) >=
2025 IPPORT_RESERVED) ||
2026 (ca->sa_family == AF_INET6 &&
2027 ntohs(((struct sockaddr_in6 *)ca)->sin6_port) >=
2028 IPPORT_RESERVED)) {
2029 cmn_err(CE_NOTE,
2030 "nfs_server: client %s%ssent NFS request from "
2031 "unprivileged port",
2032 client_name(req), client_addr(req, buf));
2033 return (0);
2038 * return 1 on success or 0 on failure
2040 stat = sec_svc_getcred(req, cr, &principal, &nfsflavor);
2043 * A failed AUTH_UNIX svc_get_cred() implies we couldn't set
2044 * the credentials; below we map that to anonymous.
2046 if (!stat && nfsflavor != AUTH_UNIX) {
2047 cmn_err(CE_NOTE,
2048 "nfs_server: couldn't get unix cred for %s",
2049 client_name(req));
2050 return (0);
2054 * Short circuit checkauth() on operations that support the
2055 * public filehandle, and if the request for that operation
2056 * is using the public filehandle. Note that we must call
2057 * sec_svc_getcred() first so that xp_cookie is set to the
2058 * right value. Normally xp_cookie is just the RPC flavor
2059 * of the the request, but in the case of RPCSEC_GSS it
2060 * could be a pseudo flavor.
2062 if (publicfh_ok)
2063 return (1);
2065 rpcflavor = req->rq_cred.oa_flavor;
2067 * Check if the auth flavor is valid for this export
2069 access = nfsauth_access(exi, req);
2070 if (access & NFSAUTH_DROP)
2071 return (-1); /* drop the request */
2073 if (access & NFSAUTH_DENIED) {
2075 * If anon_ok == 1 and we got NFSAUTH_DENIED, it was
2076 * probably due to the flavor not matching during the
2077 * the mount attempt. So map the flavor to AUTH_NONE
2078 * so that the credentials get mapped to the anonymous
2079 * user.
2081 if (anon_ok == 1)
2082 rpcflavor = AUTH_NONE;
2083 else
2084 return (0); /* deny access */
2086 } else if (access & NFSAUTH_MAPNONE) {
2088 * Access was granted even though the flavor mismatched
2089 * because AUTH_NONE was one of the exported flavors.
2091 rpcflavor = AUTH_NONE;
2093 } else if (access & NFSAUTH_WRONGSEC) {
2095 * NFSAUTH_WRONGSEC is used for NFSv4. If we get here,
2096 * it means a client ignored the list of allowed flavors
2097 * returned via the MOUNT protocol. So we just disallow it!
2099 return (0);
2102 switch (rpcflavor) {
2103 case AUTH_NONE:
2104 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2105 exi->exi_export.ex_anon);
2106 (void) crsetgroups(cr, 0, NULL);
2107 break;
2109 case AUTH_UNIX:
2110 if (!stat || crgetuid(cr) == 0 && !(access & NFSAUTH_ROOT)) {
2111 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2112 exi->exi_export.ex_anon);
2113 (void) crsetgroups(cr, 0, NULL);
2114 } else if (!stat || crgetuid(cr) == 0 &&
2115 access & NFSAUTH_ROOT) {
2117 * It is root, so apply rootid to get real UID
2118 * Find the secinfo structure. We should be able
2119 * to find it by the time we reach here.
2120 * nfsauth_access() has done the checking.
2122 secp = NULL;
2123 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2124 struct secinfo *sptr;
2125 sptr = &exi->exi_export.ex_secinfo[i];
2126 if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2127 secp = sptr;
2128 break;
2131 if (secp != NULL) {
2132 (void) crsetugid(cr, secp->s_rootid,
2133 secp->s_rootid);
2134 (void) crsetgroups(cr, 0, NULL);
2137 break;
2139 case AUTH_DES:
2140 case RPCSEC_GSS:
2142 * Find the secinfo structure. We should be able
2143 * to find it by the time we reach here.
2144 * nfsauth_access() has done the checking.
2146 secp = NULL;
2147 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2148 if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2149 nfsflavor) {
2150 secp = &exi->exi_export.ex_secinfo[i];
2151 break;
2155 if (!secp) {
2156 cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2157 "no secinfo data for flavor %d",
2158 client_name(req), client_addr(req, buf),
2159 nfsflavor);
2160 return (0);
2163 if (!checkwin(rpcflavor, secp->s_window, req)) {
2164 cmn_err(CE_NOTE,
2165 "nfs_server: client %s%sused invalid "
2166 "auth window value",
2167 client_name(req), client_addr(req, buf));
2168 return (0);
2172 * Map root principals listed in the share's root= list to root,
2173 * and map any others principals that were mapped to root by RPC
2174 * to anon.
2176 if (principal && sec_svc_inrootlist(rpcflavor, principal,
2177 secp->s_rootcnt, secp->s_rootnames)) {
2178 if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2179 return (1);
2182 (void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2185 * NOTE: If and when kernel-land privilege tracing is
2186 * added this may have to be replaced with code that
2187 * retrieves root's supplementary groups (e.g., using
2188 * kgss_get_group_info(). In the meantime principals
2189 * mapped to uid 0 get all privileges, so setting cr's
2190 * supplementary groups for them does nothing.
2192 (void) crsetgroups(cr, 0, NULL);
2194 return (1);
2198 * Not a root princ, or not in root list, map UID 0/nobody to
2199 * the anon ID for the share. (RPC sets cr's UIDs and GIDs to
2200 * UID_NOBODY and GID_NOBODY, respectively.)
2202 if (crgetuid(cr) != 0 &&
2203 (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2204 return (1);
2206 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2207 exi->exi_export.ex_anon);
2208 (void) crsetgroups(cr, 0, NULL);
2209 break;
2210 default:
2211 return (0);
2212 } /* switch on rpcflavor */
2215 * Even if anon access is disallowed via ex_anon == -1, we allow
2216 * this access if anon_ok is set. So set creds to the default
2217 * "nobody" id.
2219 if (anon_res != 0) {
2220 if (anon_ok == 0) {
2221 cmn_err(CE_NOTE,
2222 "nfs_server: client %s%ssent wrong "
2223 "authentication for %s",
2224 client_name(req), client_addr(req, buf),
2225 exi->exi_export.ex_path ?
2226 exi->exi_export.ex_path : "?");
2227 return (0);
2230 if (crsetugid(cr, UID_NOBODY, GID_NOBODY) != 0)
2231 return (0);
2234 return (1);
2238 * returns 0 on failure, -1 on a drop, -2 on wrong security flavor,
2239 * and 1 on success
2242 checkauth4(struct compound_state *cs, struct svc_req *req)
2244 int i, rpcflavor, access;
2245 struct secinfo *secp;
2246 char buf[MAXHOST + 1];
2247 int anon_res = 0, nfsflavor;
2248 struct exportinfo *exi;
2249 cred_t *cr;
2250 caddr_t principal;
2252 exi = cs->exi;
2253 cr = cs->cr;
2254 principal = cs->principal;
2255 nfsflavor = cs->nfsflavor;
2257 ASSERT(cr != NULL);
2259 rpcflavor = req->rq_cred.oa_flavor;
2260 cs->access &= ~CS_ACCESS_LIMITED;
2263 * Check for privileged port number
2264 * N.B.: this assumes that we know the format of a netbuf.
2266 if (nfs_portmon) {
2267 struct sockaddr *ca;
2268 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2270 if (ca == NULL)
2271 return (0);
2273 if ((ca->sa_family == AF_INET &&
2274 ntohs(((struct sockaddr_in *)ca)->sin_port) >=
2275 IPPORT_RESERVED) ||
2276 (ca->sa_family == AF_INET6 &&
2277 ntohs(((struct sockaddr_in6 *)ca)->sin6_port) >=
2278 IPPORT_RESERVED)) {
2279 cmn_err(CE_NOTE,
2280 "nfs_server: client %s%ssent NFSv4 request from "
2281 "unprivileged port",
2282 client_name(req), client_addr(req, buf));
2283 return (0);
2288 * Check the access right per auth flavor on the vnode of
2289 * this export for the given request.
2291 access = nfsauth4_access(cs->exi, cs->vp, req);
2293 if (access & NFSAUTH_WRONGSEC)
2294 return (-2); /* no access for this security flavor */
2296 if (access & NFSAUTH_DROP)
2297 return (-1); /* drop the request */
2299 if (access & NFSAUTH_DENIED) {
2301 if (exi->exi_export.ex_seccnt > 0)
2302 return (0); /* deny access */
2304 } else if (access & NFSAUTH_LIMITED) {
2306 cs->access |= CS_ACCESS_LIMITED;
2308 } else if (access & NFSAUTH_MAPNONE) {
2310 * Access was granted even though the flavor mismatched
2311 * because AUTH_NONE was one of the exported flavors.
2313 rpcflavor = AUTH_NONE;
2317 * XXX probably need to redo some of it for nfsv4?
2318 * return 1 on success or 0 on failure
2321 switch (rpcflavor) {
2322 case AUTH_NONE:
2323 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2324 exi->exi_export.ex_anon);
2325 (void) crsetgroups(cr, 0, NULL);
2326 break;
2328 case AUTH_UNIX:
2329 if (crgetuid(cr) == 0 && !(access & NFSAUTH_ROOT)) {
2330 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2331 exi->exi_export.ex_anon);
2332 (void) crsetgroups(cr, 0, NULL);
2333 } else if (crgetuid(cr) == 0 && access & NFSAUTH_ROOT) {
2335 * It is root, so apply rootid to get real UID
2336 * Find the secinfo structure. We should be able
2337 * to find it by the time we reach here.
2338 * nfsauth_access() has done the checking.
2340 secp = NULL;
2341 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2342 struct secinfo *sptr;
2343 sptr = &exi->exi_export.ex_secinfo[i];
2344 if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2345 secp = &exi->exi_export.ex_secinfo[i];
2346 break;
2349 if (secp != NULL) {
2350 (void) crsetugid(cr, secp->s_rootid,
2351 secp->s_rootid);
2352 (void) crsetgroups(cr, 0, NULL);
2355 break;
2357 default:
2359 * Find the secinfo structure. We should be able
2360 * to find it by the time we reach here.
2361 * nfsauth_access() has done the checking.
2363 secp = NULL;
2364 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2365 if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2366 nfsflavor) {
2367 secp = &exi->exi_export.ex_secinfo[i];
2368 break;
2372 if (!secp) {
2373 cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2374 "no secinfo data for flavor %d",
2375 client_name(req), client_addr(req, buf),
2376 nfsflavor);
2377 return (0);
2380 if (!checkwin(rpcflavor, secp->s_window, req)) {
2381 cmn_err(CE_NOTE,
2382 "nfs_server: client %s%sused invalid "
2383 "auth window value",
2384 client_name(req), client_addr(req, buf));
2385 return (0);
2389 * Map root principals listed in the share's root= list to root,
2390 * and map any others principals that were mapped to root by RPC
2391 * to anon. If not going to anon, set to rootid (root_mapping).
2393 if (principal && sec_svc_inrootlist(rpcflavor, principal,
2394 secp->s_rootcnt, secp->s_rootnames)) {
2395 if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2396 return (1);
2398 (void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2401 * NOTE: If and when kernel-land privilege tracing is
2402 * added this may have to be replaced with code that
2403 * retrieves root's supplementary groups (e.g., using
2404 * kgss_get_group_info(). In the meantime principals
2405 * mapped to uid 0 get all privileges, so setting cr's
2406 * supplementary groups for them does nothing.
2408 (void) crsetgroups(cr, 0, NULL);
2410 return (1);
2414 * Not a root princ, or not in root list, map UID 0/nobody to
2415 * the anon ID for the share. (RPC sets cr's UIDs and GIDs to
2416 * UID_NOBODY and GID_NOBODY, respectively.)
2418 if (crgetuid(cr) != 0 &&
2419 (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2420 return (1);
2422 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2423 exi->exi_export.ex_anon);
2424 (void) crsetgroups(cr, 0, NULL);
2425 break;
2426 } /* switch on rpcflavor */
2429 * Even if anon access is disallowed via ex_anon == -1, we allow
2430 * this access if anon_ok is set. So set creds to the default
2431 * "nobody" id.
2434 if (anon_res != 0) {
2435 cmn_err(CE_NOTE,
2436 "nfs_server: client %s%ssent wrong "
2437 "authentication for %s",
2438 client_name(req), client_addr(req, buf),
2439 exi->exi_export.ex_path ?
2440 exi->exi_export.ex_path : "?");
2441 return (0);
2444 return (1);
2448 static char *
2449 client_name(struct svc_req *req)
2451 char *hostname = NULL;
2454 * If it's a Unix cred then use the
2455 * hostname from the credential.
2457 if (req->rq_cred.oa_flavor == AUTH_UNIX) {
2458 hostname = ((struct authunix_parms *)
2459 req->rq_clntcred)->aup_machname;
2461 if (hostname == NULL)
2462 hostname = "";
2464 return (hostname);
2467 static char *
2468 client_addr(struct svc_req *req, char *buf)
2470 struct sockaddr *ca;
2471 uchar_t *b;
2472 char *frontspace = "";
2475 * We assume we are called in tandem with client_name and the
2476 * format string looks like "...client %s%sblah blah..."
2478 * If it's a Unix cred then client_name returned
2479 * a host name, so we need insert a space between host name
2480 * and IP address.
2482 if (req->rq_cred.oa_flavor == AUTH_UNIX)
2483 frontspace = " ";
2486 * Convert the caller's IP address to a dotted string
2488 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2490 if (ca->sa_family == AF_INET) {
2491 b = (uchar_t *)&((struct sockaddr_in *)ca)->sin_addr;
2492 (void) sprintf(buf, "%s(%d.%d.%d.%d) ", frontspace,
2493 b[0] & 0xFF, b[1] & 0xFF, b[2] & 0xFF, b[3] & 0xFF);
2494 } else if (ca->sa_family == AF_INET6) {
2495 struct sockaddr_in6 *sin6;
2496 sin6 = (struct sockaddr_in6 *)ca;
2497 (void) kinet_ntop6((uchar_t *)&sin6->sin6_addr,
2498 buf, INET6_ADDRSTRLEN);
2500 } else {
2503 * No IP address to print. If there was a host name
2504 * printed, then we print a space.
2506 (void) sprintf(buf, frontspace);
2509 return (buf);
2513 * NFS Server initialization routine. This routine should only be called
2514 * once. It performs the following tasks:
2515 * - Call sub-initialization routines (localize access to variables)
2516 * - Initialize all locks
2517 * - initialize the version 3 write verifier
2520 nfs_srvinit(void)
2522 int error;
2524 error = nfs_exportinit();
2525 if (error != 0)
2526 return (error);
2527 error = rfs4_srvrinit();
2528 if (error != 0) {
2529 nfs_exportfini();
2530 return (error);
2532 rfs_srvrinit();
2533 rfs3_srvrinit();
2534 nfsauth_init();
2536 /* Init the stuff to control start/stop */
2537 nfs_server_upordown = NFS_SERVER_STOPPED;
2538 mutex_init(&nfs_server_upordown_lock, NULL, MUTEX_DEFAULT, NULL);
2539 cv_init(&nfs_server_upordown_cv, NULL, CV_DEFAULT, NULL);
2540 mutex_init(&rdma_wait_mutex, NULL, MUTEX_DEFAULT, NULL);
2541 cv_init(&rdma_wait_cv, NULL, CV_DEFAULT, NULL);
2543 return (0);
2547 * NFS Server finalization routine. This routine is called to cleanup the
2548 * initialization work previously performed if the NFS server module could
2549 * not be loaded correctly.
2551 void
2552 nfs_srvfini(void)
2554 nfsauth_fini();
2555 rfs3_srvrfini();
2556 rfs_srvrfini();
2557 nfs_exportfini();
2559 mutex_destroy(&nfs_server_upordown_lock);
2560 cv_destroy(&nfs_server_upordown_cv);
2561 mutex_destroy(&rdma_wait_mutex);
2562 cv_destroy(&rdma_wait_cv);
2566 * Set up an iovec array of up to cnt pointers.
2569 void
2570 mblk_to_iov(mblk_t *m, int cnt, struct iovec *iovp)
2572 while (m != NULL && cnt-- > 0) {
2573 iovp->iov_base = (caddr_t)m->b_rptr;
2574 iovp->iov_len = (m->b_wptr - m->b_rptr);
2575 iovp++;
2576 m = m->b_cont;
2581 * Common code between NFS Version 2 and NFS Version 3 for the public
2582 * filehandle multicomponent lookups.
2586 * Public filehandle evaluation of a multi-component lookup, following
2587 * symbolic links, if necessary. This may result in a vnode in another
2588 * filesystem, which is OK as long as the other filesystem is exported.
2590 * Note that the exi will be set either to NULL or a new reference to the
2591 * exportinfo struct that corresponds to the vnode of the multi-component path.
2592 * It is the callers responsibility to release this reference.
2595 rfs_publicfh_mclookup(char *p, vnode_t *dvp, cred_t *cr, vnode_t **vpp,
2596 struct exportinfo **exi, struct sec_ol *sec)
2598 int pathflag;
2599 vnode_t *mc_dvp = NULL;
2600 vnode_t *realvp;
2601 int error;
2603 *exi = NULL;
2606 * check if the given path is a url or native path. Since p is
2607 * modified by MCLpath(), it may be empty after returning from
2608 * there, and should be checked.
2610 if ((pathflag = MCLpath(&p)) == -1)
2611 return (EIO);
2614 * If pathflag is SECURITY_QUERY, turn the SEC_QUERY bit
2615 * on in sec->sec_flags. This bit will later serve as an
2616 * indication in makefh_ol() or makefh3_ol() to overload the
2617 * filehandle to contain the sec modes used by the server for
2618 * the path.
2620 if (pathflag == SECURITY_QUERY) {
2621 if ((sec->sec_index = (uint_t)(*p)) > 0) {
2622 sec->sec_flags |= SEC_QUERY;
2623 p++;
2624 if ((pathflag = MCLpath(&p)) == -1)
2625 return (EIO);
2626 } else {
2627 cmn_err(CE_NOTE,
2628 "nfs_server: invalid security index %d, "
2629 "violating WebNFS SNEGO protocol.", sec->sec_index);
2630 return (EIO);
2634 if (p[0] == '\0') {
2635 error = ENOENT;
2636 goto publicfh_done;
2639 error = rfs_pathname(p, &mc_dvp, vpp, dvp, cr, pathflag);
2642 * If name resolves to "/" we get EINVAL since we asked for
2643 * the vnode of the directory that the file is in. Try again
2644 * with NULL directory vnode.
2646 if (error == EINVAL) {
2647 error = rfs_pathname(p, NULL, vpp, dvp, cr, pathflag);
2648 if (!error) {
2649 ASSERT(*vpp != NULL);
2650 if ((*vpp)->v_type == VDIR) {
2651 VN_HOLD(*vpp);
2652 mc_dvp = *vpp;
2653 } else {
2655 * This should not happen, the filesystem is
2656 * in an inconsistent state. Fail the lookup
2657 * at this point.
2659 VN_RELE(*vpp);
2660 error = EINVAL;
2665 if (error)
2666 goto publicfh_done;
2668 if (*vpp == NULL) {
2669 error = ENOENT;
2670 goto publicfh_done;
2673 ASSERT(mc_dvp != NULL);
2674 ASSERT(*vpp != NULL);
2676 if ((*vpp)->v_type == VDIR) {
2677 do {
2679 * *vpp may be an AutoFS node, so we perform
2680 * a VOP_ACCESS() to trigger the mount of the intended
2681 * filesystem, so we can perform the lookup in the
2682 * intended filesystem.
2684 (void) VOP_ACCESS(*vpp, 0, 0, cr, NULL);
2687 * If vnode is covered, get the
2688 * the topmost vnode.
2690 if (vn_mountedvfs(*vpp) != NULL) {
2691 error = traverse(vpp);
2692 if (error) {
2693 VN_RELE(*vpp);
2694 goto publicfh_done;
2698 if (VOP_REALVP(*vpp, &realvp, NULL) == 0 &&
2699 realvp != *vpp) {
2701 * If realvp is different from *vpp
2702 * then release our reference on *vpp, so that
2703 * the export access check be performed on the
2704 * real filesystem instead.
2706 VN_HOLD(realvp);
2707 VN_RELE(*vpp);
2708 *vpp = realvp;
2709 } else {
2710 break;
2712 /* LINTED */
2713 } while (TRUE);
2716 * Let nfs_vptexi() figure what the real parent is.
2718 VN_RELE(mc_dvp);
2719 mc_dvp = NULL;
2721 } else {
2723 * If vnode is covered, get the
2724 * the topmost vnode.
2726 if (vn_mountedvfs(mc_dvp) != NULL) {
2727 error = traverse(&mc_dvp);
2728 if (error) {
2729 VN_RELE(*vpp);
2730 goto publicfh_done;
2734 if (VOP_REALVP(mc_dvp, &realvp, NULL) == 0 &&
2735 realvp != mc_dvp) {
2737 * *vpp is a file, obtain realvp of the parent
2738 * directory vnode.
2740 VN_HOLD(realvp);
2741 VN_RELE(mc_dvp);
2742 mc_dvp = realvp;
2747 * The pathname may take us from the public filesystem to another.
2748 * If that's the case then just set the exportinfo to the new export
2749 * and build filehandle for it. Thanks to per-access checking there's
2750 * no security issues with doing this. If the client is not allowed
2751 * access to this new export then it will get an access error when it
2752 * tries to use the filehandle
2754 if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2755 VN_RELE(*vpp);
2756 goto publicfh_done;
2760 * Not allowed access to pseudo exports.
2762 if (PSEUDO(*exi)) {
2763 error = ENOENT;
2764 VN_RELE(*vpp);
2765 goto publicfh_done;
2769 * Do a lookup for the index file. We know the index option doesn't
2770 * allow paths through handling in the share command, so mc_dvp will
2771 * be the parent for the index file vnode, if its present. Use
2772 * temporary pointers to preserve and reuse the vnode pointers of the
2773 * original directory in case there's no index file. Note that the
2774 * index file is a native path, and should not be interpreted by
2775 * the URL parser in rfs_pathname()
2777 if (((*exi)->exi_export.ex_flags & EX_INDEX) &&
2778 ((*vpp)->v_type == VDIR) && (pathflag == URLPATH)) {
2779 vnode_t *tvp, *tmc_dvp; /* temporary vnode pointers */
2781 tmc_dvp = mc_dvp;
2782 mc_dvp = tvp = *vpp;
2784 error = rfs_pathname((*exi)->exi_export.ex_index, NULL, vpp,
2785 mc_dvp, cr, NATIVEPATH);
2787 if (error == ENOENT) {
2788 *vpp = tvp;
2789 mc_dvp = tmc_dvp;
2790 error = 0;
2791 } else { /* ok or error other than ENOENT */
2792 if (tmc_dvp)
2793 VN_RELE(tmc_dvp);
2794 if (error)
2795 goto publicfh_done;
2798 * Found a valid vp for index "filename". Sanity check
2799 * for odd case where a directory is provided as index
2800 * option argument and leads us to another filesystem
2803 /* Release the reference on the old exi value */
2804 exi_rele(*exi);
2805 *exi = NULL;
2807 if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2808 VN_RELE(*vpp);
2809 goto publicfh_done;
2814 publicfh_done:
2815 if (mc_dvp)
2816 VN_RELE(mc_dvp);
2818 if (error && *exi != NULL)
2819 exi_rele(*exi);
2821 return (error);
2825 * Evaluate a multi-component path
2828 rfs_pathname(
2829 char *path, /* pathname to evaluate */
2830 vnode_t **dirvpp, /* ret for ptr to parent dir vnode */
2831 vnode_t **compvpp, /* ret for ptr to component vnode */
2832 vnode_t *startdvp, /* starting vnode */
2833 cred_t *cr, /* user's credential */
2834 int pathflag) /* flag to identify path, e.g. URL */
2836 char namebuf[TYPICALMAXPATHLEN];
2837 struct pathname pn;
2838 int error;
2841 * If pathname starts with '/', then set startdvp to root.
2843 if (*path == '/') {
2844 while (*path == '/')
2845 path++;
2847 startdvp = rootdir;
2850 error = pn_get_buf(path, UIO_SYSSPACE, &pn, namebuf, sizeof (namebuf));
2851 if (error == 0) {
2853 * Call the URL parser for URL paths to modify the original
2854 * string to handle any '%' encoded characters that exist.
2855 * Done here to avoid an extra bcopy in the lookup.
2856 * We need to be careful about pathlen's. We know that
2857 * rfs_pathname() is called with a non-empty path. However,
2858 * it could be emptied due to the path simply being all /'s,
2859 * which is valid to proceed with the lookup, or due to the
2860 * URL parser finding an encoded null character at the
2861 * beginning of path which should not proceed with the lookup.
2863 if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2864 URLparse(pn.pn_path);
2865 if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0)
2866 return (ENOENT);
2868 VN_HOLD(startdvp);
2869 error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2870 rootdir, startdvp, cr);
2872 if (error == ENAMETOOLONG) {
2874 * This thread used a pathname > TYPICALMAXPATHLEN bytes long.
2876 if (error = pn_get(path, UIO_SYSSPACE, &pn))
2877 return (error);
2878 if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2879 URLparse(pn.pn_path);
2880 if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0) {
2881 pn_free(&pn);
2882 return (ENOENT);
2885 VN_HOLD(startdvp);
2886 error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2887 rootdir, startdvp, cr);
2888 pn_free(&pn);
2891 return (error);
2895 * Adapt the multicomponent lookup path depending on the pathtype
2897 static int
2898 MCLpath(char **path)
2900 unsigned char c = (unsigned char)**path;
2903 * If the MCL path is between 0x20 and 0x7E (graphic printable
2904 * character of the US-ASCII coded character set), its a URL path,
2905 * per RFC 1738.
2907 if (c >= 0x20 && c <= 0x7E)
2908 return (URLPATH);
2911 * If the first octet of the MCL path is not an ASCII character
2912 * then it must be interpreted as a tag value that describes the
2913 * format of the remaining octets of the MCL path.
2915 * If the first octet of the MCL path is 0x81 it is a query
2916 * for the security info.
2918 switch (c) {
2919 case 0x80: /* native path, i.e. MCL via mount protocol */
2920 (*path)++;
2921 return (NATIVEPATH);
2922 case 0x81: /* security query */
2923 (*path)++;
2924 return (SECURITY_QUERY);
2925 default:
2926 return (-1);
2930 #define fromhex(c) ((c >= '0' && c <= '9') ? (c - '0') : \
2931 ((c >= 'A' && c <= 'F') ? (c - 'A' + 10) :\
2932 ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : 0)))
2935 * The implementation of URLparse guarantees that the final string will
2936 * fit in the original one. Replaces '%' occurrences followed by 2 characters
2937 * with its corresponding hexadecimal character.
2939 static void
2940 URLparse(char *str)
2942 char *p, *q;
2944 p = q = str;
2945 while (*p) {
2946 *q = *p;
2947 if (*p++ == '%') {
2948 if (*p) {
2949 *q = fromhex(*p) * 16;
2950 p++;
2951 if (*p) {
2952 *q += fromhex(*p);
2953 p++;
2957 q++;
2959 *q = '\0';
2964 * Get the export information for the lookup vnode, and verify its
2965 * useable.
2967 * Set @exip only in success
2970 nfs_check_vpexi(vnode_t *mc_dvp, vnode_t *vp, cred_t *cr,
2971 struct exportinfo **exip)
2973 int walk;
2974 int error = 0;
2975 struct exportinfo *exi;
2977 exi = nfs_vptoexi(mc_dvp, vp, cr, &walk, NULL, FALSE);
2978 if (exi == NULL)
2979 error = EACCES;
2980 else {
2982 * If nosub is set for this export then
2983 * a lookup relative to the public fh
2984 * must not terminate below the
2985 * exported directory.
2987 if (exi->exi_export.ex_flags & EX_NOSUB && walk > 0) {
2988 error = EACCES;
2989 exi_rele(exi);
2992 if (error == 0)
2993 *exip = exi;
2994 return (error);
2998 * Do the main work of handling HA-NFSv4 Resource Group failover on
2999 * Sun Cluster.
3000 * We need to detect whether any RG admin paths have been added or removed,
3001 * and adjust resources accordingly.
3002 * Currently we're using a very inefficient algorithm, ~ 2 * O(n**2). In
3003 * order to scale, the list and array of paths need to be held in more
3004 * suitable data structures.
3006 static void
3007 hanfsv4_failover(void)
3009 int i, start_grace, numadded_paths = 0;
3010 char **added_paths = NULL;
3011 rfs4_dss_path_t *dss_path;
3014 * Note: currently, rfs4_dss_pathlist cannot be NULL, since
3015 * it will always include an entry for NFS4_DSS_VAR_DIR. If we
3016 * make the latter dynamically specified too, the following will
3017 * need to be adjusted.
3021 * First, look for removed paths: RGs that have been failed-over
3022 * away from this node.
3023 * Walk the "currently-serving" rfs4_dss_pathlist and, for each
3024 * path, check if it is on the "passed-in" rfs4_dss_newpaths array
3025 * from nfsd. If not, that RG path has been removed.
3027 * Note that nfsd has sorted rfs4_dss_newpaths for us, and removed
3028 * any duplicates.
3030 dss_path = rfs4_dss_pathlist;
3031 do {
3032 int found = 0;
3033 char *path = dss_path->path;
3035 /* used only for non-HA so may not be removed */
3036 if (strcmp(path, NFS4_DSS_VAR_DIR) == 0) {
3037 dss_path = dss_path->next;
3038 continue;
3041 for (i = 0; i < rfs4_dss_numnewpaths; i++) {
3042 int cmpret;
3043 char *newpath = rfs4_dss_newpaths[i];
3046 * Since nfsd has sorted rfs4_dss_newpaths for us,
3047 * once the return from strcmp is negative we know
3048 * we've passed the point where "path" should be,
3049 * and can stop searching: "path" has been removed.
3051 cmpret = strcmp(path, newpath);
3052 if (cmpret < 0)
3053 break;
3054 if (cmpret == 0) {
3055 found = 1;
3056 break;
3060 if (found == 0) {
3061 unsigned index = dss_path->index;
3062 rfs4_servinst_t *sip = dss_path->sip;
3063 rfs4_dss_path_t *path_next = dss_path->next;
3066 * This path has been removed.
3067 * We must clear out the servinst reference to
3068 * it, since it's now owned by another
3069 * node: we should not attempt to touch it.
3071 ASSERT(dss_path == sip->dss_paths[index]);
3072 sip->dss_paths[index] = NULL;
3074 /* remove from "currently-serving" list, and destroy */
3075 remque(dss_path);
3076 /* allow for NUL */
3077 kmem_free(dss_path->path, strlen(dss_path->path) + 1);
3078 kmem_free(dss_path, sizeof (rfs4_dss_path_t));
3080 dss_path = path_next;
3081 } else {
3082 /* path was found; not removed */
3083 dss_path = dss_path->next;
3085 } while (dss_path != rfs4_dss_pathlist);
3088 * Now, look for added paths: RGs that have been failed-over
3089 * to this node.
3090 * Walk the "passed-in" rfs4_dss_newpaths array from nfsd and,
3091 * for each path, check if it is on the "currently-serving"
3092 * rfs4_dss_pathlist. If not, that RG path has been added.
3094 * Note: we don't do duplicate detection here; nfsd does that for us.
3096 * Note: numadded_paths <= rfs4_dss_numnewpaths, which gives us
3097 * an upper bound for the size needed for added_paths[numadded_paths].
3100 /* probably more space than we need, but guaranteed to be enough */
3101 if (rfs4_dss_numnewpaths > 0) {
3102 size_t sz = rfs4_dss_numnewpaths * sizeof (char *);
3103 added_paths = kmem_zalloc(sz, KM_SLEEP);
3106 /* walk the "passed-in" rfs4_dss_newpaths array from nfsd */
3107 for (i = 0; i < rfs4_dss_numnewpaths; i++) {
3108 int found = 0;
3109 char *newpath = rfs4_dss_newpaths[i];
3111 dss_path = rfs4_dss_pathlist;
3112 do {
3113 char *path = dss_path->path;
3115 /* used only for non-HA */
3116 if (strcmp(path, NFS4_DSS_VAR_DIR) == 0) {
3117 dss_path = dss_path->next;
3118 continue;
3121 if (strncmp(path, newpath, strlen(path)) == 0) {
3122 found = 1;
3123 break;
3126 dss_path = dss_path->next;
3127 } while (dss_path != rfs4_dss_pathlist);
3129 if (found == 0) {
3130 added_paths[numadded_paths] = newpath;
3131 numadded_paths++;
3135 /* did we find any added paths? */
3136 if (numadded_paths > 0) {
3137 /* create a new server instance, and start its grace period */
3138 start_grace = 1;
3139 rfs4_servinst_create(start_grace, numadded_paths, added_paths);
3141 /* read in the stable storage state from these paths */
3142 rfs4_dss_readstate(numadded_paths, added_paths);
3145 * Multiple failovers during a grace period will cause
3146 * clients of the same resource group to be partitioned
3147 * into different server instances, with different
3148 * grace periods. Since clients of the same resource
3149 * group must be subject to the same grace period,
3150 * we need to reset all currently active grace periods.
3152 rfs4_grace_reset_all();
3155 if (rfs4_dss_numnewpaths > 0)
3156 kmem_free(added_paths, rfs4_dss_numnewpaths * sizeof (char *));
3160 * Used by NFSv3 and NFSv4 server to query label of
3161 * a pathname component during lookup/access ops.
3163 ts_label_t *
3164 nfs_getflabel(vnode_t *vp, struct exportinfo *exi)
3166 zone_t *zone;
3167 ts_label_t *zone_label;
3168 char *path;
3170 mutex_enter(&vp->v_lock);
3171 if (vp->v_path != NULL) {
3172 zone = zone_find_by_any_path(vp->v_path, B_FALSE);
3173 mutex_exit(&vp->v_lock);
3174 } else {
3176 * v_path not cached. Fall back on pathname of exported
3177 * file system as we rely on pathname from which we can
3178 * derive a label. The exported file system portion of
3179 * path is sufficient to obtain a label.
3181 path = exi->exi_export.ex_path;
3182 if (path == NULL) {
3183 mutex_exit(&vp->v_lock);
3184 return (NULL);
3186 zone = zone_find_by_any_path(path, B_FALSE);
3187 mutex_exit(&vp->v_lock);
3190 * Caller has verified that the file is either
3191 * exported or visible. So if the path falls in
3192 * global zone, admin_low is returned; otherwise
3193 * the zone's label is returned.
3195 zone_label = zone->zone_slabel;
3196 label_hold(zone_label);
3197 zone_rele(zone);
3198 return (zone_label);
3202 * TX NFS routine used by NFSv3 and NFSv4 to do label check
3203 * on client label and server's file object lable.
3205 boolean_t
3206 do_rfs_label_check(bslabel_t *clabel, vnode_t *vp, int flag,
3207 struct exportinfo *exi)
3209 bslabel_t *slabel;
3210 ts_label_t *tslabel;
3211 boolean_t result;
3213 if ((tslabel = nfs_getflabel(vp, exi)) == NULL) {
3214 return (B_FALSE);
3216 slabel = label2bslabel(tslabel);
3217 DTRACE_PROBE4(tx__rfs__log__info__labelcheck, char *,
3218 "comparing server's file label(1) with client label(2) (vp(3))",
3219 bslabel_t *, slabel, bslabel_t *, clabel, vnode_t *, vp);
3221 if (flag == EQUALITY_CHECK)
3222 result = blequal(clabel, slabel);
3223 else
3224 result = bldominates(clabel, slabel);
3225 label_rele(tslabel);
3226 return (result);
3230 * Callback function to return the loaned buffers.
3231 * Calls VOP_RETZCBUF() only after all uio_iov[]
3232 * buffers are returned. nu_ref maintains the count.
3234 void
3235 rfs_free_xuio(void *free_arg)
3237 uint_t ref;
3238 nfs_xuio_t *nfsuiop = (nfs_xuio_t *)free_arg;
3240 ref = atomic_dec_uint_nv(&nfsuiop->nu_ref);
3243 * Call VOP_RETZCBUF() only when all the iov buffers
3244 * are sent OTW.
3246 if (ref != 0)
3247 return;
3249 if (((uio_t *)nfsuiop)->uio_extflg & UIO_XUIO) {
3250 (void) VOP_RETZCBUF(nfsuiop->nu_vp, (xuio_t *)free_arg, NULL,
3251 NULL);
3252 VN_RELE(nfsuiop->nu_vp);
3255 kmem_cache_free(nfs_xuio_cache, free_arg);
3258 xuio_t *
3259 rfs_setup_xuio(vnode_t *vp)
3261 nfs_xuio_t *nfsuiop;
3263 nfsuiop = kmem_cache_alloc(nfs_xuio_cache, KM_SLEEP);
3265 bzero(nfsuiop, sizeof (nfs_xuio_t));
3266 nfsuiop->nu_vp = vp;
3269 * ref count set to 1. more may be added
3270 * if multiple mblks refer to multiple iov's.
3271 * This is done in uio_to_mblk().
3274 nfsuiop->nu_ref = 1;
3276 nfsuiop->nu_frtn.free_func = rfs_free_xuio;
3277 nfsuiop->nu_frtn.free_arg = (char *)nfsuiop;
3279 nfsuiop->nu_uio.xu_type = UIOTYPE_ZEROCOPY;
3281 return (&nfsuiop->nu_uio);
3284 mblk_t *
3285 uio_to_mblk(uio_t *uiop)
3287 struct iovec *iovp;
3288 int i;
3289 mblk_t *mp, *mp1;
3290 nfs_xuio_t *nfsuiop = (nfs_xuio_t *)uiop;
3292 if (uiop->uio_iovcnt == 0)
3293 return (NULL);
3295 iovp = uiop->uio_iov;
3296 mp = mp1 = esballoca((uchar_t *)iovp->iov_base, iovp->iov_len,
3297 BPRI_MED, &nfsuiop->nu_frtn);
3298 ASSERT(mp != NULL);
3300 mp->b_wptr += iovp->iov_len;
3301 mp->b_datap->db_type = M_DATA;
3303 for (i = 1; i < uiop->uio_iovcnt; i++) {
3304 iovp = (uiop->uio_iov + i);
3306 mp1->b_cont = esballoca(
3307 (uchar_t *)iovp->iov_base, iovp->iov_len, BPRI_MED,
3308 &nfsuiop->nu_frtn);
3310 mp1 = mp1->b_cont;
3311 ASSERT(mp1 != NULL);
3312 mp1->b_wptr += iovp->iov_len;
3313 mp1->b_datap->db_type = M_DATA;
3316 nfsuiop->nu_ref = uiop->uio_iovcnt;
3318 return (mp);
3321 void
3322 rfs_rndup_mblks(mblk_t *mp, uint_t len, int buf_loaned)
3324 int i, rndup;
3325 int alloc_err = 0;
3326 mblk_t *rmp;
3328 rndup = BYTES_PER_XDR_UNIT - (len % BYTES_PER_XDR_UNIT);
3330 /* single mblk_t non copy-reduction case */
3331 if (!buf_loaned) {
3332 mp->b_wptr += len;
3333 if (rndup != BYTES_PER_XDR_UNIT) {
3334 for (i = 0; i < rndup; i++)
3335 *mp->b_wptr++ = '\0';
3337 return;
3340 /* no need for extra rndup */
3341 if (rndup == BYTES_PER_XDR_UNIT)
3342 return;
3344 while (mp->b_cont)
3345 mp = mp->b_cont;
3348 * In case of copy-reduction mblks, the size of the mblks
3349 * are fixed and are of the size of the loaned buffers.
3350 * Allocate a roundup mblk and chain it to the data
3351 * buffers. This is sub-optimal, but not expected to
3352 * happen in regular common workloads.
3355 rmp = allocb_wait(rndup, BPRI_MED, STR_NOSIG, &alloc_err);
3356 ASSERT(rmp != NULL);
3357 ASSERT(alloc_err == 0);
3359 for (i = 0; i < rndup; i++)
3360 *rmp->b_wptr++ = '\0';
3362 rmp->b_datap->db_type = M_DATA;
3363 mp->b_cont = rmp;