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";
41 * Implements a connectionless client side RPC.
44 #include "namespace.h"
45 #include "reentrant.h"
46 #include <sys/types.h>
47 #include <sys/event.h>
49 #include <sys/socket.h>
50 #include <sys/ioctl.h>
52 #include <arpa/inet.h>
54 #include <rpc/rpcsec_gss.h>
64 #include "un-namespace.h"
69 #ifdef _FREEFALL_CONFIG
71 * Disable RPC exponential back-off for FreeBSD.org systems.
73 #define RPC_MAX_BACKOFF 1 /* second */
75 #define RPC_MAX_BACKOFF 30 /* seconds */
79 static struct clnt_ops *clnt_dg_ops(void);
80 static bool_t time_not_ok(struct timeval *);
81 static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
82 xdrproc_t, void *, struct timeval);
83 static void clnt_dg_geterr(CLIENT *, struct rpc_err *);
84 static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *);
85 static void clnt_dg_abort(CLIENT *);
86 static bool_t clnt_dg_control(CLIENT *, u_int, void *);
87 static void clnt_dg_destroy(CLIENT *);
93 * This machinery implements per-fd locks for MT-safety. It is not
94 * sufficient to do per-CLIENT handle locks for MT-safety because a
95 * user may create more than one CLIENT handle with the same fd behind
96 * it. Therefore, we allocate an associative array of flags and condition
97 * variables (dg_fd). The flags and the array are protected by the
98 * clnt_fd_lock mutex. dg_fd[fd].lock == 1 => a call is active on some
99 * CLIENT handle created for that fd. The current implementation holds
100 * locks across the entire RPC and reply, including retransmissions. Yes,
101 * this is silly, and as soon as this code is proven to work, this should
102 * be the first thing fixed. One step at a time.
105 RB_ENTRY(dg_fd) dg_link;
110 cmp_dg_fd(struct dg_fd *a, struct dg_fd *b)
114 } else if (a->fd < b->fd) {
120 RB_HEAD(dg_fd_list, dg_fd);
121 RB_PROTOTYPE(dg_fd_list, dg_fd, dg_link, cmp_dg_fd);
122 RB_GENERATE(dg_fd_list, dg_fd, dg_link, cmp_dg_fd);
123 struct dg_fd_list dg_fd_head = RB_INITIALIZER(&dg_fd_head);
126 * Find the lock structure for the given file descriptor, or initialize it if
127 * it does not already exist. The clnt_fd_lock mutex must be held.
129 static struct dg_fd *
132 struct dg_fd key, *elem;
135 elem = RB_FIND(dg_fd_list, &dg_fd_head, &key);
137 elem = calloc(1, sizeof(*elem));
139 mutex_init(&elem->mtx, NULL);
140 RB_INSERT(dg_fd_list, &dg_fd_head, elem);
146 release_fd_lock(struct dg_fd *elem, sigset_t mask)
148 mutex_unlock(&elem->mtx);
149 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
152 static const char mem_err_clnt_dg[] = "clnt_dg_create: out of memory";
154 /* VARIABLES PROTECTED BY clnt_fd_lock: dg_fd */
156 #define MCALL_MSG_SIZE 24
159 * Private data kept per client handle
162 int cu_fd; /* connections fd */
163 bool_t cu_closeit; /* opened by library */
164 struct sockaddr_storage cu_raddr; /* remote address */
166 struct timeval cu_wait; /* retransmit interval */
167 struct timeval cu_total; /* total time for the call */
168 struct rpc_err cu_error;
171 u_int cu_sendsz; /* send size */
172 char cu_outhdr[MCALL_MSG_SIZE];
174 u_int cu_recvsz; /* recv size */
176 int cu_connect; /* Use connect(). */
177 int cu_connected; /* Have done connect(). */
178 struct kevent cu_kin;
184 * Connection less client creation returns with client handle parameters.
185 * Default options are set, which the user can change using clnt_control().
186 * fd should be open and bound.
187 * NB: The rpch->cl_auth is initialized to null authentication.
188 * Caller may wish to set this something more useful.
190 * sendsz and recvsz are the maximum allowable packet sizes that can be
191 * sent and received. Normally they are the same, but they can be
192 * changed to improve the program efficiency and buffer allocation.
193 * If they are 0, use the transport default.
195 * If svcaddr is NULL, returns NULL.
197 * fd - open file descriptor
198 * svcaddr - servers address
199 * program - program number
200 * version - version number
201 * sendsz - buffer recv size
202 * recvsz - buffer send size
205 clnt_dg_create(int fd, const struct netbuf *svcaddr, rpcprog_t program,
206 rpcvers_t version, u_int sendsz, u_int recvsz)
208 CLIENT *cl = NULL; /* client handle */
209 struct cu_data *cu = NULL; /* private data */
211 struct rpc_msg call_msg;
212 struct __rpc_sockinfo si;
215 if (svcaddr == NULL) {
216 rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
220 if (!__rpc_fd2sockinfo(fd, &si)) {
221 rpc_createerr.cf_stat = RPC_TLIERROR;
222 rpc_createerr.cf_error.re_errno = 0;
226 * Find the receive and the send size
228 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
229 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
230 if ((sendsz == 0) || (recvsz == 0)) {
231 rpc_createerr.cf_stat = RPC_TLIERROR; /* XXX */
232 rpc_createerr.cf_error.re_errno = 0;
236 if ((cl = mem_alloc(sizeof (CLIENT))) == NULL)
239 * Should be multiple of 4 for XDR.
241 sendsz = ((sendsz + 3) / 4) * 4;
242 recvsz = ((recvsz + 3) / 4) * 4;
243 cu = mem_alloc(sizeof (*cu) + sendsz + recvsz);
246 (void) memcpy(&cu->cu_raddr, svcaddr->buf, (size_t)svcaddr->len);
247 cu->cu_rlen = svcaddr->len;
248 cu->cu_outbuf = &cu->cu_inbuf[recvsz];
249 /* Other values can also be set through clnt_control() */
250 cu->cu_wait.tv_sec = 15; /* heuristically chosen */
251 cu->cu_wait.tv_usec = 0;
252 cu->cu_total.tv_sec = -1;
253 cu->cu_total.tv_usec = -1;
254 cu->cu_sendsz = sendsz;
255 cu->cu_recvsz = recvsz;
256 cu->cu_async = FALSE;
257 cu->cu_connect = FALSE;
258 cu->cu_connected = FALSE;
259 (void) gettimeofday(&now, NULL);
260 call_msg.rm_xid = __RPC_GETXID(&now);
261 call_msg.rm_call.cb_prog = program;
262 call_msg.rm_call.cb_vers = version;
263 xdrmem_create(&(cu->cu_outxdrs), cu->cu_outhdr, MCALL_MSG_SIZE,
265 if (! xdr_callhdr(&cu->cu_outxdrs, &call_msg)) {
266 rpc_createerr.cf_stat = RPC_CANTENCODEARGS; /* XXX */
267 rpc_createerr.cf_error.re_errno = 0;
270 cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
271 XDR_DESTROY(&cu->cu_outxdrs);
272 xdrmem_create(&cu->cu_outxdrs, cu->cu_outbuf, sendsz, XDR_ENCODE);
274 /* XXX fvdl - do we still want this? */
276 (void)bindresvport_sa(fd, (struct sockaddr *)svcaddr->buf);
278 _ioctl(fd, FIONBIO, (char *)(void *)&one);
281 * By default, closeit is always FALSE. It is users responsibility
282 * to do a close on it, else the user may use clnt_control
283 * to let clnt_destroy do it for him/her.
285 cu->cu_closeit = FALSE;
287 cl->cl_ops = clnt_dg_ops();
288 cl->cl_private = (caddr_t)(void *)cu;
289 cl->cl_auth = authnone_create();
293 EV_SET(&cu->cu_kin, cu->cu_fd, EVFILT_READ, EV_ADD, 0, 0, 0);
296 warnx(mem_err_clnt_dg);
297 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
298 rpc_createerr.cf_error.re_errno = errno;
301 mem_free(cl, sizeof (CLIENT));
303 mem_free(cu, sizeof (*cu) + sendsz + recvsz);
310 * proc - procedure number
311 * xargs - xdr routine for args
312 * argsp - pointer to args
313 * xresults - xdr routine for results
314 * resultsp - pointer to results
315 * utimeout - seconds to wait before giving up
317 static enum clnt_stat
318 clnt_dg_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xargs, void *argsp,
319 xdrproc_t xresults, void *resultsp, struct timeval utimeout)
321 struct cu_data *cu = (struct cu_data *)cl->cl_private;
324 struct rpc_msg reply_msg;
327 int nrefreshes = 2; /* number of times to refresh cred */
328 int nretries = 0; /* number of times we retransmitted */
329 struct timeval timeout;
330 struct timeval retransmit_time;
331 struct timeval next_sendtime, starttime, time_waited, tv;
344 sigfillset(&newmask);
345 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
346 mutex_lock(&clnt_fd_lock);
347 elem = dg_fd_find(cu->cu_fd);
348 mutex_unlock(&clnt_fd_lock);
349 mutex_lock(&elem->mtx);
350 if (cu->cu_total.tv_usec == -1) {
351 timeout = utimeout; /* use supplied timeout */
353 timeout = cu->cu_total; /* use default timeout */
356 if (cu->cu_connect && !cu->cu_connected) {
357 if (_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
359 cu->cu_error.re_errno = errno;
360 cu->cu_error.re_status = RPC_CANTSEND;
363 cu->cu_connected = 1;
365 if (cu->cu_connected) {
369 sa = (struct sockaddr *)&cu->cu_raddr;
372 time_waited.tv_sec = 0;
373 time_waited.tv_usec = 0;
374 retransmit_time = next_sendtime = cu->cu_wait;
375 gettimeofday(&starttime, NULL);
377 /* Clean up in case the last call ended in a longjmp(3) call. */
380 if ((cu->cu_kq = kqueue()) < 0) {
381 cu->cu_error.re_errno = errno;
382 cu->cu_error.re_status = RPC_CANTSEND;
388 if (cu->cu_async == TRUE && xargs == NULL)
391 * the transaction is the first thing in the out buffer
392 * XXX Yes, and it's in network byte order, so we should to
393 * be careful when we increment it, shouldn't we.
395 xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr));
397 *(u_int32_t *)(void *)(cu->cu_outhdr) = htonl(xid);
399 xdrs = &(cu->cu_outxdrs);
400 xdrs->x_op = XDR_ENCODE;
403 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
404 if ((! XDR_PUTBYTES(xdrs, cu->cu_outhdr, cu->cu_xdrpos)) ||
405 (! XDR_PUTINT32(xdrs, &proc)) ||
406 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
407 (! (*xargs)(xdrs, argsp))) {
408 cu->cu_error.re_status = RPC_CANTENCODEARGS;
412 *(uint32_t *) &cu->cu_outhdr[cu->cu_xdrpos] = htonl(proc);
413 if (!__rpc_gss_wrap(cl->cl_auth, cu->cu_outhdr,
414 cu->cu_xdrpos + sizeof(uint32_t),
415 xdrs, xargs, argsp)) {
416 cu->cu_error.re_status = RPC_CANTENCODEARGS;
420 outlen = (size_t)XDR_GETPOS(xdrs);
423 if (_sendto(cu->cu_fd, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) {
424 cu->cu_error.re_errno = errno;
425 cu->cu_error.re_status = RPC_CANTSEND;
430 * Hack to provide rpc-based message passing
432 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
433 cu->cu_error.re_status = RPC_TIMEDOUT;
440 * sub-optimal code appears here because we have
441 * some clock time to spare while the packets are in flight.
442 * (We assume that this is actually only executed once.)
444 reply_msg.acpted_rply.ar_verf = _null_auth;
445 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
446 reply_msg.acpted_rply.ar_results.where = resultsp;
447 reply_msg.acpted_rply.ar_results.proc = xresults;
449 reply_msg.acpted_rply.ar_results.where = NULL;
450 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
454 /* Decide how long to wait. */
455 if (timercmp(&next_sendtime, &timeout, <))
456 timersub(&next_sendtime, &time_waited, &tv);
458 timersub(&timeout, &time_waited, &tv);
459 if (tv.tv_sec < 0 || tv.tv_usec < 0)
460 tv.tv_sec = tv.tv_usec = 0;
461 TIMEVAL_TO_TIMESPEC(&tv, &ts);
463 n = _kevent(cu->cu_kq, &cu->cu_kin, kin_len, &kv, 1, &ts);
464 /* We don't need to register the event again. */
468 if (kv.flags & EV_ERROR) {
469 cu->cu_error.re_errno = kv.data;
470 cu->cu_error.re_status = RPC_CANTRECV;
473 /* We have some data now */
475 recvlen = _recvfrom(cu->cu_fd, cu->cu_inbuf,
476 cu->cu_recvsz, 0, NULL, NULL);
477 } while (recvlen < 0 && errno == EINTR);
478 if (recvlen < 0 && errno != EWOULDBLOCK) {
479 cu->cu_error.re_errno = errno;
480 cu->cu_error.re_status = RPC_CANTRECV;
483 if (recvlen >= sizeof(u_int32_t) &&
484 (cu->cu_async == TRUE ||
485 *((u_int32_t *)(void *)(cu->cu_inbuf)) ==
486 *((u_int32_t *)(void *)(cu->cu_outbuf)))) {
487 /* We now assume we have the proper reply. */
491 if (n == -1 && errno != EINTR) {
492 cu->cu_error.re_errno = errno;
493 cu->cu_error.re_status = RPC_CANTRECV;
496 gettimeofday(&tv, NULL);
497 timersub(&tv, &starttime, &time_waited);
499 /* Check for timeout. */
500 if (timercmp(&time_waited, &timeout, >)) {
501 cu->cu_error.re_status = RPC_TIMEDOUT;
505 /* Retransmit if necessary. */
506 if (timercmp(&time_waited, &next_sendtime, >)) {
507 /* update retransmit_time */
508 if (retransmit_time.tv_sec < RPC_MAX_BACKOFF)
509 timeradd(&retransmit_time, &retransmit_time,
511 timeradd(&next_sendtime, &retransmit_time,
516 * When retransmitting a RPCSEC_GSS message,
517 * we must use a new sequence number (handled
518 * by __rpc_gss_wrap above).
520 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS)
523 goto call_again_same_xid;
528 * now decode and validate the response
531 xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
532 ok = xdr_replymsg(&reply_xdrs, &reply_msg);
533 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
535 if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
536 (reply_msg.acpted_rply.ar_stat == SUCCESS))
537 cu->cu_error.re_status = RPC_SUCCESS;
539 _seterr_reply(&reply_msg, &(cu->cu_error));
541 if (cu->cu_error.re_status == RPC_SUCCESS) {
542 if (! AUTH_VALIDATE(cl->cl_auth,
543 &reply_msg.acpted_rply.ar_verf)) {
545 cl->cl_auth->ah_cred.oa_flavor
548 * If we retransmitted, its
549 * possible that we will
550 * receive a reply for one of
551 * the earlier transmissions
552 * (which will use an older
553 * RPCSEC_GSS sequence
554 * number). In this case, just
555 * go back and listen for a
556 * new reply. We could keep a
557 * record of all the seq
558 * numbers we have transmitted
559 * so far so that we could
560 * accept a reply for any of
564 cu->cu_error.re_status = RPC_AUTHERROR;
565 cu->cu_error.re_why = AUTH_INVALIDRESP;
567 if (cl->cl_auth->ah_cred.oa_flavor
569 if (!__rpc_gss_unwrap(cl->cl_auth,
570 &reply_xdrs, xresults,
572 cu->cu_error.re_status =
576 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
577 xdrs->x_op = XDR_FREE;
578 (void) xdr_opaque_auth(xdrs,
579 &(reply_msg.acpted_rply.ar_verf));
581 } /* end successful completion */
583 * If unsuccessful AND error is an authentication error
584 * then refresh credentials and try again, else break
586 else if (cu->cu_error.re_status == RPC_AUTHERROR)
587 /* maybe our credentials need to be refreshed ... */
588 if (nrefreshes > 0 &&
589 AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
593 /* end of unsuccessful completion */
594 } /* end of valid reply message */
596 cu->cu_error.re_status = RPC_CANTDECODERES;
603 release_fd_lock(elem, mask);
604 return (cu->cu_error.re_status);
608 clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp)
610 struct cu_data *cu = (struct cu_data *)cl->cl_private;
612 *errp = cu->cu_error;
616 clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
618 struct cu_data *cu = (struct cu_data *)cl->cl_private;
620 XDR *xdrs = &(cu->cu_outxdrs);
625 sigfillset(&newmask);
626 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
627 mutex_lock(&clnt_fd_lock);
628 elem = dg_fd_find(cu->cu_fd);
629 mutex_lock(&elem->mtx);
630 xdrs->x_op = XDR_FREE;
631 dummy = (*xdr_res)(xdrs, res_ptr);
632 mutex_unlock(&clnt_fd_lock);
633 release_fd_lock(elem, mask);
639 clnt_dg_abort(CLIENT *h)
644 clnt_dg_control(CLIENT *cl, u_int request, void *info)
646 struct cu_data *cu = (struct cu_data *)cl->cl_private;
652 sigfillset(&newmask);
653 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
654 mutex_lock(&clnt_fd_lock);
655 elem = dg_fd_find(cu->cu_fd);
656 mutex_unlock(&clnt_fd_lock);
657 mutex_lock(&elem->mtx);
660 cu->cu_closeit = TRUE;
661 release_fd_lock(elem, mask);
663 case CLSET_FD_NCLOSE:
664 cu->cu_closeit = FALSE;
665 release_fd_lock(elem, mask);
669 /* for other requests which use info */
671 release_fd_lock(elem, mask);
676 if (time_not_ok((struct timeval *)info)) {
677 release_fd_lock(elem, mask);
680 cu->cu_total = *(struct timeval *)info;
683 *(struct timeval *)info = cu->cu_total;
685 case CLGET_SERVER_ADDR: /* Give him the fd address */
686 /* Now obsolete. Only for backward compatibility */
687 (void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
689 case CLSET_RETRY_TIMEOUT:
690 if (time_not_ok((struct timeval *)info)) {
691 release_fd_lock(elem, mask);
694 cu->cu_wait = *(struct timeval *)info;
696 case CLGET_RETRY_TIMEOUT:
697 *(struct timeval *)info = cu->cu_wait;
700 *(int *)info = cu->cu_fd;
703 addr = (struct netbuf *)info;
704 addr->buf = &cu->cu_raddr;
705 addr->len = cu->cu_rlen;
706 addr->maxlen = sizeof cu->cu_raddr;
708 case CLSET_SVC_ADDR: /* set to new address */
709 addr = (struct netbuf *)info;
710 if (addr->len < sizeof cu->cu_raddr) {
711 release_fd_lock(elem, mask);
714 (void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
715 cu->cu_rlen = addr->len;
719 * use the knowledge that xid is the
720 * first element in the call structure *.
721 * This will get the xid of the PREVIOUS call
724 ntohl(*(u_int32_t *)(void *)cu->cu_outhdr);
728 /* This will set the xid of the NEXT call */
729 *(u_int32_t *)(void *)cu->cu_outhdr =
730 htonl(*(u_int32_t *)info - 1);
731 /* decrement by 1 as clnt_dg_call() increments once */
736 * This RELIES on the information that, in the call body,
737 * the version number field is the fifth field from the
738 * beginning of the RPC header. MUST be changed if the
739 * call_struct is changed
742 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
743 4 * BYTES_PER_XDR_UNIT));
747 *(u_int32_t *)(void *)(cu->cu_outhdr + 4 * BYTES_PER_XDR_UNIT)
748 = htonl(*(u_int32_t *)info);
753 * This RELIES on the information that, in the call body,
754 * the program number field is the fourth field from the
755 * beginning of the RPC header. MUST be changed if the
756 * call_struct is changed
759 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
760 3 * BYTES_PER_XDR_UNIT));
764 *(u_int32_t *)(void *)(cu->cu_outhdr + 3 * BYTES_PER_XDR_UNIT)
765 = htonl(*(u_int32_t *)info);
768 cu->cu_async = *(int *)info;
771 cu->cu_connect = *(int *)info;
774 release_fd_lock(elem, mask);
777 release_fd_lock(elem, mask);
782 clnt_dg_destroy(CLIENT *cl)
784 struct cu_data *cu = (struct cu_data *)cl->cl_private;
786 int cu_fd = cu->cu_fd;
790 sigfillset(&newmask);
791 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
792 mutex_lock(&clnt_fd_lock);
793 elem = dg_fd_find(cu_fd);
794 mutex_lock(&elem->mtx);
799 XDR_DESTROY(&(cu->cu_outxdrs));
800 mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
801 if (cl->cl_netid && cl->cl_netid[0])
802 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
803 if (cl->cl_tp && cl->cl_tp[0])
804 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
805 mem_free(cl, sizeof (CLIENT));
806 mutex_unlock(&clnt_fd_lock);
807 release_fd_lock(elem, mask);
810 static struct clnt_ops *
813 static struct clnt_ops ops;
817 /* VARIABLES PROTECTED BY ops_lock: ops */
819 sigfillset(&newmask);
820 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
821 mutex_lock(&ops_lock);
822 if (ops.cl_call == NULL) {
823 ops.cl_call = clnt_dg_call;
824 ops.cl_abort = clnt_dg_abort;
825 ops.cl_geterr = clnt_dg_geterr;
826 ops.cl_freeres = clnt_dg_freeres;
827 ops.cl_destroy = clnt_dg_destroy;
828 ops.cl_control = clnt_dg_control;
830 mutex_unlock(&ops_lock);
831 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
836 * Make sure that the time is not garbage. -1 value is allowed.
839 time_not_ok(struct timeval *t)
841 return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
842 t->tv_usec < -1 || t->tv_usec > 1000000);