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]
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>
41 #include <sys/vnode.h>
42 #include <sys/pathname.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>
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>
68 #include <rpc/types.h>
70 #include <rpc/auth_unix.h>
71 #include <rpc/auth_des.h>
74 #include <rpc/rpc_rdma.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>
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>
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;
116 if ((status
= nfs_srvinit()) != 0) {
117 cmn_err(CE_WARN
, "_init: nfs_srvinit failed");
121 status
= mod_install((struct modlinkage
*)&modlinkage
);
124 * Could not load module, cleanup previous
125 * initialization work.
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
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);
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, \
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,
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 *);
211 * This table is used by svc_getreq() to dispatch a request with
212 * a given prog/vers pair to an appropriate service provider
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
,
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.
253 NFS_SERVER_STOPPED
, /* server state destroyed */
254 NFS_SERVER_STOPPING
, /* server state being destroyed */
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.
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
300 * If we quiesce the server, we're shutting it down without destroying the
301 * server state. This allows it to warm start subsequently.
304 nfs_srv_stop_all(void)
307 nfs_srv_shutdown_all(quiesce
);
311 * This alternative shutdown routine can be requested via nfssys()
314 nfs_srv_quiesce_all(void)
317 nfs_srv_shutdown_all(quiesce
);
321 nfs_srv_shutdown_all(int quiesce
) {
322 mutex_enter(&nfs_server_upordown_lock
);
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");
337 if (nfs_server_upordown
== NFS_SERVER_OFFLINE
) {
338 nfs_server_upordown
= NFS_SERVER_STOPPING
;
339 mutex_exit(&nfs_server_upordown_lock
);
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
);
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
;
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
,
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
) {
381 if (versmax
== NFS_V4
)
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
;
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
;
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
)
419 char buf
[KNC_STRSIZE
];
421 STRUCT_HANDLE(nfs_svc_args
, uap
);
422 struct netbuf addrmask
;
423 SVC_CALLOUT_TABLE
*sctp
= NULL
;
426 model
= model
; /* STRUCT macros don't always refer to it */
429 STRUCT_SET_HANDLE(uap
, model
, arg
);
431 /* Check privileges in nfssys() */
433 if ((fp
= getf(STRUCT_FGET(uap
, fd
))) == NULL
)
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
,
447 releasef(STRUCT_FGET(uap
, fd
));
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
,
457 releasef(STRUCT_FGET(uap
, fd
));
458 kmem_free(addrmask
.buf
, addrmask
.maxlen
);
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
;
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
);
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
);
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();
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
533 if (cluster_bootflags
& CLUSTER_BOOTED
)
538 nfs4_drc
= rfs4_init_drc(nfs4_drc_max
,
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
)
564 rdma_xprt_group_t started_rdma_xprts
;
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
;
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
;
597 error
= svc_rdma_kcreate(rsa
->netid
, &nfs_sct_rdma
, rsa
->poolid
,
598 &started_rdma_xprts
);
605 * wait till either interrupted by a signal on
606 * nfs service stop/restart or signalled by a
607 * rdma plugin attach/detatch.
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
) &&
619 rdma_stop(&started_rdma_xprts
);
624 * nfs service stop/restart, break out of the
625 * wait loop and return;
627 if (stat
== RDMA_INTR
)
631 * restart stopped services on a HCA attach event
632 * (if not already running)
635 if ((stat
== RDMA_HCA_ATTACH
) && (svc_state
== 0))
639 * loop until a nfs service stop/restart
648 rpc_null(caddr_t
*argp
, caddr_t
*resp
)
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
);
665 rfs_error(caddr_t
*argp
, caddr_t
*resp
)
667 /* return (EOPNOTSUPP); */
675 static char *rfscallnames_v2
[] = {
696 static struct rpcdisp rfsdisptab_v2
[] = {
703 xdr_void
, NULL_xdrproc_t
, 0,
704 xdr_void
, NULL_xdrproc_t
, 0,
705 nullfree
, RPC_IDEMPOTENT
,
708 /* RFS_GETATTR = 1 */
710 xdr_fhandle
, xdr_fastfhandle
, sizeof (fhandle_t
),
711 xdr_attrstat
, xdr_fastattrstat
, sizeof (struct nfsattrstat
),
712 nullfree
, RPC_IDEMPOTENT
|RPC_ALLOWANON
|RPC_MAPRESP
,
715 /* RFS_SETATTR = 2 */
717 xdr_saargs
, NULL_xdrproc_t
, sizeof (struct nfssaargs
),
718 xdr_attrstat
, xdr_fastattrstat
, sizeof (struct nfsattrstat
),
719 nullfree
, RPC_MAPRESP
,
722 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
724 xdr_void
, NULL_xdrproc_t
, 0,
725 xdr_void
, NULL_xdrproc_t
, 0,
726 nullfree
, RPC_IDEMPOTENT
,
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
,
736 /* RFS_READLINK = 5 */
738 xdr_fhandle
, xdr_fastfhandle
, sizeof (fhandle_t
),
739 xdr_rdlnres
, NULL_xdrproc_t
, sizeof (struct nfsrdlnres
),
740 rfs_rlfree
, RPC_IDEMPOTENT
,
745 xdr_readargs
, NULL_xdrproc_t
, sizeof (struct nfsreadargs
),
746 xdr_rdresult
, NULL_xdrproc_t
, sizeof (struct nfsrdresult
),
747 rfs_rdfree
, RPC_IDEMPOTENT
,
750 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
752 xdr_void
, NULL_xdrproc_t
, 0,
753 xdr_void
, NULL_xdrproc_t
, 0,
754 nullfree
, RPC_IDEMPOTENT
,
759 xdr_writeargs
, NULL_xdrproc_t
, sizeof (struct nfswriteargs
),
760 xdr_attrstat
, xdr_fastattrstat
, sizeof (struct nfsattrstat
),
761 nullfree
, RPC_MAPRESP
,
766 xdr_creatargs
, NULL_xdrproc_t
, sizeof (struct nfscreatargs
),
767 xdr_diropres
, xdr_fastdiropres
, sizeof (struct nfsdiropres
),
768 nullfree
, RPC_MAPRESP
,
771 /* RFS_REMOVE = 10 */
773 xdr_diropargs
, NULL_xdrproc_t
, sizeof (struct nfsdiropargs
),
774 #ifdef _LITTLE_ENDIAN
775 xdr_enum
, xdr_fastenum
, sizeof (enum nfsstat
),
777 xdr_enum
, NULL_xdrproc_t
, sizeof (enum nfsstat
),
779 nullfree
, RPC_MAPRESP
,
782 /* RFS_RENAME = 11 */
784 xdr_rnmargs
, NULL_xdrproc_t
, sizeof (struct nfsrnmargs
),
785 #ifdef _LITTLE_ENDIAN
786 xdr_enum
, xdr_fastenum
, sizeof (enum nfsstat
),
788 xdr_enum
, NULL_xdrproc_t
, sizeof (enum nfsstat
),
790 nullfree
, RPC_MAPRESP
,
795 xdr_linkargs
, NULL_xdrproc_t
, sizeof (struct nfslinkargs
),
796 #ifdef _LITTLE_ENDIAN
797 xdr_enum
, xdr_fastenum
, sizeof (enum nfsstat
),
799 xdr_enum
, NULL_xdrproc_t
, sizeof (enum nfsstat
),
801 nullfree
, RPC_MAPRESP
,
804 /* RFS_SYMLINK = 13 */
806 xdr_slargs
, NULL_xdrproc_t
, sizeof (struct nfsslargs
),
807 #ifdef _LITTLE_ENDIAN
808 xdr_enum
, xdr_fastenum
, sizeof (enum nfsstat
),
810 xdr_enum
, NULL_xdrproc_t
, sizeof (enum nfsstat
),
812 nullfree
, RPC_MAPRESP
,
817 xdr_creatargs
, NULL_xdrproc_t
, sizeof (struct nfscreatargs
),
818 xdr_diropres
, xdr_fastdiropres
, sizeof (struct nfsdiropres
),
819 nullfree
, RPC_MAPRESP
,
824 xdr_diropargs
, NULL_xdrproc_t
, sizeof (struct nfsdiropargs
),
825 #ifdef _LITTLE_ENDIAN
826 xdr_enum
, xdr_fastenum
, sizeof (enum nfsstat
),
828 xdr_enum
, NULL_xdrproc_t
, sizeof (enum nfsstat
),
830 nullfree
, RPC_MAPRESP
,
833 /* RFS_READDIR = 16 */
835 xdr_rddirargs
, NULL_xdrproc_t
, sizeof (struct nfsrddirargs
),
836 xdr_putrddirres
, NULL_xdrproc_t
, sizeof (struct nfsrddirres
),
837 rfs_rddirfree
, RPC_IDEMPOTENT
,
840 /* RFS_STATFS = 17 */
842 xdr_fhandle
, xdr_fastfhandle
, sizeof (fhandle_t
),
843 xdr_statfs
, xdr_faststatfs
, sizeof (struct nfsstatfs
),
844 nullfree
, RPC_IDEMPOTENT
|RPC_ALLOWANON
|RPC_MAPRESP
,
848 static char *rfscallnames_v3
[] = {
873 static struct rpcdisp rfsdisptab_v3
[] = {
880 xdr_void
, NULL_xdrproc_t
, 0,
881 xdr_void
, NULL_xdrproc_t
, 0,
882 nullfree
, RPC_IDEMPOTENT
,
885 /* RFS3_GETATTR = 1 */
887 xdr_nfs_fh3_server
, NULL_xdrproc_t
, sizeof (GETATTR3args
),
888 xdr_GETATTR3res
, NULL_xdrproc_t
, sizeof (GETATTR3res
),
889 nullfree
, (RPC_IDEMPOTENT
| RPC_ALLOWANON
),
892 /* RFS3_SETATTR = 2 */
894 xdr_SETATTR3args
, NULL_xdrproc_t
, sizeof (SETATTR3args
),
895 xdr_SETATTR3res
, NULL_xdrproc_t
, sizeof (SETATTR3res
),
899 /* RFS3_LOOKUP = 3 */
901 xdr_diropargs3
, NULL_xdrproc_t
, sizeof (LOOKUP3args
),
902 xdr_LOOKUP3res
, NULL_xdrproc_t
, sizeof (LOOKUP3res
),
903 nullfree
, (RPC_IDEMPOTENT
| RPC_PUBLICFH_OK
),
906 /* RFS3_ACCESS = 4 */
908 xdr_ACCESS3args
, NULL_xdrproc_t
, sizeof (ACCESS3args
),
909 xdr_ACCESS3res
, NULL_xdrproc_t
, sizeof (ACCESS3res
),
910 nullfree
, RPC_IDEMPOTENT
,
913 /* RFS3_READLINK = 5 */
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
},
922 xdr_READ3args
, NULL_xdrproc_t
, sizeof (READ3args
),
923 xdr_READ3res
, NULL_xdrproc_t
, sizeof (READ3res
),
924 rfs3_read_free
, RPC_IDEMPOTENT
,
929 xdr_WRITE3args
, NULL_xdrproc_t
, sizeof (WRITE3args
),
930 xdr_WRITE3res
, NULL_xdrproc_t
, sizeof (WRITE3res
),
934 /* RFS3_CREATE = 8 */
936 xdr_CREATE3args
, NULL_xdrproc_t
, sizeof (CREATE3args
),
937 xdr_CREATE3res
, NULL_xdrproc_t
, sizeof (CREATE3res
),
943 xdr_MKDIR3args
, NULL_xdrproc_t
, sizeof (MKDIR3args
),
944 xdr_MKDIR3res
, NULL_xdrproc_t
, sizeof (MKDIR3res
),
948 /* RFS3_SYMLINK = 10 */
950 xdr_SYMLINK3args
, NULL_xdrproc_t
, sizeof (SYMLINK3args
),
951 xdr_SYMLINK3res
, NULL_xdrproc_t
, sizeof (SYMLINK3res
),
955 /* RFS3_MKNOD = 11 */
957 xdr_MKNOD3args
, NULL_xdrproc_t
, sizeof (MKNOD3args
),
958 xdr_MKNOD3res
, NULL_xdrproc_t
, sizeof (MKNOD3res
),
962 /* RFS3_REMOVE = 12 */
964 xdr_diropargs3
, NULL_xdrproc_t
, sizeof (REMOVE3args
),
965 xdr_REMOVE3res
, NULL_xdrproc_t
, sizeof (REMOVE3res
),
969 /* RFS3_RMDIR = 13 */
971 xdr_diropargs3
, NULL_xdrproc_t
, sizeof (RMDIR3args
),
972 xdr_RMDIR3res
, NULL_xdrproc_t
, sizeof (RMDIR3res
),
976 /* RFS3_RENAME = 14 */
978 xdr_RENAME3args
, NULL_xdrproc_t
, sizeof (RENAME3args
),
979 xdr_RENAME3res
, NULL_xdrproc_t
, sizeof (RENAME3res
),
985 xdr_LINK3args
, NULL_xdrproc_t
, sizeof (LINK3args
),
986 xdr_LINK3res
, NULL_xdrproc_t
, sizeof (LINK3res
),
990 /* RFS3_READDIR = 16 */
992 xdr_READDIR3args
, NULL_xdrproc_t
, sizeof (READDIR3args
),
993 xdr_READDIR3res
, NULL_xdrproc_t
, sizeof (READDIR3res
),
994 rfs3_readdir_free
, RPC_IDEMPOTENT
,
997 /* RFS3_READDIRPLUS = 17 */
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 */
1006 xdr_nfs_fh3_server
, NULL_xdrproc_t
, sizeof (FSSTAT3args
),
1007 xdr_FSSTAT3res
, NULL_xdrproc_t
, sizeof (FSSTAT3res
),
1008 nullfree
, RPC_IDEMPOTENT
,
1011 /* RFS3_FSINFO = 19 */
1013 xdr_nfs_fh3_server
, NULL_xdrproc_t
, sizeof (FSINFO3args
),
1014 xdr_FSINFO3res
, NULL_xdrproc_t
, sizeof (FSINFO3res
),
1015 nullfree
, RPC_IDEMPOTENT
|RPC_ALLOWANON
,
1018 /* RFS3_PATHCONF = 20 */
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 */
1027 xdr_COMMIT3args
, NULL_xdrproc_t
, sizeof (COMMIT3args
),
1028 xdr_COMMIT3res
, NULL_xdrproc_t
, sizeof (COMMIT3res
),
1029 nullfree
, RPC_IDEMPOTENT
,
1033 static char *rfscallnames_v4
[] = {
1045 static struct rpcdisp rfsdisptab_v4
[] = {
1052 xdr_void
, NULL_xdrproc_t
, 0,
1053 xdr_void
, NULL_xdrproc_t
, 0,
1054 nullfree
, RPC_IDEMPOTENT
, 0},
1056 /* RFS4_compound = 1 */
1058 xdr_COMPOUND4args_srv
, NULL_xdrproc_t
, sizeof (COMPOUND4args
),
1059 xdr_COMPOUND4res_srv
, NULL_xdrproc_t
, sizeof (COMPOUND4res
),
1060 rfs4_compound_free
, 0, 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
;
1085 struct nfsreadargs nfs2_read_args
;
1087 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
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
;
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
;
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
;
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
;
1195 COMPOUND4args nfs4_compound_args
;
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
;
1220 struct nfsrdresult nfs2_read_res
;
1222 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
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
;
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
;
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
;
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
;
1329 /* RFS4_COMPOUND = 1 */
1330 COMPOUND4res nfs4_compound_res
;
1334 static struct rpc_disptable rfs_disptable
[] = {
1335 {sizeof (rfsdisptab_v2
) / sizeof (rfsdisptab_v2
[0]),
1337 &rfsproccnt_v2_ptr
, rfsdisptab_v2
},
1338 {sizeof (rfsdisptab_v3
) / sizeof (rfsdisptab_v3
[0]),
1340 &rfsproccnt_v3_ptr
, rfsdisptab_v3
},
1341 {sizeof (rfsdisptab_v4
) / sizeof (rfsdisptab_v4
[0]),
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;
1358 static int cred_hits
= 0;
1359 static int cred_misses
= 0;
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;
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
;
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
;
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
;
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
;
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
)
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
)
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
)
1484 struct rpcdisp
*disp
= NULL
;
1489 struct exportinfo
*exi
= NULL
;
1490 unsigned int nfslog_rec_id
;
1494 bool_t publicfh_ok
= FALSE
;
1496 bool_t dupcached
= FALSE
;
1498 bool_t logging_enabled
= FALSE
;
1499 struct exportinfo
*nfslog_exi
= NULL
;
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
);
1508 cmn_err(CE_NOTE
, "%s: bad version number %u", pgmname
, vers
);
1513 which
= req
->rq_proc
;
1514 if (which
< 0 || which
>= disptable
[(int)vers
].dis_nprocs
) {
1515 svcerr_noproc(req
->rq_xprt
);
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
;
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
))
1537 if ((auth_flavor
== RPCSEC_GSS
) ||
1538 disp
->dis_fastxdrargs
== NULL_xdrproc_t
||
1539 !SVC_GETARGS(xprt
, disp
->dis_fastxdrargs
, (char *)&args
))
1542 bzero(args
, disp
->dis_argsz
);
1543 if (!SVC_GETARGS(xprt
, disp
->dis_xdrargs
, args
)) {
1546 * Check if we are outside our capabilities.
1548 if (rfs4_minorvers_mismatch(req
, xprt
, (void *)args
))
1551 svcerr_decode(xprt
);
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
));
1562 * If Version 4 use that specific dispatch function.
1564 if (req
->rq_vers
== 4) {
1565 error
+= rfs4_dispatch(disp
, req
, xprt
, args
);
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
) {
1582 fh
= (*disp
->dis_getfh
)(args
);
1583 switch (req
->rq_vers
) {
1585 fh2
= (fhandle_t
*)fh
;
1586 fsid
= &fh2
->fh_fsid
;
1587 fid
= (fid_t
*)&fh2
->fh_len
;
1588 xfid
= (fid_t
*)&fh2
->fh_xlen
;
1591 fh3
= (nfs_fh3
*)fh
;
1592 fsid
= &fh3
->fh3_fsid
;
1593 fid
= FH3TOFIDP(fh3
);
1594 xfid
= FH3TOXFIDP(fh3
);
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
1615 * Added anon_ok argument to checkauth().
1618 if ((dis_flags
& RPC_ALLOWANON
) && EQFID(fid
, xfid
))
1626 if (crgetref(cr
) != 1) {
1634 if (crgetref(cr
) != 1) {
1641 exi
= checkexport(fsid
, xfid
);
1644 publicfh_ok
= PUBLICFH_CHECK(disp
, exi
, fsid
, xfid
);
1647 * Don't allow non-V4 clients access
1651 svcerr_weakauth(xprt
);
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
1664 svcerr_weakauth(xprt
);
1673 if ((dis_flags
& RPC_MAPRESP
) && (auth_flavor
!= RPCSEC_GSS
)) {
1674 res
= (char *)SVC_GETRES(xprt
, disp
->dis_ressz
);
1676 res
= (char *)&res_buf
;
1678 res
= (char *)&res_buf
;
1680 if (!(dis_flags
& RPC_IDEMPOTENT
)) {
1681 dupstat
= SVC_DUP_EXT(xprt
, req
, res
, disp
->dis_ressz
, &dr
,
1686 svcerr_systemerr(xprt
);
1690 case DUP_INPROGRESS
:
1691 if (res
!= (char *)&res_buf
)
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
)
1712 if (dis_flags
& RPC_AVOIDWORK
) {
1713 SVC_DUPDONE_EXT(xprt
, dr
, res
, NULL
,
1714 disp
->dis_ressz
, DUP_DROP
);
1716 SVC_DUPDONE_EXT(xprt
, dr
, res
,
1717 disp
->dis_resfree
== nullfree
? NULL
:
1719 disp
->dis_ressz
, DUP_DONE
);
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
)
1742 if (auth_tooweak(req
, res
)) {
1743 svcerr_weakauth(xprt
);
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
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
1784 if (rfs_no_fast_xdrres
== 0 && res
!= (char *)&res_buf
)
1786 if (res
!= (char *)&res_buf
)
1789 if (!svc_sendreply(xprt
, disp
->dis_fastxdrres
, res
)) {
1790 cmn_err(CE_NOTE
, "%s: bad sendreply", pgmname
);
1791 svcerr_systemerr(xprt
);
1795 if (!svc_sendreply(xprt
, disp
->dis_xdrres
, res
)) {
1796 cmn_err(CE_NOTE
, "%s: bad sendreply", pgmname
);
1797 svcerr_systemerr(xprt
);
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
);
1822 * Free arguments struct
1825 if (!SVC_FREEARGS(xprt
, disp
->dis_xdrargs
, args
)) {
1826 cmn_err(CE_NOTE
, "%s: bad freeargs", pgmname
);
1830 if (!SVC_FREEARGS(xprt
, (xdrproc_t
)0, (caddr_t
)0)) {
1831 cmn_err(CE_NOTE
, "%s: bad freeargs", pgmname
);
1839 global_svstat_ptr
[req
->rq_vers
][NFS_BADCALLS
].value
.ui64
+= error
;
1841 global_svstat_ptr
[req
->rq_vers
][NFS_CALLS
].value
.ui64
++;
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
[] = {
1860 static struct rpcdisp acldisptab_v2
[] = {
1867 xdr_void
, NULL_xdrproc_t
, 0,
1868 xdr_void
, NULL_xdrproc_t
, 0,
1869 nullfree
, RPC_IDEMPOTENT
,
1872 /* ACL2_GETACL = 1 */
1874 xdr_GETACL2args
, xdr_fastGETACL2args
, sizeof (GETACL2args
),
1875 xdr_GETACL2res
, NULL_xdrproc_t
, sizeof (GETACL2res
),
1876 acl2_getacl_free
, RPC_IDEMPOTENT
,
1879 /* ACL2_SETACL = 2 */
1881 xdr_SETACL2args
, NULL_xdrproc_t
, sizeof (SETACL2args
),
1882 #ifdef _LITTLE_ENDIAN
1883 xdr_SETACL2res
, xdr_fastSETACL2res
, sizeof (SETACL2res
),
1885 xdr_SETACL2res
, NULL_xdrproc_t
, sizeof (SETACL2res
),
1887 nullfree
, RPC_MAPRESP
,
1890 /* ACL2_GETATTR = 3 */
1892 xdr_GETATTR2args
, xdr_fastGETATTR2args
, sizeof (GETATTR2args
),
1893 #ifdef _LITTLE_ENDIAN
1894 xdr_GETATTR2res
, xdr_fastGETATTR2res
, sizeof (GETATTR2res
),
1896 xdr_GETATTR2res
, NULL_xdrproc_t
, sizeof (GETATTR2res
),
1898 nullfree
, RPC_IDEMPOTENT
|RPC_ALLOWANON
|RPC_MAPRESP
,
1899 acl2_getattr_getfh
},
1901 /* ACL2_ACCESS = 4 */
1903 xdr_ACCESS2args
, xdr_fastACCESS2args
, sizeof (ACCESS2args
),
1904 #ifdef _LITTLE_ENDIAN
1905 xdr_ACCESS2res
, xdr_fastACCESS2res
, sizeof (ACCESS2res
),
1907 xdr_ACCESS2res
, NULL_xdrproc_t
, sizeof (ACCESS2res
),
1909 nullfree
, RPC_IDEMPOTENT
|RPC_MAPRESP
,
1912 /* ACL2_GETXATTRDIR = 5 */
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
[] = {
1927 static struct rpcdisp acldisptab_v3
[] = {
1934 xdr_void
, NULL_xdrproc_t
, 0,
1935 xdr_void
, NULL_xdrproc_t
, 0,
1936 nullfree
, RPC_IDEMPOTENT
,
1939 /* ACL3_GETACL = 1 */
1941 xdr_GETACL3args
, NULL_xdrproc_t
, sizeof (GETACL3args
),
1942 xdr_GETACL3res
, NULL_xdrproc_t
, sizeof (GETACL3res
),
1943 acl3_getacl_free
, RPC_IDEMPOTENT
,
1946 /* ACL3_SETACL = 2 */
1948 xdr_SETACL3args
, NULL_xdrproc_t
, sizeof (SETACL3args
),
1949 xdr_SETACL3res
, NULL_xdrproc_t
, sizeof (SETACL3res
),
1953 /* ACL3_GETXATTRDIR = 3 */
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]),
1964 &aclproccnt_v2_ptr
, acldisptab_v2
},
1965 {sizeof (acldisptab_v3
) / sizeof (acldisptab_v3
[0]),
1967 &aclproccnt_v3_ptr
, acldisptab_v3
},
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
;
1984 adc
= (struct authdes_cred
*)req
->rq_clntcred
;
1985 if (adc
->adc_fullname
.window
> window
)
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.
2003 checkauth(struct exportinfo
*exi
, struct svc_req
*req
, cred_t
*cr
, int anon_ok
,
2006 int i
, nfsflavor
, rpcflavor
, stat
, access
;
2007 struct secinfo
*secp
;
2009 char buf
[INET6_ADDRSTRLEN
]; /* to hold both IPv4 and IPv6 addr */
2013 * Check for privileged port number
2014 * N.B.: this assumes that we know the format of a netbuf.
2017 struct sockaddr
*ca
;
2018 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
2023 if ((ca
->sa_family
== AF_INET
&&
2024 ntohs(((struct sockaddr_in
*)ca
)->sin_port
) >=
2026 (ca
->sa_family
== AF_INET6
&&
2027 ntohs(((struct sockaddr_in6
*)ca
)->sin6_port
) >=
2030 "nfs_server: client %s%ssent NFS request from "
2031 "unprivileged port",
2032 client_name(req
), client_addr(req
, buf
));
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
) {
2048 "nfs_server: couldn't get unix cred for %s",
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.
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
2082 rpcflavor
= AUTH_NONE
;
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!
2102 switch (rpcflavor
) {
2104 anon_res
= crsetugid(cr
, exi
->exi_export
.ex_anon
,
2105 exi
->exi_export
.ex_anon
);
2106 (void) crsetgroups(cr
, 0, NULL
);
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.
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
) {
2132 (void) crsetugid(cr
, secp
->s_rootid
,
2134 (void) crsetgroups(cr
, 0, NULL
);
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.
2147 for (i
= 0; i
< exi
->exi_export
.ex_seccnt
; i
++) {
2148 if (exi
->exi_export
.ex_secinfo
[i
].s_secinfo
.sc_nfsnum
==
2150 secp
= &exi
->exi_export
.ex_secinfo
[i
];
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
),
2163 if (!checkwin(rpcflavor
, secp
->s_window
, req
)) {
2165 "nfs_server: client %s%sused invalid "
2166 "auth window value",
2167 client_name(req
), client_addr(req
, buf
));
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
2176 if (principal
&& sec_svc_inrootlist(rpcflavor
, principal
,
2177 secp
->s_rootcnt
, secp
->s_rootnames
)) {
2178 if (crgetuid(cr
) == 0 && secp
->s_rootid
== 0)
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
);
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
))
2206 anon_res
= crsetugid(cr
, exi
->exi_export
.ex_anon
,
2207 exi
->exi_export
.ex_anon
);
2208 (void) crsetgroups(cr
, 0, NULL
);
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
2219 if (anon_res
!= 0) {
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
: "?");
2230 if (crsetugid(cr
, UID_NOBODY
, GID_NOBODY
) != 0)
2238 * returns 0 on failure, -1 on a drop, -2 on wrong security flavor,
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
;
2254 principal
= cs
->principal
;
2255 nfsflavor
= cs
->nfsflavor
;
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.
2267 struct sockaddr
*ca
;
2268 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
2273 if ((ca
->sa_family
== AF_INET
&&
2274 ntohs(((struct sockaddr_in
*)ca
)->sin_port
) >=
2276 (ca
->sa_family
== AF_INET6
&&
2277 ntohs(((struct sockaddr_in6
*)ca
)->sin6_port
) >=
2280 "nfs_server: client %s%ssent NFSv4 request from "
2281 "unprivileged port",
2282 client_name(req
), client_addr(req
, buf
));
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
) {
2323 anon_res
= crsetugid(cr
, exi
->exi_export
.ex_anon
,
2324 exi
->exi_export
.ex_anon
);
2325 (void) crsetgroups(cr
, 0, NULL
);
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.
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
];
2350 (void) crsetugid(cr
, secp
->s_rootid
,
2352 (void) crsetgroups(cr
, 0, NULL
);
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.
2364 for (i
= 0; i
< exi
->exi_export
.ex_seccnt
; i
++) {
2365 if (exi
->exi_export
.ex_secinfo
[i
].s_secinfo
.sc_nfsnum
==
2367 secp
= &exi
->exi_export
.ex_secinfo
[i
];
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
),
2380 if (!checkwin(rpcflavor
, secp
->s_window
, req
)) {
2382 "nfs_server: client %s%sused invalid "
2383 "auth window value",
2384 client_name(req
), client_addr(req
, buf
));
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)
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
);
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
))
2422 anon_res
= crsetugid(cr
, exi
->exi_export
.ex_anon
,
2423 exi
->exi_export
.ex_anon
);
2424 (void) crsetgroups(cr
, 0, NULL
);
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
2434 if (anon_res
!= 0) {
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
: "?");
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
)
2468 client_addr(struct svc_req
*req
, char *buf
)
2470 struct sockaddr
*ca
;
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
2482 if (req
->rq_cred
.oa_flavor
== AUTH_UNIX
)
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
);
2503 * No IP address to print. If there was a host name
2504 * printed, then we print a space.
2506 (void) sprintf(buf
, frontspace
);
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
2524 error
= nfs_exportinit();
2527 error
= rfs4_srvrinit();
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
);
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.
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.
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
);
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
)
2599 vnode_t
*mc_dvp
= 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)
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
2620 if (pathflag
== SECURITY_QUERY
) {
2621 if ((sec
->sec_index
= (uint_t
)(*p
)) > 0) {
2622 sec
->sec_flags
|= SEC_QUERY
;
2624 if ((pathflag
= MCLpath(&p
)) == -1)
2628 "nfs_server: invalid security index %d, "
2629 "violating WebNFS SNEGO protocol.", sec
->sec_index
);
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
);
2649 ASSERT(*vpp
!= NULL
);
2650 if ((*vpp
)->v_type
== VDIR
) {
2655 * This should not happen, the filesystem is
2656 * in an inconsistent state. Fail the lookup
2673 ASSERT(mc_dvp
!= NULL
);
2674 ASSERT(*vpp
!= NULL
);
2676 if ((*vpp
)->v_type
== VDIR
) {
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
);
2698 if (VOP_REALVP(*vpp
, &realvp
, NULL
) == 0 &&
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.
2716 * Let nfs_vptexi() figure what the real parent is.
2723 * If vnode is covered, get the
2724 * the topmost vnode.
2726 if (vn_mountedvfs(mc_dvp
) != NULL
) {
2727 error
= traverse(&mc_dvp
);
2734 if (VOP_REALVP(mc_dvp
, &realvp
, NULL
) == 0 &&
2737 * *vpp is a file, obtain realvp of the parent
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
)) {
2760 * Not allowed access to pseudo exports.
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 */
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
) {
2791 } else { /* ok or error other than ENOENT */
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 */
2807 if (error
= nfs_check_vpexi(mc_dvp
, *vpp
, kcred
, exi
)) {
2818 if (error
&& *exi
!= NULL
)
2825 * Evaluate a multi-component path
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
];
2841 * If pathname starts with '/', then set startdvp to root.
2844 while (*path
== '/')
2850 error
= pn_get_buf(path
, UIO_SYSSPACE
, &pn
, namebuf
, sizeof (namebuf
));
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)
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
))
2878 if (pn
.pn_pathlen
!= 0 && pathflag
== URLPATH
) {
2879 URLparse(pn
.pn_path
);
2880 if ((pn
.pn_pathlen
= strlen(pn
.pn_path
)) == 0) {
2886 error
= lookuppnvp(&pn
, NULL
, NO_FOLLOW
, dirvpp
, compvpp
,
2887 rootdir
, startdvp
, cr
);
2895 * Adapt the multicomponent lookup path depending on the pathtype
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,
2907 if (c
>= 0x20 && c
<= 0x7E)
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.
2919 case 0x80: /* native path, i.e. MCL via mount protocol */
2921 return (NATIVEPATH
);
2922 case 0x81: /* security query */
2924 return (SECURITY_QUERY
);
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.
2949 *q
= fromhex(*p
) * 16;
2964 * Get the export information for the lookup vnode, and verify its
2967 * Set @exip only in success
2970 nfs_check_vpexi(vnode_t
*mc_dvp
, vnode_t
*vp
, cred_t
*cr
,
2971 struct exportinfo
**exip
)
2975 struct exportinfo
*exi
;
2977 exi
= nfs_vptoexi(mc_dvp
, vp
, cr
, &walk
, NULL
, FALSE
);
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) {
2998 * Do the main work of handling HA-NFSv4 Resource Group failover on
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.
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
3030 dss_path
= rfs4_dss_pathlist
;
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
;
3041 for (i
= 0; i
< rfs4_dss_numnewpaths
; i
++) {
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
);
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 */
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
;
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
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
++) {
3109 char *newpath
= rfs4_dss_newpaths
[i
];
3111 dss_path
= rfs4_dss_pathlist
;
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
;
3121 if (strncmp(path
, newpath
, strlen(path
)) == 0) {
3126 dss_path
= dss_path
->next
;
3127 } while (dss_path
!= rfs4_dss_pathlist
);
3130 added_paths
[numadded_paths
] = newpath
;
3135 /* did we find any added paths? */
3136 if (numadded_paths
> 0) {
3137 /* create a new server instance, and start its grace period */
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.
3164 nfs_getflabel(vnode_t
*vp
, struct exportinfo
*exi
)
3167 ts_label_t
*zone_label
;
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
);
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
;
3183 mutex_exit(&vp
->v_lock
);
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
);
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.
3206 do_rfs_label_check(bslabel_t
*clabel
, vnode_t
*vp
, int flag
,
3207 struct exportinfo
*exi
)
3210 ts_label_t
*tslabel
;
3213 if ((tslabel
= nfs_getflabel(vp
, exi
)) == NULL
) {
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
);
3224 result
= bldominates(clabel
, slabel
);
3225 label_rele(tslabel
);
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.
3235 rfs_free_xuio(void *free_arg
)
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
3249 if (((uio_t
*)nfsuiop
)->uio_extflg
& UIO_XUIO
) {
3250 (void) VOP_RETZCBUF(nfsuiop
->nu_vp
, (xuio_t
*)free_arg
, NULL
,
3252 VN_RELE(nfsuiop
->nu_vp
);
3255 kmem_cache_free(nfs_xuio_cache
, free_arg
);
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
);
3285 uio_to_mblk(uio_t
*uiop
)
3290 nfs_xuio_t
*nfsuiop
= (nfs_xuio_t
*)uiop
;
3292 if (uiop
->uio_iovcnt
== 0)
3295 iovp
= uiop
->uio_iov
;
3296 mp
= mp1
= esballoca((uchar_t
*)iovp
->iov_base
, iovp
->iov_len
,
3297 BPRI_MED
, &nfsuiop
->nu_frtn
);
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
,
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
;
3322 rfs_rndup_mblks(mblk_t
*mp
, uint_t len
, int buf_loaned
)
3328 rndup
= BYTES_PER_XDR_UNIT
- (len
% BYTES_PER_XDR_UNIT
);
3330 /* single mblk_t non copy-reduction case */
3333 if (rndup
!= BYTES_PER_XDR_UNIT
) {
3334 for (i
= 0; i
< rndup
; i
++)
3335 *mp
->b_wptr
++ = '\0';
3340 /* no need for extra rndup */
3341 if (rndup
== BYTES_PER_XDR_UNIT
)
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
;