Lines Matching +full:cm +full:- +full:poll +full:- +full:interval
3 /*-
4 * SPDX-License-Identifier: BSD-3-Clause
11 * - Redistributions of source code must retain the above copyright notice,
13 * - Redistributions in binary form must reproduce the above copyright notice,
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
39 * A sequence of calls may be batched-up in a send buffer. The rpc call
55 #include <sys/poll.h>
77 #include "un-namespace.h"
105 struct timeval ct_wait; /* wait interval in milliseconds */
118 * This machinery implements per-fd locks for MT-safety. It is not
119 * sufficient to do per-CLIENT handle locks for MT-safety because a
137 if (a->fd > b->fd) { in cmp_vc_fd()
139 } else if (a->fd < b->fd) { in cmp_vc_fd()
140 return (-1); in cmp_vc_fd()
163 elem->fd = fd; in vc_fd_find()
164 mutex_init(&elem->mtx, NULL); in vc_fd_find()
173 mutex_unlock(&elem->mtx); in release_fd_lock()
187 * NB: The rpch->cl_auth is set null authentication. Caller may wish to
192 * fd - open file descriptor
193 * raddr - servers address
194 * prog - program number
195 * vers - version number
196 * sendsz - buffer send size
197 * recvsz - buffer recv size
224 ct->ct_addr.buf = NULL; in clnt_vc_create()
227 * XXX - fvdl connecting while holding a mutex? in clnt_vc_create()
237 if (_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){ in clnt_vc_create()
248 ct->ct_closeit = FALSE; in clnt_vc_create()
253 ct->ct_fd = fd; in clnt_vc_create()
254 ct->ct_wait.tv_usec = 0; in clnt_vc_create()
255 ct->ct_waitset = FALSE; in clnt_vc_create()
256 ct->ct_addr.buf = malloc(raddr->maxlen); in clnt_vc_create()
257 if (ct->ct_addr.buf == NULL) in clnt_vc_create()
259 memcpy(ct->ct_addr.buf, raddr->buf, raddr->len); in clnt_vc_create()
260 ct->ct_addr.len = raddr->len; in clnt_vc_create()
261 ct->ct_addr.maxlen = raddr->maxlen; in clnt_vc_create()
274 * pre-serialize the static part of the call msg and stash it away in clnt_vc_create()
276 xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE, in clnt_vc_create()
278 if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) { in clnt_vc_create()
279 if (ct->ct_closeit) { in clnt_vc_create()
284 ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs)); in clnt_vc_create()
285 XDR_DESTROY(&(ct->ct_xdrs)); in clnt_vc_create()
286 assert(ct->ct_mpos + sizeof(uint32_t) <= MCALL_MSG_SIZE); in clnt_vc_create()
292 cl->cl_ops = clnt_vc_ops(); in clnt_vc_create()
293 cl->cl_private = ct; in clnt_vc_create()
294 cl->cl_auth = authnone_create(); in clnt_vc_create()
297 xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz, in clnt_vc_create()
298 cl->cl_private, read_vc, write_vc); in clnt_vc_create()
303 if (ct->ct_addr.len) in clnt_vc_create()
304 mem_free(ct->ct_addr.buf, ct->ct_addr.len); in clnt_vc_create()
316 struct ct_data *ct = (struct ct_data *) cl->cl_private; in clnt_vc_call()
317 XDR *xdrs = &(ct->ct_xdrs); in clnt_vc_call()
321 u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */ in clnt_vc_call()
332 elem = vc_fd_find(ct->ct_fd); in clnt_vc_call()
334 mutex_lock(&elem->mtx); in clnt_vc_call()
335 if (!ct->ct_waitset) { in clnt_vc_call()
338 ct->ct_wait = timeout; in clnt_vc_call()
346 xdrs->x_op = XDR_ENCODE; in clnt_vc_call()
347 ct->ct_error.re_status = RPC_SUCCESS; in clnt_vc_call()
348 x_id = ntohl(--(*msg_x_id)); in clnt_vc_call()
350 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) { in clnt_vc_call()
351 if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) || in clnt_vc_call()
353 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) || in clnt_vc_call()
355 if (ct->ct_error.re_status == RPC_SUCCESS) in clnt_vc_call()
356 ct->ct_error.re_status = RPC_CANTENCODEARGS; in clnt_vc_call()
359 return (ct->ct_error.re_status); in clnt_vc_call()
362 *(uint32_t *) &ct->ct_u.ct_mcallc[ct->ct_mpos] = htonl(proc); in clnt_vc_call()
363 if (! __rpc_gss_wrap(cl->cl_auth, ct->ct_u.ct_mcallc, in clnt_vc_call()
364 ct->ct_mpos + sizeof(uint32_t), in clnt_vc_call()
366 if (ct->ct_error.re_status == RPC_SUCCESS) in clnt_vc_call()
367 ct->ct_error.re_status = RPC_CANTENCODEARGS; in clnt_vc_call()
370 return (ct->ct_error.re_status); in clnt_vc_call()
375 return (ct->ct_error.re_status = RPC_CANTSEND); in clnt_vc_call()
382 * Hack to provide rpc-based message passing in clnt_vc_call()
386 return(ct->ct_error.re_status = RPC_TIMEDOUT); in clnt_vc_call()
393 xdrs->x_op = XDR_DECODE; in clnt_vc_call()
400 return (ct->ct_error.re_status); in clnt_vc_call()
404 if (ct->ct_error.re_status == RPC_SUCCESS) in clnt_vc_call()
407 return (ct->ct_error.re_status); in clnt_vc_call()
416 _seterr_reply(&reply_msg, &(ct->ct_error)); in clnt_vc_call()
417 if (ct->ct_error.re_status == RPC_SUCCESS) { in clnt_vc_call()
418 if (! AUTH_VALIDATE(cl->cl_auth, in clnt_vc_call()
420 ct->ct_error.re_status = RPC_AUTHERROR; in clnt_vc_call()
421 ct->ct_error.re_why = AUTH_INVALIDRESP; in clnt_vc_call()
423 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) { in clnt_vc_call()
426 reply_stat = __rpc_gss_unwrap(cl->cl_auth, in clnt_vc_call()
430 if (ct->ct_error.re_status == RPC_SUCCESS) in clnt_vc_call()
431 ct->ct_error.re_status = in clnt_vc_call()
437 xdrs->x_op = XDR_FREE; in clnt_vc_call()
444 if (refreshes-- && AUTH_REFRESH(cl->cl_auth, &reply_msg)) in clnt_vc_call()
448 return (ct->ct_error.re_status); in clnt_vc_call()
459 ct = (struct ct_data *) cl->cl_private; in clnt_vc_geterr()
460 *errp = ct->ct_error; in clnt_vc_geterr()
475 ct = (struct ct_data *)cl->cl_private; in clnt_vc_freeres()
476 xdrs = &(ct->ct_xdrs); in clnt_vc_freeres()
481 elem = vc_fd_find(ct->ct_fd); in clnt_vc_freeres()
482 mutex_lock(&elem->mtx); in clnt_vc_freeres()
483 xdrs->x_op = XDR_FREE; in clnt_vc_freeres()
522 ct = (struct ct_data *)cl->cl_private; in clnt_vc_control()
527 elem = vc_fd_find(ct->ct_fd); in clnt_vc_control()
529 mutex_lock(&elem->mtx); in clnt_vc_control()
533 ct->ct_closeit = TRUE; in clnt_vc_control()
537 ct->ct_closeit = FALSE; in clnt_vc_control()
555 ct->ct_wait = *(struct timeval *)infop; in clnt_vc_control()
556 ct->ct_waitset = TRUE; in clnt_vc_control()
559 *(struct timeval *)infop = ct->ct_wait; in clnt_vc_control()
562 (void) memcpy(info, ct->ct_addr.buf, (size_t)ct->ct_addr.len); in clnt_vc_control()
565 *(int *)info = ct->ct_fd; in clnt_vc_control()
569 *(struct netbuf *)info = ct->ct_addr; in clnt_vc_control()
580 ntohlp(info, &ct->ct_u.ct_mcalli); in clnt_vc_control()
585 htonlp(&ct->ct_u.ct_mcalli, info, 1); in clnt_vc_control()
594 ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT); in clnt_vc_control()
598 htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info, 0); in clnt_vc_control()
608 ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT); in clnt_vc_control()
612 htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info, 0); in clnt_vc_control()
627 struct ct_data *ct = (struct ct_data *) cl->cl_private; in clnt_vc_destroy()
629 int ct_fd = ct->ct_fd; in clnt_vc_destroy()
635 ct = (struct ct_data *) cl->cl_private; in clnt_vc_destroy()
641 mutex_lock(&elem->mtx); in clnt_vc_destroy()
642 if (ct->ct_closeit && ct->ct_fd != -1) { in clnt_vc_destroy()
643 (void)_close(ct->ct_fd); in clnt_vc_destroy()
645 XDR_DESTROY(&(ct->ct_xdrs)); in clnt_vc_destroy()
646 free(ct->ct_addr.buf); in clnt_vc_destroy()
648 if (cl->cl_netid && cl->cl_netid[0]) in clnt_vc_destroy()
649 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1); in clnt_vc_destroy()
650 if (cl->cl_tp && cl->cl_tp[0]) in clnt_vc_destroy()
651 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1); in clnt_vc_destroy()
669 int milliseconds = (int)((ct->ct_wait.tv_sec * 1000) + in read_vc()
670 (ct->ct_wait.tv_usec / 1000)); in read_vc()
674 fd.fd = ct->ct_fd; in read_vc()
679 ct->ct_error.re_status = RPC_TIMEDOUT; in read_vc()
680 return (-1); in read_vc()
682 case -1: in read_vc()
685 ct->ct_error.re_status = RPC_CANTRECV; in read_vc()
686 ct->ct_error.re_errno = errno; in read_vc()
687 return (-1); in read_vc()
693 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) && in read_vc()
695 len = __msgread(ct->ct_fd, buf, (size_t)len); in read_vc()
697 len = _read(ct->ct_fd, buf, (size_t)len); in read_vc()
703 ct->ct_error.re_errno = ECONNRESET; in read_vc()
704 ct->ct_error.re_status = RPC_CANTRECV; in read_vc()
705 len = -1; /* it's really an error */ in read_vc()
708 case -1: in read_vc()
709 ct->ct_error.re_errno = errno; in read_vc()
710 ct->ct_error.re_status = RPC_CANTRECV; in read_vc()
725 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) && in write_vc()
727 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) { in write_vc()
728 if ((i = __msgwrite(ct->ct_fd, buf, in write_vc()
729 (size_t)cnt)) == -1) { in write_vc()
730 ct->ct_error.re_errno = errno; in write_vc()
731 ct->ct_error.re_status = RPC_CANTSEND; in write_vc()
732 return (-1); in write_vc()
736 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) { in write_vc()
737 if ((i = _write(ct->ct_fd, buf, (size_t)cnt)) == -1) { in write_vc()
738 ct->ct_error.re_errno = errno; in write_vc()
739 ct->ct_error.re_status = RPC_CANTSEND; in write_vc()
740 return (-1); in write_vc()
772 * Make sure that the time is not garbage. -1 value is disallowed.
778 return (t->tv_sec <= -1 || t->tv_sec > 100000000 || in time_not_ok()
779 t->tv_usec <= -1 || t->tv_usec > 1000000); in time_not_ok()
790 } cm; in __msgread() local
792 bzero((char *)&cm, sizeof(cm)); in __msgread()
800 msg.msg_control = (caddr_t)&cm; in __msgread()
815 } cm; in __msgwrite() local
817 bzero((char *)&cm, sizeof(cm)); in __msgwrite()
821 cm.cmsg.cmsg_type = SCM_CREDS; in __msgwrite()
822 cm.cmsg.cmsg_level = SOL_SOCKET; in __msgwrite()
823 cm.cmsg.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred)); in __msgwrite()
829 msg.msg_control = (caddr_t)&cm; in __msgwrite()