clnt_bck.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /* $NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 fvdl Exp $ */
  2. /*-
  3. * Copyright (c) 2009, Sun Microsystems, Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * - Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * - Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * - Neither the name of Sun Microsystems, Inc. nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  21. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. * POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #if defined(LIBC_SCCS) && !defined(lint)
  30. static char *sccsid2 = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
  31. static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
  32. static char sccsid3[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
  33. #endif
  34. #include <sys/cdefs.h>
  35. __FBSDID("$FreeBSD$");
  36. /*
  37. * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
  38. *
  39. * Copyright (C) 1984, Sun Microsystems, Inc.
  40. *
  41. * TCP based RPC supports 'batched calls'.
  42. * A sequence of calls may be batched-up in a send buffer. The rpc call
  43. * return immediately to the client even though the call was not necessarily
  44. * sent. The batching occurs if the results' xdr routine is NULL (0) AND
  45. * the rpc timeout value is zero (see clnt.h, rpc).
  46. *
  47. * Clients should NOT casually batch calls that in fact return results; that is,
  48. * the server side should be aware that a call is batched and not produce any
  49. * return message. Batched calls that produce many result messages can
  50. * deadlock (netlock) the client and the server....
  51. *
  52. * Now go hang yourself.
  53. */
  54. /*
  55. * This code handles the special case of a NFSv4.n backchannel for
  56. * callback RPCs. It is similar to clnt_vc.c, but uses the TCP
  57. * connection provided by the client to the server.
  58. */
  59. #include "opt_kern_tls.h"
  60. #include <sys/param.h>
  61. #include <sys/systm.h>
  62. #include <sys/ktls.h>
  63. #include <sys/lock.h>
  64. #include <sys/malloc.h>
  65. #include <sys/mbuf.h>
  66. #include <sys/mutex.h>
  67. #include <sys/pcpu.h>
  68. #include <sys/proc.h>
  69. #include <sys/protosw.h>
  70. #include <sys/socket.h>
  71. #include <sys/socketvar.h>
  72. #include <sys/sx.h>
  73. #include <sys/syslog.h>
  74. #include <sys/time.h>
  75. #include <sys/uio.h>
  76. #include <net/vnet.h>
  77. #include <netinet/tcp.h>
  78. #include <rpc/rpc.h>
  79. #include <rpc/rpc_com.h>
  80. #include <rpc/krpc.h>
  81. #include <rpc/rpcsec_tls.h>
  82. struct cmessage {
  83. struct cmsghdr cmsg;
  84. struct cmsgcred cmcred;
  85. };
  86. static void clnt_bck_geterr(CLIENT *, struct rpc_err *);
  87. static bool_t clnt_bck_freeres(CLIENT *, xdrproc_t, void *);
  88. static void clnt_bck_abort(CLIENT *);
  89. static bool_t clnt_bck_control(CLIENT *, u_int, void *);
  90. static void clnt_bck_close(CLIENT *);
  91. static void clnt_bck_destroy(CLIENT *);
  92. static struct clnt_ops clnt_bck_ops = {
  93. .cl_abort = clnt_bck_abort,
  94. .cl_geterr = clnt_bck_geterr,
  95. .cl_freeres = clnt_bck_freeres,
  96. .cl_close = clnt_bck_close,
  97. .cl_destroy = clnt_bck_destroy,
  98. .cl_control = clnt_bck_control
  99. };
  100. /*
  101. * Create a client handle for a connection.
  102. * Default options are set, which the user can change using clnt_control()'s.
  103. * This code handles the special case of an NFSv4.1 session backchannel
  104. * call, which is sent on a TCP connection created against the server
  105. * by a client.
  106. */
  107. void *
  108. clnt_bck_create(
  109. struct socket *so, /* Server transport socket. */
  110. const rpcprog_t prog, /* program number */
  111. const rpcvers_t vers) /* version number */
  112. {
  113. CLIENT *cl; /* client handle */
  114. struct ct_data *ct = NULL; /* client handle */
  115. struct timeval now;
  116. struct rpc_msg call_msg;
  117. static uint32_t disrupt;
  118. XDR xdrs;
  119. if (disrupt == 0)
  120. disrupt = (uint32_t)(long)so;
  121. cl = (CLIENT *)mem_alloc(sizeof (*cl));
  122. ct = (struct ct_data *)mem_alloc(sizeof (*ct));
  123. mtx_init(&ct->ct_lock, "ct->ct_lock", NULL, MTX_DEF);
  124. ct->ct_threads = 0;
  125. ct->ct_closing = FALSE;
  126. ct->ct_closed = FALSE;
  127. ct->ct_upcallrefs = 0;
  128. ct->ct_closeit = FALSE;
  129. /*
  130. * Set up private data struct
  131. */
  132. ct->ct_wait.tv_sec = -1;
  133. ct->ct_wait.tv_usec = -1;
  134. /*
  135. * Initialize call message
  136. */
  137. getmicrotime(&now);
  138. ct->ct_xid = ((uint32_t)++disrupt) ^ __RPC_GETXID(&now);
  139. call_msg.rm_xid = ct->ct_xid;
  140. call_msg.rm_direction = CALL;
  141. call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  142. call_msg.rm_call.cb_prog = (uint32_t)prog;
  143. call_msg.rm_call.cb_vers = (uint32_t)vers;
  144. /*
  145. * pre-serialize the static part of the call msg and stash it away
  146. */
  147. xdrmem_create(&xdrs, ct->ct_mcallc, MCALL_MSG_SIZE,
  148. XDR_ENCODE);
  149. if (!xdr_callhdr(&xdrs, &call_msg))
  150. goto err;
  151. ct->ct_mpos = XDR_GETPOS(&xdrs);
  152. XDR_DESTROY(&xdrs);
  153. ct->ct_waitchan = "rpcbck";
  154. ct->ct_waitflag = 0;
  155. cl->cl_refs = 1;
  156. cl->cl_ops = &clnt_bck_ops;
  157. cl->cl_private = ct;
  158. cl->cl_auth = authnone_create();
  159. TAILQ_INIT(&ct->ct_pending);
  160. return (cl);
  161. err:
  162. mtx_destroy(&ct->ct_lock);
  163. mem_free(ct, sizeof (struct ct_data));
  164. mem_free(cl, sizeof (CLIENT));
  165. return (NULL);
  166. }
  167. enum clnt_stat
  168. clnt_bck_call(
  169. CLIENT *cl, /* client handle */
  170. struct rpc_callextra *ext, /* call metadata */
  171. rpcproc_t proc, /* procedure number */
  172. struct mbuf *args, /* pointer to args */
  173. struct mbuf **resultsp, /* pointer to results */
  174. struct timeval utimeout,
  175. SVCXPRT *xprt)
  176. {
  177. struct ct_data *ct = (struct ct_data *) cl->cl_private;
  178. AUTH *auth;
  179. struct rpc_err *errp;
  180. enum clnt_stat stat;
  181. XDR xdrs;
  182. struct rpc_msg reply_msg;
  183. bool_t ok;
  184. int nrefreshes = 2; /* number of times to refresh cred */
  185. struct timeval timeout;
  186. uint32_t xid;
  187. struct mbuf *mreq = NULL, *results;
  188. struct ct_request *cr;
  189. int error, maxextsiz;
  190. #ifdef KERN_TLS
  191. u_int maxlen;
  192. #endif
  193. cr = malloc(sizeof(struct ct_request), M_RPC, M_WAITOK);
  194. mtx_lock(&ct->ct_lock);
  195. if (ct->ct_closing || ct->ct_closed) {
  196. mtx_unlock(&ct->ct_lock);
  197. free(cr, M_RPC);
  198. return (RPC_CANTSEND);
  199. }
  200. ct->ct_threads++;
  201. if (ext) {
  202. auth = ext->rc_auth;
  203. errp = &ext->rc_err;
  204. } else {
  205. auth = cl->cl_auth;
  206. errp = &ct->ct_error;
  207. }
  208. cr->cr_mrep = NULL;
  209. cr->cr_error = 0;
  210. if (ct->ct_wait.tv_usec == -1)
  211. timeout = utimeout; /* use supplied timeout */
  212. else
  213. timeout = ct->ct_wait; /* use default timeout */
  214. call_again:
  215. mtx_assert(&ct->ct_lock, MA_OWNED);
  216. ct->ct_xid++;
  217. xid = ct->ct_xid;
  218. mtx_unlock(&ct->ct_lock);
  219. /*
  220. * Leave space to pre-pend the record mark.
  221. */
  222. mreq = m_gethdr(M_WAITOK, MT_DATA);
  223. mreq->m_data += sizeof(uint32_t);
  224. KASSERT(ct->ct_mpos + sizeof(uint32_t) <= MHLEN,
  225. ("RPC header too big"));
  226. bcopy(ct->ct_mcallc, mreq->m_data, ct->ct_mpos);
  227. mreq->m_len = ct->ct_mpos;
  228. /*
  229. * The XID is the first thing in the request.
  230. */
  231. *mtod(mreq, uint32_t *) = htonl(xid);
  232. xdrmbuf_create(&xdrs, mreq, XDR_ENCODE);
  233. errp->re_status = stat = RPC_SUCCESS;
  234. if ((!XDR_PUTINT32(&xdrs, &proc)) ||
  235. (!AUTH_MARSHALL(auth, xid, &xdrs,
  236. m_copym(args, 0, M_COPYALL, M_WAITOK)))) {
  237. errp->re_status = stat = RPC_CANTENCODEARGS;
  238. mtx_lock(&ct->ct_lock);
  239. goto out;
  240. }
  241. mreq->m_pkthdr.len = m_length(mreq, NULL);
  242. /*
  243. * Prepend a record marker containing the packet length.
  244. */
  245. M_PREPEND(mreq, sizeof(uint32_t), M_WAITOK);
  246. *mtod(mreq, uint32_t *) =
  247. htonl(0x80000000 | (mreq->m_pkthdr.len - sizeof(uint32_t)));
  248. cr->cr_xid = xid;
  249. mtx_lock(&ct->ct_lock);
  250. /*
  251. * Check to see if the client end has already started to close down
  252. * the connection. The svc code will have set ct_error.re_status
  253. * to RPC_CANTRECV if this is the case.
  254. * If the client starts to close down the connection after this
  255. * point, it will be detected later when cr_error is checked,
  256. * since the request is in the ct_pending queue.
  257. */
  258. if (ct->ct_error.re_status == RPC_CANTRECV) {
  259. if (errp != &ct->ct_error) {
  260. errp->re_errno = ct->ct_error.re_errno;
  261. errp->re_status = RPC_CANTRECV;
  262. }
  263. stat = RPC_CANTRECV;
  264. goto out;
  265. }
  266. TAILQ_INSERT_TAIL(&ct->ct_pending, cr, cr_link);
  267. mtx_unlock(&ct->ct_lock);
  268. /* For RPC-over-TLS, copy mrep to a chain of ext_pgs. */
  269. if ((xprt->xp_tls & RPCTLS_FLAGS_HANDSHAKE) != 0) {
  270. /*
  271. * Copy the mbuf chain to a chain of
  272. * ext_pgs mbuf(s) as required by KERN_TLS.
  273. */
  274. maxextsiz = TLS_MAX_MSG_SIZE_V10_2;
  275. #ifdef KERN_TLS
  276. if (rpctls_getinfo(&maxlen, false, false))
  277. maxextsiz = min(maxextsiz, maxlen);
  278. #endif
  279. mreq = _rpc_copym_into_ext_pgs(mreq, maxextsiz);
  280. }
  281. /*
  282. * sosend consumes mreq.
  283. */
  284. sx_xlock(&xprt->xp_lock);
  285. error = sosend(xprt->xp_socket, NULL, NULL, mreq, NULL, 0, curthread);
  286. if (error != 0) printf("sosend=%d\n", error);
  287. mreq = NULL;
  288. if (error == EMSGSIZE) {
  289. printf("emsgsize\n");
  290. SOCKBUF_LOCK(&xprt->xp_socket->so_snd);
  291. sbwait(&xprt->xp_socket->so_snd);
  292. SOCKBUF_UNLOCK(&xprt->xp_socket->so_snd);
  293. sx_xunlock(&xprt->xp_lock);
  294. AUTH_VALIDATE(auth, xid, NULL, NULL);
  295. mtx_lock(&ct->ct_lock);
  296. TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
  297. goto call_again;
  298. }
  299. sx_xunlock(&xprt->xp_lock);
  300. reply_msg.acpted_rply.ar_verf.oa_flavor = AUTH_NULL;
  301. reply_msg.acpted_rply.ar_verf.oa_base = cr->cr_verf;
  302. reply_msg.acpted_rply.ar_verf.oa_length = 0;
  303. reply_msg.acpted_rply.ar_results.where = NULL;
  304. reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
  305. mtx_lock(&ct->ct_lock);
  306. if (error) {
  307. TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
  308. errp->re_errno = error;
  309. errp->re_status = stat = RPC_CANTSEND;
  310. goto out;
  311. }
  312. /*
  313. * Check to see if we got an upcall while waiting for the
  314. * lock. In both these cases, the request has been removed
  315. * from ct->ct_pending.
  316. */
  317. if (cr->cr_error) {
  318. TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
  319. errp->re_errno = cr->cr_error;
  320. errp->re_status = stat = RPC_CANTRECV;
  321. goto out;
  322. }
  323. if (cr->cr_mrep) {
  324. TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
  325. goto got_reply;
  326. }
  327. /*
  328. * Hack to provide rpc-based message passing
  329. */
  330. if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
  331. TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
  332. errp->re_status = stat = RPC_TIMEDOUT;
  333. goto out;
  334. }
  335. error = msleep(cr, &ct->ct_lock, ct->ct_waitflag, ct->ct_waitchan,
  336. tvtohz(&timeout));
  337. TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
  338. if (error) {
  339. /*
  340. * The sleep returned an error so our request is still
  341. * on the list. Turn the error code into an
  342. * appropriate client status.
  343. */
  344. errp->re_errno = error;
  345. switch (error) {
  346. case EINTR:
  347. stat = RPC_INTR;
  348. break;
  349. case EWOULDBLOCK:
  350. stat = RPC_TIMEDOUT;
  351. break;
  352. default:
  353. stat = RPC_CANTRECV;
  354. }
  355. errp->re_status = stat;
  356. goto out;
  357. } else {
  358. /*
  359. * We were woken up by the svc thread. If the
  360. * upcall had a receive error, report that,
  361. * otherwise we have a reply.
  362. */
  363. if (cr->cr_error) {
  364. errp->re_errno = cr->cr_error;
  365. errp->re_status = stat = RPC_CANTRECV;
  366. goto out;
  367. }
  368. }
  369. got_reply:
  370. /*
  371. * Now decode and validate the response. We need to drop the
  372. * lock since xdr_replymsg may end up sleeping in malloc.
  373. */
  374. mtx_unlock(&ct->ct_lock);
  375. if (ext && ext->rc_feedback)
  376. ext->rc_feedback(FEEDBACK_OK, proc, ext->rc_feedback_arg);
  377. xdrmbuf_create(&xdrs, cr->cr_mrep, XDR_DECODE);
  378. ok = xdr_replymsg(&xdrs, &reply_msg);
  379. cr->cr_mrep = NULL;
  380. if (ok) {
  381. if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
  382. (reply_msg.acpted_rply.ar_stat == SUCCESS))
  383. errp->re_status = stat = RPC_SUCCESS;
  384. else
  385. stat = _seterr_reply(&reply_msg, errp);
  386. if (stat == RPC_SUCCESS) {
  387. results = xdrmbuf_getall(&xdrs);
  388. if (!AUTH_VALIDATE(auth, xid,
  389. &reply_msg.acpted_rply.ar_verf, &results)) {
  390. errp->re_status = stat = RPC_AUTHERROR;
  391. errp->re_why = AUTH_INVALIDRESP;
  392. } else {
  393. KASSERT(results,
  394. ("auth validated but no result"));
  395. *resultsp = results;
  396. }
  397. } /* end successful completion */
  398. /*
  399. * If unsuccessful AND error is an authentication error
  400. * then refresh credentials and try again, else break
  401. */
  402. else if (stat == RPC_AUTHERROR)
  403. /* maybe our credentials need to be refreshed ... */
  404. if (nrefreshes > 0 && AUTH_REFRESH(auth, &reply_msg)) {
  405. nrefreshes--;
  406. XDR_DESTROY(&xdrs);
  407. mtx_lock(&ct->ct_lock);
  408. goto call_again;
  409. }
  410. /* end of unsuccessful completion */
  411. /* end of valid reply message */
  412. } else
  413. errp->re_status = stat = RPC_CANTDECODERES;
  414. XDR_DESTROY(&xdrs);
  415. mtx_lock(&ct->ct_lock);
  416. out:
  417. mtx_assert(&ct->ct_lock, MA_OWNED);
  418. KASSERT(stat != RPC_SUCCESS || *resultsp,
  419. ("RPC_SUCCESS without reply"));
  420. if (mreq != NULL)
  421. m_freem(mreq);
  422. if (cr->cr_mrep != NULL)
  423. m_freem(cr->cr_mrep);
  424. ct->ct_threads--;
  425. if (ct->ct_closing)
  426. wakeup(ct);
  427. mtx_unlock(&ct->ct_lock);
  428. if (auth && stat != RPC_SUCCESS)
  429. AUTH_VALIDATE(auth, xid, NULL, NULL);
  430. free(cr, M_RPC);
  431. return (stat);
  432. }
  433. static void
  434. clnt_bck_geterr(CLIENT *cl, struct rpc_err *errp)
  435. {
  436. struct ct_data *ct = (struct ct_data *) cl->cl_private;
  437. *errp = ct->ct_error;
  438. }
  439. static bool_t
  440. clnt_bck_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
  441. {
  442. XDR xdrs;
  443. bool_t dummy;
  444. xdrs.x_op = XDR_FREE;
  445. dummy = (*xdr_res)(&xdrs, res_ptr);
  446. return (dummy);
  447. }
  448. /*ARGSUSED*/
  449. static void
  450. clnt_bck_abort(CLIENT *cl)
  451. {
  452. }
  453. static bool_t
  454. clnt_bck_control(CLIENT *cl, u_int request, void *info)
  455. {
  456. return (TRUE);
  457. }
  458. static void
  459. clnt_bck_close(CLIENT *cl)
  460. {
  461. struct ct_data *ct = (struct ct_data *) cl->cl_private;
  462. mtx_lock(&ct->ct_lock);
  463. if (ct->ct_closed) {
  464. mtx_unlock(&ct->ct_lock);
  465. return;
  466. }
  467. if (ct->ct_closing) {
  468. while (ct->ct_closing)
  469. msleep(ct, &ct->ct_lock, 0, "rpcclose", 0);
  470. KASSERT(ct->ct_closed, ("client should be closed"));
  471. mtx_unlock(&ct->ct_lock);
  472. return;
  473. }
  474. ct->ct_closing = FALSE;
  475. ct->ct_closed = TRUE;
  476. mtx_unlock(&ct->ct_lock);
  477. wakeup(ct);
  478. }
  479. static void
  480. clnt_bck_destroy(CLIENT *cl)
  481. {
  482. struct ct_data *ct = (struct ct_data *) cl->cl_private;
  483. clnt_bck_close(cl);
  484. mtx_destroy(&ct->ct_lock);
  485. mem_free(ct, sizeof(struct ct_data));
  486. if (cl->cl_netid && cl->cl_netid[0])
  487. mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
  488. if (cl->cl_tp && cl->cl_tp[0])
  489. mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
  490. mem_free(cl, sizeof(CLIENT));
  491. }
  492. /*
  493. * This call is done by the svc code when a backchannel RPC reply is
  494. * received.
  495. */
  496. void
  497. clnt_bck_svccall(void *arg, struct mbuf *mrep, uint32_t xid)
  498. {
  499. struct ct_data *ct = (struct ct_data *)arg;
  500. struct ct_request *cr;
  501. int foundreq;
  502. mtx_lock(&ct->ct_lock);
  503. ct->ct_upcallrefs++;
  504. /*
  505. * See if we can match this reply to a request.
  506. */
  507. foundreq = 0;
  508. TAILQ_FOREACH(cr, &ct->ct_pending, cr_link) {
  509. if (cr->cr_xid == xid) {
  510. /*
  511. * This one matches. We leave the reply mbuf list in
  512. * cr->cr_mrep. Set the XID to zero so that we will
  513. * ignore any duplicated replies.
  514. */
  515. cr->cr_xid = 0;
  516. cr->cr_mrep = mrep;
  517. cr->cr_error = 0;
  518. foundreq = 1;
  519. wakeup(cr);
  520. break;
  521. }
  522. }
  523. ct->ct_upcallrefs--;
  524. if (ct->ct_upcallrefs < 0)
  525. panic("rpcvc svccall refcnt");
  526. if (ct->ct_upcallrefs == 0)
  527. wakeup(&ct->ct_upcallrefs);
  528. mtx_unlock(&ct->ct_lock);
  529. if (foundreq == 0)
  530. m_freem(mrep);
  531. }