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.
37 * Implements a connectionless client side RPC.
40 #include "namespace.h"
41 #include "reentrant.h"
42 #include <sys/types.h>
43 #include <sys/event.h>
45 #include <sys/socket.h>
46 #include <sys/ioctl.h>
48 #include <arpa/inet.h>
50 #include <rpc/rpcsec_gss.h>
60 #include "un-namespace.h"
65 #ifdef _FREEFALL_CONFIG
67 * Disable RPC exponential back-off for FreeBSD.org systems.
69 #define RPC_MAX_BACKOFF 1 /* second */
71 #define RPC_MAX_BACKOFF 30 /* seconds */
75 static struct clnt_ops *clnt_dg_ops(void);
76 static bool_t time_not_ok(struct timeval *);
77 static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
78 xdrproc_t, void *, struct timeval);
79 static void clnt_dg_geterr(CLIENT *, struct rpc_err *);
80 static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *);
81 static void clnt_dg_abort(CLIENT *);
82 static bool_t clnt_dg_control(CLIENT *, u_int, void *);
83 static void clnt_dg_destroy(CLIENT *);
89 * This machinery implements per-fd locks for MT-safety. It is not
90 * sufficient to do per-CLIENT handle locks for MT-safety because a
91 * user may create more than one CLIENT handle with the same fd behind
92 * it. Therefore, we allocate an associative array of flags and condition
93 * variables (dg_fd). The flags and the array are protected by the
94 * clnt_fd_lock mutex. dg_fd[fd].lock == 1 => a call is active on some
95 * CLIENT handle created for that fd. The current implementation holds
96 * locks across the entire RPC and reply, including retransmissions. Yes,
97 * this is silly, and as soon as this code is proven to work, this should
98 * be the first thing fixed. One step at a time.
101 RB_ENTRY(dg_fd) dg_link;
106 cmp_dg_fd(struct dg_fd *a, struct dg_fd *b)
110 } else if (a->fd < b->fd) {
116 RB_HEAD(dg_fd_list, dg_fd);
117 RB_PROTOTYPE(dg_fd_list, dg_fd, dg_link, cmp_dg_fd);
118 RB_GENERATE(dg_fd_list, dg_fd, dg_link, cmp_dg_fd);
119 struct dg_fd_list dg_fd_head = RB_INITIALIZER(&dg_fd_head);
122 * Find the lock structure for the given file descriptor, or initialize it if
123 * it does not already exist. The clnt_fd_lock mutex must be held.
125 static struct dg_fd *
128 struct dg_fd key, *elem;
131 elem = RB_FIND(dg_fd_list, &dg_fd_head, &key);
133 elem = calloc(1, sizeof(*elem));
135 mutex_init(&elem->mtx, NULL);
136 RB_INSERT(dg_fd_list, &dg_fd_head, elem);
142 release_fd_lock(struct dg_fd *elem, sigset_t mask)
144 mutex_unlock(&elem->mtx);
145 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
148 static const char mem_err_clnt_dg[] = "clnt_dg_create: out of memory";
150 /* VARIABLES PROTECTED BY clnt_fd_lock: dg_fd */
152 #define MCALL_MSG_SIZE 24
155 * Private data kept per client handle
158 int cu_fd; /* connections fd */
159 bool_t cu_closeit; /* opened by library */
160 struct sockaddr_storage cu_raddr; /* remote address */
162 struct timeval cu_wait; /* retransmit interval */
163 struct timeval cu_total; /* total time for the call */
164 struct rpc_err cu_error;
167 u_int cu_sendsz; /* send size */
168 char cu_outhdr[MCALL_MSG_SIZE];
170 u_int cu_recvsz; /* recv size */
172 int cu_connect; /* Use connect(). */
173 int cu_connected; /* Have done connect(). */
174 struct kevent cu_kin;
180 * Connection less client creation returns with client handle parameters.
181 * Default options are set, which the user can change using clnt_control().
182 * fd should be open and bound.
183 * NB: The rpch->cl_auth is initialized to null authentication.
184 * Caller may wish to set this something more useful.
186 * sendsz and recvsz are the maximum allowable packet sizes that can be
187 * sent and received. Normally they are the same, but they can be
188 * changed to improve the program efficiency and buffer allocation.
189 * If they are 0, use the transport default.
191 * If svcaddr is NULL, returns NULL.
193 * fd - open file descriptor
194 * svcaddr - servers address
195 * program - program number
196 * version - version number
197 * sendsz - buffer recv size
198 * recvsz - buffer send size
201 clnt_dg_create(int fd, const struct netbuf *svcaddr, rpcprog_t program,
202 rpcvers_t version, u_int sendsz, u_int recvsz)
204 CLIENT *cl = NULL; /* client handle */
205 struct cu_data *cu = NULL; /* private data */
207 struct rpc_msg call_msg;
208 struct __rpc_sockinfo si;
211 if (svcaddr == NULL) {
212 rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
216 if (!__rpc_fd2sockinfo(fd, &si)) {
217 rpc_createerr.cf_stat = RPC_TLIERROR;
218 rpc_createerr.cf_error.re_errno = 0;
222 * Find the receive and the send size
224 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
225 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
226 if ((sendsz == 0) || (recvsz == 0)) {
227 rpc_createerr.cf_stat = RPC_TLIERROR; /* XXX */
228 rpc_createerr.cf_error.re_errno = 0;
232 if ((cl = mem_alloc(sizeof (CLIENT))) == NULL)
235 * Should be multiple of 4 for XDR.
237 sendsz = ((sendsz + 3) / 4) * 4;
238 recvsz = ((recvsz + 3) / 4) * 4;
239 cu = mem_alloc(sizeof (*cu) + sendsz + recvsz);
242 (void) memcpy(&cu->cu_raddr, svcaddr->buf, (size_t)svcaddr->len);
243 cu->cu_rlen = svcaddr->len;
244 cu->cu_outbuf = &cu->cu_inbuf[recvsz];
245 /* Other values can also be set through clnt_control() */
246 cu->cu_wait.tv_sec = 15; /* heuristically chosen */
247 cu->cu_wait.tv_usec = 0;
248 cu->cu_total.tv_sec = -1;
249 cu->cu_total.tv_usec = -1;
250 cu->cu_sendsz = sendsz;
251 cu->cu_recvsz = recvsz;
252 cu->cu_async = FALSE;
253 cu->cu_connect = FALSE;
254 cu->cu_connected = FALSE;
255 (void) gettimeofday(&now, NULL);
256 call_msg.rm_xid = __RPC_GETXID(&now);
257 call_msg.rm_call.cb_prog = program;
258 call_msg.rm_call.cb_vers = version;
259 xdrmem_create(&(cu->cu_outxdrs), cu->cu_outhdr, MCALL_MSG_SIZE,
261 if (! xdr_callhdr(&cu->cu_outxdrs, &call_msg)) {
262 rpc_createerr.cf_stat = RPC_CANTENCODEARGS; /* XXX */
263 rpc_createerr.cf_error.re_errno = 0;
266 cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
267 XDR_DESTROY(&cu->cu_outxdrs);
268 xdrmem_create(&cu->cu_outxdrs, cu->cu_outbuf, sendsz, XDR_ENCODE);
270 /* XXX fvdl - do we still want this? */
272 (void)bindresvport_sa(fd, (struct sockaddr *)svcaddr->buf);
274 _ioctl(fd, FIONBIO, (char *)(void *)&one);
277 * By default, closeit is always FALSE. It is users responsibility
278 * to do a close on it, else the user may use clnt_control
279 * to let clnt_destroy do it for him/her.
281 cu->cu_closeit = FALSE;
283 cl->cl_ops = clnt_dg_ops();
284 cl->cl_private = (caddr_t)(void *)cu;
285 cl->cl_auth = authnone_create();
289 EV_SET(&cu->cu_kin, cu->cu_fd, EVFILT_READ, EV_ADD, 0, 0, 0);
292 warnx(mem_err_clnt_dg);
293 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
294 rpc_createerr.cf_error.re_errno = errno;
297 mem_free(cl, sizeof (CLIENT));
299 mem_free(cu, sizeof (*cu) + sendsz + recvsz);
306 * proc - procedure number
307 * xargs - xdr routine for args
308 * argsp - pointer to args
309 * xresults - xdr routine for results
310 * resultsp - pointer to results
311 * utimeout - seconds to wait before giving up
313 static enum clnt_stat
314 clnt_dg_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xargs, void *argsp,
315 xdrproc_t xresults, void *resultsp, struct timeval utimeout)
317 struct cu_data *cu = (struct cu_data *)cl->cl_private;
320 struct rpc_msg reply_msg;
323 int nrefreshes = 2; /* number of times to refresh cred */
324 int nretries = 0; /* number of times we retransmitted */
325 struct timeval timeout;
326 struct timeval retransmit_time;
327 struct timeval next_sendtime, starttime, time_waited, tv;
340 sigfillset(&newmask);
341 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
342 mutex_lock(&clnt_fd_lock);
343 elem = dg_fd_find(cu->cu_fd);
344 mutex_unlock(&clnt_fd_lock);
345 mutex_lock(&elem->mtx);
346 if (cu->cu_total.tv_usec == -1) {
347 timeout = utimeout; /* use supplied timeout */
349 timeout = cu->cu_total; /* use default timeout */
352 if (cu->cu_connect && !cu->cu_connected) {
353 if (_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
355 cu->cu_error.re_errno = errno;
356 cu->cu_error.re_status = RPC_CANTSEND;
359 cu->cu_connected = 1;
361 if (cu->cu_connected) {
365 sa = (struct sockaddr *)&cu->cu_raddr;
368 time_waited.tv_sec = 0;
369 time_waited.tv_usec = 0;
370 retransmit_time = next_sendtime = cu->cu_wait;
371 gettimeofday(&starttime, NULL);
373 /* Clean up in case the last call ended in a longjmp(3) call. */
376 if ((cu->cu_kq = kqueue()) < 0) {
377 cu->cu_error.re_errno = errno;
378 cu->cu_error.re_status = RPC_CANTSEND;
384 if (cu->cu_async == TRUE && xargs == NULL)
387 * the transaction is the first thing in the out buffer
388 * XXX Yes, and it's in network byte order, so we should to
389 * be careful when we increment it, shouldn't we.
391 xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr));
393 *(u_int32_t *)(void *)(cu->cu_outhdr) = htonl(xid);
395 xdrs = &(cu->cu_outxdrs);
396 xdrs->x_op = XDR_ENCODE;
399 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
400 if ((! XDR_PUTBYTES(xdrs, cu->cu_outhdr, cu->cu_xdrpos)) ||
401 (! XDR_PUTINT32(xdrs, &proc)) ||
402 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
403 (! (*xargs)(xdrs, argsp))) {
404 cu->cu_error.re_status = RPC_CANTENCODEARGS;
408 *(uint32_t *) &cu->cu_outhdr[cu->cu_xdrpos] = htonl(proc);
409 if (!__rpc_gss_wrap(cl->cl_auth, cu->cu_outhdr,
410 cu->cu_xdrpos + sizeof(uint32_t),
411 xdrs, xargs, argsp)) {
412 cu->cu_error.re_status = RPC_CANTENCODEARGS;
416 outlen = (size_t)XDR_GETPOS(xdrs);
419 if (_sendto(cu->cu_fd, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) {
420 cu->cu_error.re_errno = errno;
421 cu->cu_error.re_status = RPC_CANTSEND;
426 * Hack to provide rpc-based message passing
428 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
429 cu->cu_error.re_status = RPC_TIMEDOUT;
436 * sub-optimal code appears here because we have
437 * some clock time to spare while the packets are in flight.
438 * (We assume that this is actually only executed once.)
440 reply_msg.acpted_rply.ar_verf = _null_auth;
441 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
442 reply_msg.acpted_rply.ar_results.where = resultsp;
443 reply_msg.acpted_rply.ar_results.proc = xresults;
445 reply_msg.acpted_rply.ar_results.where = NULL;
446 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
450 /* Decide how long to wait. */
451 if (timercmp(&next_sendtime, &timeout, <))
452 timersub(&next_sendtime, &time_waited, &tv);
454 timersub(&timeout, &time_waited, &tv);
455 if (tv.tv_sec < 0 || tv.tv_usec < 0)
456 tv.tv_sec = tv.tv_usec = 0;
457 TIMEVAL_TO_TIMESPEC(&tv, &ts);
459 n = _kevent(cu->cu_kq, &cu->cu_kin, kin_len, &kv, 1, &ts);
460 /* We don't need to register the event again. */
464 if (kv.flags & EV_ERROR) {
465 cu->cu_error.re_errno = kv.data;
466 cu->cu_error.re_status = RPC_CANTRECV;
469 /* We have some data now */
471 recvlen = _recvfrom(cu->cu_fd, cu->cu_inbuf,
472 cu->cu_recvsz, 0, NULL, NULL);
473 } while (recvlen < 0 && errno == EINTR);
474 if (recvlen < 0 && errno != EWOULDBLOCK) {
475 cu->cu_error.re_errno = errno;
476 cu->cu_error.re_status = RPC_CANTRECV;
479 if (recvlen >= sizeof(u_int32_t) &&
480 (cu->cu_async == TRUE ||
481 *((u_int32_t *)(void *)(cu->cu_inbuf)) ==
482 *((u_int32_t *)(void *)(cu->cu_outbuf)))) {
483 /* We now assume we have the proper reply. */
487 if (n == -1 && errno != EINTR) {
488 cu->cu_error.re_errno = errno;
489 cu->cu_error.re_status = RPC_CANTRECV;
492 gettimeofday(&tv, NULL);
493 timersub(&tv, &starttime, &time_waited);
495 /* Check for timeout. */
496 if (timercmp(&time_waited, &timeout, >)) {
497 cu->cu_error.re_status = RPC_TIMEDOUT;
501 /* Retransmit if necessary. */
502 if (timercmp(&time_waited, &next_sendtime, >)) {
503 /* update retransmit_time */
504 if (retransmit_time.tv_sec < RPC_MAX_BACKOFF)
505 timeradd(&retransmit_time, &retransmit_time,
507 timeradd(&next_sendtime, &retransmit_time,
512 * When retransmitting a RPCSEC_GSS message,
513 * we must use a new sequence number (handled
514 * by __rpc_gss_wrap above).
516 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS)
519 goto call_again_same_xid;
524 * now decode and validate the response
527 xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
528 ok = xdr_replymsg(&reply_xdrs, &reply_msg);
529 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
531 if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
532 (reply_msg.acpted_rply.ar_stat == SUCCESS))
533 cu->cu_error.re_status = RPC_SUCCESS;
535 _seterr_reply(&reply_msg, &(cu->cu_error));
537 if (cu->cu_error.re_status == RPC_SUCCESS) {
538 if (! AUTH_VALIDATE(cl->cl_auth,
539 &reply_msg.acpted_rply.ar_verf)) {
541 cl->cl_auth->ah_cred.oa_flavor
544 * If we retransmitted, its
545 * possible that we will
546 * receive a reply for one of
547 * the earlier transmissions
548 * (which will use an older
549 * RPCSEC_GSS sequence
550 * number). In this case, just
551 * go back and listen for a
552 * new reply. We could keep a
553 * record of all the seq
554 * numbers we have transmitted
555 * so far so that we could
556 * accept a reply for any of
560 cu->cu_error.re_status = RPC_AUTHERROR;
561 cu->cu_error.re_why = AUTH_INVALIDRESP;
563 if (cl->cl_auth->ah_cred.oa_flavor
565 if (!__rpc_gss_unwrap(cl->cl_auth,
566 &reply_xdrs, xresults,
568 cu->cu_error.re_status =
572 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
573 xdrs->x_op = XDR_FREE;
574 (void) xdr_opaque_auth(xdrs,
575 &(reply_msg.acpted_rply.ar_verf));
577 } /* end successful completion */
579 * If unsuccessful AND error is an authentication error
580 * then refresh credentials and try again, else break
582 else if (cu->cu_error.re_status == RPC_AUTHERROR)
583 /* maybe our credentials need to be refreshed ... */
584 if (nrefreshes > 0 &&
585 AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
589 /* end of unsuccessful completion */
590 } /* end of valid reply message */
592 cu->cu_error.re_status = RPC_CANTDECODERES;
599 release_fd_lock(elem, mask);
600 return (cu->cu_error.re_status);
604 clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp)
606 struct cu_data *cu = (struct cu_data *)cl->cl_private;
608 *errp = cu->cu_error;
612 clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
614 struct cu_data *cu = (struct cu_data *)cl->cl_private;
616 XDR *xdrs = &(cu->cu_outxdrs);
621 sigfillset(&newmask);
622 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
623 mutex_lock(&clnt_fd_lock);
624 elem = dg_fd_find(cu->cu_fd);
625 mutex_lock(&elem->mtx);
626 xdrs->x_op = XDR_FREE;
627 dummy = (*xdr_res)(xdrs, res_ptr);
628 mutex_unlock(&clnt_fd_lock);
629 release_fd_lock(elem, mask);
635 clnt_dg_abort(CLIENT *h)
640 clnt_dg_control(CLIENT *cl, u_int request, void *info)
642 struct cu_data *cu = (struct cu_data *)cl->cl_private;
648 sigfillset(&newmask);
649 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
650 mutex_lock(&clnt_fd_lock);
651 elem = dg_fd_find(cu->cu_fd);
652 mutex_unlock(&clnt_fd_lock);
653 mutex_lock(&elem->mtx);
656 cu->cu_closeit = TRUE;
657 release_fd_lock(elem, mask);
659 case CLSET_FD_NCLOSE:
660 cu->cu_closeit = FALSE;
661 release_fd_lock(elem, mask);
665 /* for other requests which use info */
667 release_fd_lock(elem, mask);
672 if (time_not_ok((struct timeval *)info)) {
673 release_fd_lock(elem, mask);
676 cu->cu_total = *(struct timeval *)info;
679 *(struct timeval *)info = cu->cu_total;
681 case CLGET_SERVER_ADDR: /* Give him the fd address */
682 /* Now obsolete. Only for backward compatibility */
683 (void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
685 case CLSET_RETRY_TIMEOUT:
686 if (time_not_ok((struct timeval *)info)) {
687 release_fd_lock(elem, mask);
690 cu->cu_wait = *(struct timeval *)info;
692 case CLGET_RETRY_TIMEOUT:
693 *(struct timeval *)info = cu->cu_wait;
696 *(int *)info = cu->cu_fd;
699 addr = (struct netbuf *)info;
700 addr->buf = &cu->cu_raddr;
701 addr->len = cu->cu_rlen;
702 addr->maxlen = sizeof cu->cu_raddr;
704 case CLSET_SVC_ADDR: /* set to new address */
705 addr = (struct netbuf *)info;
706 if (addr->len < sizeof cu->cu_raddr) {
707 release_fd_lock(elem, mask);
710 (void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
711 cu->cu_rlen = addr->len;
715 * use the knowledge that xid is the
716 * first element in the call structure *.
717 * This will get the xid of the PREVIOUS call
720 ntohl(*(u_int32_t *)(void *)cu->cu_outhdr);
724 /* This will set the xid of the NEXT call */
725 *(u_int32_t *)(void *)cu->cu_outhdr =
726 htonl(*(u_int32_t *)info - 1);
727 /* decrement by 1 as clnt_dg_call() increments once */
732 * This RELIES on the information that, in the call body,
733 * the version number field is the fifth field from the
734 * beginning of the RPC header. MUST be changed if the
735 * call_struct is changed
738 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
739 4 * BYTES_PER_XDR_UNIT));
743 *(u_int32_t *)(void *)(cu->cu_outhdr + 4 * BYTES_PER_XDR_UNIT)
744 = htonl(*(u_int32_t *)info);
749 * This RELIES on the information that, in the call body,
750 * the program number field is the fourth field from the
751 * beginning of the RPC header. MUST be changed if the
752 * call_struct is changed
755 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
756 3 * BYTES_PER_XDR_UNIT));
760 *(u_int32_t *)(void *)(cu->cu_outhdr + 3 * BYTES_PER_XDR_UNIT)
761 = htonl(*(u_int32_t *)info);
764 cu->cu_async = *(int *)info;
767 cu->cu_connect = *(int *)info;
770 release_fd_lock(elem, mask);
773 release_fd_lock(elem, mask);
778 clnt_dg_destroy(CLIENT *cl)
780 struct cu_data *cu = (struct cu_data *)cl->cl_private;
782 int cu_fd = cu->cu_fd;
786 sigfillset(&newmask);
787 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
788 mutex_lock(&clnt_fd_lock);
789 elem = dg_fd_find(cu_fd);
790 mutex_lock(&elem->mtx);
795 XDR_DESTROY(&(cu->cu_outxdrs));
796 mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
797 if (cl->cl_netid && cl->cl_netid[0])
798 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
799 if (cl->cl_tp && cl->cl_tp[0])
800 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
801 mem_free(cl, sizeof (CLIENT));
802 mutex_unlock(&clnt_fd_lock);
803 release_fd_lock(elem, mask);
806 static struct clnt_ops *
809 static struct clnt_ops ops;
813 /* VARIABLES PROTECTED BY ops_lock: ops */
815 sigfillset(&newmask);
816 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
817 mutex_lock(&ops_lock);
818 if (ops.cl_call == NULL) {
819 ops.cl_call = clnt_dg_call;
820 ops.cl_abort = clnt_dg_abort;
821 ops.cl_geterr = clnt_dg_geterr;
822 ops.cl_freeres = clnt_dg_freeres;
823 ops.cl_destroy = clnt_dg_destroy;
824 ops.cl_control = clnt_dg_control;
826 mutex_unlock(&ops_lock);
827 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
832 * Make sure that the time is not garbage. -1 value is allowed.
835 time_not_ok(struct timeval *t)
837 return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
838 t->tv_usec < -1 || t->tv_usec > 1000000);