1 /* $NetBSD: clnt_dg.c,v 1.4 2000/07/14 08:40:41 fvdl Exp $ */
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
35 #if defined(LIBC_SCCS) && !defined(lint)
36 #ident "@(#)clnt_dg.c 1.23 94/04/22 SMI"
37 static char sccsid[] = "@(#)clnt_dg.c 1.19 89/03/16 Copyr 1988 Sun Micro";
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
43 * Implements a connectionless client side RPC.
46 #include "namespace.h"
47 #include "reentrant.h"
48 #include <sys/types.h>
49 #include <sys/event.h>
51 #include <sys/socket.h>
52 #include <sys/ioctl.h>
53 #include <arpa/inet.h>
55 #include <rpc/rpcsec_gss.h>
62 #include "un-namespace.h"
67 #ifdef _FREEFALL_CONFIG
69 * Disable RPC exponential back-off for FreeBSD.org systems.
71 #define RPC_MAX_BACKOFF 1 /* second */
73 #define RPC_MAX_BACKOFF 30 /* seconds */
77 static struct clnt_ops *clnt_dg_ops(void);
78 static bool_t time_not_ok(struct timeval *);
79 static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
80 xdrproc_t, void *, struct timeval);
81 static void clnt_dg_geterr(CLIENT *, struct rpc_err *);
82 static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *);
83 static void clnt_dg_abort(CLIENT *);
84 static bool_t clnt_dg_control(CLIENT *, u_int, void *);
85 static void clnt_dg_destroy(CLIENT *);
91 * This machinery implements per-fd locks for MT-safety. It is not
92 * sufficient to do per-CLIENT handle locks for MT-safety because a
93 * user may create more than one CLIENT handle with the same fd behind
94 * it. Therfore, we allocate an array of flags (dg_fd_locks), protected
95 * by the clnt_fd_lock mutex, and an array (dg_cv) of condition variables
96 * similarly protected. Dg_fd_lock[fd] == 1 => a call is activte on some
97 * CLIENT handle created for that fd.
98 * The current implementation holds locks across the entire RPC and reply,
99 * including retransmissions. Yes, this is silly, and as soon as this
100 * code is proven to work, this should be the first thing fixed. One step
103 static int *dg_fd_locks;
104 static cond_t *dg_cv;
105 #define release_fd_lock(fd, mask) { \
106 mutex_lock(&clnt_fd_lock); \
107 dg_fd_locks[fd] = 0; \
108 mutex_unlock(&clnt_fd_lock); \
109 thr_sigsetmask(SIG_SETMASK, &(mask), NULL); \
110 cond_signal(&dg_cv[fd]); \
113 static const char mem_err_clnt_dg[] = "clnt_dg_create: out of memory";
115 /* VARIABLES PROTECTED BY clnt_fd_lock: dg_fd_locks, dg_cv */
117 #define MCALL_MSG_SIZE 24
120 * Private data kept per client handle
123 int cu_fd; /* connections fd */
124 bool_t cu_closeit; /* opened by library */
125 struct sockaddr_storage cu_raddr; /* remote address */
127 struct timeval cu_wait; /* retransmit interval */
128 struct timeval cu_total; /* total time for the call */
129 struct rpc_err cu_error;
132 u_int cu_sendsz; /* send size */
133 char cu_outhdr[MCALL_MSG_SIZE];
135 u_int cu_recvsz; /* recv size */
137 int cu_connect; /* Use connect(). */
138 int cu_connected; /* Have done connect(). */
139 struct kevent cu_kin;
145 * Connection less client creation returns with client handle parameters.
146 * Default options are set, which the user can change using clnt_control().
147 * fd should be open and bound.
148 * NB: The rpch->cl_auth is initialized to null authentication.
149 * Caller may wish to set this something more useful.
151 * sendsz and recvsz are the maximum allowable packet sizes that can be
152 * sent and received. Normally they are the same, but they can be
153 * changed to improve the program efficiency and buffer allocation.
154 * If they are 0, use the transport default.
156 * If svcaddr is NULL, returns NULL.
159 clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
160 int fd; /* open file descriptor */
161 const struct netbuf *svcaddr; /* servers address */
162 rpcprog_t program; /* program number */
163 rpcvers_t version; /* version number */
164 u_int sendsz; /* buffer recv size */
165 u_int recvsz; /* buffer send size */
167 CLIENT *cl = NULL; /* client handle */
168 struct cu_data *cu = NULL; /* private data */
170 struct rpc_msg call_msg;
173 struct __rpc_sockinfo si;
176 sigfillset(&newmask);
177 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
178 mutex_lock(&clnt_fd_lock);
179 if (dg_fd_locks == (int *) NULL) {
182 int dtbsize = __rpc_dtbsize();
184 fd_allocsz = dtbsize * sizeof (int);
185 dg_fd_locks = (int *) mem_alloc(fd_allocsz);
186 if (dg_fd_locks == (int *) NULL) {
187 mutex_unlock(&clnt_fd_lock);
188 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
191 memset(dg_fd_locks, '\0', fd_allocsz);
193 cv_allocsz = dtbsize * sizeof (cond_t);
194 dg_cv = (cond_t *) mem_alloc(cv_allocsz);
195 if (dg_cv == (cond_t *) NULL) {
196 mem_free(dg_fd_locks, fd_allocsz);
197 dg_fd_locks = (int *) NULL;
198 mutex_unlock(&clnt_fd_lock);
199 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
204 for (i = 0; i < dtbsize; i++)
205 cond_init(&dg_cv[i], 0, (void *) 0);
209 mutex_unlock(&clnt_fd_lock);
210 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
212 if (svcaddr == NULL) {
213 rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
217 if (!__rpc_fd2sockinfo(fd, &si)) {
218 rpc_createerr.cf_stat = RPC_TLIERROR;
219 rpc_createerr.cf_error.re_errno = 0;
223 * Find the receive and the send size
225 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
226 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
227 if ((sendsz == 0) || (recvsz == 0)) {
228 rpc_createerr.cf_stat = RPC_TLIERROR; /* XXX */
229 rpc_createerr.cf_error.re_errno = 0;
233 if ((cl = mem_alloc(sizeof (CLIENT))) == NULL)
236 * Should be multiple of 4 for XDR.
238 sendsz = ((sendsz + 3) / 4) * 4;
239 recvsz = ((recvsz + 3) / 4) * 4;
240 cu = mem_alloc(sizeof (*cu) + sendsz + recvsz);
243 (void) memcpy(&cu->cu_raddr, svcaddr->buf, (size_t)svcaddr->len);
244 cu->cu_rlen = svcaddr->len;
245 cu->cu_outbuf = &cu->cu_inbuf[recvsz];
246 /* Other values can also be set through clnt_control() */
247 cu->cu_wait.tv_sec = 15; /* heuristically chosen */
248 cu->cu_wait.tv_usec = 0;
249 cu->cu_total.tv_sec = -1;
250 cu->cu_total.tv_usec = -1;
251 cu->cu_sendsz = sendsz;
252 cu->cu_recvsz = recvsz;
253 cu->cu_async = FALSE;
254 cu->cu_connect = FALSE;
255 cu->cu_connected = FALSE;
256 (void) gettimeofday(&now, NULL);
257 call_msg.rm_xid = __RPC_GETXID(&now);
258 call_msg.rm_call.cb_prog = program;
259 call_msg.rm_call.cb_vers = version;
260 xdrmem_create(&(cu->cu_outxdrs), cu->cu_outhdr, MCALL_MSG_SIZE,
262 if (! xdr_callhdr(&cu->cu_outxdrs, &call_msg)) {
263 rpc_createerr.cf_stat = RPC_CANTENCODEARGS; /* XXX */
264 rpc_createerr.cf_error.re_errno = 0;
267 cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
268 XDR_DESTROY(&cu->cu_outxdrs);
269 xdrmem_create(&cu->cu_outxdrs, cu->cu_outbuf, sendsz, XDR_ENCODE);
271 /* XXX fvdl - do we still want this? */
273 (void)bindresvport_sa(fd, (struct sockaddr *)svcaddr->buf);
275 _ioctl(fd, FIONBIO, (char *)(void *)&one);
278 * By default, closeit is always FALSE. It is users responsibility
279 * to do a close on it, else the user may use clnt_control
280 * to let clnt_destroy do it for him/her.
282 cu->cu_closeit = FALSE;
284 cl->cl_ops = clnt_dg_ops();
285 cl->cl_private = (caddr_t)(void *)cu;
286 cl->cl_auth = authnone_create();
290 EV_SET(&cu->cu_kin, cu->cu_fd, EVFILT_READ, EV_ADD, 0, 0, 0);
293 warnx(mem_err_clnt_dg);
294 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
295 rpc_createerr.cf_error.re_errno = errno;
298 mem_free(cl, sizeof (CLIENT));
300 mem_free(cu, sizeof (*cu) + sendsz + recvsz);
305 static enum clnt_stat
306 clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
307 CLIENT *cl; /* client handle */
308 rpcproc_t proc; /* procedure number */
309 xdrproc_t xargs; /* xdr routine for args */
310 void *argsp; /* pointer to args */
311 xdrproc_t xresults; /* xdr routine for results */
312 void *resultsp; /* pointer to results */
313 struct timeval utimeout; /* seconds to wait before giving up */
315 struct cu_data *cu = (struct cu_data *)cl->cl_private;
318 struct rpc_msg reply_msg;
321 int nrefreshes = 2; /* number of times to refresh cred */
322 int nretries = 0; /* number of times we retransmitted */
323 struct timeval timeout;
324 struct timeval retransmit_time;
325 struct timeval next_sendtime, starttime, time_waited, tv;
331 socklen_t inlen, salen;
333 int kin_len, n, rpc_lock_value;
337 sigfillset(&newmask);
338 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
339 mutex_lock(&clnt_fd_lock);
340 while (dg_fd_locks[cu->cu_fd])
341 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
346 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
347 mutex_unlock(&clnt_fd_lock);
348 if (cu->cu_total.tv_usec == -1) {
349 timeout = utimeout; /* use supplied timeout */
351 timeout = cu->cu_total; /* use default timeout */
354 if (cu->cu_connect && !cu->cu_connected) {
355 if (_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
357 cu->cu_error.re_errno = errno;
358 cu->cu_error.re_status = RPC_CANTSEND;
361 cu->cu_connected = 1;
363 if (cu->cu_connected) {
367 sa = (struct sockaddr *)&cu->cu_raddr;
370 time_waited.tv_sec = 0;
371 time_waited.tv_usec = 0;
372 retransmit_time = next_sendtime = cu->cu_wait;
373 gettimeofday(&starttime, NULL);
375 /* Clean up in case the last call ended in a longjmp(3) call. */
378 if ((cu->cu_kq = kqueue()) < 0) {
379 cu->cu_error.re_errno = errno;
380 cu->cu_error.re_status = RPC_CANTSEND;
386 if (cu->cu_async == TRUE && xargs == NULL)
389 * the transaction is the first thing in the out buffer
390 * XXX Yes, and it's in network byte order, so we should to
391 * be careful when we increment it, shouldn't we.
393 xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr));
395 *(u_int32_t *)(void *)(cu->cu_outhdr) = htonl(xid);
397 xdrs = &(cu->cu_outxdrs);
398 xdrs->x_op = XDR_ENCODE;
401 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
402 if ((! XDR_PUTBYTES(xdrs, cu->cu_outhdr, cu->cu_xdrpos)) ||
403 (! XDR_PUTINT32(xdrs, &proc)) ||
404 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
405 (! (*xargs)(xdrs, argsp))) {
406 cu->cu_error.re_status = RPC_CANTENCODEARGS;
410 *(uint32_t *) &cu->cu_outhdr[cu->cu_xdrpos] = htonl(proc);
411 if (!__rpc_gss_wrap(cl->cl_auth, cu->cu_outhdr,
412 cu->cu_xdrpos + sizeof(uint32_t),
413 xdrs, xargs, argsp)) {
414 cu->cu_error.re_status = RPC_CANTENCODEARGS;
418 outlen = (size_t)XDR_GETPOS(xdrs);
421 if (_sendto(cu->cu_fd, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) {
422 cu->cu_error.re_errno = errno;
423 cu->cu_error.re_status = RPC_CANTSEND;
428 * Hack to provide rpc-based message passing
430 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
431 cu->cu_error.re_status = RPC_TIMEDOUT;
438 * sub-optimal code appears here because we have
439 * some clock time to spare while the packets are in flight.
440 * (We assume that this is actually only executed once.)
442 reply_msg.acpted_rply.ar_verf = _null_auth;
443 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
444 reply_msg.acpted_rply.ar_results.where = resultsp;
445 reply_msg.acpted_rply.ar_results.proc = xresults;
447 reply_msg.acpted_rply.ar_results.where = NULL;
448 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
452 /* Decide how long to wait. */
453 if (timercmp(&next_sendtime, &timeout, <))
454 timersub(&next_sendtime, &time_waited, &tv);
456 timersub(&timeout, &time_waited, &tv);
457 if (tv.tv_sec < 0 || tv.tv_usec < 0)
458 tv.tv_sec = tv.tv_usec = 0;
459 TIMEVAL_TO_TIMESPEC(&tv, &ts);
461 n = _kevent(cu->cu_kq, &cu->cu_kin, kin_len, &kv, 1, &ts);
462 /* We don't need to register the event again. */
466 if (kv.flags & EV_ERROR) {
467 cu->cu_error.re_errno = kv.data;
468 cu->cu_error.re_status = RPC_CANTRECV;
471 /* We have some data now */
473 recvlen = _recvfrom(cu->cu_fd, cu->cu_inbuf,
474 cu->cu_recvsz, 0, NULL, NULL);
475 } while (recvlen < 0 && errno == EINTR);
476 if (recvlen < 0 && errno != EWOULDBLOCK) {
477 cu->cu_error.re_errno = errno;
478 cu->cu_error.re_status = RPC_CANTRECV;
481 if (recvlen >= sizeof(u_int32_t) &&
482 (cu->cu_async == TRUE ||
483 *((u_int32_t *)(void *)(cu->cu_inbuf)) ==
484 *((u_int32_t *)(void *)(cu->cu_outbuf)))) {
485 /* We now assume we have the proper reply. */
489 if (n == -1 && errno != EINTR) {
490 cu->cu_error.re_errno = errno;
491 cu->cu_error.re_status = RPC_CANTRECV;
494 gettimeofday(&tv, NULL);
495 timersub(&tv, &starttime, &time_waited);
497 /* Check for timeout. */
498 if (timercmp(&time_waited, &timeout, >)) {
499 cu->cu_error.re_status = RPC_TIMEDOUT;
503 /* Retransmit if necessary. */
504 if (timercmp(&time_waited, &next_sendtime, >)) {
505 /* update retransmit_time */
506 if (retransmit_time.tv_sec < RPC_MAX_BACKOFF)
507 timeradd(&retransmit_time, &retransmit_time,
509 timeradd(&next_sendtime, &retransmit_time,
514 * When retransmitting a RPCSEC_GSS message,
515 * we must use a new sequence number (handled
516 * by __rpc_gss_wrap above).
518 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS)
521 goto call_again_same_xid;
524 inlen = (socklen_t)recvlen;
527 * now decode and validate the response
530 xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
531 ok = xdr_replymsg(&reply_xdrs, &reply_msg);
532 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
534 if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
535 (reply_msg.acpted_rply.ar_stat == SUCCESS))
536 cu->cu_error.re_status = RPC_SUCCESS;
538 _seterr_reply(&reply_msg, &(cu->cu_error));
540 if (cu->cu_error.re_status == RPC_SUCCESS) {
541 if (! AUTH_VALIDATE(cl->cl_auth,
542 &reply_msg.acpted_rply.ar_verf)) {
544 cl->cl_auth->ah_cred.oa_flavor
547 * If we retransmitted, its
548 * possible that we will
549 * receive a reply for one of
550 * the earlier transmissions
551 * (which will use an older
552 * RPCSEC_GSS sequence
553 * number). In this case, just
554 * go back and listen for a
555 * new reply. We could keep a
556 * record of all the seq
557 * numbers we have transmitted
558 * so far so that we could
559 * accept a reply for any of
563 cu->cu_error.re_status = RPC_AUTHERROR;
564 cu->cu_error.re_why = AUTH_INVALIDRESP;
566 if (cl->cl_auth->ah_cred.oa_flavor
568 if (!__rpc_gss_unwrap(cl->cl_auth,
569 &reply_xdrs, xresults,
571 cu->cu_error.re_status =
575 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
576 xdrs->x_op = XDR_FREE;
577 (void) xdr_opaque_auth(xdrs,
578 &(reply_msg.acpted_rply.ar_verf));
580 } /* end successful completion */
582 * If unsuccesful AND error is an authentication error
583 * then refresh credentials and try again, else break
585 else if (cu->cu_error.re_status == RPC_AUTHERROR)
586 /* maybe our credentials need to be refreshed ... */
587 if (nrefreshes > 0 &&
588 AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
592 /* end of unsuccessful completion */
593 } /* end of valid reply message */
595 cu->cu_error.re_status = RPC_CANTDECODERES;
602 release_fd_lock(cu->cu_fd, mask);
603 return (cu->cu_error.re_status);
607 clnt_dg_geterr(cl, errp)
609 struct rpc_err *errp;
611 struct cu_data *cu = (struct cu_data *)cl->cl_private;
613 *errp = cu->cu_error;
617 clnt_dg_freeres(cl, xdr_res, res_ptr)
622 struct cu_data *cu = (struct cu_data *)cl->cl_private;
623 XDR *xdrs = &(cu->cu_outxdrs);
628 sigfillset(&newmask);
629 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
630 mutex_lock(&clnt_fd_lock);
631 while (dg_fd_locks[cu->cu_fd])
632 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
633 xdrs->x_op = XDR_FREE;
634 dummy = (*xdr_res)(xdrs, res_ptr);
635 mutex_unlock(&clnt_fd_lock);
636 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
637 cond_signal(&dg_cv[cu->cu_fd]);
649 clnt_dg_control(cl, request, info)
654 struct cu_data *cu = (struct cu_data *)cl->cl_private;
660 sigfillset(&newmask);
661 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
662 mutex_lock(&clnt_fd_lock);
663 while (dg_fd_locks[cu->cu_fd])
664 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
669 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
670 mutex_unlock(&clnt_fd_lock);
673 cu->cu_closeit = TRUE;
674 release_fd_lock(cu->cu_fd, mask);
676 case CLSET_FD_NCLOSE:
677 cu->cu_closeit = FALSE;
678 release_fd_lock(cu->cu_fd, mask);
682 /* for other requests which use info */
684 release_fd_lock(cu->cu_fd, mask);
689 if (time_not_ok((struct timeval *)info)) {
690 release_fd_lock(cu->cu_fd, mask);
693 cu->cu_total = *(struct timeval *)info;
696 *(struct timeval *)info = cu->cu_total;
698 case CLGET_SERVER_ADDR: /* Give him the fd address */
699 /* Now obsolete. Only for backward compatibility */
700 (void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
702 case CLSET_RETRY_TIMEOUT:
703 if (time_not_ok((struct timeval *)info)) {
704 release_fd_lock(cu->cu_fd, mask);
707 cu->cu_wait = *(struct timeval *)info;
709 case CLGET_RETRY_TIMEOUT:
710 *(struct timeval *)info = cu->cu_wait;
713 *(int *)info = cu->cu_fd;
716 addr = (struct netbuf *)info;
717 addr->buf = &cu->cu_raddr;
718 addr->len = cu->cu_rlen;
719 addr->maxlen = sizeof cu->cu_raddr;
721 case CLSET_SVC_ADDR: /* set to new address */
722 addr = (struct netbuf *)info;
723 if (addr->len < sizeof cu->cu_raddr) {
724 release_fd_lock(cu->cu_fd, mask);
727 (void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
728 cu->cu_rlen = addr->len;
732 * use the knowledge that xid is the
733 * first element in the call structure *.
734 * This will get the xid of the PREVIOUS call
737 ntohl(*(u_int32_t *)(void *)cu->cu_outhdr);
741 /* This will set the xid of the NEXT call */
742 *(u_int32_t *)(void *)cu->cu_outhdr =
743 htonl(*(u_int32_t *)info - 1);
744 /* decrement by 1 as clnt_dg_call() increments once */
749 * This RELIES on the information that, in the call body,
750 * the version number field is the fifth field from the
751 * begining of the RPC header. MUST be changed if the
752 * call_struct is changed
755 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
756 4 * BYTES_PER_XDR_UNIT));
760 *(u_int32_t *)(void *)(cu->cu_outhdr + 4 * BYTES_PER_XDR_UNIT)
761 = htonl(*(u_int32_t *)info);
766 * This RELIES on the information that, in the call body,
767 * the program number field is the fourth field from the
768 * begining of the RPC header. MUST be changed if the
769 * call_struct is changed
772 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
773 3 * BYTES_PER_XDR_UNIT));
777 *(u_int32_t *)(void *)(cu->cu_outhdr + 3 * BYTES_PER_XDR_UNIT)
778 = htonl(*(u_int32_t *)info);
781 cu->cu_async = *(int *)info;
784 cu->cu_connect = *(int *)info;
787 release_fd_lock(cu->cu_fd, mask);
790 release_fd_lock(cu->cu_fd, mask);
798 struct cu_data *cu = (struct cu_data *)cl->cl_private;
799 int cu_fd = cu->cu_fd;
803 sigfillset(&newmask);
804 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
805 mutex_lock(&clnt_fd_lock);
806 while (dg_fd_locks[cu_fd])
807 cond_wait(&dg_cv[cu_fd], &clnt_fd_lock);
812 XDR_DESTROY(&(cu->cu_outxdrs));
813 mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
814 if (cl->cl_netid && cl->cl_netid[0])
815 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
816 if (cl->cl_tp && cl->cl_tp[0])
817 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
818 mem_free(cl, sizeof (CLIENT));
819 mutex_unlock(&clnt_fd_lock);
820 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
821 cond_signal(&dg_cv[cu_fd]);
824 static struct clnt_ops *
827 static struct clnt_ops ops;
831 /* VARIABLES PROTECTED BY ops_lock: ops */
833 sigfillset(&newmask);
834 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
835 mutex_lock(&ops_lock);
836 if (ops.cl_call == NULL) {
837 ops.cl_call = clnt_dg_call;
838 ops.cl_abort = clnt_dg_abort;
839 ops.cl_geterr = clnt_dg_geterr;
840 ops.cl_freeres = clnt_dg_freeres;
841 ops.cl_destroy = clnt_dg_destroy;
842 ops.cl_control = clnt_dg_control;
844 mutex_unlock(&ops_lock);
845 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
850 * Make sure that the time is not garbage. -1 value is allowed.
856 return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
857 t->tv_usec < -1 || t->tv_usec > 1000000);