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>
41 __FBSDID("$FreeBSD$");
44 * Implements a connectionless client side RPC.
47 #include "namespace.h"
48 #include "reentrant.h"
49 #include <sys/types.h>
50 #include <sys/event.h>
52 #include <sys/socket.h>
53 #include <sys/ioctl.h>
54 #include <arpa/inet.h>
56 #include <rpc/rpcsec_gss.h>
63 #include "un-namespace.h"
68 #ifdef _FREEFALL_CONFIG
70 * Disable RPC exponential back-off for FreeBSD.org systems.
72 #define RPC_MAX_BACKOFF 1 /* second */
74 #define RPC_MAX_BACKOFF 30 /* seconds */
78 static struct clnt_ops *clnt_dg_ops(void);
79 static bool_t time_not_ok(struct timeval *);
80 static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
81 xdrproc_t, void *, struct timeval);
82 static void clnt_dg_geterr(CLIENT *, struct rpc_err *);
83 static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *);
84 static void clnt_dg_abort(CLIENT *);
85 static bool_t clnt_dg_control(CLIENT *, u_int, void *);
86 static void clnt_dg_destroy(CLIENT *);
92 * This machinery implements per-fd locks for MT-safety. It is not
93 * sufficient to do per-CLIENT handle locks for MT-safety because a
94 * user may create more than one CLIENT handle with the same fd behind
95 * it. Therfore, we allocate an array of flags (dg_fd_locks), protected
96 * by the clnt_fd_lock mutex, and an array (dg_cv) of condition variables
97 * similarly protected. Dg_fd_lock[fd] == 1 => a call is activte on some
98 * CLIENT handle created for that fd.
99 * The current implementation holds locks across the entire RPC and reply,
100 * including retransmissions. Yes, this is silly, and as soon as this
101 * code is proven to work, this should be the first thing fixed. One step
104 static int *dg_fd_locks;
105 static cond_t *dg_cv;
106 #define release_fd_lock(fd, mask) { \
107 mutex_lock(&clnt_fd_lock); \
108 dg_fd_locks[fd] = 0; \
109 mutex_unlock(&clnt_fd_lock); \
110 thr_sigsetmask(SIG_SETMASK, &(mask), NULL); \
111 cond_signal(&dg_cv[fd]); \
114 static const char mem_err_clnt_dg[] = "clnt_dg_create: out of memory";
116 /* VARIABLES PROTECTED BY clnt_fd_lock: dg_fd_locks, dg_cv */
118 #define MCALL_MSG_SIZE 24
121 * Private data kept per client handle
124 int cu_fd; /* connections fd */
125 bool_t cu_closeit; /* opened by library */
126 struct sockaddr_storage cu_raddr; /* remote address */
128 struct timeval cu_wait; /* retransmit interval */
129 struct timeval cu_total; /* total time for the call */
130 struct rpc_err cu_error;
133 u_int cu_sendsz; /* send size */
134 char cu_outhdr[MCALL_MSG_SIZE];
136 u_int cu_recvsz; /* recv size */
138 int cu_connect; /* Use connect(). */
139 int cu_connected; /* Have done connect(). */
140 struct kevent cu_kin;
146 * Connection less client creation returns with client handle parameters.
147 * Default options are set, which the user can change using clnt_control().
148 * fd should be open and bound.
149 * NB: The rpch->cl_auth is initialized to null authentication.
150 * Caller may wish to set this something more useful.
152 * sendsz and recvsz are the maximum allowable packet sizes that can be
153 * sent and received. Normally they are the same, but they can be
154 * changed to improve the program efficiency and buffer allocation.
155 * If they are 0, use the transport default.
157 * If svcaddr is NULL, returns NULL.
159 * fd - open file descriptor
160 * svcaddr - servers address
161 * program - program number
162 * version - version number
163 * sendsz - buffer recv size
164 * recvsz - buffer send size
167 clnt_dg_create(int fd, const struct netbuf *svcaddr, rpcprog_t program,
168 rpcvers_t version, u_int sendsz, u_int recvsz)
170 CLIENT *cl = NULL; /* client handle */
171 struct cu_data *cu = NULL; /* private data */
173 struct rpc_msg call_msg;
176 struct __rpc_sockinfo si;
179 sigfillset(&newmask);
180 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
181 mutex_lock(&clnt_fd_lock);
182 if (dg_fd_locks == (int *) NULL) {
185 int dtbsize = __rpc_dtbsize();
187 fd_allocsz = dtbsize * sizeof (int);
188 dg_fd_locks = (int *) mem_alloc(fd_allocsz);
189 if (dg_fd_locks == (int *) NULL) {
190 mutex_unlock(&clnt_fd_lock);
191 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
194 memset(dg_fd_locks, '\0', fd_allocsz);
196 cv_allocsz = dtbsize * sizeof (cond_t);
197 dg_cv = (cond_t *) mem_alloc(cv_allocsz);
198 if (dg_cv == (cond_t *) NULL) {
199 mem_free(dg_fd_locks, fd_allocsz);
200 dg_fd_locks = (int *) NULL;
201 mutex_unlock(&clnt_fd_lock);
202 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
207 for (i = 0; i < dtbsize; i++)
208 cond_init(&dg_cv[i], 0, (void *) 0);
212 mutex_unlock(&clnt_fd_lock);
213 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
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;
339 int kin_len, n, rpc_lock_value;
343 sigfillset(&newmask);
344 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
345 mutex_lock(&clnt_fd_lock);
346 while (dg_fd_locks[cu->cu_fd])
347 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
352 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
353 mutex_unlock(&clnt_fd_lock);
354 if (cu->cu_total.tv_usec == -1) {
355 timeout = utimeout; /* use supplied timeout */
357 timeout = cu->cu_total; /* use default timeout */
360 if (cu->cu_connect && !cu->cu_connected) {
361 if (_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
363 cu->cu_error.re_errno = errno;
364 cu->cu_error.re_status = RPC_CANTSEND;
367 cu->cu_connected = 1;
369 if (cu->cu_connected) {
373 sa = (struct sockaddr *)&cu->cu_raddr;
376 time_waited.tv_sec = 0;
377 time_waited.tv_usec = 0;
378 retransmit_time = next_sendtime = cu->cu_wait;
379 gettimeofday(&starttime, NULL);
381 /* Clean up in case the last call ended in a longjmp(3) call. */
384 if ((cu->cu_kq = kqueue()) < 0) {
385 cu->cu_error.re_errno = errno;
386 cu->cu_error.re_status = RPC_CANTSEND;
392 if (cu->cu_async == TRUE && xargs == NULL)
395 * the transaction is the first thing in the out buffer
396 * XXX Yes, and it's in network byte order, so we should to
397 * be careful when we increment it, shouldn't we.
399 xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr));
401 *(u_int32_t *)(void *)(cu->cu_outhdr) = htonl(xid);
403 xdrs = &(cu->cu_outxdrs);
404 xdrs->x_op = XDR_ENCODE;
407 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
408 if ((! XDR_PUTBYTES(xdrs, cu->cu_outhdr, cu->cu_xdrpos)) ||
409 (! XDR_PUTINT32(xdrs, &proc)) ||
410 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
411 (! (*xargs)(xdrs, argsp))) {
412 cu->cu_error.re_status = RPC_CANTENCODEARGS;
416 *(uint32_t *) &cu->cu_outhdr[cu->cu_xdrpos] = htonl(proc);
417 if (!__rpc_gss_wrap(cl->cl_auth, cu->cu_outhdr,
418 cu->cu_xdrpos + sizeof(uint32_t),
419 xdrs, xargs, argsp)) {
420 cu->cu_error.re_status = RPC_CANTENCODEARGS;
424 outlen = (size_t)XDR_GETPOS(xdrs);
427 if (_sendto(cu->cu_fd, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) {
428 cu->cu_error.re_errno = errno;
429 cu->cu_error.re_status = RPC_CANTSEND;
434 * Hack to provide rpc-based message passing
436 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
437 cu->cu_error.re_status = RPC_TIMEDOUT;
444 * sub-optimal code appears here because we have
445 * some clock time to spare while the packets are in flight.
446 * (We assume that this is actually only executed once.)
448 reply_msg.acpted_rply.ar_verf = _null_auth;
449 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
450 reply_msg.acpted_rply.ar_results.where = resultsp;
451 reply_msg.acpted_rply.ar_results.proc = xresults;
453 reply_msg.acpted_rply.ar_results.where = NULL;
454 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
458 /* Decide how long to wait. */
459 if (timercmp(&next_sendtime, &timeout, <))
460 timersub(&next_sendtime, &time_waited, &tv);
462 timersub(&timeout, &time_waited, &tv);
463 if (tv.tv_sec < 0 || tv.tv_usec < 0)
464 tv.tv_sec = tv.tv_usec = 0;
465 TIMEVAL_TO_TIMESPEC(&tv, &ts);
467 n = _kevent(cu->cu_kq, &cu->cu_kin, kin_len, &kv, 1, &ts);
468 /* We don't need to register the event again. */
472 if (kv.flags & EV_ERROR) {
473 cu->cu_error.re_errno = kv.data;
474 cu->cu_error.re_status = RPC_CANTRECV;
477 /* We have some data now */
479 recvlen = _recvfrom(cu->cu_fd, cu->cu_inbuf,
480 cu->cu_recvsz, 0, NULL, NULL);
481 } while (recvlen < 0 && errno == EINTR);
482 if (recvlen < 0 && errno != EWOULDBLOCK) {
483 cu->cu_error.re_errno = errno;
484 cu->cu_error.re_status = RPC_CANTRECV;
487 if (recvlen >= sizeof(u_int32_t) &&
488 (cu->cu_async == TRUE ||
489 *((u_int32_t *)(void *)(cu->cu_inbuf)) ==
490 *((u_int32_t *)(void *)(cu->cu_outbuf)))) {
491 /* We now assume we have the proper reply. */
495 if (n == -1 && errno != EINTR) {
496 cu->cu_error.re_errno = errno;
497 cu->cu_error.re_status = RPC_CANTRECV;
500 gettimeofday(&tv, NULL);
501 timersub(&tv, &starttime, &time_waited);
503 /* Check for timeout. */
504 if (timercmp(&time_waited, &timeout, >)) {
505 cu->cu_error.re_status = RPC_TIMEDOUT;
509 /* Retransmit if necessary. */
510 if (timercmp(&time_waited, &next_sendtime, >)) {
511 /* update retransmit_time */
512 if (retransmit_time.tv_sec < RPC_MAX_BACKOFF)
513 timeradd(&retransmit_time, &retransmit_time,
515 timeradd(&next_sendtime, &retransmit_time,
520 * When retransmitting a RPCSEC_GSS message,
521 * we must use a new sequence number (handled
522 * by __rpc_gss_wrap above).
524 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS)
527 goto call_again_same_xid;
532 * now decode and validate the response
535 xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
536 ok = xdr_replymsg(&reply_xdrs, &reply_msg);
537 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
539 if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
540 (reply_msg.acpted_rply.ar_stat == SUCCESS))
541 cu->cu_error.re_status = RPC_SUCCESS;
543 _seterr_reply(&reply_msg, &(cu->cu_error));
545 if (cu->cu_error.re_status == RPC_SUCCESS) {
546 if (! AUTH_VALIDATE(cl->cl_auth,
547 &reply_msg.acpted_rply.ar_verf)) {
549 cl->cl_auth->ah_cred.oa_flavor
552 * If we retransmitted, its
553 * possible that we will
554 * receive a reply for one of
555 * the earlier transmissions
556 * (which will use an older
557 * RPCSEC_GSS sequence
558 * number). In this case, just
559 * go back and listen for a
560 * new reply. We could keep a
561 * record of all the seq
562 * numbers we have transmitted
563 * so far so that we could
564 * accept a reply for any of
568 cu->cu_error.re_status = RPC_AUTHERROR;
569 cu->cu_error.re_why = AUTH_INVALIDRESP;
571 if (cl->cl_auth->ah_cred.oa_flavor
573 if (!__rpc_gss_unwrap(cl->cl_auth,
574 &reply_xdrs, xresults,
576 cu->cu_error.re_status =
580 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
581 xdrs->x_op = XDR_FREE;
582 (void) xdr_opaque_auth(xdrs,
583 &(reply_msg.acpted_rply.ar_verf));
585 } /* end successful completion */
587 * If unsuccessful AND error is an authentication error
588 * then refresh credentials and try again, else break
590 else if (cu->cu_error.re_status == RPC_AUTHERROR)
591 /* maybe our credentials need to be refreshed ... */
592 if (nrefreshes > 0 &&
593 AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
597 /* end of unsuccessful completion */
598 } /* end of valid reply message */
600 cu->cu_error.re_status = RPC_CANTDECODERES;
607 release_fd_lock(cu->cu_fd, mask);
608 return (cu->cu_error.re_status);
612 clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp)
614 struct cu_data *cu = (struct cu_data *)cl->cl_private;
616 *errp = cu->cu_error;
620 clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, void *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]);
643 clnt_dg_abort(CLIENT *h)
648 clnt_dg_control(CLIENT *cl, u_int request, void *info)
650 struct cu_data *cu = (struct cu_data *)cl->cl_private;
656 sigfillset(&newmask);
657 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
658 mutex_lock(&clnt_fd_lock);
659 while (dg_fd_locks[cu->cu_fd])
660 cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
665 dg_fd_locks[cu->cu_fd] = rpc_lock_value;
666 mutex_unlock(&clnt_fd_lock);
669 cu->cu_closeit = TRUE;
670 release_fd_lock(cu->cu_fd, mask);
672 case CLSET_FD_NCLOSE:
673 cu->cu_closeit = FALSE;
674 release_fd_lock(cu->cu_fd, mask);
678 /* for other requests which use info */
680 release_fd_lock(cu->cu_fd, mask);
685 if (time_not_ok((struct timeval *)info)) {
686 release_fd_lock(cu->cu_fd, mask);
689 cu->cu_total = *(struct timeval *)info;
692 *(struct timeval *)info = cu->cu_total;
694 case CLGET_SERVER_ADDR: /* Give him the fd address */
695 /* Now obsolete. Only for backward compatibility */
696 (void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
698 case CLSET_RETRY_TIMEOUT:
699 if (time_not_ok((struct timeval *)info)) {
700 release_fd_lock(cu->cu_fd, mask);
703 cu->cu_wait = *(struct timeval *)info;
705 case CLGET_RETRY_TIMEOUT:
706 *(struct timeval *)info = cu->cu_wait;
709 *(int *)info = cu->cu_fd;
712 addr = (struct netbuf *)info;
713 addr->buf = &cu->cu_raddr;
714 addr->len = cu->cu_rlen;
715 addr->maxlen = sizeof cu->cu_raddr;
717 case CLSET_SVC_ADDR: /* set to new address */
718 addr = (struct netbuf *)info;
719 if (addr->len < sizeof cu->cu_raddr) {
720 release_fd_lock(cu->cu_fd, mask);
723 (void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
724 cu->cu_rlen = addr->len;
728 * use the knowledge that xid is the
729 * first element in the call structure *.
730 * This will get the xid of the PREVIOUS call
733 ntohl(*(u_int32_t *)(void *)cu->cu_outhdr);
737 /* This will set the xid of the NEXT call */
738 *(u_int32_t *)(void *)cu->cu_outhdr =
739 htonl(*(u_int32_t *)info - 1);
740 /* decrement by 1 as clnt_dg_call() increments once */
745 * This RELIES on the information that, in the call body,
746 * the version number field is the fifth field from the
747 * beginning of the RPC header. MUST be changed if the
748 * call_struct is changed
751 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
752 4 * BYTES_PER_XDR_UNIT));
756 *(u_int32_t *)(void *)(cu->cu_outhdr + 4 * BYTES_PER_XDR_UNIT)
757 = htonl(*(u_int32_t *)info);
762 * This RELIES on the information that, in the call body,
763 * the program number field is the fourth field from the
764 * beginning of the RPC header. MUST be changed if the
765 * call_struct is changed
768 ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
769 3 * BYTES_PER_XDR_UNIT));
773 *(u_int32_t *)(void *)(cu->cu_outhdr + 3 * BYTES_PER_XDR_UNIT)
774 = htonl(*(u_int32_t *)info);
777 cu->cu_async = *(int *)info;
780 cu->cu_connect = *(int *)info;
783 release_fd_lock(cu->cu_fd, mask);
786 release_fd_lock(cu->cu_fd, mask);
791 clnt_dg_destroy(CLIENT *cl)
793 struct cu_data *cu = (struct cu_data *)cl->cl_private;
794 int cu_fd = cu->cu_fd;
798 sigfillset(&newmask);
799 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
800 mutex_lock(&clnt_fd_lock);
801 while (dg_fd_locks[cu_fd])
802 cond_wait(&dg_cv[cu_fd], &clnt_fd_lock);
807 XDR_DESTROY(&(cu->cu_outxdrs));
808 mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
809 if (cl->cl_netid && cl->cl_netid[0])
810 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
811 if (cl->cl_tp && cl->cl_tp[0])
812 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
813 mem_free(cl, sizeof (CLIENT));
814 mutex_unlock(&clnt_fd_lock);
815 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
816 cond_signal(&dg_cv[cu_fd]);
819 static struct clnt_ops *
822 static struct clnt_ops ops;
826 /* VARIABLES PROTECTED BY ops_lock: ops */
828 sigfillset(&newmask);
829 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
830 mutex_lock(&ops_lock);
831 if (ops.cl_call == NULL) {
832 ops.cl_call = clnt_dg_call;
833 ops.cl_abort = clnt_dg_abort;
834 ops.cl_geterr = clnt_dg_geterr;
835 ops.cl_freeres = clnt_dg_freeres;
836 ops.cl_destroy = clnt_dg_destroy;
837 ops.cl_control = clnt_dg_control;
839 mutex_unlock(&ops_lock);
840 thr_sigsetmask(SIG_SETMASK, &mask, NULL);
845 * Make sure that the time is not garbage. -1 value is allowed.
848 time_not_ok(struct timeval *t)
850 return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
851 t->tv_usec < -1 || t->tv_usec > 1000000);