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