1 /* $NetBSD: clnt_dg.c,v 1.4 2000/07/14 08:40:41 fvdl Exp $ */
4 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
34 #if defined(LIBC_SCCS) && !defined(lint)
35 #ident "@(#)clnt_dg.c 1.23 94/04/22 SMI"
36 static char sccsid[] = "@(#)clnt_dg.c 1.19 89/03/16 Copyr 1988 Sun Micro";
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
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. Therfore, 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 activte 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.
158 clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
159 int fd; /* open file descriptor */
160 const struct netbuf *svcaddr; /* servers address */
161 rpcprog_t program; /* program number */
162 rpcvers_t version; /* version number */
163 u_int sendsz; /* buffer recv size */
164 u_int recvsz; /* buffer send size */
166 CLIENT *cl = NULL; /* client handle */
167 struct cu_data *cu = NULL; /* private data */
169 struct rpc_msg call_msg;
172 struct __rpc_sockinfo si;
175 sigfillset(&newmask);
176 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
177 mutex_lock(&clnt_fd_lock);
178 if (dg_fd_locks == (int *) NULL) {
181 int dtbsize = __rpc_dtbsize();
183 fd_allocsz = dtbsize * sizeof (int);
184 dg_fd_locks = (int *) mem_alloc(fd_allocsz);
185 if (dg_fd_locks == (int *) NULL) {
186 mutex_unlock(&clnt_fd_lock);
187 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
190 memset(dg_fd_locks, '\0', fd_allocsz);
192 cv_allocsz = dtbsize * sizeof (cond_t);
193 dg_cv = (cond_t *) mem_alloc(cv_allocsz);
194 if (dg_cv == (cond_t *) NULL) {
195 mem_free(dg_fd_locks, fd_allocsz);
196 dg_fd_locks = (int *) NULL;
197 mutex_unlock(&clnt_fd_lock);
198 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
203 for (i = 0; i < dtbsize; i++)
204 cond_init(&dg_cv[i], 0, (void *) 0);
208 mutex_unlock(&clnt_fd_lock);
209 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
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);
304 static enum clnt_stat
305 clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
306 CLIENT *cl; /* client handle */
307 rpcproc_t proc; /* procedure number */
308 xdrproc_t xargs; /* xdr routine for args */
309 void *argsp; /* pointer to args */
310 xdrproc_t xresults; /* xdr routine for results */
311 void *resultsp; /* pointer to results */
312 struct timeval utimeout; /* seconds to wait before giving up */
314 struct cu_data *cu = (struct cu_data *)cl->cl_private;
317 struct rpc_msg reply_msg;
320 int nrefreshes = 2; /* number of times to refresh cred */
321 int nretries = 0; /* number of times we retransmitted */
322 struct timeval timeout;
323 struct timeval retransmit_time;
324 struct timeval next_sendtime, starttime, time_waited, tv;
332 int kin_len, n, rpc_lock_value;
336 sigfillset(&newmask);
337 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
338 mutex_lock(&clnt_fd_lock);
339 while (dg_fd_locks[cu->cu_fd])
340 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
345 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
346 mutex_unlock(&clnt_fd_lock);
347 if (cu->cu_total.tv_usec == -1) {
348 timeout = utimeout; /* use supplied timeout */
350 timeout = cu->cu_total; /* use default timeout */
353 if (cu->cu_connect && !cu->cu_connected) {
354 if (_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
356 cu->cu_error.re_errno = errno;
357 cu->cu_error.re_status = RPC_CANTSEND;
360 cu->cu_connected = 1;
362 if (cu->cu_connected) {
366 sa = (struct sockaddr *)&cu->cu_raddr;
369 time_waited.tv_sec = 0;
370 time_waited.tv_usec = 0;
371 retransmit_time = next_sendtime = cu->cu_wait;
372 gettimeofday(&starttime, NULL);
374 /* Clean up in case the last call ended in a longjmp(3) call. */
377 if ((cu->cu_kq = kqueue()) < 0) {
378 cu->cu_error.re_errno = errno;
379 cu->cu_error.re_status = RPC_CANTSEND;
385 if (cu->cu_async == TRUE && xargs == NULL)
388 * the transaction is the first thing in the out buffer
389 * XXX Yes, and it's in network byte order, so we should to
390 * be careful when we increment it, shouldn't we.
392 xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr));
394 *(u_int32_t *)(void *)(cu->cu_outhdr) = htonl(xid);
396 xdrs = &(cu->cu_outxdrs);
397 xdrs->x_op = XDR_ENCODE;
400 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
401 if ((! XDR_PUTBYTES(xdrs, cu->cu_outhdr, cu->cu_xdrpos)) ||
402 (! XDR_PUTINT32(xdrs, &proc)) ||
403 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
404 (! (*xargs)(xdrs, argsp))) {
405 cu->cu_error.re_status = RPC_CANTENCODEARGS;
409 *(uint32_t *) &cu->cu_outhdr[cu->cu_xdrpos] = htonl(proc);
410 if (!__rpc_gss_wrap(cl->cl_auth, cu->cu_outhdr,
411 cu->cu_xdrpos + sizeof(uint32_t),
412 xdrs, xargs, argsp)) {
413 cu->cu_error.re_status = RPC_CANTENCODEARGS;
417 outlen = (size_t)XDR_GETPOS(xdrs);
420 if (_sendto(cu->cu_fd, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) {
421 cu->cu_error.re_errno = errno;
422 cu->cu_error.re_status = RPC_CANTSEND;
427 * Hack to provide rpc-based message passing
429 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
430 cu->cu_error.re_status = RPC_TIMEDOUT;
437 * sub-optimal code appears here because we have
438 * some clock time to spare while the packets are in flight.
439 * (We assume that this is actually only executed once.)
441 reply_msg.acpted_rply.ar_verf = _null_auth;
442 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
443 reply_msg.acpted_rply.ar_results.where = resultsp;
444 reply_msg.acpted_rply.ar_results.proc = xresults;
446 reply_msg.acpted_rply.ar_results.where = NULL;
447 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
451 /* Decide how long to wait. */
452 if (timercmp(&next_sendtime, &timeout, <))
453 timersub(&next_sendtime, &time_waited, &tv);
455 timersub(&timeout, &time_waited, &tv);
456 if (tv.tv_sec < 0 || tv.tv_usec < 0)
457 tv.tv_sec = tv.tv_usec = 0;
458 TIMEVAL_TO_TIMESPEC(&tv, &ts);
460 n = _kevent(cu->cu_kq, &cu->cu_kin, kin_len, &kv, 1, &ts);
461 /* We don't need to register the event again. */
465 if (kv.flags & EV_ERROR) {
466 cu->cu_error.re_errno = kv.data;
467 cu->cu_error.re_status = RPC_CANTRECV;
470 /* We have some data now */
472 recvlen = _recvfrom(cu->cu_fd, cu->cu_inbuf,
473 cu->cu_recvsz, 0, NULL, NULL);
474 } while (recvlen < 0 && errno == EINTR);
475 if (recvlen < 0 && errno != EWOULDBLOCK) {
476 cu->cu_error.re_errno = errno;
477 cu->cu_error.re_status = RPC_CANTRECV;
480 if (recvlen >= sizeof(u_int32_t) &&
481 (cu->cu_async == TRUE ||
482 *((u_int32_t *)(void *)(cu->cu_inbuf)) ==
483 *((u_int32_t *)(void *)(cu->cu_outbuf)))) {
484 /* We now assume we have the proper reply. */
488 if (n == -1 && errno != EINTR) {
489 cu->cu_error.re_errno = errno;
490 cu->cu_error.re_status = RPC_CANTRECV;
493 gettimeofday(&tv, NULL);
494 timersub(&tv, &starttime, &time_waited);
496 /* Check for timeout. */
497 if (timercmp(&time_waited, &timeout, >)) {
498 cu->cu_error.re_status = RPC_TIMEDOUT;
502 /* Retransmit if necessary. */
503 if (timercmp(&time_waited, &next_sendtime, >)) {
504 /* update retransmit_time */
505 if (retransmit_time.tv_sec < RPC_MAX_BACKOFF)
506 timeradd(&retransmit_time, &retransmit_time,
508 timeradd(&next_sendtime, &retransmit_time,
513 * When retransmitting a RPCSEC_GSS message,
514 * we must use a new sequence number (handled
515 * by __rpc_gss_wrap above).
517 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS)
520 goto call_again_same_xid;
525 * now decode and validate the response
528 xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
529 ok = xdr_replymsg(&reply_xdrs, &reply_msg);
530 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
532 if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
533 (reply_msg.acpted_rply.ar_stat == SUCCESS))
534 cu->cu_error.re_status = RPC_SUCCESS;
536 _seterr_reply(&reply_msg, &(cu->cu_error));
538 if (cu->cu_error.re_status == RPC_SUCCESS) {
539 if (! AUTH_VALIDATE(cl->cl_auth,
540 &reply_msg.acpted_rply.ar_verf)) {
542 cl->cl_auth->ah_cred.oa_flavor
545 * If we retransmitted, its
546 * possible that we will
547 * receive a reply for one of
548 * the earlier transmissions
549 * (which will use an older
550 * RPCSEC_GSS sequence
551 * number). In this case, just
552 * go back and listen for a
553 * new reply. We could keep a
554 * record of all the seq
555 * numbers we have transmitted
556 * so far so that we could
557 * accept a reply for any of
561 cu->cu_error.re_status = RPC_AUTHERROR;
562 cu->cu_error.re_why = AUTH_INVALIDRESP;
564 if (cl->cl_auth->ah_cred.oa_flavor
566 if (!__rpc_gss_unwrap(cl->cl_auth,
567 &reply_xdrs, xresults,
569 cu->cu_error.re_status =
573 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
574 xdrs->x_op = XDR_FREE;
575 (void) xdr_opaque_auth(xdrs,
576 &(reply_msg.acpted_rply.ar_verf));
578 } /* end successful completion */
580 * If unsuccesful AND error is an authentication error
581 * then refresh credentials and try again, else break
583 else if (cu->cu_error.re_status == RPC_AUTHERROR)
584 /* maybe our credentials need to be refreshed ... */
585 if (nrefreshes > 0 &&
586 AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
590 /* end of unsuccessful completion */
591 } /* end of valid reply message */
593 cu->cu_error.re_status = RPC_CANTDECODERES;
600 release_fd_lock(cu->cu_fd, mask);
601 return (cu->cu_error.re_status);
605 clnt_dg_geterr(cl, errp)
607 struct rpc_err *errp;
609 struct cu_data *cu = (struct cu_data *)cl->cl_private;
611 *errp = cu->cu_error;
615 clnt_dg_freeres(cl, xdr_res, 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]);
647 clnt_dg_control(cl, request, info)
652 struct cu_data *cu = (struct cu_data *)cl->cl_private;
658 sigfillset(&newmask);
659 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
660 mutex_lock(&clnt_fd_lock);
661 while (dg_fd_locks[cu->cu_fd])
662 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
667 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
668 mutex_unlock(&clnt_fd_lock);
671 cu->cu_closeit = TRUE;
672 release_fd_lock(cu->cu_fd, mask);
674 case CLSET_FD_NCLOSE:
675 cu->cu_closeit = FALSE;
676 release_fd_lock(cu->cu_fd, mask);
680 /* for other requests which use info */
682 release_fd_lock(cu->cu_fd, mask);
687 if (time_not_ok((struct timeval *)info)) {
688 release_fd_lock(cu->cu_fd, mask);
691 cu->cu_total = *(struct timeval *)info;
694 *(struct timeval *)info = cu->cu_total;
696 case CLGET_SERVER_ADDR: /* Give him the fd address */
697 /* Now obsolete. Only for backward compatibility */
698 (void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
700 case CLSET_RETRY_TIMEOUT:
701 if (time_not_ok((struct timeval *)info)) {
702 release_fd_lock(cu->cu_fd, mask);
705 cu->cu_wait = *(struct timeval *)info;
707 case CLGET_RETRY_TIMEOUT:
708 *(struct timeval *)info = cu->cu_wait;
711 *(int *)info = cu->cu_fd;
714 addr = (struct netbuf *)info;
715 addr->buf = &cu->cu_raddr;
716 addr->len = cu->cu_rlen;
717 addr->maxlen = sizeof cu->cu_raddr;
719 case CLSET_SVC_ADDR: /* set to new address */
720 addr = (struct netbuf *)info;
721 if (addr->len < sizeof cu->cu_raddr) {
722 release_fd_lock(cu->cu_fd, mask);
725 (void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
726 cu->cu_rlen = addr->len;
730 * use the knowledge that xid is the
731 * first element in the call structure *.
732 * This will get the xid of the PREVIOUS call
735 ntohl(*(u_int32_t *)(void *)cu->cu_outhdr);
739 /* This will set the xid of the NEXT call */
740 *(u_int32_t *)(void *)cu->cu_outhdr =
741 htonl(*(u_int32_t *)info - 1);
742 /* decrement by 1 as clnt_dg_call() increments once */
747 * This RELIES on the information that, in the call body,
748 * the version number field is the fifth field from the
749 * begining of the RPC header. MUST be changed if the
750 * call_struct is changed
753 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
754 4 * BYTES_PER_XDR_UNIT));
758 *(u_int32_t *)(void *)(cu->cu_outhdr + 4 * BYTES_PER_XDR_UNIT)
759 = htonl(*(u_int32_t *)info);
764 * This RELIES on the information that, in the call body,
765 * the program number field is the fourth field from the
766 * begining of the RPC header. MUST be changed if the
767 * call_struct is changed
770 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
771 3 * BYTES_PER_XDR_UNIT));
775 *(u_int32_t *)(void *)(cu->cu_outhdr + 3 * BYTES_PER_XDR_UNIT)
776 = htonl(*(u_int32_t *)info);
779 cu->cu_async = *(int *)info;
782 cu->cu_connect = *(int *)info;
785 release_fd_lock(cu->cu_fd, mask);
788 release_fd_lock(cu->cu_fd, mask);
796 struct cu_data *cu = (struct cu_data *)cl->cl_private;
797 int cu_fd = cu->cu_fd;
801 sigfillset(&newmask);
802 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
803 mutex_lock(&clnt_fd_lock);
804 while (dg_fd_locks[cu_fd])
805 cond_wait(&dg_cv[cu_fd], &clnt_fd_lock);
810 XDR_DESTROY(&(cu->cu_outxdrs));
811 mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
812 if (cl->cl_netid && cl->cl_netid[0])
813 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
814 if (cl->cl_tp && cl->cl_tp[0])
815 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
816 mem_free(cl, sizeof (CLIENT));
817 mutex_unlock(&clnt_fd_lock);
818 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
819 cond_signal(&dg_cv[cu_fd]);
822 static struct clnt_ops *
825 static struct clnt_ops ops;
829 /* VARIABLES PROTECTED BY ops_lock: ops */
831 sigfillset(&newmask);
832 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
833 mutex_lock(&ops_lock);
834 if (ops.cl_call == NULL) {
835 ops.cl_call = clnt_dg_call;
836 ops.cl_abort = clnt_dg_abort;
837 ops.cl_geterr = clnt_dg_geterr;
838 ops.cl_freeres = clnt_dg_freeres;
839 ops.cl_destroy = clnt_dg_destroy;
840 ops.cl_control = clnt_dg_control;
842 mutex_unlock(&ops_lock);
843 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
848 * Make sure that the time is not garbage. -1 value is allowed.
854 return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
855 t->tv_usec < -1 || t->tv_usec > 1000000);