1 /* $NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 fvdl Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2010, Oracle America, 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 the "Oracle America, 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.
32 * from: @(#)clnt.h 1.31 94/04/29 SMI
33 * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
38 * clnt.h - Client side remote procedure call interface.
40 * Copyright (c) 1986-1991,1994-1999 by Sun Microsystems, Inc.
41 * All rights reserved.
46 #include <rpc/clnt_stat.h>
47 #include <sys/cdefs.h>
49 #include <sys/refcount.h>
50 #include <rpc/netconfig.h>
52 #include <netconfig.h>
57 * Well-known IPV6 RPC broadcast address.
59 #define RPCB_MULTICAST_ADDR "ff02::202"
62 * the following errors are in general unrecoverable. The caller
63 * should give up rather than retry.
65 #define IS_UNRECOVERABLE_RPC(s) (((s) == RPC_AUTHERROR) || \
66 ((s) == RPC_CANTENCODEARGS) || \
67 ((s) == RPC_CANTDECODERES) || \
68 ((s) == RPC_VERSMISMATCH) || \
69 ((s) == RPC_PROCUNAVAIL) || \
70 ((s) == RPC_PROGUNAVAIL) || \
71 ((s) == RPC_PROGVERSMISMATCH) || \
72 ((s) == RPC_CANTDECODEARGS))
78 enum clnt_stat re_status;
80 int RE_errno; /* related system error */
81 enum auth_stat RE_why; /* why the auth error occurred */
83 rpcvers_t low; /* lowest version supported */
84 rpcvers_t high; /* highest version supported */
86 struct { /* maybe meaningful if RPC_FAILED */
89 } RE_lb; /* life boot & debugging only */
91 #define re_errno ru.RE_errno
92 #define re_why ru.RE_why
93 #define re_vers ru.RE_vers
94 #define re_lb ru.RE_lb
99 * Functions of this type may be used to receive notification when RPC
100 * calls have to be re-transmitted etc.
102 typedef void rpc_feedback(int cmd, int procnum, void *);
105 * Timers used for the pseudo-transport protocol when using datagrams
108 u_short rt_srtt; /* smoothed round-trip time */
109 u_short rt_deviate; /* estimated deviation */
110 u_long rt_rtxcur; /* current (backed-off) rto */
114 * A structure used with CLNT_CALL_EXT to pass extra information used
115 * while processing an RPC call.
117 struct rpc_callextra {
118 AUTH *rc_auth; /* auth handle to use for this call */
119 rpc_feedback *rc_feedback; /* callback for retransmits etc. */
120 void *rc_feedback_arg; /* argument for callback */
121 struct rpc_timers *rc_timers; /* optional RTT timers */
122 struct rpc_err rc_err; /* detailed call status */
128 * Created by individual implementations
129 * Client is responsible for initializing auth, see e.g. auth_none.c.
131 typedef struct __rpc_client {
133 volatile u_int cl_refs; /* reference count */
134 AUTH *cl_auth; /* authenticator */
136 /* call remote procedure */
137 enum clnt_stat (*cl_call)(struct __rpc_client *,
138 struct rpc_callextra *, rpcproc_t,
139 struct mbuf *, struct mbuf **, struct timeval);
141 void (*cl_abort)(struct __rpc_client *);
142 /* get specific error code */
143 void (*cl_geterr)(struct __rpc_client *,
146 bool_t (*cl_freeres)(struct __rpc_client *,
148 /* close the connection and terminate pending RPCs */
149 void (*cl_close)(struct __rpc_client *);
150 /* destroy this structure */
151 void (*cl_destroy)(struct __rpc_client *);
152 /* the ioctl() of rpc */
153 bool_t (*cl_control)(struct __rpc_client *, u_int,
157 AUTH *cl_auth; /* authenticator */
159 /* call remote procedure */
160 enum clnt_stat (*cl_call)(struct __rpc_client *,
161 rpcproc_t, xdrproc_t, void *, xdrproc_t,
162 void *, struct timeval);
164 void (*cl_abort)(struct __rpc_client *);
165 /* get specific error code */
166 void (*cl_geterr)(struct __rpc_client *,
169 bool_t (*cl_freeres)(struct __rpc_client *,
171 /* destroy this structure */
172 void (*cl_destroy)(struct __rpc_client *);
173 /* the ioctl() of rpc */
174 bool_t (*cl_control)(struct __rpc_client *, u_int,
178 void *cl_private; /* private stuff */
179 char *cl_netid; /* network token */
180 char *cl_tp; /* device name */
184 * Feedback values used for possible congestion and rate control
186 #define FEEDBACK_OK 1 /* no retransmits */
187 #define FEEDBACK_REXMIT1 2 /* first retransmit */
188 #define FEEDBACK_REXMIT2 3 /* second and subsequent retransmit */
189 #define FEEDBACK_RECONNECT 4 /* client reconnect */
191 /* Used to set version of portmapper used in broadcast */
193 #define CLCR_SET_LOWVERS 3
194 #define CLCR_GET_LOWVERS 4
196 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
199 * client side rpc interface ops
201 * Parameter types are:
206 #define CLNT_ACQUIRE(rh) \
207 refcount_acquire(&(rh)->cl_refs)
208 #define CLNT_RELEASE(rh) \
209 if (refcount_release(&(rh)->cl_refs)) \
217 #define CLNT_CLOSE(rh) ((*(rh)->cl_ops->cl_close)(rh))
219 enum clnt_stat clnt_call_private(CLIENT *, struct rpc_callextra *, rpcproc_t,
220 xdrproc_t, void *, xdrproc_t, void *, struct timeval);
224 * CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, timeout)
226 * struct rpc_callextra *ext;
229 * struct mbuf **mrepp;
230 * struct timeval timeout;
232 * Call arguments in mreq which is consumed by the call (even if there
233 * is an error). Results returned in *mrepp.
235 #define CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, secs) \
236 ((*(rh)->cl_ops->cl_call)(rh, ext, proc, mreq, mrepp, secs))
240 * CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, timeout)
242 * struct rpc_callextra *ext;
248 * struct timeval timeout;
250 #define CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, secs) \
251 clnt_call_private(rh, ext, proc, xargs, \
252 argsp, xres, resp, secs)
257 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
264 * struct timeval timeout;
267 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
268 clnt_call_private(rh, NULL, proc, xargs, \
269 argsp, xres, resp, secs)
270 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
271 clnt_call_private(rh, NULL, proc, xargs, \
272 argsp, xres, resp, secs)
274 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
275 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
276 argsp, xres, resp, secs))
277 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
278 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
279 argsp, xres, resp, secs))
287 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
288 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
295 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
296 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
301 * CLNT_FREERES(rh, xres, resp);
306 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
307 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
311 * CLNT_CONTROL(cl, request, info)
316 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
317 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
320 * control operations that apply to both udp and tcp transports
322 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
323 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
324 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
325 #define CLGET_FD 6 /* get connections file descriptor */
326 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
327 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
328 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
329 #define CLGET_XID 10 /* Get xid */
330 #define CLSET_XID 11 /* Set xid */
331 #define CLGET_VERS 12 /* Get version number */
332 #define CLSET_VERS 13 /* Set version number */
333 #define CLGET_PROG 14 /* Get program number */
334 #define CLSET_PROG 15 /* Set program number */
335 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
336 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
337 #define CLSET_POP_TIMOD 18 /* pop timod */
339 * Connectionless only control operations
341 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
342 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
343 #define CLSET_ASYNC 19
344 #define CLSET_CONNECT 20 /* Use connect() for UDP. (int) */
348 * Kernel control operations. The default msleep string is "rpcrecv",
349 * and sleeps are non-interruptible by default.
351 #define CLSET_WAITCHAN 21 /* set string to use in msleep call */
352 #define CLGET_WAITCHAN 22 /* get string used in msleep call */
353 #define CLSET_INTERRUPTIBLE 23 /* set interruptible flag */
354 #define CLGET_INTERRUPTIBLE 24 /* set interruptible flag */
355 #define CLSET_RETRIES 25 /* set retry count for reconnect */
356 #define CLGET_RETRIES 26 /* get retry count for reconnect */
357 #define CLSET_PRIVPORT 27 /* set privileged source port flag */
358 #define CLGET_PRIVPORT 28 /* get privileged source port flag */
359 #define CLSET_BACKCHANNEL 29 /* set backchannel for socket */
368 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
369 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
373 * RPCTEST is a test program which is accessible on every rpc
374 * transport/port. It is used for testing, performance evaluation,
375 * and network administration.
378 #define RPCTEST_PROGRAM ((rpcprog_t)1)
379 #define RPCTEST_VERSION ((rpcvers_t)1)
380 #define RPCTEST_NULL_PROC ((rpcproc_t)2)
381 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
384 * By convention, procedure 0 takes null arguments and returns them
387 #define NULLPROC ((rpcproc_t)0)
390 * Below are the client handle creation routines for the various
391 * implementations of client side rpc. They can return NULL if a
392 * creation failure occurs.
396 * Generic client creation routine. Supported protocols are those that
397 * belong to the nettype namespace (/etc/netconfig).
403 * struct socket *so; -- socket
404 * struct sockaddr *svcaddr; -- servers address
405 * rpcprog_t prog; -- program number
406 * rpcvers_t vers; -- version number
407 * size_t sendsz; -- buffer recv size
408 * size_t recvsz; -- buffer send size
410 extern CLIENT *clnt_dg_create(struct socket *so,
411 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version,
412 size_t sendsz, size_t recvsz);
415 * struct socket *so; -- socket
416 * struct sockaddr *svcaddr; -- servers address
417 * rpcprog_t prog; -- program number
418 * rpcvers_t vers; -- version number
419 * size_t sendsz; -- buffer recv size
420 * size_t recvsz; -- buffer send size
421 * int intrflag; -- is it interruptible
423 extern CLIENT *clnt_vc_create(struct socket *so,
424 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version,
425 size_t sendsz, size_t recvsz, int intrflag);
428 * struct netconfig *nconf; -- network type
429 * struct sockaddr *svcaddr; -- servers address
430 * rpcprog_t prog; -- program number
431 * rpcvers_t vers; -- version number
432 * size_t sendsz; -- buffer recv size
433 * size_t recvsz; -- buffer send size
435 extern CLIENT *clnt_reconnect_create(struct netconfig *nconf,
436 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version,
437 size_t sendsz, size_t recvsz);
441 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
445 * const char *hostname; -- hostname
446 * const rpcprog_t prog; -- program number
447 * const rpcvers_t vers; -- version number
448 * const char *nettype; -- network type
452 * Generic client creation routine. Just like clnt_create(), except
453 * it takes an additional timeout parameter.
455 extern CLIENT * clnt_create_timed(const char *, const rpcprog_t,
456 const rpcvers_t, const char *, const struct timeval *);
459 * const char *hostname; -- hostname
460 * const rpcprog_t prog; -- program number
461 * const rpcvers_t vers; -- version number
462 * const char *nettype; -- network type
463 * const struct timeval *tp; -- timeout
467 * Generic client creation routine. Supported protocols are which belong
468 * to the nettype name space.
470 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
471 const rpcvers_t, const rpcvers_t,
474 * const char *host; -- hostname
475 * const rpcprog_t prog; -- program number
476 * rpcvers_t *vers_out; -- servers highest available version
477 * const rpcvers_t vers_low; -- low version number
478 * const rpcvers_t vers_high; -- high version number
479 * const char *nettype; -- network type
483 * Generic client creation routine. Supported protocols are which belong
484 * to the nettype name space.
486 extern CLIENT * clnt_create_vers_timed(const char *, const rpcprog_t,
487 rpcvers_t *, const rpcvers_t, const rpcvers_t, const char *,
488 const struct timeval *);
490 * const char *host; -- hostname
491 * const rpcprog_t prog; -- program number
492 * rpcvers_t *vers_out; -- servers highest available version
493 * const rpcvers_t vers_low; -- low version number
494 * const rpcvers_t vers_high; -- high version number
495 * const char *nettype; -- network type
496 * const struct timeval *tp -- timeout
500 * Generic client creation routine. It takes a netconfig structure
503 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t,
504 const rpcvers_t, const struct netconfig *);
506 * const char *hostname; -- hostname
507 * const rpcprog_t prog; -- program number
508 * const rpcvers_t vers; -- version number
509 * const struct netconfig *netconf; -- network config structure
513 * Generic client creation routine. Just like clnt_tp_create(), except
514 * it takes an additional timeout parameter.
516 extern CLIENT * clnt_tp_create_timed(const char *, const rpcprog_t,
517 const rpcvers_t, const struct netconfig *, const struct timeval *);
519 * const char *hostname; -- hostname
520 * const rpcprog_t prog; -- program number
521 * const rpcvers_t vers; -- version number
522 * const struct netconfig *netconf; -- network config structure
523 * const struct timeval *tp -- timeout
527 * Generic TLI create routine. Only provided for compatibility.
530 extern CLIENT *clnt_tli_create(const int, const struct netconfig *,
531 struct netbuf *, const rpcprog_t,
532 const rpcvers_t, const u_int, const u_int);
534 * const int fd; -- fd
535 * const struct netconfig *nconf; -- netconfig structure
536 * struct netbuf *svcaddr; -- servers address
537 * const u_long prog; -- program number
538 * const u_long vers; -- version number
539 * const u_int sendsz; -- send size
540 * const u_int recvsz; -- recv size
544 * Low level clnt create routine for connectionful transports, e.g. tcp.
546 extern CLIENT *clnt_vc_create(const int, const struct netbuf *,
547 const rpcprog_t, const rpcvers_t,
550 * Added for compatibility to old rpc 4.0. Obsoleted by clnt_vc_create().
552 extern CLIENT *clntunix_create(struct sockaddr_un *,
553 u_long, u_long, int *, u_int, u_int);
555 * const int fd; -- open file descriptor
556 * const struct netbuf *svcaddr; -- servers address
557 * const rpcprog_t prog; -- program number
558 * const rpcvers_t vers; -- version number
559 * const u_int sendsz; -- buffer recv size
560 * const u_int recvsz; -- buffer send size
564 * Low level clnt create routine for connectionless transports, e.g. udp.
566 extern CLIENT *clnt_dg_create(const int, const struct netbuf *,
567 const rpcprog_t, const rpcvers_t,
568 const u_int, const u_int);
570 * const int fd; -- open file descriptor
571 * const struct netbuf *svcaddr; -- servers address
572 * const rpcprog_t program; -- program number
573 * const rpcvers_t version; -- version number
574 * const u_int sendsz; -- buffer recv size
575 * const u_int recvsz; -- buffer send size
579 * Memory based rpc (for speed check and testing)
581 * clnt_raw_create(prog, vers)
585 extern CLIENT *clnt_raw_create(rpcprog_t, rpcvers_t);
592 * Print why creation failed
595 extern void clnt_pcreateerror(const char *); /* stderr */
596 extern char *clnt_spcreateerror(const char *); /* string */
600 * Like clnt_perror(), but is more verbose in its output
603 extern void clnt_perrno(enum clnt_stat); /* stderr */
604 extern char *clnt_sperrno(enum clnt_stat); /* string */
608 * Print an English error message, given the client error code
611 extern void clnt_perror(CLIENT *, const char *); /* stderr */
612 extern char *clnt_sperror(CLIENT *, const char *); /* string */
617 * If a creation fails, the following allows the user to figure out why.
619 struct rpc_createerr {
620 enum clnt_stat cf_stat;
621 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
625 extern struct rpc_createerr rpc_createerr;
628 extern struct rpc_createerr *__rpc_createerr(void);
630 #define rpc_createerr (*(__rpc_createerr()))
635 * The simplified interface:
637 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
639 * const rpcprog_t prognum;
640 * const rpcvers_t versnum;
641 * const rpcproc_t procnum;
642 * const xdrproc_t inproc, outproc;
645 * const char *nettype;
648 extern enum clnt_stat rpc_call(const char *, const rpcprog_t,
649 const rpcvers_t, const rpcproc_t,
650 const xdrproc_t, const char *,
651 const xdrproc_t, char *, const char *);
655 * RPC broadcast interface
656 * The call is broadcasted to all locally connected nets.
658 * extern enum clnt_stat
659 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
660 * eachresult, nettype)
661 * const rpcprog_t prog; -- program number
662 * const rpcvers_t vers; -- version number
663 * const rpcproc_t proc; -- procedure number
664 * const xdrproc_t xargs; -- xdr routine for args
665 * caddr_t argsp; -- pointer to args
666 * const xdrproc_t xresults; -- xdr routine for results
667 * caddr_t resultsp; -- pointer to results
668 * const resultproc_t eachresult; -- call with each result
669 * const char *nettype; -- Transport type
671 * For each valid response received, the procedure eachresult is called.
673 * done = eachresult(resp, raddr, nconf)
676 * struct netbuf *raddr;
677 * struct netconfig *nconf;
678 * where resp points to the results of the call and raddr is the
679 * address if the responder to the broadcast. nconf is the transport
680 * on which the response was received.
682 * extern enum clnt_stat
683 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
684 * eachresult, inittime, waittime, nettype)
685 * const rpcprog_t prog; -- program number
686 * const rpcvers_t vers; -- version number
687 * const rpcproc_t proc; -- procedure number
688 * const xdrproc_t xargs; -- xdr routine for args
689 * caddr_t argsp; -- pointer to args
690 * const xdrproc_t xresults; -- xdr routine for results
691 * caddr_t resultsp; -- pointer to results
692 * const resultproc_t eachresult; -- call with each result
693 * const int inittime; -- how long to wait initially
694 * const int waittime; -- maximum time to wait
695 * const char *nettype; -- Transport type
698 typedef bool_t (*resultproc_t)(caddr_t, ...);
701 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
702 const rpcproc_t, const xdrproc_t,
703 caddr_t, const xdrproc_t, caddr_t,
704 const resultproc_t, const char *);
705 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
706 const rpcproc_t, const xdrproc_t,
707 caddr_t, const xdrproc_t, caddr_t,
708 const resultproc_t, const int,
709 const int, const char *);
712 /* For backward compatibility */
713 #include <rpc/clnt_soc.h>
716 #endif /* !_RPC_CLNT_H_ */