1 /* $NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 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 #if defined(LIBC_SCCS) && !defined(lint)
32 static char *sccsid2 = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
33 static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
34 static char sccsid3[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
40 * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
42 * Copyright (C) 1984, Sun Microsystems, Inc.
44 * TCP based RPC supports 'batched calls'.
45 * A sequence of calls may be batched-up in a send buffer. The rpc call
46 * return immediately to the client even though the call was not necessarily
47 * sent. The batching occurs if the results' xdr routine is NULL (0) AND
48 * the rpc timeout value is zero (see clnt.h, rpc).
50 * Clients should NOT casually batch calls that in fact return results; that is,
51 * the server side should be aware that a call is batched and not produce any
52 * return message. Batched calls that produce many result messages can
53 * deadlock (netlock) the client and the server....
55 * Now go hang yourself.
58 #include "namespace.h"
59 #include "reentrant.h"
60 #include <sys/types.h>
62 #include <sys/syslog.h>
63 #include <sys/socket.h>
67 #include <arpa/inet.h>
79 #include <rpc/rpcsec_gss.h>
80 #include "un-namespace.h"
84 #define MCALL_MSG_SIZE 24
88 struct cmsgcred cmcred;
91 static enum clnt_stat clnt_vc_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
92 xdrproc_t, void *, struct timeval);
93 static void clnt_vc_geterr(CLIENT *, struct rpc_err *);
94 static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, void *);
95 static void clnt_vc_abort(CLIENT *);
96 static bool_t clnt_vc_control(CLIENT *, u_int, void *);
97 static void clnt_vc_destroy(CLIENT *);
98 static struct clnt_ops *clnt_vc_ops(void);
99 static bool_t time_not_ok(struct timeval *);
100 static int read_vc(void *, void *, int);
101 static int write_vc(void *, void *, int);
102 static int __msgwrite(int, void *, size_t);
103 static int __msgread(int, void *, size_t);
106 int ct_fd; /* connection's fd */
107 bool_t ct_closeit; /* close it on destroy */
108 struct timeval ct_wait; /* wait interval in milliseconds */
109 bool_t ct_waitset; /* wait set by clnt_control? */
110 struct netbuf ct_addr; /* remote addr */
111 struct rpc_err ct_error;
113 char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
116 u_int ct_mpos; /* pos after marshal */
117 XDR ct_xdrs; /* XDR stream */
121 * This machinery implements per-fd locks for MT-safety. It is not
122 * sufficient to do per-CLIENT handle locks for MT-safety because a
123 * user may create more than one CLIENT handle with the same fd behind
124 * it. Therfore, we allocate an array of flags (vc_fd_locks), protected
125 * by the clnt_fd_lock mutex, and an array (vc_cv) of condition variables
126 * similarly protected. Vc_fd_lock[fd] == 1 => a call is activte on some
127 * CLIENT handle created for that fd.
128 * The current implementation holds locks across the entire RPC and reply.
129 * Yes, this is silly, and as soon as this code is proven to work, this
130 * should be the first thing fixed. One step at a time.
132 static int *vc_fd_locks;
133 static cond_t *vc_cv;
134 #define release_fd_lock(fd, mask) { \
135 mutex_lock(&clnt_fd_lock); \
136 vc_fd_locks[fd] = 0; \
137 mutex_unlock(&clnt_fd_lock); \
138 thr_sigsetmask(SIG_SETMASK, &(mask), (sigset_t *) NULL); \
139 cond_signal(&vc_cv[fd]); \
142 static const char clnt_vc_errstr[] = "%s : %s";
143 static const char clnt_vc_str[] = "clnt_vc_create";
144 static const char clnt_read_vc_str[] = "read_vc";
145 static const char __no_mem_str[] = "out of memory";
148 * Create a client handle for a connection.
149 * Default options are set, which the user can change using clnt_control()'s.
150 * The rpc/vc package does buffering similar to stdio, so the client
151 * must pick send and receive buffer sizes, 0 => use the default.
152 * NB: fd is copied into a private area.
153 * NB: The rpch->cl_auth is set null authentication. Caller may wish to
154 * set this something more useful.
156 * fd should be an open socket
158 * fd - open file descriptor
159 * raddr - servers address
160 * prog - program number
161 * vers - version number
162 * sendsz - buffer send size
163 * recvsz - buffer recv size
166 clnt_vc_create(int fd, const struct netbuf *raddr, const rpcprog_t prog,
167 const rpcvers_t vers, u_int sendsz, u_int recvsz)
169 CLIENT *cl; /* client handle */
170 struct ct_data *ct = NULL; /* client handle */
172 struct rpc_msg call_msg;
173 static u_int32_t disrupt;
176 struct sockaddr_storage ss;
178 struct __rpc_sockinfo si;
181 disrupt = (u_int32_t)(long)raddr;
183 cl = (CLIENT *)mem_alloc(sizeof (*cl));
184 ct = (struct ct_data *)mem_alloc(sizeof (*ct));
185 if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
186 (void) syslog(LOG_ERR, clnt_vc_errstr,
187 clnt_vc_str, __no_mem_str);
188 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
189 rpc_createerr.cf_error.re_errno = errno;
192 ct->ct_addr.buf = NULL;
193 sigfillset(&newmask);
194 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
195 mutex_lock(&clnt_fd_lock);
196 if (vc_fd_locks == (int *) NULL) {
197 int cv_allocsz, fd_allocsz;
198 int dtbsize = __rpc_dtbsize();
200 fd_allocsz = dtbsize * sizeof (int);
201 vc_fd_locks = (int *) mem_alloc(fd_allocsz);
202 if (vc_fd_locks == (int *) NULL) {
203 mutex_unlock(&clnt_fd_lock);
204 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
207 memset(vc_fd_locks, '\0', fd_allocsz);
209 assert(vc_cv == (cond_t *) NULL);
210 cv_allocsz = dtbsize * sizeof (cond_t);
211 vc_cv = (cond_t *) mem_alloc(cv_allocsz);
212 if (vc_cv == (cond_t *) NULL) {
213 mem_free(vc_fd_locks, fd_allocsz);
214 vc_fd_locks = (int *) NULL;
215 mutex_unlock(&clnt_fd_lock);
216 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
221 for (i = 0; i < dtbsize; i++)
222 cond_init(&vc_cv[i], 0, (void *) 0);
225 assert(vc_cv != (cond_t *) NULL);
228 * XXX - fvdl connecting while holding a mutex?
231 if (_getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
232 if (errno != ENOTCONN) {
233 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
234 rpc_createerr.cf_error.re_errno = errno;
235 mutex_unlock(&clnt_fd_lock);
236 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
239 if (_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
240 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
241 rpc_createerr.cf_error.re_errno = errno;
242 mutex_unlock(&clnt_fd_lock);
243 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
247 mutex_unlock(&clnt_fd_lock);
248 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
249 if (!__rpc_fd2sockinfo(fd, &si))
252 ct->ct_closeit = FALSE;
255 * Set up private data struct
258 ct->ct_wait.tv_usec = 0;
259 ct->ct_waitset = FALSE;
260 ct->ct_addr.buf = malloc(raddr->maxlen);
261 if (ct->ct_addr.buf == NULL)
263 memcpy(ct->ct_addr.buf, raddr->buf, raddr->len);
264 ct->ct_addr.len = raddr->len;
265 ct->ct_addr.maxlen = raddr->maxlen;
268 * Initialize call message
270 (void)gettimeofday(&now, NULL);
271 call_msg.rm_xid = ((u_int32_t)++disrupt) ^ __RPC_GETXID(&now);
272 call_msg.rm_direction = CALL;
273 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
274 call_msg.rm_call.cb_prog = (u_int32_t)prog;
275 call_msg.rm_call.cb_vers = (u_int32_t)vers;
278 * pre-serialize the static part of the call msg and stash it away
280 xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
282 if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
283 if (ct->ct_closeit) {
288 ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
289 XDR_DESTROY(&(ct->ct_xdrs));
290 assert(ct->ct_mpos + sizeof(uint32_t) <= MCALL_MSG_SIZE);
293 * Create a client handle which uses xdrrec for serialization
294 * and authnone for authentication.
296 cl->cl_ops = clnt_vc_ops();
298 cl->cl_auth = authnone_create();
299 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
300 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
301 xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
302 cl->cl_private, read_vc, write_vc);
308 mem_free(ct->ct_addr.buf, ct->ct_addr.len);
309 mem_free(ct, sizeof (struct ct_data));
312 mem_free(cl, sizeof (CLIENT));
313 return ((CLIENT *)NULL);
316 static enum clnt_stat
317 clnt_vc_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xdr_args, void *args_ptr,
318 xdrproc_t xdr_results, void *results_ptr, struct timeval timeout)
320 struct ct_data *ct = (struct ct_data *) cl->cl_private;
321 XDR *xdrs = &(ct->ct_xdrs);
322 struct rpc_msg reply_msg;
324 u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */
327 sigset_t mask, newmask;
333 sigfillset(&newmask);
334 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
335 mutex_lock(&clnt_fd_lock);
336 while (vc_fd_locks[ct->ct_fd])
337 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
342 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
343 mutex_unlock(&clnt_fd_lock);
344 if (!ct->ct_waitset) {
345 /* If time is not within limits, we ignore it. */
346 if (time_not_ok(&timeout) == FALSE)
347 ct->ct_wait = timeout;
351 (xdr_results == NULL && timeout.tv_sec == 0
352 && timeout.tv_usec == 0) ? FALSE : TRUE;
355 xdrs->x_op = XDR_ENCODE;
356 ct->ct_error.re_status = RPC_SUCCESS;
357 x_id = ntohl(--(*msg_x_id));
359 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
360 if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
361 (! XDR_PUTINT32(xdrs, &proc)) ||
362 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
363 (! (*xdr_args)(xdrs, args_ptr))) {
364 if (ct->ct_error.re_status == RPC_SUCCESS)
365 ct->ct_error.re_status = RPC_CANTENCODEARGS;
366 (void)xdrrec_endofrecord(xdrs, TRUE);
367 release_fd_lock(ct->ct_fd, mask);
368 return (ct->ct_error.re_status);
371 *(uint32_t *) &ct->ct_u.ct_mcallc[ct->ct_mpos] = htonl(proc);
372 if (! __rpc_gss_wrap(cl->cl_auth, ct->ct_u.ct_mcallc,
373 ct->ct_mpos + sizeof(uint32_t),
374 xdrs, xdr_args, args_ptr)) {
375 if (ct->ct_error.re_status == RPC_SUCCESS)
376 ct->ct_error.re_status = RPC_CANTENCODEARGS;
377 (void)xdrrec_endofrecord(xdrs, TRUE);
378 release_fd_lock(ct->ct_fd, mask);
379 return (ct->ct_error.re_status);
382 if (! xdrrec_endofrecord(xdrs, shipnow)) {
383 release_fd_lock(ct->ct_fd, mask);
384 return (ct->ct_error.re_status = RPC_CANTSEND);
387 release_fd_lock(ct->ct_fd, mask);
388 return (RPC_SUCCESS);
391 * Hack to provide rpc-based message passing
393 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
394 release_fd_lock(ct->ct_fd, mask);
395 return(ct->ct_error.re_status = RPC_TIMEDOUT);
400 * Keep receiving until we get a valid transaction id
402 xdrs->x_op = XDR_DECODE;
404 reply_msg.acpted_rply.ar_verf = _null_auth;
405 reply_msg.acpted_rply.ar_results.where = NULL;
406 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
407 if (! xdrrec_skiprecord(xdrs)) {
408 release_fd_lock(ct->ct_fd, mask);
409 return (ct->ct_error.re_status);
411 /* now decode and validate the response header */
412 if (! xdr_replymsg(xdrs, &reply_msg)) {
413 if (ct->ct_error.re_status == RPC_SUCCESS)
415 release_fd_lock(ct->ct_fd, mask);
416 return (ct->ct_error.re_status);
418 if (reply_msg.rm_xid == x_id)
425 _seterr_reply(&reply_msg, &(ct->ct_error));
426 if (ct->ct_error.re_status == RPC_SUCCESS) {
427 if (! AUTH_VALIDATE(cl->cl_auth,
428 &reply_msg.acpted_rply.ar_verf)) {
429 ct->ct_error.re_status = RPC_AUTHERROR;
430 ct->ct_error.re_why = AUTH_INVALIDRESP;
432 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
433 reply_stat = (*xdr_results)(xdrs, results_ptr);
435 reply_stat = __rpc_gss_unwrap(cl->cl_auth,
436 xdrs, xdr_results, results_ptr);
439 if (ct->ct_error.re_status == RPC_SUCCESS)
440 ct->ct_error.re_status =
444 /* free verifier ... */
445 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
446 xdrs->x_op = XDR_FREE;
447 (void)xdr_opaque_auth(xdrs,
448 &(reply_msg.acpted_rply.ar_verf));
450 } /* end successful completion */
452 /* maybe our credentials need to be refreshed ... */
453 if (refreshes-- && AUTH_REFRESH(cl->cl_auth, &reply_msg))
455 } /* end of unsuccessful completion */
456 release_fd_lock(ct->ct_fd, mask);
457 return (ct->ct_error.re_status);
461 clnt_vc_geterr(CLIENT *cl, struct rpc_err *errp)
466 assert(errp != NULL);
468 ct = (struct ct_data *) cl->cl_private;
469 *errp = ct->ct_error;
473 clnt_vc_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
483 ct = (struct ct_data *)cl->cl_private;
484 xdrs = &(ct->ct_xdrs);
486 sigfillset(&newmask);
487 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
488 mutex_lock(&clnt_fd_lock);
489 while (vc_fd_locks[ct->ct_fd])
490 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
491 xdrs->x_op = XDR_FREE;
492 dummy = (*xdr_res)(xdrs, res_ptr);
493 mutex_unlock(&clnt_fd_lock);
494 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
495 cond_signal(&vc_cv[ct->ct_fd]);
502 clnt_vc_abort(CLIENT *cl)
507 htonlp(void *dst, const void *src, uint32_t incr)
509 /* We are aligned, so we think */
510 *(uint32_t *)dst = htonl(*(const uint32_t *)src + incr);
514 ntohlp(void *dst, const void *src)
516 /* We are aligned, so we think */
517 *(uint32_t *)dst = htonl(*(const uint32_t *)src);
521 clnt_vc_control(CLIENT *cl, u_int request, void *info)
531 ct = (struct ct_data *)cl->cl_private;
533 sigfillset(&newmask);
534 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
535 mutex_lock(&clnt_fd_lock);
536 while (vc_fd_locks[ct->ct_fd])
537 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
542 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
543 mutex_unlock(&clnt_fd_lock);
547 ct->ct_closeit = TRUE;
548 release_fd_lock(ct->ct_fd, mask);
550 case CLSET_FD_NCLOSE:
551 ct->ct_closeit = FALSE;
552 release_fd_lock(ct->ct_fd, mask);
558 /* for other requests which use info */
560 release_fd_lock(ct->ct_fd, mask);
565 if (time_not_ok((struct timeval *)info)) {
566 release_fd_lock(ct->ct_fd, mask);
569 ct->ct_wait = *(struct timeval *)infop;
570 ct->ct_waitset = TRUE;
573 *(struct timeval *)infop = ct->ct_wait;
575 case CLGET_SERVER_ADDR:
576 (void) memcpy(info, ct->ct_addr.buf, (size_t)ct->ct_addr.len);
579 *(int *)info = ct->ct_fd;
582 /* The caller should not free this memory area */
583 *(struct netbuf *)info = ct->ct_addr;
585 case CLSET_SVC_ADDR: /* set to new address */
586 release_fd_lock(ct->ct_fd, mask);
590 * use the knowledge that xid is the
591 * first element in the call structure
592 * This will get the xid of the PREVIOUS call
594 ntohlp(info, &ct->ct_u.ct_mcalli);
597 /* This will set the xid of the NEXT call */
598 /* increment by 1 as clnt_vc_call() decrements once */
599 htonlp(&ct->ct_u.ct_mcalli, info, 1);
603 * This RELIES on the information that, in the call body,
604 * the version number field is the fifth field from the
605 * begining of the RPC header. MUST be changed if the
606 * call_struct is changed
608 ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT);
612 htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info, 0);
617 * This RELIES on the information that, in the call body,
618 * the program number field is the fourth field from the
619 * begining of the RPC header. MUST be changed if the
620 * call_struct is changed
622 ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT);
626 htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info, 0);
630 release_fd_lock(ct->ct_fd, mask);
633 release_fd_lock(ct->ct_fd, mask);
639 clnt_vc_destroy(CLIENT *cl)
641 struct ct_data *ct = (struct ct_data *) cl->cl_private;
642 int ct_fd = ct->ct_fd;
648 ct = (struct ct_data *) cl->cl_private;
650 sigfillset(&newmask);
651 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
652 mutex_lock(&clnt_fd_lock);
653 while (vc_fd_locks[ct_fd])
654 cond_wait(&vc_cv[ct_fd], &clnt_fd_lock);
655 if (ct->ct_closeit && ct->ct_fd != -1) {
656 (void)_close(ct->ct_fd);
658 XDR_DESTROY(&(ct->ct_xdrs));
659 free(ct->ct_addr.buf);
660 mem_free(ct, sizeof(struct ct_data));
661 if (cl->cl_netid && cl->cl_netid[0])
662 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
663 if (cl->cl_tp && cl->cl_tp[0])
664 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
665 mem_free(cl, sizeof(CLIENT));
666 mutex_unlock(&clnt_fd_lock);
667 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
668 cond_signal(&vc_cv[ct_fd]);
672 * Interface between xdr serializer and tcp connection.
673 * Behaves like the system calls, read & write, but keeps some error state
674 * around for the rpc level.
677 read_vc(void *ctp, void *buf, int len)
681 struct ct_data *ct = (struct ct_data *)ctp;
683 int milliseconds = (int)((ct->ct_wait.tv_sec * 1000) +
684 (ct->ct_wait.tv_usec / 1000));
691 switch (_poll(&fd, 1, milliseconds)) {
693 ct->ct_error.re_status = RPC_TIMEDOUT;
699 ct->ct_error.re_status = RPC_CANTRECV;
700 ct->ct_error.re_errno = errno;
707 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
708 (sa.sa_family == AF_LOCAL)) {
709 len = __msgread(ct->ct_fd, buf, (size_t)len);
711 len = _read(ct->ct_fd, buf, (size_t)len);
717 ct->ct_error.re_errno = ECONNRESET;
718 ct->ct_error.re_status = RPC_CANTRECV;
719 len = -1; /* it's really an error */
723 ct->ct_error.re_errno = errno;
724 ct->ct_error.re_status = RPC_CANTRECV;
731 write_vc(void *ctp, void *buf, int len)
735 struct ct_data *ct = (struct ct_data *)ctp;
739 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
740 (sa.sa_family == AF_LOCAL)) {
741 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
742 if ((i = __msgwrite(ct->ct_fd, buf,
743 (size_t)cnt)) == -1) {
744 ct->ct_error.re_errno = errno;
745 ct->ct_error.re_status = RPC_CANTSEND;
750 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
751 if ((i = _write(ct->ct_fd, buf, (size_t)cnt)) == -1) {
752 ct->ct_error.re_errno = errno;
753 ct->ct_error.re_status = RPC_CANTSEND;
761 static struct clnt_ops *
764 static struct clnt_ops ops;
765 sigset_t mask, newmask;
767 /* VARIABLES PROTECTED BY ops_lock: ops */
769 sigfillset(&newmask);
770 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
771 mutex_lock(&ops_lock);
772 if (ops.cl_call == NULL) {
773 ops.cl_call = clnt_vc_call;
774 ops.cl_abort = clnt_vc_abort;
775 ops.cl_geterr = clnt_vc_geterr;
776 ops.cl_freeres = clnt_vc_freeres;
777 ops.cl_destroy = clnt_vc_destroy;
778 ops.cl_control = clnt_vc_control;
780 mutex_unlock(&ops_lock);
781 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
786 * Make sure that the time is not garbage. -1 value is disallowed.
787 * Note this is different from time_not_ok in clnt_dg.c
790 time_not_ok(struct timeval *t)
792 return (t->tv_sec <= -1 || t->tv_sec > 100000000 ||
793 t->tv_usec <= -1 || t->tv_usec > 1000000);
797 __msgread(int sock, void *buf, size_t cnt)
803 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
806 bzero((char *)&cm, sizeof(cm));
807 iov[0].iov_base = buf;
808 iov[0].iov_len = cnt;
814 msg.msg_control = (caddr_t)&cm;
815 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
818 return(_recvmsg(sock, &msg, 0));
822 __msgwrite(int sock, void *buf, size_t cnt)
828 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
831 bzero((char *)&cm, sizeof(cm));
832 iov[0].iov_base = buf;
833 iov[0].iov_len = cnt;
835 cm.cmsg.cmsg_type = SCM_CREDS;
836 cm.cmsg.cmsg_level = SOL_SOCKET;
837 cm.cmsg.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
843 msg.msg_control = (caddr_t)&cm;
844 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
847 return(_sendmsg(sock, &msg, 0));