1 /* $NetBSD: clnt_dg.c,v 1.4 2000/07/14 08:40:41 fvdl Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2009, Sun Microsystems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
36 #if defined(LIBC_SCCS) && !defined(lint)
37 #ident "@(#)clnt_dg.c 1.23 94/04/22 SMI"
38 static char sccsid[] = "@(#)clnt_dg.c 1.19 89/03/16 Copyr 1988 Sun Micro";
40 #include <sys/cdefs.h>
42 * Implements a connectionless client side RPC.
45 #include "namespace.h"
46 #include "reentrant.h"
47 #include <sys/types.h>
48 #include <sys/event.h>
50 #include <sys/socket.h>
51 #include <sys/ioctl.h>
52 #include <arpa/inet.h>
54 #include <rpc/rpcsec_gss.h>
61 #include "un-namespace.h"
66 #ifdef _FREEFALL_CONFIG
68 * Disable RPC exponential back-off for FreeBSD.org systems.
70 #define RPC_MAX_BACKOFF 1 /* second */
72 #define RPC_MAX_BACKOFF 30 /* seconds */
76 static struct clnt_ops *clnt_dg_ops(void);
77 static bool_t time_not_ok(struct timeval *);
78 static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
79 xdrproc_t, void *, struct timeval);
80 static void clnt_dg_geterr(CLIENT *, struct rpc_err *);
81 static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *);
82 static void clnt_dg_abort(CLIENT *);
83 static bool_t clnt_dg_control(CLIENT *, u_int, void *);
84 static void clnt_dg_destroy(CLIENT *);
90 * This machinery implements per-fd locks for MT-safety. It is not
91 * sufficient to do per-CLIENT handle locks for MT-safety because a
92 * user may create more than one CLIENT handle with the same fd behind
93 * it. Therefore, we allocate an array of flags (dg_fd_locks), protected
94 * by the clnt_fd_lock mutex, and an array (dg_cv) of condition variables
95 * similarly protected. Dg_fd_lock[fd] == 1 => a call is active on some
96 * CLIENT handle created for that fd.
97 * The current implementation holds locks across the entire RPC and reply,
98 * including retransmissions. Yes, this is silly, and as soon as this
99 * code is proven to work, this should be the first thing fixed. One step
102 static int *dg_fd_locks;
103 static cond_t *dg_cv;
104 #define release_fd_lock(fd, mask) { \
105 mutex_lock(&clnt_fd_lock); \
106 dg_fd_locks[fd] = 0; \
107 mutex_unlock(&clnt_fd_lock); \
108 thr_sigsetmask(SIG_SETMASK, &(mask), NULL); \
109 cond_signal(&dg_cv[fd]); \
112 static const char mem_err_clnt_dg[] = "clnt_dg_create: out of memory";
114 /* VARIABLES PROTECTED BY clnt_fd_lock: dg_fd_locks, dg_cv */
116 #define MCALL_MSG_SIZE 24
119 * Private data kept per client handle
122 int cu_fd; /* connections fd */
123 bool_t cu_closeit; /* opened by library */
124 struct sockaddr_storage cu_raddr; /* remote address */
126 struct timeval cu_wait; /* retransmit interval */
127 struct timeval cu_total; /* total time for the call */
128 struct rpc_err cu_error;
131 u_int cu_sendsz; /* send size */
132 char cu_outhdr[MCALL_MSG_SIZE];
134 u_int cu_recvsz; /* recv size */
136 int cu_connect; /* Use connect(). */
137 int cu_connected; /* Have done connect(). */
138 struct kevent cu_kin;
144 * Connection less client creation returns with client handle parameters.
145 * Default options are set, which the user can change using clnt_control().
146 * fd should be open and bound.
147 * NB: The rpch->cl_auth is initialized to null authentication.
148 * Caller may wish to set this something more useful.
150 * sendsz and recvsz are the maximum allowable packet sizes that can be
151 * sent and received. Normally they are the same, but they can be
152 * changed to improve the program efficiency and buffer allocation.
153 * If they are 0, use the transport default.
155 * If svcaddr is NULL, returns NULL.
157 * fd - open file descriptor
158 * svcaddr - servers address
159 * program - program number
160 * version - version number
161 * sendsz - buffer recv size
162 * recvsz - buffer send size
165 clnt_dg_create(int fd, const struct netbuf *svcaddr, rpcprog_t program,
166 rpcvers_t version, u_int sendsz, u_int recvsz)
168 CLIENT *cl = NULL; /* client handle */
169 struct cu_data *cu = NULL; /* private data */
171 struct rpc_msg call_msg;
174 struct __rpc_sockinfo si;
177 sigfillset(&newmask);
178 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
179 mutex_lock(&clnt_fd_lock);
180 if (dg_fd_locks == (int *) NULL) {
183 int dtbsize = __rpc_dtbsize();
185 fd_allocsz = dtbsize * sizeof (int);
186 dg_fd_locks = (int *) mem_alloc(fd_allocsz);
187 if (dg_fd_locks == (int *) NULL) {
188 mutex_unlock(&clnt_fd_lock);
189 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
192 memset(dg_fd_locks, '\0', fd_allocsz);
194 cv_allocsz = dtbsize * sizeof (cond_t);
195 dg_cv = (cond_t *) mem_alloc(cv_allocsz);
196 if (dg_cv == (cond_t *) NULL) {
197 mem_free(dg_fd_locks, fd_allocsz);
198 dg_fd_locks = (int *) NULL;
199 mutex_unlock(&clnt_fd_lock);
200 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
205 for (i = 0; i < dtbsize; i++)
206 cond_init(&dg_cv[i], 0, (void *) 0);
210 mutex_unlock(&clnt_fd_lock);
211 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
213 if (svcaddr == NULL) {
214 rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
218 if (!__rpc_fd2sockinfo(fd, &si)) {
219 rpc_createerr.cf_stat = RPC_TLIERROR;
220 rpc_createerr.cf_error.re_errno = 0;
224 * Find the receive and the send size
226 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
227 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
228 if ((sendsz == 0) || (recvsz == 0)) {
229 rpc_createerr.cf_stat = RPC_TLIERROR; /* XXX */
230 rpc_createerr.cf_error.re_errno = 0;
234 if ((cl = mem_alloc(sizeof (CLIENT))) == NULL)
237 * Should be multiple of 4 for XDR.
239 sendsz = ((sendsz + 3) / 4) * 4;
240 recvsz = ((recvsz + 3) / 4) * 4;
241 cu = mem_alloc(sizeof (*cu) + sendsz + recvsz);
244 (void) memcpy(&cu->cu_raddr, svcaddr->buf, (size_t)svcaddr->len);
245 cu->cu_rlen = svcaddr->len;
246 cu->cu_outbuf = &cu->cu_inbuf[recvsz];
247 /* Other values can also be set through clnt_control() */
248 cu->cu_wait.tv_sec = 15; /* heuristically chosen */
249 cu->cu_wait.tv_usec = 0;
250 cu->cu_total.tv_sec = -1;
251 cu->cu_total.tv_usec = -1;
252 cu->cu_sendsz = sendsz;
253 cu->cu_recvsz = recvsz;
254 cu->cu_async = FALSE;
255 cu->cu_connect = FALSE;
256 cu->cu_connected = FALSE;
257 (void) gettimeofday(&now, NULL);
258 call_msg.rm_xid = __RPC_GETXID(&now);
259 call_msg.rm_call.cb_prog = program;
260 call_msg.rm_call.cb_vers = version;
261 xdrmem_create(&(cu->cu_outxdrs), cu->cu_outhdr, MCALL_MSG_SIZE,
263 if (! xdr_callhdr(&cu->cu_outxdrs, &call_msg)) {
264 rpc_createerr.cf_stat = RPC_CANTENCODEARGS; /* XXX */
265 rpc_createerr.cf_error.re_errno = 0;
268 cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
269 XDR_DESTROY(&cu->cu_outxdrs);
270 xdrmem_create(&cu->cu_outxdrs, cu->cu_outbuf, sendsz, XDR_ENCODE);
272 /* XXX fvdl - do we still want this? */
274 (void)bindresvport_sa(fd, (struct sockaddr *)svcaddr->buf);
276 _ioctl(fd, FIONBIO, (char *)(void *)&one);
279 * By default, closeit is always FALSE. It is users responsibility
280 * to do a close on it, else the user may use clnt_control
281 * to let clnt_destroy do it for him/her.
283 cu->cu_closeit = FALSE;
285 cl->cl_ops = clnt_dg_ops();
286 cl->cl_private = (caddr_t)(void *)cu;
287 cl->cl_auth = authnone_create();
291 EV_SET(&cu->cu_kin, cu->cu_fd, EVFILT_READ, EV_ADD, 0, 0, 0);
294 warnx(mem_err_clnt_dg);
295 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
296 rpc_createerr.cf_error.re_errno = errno;
299 mem_free(cl, sizeof (CLIENT));
301 mem_free(cu, sizeof (*cu) + sendsz + recvsz);
308 * proc - procedure number
309 * xargs - xdr routine for args
310 * argsp - pointer to args
311 * xresults - xdr routine for results
312 * resultsp - pointer to results
313 * utimeout - seconds to wait before giving up
315 static enum clnt_stat
316 clnt_dg_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xargs, void *argsp,
317 xdrproc_t xresults, void *resultsp, struct timeval utimeout)
319 struct cu_data *cu = (struct cu_data *)cl->cl_private;
322 struct rpc_msg reply_msg;
325 int nrefreshes = 2; /* number of times to refresh cred */
326 int nretries = 0; /* number of times we retransmitted */
327 struct timeval timeout;
328 struct timeval retransmit_time;
329 struct timeval next_sendtime, starttime, time_waited, tv;
337 int kin_len, n, rpc_lock_value;
341 sigfillset(&newmask);
342 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
343 mutex_lock(&clnt_fd_lock);
344 while (dg_fd_locks[cu->cu_fd])
345 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
350 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
351 mutex_unlock(&clnt_fd_lock);
352 if (cu->cu_total.tv_usec == -1) {
353 timeout = utimeout; /* use supplied timeout */
355 timeout = cu->cu_total; /* use default timeout */
358 if (cu->cu_connect && !cu->cu_connected) {
359 if (_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
361 cu->cu_error.re_errno = errno;
362 cu->cu_error.re_status = RPC_CANTSEND;
365 cu->cu_connected = 1;
367 if (cu->cu_connected) {
371 sa = (struct sockaddr *)&cu->cu_raddr;
374 time_waited.tv_sec = 0;
375 time_waited.tv_usec = 0;
376 retransmit_time = next_sendtime = cu->cu_wait;
377 gettimeofday(&starttime, NULL);
379 /* Clean up in case the last call ended in a longjmp(3) call. */
382 if ((cu->cu_kq = kqueue()) < 0) {
383 cu->cu_error.re_errno = errno;
384 cu->cu_error.re_status = RPC_CANTSEND;
390 if (cu->cu_async == TRUE && xargs == NULL)
393 * the transaction is the first thing in the out buffer
394 * XXX Yes, and it's in network byte order, so we should to
395 * be careful when we increment it, shouldn't we.
397 xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr));
399 *(u_int32_t *)(void *)(cu->cu_outhdr) = htonl(xid);
401 xdrs = &(cu->cu_outxdrs);
402 xdrs->x_op = XDR_ENCODE;
405 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
406 if ((! XDR_PUTBYTES(xdrs, cu->cu_outhdr, cu->cu_xdrpos)) ||
407 (! XDR_PUTINT32(xdrs, &proc)) ||
408 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
409 (! (*xargs)(xdrs, argsp))) {
410 cu->cu_error.re_status = RPC_CANTENCODEARGS;
414 *(uint32_t *) &cu->cu_outhdr[cu->cu_xdrpos] = htonl(proc);
415 if (!__rpc_gss_wrap(cl->cl_auth, cu->cu_outhdr,
416 cu->cu_xdrpos + sizeof(uint32_t),
417 xdrs, xargs, argsp)) {
418 cu->cu_error.re_status = RPC_CANTENCODEARGS;
422 outlen = (size_t)XDR_GETPOS(xdrs);
425 if (_sendto(cu->cu_fd, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) {
426 cu->cu_error.re_errno = errno;
427 cu->cu_error.re_status = RPC_CANTSEND;
432 * Hack to provide rpc-based message passing
434 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
435 cu->cu_error.re_status = RPC_TIMEDOUT;
442 * sub-optimal code appears here because we have
443 * some clock time to spare while the packets are in flight.
444 * (We assume that this is actually only executed once.)
446 reply_msg.acpted_rply.ar_verf = _null_auth;
447 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
448 reply_msg.acpted_rply.ar_results.where = resultsp;
449 reply_msg.acpted_rply.ar_results.proc = xresults;
451 reply_msg.acpted_rply.ar_results.where = NULL;
452 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
456 /* Decide how long to wait. */
457 if (timercmp(&next_sendtime, &timeout, <))
458 timersub(&next_sendtime, &time_waited, &tv);
460 timersub(&timeout, &time_waited, &tv);
461 if (tv.tv_sec < 0 || tv.tv_usec < 0)
462 tv.tv_sec = tv.tv_usec = 0;
463 TIMEVAL_TO_TIMESPEC(&tv, &ts);
465 n = _kevent(cu->cu_kq, &cu->cu_kin, kin_len, &kv, 1, &ts);
466 /* We don't need to register the event again. */
470 if (kv.flags & EV_ERROR) {
471 cu->cu_error.re_errno = kv.data;
472 cu->cu_error.re_status = RPC_CANTRECV;
475 /* We have some data now */
477 recvlen = _recvfrom(cu->cu_fd, cu->cu_inbuf,
478 cu->cu_recvsz, 0, NULL, NULL);
479 } while (recvlen < 0 && errno == EINTR);
480 if (recvlen < 0 && errno != EWOULDBLOCK) {
481 cu->cu_error.re_errno = errno;
482 cu->cu_error.re_status = RPC_CANTRECV;
485 if (recvlen >= sizeof(u_int32_t) &&
486 (cu->cu_async == TRUE ||
487 *((u_int32_t *)(void *)(cu->cu_inbuf)) ==
488 *((u_int32_t *)(void *)(cu->cu_outbuf)))) {
489 /* We now assume we have the proper reply. */
493 if (n == -1 && errno != EINTR) {
494 cu->cu_error.re_errno = errno;
495 cu->cu_error.re_status = RPC_CANTRECV;
498 gettimeofday(&tv, NULL);
499 timersub(&tv, &starttime, &time_waited);
501 /* Check for timeout. */
502 if (timercmp(&time_waited, &timeout, >)) {
503 cu->cu_error.re_status = RPC_TIMEDOUT;
507 /* Retransmit if necessary. */
508 if (timercmp(&time_waited, &next_sendtime, >)) {
509 /* update retransmit_time */
510 if (retransmit_time.tv_sec < RPC_MAX_BACKOFF)
511 timeradd(&retransmit_time, &retransmit_time,
513 timeradd(&next_sendtime, &retransmit_time,
518 * When retransmitting a RPCSEC_GSS message,
519 * we must use a new sequence number (handled
520 * by __rpc_gss_wrap above).
522 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS)
525 goto call_again_same_xid;
530 * now decode and validate the response
533 xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
534 ok = xdr_replymsg(&reply_xdrs, &reply_msg);
535 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
537 if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
538 (reply_msg.acpted_rply.ar_stat == SUCCESS))
539 cu->cu_error.re_status = RPC_SUCCESS;
541 _seterr_reply(&reply_msg, &(cu->cu_error));
543 if (cu->cu_error.re_status == RPC_SUCCESS) {
544 if (! AUTH_VALIDATE(cl->cl_auth,
545 &reply_msg.acpted_rply.ar_verf)) {
547 cl->cl_auth->ah_cred.oa_flavor
550 * If we retransmitted, its
551 * possible that we will
552 * receive a reply for one of
553 * the earlier transmissions
554 * (which will use an older
555 * RPCSEC_GSS sequence
556 * number). In this case, just
557 * go back and listen for a
558 * new reply. We could keep a
559 * record of all the seq
560 * numbers we have transmitted
561 * so far so that we could
562 * accept a reply for any of
566 cu->cu_error.re_status = RPC_AUTHERROR;
567 cu->cu_error.re_why = AUTH_INVALIDRESP;
569 if (cl->cl_auth->ah_cred.oa_flavor
571 if (!__rpc_gss_unwrap(cl->cl_auth,
572 &reply_xdrs, xresults,
574 cu->cu_error.re_status =
578 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
579 xdrs->x_op = XDR_FREE;
580 (void) xdr_opaque_auth(xdrs,
581 &(reply_msg.acpted_rply.ar_verf));
583 } /* end successful completion */
585 * If unsuccessful AND error is an authentication error
586 * then refresh credentials and try again, else break
588 else if (cu->cu_error.re_status == RPC_AUTHERROR)
589 /* maybe our credentials need to be refreshed ... */
590 if (nrefreshes > 0 &&
591 AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
595 /* end of unsuccessful completion */
596 } /* end of valid reply message */
598 cu->cu_error.re_status = RPC_CANTDECODERES;
605 release_fd_lock(cu->cu_fd, mask);
606 return (cu->cu_error.re_status);
610 clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp)
612 struct cu_data *cu = (struct cu_data *)cl->cl_private;
614 *errp = cu->cu_error;
618 clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
620 struct cu_data *cu = (struct cu_data *)cl->cl_private;
621 XDR *xdrs = &(cu->cu_outxdrs);
626 sigfillset(&newmask);
627 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
628 mutex_lock(&clnt_fd_lock);
629 while (dg_fd_locks[cu->cu_fd])
630 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
631 xdrs->x_op = XDR_FREE;
632 dummy = (*xdr_res)(xdrs, res_ptr);
633 mutex_unlock(&clnt_fd_lock);
634 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
635 cond_signal(&dg_cv[cu->cu_fd]);
641 clnt_dg_abort(CLIENT *h)
646 clnt_dg_control(CLIENT *cl, u_int request, void *info)
648 struct cu_data *cu = (struct cu_data *)cl->cl_private;
654 sigfillset(&newmask);
655 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
656 mutex_lock(&clnt_fd_lock);
657 while (dg_fd_locks[cu->cu_fd])
658 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
663 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
664 mutex_unlock(&clnt_fd_lock);
667 cu->cu_closeit = TRUE;
668 release_fd_lock(cu->cu_fd, mask);
670 case CLSET_FD_NCLOSE:
671 cu->cu_closeit = FALSE;
672 release_fd_lock(cu->cu_fd, mask);
676 /* for other requests which use info */
678 release_fd_lock(cu->cu_fd, mask);
683 if (time_not_ok((struct timeval *)info)) {
684 release_fd_lock(cu->cu_fd, mask);
687 cu->cu_total = *(struct timeval *)info;
690 *(struct timeval *)info = cu->cu_total;
692 case CLGET_SERVER_ADDR: /* Give him the fd address */
693 /* Now obsolete. Only for backward compatibility */
694 (void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
696 case CLSET_RETRY_TIMEOUT:
697 if (time_not_ok((struct timeval *)info)) {
698 release_fd_lock(cu->cu_fd, mask);
701 cu->cu_wait = *(struct timeval *)info;
703 case CLGET_RETRY_TIMEOUT:
704 *(struct timeval *)info = cu->cu_wait;
707 *(int *)info = cu->cu_fd;
710 addr = (struct netbuf *)info;
711 addr->buf = &cu->cu_raddr;
712 addr->len = cu->cu_rlen;
713 addr->maxlen = sizeof cu->cu_raddr;
715 case CLSET_SVC_ADDR: /* set to new address */
716 addr = (struct netbuf *)info;
717 if (addr->len < sizeof cu->cu_raddr) {
718 release_fd_lock(cu->cu_fd, mask);
721 (void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
722 cu->cu_rlen = addr->len;
726 * use the knowledge that xid is the
727 * first element in the call structure *.
728 * This will get the xid of the PREVIOUS call
731 ntohl(*(u_int32_t *)(void *)cu->cu_outhdr);
735 /* This will set the xid of the NEXT call */
736 *(u_int32_t *)(void *)cu->cu_outhdr =
737 htonl(*(u_int32_t *)info - 1);
738 /* decrement by 1 as clnt_dg_call() increments once */
743 * This RELIES on the information that, in the call body,
744 * the version number field is the fifth field from the
745 * beginning of the RPC header. MUST be changed if the
746 * call_struct is changed
749 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
750 4 * BYTES_PER_XDR_UNIT));
754 *(u_int32_t *)(void *)(cu->cu_outhdr + 4 * BYTES_PER_XDR_UNIT)
755 = htonl(*(u_int32_t *)info);
760 * This RELIES on the information that, in the call body,
761 * the program number field is the fourth field from the
762 * beginning of the RPC header. MUST be changed if the
763 * call_struct is changed
766 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
767 3 * BYTES_PER_XDR_UNIT));
771 *(u_int32_t *)(void *)(cu->cu_outhdr + 3 * BYTES_PER_XDR_UNIT)
772 = htonl(*(u_int32_t *)info);
775 cu->cu_async = *(int *)info;
778 cu->cu_connect = *(int *)info;
781 release_fd_lock(cu->cu_fd, mask);
784 release_fd_lock(cu->cu_fd, mask);
789 clnt_dg_destroy(CLIENT *cl)
791 struct cu_data *cu = (struct cu_data *)cl->cl_private;
792 int cu_fd = cu->cu_fd;
796 sigfillset(&newmask);
797 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
798 mutex_lock(&clnt_fd_lock);
799 while (dg_fd_locks[cu_fd])
800 cond_wait(&dg_cv[cu_fd], &clnt_fd_lock);
805 XDR_DESTROY(&(cu->cu_outxdrs));
806 mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
807 if (cl->cl_netid && cl->cl_netid[0])
808 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
809 if (cl->cl_tp && cl->cl_tp[0])
810 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
811 mem_free(cl, sizeof (CLIENT));
812 mutex_unlock(&clnt_fd_lock);
813 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
814 cond_signal(&dg_cv[cu_fd]);
817 static struct clnt_ops *
820 static struct clnt_ops ops;
824 /* VARIABLES PROTECTED BY ops_lock: ops */
826 sigfillset(&newmask);
827 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
828 mutex_lock(&ops_lock);
829 if (ops.cl_call == NULL) {
830 ops.cl_call = clnt_dg_call;
831 ops.cl_abort = clnt_dg_abort;
832 ops.cl_geterr = clnt_dg_geterr;
833 ops.cl_freeres = clnt_dg_freeres;
834 ops.cl_destroy = clnt_dg_destroy;
835 ops.cl_control = clnt_dg_control;
837 mutex_unlock(&ops_lock);
838 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
843 * Make sure that the time is not garbage. -1 value is allowed.
846 time_not_ok(struct timeval *t)
848 return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
849 t->tv_usec < -1 || t->tv_usec > 1000000);