17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5e810a982Svv149972 * Common Development and Distribution License (the "License").
6e810a982Svv149972 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*cf98b944SMarcel Telka
227c478bd9Sstevel@tonic-gate /*
23*cf98b944SMarcel Telka * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
240a4b0810SKaren Rochford * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD
327c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California.
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate * svc_clts.c
377c478bd9Sstevel@tonic-gate * Server side for RPC in the kernel.
387c478bd9Sstevel@tonic-gate *
397c478bd9Sstevel@tonic-gate */
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include <sys/param.h>
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
447c478bd9Sstevel@tonic-gate #include <sys/file.h>
457c478bd9Sstevel@tonic-gate #include <sys/stream.h>
46920e8367SMarcel Telka #include <sys/strsun.h>
477c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
487c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
497c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
507c478bd9Sstevel@tonic-gate #include <sys/t_kuser.h>
517c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
527c478bd9Sstevel@tonic-gate #include <sys/errno.h>
537c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
547c478bd9Sstevel@tonic-gate #include <sys/systm.h>
557c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
567c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
577c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
587c478bd9Sstevel@tonic-gate #include <sys/debug.h>
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate #include <rpc/types.h>
617c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
627c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
637c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
647c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
657c478bd9Sstevel@tonic-gate #include <rpc/svc.h>
66e810a982Svv149972 #include <inet/ip.h>
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate * Routines exported through ops vector.
707c478bd9Sstevel@tonic-gate */
717c478bd9Sstevel@tonic-gate static bool_t svc_clts_krecv(SVCXPRT *, mblk_t *, struct rpc_msg *);
727c478bd9Sstevel@tonic-gate static bool_t svc_clts_ksend(SVCXPRT *, struct rpc_msg *);
737c478bd9Sstevel@tonic-gate static bool_t svc_clts_kgetargs(SVCXPRT *, xdrproc_t, caddr_t);
747c478bd9Sstevel@tonic-gate static bool_t svc_clts_kfreeargs(SVCXPRT *, xdrproc_t, caddr_t);
757c478bd9Sstevel@tonic-gate static void svc_clts_kdestroy(SVCMASTERXPRT *);
767c478bd9Sstevel@tonic-gate static int svc_clts_kdup(struct svc_req *, caddr_t, int,
777c478bd9Sstevel@tonic-gate struct dupreq **, bool_t *);
787c478bd9Sstevel@tonic-gate static void svc_clts_kdupdone(struct dupreq *, caddr_t,
797c478bd9Sstevel@tonic-gate void (*)(), int, int);
807c478bd9Sstevel@tonic-gate static int32_t *svc_clts_kgetres(SVCXPRT *, int);
817c478bd9Sstevel@tonic-gate static void svc_clts_kclone_destroy(SVCXPRT *);
827c478bd9Sstevel@tonic-gate static void svc_clts_kfreeres(SVCXPRT *);
837c478bd9Sstevel@tonic-gate static void svc_clts_kstart(SVCMASTERXPRT *);
8460536ef9SKaren Rochford static void svc_clts_kclone_xprt(SVCXPRT *, SVCXPRT *);
850a4b0810SKaren Rochford static void svc_clts_ktattrs(SVCXPRT *, int, void **);
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate * Server transport operations vector.
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate struct svc_ops svc_clts_op = {
917c478bd9Sstevel@tonic-gate svc_clts_krecv, /* Get requests */
927c478bd9Sstevel@tonic-gate svc_clts_kgetargs, /* Deserialize arguments */
937c478bd9Sstevel@tonic-gate svc_clts_ksend, /* Send reply */
947c478bd9Sstevel@tonic-gate svc_clts_kfreeargs, /* Free argument data space */
957c478bd9Sstevel@tonic-gate svc_clts_kdestroy, /* Destroy transport handle */
967c478bd9Sstevel@tonic-gate svc_clts_kdup, /* Check entry in dup req cache */
977c478bd9Sstevel@tonic-gate svc_clts_kdupdone, /* Mark entry in dup req cache as done */
987c478bd9Sstevel@tonic-gate svc_clts_kgetres, /* Get pointer to response buffer */
997c478bd9Sstevel@tonic-gate svc_clts_kfreeres, /* Destroy pre-serialized response header */
1007c478bd9Sstevel@tonic-gate svc_clts_kclone_destroy, /* Destroy a clone xprt */
10160536ef9SKaren Rochford svc_clts_kstart, /* Tell `ready-to-receive' to rpcmod */
1020a4b0810SKaren Rochford svc_clts_kclone_xprt, /* transport specific clone xprt function */
1030a4b0810SKaren Rochford svc_clts_ktattrs /* Transport specific attributes. */
1047c478bd9Sstevel@tonic-gate };
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate * Transport private data.
1087c478bd9Sstevel@tonic-gate * Kept in xprt->xp_p2buf.
1097c478bd9Sstevel@tonic-gate */
1107c478bd9Sstevel@tonic-gate struct udp_data {
1117c478bd9Sstevel@tonic-gate mblk_t *ud_resp; /* buffer for response */
1127c478bd9Sstevel@tonic-gate mblk_t *ud_inmp; /* mblk chain of request */
1137c478bd9Sstevel@tonic-gate };
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate #define UD_MAXSIZE 8800
1167c478bd9Sstevel@tonic-gate #define UD_INITSIZE 2048
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate * Connectionless server statistics
1207c478bd9Sstevel@tonic-gate */
1217c478bd9Sstevel@tonic-gate static const struct rpc_clts_server {
1227c478bd9Sstevel@tonic-gate kstat_named_t rscalls;
1237c478bd9Sstevel@tonic-gate kstat_named_t rsbadcalls;
1247c478bd9Sstevel@tonic-gate kstat_named_t rsnullrecv;
1257c478bd9Sstevel@tonic-gate kstat_named_t rsbadlen;
1267c478bd9Sstevel@tonic-gate kstat_named_t rsxdrcall;
1277c478bd9Sstevel@tonic-gate kstat_named_t rsdupchecks;
1287c478bd9Sstevel@tonic-gate kstat_named_t rsdupreqs;
1297c478bd9Sstevel@tonic-gate } clts_rsstat_tmpl = {
1307c478bd9Sstevel@tonic-gate { "calls", KSTAT_DATA_UINT64 },
1317c478bd9Sstevel@tonic-gate { "badcalls", KSTAT_DATA_UINT64 },
1327c478bd9Sstevel@tonic-gate { "nullrecv", KSTAT_DATA_UINT64 },
1337c478bd9Sstevel@tonic-gate { "badlen", KSTAT_DATA_UINT64 },
1347c478bd9Sstevel@tonic-gate { "xdrcall", KSTAT_DATA_UINT64 },
1357c478bd9Sstevel@tonic-gate { "dupchecks", KSTAT_DATA_UINT64 },
1367c478bd9Sstevel@tonic-gate { "dupreqs", KSTAT_DATA_UINT64 }
1377c478bd9Sstevel@tonic-gate };
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate static uint_t clts_rsstat_ndata =
1407c478bd9Sstevel@tonic-gate sizeof (clts_rsstat_tmpl) / sizeof (kstat_named_t);
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate #define CLONE2STATS(clone_xprt) \
1437c478bd9Sstevel@tonic-gate (struct rpc_clts_server *)(clone_xprt)->xp_master->xp_p2
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate #define RSSTAT_INCR(stats, x) \
1461a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&(stats)->x.value.ui64)
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate * Create a transport record.
1507c478bd9Sstevel@tonic-gate * The transport record, output buffer, and private data structure
1517c478bd9Sstevel@tonic-gate * are allocated. The output buffer is serialized into using xdrmem.
1527c478bd9Sstevel@tonic-gate * There is one transport record per user process which implements a
1537c478bd9Sstevel@tonic-gate * set of services.
1547c478bd9Sstevel@tonic-gate */
1557c478bd9Sstevel@tonic-gate /* ARGSUSED */
1567c478bd9Sstevel@tonic-gate int
svc_clts_kcreate(file_t * fp,uint_t sendsz,struct T_info_ack * tinfo,SVCMASTERXPRT ** nxprt)1577c478bd9Sstevel@tonic-gate svc_clts_kcreate(file_t *fp, uint_t sendsz, struct T_info_ack *tinfo,
1587c478bd9Sstevel@tonic-gate SVCMASTERXPRT **nxprt)
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate SVCMASTERXPRT *xprt;
1617c478bd9Sstevel@tonic-gate struct rpcstat *rpcstat;
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate if (nxprt == NULL)
1647c478bd9Sstevel@tonic-gate return (EINVAL);
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate rpcstat = zone_getspecific(rpcstat_zone_key, curproc->p_zone);
1677c478bd9Sstevel@tonic-gate ASSERT(rpcstat != NULL);
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate xprt = kmem_zalloc(sizeof (*xprt), KM_SLEEP);
170e810a982Svv149972 xprt->xp_lcladdr.buf = kmem_zalloc(sizeof (sin6_t), KM_SLEEP);
1717c478bd9Sstevel@tonic-gate xprt->xp_p2 = (caddr_t)rpcstat->rpc_clts_server;
1727c478bd9Sstevel@tonic-gate xprt->xp_ops = &svc_clts_op;
1737c478bd9Sstevel@tonic-gate xprt->xp_msg_size = tinfo->TSDU_size;
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate xprt->xp_rtaddr.buf = NULL;
1767c478bd9Sstevel@tonic-gate xprt->xp_rtaddr.maxlen = tinfo->ADDR_size;
1777c478bd9Sstevel@tonic-gate xprt->xp_rtaddr.len = 0;
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate *nxprt = xprt;
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate return (0);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate * Destroy a transport record.
1867c478bd9Sstevel@tonic-gate * Frees the space allocated for a transport record.
1877c478bd9Sstevel@tonic-gate */
1887c478bd9Sstevel@tonic-gate static void
svc_clts_kdestroy(SVCMASTERXPRT * xprt)1897c478bd9Sstevel@tonic-gate svc_clts_kdestroy(SVCMASTERXPRT *xprt)
1907c478bd9Sstevel@tonic-gate {
1917c478bd9Sstevel@tonic-gate if (xprt->xp_netid)
1927c478bd9Sstevel@tonic-gate kmem_free(xprt->xp_netid, strlen(xprt->xp_netid) + 1);
1937c478bd9Sstevel@tonic-gate if (xprt->xp_addrmask.maxlen)
1947c478bd9Sstevel@tonic-gate kmem_free(xprt->xp_addrmask.buf, xprt->xp_addrmask.maxlen);
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate mutex_destroy(&xprt->xp_req_lock);
1977c478bd9Sstevel@tonic-gate mutex_destroy(&xprt->xp_thread_lock);
1987c478bd9Sstevel@tonic-gate
199e810a982Svv149972 kmem_free(xprt->xp_lcladdr.buf, sizeof (sin6_t));
2007c478bd9Sstevel@tonic-gate kmem_free(xprt, sizeof (SVCMASTERXPRT));
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate * Transport-type specific part of svc_xprt_cleanup().
2057c478bd9Sstevel@tonic-gate * Frees the message buffer space allocated for a clone of a transport record
2067c478bd9Sstevel@tonic-gate */
2077c478bd9Sstevel@tonic-gate static void
svc_clts_kclone_destroy(SVCXPRT * clone_xprt)2087c478bd9Sstevel@tonic-gate svc_clts_kclone_destroy(SVCXPRT *clone_xprt)
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
2117c478bd9Sstevel@tonic-gate struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate if (ud->ud_resp) {
2147c478bd9Sstevel@tonic-gate /*
2157c478bd9Sstevel@tonic-gate * There should not be any left over results buffer.
2167c478bd9Sstevel@tonic-gate */
2177c478bd9Sstevel@tonic-gate ASSERT(ud->ud_resp->b_cont == NULL);
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate * Free the T_UNITDATA_{REQ/IND} that svc_clts_krecv
2217c478bd9Sstevel@tonic-gate * saved.
2227c478bd9Sstevel@tonic-gate */
2237c478bd9Sstevel@tonic-gate freeb(ud->ud_resp);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate if (ud->ud_inmp)
2267c478bd9Sstevel@tonic-gate freemsg(ud->ud_inmp);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate * svc_tli_kcreate() calls this function at the end to tell
2317c478bd9Sstevel@tonic-gate * rpcmod that the transport is ready to receive requests.
2327c478bd9Sstevel@tonic-gate */
2337c478bd9Sstevel@tonic-gate /* ARGSUSED */
2347c478bd9Sstevel@tonic-gate static void
svc_clts_kstart(SVCMASTERXPRT * xprt)2357c478bd9Sstevel@tonic-gate svc_clts_kstart(SVCMASTERXPRT *xprt)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate
23960536ef9SKaren Rochford static void
svc_clts_kclone_xprt(SVCXPRT * src_xprt,SVCXPRT * dst_xprt)24060536ef9SKaren Rochford svc_clts_kclone_xprt(SVCXPRT *src_xprt, SVCXPRT *dst_xprt)
24160536ef9SKaren Rochford {
24260536ef9SKaren Rochford struct udp_data *ud_src =
24360536ef9SKaren Rochford (struct udp_data *)src_xprt->xp_p2buf;
24460536ef9SKaren Rochford struct udp_data *ud_dst =
24560536ef9SKaren Rochford (struct udp_data *)dst_xprt->xp_p2buf;
24660536ef9SKaren Rochford
24760536ef9SKaren Rochford if (ud_src->ud_resp)
24860536ef9SKaren Rochford ud_dst->ud_resp = dupb(ud_src->ud_resp);
24960536ef9SKaren Rochford
25060536ef9SKaren Rochford }
25160536ef9SKaren Rochford
2520a4b0810SKaren Rochford static void
svc_clts_ktattrs(SVCXPRT * clone_xprt,int attrflag,void ** tattr)2530a4b0810SKaren Rochford svc_clts_ktattrs(SVCXPRT *clone_xprt, int attrflag, void **tattr)
2540a4b0810SKaren Rochford {
2550a4b0810SKaren Rochford *tattr = NULL;
2560a4b0810SKaren Rochford
2570a4b0810SKaren Rochford switch (attrflag) {
2580a4b0810SKaren Rochford case SVC_TATTR_ADDRMASK:
2590a4b0810SKaren Rochford *tattr = (void *)&clone_xprt->xp_master->xp_addrmask;
2600a4b0810SKaren Rochford }
2610a4b0810SKaren Rochford }
26260536ef9SKaren Rochford
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate * Receive rpc requests.
2657c478bd9Sstevel@tonic-gate * Pulls a request in off the socket, checks if the packet is intact,
2667c478bd9Sstevel@tonic-gate * and deserializes the call packet.
2677c478bd9Sstevel@tonic-gate */
2687c478bd9Sstevel@tonic-gate static bool_t
svc_clts_krecv(SVCXPRT * clone_xprt,mblk_t * mp,struct rpc_msg * msg)2697c478bd9Sstevel@tonic-gate svc_clts_krecv(SVCXPRT *clone_xprt, mblk_t *mp, struct rpc_msg *msg)
2707c478bd9Sstevel@tonic-gate {
2717c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
2727c478bd9Sstevel@tonic-gate struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
2737c478bd9Sstevel@tonic-gate XDR *xdrs = &clone_xprt->xp_xdrin;
2747c478bd9Sstevel@tonic-gate struct rpc_clts_server *stats = CLONE2STATS(clone_xprt);
2757c478bd9Sstevel@tonic-gate union T_primitives *pptr;
2767c478bd9Sstevel@tonic-gate int hdrsz;
277de8c4a14SErik Nordmark cred_t *cr;
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_SVC_CLTS_KRECV_START,
2807c478bd9Sstevel@tonic-gate "svc_clts_krecv_start:");
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rscalls);
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate * The incoming request should start with an M_PROTO message.
2867c478bd9Sstevel@tonic-gate */
2877c478bd9Sstevel@tonic-gate if (mp->b_datap->db_type != M_PROTO) {
2887c478bd9Sstevel@tonic-gate goto bad;
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate /*
2927c478bd9Sstevel@tonic-gate * The incoming request should be an T_UNITDTA_IND. There
2937c478bd9Sstevel@tonic-gate * might be other messages coming up the stream, but we can
2947c478bd9Sstevel@tonic-gate * ignore them.
2957c478bd9Sstevel@tonic-gate */
2967c478bd9Sstevel@tonic-gate pptr = (union T_primitives *)mp->b_rptr;
2977c478bd9Sstevel@tonic-gate if (pptr->type != T_UNITDATA_IND) {
2987c478bd9Sstevel@tonic-gate goto bad;
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate /*
3017c478bd9Sstevel@tonic-gate * Do some checking to make sure that the header at least looks okay.
3027c478bd9Sstevel@tonic-gate */
3037c478bd9Sstevel@tonic-gate hdrsz = (int)(mp->b_wptr - mp->b_rptr);
3047c478bd9Sstevel@tonic-gate if (hdrsz < TUNITDATAINDSZ ||
3057c478bd9Sstevel@tonic-gate hdrsz < (pptr->unitdata_ind.OPT_offset +
3067c478bd9Sstevel@tonic-gate pptr->unitdata_ind.OPT_length) ||
3077c478bd9Sstevel@tonic-gate hdrsz < (pptr->unitdata_ind.SRC_offset +
3087c478bd9Sstevel@tonic-gate pptr->unitdata_ind.SRC_length)) {
3097c478bd9Sstevel@tonic-gate goto bad;
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate /*
3137c478bd9Sstevel@tonic-gate * Make sure that the transport provided a usable address.
3147c478bd9Sstevel@tonic-gate */
3157c478bd9Sstevel@tonic-gate if (pptr->unitdata_ind.SRC_length <= 0) {
3167c478bd9Sstevel@tonic-gate goto bad;
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate * Point the remote transport address in the service_transport
3207c478bd9Sstevel@tonic-gate * handle at the address in the request.
3217c478bd9Sstevel@tonic-gate */
3227c478bd9Sstevel@tonic-gate clone_xprt->xp_rtaddr.buf = (char *)mp->b_rptr +
3237c478bd9Sstevel@tonic-gate pptr->unitdata_ind.SRC_offset;
3247c478bd9Sstevel@tonic-gate clone_xprt->xp_rtaddr.len = pptr->unitdata_ind.SRC_length;
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate /*
327e810a982Svv149972 * Copy the local transport address in the service_transport
328e810a982Svv149972 * handle at the address in the request. We will have only
329e810a982Svv149972 * the local IP address in options.
330e810a982Svv149972 */
331920e8367SMarcel Telka ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_family = AF_UNSPEC;
332e810a982Svv149972 if (pptr->unitdata_ind.OPT_length && pptr->unitdata_ind.OPT_offset) {
333e810a982Svv149972 char *dstopt = (char *)mp->b_rptr +
334e810a982Svv149972 pptr->unitdata_ind.OPT_offset;
335e810a982Svv149972 struct T_opthdr *toh = (struct T_opthdr *)dstopt;
336e810a982Svv149972
337e810a982Svv149972 if (toh->level == IPPROTO_IPV6 && toh->status == 0 &&
338e810a982Svv149972 toh->name == IPV6_PKTINFO) {
339e810a982Svv149972 struct in6_pktinfo *pkti;
340e810a982Svv149972
341e810a982Svv149972 dstopt += sizeof (struct T_opthdr);
342e810a982Svv149972 pkti = (struct in6_pktinfo *)dstopt;
343e810a982Svv149972 ((sin6_t *)(clone_xprt->xp_lcladdr.buf))->sin6_addr
344e810a982Svv149972 = pkti->ipi6_addr;
345920e8367SMarcel Telka ((sin6_t *)(clone_xprt->xp_lcladdr.buf))->sin6_family
346920e8367SMarcel Telka = AF_INET6;
347e810a982Svv149972 } else if (toh->level == IPPROTO_IP && toh->status == 0 &&
348e810a982Svv149972 toh->name == IP_RECVDSTADDR) {
349e810a982Svv149972 dstopt += sizeof (struct T_opthdr);
350e810a982Svv149972 ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_addr
351e810a982Svv149972 = *(struct in_addr *)dstopt;
352920e8367SMarcel Telka ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_family
353920e8367SMarcel Telka = AF_INET;
354e810a982Svv149972 }
355e810a982Svv149972 }
356e810a982Svv149972
357e810a982Svv149972 /*
3587c478bd9Sstevel@tonic-gate * Save the first mblk which contains the T_unidata_ind in
3597c478bd9Sstevel@tonic-gate * ud_resp. It will be used to generate the T_unitdata_req
3607c478bd9Sstevel@tonic-gate * during the reply.
361de8c4a14SErik Nordmark * We reuse any options in the T_unitdata_ind for the T_unitdata_req
362de8c4a14SErik Nordmark * since we must pass any SCM_UCRED across in order for TX to
363de8c4a14SErik Nordmark * work. We also make sure any cred_t is carried across.
3647c478bd9Sstevel@tonic-gate */
3657c478bd9Sstevel@tonic-gate if (ud->ud_resp) {
3667c478bd9Sstevel@tonic-gate if (ud->ud_resp->b_cont != NULL) {
3677c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "svc_clts_krecv: ud_resp %p, "
3687c478bd9Sstevel@tonic-gate "b_cont %p", (void *)ud->ud_resp,
3697c478bd9Sstevel@tonic-gate (void *)ud->ud_resp->b_cont);
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate freeb(ud->ud_resp);
3727c478bd9Sstevel@tonic-gate }
373de8c4a14SErik Nordmark /* Move any cred_t to the first mblk in the message */
374de8c4a14SErik Nordmark cr = msg_getcred(mp, NULL);
375de8c4a14SErik Nordmark if (cr != NULL)
376de8c4a14SErik Nordmark mblk_setcred(mp, cr, NOPID);
377de8c4a14SErik Nordmark
3787c478bd9Sstevel@tonic-gate ud->ud_resp = mp;
3797c478bd9Sstevel@tonic-gate mp = mp->b_cont;
3807c478bd9Sstevel@tonic-gate ud->ud_resp->b_cont = NULL;
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate xdrmblk_init(xdrs, mp, XDR_DECODE, 0);
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_XDR_CALLMSG_START,
3857c478bd9Sstevel@tonic-gate "xdr_callmsg_start:");
3867c478bd9Sstevel@tonic-gate if (! xdr_callmsg(xdrs, msg)) {
387*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
3887c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
3897c478bd9Sstevel@tonic-gate "xdr_callmsg_end:(%S)", "bad");
3907c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsxdrcall);
3917c478bd9Sstevel@tonic-gate goto bad;
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
3947c478bd9Sstevel@tonic-gate "xdr_callmsg_end:(%S)", "good");
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate clone_xprt->xp_xid = msg->rm_xid;
3977c478bd9Sstevel@tonic-gate ud->ud_inmp = mp;
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KRECV_END,
4007c478bd9Sstevel@tonic-gate "svc_clts_krecv_end:(%S)", "good");
4017c478bd9Sstevel@tonic-gate return (TRUE);
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate bad:
4047c478bd9Sstevel@tonic-gate freemsg(mp);
4057c478bd9Sstevel@tonic-gate if (ud->ud_resp) {
4067c478bd9Sstevel@tonic-gate /*
4077c478bd9Sstevel@tonic-gate * There should not be any left over results buffer.
4087c478bd9Sstevel@tonic-gate */
4097c478bd9Sstevel@tonic-gate ASSERT(ud->ud_resp->b_cont == NULL);
4107c478bd9Sstevel@tonic-gate freeb(ud->ud_resp);
4117c478bd9Sstevel@tonic-gate ud->ud_resp = NULL;
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsbadcalls);
4157c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KRECV_END,
4167c478bd9Sstevel@tonic-gate "svc_clts_krecv_end:(%S)", "bad");
4177c478bd9Sstevel@tonic-gate return (FALSE);
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate /*
4217c478bd9Sstevel@tonic-gate * Send rpc reply.
4227c478bd9Sstevel@tonic-gate * Serialize the reply packet into the output buffer then
4237c478bd9Sstevel@tonic-gate * call t_ksndudata to send it.
4247c478bd9Sstevel@tonic-gate */
4257c478bd9Sstevel@tonic-gate static bool_t
svc_clts_ksend(SVCXPRT * clone_xprt,struct rpc_msg * msg)4267c478bd9Sstevel@tonic-gate svc_clts_ksend(SVCXPRT *clone_xprt, struct rpc_msg *msg)
4277c478bd9Sstevel@tonic-gate {
4287c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
4297c478bd9Sstevel@tonic-gate struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
4307c478bd9Sstevel@tonic-gate XDR *xdrs = &clone_xprt->xp_xdrout;
4317c478bd9Sstevel@tonic-gate int stat = FALSE;
4327c478bd9Sstevel@tonic-gate mblk_t *mp;
4337c478bd9Sstevel@tonic-gate int msgsz;
4347c478bd9Sstevel@tonic-gate struct T_unitdata_req *udreq;
4357c478bd9Sstevel@tonic-gate xdrproc_t xdr_results;
4367c478bd9Sstevel@tonic-gate caddr_t xdr_location;
4377c478bd9Sstevel@tonic-gate bool_t has_args;
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_SVC_CLTS_KSEND_START,
4407c478bd9Sstevel@tonic-gate "svc_clts_ksend_start:");
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate ASSERT(ud->ud_resp != NULL);
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate /*
4457c478bd9Sstevel@tonic-gate * If there is a result procedure specified in the reply message,
4467c478bd9Sstevel@tonic-gate * it will be processed in the xdr_replymsg and SVCAUTH_WRAP.
4477c478bd9Sstevel@tonic-gate * We need to make sure it won't be processed twice, so we null
4487c478bd9Sstevel@tonic-gate * it for xdr_replymsg here.
4497c478bd9Sstevel@tonic-gate */
4507c478bd9Sstevel@tonic-gate has_args = FALSE;
4517c478bd9Sstevel@tonic-gate if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
4527c478bd9Sstevel@tonic-gate msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
4537c478bd9Sstevel@tonic-gate if ((xdr_results = msg->acpted_rply.ar_results.proc) != NULL) {
4547c478bd9Sstevel@tonic-gate has_args = TRUE;
4557c478bd9Sstevel@tonic-gate xdr_location = msg->acpted_rply.ar_results.where;
4567c478bd9Sstevel@tonic-gate msg->acpted_rply.ar_results.proc = xdr_void;
4577c478bd9Sstevel@tonic-gate msg->acpted_rply.ar_results.where = NULL;
4587c478bd9Sstevel@tonic-gate }
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate if (ud->ud_resp->b_cont == NULL) {
4627c478bd9Sstevel@tonic-gate /*
4637c478bd9Sstevel@tonic-gate * Allocate an initial mblk for the response data.
4647c478bd9Sstevel@tonic-gate */
4657c478bd9Sstevel@tonic-gate while ((mp = allocb(UD_INITSIZE, BPRI_LO)) == NULL) {
4667c478bd9Sstevel@tonic-gate if (strwaitbuf(UD_INITSIZE, BPRI_LO)) {
4677c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KSEND_END,
4687c478bd9Sstevel@tonic-gate "svc_clts_ksend_end:(%S)", "strwaitbuf");
4697c478bd9Sstevel@tonic-gate return (FALSE);
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate /*
474*cf98b944SMarcel Telka * Initialize the XDR encode stream. Additional mblks
4757c478bd9Sstevel@tonic-gate * will be allocated if necessary. They will be UD_MAXSIZE
4767c478bd9Sstevel@tonic-gate * sized.
4777c478bd9Sstevel@tonic-gate */
4787c478bd9Sstevel@tonic-gate xdrmblk_init(xdrs, mp, XDR_ENCODE, UD_MAXSIZE);
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate /*
4817c478bd9Sstevel@tonic-gate * Leave some space for protocol headers.
4827c478bd9Sstevel@tonic-gate */
4837c478bd9Sstevel@tonic-gate (void) XDR_SETPOS(xdrs, 512);
4847c478bd9Sstevel@tonic-gate mp->b_rptr += 512;
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate msg->rm_xid = clone_xprt->xp_xid;
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate ud->ud_resp->b_cont = mp;
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_XDR_REPLYMSG_START,
4917c478bd9Sstevel@tonic-gate "xdr_replymsg_start:");
4927c478bd9Sstevel@tonic-gate if (!(xdr_replymsg(xdrs, msg) &&
4937c478bd9Sstevel@tonic-gate (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
4947c478bd9Sstevel@tonic-gate xdr_results, xdr_location)))) {
495*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
4967c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
4977c478bd9Sstevel@tonic-gate "xdr_replymsg_end:(%S)", "bad");
4987c478bd9Sstevel@tonic-gate RPCLOG0(1, "xdr_replymsg/SVCAUTH_WRAP failed\n");
4997c478bd9Sstevel@tonic-gate goto out;
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
5027c478bd9Sstevel@tonic-gate "xdr_replymsg_end:(%S)", "good");
5037c478bd9Sstevel@tonic-gate
5047c478bd9Sstevel@tonic-gate } else if (!(xdr_replymsg_body(xdrs, msg) &&
5057c478bd9Sstevel@tonic-gate (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
5067c478bd9Sstevel@tonic-gate xdr_results, xdr_location)))) {
507*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
5087c478bd9Sstevel@tonic-gate RPCLOG0(1, "xdr_replymsg_body/SVCAUTH_WRAP failed\n");
5097c478bd9Sstevel@tonic-gate goto out;
5107c478bd9Sstevel@tonic-gate }
5117c478bd9Sstevel@tonic-gate
512*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
513*cf98b944SMarcel Telka
5147c478bd9Sstevel@tonic-gate msgsz = (int)xmsgsize(ud->ud_resp->b_cont);
5157c478bd9Sstevel@tonic-gate
5167c478bd9Sstevel@tonic-gate if (msgsz <= 0 || (clone_xprt->xp_msg_size != -1 &&
5177c478bd9Sstevel@tonic-gate msgsz > clone_xprt->xp_msg_size)) {
5187c478bd9Sstevel@tonic-gate #ifdef DEBUG
5197c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
5207c478bd9Sstevel@tonic-gate "KRPC: server response message of %d bytes; transport limits are [0, %d]",
5217c478bd9Sstevel@tonic-gate msgsz, clone_xprt->xp_msg_size);
5227c478bd9Sstevel@tonic-gate #endif
5237c478bd9Sstevel@tonic-gate goto out;
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate /*
527920e8367SMarcel Telka * Construct the T_unitdata_req. We take advantage of the fact that
528920e8367SMarcel Telka * T_unitdata_ind looks just like T_unitdata_req, except for the
529920e8367SMarcel Telka * primitive type. Reusing it means we preserve the SCM_UCRED, and
530920e8367SMarcel Telka * we must preserve it for TX to work.
531920e8367SMarcel Telka *
532920e8367SMarcel Telka * This has the side effect that we can also pass certain receive-side
533920e8367SMarcel Telka * options like IPV6_PKTINFO back down the send side. This implies
534920e8367SMarcel Telka * that we can not ASSERT on a non-NULL db_credp when we have send-side
535920e8367SMarcel Telka * options in UDP.
5367c478bd9Sstevel@tonic-gate */
537920e8367SMarcel Telka ASSERT(MBLKL(ud->ud_resp) >= TUNITDATAREQSZ);
5387c478bd9Sstevel@tonic-gate udreq = (struct T_unitdata_req *)ud->ud_resp->b_rptr;
539920e8367SMarcel Telka ASSERT(udreq->PRIM_type == T_UNITDATA_IND);
5407c478bd9Sstevel@tonic-gate udreq->PRIM_type = T_UNITDATA_REQ;
541920e8367SMarcel Telka
542920e8367SMarcel Telka /*
543920e8367SMarcel Telka * If the local IPv4 transport address is known use it as a source
544920e8367SMarcel Telka * address for the outgoing UDP packet.
545920e8367SMarcel Telka */
546920e8367SMarcel Telka if (((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_family == AF_INET) {
547920e8367SMarcel Telka struct T_opthdr *opthdr;
548920e8367SMarcel Telka in_pktinfo_t *pktinfo;
549920e8367SMarcel Telka size_t size;
550920e8367SMarcel Telka
551920e8367SMarcel Telka if (udreq->DEST_length == 0)
552920e8367SMarcel Telka udreq->OPT_offset = _TPI_ALIGN_TOPT(TUNITDATAREQSZ);
553920e8367SMarcel Telka else
554920e8367SMarcel Telka udreq->OPT_offset = _TPI_ALIGN_TOPT(udreq->DEST_offset +
555920e8367SMarcel Telka udreq->DEST_length);
556920e8367SMarcel Telka
557920e8367SMarcel Telka udreq->OPT_length = sizeof (struct T_opthdr) +
558920e8367SMarcel Telka sizeof (in_pktinfo_t);
559920e8367SMarcel Telka
560920e8367SMarcel Telka size = udreq->OPT_length + udreq->OPT_offset;
561920e8367SMarcel Telka
562920e8367SMarcel Telka /* make sure we have enough space for the option data */
563920e8367SMarcel Telka mp = reallocb(ud->ud_resp, size, 1);
564920e8367SMarcel Telka if (mp == NULL)
565920e8367SMarcel Telka goto out;
566920e8367SMarcel Telka ud->ud_resp = mp;
567920e8367SMarcel Telka udreq = (struct T_unitdata_req *)mp->b_rptr;
568920e8367SMarcel Telka
569920e8367SMarcel Telka /* set desired option header */
570920e8367SMarcel Telka opthdr = (struct T_opthdr *)(mp->b_rptr + udreq->OPT_offset);
571920e8367SMarcel Telka opthdr->len = udreq->OPT_length;
572920e8367SMarcel Telka opthdr->level = IPPROTO_IP;
573920e8367SMarcel Telka opthdr->name = IP_PKTINFO;
574920e8367SMarcel Telka
575920e8367SMarcel Telka /*
576920e8367SMarcel Telka * 1. set source IP of outbound packet
577920e8367SMarcel Telka * 2. value '0' for index means IP layer uses this as source
578920e8367SMarcel Telka * address
579920e8367SMarcel Telka */
580920e8367SMarcel Telka pktinfo = (in_pktinfo_t *)(opthdr + 1);
581920e8367SMarcel Telka (void) memset(pktinfo, 0, sizeof (in_pktinfo_t));
582920e8367SMarcel Telka pktinfo->ipi_spec_dst.s_addr =
583920e8367SMarcel Telka ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_addr.s_addr;
584920e8367SMarcel Telka pktinfo->ipi_ifindex = 0;
585920e8367SMarcel Telka
586920e8367SMarcel Telka /* adjust the end of active data */
587920e8367SMarcel Telka mp->b_wptr = mp->b_rptr + size;
588920e8367SMarcel Telka }
589920e8367SMarcel Telka
5907c478bd9Sstevel@tonic-gate put(clone_xprt->xp_wq, ud->ud_resp);
5917c478bd9Sstevel@tonic-gate stat = TRUE;
5927c478bd9Sstevel@tonic-gate ud->ud_resp = NULL;
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate out:
5957c478bd9Sstevel@tonic-gate if (stat == FALSE) {
5967c478bd9Sstevel@tonic-gate freemsg(ud->ud_resp);
5977c478bd9Sstevel@tonic-gate ud->ud_resp = NULL;
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate * This is completely disgusting. If public is set it is
6027c478bd9Sstevel@tonic-gate * a pointer to a structure whose first field is the address
6037c478bd9Sstevel@tonic-gate * of the function to free that structure and any related
6047c478bd9Sstevel@tonic-gate * stuff. (see rrokfree in nfs_xdr.c).
6057c478bd9Sstevel@tonic-gate */
6067c478bd9Sstevel@tonic-gate if (xdrs->x_public) {
6077c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
6087c478bd9Sstevel@tonic-gate (**((int (**)())xdrs->x_public))(xdrs->x_public);
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KSEND_END,
6127c478bd9Sstevel@tonic-gate "svc_clts_ksend_end:(%S)", "done");
6137c478bd9Sstevel@tonic-gate return (stat);
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate /*
6177c478bd9Sstevel@tonic-gate * Deserialize arguments.
6187c478bd9Sstevel@tonic-gate */
6197c478bd9Sstevel@tonic-gate static bool_t
svc_clts_kgetargs(SVCXPRT * clone_xprt,xdrproc_t xdr_args,caddr_t args_ptr)6207c478bd9Sstevel@tonic-gate svc_clts_kgetargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
6217c478bd9Sstevel@tonic-gate caddr_t args_ptr)
6227c478bd9Sstevel@tonic-gate {
6237c478bd9Sstevel@tonic-gate
6247c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
6257c478bd9Sstevel@tonic-gate return (SVCAUTH_UNWRAP(&clone_xprt->xp_auth, &clone_xprt->xp_xdrin,
6267c478bd9Sstevel@tonic-gate xdr_args, args_ptr));
6277c478bd9Sstevel@tonic-gate
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate static bool_t
svc_clts_kfreeargs(SVCXPRT * clone_xprt,xdrproc_t xdr_args,caddr_t args_ptr)6317c478bd9Sstevel@tonic-gate svc_clts_kfreeargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
6327c478bd9Sstevel@tonic-gate caddr_t args_ptr)
6337c478bd9Sstevel@tonic-gate {
6347c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
6357c478bd9Sstevel@tonic-gate struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
6367c478bd9Sstevel@tonic-gate XDR *xdrs = &clone_xprt->xp_xdrin;
6377c478bd9Sstevel@tonic-gate bool_t retval;
6387c478bd9Sstevel@tonic-gate
6397c478bd9Sstevel@tonic-gate if (args_ptr) {
6407c478bd9Sstevel@tonic-gate xdrs->x_op = XDR_FREE;
6417c478bd9Sstevel@tonic-gate retval = (*xdr_args)(xdrs, args_ptr);
6427c478bd9Sstevel@tonic-gate } else
6437c478bd9Sstevel@tonic-gate retval = TRUE;
6447c478bd9Sstevel@tonic-gate
645*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
646*cf98b944SMarcel Telka
6477c478bd9Sstevel@tonic-gate if (ud->ud_inmp) {
6487c478bd9Sstevel@tonic-gate freemsg(ud->ud_inmp);
6497c478bd9Sstevel@tonic-gate ud->ud_inmp = NULL;
6507c478bd9Sstevel@tonic-gate }
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate return (retval);
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate static int32_t *
svc_clts_kgetres(SVCXPRT * clone_xprt,int size)6567c478bd9Sstevel@tonic-gate svc_clts_kgetres(SVCXPRT *clone_xprt, int size)
6577c478bd9Sstevel@tonic-gate {
6587c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
6597c478bd9Sstevel@tonic-gate struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
6607c478bd9Sstevel@tonic-gate XDR *xdrs = &clone_xprt->xp_xdrout;
6617c478bd9Sstevel@tonic-gate mblk_t *mp;
6627c478bd9Sstevel@tonic-gate int32_t *buf;
6637c478bd9Sstevel@tonic-gate struct rpc_msg rply;
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate /*
6667c478bd9Sstevel@tonic-gate * Allocate an initial mblk for the response data.
6677c478bd9Sstevel@tonic-gate */
6687c478bd9Sstevel@tonic-gate while ((mp = allocb(UD_INITSIZE, BPRI_LO)) == NULL) {
6697c478bd9Sstevel@tonic-gate if (strwaitbuf(UD_INITSIZE, BPRI_LO)) {
670*cf98b944SMarcel Telka return (NULL);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate }
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate /*
677*cf98b944SMarcel Telka * Initialize the XDR encode stream. Additional mblks
6787c478bd9Sstevel@tonic-gate * will be allocated if necessary. They will be UD_MAXSIZE
6797c478bd9Sstevel@tonic-gate * sized.
6807c478bd9Sstevel@tonic-gate */
6817c478bd9Sstevel@tonic-gate xdrmblk_init(xdrs, mp, XDR_ENCODE, UD_MAXSIZE);
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate /*
6847c478bd9Sstevel@tonic-gate * Leave some space for protocol headers.
6857c478bd9Sstevel@tonic-gate */
6867c478bd9Sstevel@tonic-gate (void) XDR_SETPOS(xdrs, 512);
6877c478bd9Sstevel@tonic-gate mp->b_rptr += 512;
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate /*
6907c478bd9Sstevel@tonic-gate * Assume a successful RPC since most of them are.
6917c478bd9Sstevel@tonic-gate */
6927c478bd9Sstevel@tonic-gate rply.rm_xid = clone_xprt->xp_xid;
6937c478bd9Sstevel@tonic-gate rply.rm_direction = REPLY;
6947c478bd9Sstevel@tonic-gate rply.rm_reply.rp_stat = MSG_ACCEPTED;
6957c478bd9Sstevel@tonic-gate rply.acpted_rply.ar_verf = clone_xprt->xp_verf;
6967c478bd9Sstevel@tonic-gate rply.acpted_rply.ar_stat = SUCCESS;
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate if (!xdr_replymsg_hdr(xdrs, &rply)) {
699*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
7007c478bd9Sstevel@tonic-gate freeb(mp);
7017c478bd9Sstevel@tonic-gate return (NULL);
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, size);
7057c478bd9Sstevel@tonic-gate
706*cf98b944SMarcel Telka if (buf == NULL) {
707*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
7087c478bd9Sstevel@tonic-gate freeb(mp);
709*cf98b944SMarcel Telka } else {
7107c478bd9Sstevel@tonic-gate ud->ud_resp->b_cont = mp;
711*cf98b944SMarcel Telka }
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate return (buf);
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate static void
svc_clts_kfreeres(SVCXPRT * clone_xprt)7177c478bd9Sstevel@tonic-gate svc_clts_kfreeres(SVCXPRT *clone_xprt)
7187c478bd9Sstevel@tonic-gate {
7197c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
7207c478bd9Sstevel@tonic-gate struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate if (ud->ud_resp == NULL || ud->ud_resp->b_cont == NULL)
7237c478bd9Sstevel@tonic-gate return;
7247c478bd9Sstevel@tonic-gate
725*cf98b944SMarcel Telka XDR_DESTROY(&clone_xprt->xp_xdrout);
726*cf98b944SMarcel Telka
7277c478bd9Sstevel@tonic-gate /*
7287c478bd9Sstevel@tonic-gate * SVC_FREERES() is called whenever the server decides not to
7297c478bd9Sstevel@tonic-gate * send normal reply. Thus, we expect only one mblk to be allocated,
7307c478bd9Sstevel@tonic-gate * because we have not attempted any XDR encoding.
7317c478bd9Sstevel@tonic-gate * If we do any XDR encoding and we get an error, then SVC_REPLY()
7327c478bd9Sstevel@tonic-gate * will freemsg(ud->ud_resp);
7337c478bd9Sstevel@tonic-gate */
7347c478bd9Sstevel@tonic-gate ASSERT(ud->ud_resp->b_cont->b_cont == NULL);
7357c478bd9Sstevel@tonic-gate freeb(ud->ud_resp->b_cont);
7367c478bd9Sstevel@tonic-gate ud->ud_resp->b_cont = NULL;
7377c478bd9Sstevel@tonic-gate }
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate /*
7407c478bd9Sstevel@tonic-gate * the dup cacheing routines below provide a cache of non-failure
7417c478bd9Sstevel@tonic-gate * transaction id's. rpc service routines can use this to detect
7427c478bd9Sstevel@tonic-gate * retransmissions and re-send a non-failure response.
7437c478bd9Sstevel@tonic-gate */
7447c478bd9Sstevel@tonic-gate
7457c478bd9Sstevel@tonic-gate /*
7467c478bd9Sstevel@tonic-gate * MAXDUPREQS is the number of cached items. It should be adjusted
7477c478bd9Sstevel@tonic-gate * to the service load so that there is likely to be a response entry
7487c478bd9Sstevel@tonic-gate * when the first retransmission comes in.
7497c478bd9Sstevel@tonic-gate */
7507c478bd9Sstevel@tonic-gate #define MAXDUPREQS 1024
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate /*
7537c478bd9Sstevel@tonic-gate * This should be appropriately scaled to MAXDUPREQS.
7547c478bd9Sstevel@tonic-gate */
7557c478bd9Sstevel@tonic-gate #define DRHASHSZ 257
7567c478bd9Sstevel@tonic-gate
7577c478bd9Sstevel@tonic-gate #if ((DRHASHSZ & (DRHASHSZ - 1)) == 0)
7587c478bd9Sstevel@tonic-gate #define XIDHASH(xid) ((xid) & (DRHASHSZ - 1))
7597c478bd9Sstevel@tonic-gate #else
7607c478bd9Sstevel@tonic-gate #define XIDHASH(xid) ((xid) % DRHASHSZ)
7617c478bd9Sstevel@tonic-gate #endif
7627c478bd9Sstevel@tonic-gate #define DRHASH(dr) XIDHASH((dr)->dr_xid)
7637c478bd9Sstevel@tonic-gate #define REQTOXID(req) ((req)->rq_xprt->xp_xid)
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate static int ndupreqs = 0;
76659418bdeSgt29601@anthrax int maxdupreqs = MAXDUPREQS;
7677c478bd9Sstevel@tonic-gate static kmutex_t dupreq_lock;
7687c478bd9Sstevel@tonic-gate static struct dupreq *drhashtbl[DRHASHSZ];
7697c478bd9Sstevel@tonic-gate static int drhashstat[DRHASHSZ];
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate static void unhash(struct dupreq *);
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate /*
7747c478bd9Sstevel@tonic-gate * drmru points to the head of a circular linked list in lru order.
7757c478bd9Sstevel@tonic-gate * drmru->dr_next == drlru
7767c478bd9Sstevel@tonic-gate */
7777c478bd9Sstevel@tonic-gate struct dupreq *drmru;
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate /*
7807c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface
7817c478bd9Sstevel@tonic-gate * svc_clts_kdup
7827c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing
7837c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com
7847c478bd9Sstevel@tonic-gate *
7857c478bd9Sstevel@tonic-gate * svc_clts_kdup searches the request cache and returns 0 if the
7867c478bd9Sstevel@tonic-gate * request is not found in the cache. If it is found, then it
7877c478bd9Sstevel@tonic-gate * returns the state of the request (in progress or done) and
7887c478bd9Sstevel@tonic-gate * the status or attributes that were part of the original reply.
7897c478bd9Sstevel@tonic-gate *
7907c478bd9Sstevel@tonic-gate * If DUP_DONE (there is a duplicate) svc_clts_kdup copies over the
7917c478bd9Sstevel@tonic-gate * value of the response. In that case, also return in *dupcachedp
7927c478bd9Sstevel@tonic-gate * whether the response free routine is cached in the dupreq - in which case
7937c478bd9Sstevel@tonic-gate * the caller should not be freeing it, because it will be done later
7947c478bd9Sstevel@tonic-gate * in the svc_clts_kdup code when the dupreq is reused.
7957c478bd9Sstevel@tonic-gate */
7967c478bd9Sstevel@tonic-gate static int
svc_clts_kdup(struct svc_req * req,caddr_t res,int size,struct dupreq ** drpp,bool_t * dupcachedp)7977c478bd9Sstevel@tonic-gate svc_clts_kdup(struct svc_req *req, caddr_t res, int size, struct dupreq **drpp,
7987c478bd9Sstevel@tonic-gate bool_t *dupcachedp)
7997c478bd9Sstevel@tonic-gate {
8007c478bd9Sstevel@tonic-gate struct rpc_clts_server *stats = CLONE2STATS(req->rq_xprt);
8017c478bd9Sstevel@tonic-gate struct dupreq *dr;
8027c478bd9Sstevel@tonic-gate uint32_t xid;
8037c478bd9Sstevel@tonic-gate uint32_t drhash;
8047c478bd9Sstevel@tonic-gate int status;
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate xid = REQTOXID(req);
8077c478bd9Sstevel@tonic-gate mutex_enter(&dupreq_lock);
8087c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsdupchecks);
8097c478bd9Sstevel@tonic-gate /*
8107c478bd9Sstevel@tonic-gate * Check to see whether an entry already exists in the cache.
8117c478bd9Sstevel@tonic-gate */
8127c478bd9Sstevel@tonic-gate dr = drhashtbl[XIDHASH(xid)];
8137c478bd9Sstevel@tonic-gate while (dr != NULL) {
8147c478bd9Sstevel@tonic-gate if (dr->dr_xid == xid &&
8157c478bd9Sstevel@tonic-gate dr->dr_proc == req->rq_proc &&
8167c478bd9Sstevel@tonic-gate dr->dr_prog == req->rq_prog &&
8177c478bd9Sstevel@tonic-gate dr->dr_vers == req->rq_vers &&
8187c478bd9Sstevel@tonic-gate dr->dr_addr.len == req->rq_xprt->xp_rtaddr.len &&
8197c478bd9Sstevel@tonic-gate bcmp(dr->dr_addr.buf, req->rq_xprt->xp_rtaddr.buf,
8207c478bd9Sstevel@tonic-gate dr->dr_addr.len) == 0) {
8217c478bd9Sstevel@tonic-gate status = dr->dr_status;
8227c478bd9Sstevel@tonic-gate if (status == DUP_DONE) {
8237c478bd9Sstevel@tonic-gate bcopy(dr->dr_resp.buf, res, size);
8247c478bd9Sstevel@tonic-gate if (dupcachedp != NULL)
8257c478bd9Sstevel@tonic-gate *dupcachedp = (dr->dr_resfree != NULL);
8267c478bd9Sstevel@tonic-gate } else {
8277c478bd9Sstevel@tonic-gate dr->dr_status = DUP_INPROGRESS;
8287c478bd9Sstevel@tonic-gate *drpp = dr;
8297c478bd9Sstevel@tonic-gate }
8307c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsdupreqs);
8317c478bd9Sstevel@tonic-gate mutex_exit(&dupreq_lock);
8327c478bd9Sstevel@tonic-gate return (status);
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate dr = dr->dr_chain;
8357c478bd9Sstevel@tonic-gate }
8367c478bd9Sstevel@tonic-gate
8377c478bd9Sstevel@tonic-gate /*
8387c478bd9Sstevel@tonic-gate * There wasn't an entry, either allocate a new one or recycle
8397c478bd9Sstevel@tonic-gate * an old one.
8407c478bd9Sstevel@tonic-gate */
8417c478bd9Sstevel@tonic-gate if (ndupreqs < maxdupreqs) {
8427c478bd9Sstevel@tonic-gate dr = kmem_alloc(sizeof (*dr), KM_NOSLEEP);
8437c478bd9Sstevel@tonic-gate if (dr == NULL) {
8447c478bd9Sstevel@tonic-gate mutex_exit(&dupreq_lock);
8457c478bd9Sstevel@tonic-gate return (DUP_ERROR);
8467c478bd9Sstevel@tonic-gate }
8477c478bd9Sstevel@tonic-gate dr->dr_resp.buf = NULL;
8487c478bd9Sstevel@tonic-gate dr->dr_resp.maxlen = 0;
8497c478bd9Sstevel@tonic-gate dr->dr_addr.buf = NULL;
8507c478bd9Sstevel@tonic-gate dr->dr_addr.maxlen = 0;
8517c478bd9Sstevel@tonic-gate if (drmru) {
8527c478bd9Sstevel@tonic-gate dr->dr_next = drmru->dr_next;
8537c478bd9Sstevel@tonic-gate drmru->dr_next = dr;
8547c478bd9Sstevel@tonic-gate } else {
8557c478bd9Sstevel@tonic-gate dr->dr_next = dr;
8567c478bd9Sstevel@tonic-gate }
8577c478bd9Sstevel@tonic-gate ndupreqs++;
8587c478bd9Sstevel@tonic-gate } else {
8597c478bd9Sstevel@tonic-gate dr = drmru->dr_next;
8607c478bd9Sstevel@tonic-gate while (dr->dr_status == DUP_INPROGRESS) {
8617c478bd9Sstevel@tonic-gate dr = dr->dr_next;
8627c478bd9Sstevel@tonic-gate if (dr == drmru->dr_next) {
8637c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "svc_clts_kdup no slots free");
8647c478bd9Sstevel@tonic-gate mutex_exit(&dupreq_lock);
8657c478bd9Sstevel@tonic-gate return (DUP_ERROR);
8667c478bd9Sstevel@tonic-gate }
8677c478bd9Sstevel@tonic-gate }
8687c478bd9Sstevel@tonic-gate unhash(dr);
8697c478bd9Sstevel@tonic-gate if (dr->dr_resfree) {
8707c478bd9Sstevel@tonic-gate (*dr->dr_resfree)(dr->dr_resp.buf);
8717c478bd9Sstevel@tonic-gate }
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate dr->dr_resfree = NULL;
8747c478bd9Sstevel@tonic-gate drmru = dr;
8757c478bd9Sstevel@tonic-gate
8767c478bd9Sstevel@tonic-gate dr->dr_xid = REQTOXID(req);
8777c478bd9Sstevel@tonic-gate dr->dr_prog = req->rq_prog;
8787c478bd9Sstevel@tonic-gate dr->dr_vers = req->rq_vers;
8797c478bd9Sstevel@tonic-gate dr->dr_proc = req->rq_proc;
8807c478bd9Sstevel@tonic-gate if (dr->dr_addr.maxlen < req->rq_xprt->xp_rtaddr.len) {
8817c478bd9Sstevel@tonic-gate if (dr->dr_addr.buf != NULL)
8827c478bd9Sstevel@tonic-gate kmem_free(dr->dr_addr.buf, dr->dr_addr.maxlen);
8837c478bd9Sstevel@tonic-gate dr->dr_addr.maxlen = req->rq_xprt->xp_rtaddr.len;
8847c478bd9Sstevel@tonic-gate dr->dr_addr.buf = kmem_alloc(dr->dr_addr.maxlen,
8857c478bd9Sstevel@tonic-gate KM_NOSLEEP);
8867c478bd9Sstevel@tonic-gate if (dr->dr_addr.buf == NULL) {
8877c478bd9Sstevel@tonic-gate dr->dr_addr.maxlen = 0;
8887c478bd9Sstevel@tonic-gate dr->dr_status = DUP_DROP;
8897c478bd9Sstevel@tonic-gate mutex_exit(&dupreq_lock);
8907c478bd9Sstevel@tonic-gate return (DUP_ERROR);
8917c478bd9Sstevel@tonic-gate }
8927c478bd9Sstevel@tonic-gate }
8937c478bd9Sstevel@tonic-gate dr->dr_addr.len = req->rq_xprt->xp_rtaddr.len;
8947c478bd9Sstevel@tonic-gate bcopy(req->rq_xprt->xp_rtaddr.buf, dr->dr_addr.buf, dr->dr_addr.len);
8957c478bd9Sstevel@tonic-gate if (dr->dr_resp.maxlen < size) {
8967c478bd9Sstevel@tonic-gate if (dr->dr_resp.buf != NULL)
8977c478bd9Sstevel@tonic-gate kmem_free(dr->dr_resp.buf, dr->dr_resp.maxlen);
8987c478bd9Sstevel@tonic-gate dr->dr_resp.maxlen = (unsigned int)size;
8997c478bd9Sstevel@tonic-gate dr->dr_resp.buf = kmem_alloc(size, KM_NOSLEEP);
9007c478bd9Sstevel@tonic-gate if (dr->dr_resp.buf == NULL) {
9017c478bd9Sstevel@tonic-gate dr->dr_resp.maxlen = 0;
9027c478bd9Sstevel@tonic-gate dr->dr_status = DUP_DROP;
9037c478bd9Sstevel@tonic-gate mutex_exit(&dupreq_lock);
9047c478bd9Sstevel@tonic-gate return (DUP_ERROR);
9057c478bd9Sstevel@tonic-gate }
9067c478bd9Sstevel@tonic-gate }
9077c478bd9Sstevel@tonic-gate dr->dr_status = DUP_INPROGRESS;
9087c478bd9Sstevel@tonic-gate
9097c478bd9Sstevel@tonic-gate drhash = (uint32_t)DRHASH(dr);
9107c478bd9Sstevel@tonic-gate dr->dr_chain = drhashtbl[drhash];
9117c478bd9Sstevel@tonic-gate drhashtbl[drhash] = dr;
9127c478bd9Sstevel@tonic-gate drhashstat[drhash]++;
9137c478bd9Sstevel@tonic-gate mutex_exit(&dupreq_lock);
9147c478bd9Sstevel@tonic-gate *drpp = dr;
9157c478bd9Sstevel@tonic-gate return (DUP_NEW);
9167c478bd9Sstevel@tonic-gate }
9177c478bd9Sstevel@tonic-gate
9187c478bd9Sstevel@tonic-gate /*
9197c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface
9207c478bd9Sstevel@tonic-gate * svc_clts_kdupdone
9217c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing
9227c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com
9237c478bd9Sstevel@tonic-gate *
9247c478bd9Sstevel@tonic-gate * svc_clts_kdupdone marks the request done (DUP_DONE or DUP_DROP)
9257c478bd9Sstevel@tonic-gate * and stores the response.
9267c478bd9Sstevel@tonic-gate */
9277c478bd9Sstevel@tonic-gate static void
svc_clts_kdupdone(struct dupreq * dr,caddr_t res,void (* dis_resfree)(),int size,int status)9287c478bd9Sstevel@tonic-gate svc_clts_kdupdone(struct dupreq *dr, caddr_t res, void (*dis_resfree)(),
9297c478bd9Sstevel@tonic-gate int size, int status)
9307c478bd9Sstevel@tonic-gate {
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate ASSERT(dr->dr_resfree == NULL);
9337c478bd9Sstevel@tonic-gate if (status == DUP_DONE) {
9347c478bd9Sstevel@tonic-gate bcopy(res, dr->dr_resp.buf, size);
9357c478bd9Sstevel@tonic-gate dr->dr_resfree = dis_resfree;
9367c478bd9Sstevel@tonic-gate }
9377c478bd9Sstevel@tonic-gate dr->dr_status = status;
9387c478bd9Sstevel@tonic-gate }
9397c478bd9Sstevel@tonic-gate
9407c478bd9Sstevel@tonic-gate /*
9417c478bd9Sstevel@tonic-gate * This routine expects that the mutex, dupreq_lock, is already held.
9427c478bd9Sstevel@tonic-gate */
9437c478bd9Sstevel@tonic-gate static void
unhash(struct dupreq * dr)9447c478bd9Sstevel@tonic-gate unhash(struct dupreq *dr)
9457c478bd9Sstevel@tonic-gate {
9467c478bd9Sstevel@tonic-gate struct dupreq *drt;
9477c478bd9Sstevel@tonic-gate struct dupreq *drtprev = NULL;
9487c478bd9Sstevel@tonic-gate uint32_t drhash;
9497c478bd9Sstevel@tonic-gate
9507c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&dupreq_lock));
9517c478bd9Sstevel@tonic-gate
9527c478bd9Sstevel@tonic-gate drhash = (uint32_t)DRHASH(dr);
9537c478bd9Sstevel@tonic-gate drt = drhashtbl[drhash];
9547c478bd9Sstevel@tonic-gate while (drt != NULL) {
9557c478bd9Sstevel@tonic-gate if (drt == dr) {
9567c478bd9Sstevel@tonic-gate drhashstat[drhash]--;
9577c478bd9Sstevel@tonic-gate if (drtprev == NULL) {
9587c478bd9Sstevel@tonic-gate drhashtbl[drhash] = drt->dr_chain;
9597c478bd9Sstevel@tonic-gate } else {
9607c478bd9Sstevel@tonic-gate drtprev->dr_chain = drt->dr_chain;
9617c478bd9Sstevel@tonic-gate }
9627c478bd9Sstevel@tonic-gate return;
9637c478bd9Sstevel@tonic-gate }
9647c478bd9Sstevel@tonic-gate drtprev = drt;
9657c478bd9Sstevel@tonic-gate drt = drt->dr_chain;
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate }
9687c478bd9Sstevel@tonic-gate
9697c478bd9Sstevel@tonic-gate void
svc_clts_stats_init(zoneid_t zoneid,struct rpc_clts_server ** statsp)9707c478bd9Sstevel@tonic-gate svc_clts_stats_init(zoneid_t zoneid, struct rpc_clts_server **statsp)
9717c478bd9Sstevel@tonic-gate {
9727c478bd9Sstevel@tonic-gate kstat_t *ksp;
9737c478bd9Sstevel@tonic-gate kstat_named_t *knp;
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate knp = rpcstat_zone_init_common(zoneid, "unix", "rpc_clts_server",
9767c478bd9Sstevel@tonic-gate (const kstat_named_t *)&clts_rsstat_tmpl,
9777c478bd9Sstevel@tonic-gate sizeof (clts_rsstat_tmpl));
9787c478bd9Sstevel@tonic-gate /*
9797c478bd9Sstevel@tonic-gate * Backwards compatibility for old kstat clients
9807c478bd9Sstevel@tonic-gate */
9817c478bd9Sstevel@tonic-gate ksp = kstat_create_zone("unix", 0, "rpc_server", "rpc",
9827c478bd9Sstevel@tonic-gate KSTAT_TYPE_NAMED, clts_rsstat_ndata,
9837c478bd9Sstevel@tonic-gate KSTAT_FLAG_VIRTUAL | KSTAT_FLAG_WRITABLE, zoneid);
9847c478bd9Sstevel@tonic-gate if (ksp) {
9857c478bd9Sstevel@tonic-gate ksp->ks_data = knp;
9867c478bd9Sstevel@tonic-gate kstat_install(ksp);
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate *statsp = (struct rpc_clts_server *)knp;
9897c478bd9Sstevel@tonic-gate }
9907c478bd9Sstevel@tonic-gate
9917c478bd9Sstevel@tonic-gate void
svc_clts_stats_fini(zoneid_t zoneid,struct rpc_clts_server ** statsp)9927c478bd9Sstevel@tonic-gate svc_clts_stats_fini(zoneid_t zoneid, struct rpc_clts_server **statsp)
9937c478bd9Sstevel@tonic-gate {
9947c478bd9Sstevel@tonic-gate rpcstat_zone_fini_common(zoneid, "unix", "rpc_clts_server");
9957c478bd9Sstevel@tonic-gate kstat_delete_byname_zone("unix", 0, "rpc_server", zoneid);
9967c478bd9Sstevel@tonic-gate kmem_free(*statsp, sizeof (clts_rsstat_tmpl));
9977c478bd9Sstevel@tonic-gate }
9987c478bd9Sstevel@tonic-gate
9997c478bd9Sstevel@tonic-gate void
svc_clts_init()10007c478bd9Sstevel@tonic-gate svc_clts_init()
10017c478bd9Sstevel@tonic-gate {
10027c478bd9Sstevel@tonic-gate /*
10037c478bd9Sstevel@tonic-gate * Check to make sure that the clts private data will fit into
10047c478bd9Sstevel@tonic-gate * the stack buffer allocated by svc_run. The compiler should
10057c478bd9Sstevel@tonic-gate * remove this check, but it's a safety net if the udp_data
10067c478bd9Sstevel@tonic-gate * structure ever changes.
10077c478bd9Sstevel@tonic-gate */
10087c478bd9Sstevel@tonic-gate /*CONSTANTCONDITION*/
10097c478bd9Sstevel@tonic-gate ASSERT(sizeof (struct udp_data) <= SVC_P2LEN);
10107c478bd9Sstevel@tonic-gate
10117c478bd9Sstevel@tonic-gate mutex_init(&dupreq_lock, NULL, MUTEX_DEFAULT, NULL);
10127c478bd9Sstevel@tonic-gate }
1013