1 /* $NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 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 #if defined(LIBC_SCCS) && !defined(lint)
34 static char *sccsid2 = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
35 static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
36 static char sccsid3[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
42 * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
44 * Copyright (C) 1984, Sun Microsystems, Inc.
46 * TCP based RPC supports 'batched calls'.
47 * A sequence of calls may be batched-up in a send buffer. The rpc call
48 * return immediately to the client even though the call was not necessarily
49 * sent. The batching occurs if the results' xdr routine is NULL (0) AND
50 * the rpc timeout value is zero (see clnt.h, rpc).
52 * Clients should NOT casually batch calls that in fact return results; that is,
53 * the server side should be aware that a call is batched and not produce any
54 * return message. Batched calls that produce many result messages can
55 * deadlock (netlock) the client and the server....
57 * Now go hang yourself.
60 #include "namespace.h"
61 #include "reentrant.h"
62 #include <sys/types.h>
64 #include <sys/syslog.h>
65 #include <sys/socket.h>
69 #include <arpa/inet.h>
81 #include <rpc/rpcsec_gss.h>
82 #include "un-namespace.h"
86 #define MCALL_MSG_SIZE 24
90 struct cmsgcred cmcred;
93 static enum clnt_stat clnt_vc_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
94 xdrproc_t, void *, struct timeval);
95 static void clnt_vc_geterr(CLIENT *, struct rpc_err *);
96 static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, void *);
97 static void clnt_vc_abort(CLIENT *);
98 static bool_t clnt_vc_control(CLIENT *, u_int, void *);
99 static void clnt_vc_destroy(CLIENT *);
100 static struct clnt_ops *clnt_vc_ops(void);
101 static bool_t time_not_ok(struct timeval *);
102 static int read_vc(void *, void *, int);
103 static int write_vc(void *, void *, int);
104 static int __msgwrite(int, void *, size_t);
105 static int __msgread(int, void *, size_t);
108 int ct_fd; /* connection's fd */
109 bool_t ct_closeit; /* close it on destroy */
110 struct timeval ct_wait; /* wait interval in milliseconds */
111 bool_t ct_waitset; /* wait set by clnt_control? */
112 struct netbuf ct_addr; /* remote addr */
113 struct rpc_err ct_error;
115 char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
118 u_int ct_mpos; /* pos after marshal */
119 XDR ct_xdrs; /* XDR stream */
123 * This machinery implements per-fd locks for MT-safety. It is not
124 * sufficient to do per-CLIENT handle locks for MT-safety because a
125 * user may create more than one CLIENT handle with the same fd behind
126 * it. Therfore, we allocate an array of flags (vc_fd_locks), protected
127 * by the clnt_fd_lock mutex, and an array (vc_cv) of condition variables
128 * similarly protected. Vc_fd_lock[fd] == 1 => a call is activte on some
129 * CLIENT handle created for that fd.
130 * The current implementation holds locks across the entire RPC and reply.
131 * Yes, this is silly, and as soon as this code is proven to work, this
132 * should be the first thing fixed. One step at a time.
134 static int *vc_fd_locks;
135 static cond_t *vc_cv;
136 #define release_fd_lock(fd, mask) { \
137 mutex_lock(&clnt_fd_lock); \
138 vc_fd_locks[fd] = 0; \
139 mutex_unlock(&clnt_fd_lock); \
140 thr_sigsetmask(SIG_SETMASK, &(mask), (sigset_t *) NULL); \
141 cond_signal(&vc_cv[fd]); \
144 static const char clnt_vc_errstr[] = "%s : %s";
145 static const char clnt_vc_str[] = "clnt_vc_create";
146 static const char __no_mem_str[] = "out of memory";
149 * Create a client handle for a connection.
150 * Default options are set, which the user can change using clnt_control()'s.
151 * The rpc/vc package does buffering similar to stdio, so the client
152 * must pick send and receive buffer sizes, 0 => use the default.
153 * NB: fd is copied into a private area.
154 * NB: The rpch->cl_auth is set null authentication. Caller may wish to
155 * set this something more useful.
157 * fd should be an open socket
159 * fd - open file descriptor
160 * raddr - servers address
161 * prog - program number
162 * vers - version number
163 * sendsz - buffer send size
164 * recvsz - buffer recv size
167 clnt_vc_create(int fd, const struct netbuf *raddr, const rpcprog_t prog,
168 const rpcvers_t vers, u_int sendsz, u_int recvsz)
170 CLIENT *cl; /* client handle */
171 struct ct_data *ct = NULL; /* client handle */
173 struct rpc_msg call_msg;
174 static u_int32_t disrupt;
177 struct sockaddr_storage ss;
179 struct __rpc_sockinfo si;
182 disrupt = (u_int32_t)(long)raddr;
184 cl = (CLIENT *)mem_alloc(sizeof (*cl));
185 ct = (struct ct_data *)mem_alloc(sizeof (*ct));
186 if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
187 (void) syslog(LOG_ERR, clnt_vc_errstr,
188 clnt_vc_str, __no_mem_str);
189 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
190 rpc_createerr.cf_error.re_errno = errno;
193 ct->ct_addr.buf = NULL;
194 sigfillset(&newmask);
195 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
196 mutex_lock(&clnt_fd_lock);
197 if (vc_fd_locks == (int *) NULL) {
198 int cv_allocsz, fd_allocsz;
199 int dtbsize = __rpc_dtbsize();
201 fd_allocsz = dtbsize * sizeof (int);
202 vc_fd_locks = (int *) mem_alloc(fd_allocsz);
203 if (vc_fd_locks == (int *) NULL) {
204 mutex_unlock(&clnt_fd_lock);
205 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
208 memset(vc_fd_locks, '\0', fd_allocsz);
210 assert(vc_cv == (cond_t *) NULL);
211 cv_allocsz = dtbsize * sizeof (cond_t);
212 vc_cv = (cond_t *) mem_alloc(cv_allocsz);
213 if (vc_cv == (cond_t *) NULL) {
214 mem_free(vc_fd_locks, fd_allocsz);
215 vc_fd_locks = (int *) NULL;
216 mutex_unlock(&clnt_fd_lock);
217 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
222 for (i = 0; i < dtbsize; i++)
223 cond_init(&vc_cv[i], 0, (void *) 0);
226 assert(vc_cv != (cond_t *) NULL);
229 * XXX - fvdl connecting while holding a mutex?
232 if (_getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
233 if (errno != ENOTCONN) {
234 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
235 rpc_createerr.cf_error.re_errno = errno;
236 mutex_unlock(&clnt_fd_lock);
237 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
240 if (_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
241 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
242 rpc_createerr.cf_error.re_errno = errno;
243 mutex_unlock(&clnt_fd_lock);
244 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
248 mutex_unlock(&clnt_fd_lock);
249 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
250 if (!__rpc_fd2sockinfo(fd, &si))
253 ct->ct_closeit = FALSE;
256 * Set up private data struct
259 ct->ct_wait.tv_usec = 0;
260 ct->ct_waitset = FALSE;
261 ct->ct_addr.buf = malloc(raddr->maxlen);
262 if (ct->ct_addr.buf == NULL)
264 memcpy(ct->ct_addr.buf, raddr->buf, raddr->len);
265 ct->ct_addr.len = raddr->len;
266 ct->ct_addr.maxlen = raddr->maxlen;
269 * Initialize call message
271 (void)gettimeofday(&now, NULL);
272 call_msg.rm_xid = ((u_int32_t)++disrupt) ^ __RPC_GETXID(&now);
273 call_msg.rm_direction = CALL;
274 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
275 call_msg.rm_call.cb_prog = (u_int32_t)prog;
276 call_msg.rm_call.cb_vers = (u_int32_t)vers;
279 * pre-serialize the static part of the call msg and stash it away
281 xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
283 if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
284 if (ct->ct_closeit) {
289 ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
290 XDR_DESTROY(&(ct->ct_xdrs));
291 assert(ct->ct_mpos + sizeof(uint32_t) <= MCALL_MSG_SIZE);
294 * Create a client handle which uses xdrrec for serialization
295 * and authnone for authentication.
297 cl->cl_ops = clnt_vc_ops();
299 cl->cl_auth = authnone_create();
300 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
301 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
302 xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
303 cl->cl_private, read_vc, write_vc);
309 mem_free(ct->ct_addr.buf, ct->ct_addr.len);
310 mem_free(ct, sizeof (struct ct_data));
313 mem_free(cl, sizeof (CLIENT));
314 return ((CLIENT *)NULL);
317 static enum clnt_stat
318 clnt_vc_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xdr_args, void *args_ptr,
319 xdrproc_t xdr_results, void *results_ptr, struct timeval timeout)
321 struct ct_data *ct = (struct ct_data *) cl->cl_private;
322 XDR *xdrs = &(ct->ct_xdrs);
323 struct rpc_msg reply_msg;
325 u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */
328 sigset_t mask, newmask;
334 sigfillset(&newmask);
335 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
336 mutex_lock(&clnt_fd_lock);
337 while (vc_fd_locks[ct->ct_fd])
338 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
343 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
344 mutex_unlock(&clnt_fd_lock);
345 if (!ct->ct_waitset) {
346 /* If time is not within limits, we ignore it. */
347 if (time_not_ok(&timeout) == FALSE)
348 ct->ct_wait = timeout;
352 (xdr_results == NULL && timeout.tv_sec == 0
353 && timeout.tv_usec == 0) ? FALSE : TRUE;
356 xdrs->x_op = XDR_ENCODE;
357 ct->ct_error.re_status = RPC_SUCCESS;
358 x_id = ntohl(--(*msg_x_id));
360 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
361 if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
362 (! XDR_PUTINT32(xdrs, &proc)) ||
363 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
364 (! (*xdr_args)(xdrs, args_ptr))) {
365 if (ct->ct_error.re_status == RPC_SUCCESS)
366 ct->ct_error.re_status = RPC_CANTENCODEARGS;
367 (void)xdrrec_endofrecord(xdrs, TRUE);
368 release_fd_lock(ct->ct_fd, mask);
369 return (ct->ct_error.re_status);
372 *(uint32_t *) &ct->ct_u.ct_mcallc[ct->ct_mpos] = htonl(proc);
373 if (! __rpc_gss_wrap(cl->cl_auth, ct->ct_u.ct_mcallc,
374 ct->ct_mpos + sizeof(uint32_t),
375 xdrs, xdr_args, args_ptr)) {
376 if (ct->ct_error.re_status == RPC_SUCCESS)
377 ct->ct_error.re_status = RPC_CANTENCODEARGS;
378 (void)xdrrec_endofrecord(xdrs, TRUE);
379 release_fd_lock(ct->ct_fd, mask);
380 return (ct->ct_error.re_status);
383 if (! xdrrec_endofrecord(xdrs, shipnow)) {
384 release_fd_lock(ct->ct_fd, mask);
385 return (ct->ct_error.re_status = RPC_CANTSEND);
388 release_fd_lock(ct->ct_fd, mask);
389 return (RPC_SUCCESS);
392 * Hack to provide rpc-based message passing
394 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
395 release_fd_lock(ct->ct_fd, mask);
396 return(ct->ct_error.re_status = RPC_TIMEDOUT);
401 * Keep receiving until we get a valid transaction id
403 xdrs->x_op = XDR_DECODE;
405 reply_msg.acpted_rply.ar_verf = _null_auth;
406 reply_msg.acpted_rply.ar_results.where = NULL;
407 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
408 if (! xdrrec_skiprecord(xdrs)) {
409 release_fd_lock(ct->ct_fd, mask);
410 return (ct->ct_error.re_status);
412 /* now decode and validate the response header */
413 if (! xdr_replymsg(xdrs, &reply_msg)) {
414 if (ct->ct_error.re_status == RPC_SUCCESS)
416 release_fd_lock(ct->ct_fd, mask);
417 return (ct->ct_error.re_status);
419 if (reply_msg.rm_xid == x_id)
426 _seterr_reply(&reply_msg, &(ct->ct_error));
427 if (ct->ct_error.re_status == RPC_SUCCESS) {
428 if (! AUTH_VALIDATE(cl->cl_auth,
429 &reply_msg.acpted_rply.ar_verf)) {
430 ct->ct_error.re_status = RPC_AUTHERROR;
431 ct->ct_error.re_why = AUTH_INVALIDRESP;
433 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
434 reply_stat = (*xdr_results)(xdrs, results_ptr);
436 reply_stat = __rpc_gss_unwrap(cl->cl_auth,
437 xdrs, xdr_results, results_ptr);
440 if (ct->ct_error.re_status == RPC_SUCCESS)
441 ct->ct_error.re_status =
445 /* free verifier ... */
446 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
447 xdrs->x_op = XDR_FREE;
448 (void)xdr_opaque_auth(xdrs,
449 &(reply_msg.acpted_rply.ar_verf));
451 } /* end successful completion */
453 /* maybe our credentials need to be refreshed ... */
454 if (refreshes-- && AUTH_REFRESH(cl->cl_auth, &reply_msg))
456 } /* end of unsuccessful completion */
457 release_fd_lock(ct->ct_fd, mask);
458 return (ct->ct_error.re_status);
462 clnt_vc_geterr(CLIENT *cl, struct rpc_err *errp)
467 assert(errp != NULL);
469 ct = (struct ct_data *) cl->cl_private;
470 *errp = ct->ct_error;
474 clnt_vc_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
484 ct = (struct ct_data *)cl->cl_private;
485 xdrs = &(ct->ct_xdrs);
487 sigfillset(&newmask);
488 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
489 mutex_lock(&clnt_fd_lock);
490 while (vc_fd_locks[ct->ct_fd])
491 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
492 xdrs->x_op = XDR_FREE;
493 dummy = (*xdr_res)(xdrs, res_ptr);
494 mutex_unlock(&clnt_fd_lock);
495 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
496 cond_signal(&vc_cv[ct->ct_fd]);
503 clnt_vc_abort(CLIENT *cl)
508 htonlp(void *dst, const void *src, uint32_t incr)
510 /* We are aligned, so we think */
511 *(uint32_t *)dst = htonl(*(const uint32_t *)src + incr);
515 ntohlp(void *dst, const void *src)
517 /* We are aligned, so we think */
518 *(uint32_t *)dst = htonl(*(const uint32_t *)src);
522 clnt_vc_control(CLIENT *cl, u_int request, void *info)
532 ct = (struct ct_data *)cl->cl_private;
534 sigfillset(&newmask);
535 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
536 mutex_lock(&clnt_fd_lock);
537 while (vc_fd_locks[ct->ct_fd])
538 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
543 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
544 mutex_unlock(&clnt_fd_lock);
548 ct->ct_closeit = TRUE;
549 release_fd_lock(ct->ct_fd, mask);
551 case CLSET_FD_NCLOSE:
552 ct->ct_closeit = FALSE;
553 release_fd_lock(ct->ct_fd, mask);
559 /* for other requests which use info */
561 release_fd_lock(ct->ct_fd, mask);
566 if (time_not_ok((struct timeval *)info)) {
567 release_fd_lock(ct->ct_fd, mask);
570 ct->ct_wait = *(struct timeval *)infop;
571 ct->ct_waitset = TRUE;
574 *(struct timeval *)infop = ct->ct_wait;
576 case CLGET_SERVER_ADDR:
577 (void) memcpy(info, ct->ct_addr.buf, (size_t)ct->ct_addr.len);
580 *(int *)info = ct->ct_fd;
583 /* The caller should not free this memory area */
584 *(struct netbuf *)info = ct->ct_addr;
586 case CLSET_SVC_ADDR: /* set to new address */
587 release_fd_lock(ct->ct_fd, mask);
591 * use the knowledge that xid is the
592 * first element in the call structure
593 * This will get the xid of the PREVIOUS call
595 ntohlp(info, &ct->ct_u.ct_mcalli);
598 /* This will set the xid of the NEXT call */
599 /* increment by 1 as clnt_vc_call() decrements once */
600 htonlp(&ct->ct_u.ct_mcalli, info, 1);
604 * This RELIES on the information that, in the call body,
605 * the version number field is the fifth field from the
606 * beginning of the RPC header. MUST be changed if the
607 * call_struct is changed
609 ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT);
613 htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info, 0);
618 * This RELIES on the information that, in the call body,
619 * the program number field is the fourth field from the
620 * beginning of the RPC header. MUST be changed if the
621 * call_struct is changed
623 ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT);
627 htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info, 0);
631 release_fd_lock(ct->ct_fd, mask);
634 release_fd_lock(ct->ct_fd, mask);
640 clnt_vc_destroy(CLIENT *cl)
642 struct ct_data *ct = (struct ct_data *) cl->cl_private;
643 int ct_fd = ct->ct_fd;
649 ct = (struct ct_data *) cl->cl_private;
651 sigfillset(&newmask);
652 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
653 mutex_lock(&clnt_fd_lock);
654 while (vc_fd_locks[ct_fd])
655 cond_wait(&vc_cv[ct_fd], &clnt_fd_lock);
656 if (ct->ct_closeit && ct->ct_fd != -1) {
657 (void)_close(ct->ct_fd);
659 XDR_DESTROY(&(ct->ct_xdrs));
660 free(ct->ct_addr.buf);
661 mem_free(ct, sizeof(struct ct_data));
662 if (cl->cl_netid && cl->cl_netid[0])
663 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
664 if (cl->cl_tp && cl->cl_tp[0])
665 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
666 mem_free(cl, sizeof(CLIENT));
667 mutex_unlock(&clnt_fd_lock);
668 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
669 cond_signal(&vc_cv[ct_fd]);
673 * Interface between xdr serializer and tcp connection.
674 * Behaves like the system calls, read & write, but keeps some error state
675 * around for the rpc level.
678 read_vc(void *ctp, void *buf, int len)
682 struct ct_data *ct = (struct ct_data *)ctp;
684 int milliseconds = (int)((ct->ct_wait.tv_sec * 1000) +
685 (ct->ct_wait.tv_usec / 1000));
692 switch (_poll(&fd, 1, milliseconds)) {
694 ct->ct_error.re_status = RPC_TIMEDOUT;
700 ct->ct_error.re_status = RPC_CANTRECV;
701 ct->ct_error.re_errno = errno;
708 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
709 (sa.sa_family == AF_LOCAL)) {
710 len = __msgread(ct->ct_fd, buf, (size_t)len);
712 len = _read(ct->ct_fd, buf, (size_t)len);
718 ct->ct_error.re_errno = ECONNRESET;
719 ct->ct_error.re_status = RPC_CANTRECV;
720 len = -1; /* it's really an error */
724 ct->ct_error.re_errno = errno;
725 ct->ct_error.re_status = RPC_CANTRECV;
732 write_vc(void *ctp, void *buf, int len)
736 struct ct_data *ct = (struct ct_data *)ctp;
740 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
741 (sa.sa_family == AF_LOCAL)) {
742 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
743 if ((i = __msgwrite(ct->ct_fd, buf,
744 (size_t)cnt)) == -1) {
745 ct->ct_error.re_errno = errno;
746 ct->ct_error.re_status = RPC_CANTSEND;
751 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
752 if ((i = _write(ct->ct_fd, buf, (size_t)cnt)) == -1) {
753 ct->ct_error.re_errno = errno;
754 ct->ct_error.re_status = RPC_CANTSEND;
762 static struct clnt_ops *
765 static struct clnt_ops ops;
766 sigset_t mask, newmask;
768 /* VARIABLES PROTECTED BY ops_lock: ops */
770 sigfillset(&newmask);
771 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
772 mutex_lock(&ops_lock);
773 if (ops.cl_call == NULL) {
774 ops.cl_call = clnt_vc_call;
775 ops.cl_abort = clnt_vc_abort;
776 ops.cl_geterr = clnt_vc_geterr;
777 ops.cl_freeres = clnt_vc_freeres;
778 ops.cl_destroy = clnt_vc_destroy;
779 ops.cl_control = clnt_vc_control;
781 mutex_unlock(&ops_lock);
782 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
787 * Make sure that the time is not garbage. -1 value is disallowed.
788 * Note this is different from time_not_ok in clnt_dg.c
791 time_not_ok(struct timeval *t)
793 return (t->tv_sec <= -1 || t->tv_sec > 100000000 ||
794 t->tv_usec <= -1 || t->tv_usec > 1000000);
798 __msgread(int sock, void *buf, size_t cnt)
804 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
807 bzero((char *)&cm, sizeof(cm));
808 iov[0].iov_base = buf;
809 iov[0].iov_len = cnt;
815 msg.msg_control = (caddr_t)&cm;
816 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
819 return(_recvmsg(sock, &msg, 0));
823 __msgwrite(int sock, void *buf, size_t cnt)
829 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
832 bzero((char *)&cm, sizeof(cm));
833 iov[0].iov_base = buf;
834 iov[0].iov_len = cnt;
836 cm.cmsg.cmsg_type = SCM_CREDS;
837 cm.cmsg.cmsg_level = SOL_SOCKET;
838 cm.cmsg.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
844 msg.msg_control = (caddr_t)&cm;
845 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
848 return(_sendmsg(sock, &msg, 0));