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.
43 #include <rpc/clnt_stat.h>
44 #include <sys/cdefs.h>
45 #include <netconfig.h>
49 * Well-known IPV6 RPC broadcast address.
51 #define RPCB_MULTICAST_ADDR "ff02::202"
54 * the following errors are in general unrecoverable. The caller
55 * should give up rather than retry.
57 #define IS_UNRECOVERABLE_RPC(s) (((s) == RPC_AUTHERROR) || \
58 ((s) == RPC_CANTENCODEARGS) || \
59 ((s) == RPC_CANTDECODERES) || \
60 ((s) == RPC_VERSMISMATCH) || \
61 ((s) == RPC_PROCUNAVAIL) || \
62 ((s) == RPC_PROGUNAVAIL) || \
63 ((s) == RPC_PROGVERSMISMATCH) || \
64 ((s) == RPC_CANTDECODEARGS))
70 enum clnt_stat re_status;
72 int RE_errno; /* related system error */
73 enum auth_stat RE_why; /* why the auth error occurred */
75 rpcvers_t low; /* lowest version supported */
76 rpcvers_t high; /* highest version supported */
78 struct { /* maybe meaningful if RPC_FAILED */
81 } RE_lb; /* life boot & debugging only */
83 #define re_errno ru.RE_errno
84 #define re_why ru.RE_why
85 #define re_vers ru.RE_vers
86 #define re_lb ru.RE_lb
92 * Created by individual implementations
93 * Client is responsible for initializing auth, see e.g. auth_none.c.
95 typedef struct __rpc_client {
96 AUTH *cl_auth; /* authenticator */
98 /* call remote procedure */
99 enum clnt_stat (*cl_call)(struct __rpc_client *,
100 rpcproc_t, xdrproc_t, void *, xdrproc_t,
101 void *, struct timeval);
103 void (*cl_abort)(struct __rpc_client *);
104 /* get specific error code */
105 void (*cl_geterr)(struct __rpc_client *,
108 bool_t (*cl_freeres)(struct __rpc_client *,
110 /* destroy this structure */
111 void (*cl_destroy)(struct __rpc_client *);
112 /* the ioctl() of rpc */
113 bool_t (*cl_control)(struct __rpc_client *, u_int,
116 void *cl_private; /* private stuff */
117 char *cl_netid; /* network token */
118 char *cl_tp; /* device name */
123 * Timers used for the pseudo-transport protocol when using datagrams
126 u_short rt_srtt; /* smoothed round-trip time */
127 u_short rt_deviate; /* estimated deviation */
128 u_long rt_rtxcur; /* current (backed-off) rto */
132 * Feedback values used for possible congestion and rate control
134 #define FEEDBACK_REXMIT1 1 /* first retransmit */
135 #define FEEDBACK_OK 2 /* no retransmits */
137 /* Used to set version of portmapper used in broadcast */
139 #define CLCR_SET_LOWVERS 3
140 #define CLCR_GET_LOWVERS 4
142 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
145 * client side rpc interface ops
147 * Parameter types are:
153 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
160 * struct timeval timeout;
162 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
163 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
164 argsp, xres, resp, secs))
165 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
166 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
167 argsp, xres, resp, secs))
174 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
175 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
182 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
183 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
188 * CLNT_FREERES(rh, xres, resp);
193 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
194 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
198 * CLNT_CONTROL(cl, request, info)
203 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
204 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
207 * control operations that apply to both udp and tcp transports
209 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
210 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
211 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
212 #define CLGET_FD 6 /* get connections file descriptor */
213 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
214 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
215 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
216 #define CLGET_XID 10 /* Get xid */
217 #define CLSET_XID 11 /* Set xid */
218 #define CLGET_VERS 12 /* Get version number */
219 #define CLSET_VERS 13 /* Set version number */
220 #define CLGET_PROG 14 /* Get program number */
221 #define CLSET_PROG 15 /* Set program number */
222 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
223 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
224 #define CLSET_POP_TIMOD 18 /* pop timod */
226 * Connectionless only control operations
228 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
229 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
230 #define CLSET_ASYNC 19
231 #define CLSET_CONNECT 20 /* Use connect() for UDP. (int) */
238 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
239 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
243 * RPCTEST is a test program which is accessible on every rpc
244 * transport/port. It is used for testing, performance evaluation,
245 * and network administration.
248 #define RPCTEST_PROGRAM ((rpcprog_t)1)
249 #define RPCTEST_VERSION ((rpcvers_t)1)
250 #define RPCTEST_NULL_PROC ((rpcproc_t)2)
251 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
254 * By convention, procedure 0 takes null arguments and returns them
257 #define NULLPROC ((rpcproc_t)0)
260 * Below are the client handle creation routines for the various
261 * implementations of client side rpc. They can return NULL if a
262 * creation failure occurs.
266 * Generic client creation routine. Supported protocols are those that
267 * belong to the nettype namespace (/etc/netconfig).
270 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
274 * const char *hostname; -- hostname
275 * const rpcprog_t prog; -- program number
276 * const rpcvers_t vers; -- version number
277 * const char *nettype; -- network type
281 * Generic client creation routine. Just like clnt_create(), except
282 * it takes an additional timeout parameter.
284 extern CLIENT * clnt_create_timed(const char *, const rpcprog_t,
285 const rpcvers_t, const char *, const struct timeval *);
288 * const char *hostname; -- hostname
289 * const rpcprog_t prog; -- program number
290 * const rpcvers_t vers; -- version number
291 * const char *nettype; -- network type
292 * const struct timeval *tp; -- timeout
296 * Generic client creation routine. Supported protocols are which belong
297 * to the nettype name space.
299 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
300 const rpcvers_t, const rpcvers_t,
303 * const char *host; -- hostname
304 * const rpcprog_t prog; -- program number
305 * rpcvers_t *vers_out; -- servers highest available version
306 * const rpcvers_t vers_low; -- low version number
307 * const rpcvers_t vers_high; -- high version number
308 * const char *nettype; -- network type
312 * Generic client creation routine. Supported protocols are which belong
313 * to the nettype name space.
315 extern CLIENT * clnt_create_vers_timed(const char *, const rpcprog_t,
316 rpcvers_t *, const rpcvers_t, const rpcvers_t, const char *,
317 const struct timeval *);
319 * const char *host; -- hostname
320 * const rpcprog_t prog; -- program number
321 * rpcvers_t *vers_out; -- servers highest available version
322 * const rpcvers_t vers_low; -- low version number
323 * const rpcvers_t vers_high; -- high version number
324 * const char *nettype; -- network type
325 * const struct timeval *tp -- timeout
329 * Generic client creation routine. It takes a netconfig structure
332 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t,
333 const rpcvers_t, const struct netconfig *);
335 * const char *hostname; -- hostname
336 * const rpcprog_t prog; -- program number
337 * const rpcvers_t vers; -- version number
338 * const struct netconfig *netconf; -- network config structure
342 * Generic client creation routine. Just like clnt_tp_create(), except
343 * it takes an additional timeout parameter.
345 extern CLIENT * clnt_tp_create_timed(const char *, const rpcprog_t,
346 const rpcvers_t, const struct netconfig *, const struct timeval *);
348 * const char *hostname; -- hostname
349 * const rpcprog_t prog; -- program number
350 * const rpcvers_t vers; -- version number
351 * const struct netconfig *netconf; -- network config structure
352 * const struct timeval *tp -- timeout
356 * Generic TLI create routine. Only provided for compatibility.
359 extern CLIENT *clnt_tli_create(const int, const struct netconfig *,
360 struct netbuf *, const rpcprog_t,
361 const rpcvers_t, const u_int, const u_int);
363 * const register int fd; -- fd
364 * const struct netconfig *nconf; -- netconfig structure
365 * struct netbuf *svcaddr; -- servers address
366 * const u_long prog; -- program number
367 * const u_long vers; -- version number
368 * const u_int sendsz; -- send size
369 * const u_int recvsz; -- recv size
373 * Low level clnt create routine for connectionful transports, e.g. tcp.
375 extern CLIENT *clnt_vc_create(const int, const struct netbuf *,
376 const rpcprog_t, const rpcvers_t,
379 * Added for compatibility to old rpc 4.0. Obsoleted by clnt_vc_create().
381 extern CLIENT *clntunix_create(struct sockaddr_un *,
382 u_long, u_long, int *, u_int, u_int);
384 * const int fd; -- open file descriptor
385 * const struct netbuf *svcaddr; -- servers address
386 * const rpcprog_t prog; -- program number
387 * const rpcvers_t vers; -- version number
388 * const u_int sendsz; -- buffer recv size
389 * const u_int recvsz; -- buffer send size
393 * Low level clnt create routine for connectionless transports, e.g. udp.
395 extern CLIENT *clnt_dg_create(const int, const struct netbuf *,
396 const rpcprog_t, const rpcvers_t,
397 const u_int, const u_int);
399 * const int fd; -- open file descriptor
400 * const struct netbuf *svcaddr; -- servers address
401 * const rpcprog_t program; -- program number
402 * const rpcvers_t version; -- version number
403 * const u_int sendsz; -- buffer recv size
404 * const u_int recvsz; -- buffer send size
408 * Memory based rpc (for speed check and testing)
410 * clnt_raw_create(prog, vers)
414 extern CLIENT *clnt_raw_create(rpcprog_t, rpcvers_t);
420 * Print why creation failed
423 extern void clnt_pcreateerror(const char *); /* stderr */
424 extern char *clnt_spcreateerror(const char *); /* string */
428 * Like clnt_perror(), but is more verbose in its output
431 extern void clnt_perrno(enum clnt_stat); /* stderr */
432 extern char *clnt_sperrno(enum clnt_stat); /* string */
436 * Print an English error message, given the client error code
439 extern void clnt_perror(CLIENT *, const char *); /* stderr */
440 extern char *clnt_sperror(CLIENT *, const char *); /* string */
445 * If a creation fails, the following allows the user to figure out why.
447 struct rpc_createerr {
448 enum clnt_stat cf_stat;
449 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
453 extern struct rpc_createerr *__rpc_createerr(void);
455 #define rpc_createerr (*(__rpc_createerr()))
458 * The simplified interface:
460 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
462 * const rpcprog_t prognum;
463 * const rpcvers_t versnum;
464 * const rpcproc_t procnum;
465 * const xdrproc_t inproc, outproc;
468 * const char *nettype;
471 extern enum clnt_stat rpc_call(const char *, const rpcprog_t,
472 const rpcvers_t, const rpcproc_t,
473 const xdrproc_t, const char *,
474 const xdrproc_t, char *, const char *);
478 * RPC broadcast interface
479 * The call is broadcasted to all locally connected nets.
481 * extern enum clnt_stat
482 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
483 * eachresult, nettype)
484 * const rpcprog_t prog; -- program number
485 * const rpcvers_t vers; -- version number
486 * const rpcproc_t proc; -- procedure number
487 * const xdrproc_t xargs; -- xdr routine for args
488 * caddr_t argsp; -- pointer to args
489 * const xdrproc_t xresults; -- xdr routine for results
490 * caddr_t resultsp; -- pointer to results
491 * const resultproc_t eachresult; -- call with each result
492 * const char *nettype; -- Transport type
494 * For each valid response received, the procedure eachresult is called.
496 * done = eachresult(resp, raddr, nconf)
499 * struct netbuf *raddr;
500 * struct netconfig *nconf;
501 * where resp points to the results of the call and raddr is the
502 * address if the responder to the broadcast. nconf is the transport
503 * on which the response was received.
505 * extern enum clnt_stat
506 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
507 * eachresult, inittime, waittime, nettype)
508 * const rpcprog_t prog; -- program number
509 * const rpcvers_t vers; -- version number
510 * const rpcproc_t proc; -- procedure number
511 * const xdrproc_t xargs; -- xdr routine for args
512 * caddr_t argsp; -- pointer to args
513 * const xdrproc_t xresults; -- xdr routine for results
514 * caddr_t resultsp; -- pointer to results
515 * const resultproc_t eachresult; -- call with each result
516 * const int inittime; -- how long to wait initially
517 * const int waittime; -- maximum time to wait
518 * const char *nettype; -- Transport type
521 typedef bool_t (*resultproc_t)(caddr_t, ...);
524 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
525 const rpcproc_t, const xdrproc_t,
526 caddr_t, const xdrproc_t, caddr_t,
527 const resultproc_t, const char *);
528 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
529 const rpcproc_t, const xdrproc_t,
530 caddr_t, const xdrproc_t, caddr_t,
531 const resultproc_t, const int,
532 const int, const char *);
535 /* For backward compatibility */
536 #include <rpc/clnt_soc.h>
538 #endif /* !_RPC_CLNT_H_ */