1 /* $NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $ */
4 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #if defined(LIBC_SCCS) && !defined(lint)
32 static char *sccsid2 = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
33 static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 * svc_vc.c, Server side for Connection Oriented based RPC.
41 * Actually implements two flavors of transporter -
42 * a tcp rendezvouser (a listner and connection establisher)
43 * and a record/tcp stream.
46 #include <sys/param.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
51 #include <sys/mutex.h>
53 #include <sys/protosw.h>
54 #include <sys/queue.h>
55 #include <sys/socket.h>
56 #include <sys/socketvar.h>
58 #include <sys/systm.h>
63 #include <netinet/tcp.h>
68 #include <rpc/rpc_com.h>
70 #include <security/mac/mac_framework.h>
72 static bool_t svc_vc_rendezvous_recv(SVCXPRT *, struct rpc_msg *,
73 struct sockaddr **, struct mbuf **);
74 static enum xprt_stat svc_vc_rendezvous_stat(SVCXPRT *);
75 static void svc_vc_rendezvous_destroy(SVCXPRT *);
76 static bool_t svc_vc_null(void);
77 static void svc_vc_destroy(SVCXPRT *);
78 static enum xprt_stat svc_vc_stat(SVCXPRT *);
79 static bool_t svc_vc_ack(SVCXPRT *, uint32_t *);
80 static bool_t svc_vc_recv(SVCXPRT *, struct rpc_msg *,
81 struct sockaddr **, struct mbuf **);
82 static bool_t svc_vc_reply(SVCXPRT *, struct rpc_msg *,
83 struct sockaddr *, struct mbuf *, uint32_t *seq);
84 static bool_t svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in);
85 static bool_t svc_vc_rendezvous_control (SVCXPRT *xprt, const u_int rq,
87 static void svc_vc_backchannel_destroy(SVCXPRT *);
88 static enum xprt_stat svc_vc_backchannel_stat(SVCXPRT *);
89 static bool_t svc_vc_backchannel_recv(SVCXPRT *, struct rpc_msg *,
90 struct sockaddr **, struct mbuf **);
91 static bool_t svc_vc_backchannel_reply(SVCXPRT *, struct rpc_msg *,
92 struct sockaddr *, struct mbuf *, uint32_t *);
93 static bool_t svc_vc_backchannel_control(SVCXPRT *xprt, const u_int rq,
95 static SVCXPRT *svc_vc_create_conn(SVCPOOL *pool, struct socket *so,
96 struct sockaddr *raddr);
97 static int svc_vc_accept(struct socket *head, struct socket **sop);
98 static int svc_vc_soupcall(struct socket *so, void *arg, int waitflag);
99 static int svc_vc_rendezvous_soupcall(struct socket *, void *, int);
101 static struct xp_ops svc_vc_rendezvous_ops = {
102 .xp_recv = svc_vc_rendezvous_recv,
103 .xp_stat = svc_vc_rendezvous_stat,
104 .xp_reply = (bool_t (*)(SVCXPRT *, struct rpc_msg *,
105 struct sockaddr *, struct mbuf *, uint32_t *))svc_vc_null,
106 .xp_destroy = svc_vc_rendezvous_destroy,
107 .xp_control = svc_vc_rendezvous_control
110 static struct xp_ops svc_vc_ops = {
111 .xp_recv = svc_vc_recv,
112 .xp_stat = svc_vc_stat,
113 .xp_ack = svc_vc_ack,
114 .xp_reply = svc_vc_reply,
115 .xp_destroy = svc_vc_destroy,
116 .xp_control = svc_vc_control
119 static struct xp_ops svc_vc_backchannel_ops = {
120 .xp_recv = svc_vc_backchannel_recv,
121 .xp_stat = svc_vc_backchannel_stat,
122 .xp_reply = svc_vc_backchannel_reply,
123 .xp_destroy = svc_vc_backchannel_destroy,
124 .xp_control = svc_vc_backchannel_control
129 * xprt = svc_vc_create(sock, send_buf_size, recv_buf_size);
131 * Creates, registers, and returns a (rpc) tcp based transporter.
132 * Once *xprt is initialized, it is registered as a transporter
133 * see (svc.h, xprt_register). This routine returns
134 * a NULL if a problem occurred.
136 * The filedescriptor passed in is expected to refer to a bound, but
137 * not yet connected socket.
139 * Since streams do buffered io similar to stdio, the caller can specify
140 * how big the send and receive buffers are via the second and third parms;
141 * 0 => use the system default.
144 svc_vc_create(SVCPOOL *pool, struct socket *so, size_t sendsize,
152 if (so->so_state & (SS_ISCONNECTED|SS_ISDISCONNECTED)) {
154 CURVNET_SET(so->so_vnet);
155 error = so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa);
159 xprt = svc_vc_create_conn(pool, so, sa);
165 xprt = svc_xprt_alloc();
166 sx_init(&xprt->xp_lock, "xprt->xp_lock");
167 xprt->xp_pool = pool;
168 xprt->xp_socket = so;
171 xprt->xp_ops = &svc_vc_rendezvous_ops;
173 CURVNET_SET(so->so_vnet);
174 error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa);
177 goto cleanup_svc_vc_create;
180 memcpy(&xprt->xp_ltaddr, sa, sa->sa_len);
185 solisten(so, -1, curthread);
188 xprt->xp_upcallset = 1;
189 solisten_upcall_set(so, svc_vc_rendezvous_soupcall, xprt);
194 cleanup_svc_vc_create:
195 sx_destroy(&xprt->xp_lock);
202 * Create a new transport for a socket optained via soaccept().
205 svc_vc_create_conn(SVCPOOL *pool, struct socket *so, struct sockaddr *raddr)
209 struct sockaddr* sa = NULL;
214 bzero(&opt, sizeof(struct sockopt));
215 opt.sopt_dir = SOPT_SET;
216 opt.sopt_level = SOL_SOCKET;
217 opt.sopt_name = SO_KEEPALIVE;
219 opt.sopt_valsize = sizeof(one);
220 error = sosetopt(so, &opt);
225 if (so->so_proto->pr_protocol == IPPROTO_TCP) {
226 bzero(&opt, sizeof(struct sockopt));
227 opt.sopt_dir = SOPT_SET;
228 opt.sopt_level = IPPROTO_TCP;
229 opt.sopt_name = TCP_NODELAY;
231 opt.sopt_valsize = sizeof(one);
232 error = sosetopt(so, &opt);
238 cd = mem_alloc(sizeof(*cd));
239 cd->strm_stat = XPRT_IDLE;
241 xprt = svc_xprt_alloc();
242 sx_init(&xprt->xp_lock, "xprt->xp_lock");
243 xprt->xp_pool = pool;
244 xprt->xp_socket = so;
247 xprt->xp_ops = &svc_vc_ops;
250 * See http://www.connectathon.org/talks96/nfstcp.pdf - client
251 * has a 5 minute timer, server has a 6 minute timer.
253 xprt->xp_idletimeout = 6 * 60;
255 memcpy(&xprt->xp_rtaddr, raddr, raddr->sa_len);
257 CURVNET_SET(so->so_vnet);
258 error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa);
261 goto cleanup_svc_vc_create;
263 memcpy(&xprt->xp_ltaddr, sa, sa->sa_len);
268 SOCKBUF_LOCK(&so->so_rcv);
269 xprt->xp_upcallset = 1;
270 soupcall_set(so, SO_RCV, svc_vc_soupcall, xprt);
271 SOCKBUF_UNLOCK(&so->so_rcv);
274 * Throw the transport into the active list in case it already
275 * has some data buffered.
277 sx_xlock(&xprt->xp_lock);
279 sx_xunlock(&xprt->xp_lock);
282 cleanup_svc_vc_create:
283 sx_destroy(&xprt->xp_lock);
285 mem_free(cd, sizeof(*cd));
291 * Create a new transport for a backchannel on a clnt_vc socket.
294 svc_vc_create_backchannel(SVCPOOL *pool)
296 SVCXPRT *xprt = NULL;
297 struct cf_conn *cd = NULL;
299 cd = mem_alloc(sizeof(*cd));
300 cd->strm_stat = XPRT_IDLE;
302 xprt = svc_xprt_alloc();
303 sx_init(&xprt->xp_lock, "xprt->xp_lock");
304 xprt->xp_pool = pool;
305 xprt->xp_socket = NULL;
308 xprt->xp_ops = &svc_vc_backchannel_ops;
313 * This does all of the accept except the final call to soaccept. The
314 * caller will call soaccept after dropping its locks (soaccept may
318 svc_vc_accept(struct socket *head, struct socket **sop)
324 /* XXXGL: shouldn't that be an assertion? */
325 if ((head->so_options & SO_ACCEPTCONN) == 0) {
330 error = mac_socket_check_accept(curthread->td_ucred, head);
335 * XXXGL: we want non-blocking semantics. The socket could be a
336 * socket created by kernel as well as socket shared with userland,
337 * so we can't be sure about presense of SS_NBIO. We also shall not
338 * toggle it on the socket, since that may surprise userland. So we
339 * set SS_NBIO only temporarily.
342 nbio = head->so_state & SS_NBIO;
343 head->so_state |= SS_NBIO;
344 error = solisten_dequeue(head, &so, 0);
345 head->so_state &= (nbio & ~SS_NBIO);
349 so->so_state |= nbio;
352 /* connection has been removed from the listen queue */
353 KNOTE_UNLOCKED(&head->so_rdsel.si_note, 0);
360 svc_vc_rendezvous_recv(SVCXPRT *xprt, struct rpc_msg *msg,
361 struct sockaddr **addrp, struct mbuf **mp)
363 struct socket *so = NULL;
364 struct sockaddr *sa = NULL;
369 * The socket upcall calls xprt_active() which will eventually
370 * cause the server to call us here. We attempt to accept a
371 * connection from the socket and turn it into a new
372 * transport. If the accept fails, we have drained all pending
373 * connections so we call xprt_inactive().
375 sx_xlock(&xprt->xp_lock);
377 error = svc_vc_accept(xprt->xp_socket, &so);
379 if (error == EWOULDBLOCK) {
381 * We must re-test for new connections after taking
382 * the lock to protect us in the case where a new
383 * connection arrives after our call to accept fails
386 SOLISTEN_LOCK(xprt->xp_socket);
387 if (TAILQ_EMPTY(&xprt->xp_socket->sol_comp))
388 xprt_inactive_self(xprt);
389 SOLISTEN_UNLOCK(xprt->xp_socket);
390 sx_xunlock(&xprt->xp_lock);
395 SOLISTEN_LOCK(xprt->xp_socket);
396 if (xprt->xp_upcallset) {
397 xprt->xp_upcallset = 0;
398 soupcall_clear(xprt->xp_socket, SO_RCV);
400 SOLISTEN_UNLOCK(xprt->xp_socket);
401 xprt_inactive_self(xprt);
402 sx_xunlock(&xprt->xp_lock);
406 sx_xunlock(&xprt->xp_lock);
409 error = soaccept(so, &sa);
413 * XXX not sure if I need to call sofree or soclose here.
421 * svc_vc_create_conn will call xprt_register - we don't need
422 * to do anything with the new connection except derefence it.
424 new_xprt = svc_vc_create_conn(xprt->xp_pool, so, sa);
428 SVC_RELEASE(new_xprt);
433 return (FALSE); /* there is never an rpc msg to be processed */
437 static enum xprt_stat
438 svc_vc_rendezvous_stat(SVCXPRT *xprt)
445 svc_vc_destroy_common(SVCXPRT *xprt)
449 (void)soclose(xprt->xp_socket);
452 (void) mem_free(xprt->xp_netid, strlen(xprt->xp_netid) + 1);
457 svc_vc_rendezvous_destroy(SVCXPRT *xprt)
460 SOLISTEN_LOCK(xprt->xp_socket);
461 if (xprt->xp_upcallset) {
462 xprt->xp_upcallset = 0;
463 solisten_upcall_set(xprt->xp_socket, NULL, NULL);
465 SOLISTEN_UNLOCK(xprt->xp_socket);
467 svc_vc_destroy_common(xprt);
471 svc_vc_destroy(SVCXPRT *xprt)
473 struct cf_conn *cd = (struct cf_conn *)xprt->xp_p1;
475 SOCKBUF_LOCK(&xprt->xp_socket->so_rcv);
476 if (xprt->xp_upcallset) {
477 xprt->xp_upcallset = 0;
478 soupcall_clear(xprt->xp_socket, SO_RCV);
480 SOCKBUF_UNLOCK(&xprt->xp_socket->so_rcv);
482 svc_vc_destroy_common(xprt);
487 m_freem(cd->mpending);
488 mem_free(cd, sizeof(*cd));
492 svc_vc_backchannel_destroy(SVCXPRT *xprt)
494 struct cf_conn *cd = (struct cf_conn *)xprt->xp_p1;
504 mem_free(cd, sizeof(*cd));
509 svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in)
515 svc_vc_rendezvous_control(SVCXPRT *xprt, const u_int rq, void *in)
522 svc_vc_backchannel_control(SVCXPRT *xprt, const u_int rq, void *in)
528 static enum xprt_stat
529 svc_vc_stat(SVCXPRT *xprt)
533 cd = (struct cf_conn *)(xprt->xp_p1);
535 if (cd->strm_stat == XPRT_DIED)
538 if (cd->mreq != NULL && cd->resid == 0 && cd->eor)
539 return (XPRT_MOREREQS);
541 if (soreadable(xprt->xp_socket))
542 return (XPRT_MOREREQS);
548 svc_vc_ack(SVCXPRT *xprt, uint32_t *ack)
551 *ack = atomic_load_acq_32(&xprt->xp_snt_cnt);
552 *ack -= sbused(&xprt->xp_socket->so_snd);
556 static enum xprt_stat
557 svc_vc_backchannel_stat(SVCXPRT *xprt)
561 cd = (struct cf_conn *)(xprt->xp_p1);
563 if (cd->mreq != NULL)
564 return (XPRT_MOREREQS);
570 * If we have an mbuf chain in cd->mpending, try to parse a record from it,
571 * leaving the result in cd->mreq. If we don't have a complete record, leave
572 * the partial result in cd->mreq and try to read more from the socket.
575 svc_vc_process_pending(SVCXPRT *xprt)
577 struct cf_conn *cd = (struct cf_conn *) xprt->xp_p1;
578 struct socket *so = xprt->xp_socket;
582 * If cd->resid is non-zero, we have part of the
583 * record already, otherwise we are expecting a record
586 if (!cd->resid && cd->mpending) {
588 * See if there is enough data buffered to
589 * make up a record marker. Make sure we can
590 * handle the case where the record marker is
591 * split across more than one mbuf.
597 while (n < sizeof(uint32_t) && m) {
601 if (n < sizeof(uint32_t)) {
602 so->so_rcv.sb_lowat = sizeof(uint32_t) - n;
605 m_copydata(cd->mpending, 0, sizeof(header),
607 header = ntohl(header);
608 cd->eor = (header & 0x80000000) != 0;
609 cd->resid = header & 0x7fffffff;
610 m_adj(cd->mpending, sizeof(uint32_t));
614 * Start pulling off mbufs from cd->mpending
615 * until we either have a complete record or
616 * we run out of data. We use m_split to pull
617 * data - it will pull as much as possible and
618 * split the last mbuf if necessary.
620 while (cd->mpending && cd->resid) {
622 if (cd->mpending->m_next
623 || cd->mpending->m_len > cd->resid)
624 cd->mpending = m_split(cd->mpending,
625 cd->resid, M_WAITOK);
629 m_last(cd->mreq)->m_next = m;
633 cd->resid -= m->m_len;
639 * Block receive upcalls if we have more data pending,
640 * otherwise report our need.
643 so->so_rcv.sb_lowat = INT_MAX;
645 so->so_rcv.sb_lowat =
646 imax(1, imin(cd->resid, so->so_rcv.sb_hiwat / 2));
651 svc_vc_recv(SVCXPRT *xprt, struct rpc_msg *msg,
652 struct sockaddr **addrp, struct mbuf **mp)
654 struct cf_conn *cd = (struct cf_conn *) xprt->xp_p1;
657 struct socket* so = xprt->xp_socket;
660 uint32_t xid_plus_direction[2];
663 * Serialise access to the socket and our own record parsing
666 sx_xlock(&xprt->xp_lock);
669 /* If we have no request ready, check pending queue. */
670 while (cd->mpending &&
671 (cd->mreq == NULL || cd->resid != 0 || !cd->eor)) {
672 if (!svc_vc_process_pending(xprt))
676 /* Process and return complete request in cd->mreq. */
677 if (cd->mreq != NULL && cd->resid == 0 && cd->eor) {
680 * Now, check for a backchannel reply.
681 * The XID is in the first uint32_t of the reply
682 * and the message direction is the second one.
684 if ((cd->mreq->m_len >= sizeof(xid_plus_direction) ||
685 m_length(cd->mreq, NULL) >=
686 sizeof(xid_plus_direction)) &&
687 xprt->xp_p2 != NULL) {
688 m_copydata(cd->mreq, 0,
689 sizeof(xid_plus_direction),
690 (char *)xid_plus_direction);
691 xid_plus_direction[0] =
692 ntohl(xid_plus_direction[0]);
693 xid_plus_direction[1] =
694 ntohl(xid_plus_direction[1]);
695 /* Check message direction. */
696 if (xid_plus_direction[1] == REPLY) {
697 clnt_bck_svccall(xprt->xp_p2,
699 xid_plus_direction[0]);
705 xdrmbuf_create(&xdrs, cd->mreq, XDR_DECODE);
708 /* Check for next request in a pending queue. */
709 svc_vc_process_pending(xprt);
710 if (cd->mreq == NULL || cd->resid != 0) {
711 SOCKBUF_LOCK(&so->so_rcv);
713 xprt_inactive_self(xprt);
714 SOCKBUF_UNLOCK(&so->so_rcv);
717 sx_xunlock(&xprt->xp_lock);
719 if (! xdr_callmsg(&xdrs, msg)) {
725 *mp = xdrmbuf_getall(&xdrs);
732 * The socket upcall calls xprt_active() which will eventually
733 * cause the server to call us here. We attempt to
734 * read as much as possible from the socket and put
735 * the result in cd->mpending. If the read fails,
736 * we have drained both cd->mpending and the socket so
737 * we can call xprt_inactive().
739 uio.uio_resid = 1000000000;
740 uio.uio_td = curthread;
742 rcvflag = MSG_DONTWAIT;
743 error = soreceive(so, NULL, &uio, &m, NULL, &rcvflag);
745 if (error == EWOULDBLOCK) {
747 * We must re-test for readability after
748 * taking the lock to protect us in the case
749 * where a new packet arrives on the socket
750 * after our call to soreceive fails with
753 SOCKBUF_LOCK(&so->so_rcv);
755 xprt_inactive_self(xprt);
756 SOCKBUF_UNLOCK(&so->so_rcv);
757 sx_xunlock(&xprt->xp_lock);
762 SOCKBUF_LOCK(&so->so_rcv);
763 if (xprt->xp_upcallset) {
764 xprt->xp_upcallset = 0;
765 soupcall_clear(so, SO_RCV);
767 SOCKBUF_UNLOCK(&so->so_rcv);
768 xprt_inactive_self(xprt);
769 cd->strm_stat = XPRT_DIED;
770 sx_xunlock(&xprt->xp_lock);
776 * EOF - the other end has closed the socket.
778 xprt_inactive_self(xprt);
779 cd->strm_stat = XPRT_DIED;
780 sx_xunlock(&xprt->xp_lock);
785 m_last(cd->mpending)->m_next = m;
792 svc_vc_backchannel_recv(SVCXPRT *xprt, struct rpc_msg *msg,
793 struct sockaddr **addrp, struct mbuf **mp)
795 struct cf_conn *cd = (struct cf_conn *) xprt->xp_p1;
800 sx_xlock(&xprt->xp_lock);
801 ct = (struct ct_data *)xprt->xp_p2;
803 sx_xunlock(&xprt->xp_lock);
806 mtx_lock(&ct->ct_lock);
809 xprt_inactive_self(xprt);
810 mtx_unlock(&ct->ct_lock);
811 sx_xunlock(&xprt->xp_lock);
814 cd->mreq = m->m_nextpkt;
815 mtx_unlock(&ct->ct_lock);
816 sx_xunlock(&xprt->xp_lock);
818 xdrmbuf_create(&xdrs, m, XDR_DECODE);
819 if (! xdr_callmsg(&xdrs, msg)) {
824 *mp = xdrmbuf_getall(&xdrs);
830 svc_vc_reply(SVCXPRT *xprt, struct rpc_msg *msg,
831 struct sockaddr *addr, struct mbuf *m, uint32_t *seq)
839 * Leave space for record mark.
841 mrep = m_gethdr(M_WAITOK, MT_DATA);
842 mrep->m_data += sizeof(uint32_t);
844 xdrmbuf_create(&xdrs, mrep, XDR_ENCODE);
846 if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
847 msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
848 if (!xdr_replymsg(&xdrs, msg))
851 xdrmbuf_append(&xdrs, m);
853 stat = xdr_replymsg(&xdrs, msg);
860 * Prepend a record marker containing the reply length.
862 M_PREPEND(mrep, sizeof(uint32_t), M_WAITOK);
863 len = mrep->m_pkthdr.len;
864 *mtod(mrep, uint32_t *) =
865 htonl(0x80000000 | (len - sizeof(uint32_t)));
866 atomic_add_32(&xprt->xp_snd_cnt, len);
867 error = sosend(xprt->xp_socket, NULL, NULL, mrep, NULL,
870 atomic_add_rel_32(&xprt->xp_snt_cnt, len);
872 *seq = xprt->xp_snd_cnt;
875 atomic_subtract_32(&xprt->xp_snd_cnt, len);
886 svc_vc_backchannel_reply(SVCXPRT *xprt, struct rpc_msg *msg,
887 struct sockaddr *addr, struct mbuf *m, uint32_t *seq)
896 * Leave space for record mark.
898 mrep = m_gethdr(M_WAITOK, MT_DATA);
899 mrep->m_data += sizeof(uint32_t);
901 xdrmbuf_create(&xdrs, mrep, XDR_ENCODE);
903 if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
904 msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
905 if (!xdr_replymsg(&xdrs, msg))
908 xdrmbuf_append(&xdrs, m);
910 stat = xdr_replymsg(&xdrs, msg);
917 * Prepend a record marker containing the reply length.
919 M_PREPEND(mrep, sizeof(uint32_t), M_WAITOK);
920 *mtod(mrep, uint32_t *) =
921 htonl(0x80000000 | (mrep->m_pkthdr.len
922 - sizeof(uint32_t)));
923 sx_xlock(&xprt->xp_lock);
924 ct = (struct ct_data *)xprt->xp_p2;
926 error = sosend(ct->ct_socket, NULL, NULL, mrep, NULL,
930 sx_xunlock(&xprt->xp_lock);
951 svc_vc_soupcall(struct socket *so, void *arg, int waitflag)
953 SVCXPRT *xprt = (SVCXPRT *) arg;
955 if (soreadable(xprt->xp_socket))
961 svc_vc_rendezvous_soupcall(struct socket *head, void *arg, int waitflag)
963 SVCXPRT *xprt = (SVCXPRT *) arg;
965 if (!TAILQ_EMPTY(&head->sol_comp))
972 * Get the effective UID of the sending process. Used by rpcbind, keyserv
973 * and rpc.yppasswdd on AF_LOCAL.
976 __rpc_get_local_uid(SVCXPRT *transp, uid_t *uid) {
982 sock = transp->xp_fd;
983 sa = (struct sockaddr *)transp->xp_rtaddr;
984 if (sa->sa_family == AF_LOCAL) {
985 ret = getpeereid(sock, &euid, &egid);