1 /* $NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 fvdl Exp $ */
4 * Copyright (c) 2010, Oracle America, 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 the "Oracle America, 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.
30 * from: @(#)clnt.h 1.31 94/04/29 SMI
31 * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
32 * $FreeBSD: src/include/rpc/clnt.h,v 1.21 2003/01/24 01:47:55 fjoe Exp $
36 * clnt.h - Client side remote procedure call interface.
39 #ifndef _TIRPC_CLNT_H_
40 #define _TIRPC_CLNT_H_
42 #include <rpc/clnt_stat.h>
45 #include <sys/cdefs.h>
46 #include <netconfig.h>
50 * Well-known IPV6 RPC broadcast address.
52 #define RPCB_MULTICAST_ADDR "ff02::202"
55 * the following errors are in general unrecoverable. The caller
56 * should give up rather than retry.
58 #define IS_UNRECOVERABLE_RPC(s) (((s) == RPC_AUTHERROR) || \
59 ((s) == RPC_CANTENCODEARGS) || \
60 ((s) == RPC_CANTDECODERES) || \
61 ((s) == RPC_VERSMISMATCH) || \
62 ((s) == RPC_PROCUNAVAIL) || \
63 ((s) == RPC_PROGUNAVAIL) || \
64 ((s) == RPC_PROGVERSMISMATCH) || \
65 ((s) == RPC_CANTDECODEARGS))
71 enum clnt_stat re_status;
73 int RE_errno; /* related system error */
74 enum auth_stat RE_why; /* why the auth error occurred */
76 rpcvers_t low; /* lowest version supported */
77 rpcvers_t high; /* highest version supported */
79 struct { /* maybe meaningful if RPC_FAILED */
82 } RE_lb; /* life boot & debugging only */
84 #define re_errno ru.RE_errno
85 #define re_why ru.RE_why
86 #define re_vers ru.RE_vers
87 #define re_lb ru.RE_lb
93 * Created by individual implementations
94 * Client is responsible for initializing auth, see e.g. auth_none.c.
96 typedef struct __rpc_client {
97 AUTH *cl_auth; /* authenticator */
99 /* call remote procedure */
100 enum clnt_stat (*cl_call)(struct __rpc_client *,
101 rpcproc_t, xdrproc_t, void *, xdrproc_t,
102 void *, struct timeval);
104 void (*cl_abort)(struct __rpc_client *);
105 /* get specific error code */
106 void (*cl_geterr)(struct __rpc_client *,
109 bool_t (*cl_freeres)(struct __rpc_client *,
111 /* destroy this structure */
112 void (*cl_destroy)(struct __rpc_client *);
113 /* the ioctl() of rpc */
114 bool_t (*cl_control)(struct __rpc_client *, u_int,
117 void *cl_private; /* private stuff */
118 char *cl_netid; /* network token */
119 char *cl_tp; /* device name */
124 * Timers used for the pseudo-transport protocol when using datagrams
127 u_short rt_srtt; /* smoothed round-trip time */
128 u_short rt_deviate; /* estimated deviation */
129 u_long rt_rtxcur; /* current (backed-off) rto */
133 * Feedback values used for possible congestion and rate control
135 #define FEEDBACK_REXMIT1 1 /* first retransmit */
136 #define FEEDBACK_OK 2 /* no retransmits */
138 /* Used to set version of portmapper used in broadcast */
140 #define CLCR_SET_LOWVERS 3
141 #define CLCR_GET_LOWVERS 4
143 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
146 * client side rpc interface ops
148 * Parameter types are:
154 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
161 * struct timeval timeout;
163 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
164 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
165 argsp, xres, resp, secs))
166 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
167 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
168 argsp, xres, resp, secs))
175 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
176 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
183 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
184 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
189 * CLNT_FREERES(rh, xres, resp);
194 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
195 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
199 * CLNT_CONTROL(cl, request, info)
204 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
205 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
208 * control operations that apply to both udp and tcp transports
210 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
211 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
212 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
213 #define CLGET_FD 6 /* get connections file descriptor */
214 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
215 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
216 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
217 #define CLGET_XID 10 /* Get xid */
218 #define CLSET_XID 11 /* Set xid */
219 #define CLGET_VERS 12 /* Get version number */
220 #define CLSET_VERS 13 /* Set version number */
221 #define CLGET_PROG 14 /* Get program number */
222 #define CLSET_PROG 15 /* Set program number */
223 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
224 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
225 #define CLSET_POP_TIMOD 18 /* pop timod */
227 * Connectionless only control operations
229 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
230 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
231 #define CLSET_ASYNC 19
232 #define CLSET_CONNECT 20 /* Use connect() for UDP. (int) */
239 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
240 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
244 * RPCTEST is a test program which is accessible on every rpc
245 * transport/port. It is used for testing, performance evaluation,
246 * and network administration.
249 #define RPCTEST_PROGRAM ((rpcprog_t)1)
250 #define RPCTEST_VERSION ((rpcvers_t)1)
251 #define RPCTEST_NULL_PROC ((rpcproc_t)2)
252 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
255 * By convention, procedure 0 takes null arguments and returns them
258 #define NULLPROC ((rpcproc_t)0)
261 * Below are the client handle creation routines for the various
262 * implementations of client side rpc. They can return NULL if a
263 * creation failure occurs.
267 * Generic client creation routine. Supported protocols are those that
268 * belong to the nettype namespace (/etc/netconfig).
271 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
275 * const char *hostname; -- hostname
276 * const rpcprog_t prog; -- program number
277 * const rpcvers_t vers; -- version number
278 * const char *nettype; -- network type
282 * Generic client creation routine. Just like clnt_create(), except
283 * it takes an additional timeout parameter.
285 extern CLIENT * clnt_create_timed(const char *, const rpcprog_t,
286 const rpcvers_t, const char *, const struct timeval *);
289 * const char *hostname; -- hostname
290 * const rpcprog_t prog; -- program number
291 * const rpcvers_t vers; -- version number
292 * const char *nettype; -- network type
293 * const struct timeval *tp; -- timeout
297 * Generic client creation routine. Supported protocols are which belong
298 * to the nettype name space.
300 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
301 const rpcvers_t, const rpcvers_t,
304 * const char *host; -- hostname
305 * const rpcprog_t prog; -- program number
306 * rpcvers_t *vers_out; -- servers highest available version
307 * const rpcvers_t vers_low; -- low version number
308 * const rpcvers_t vers_high; -- high version number
309 * const char *nettype; -- network type
313 * Generic client creation routine. Supported protocols are which belong
314 * to the nettype name space.
316 extern CLIENT * clnt_create_vers_timed(const char *, const rpcprog_t,
317 rpcvers_t *, const rpcvers_t, const rpcvers_t, const char *,
318 const struct timeval *);
320 * const char *host; -- hostname
321 * const rpcprog_t prog; -- program number
322 * rpcvers_t *vers_out; -- servers highest available version
323 * const rpcvers_t vers_low; -- low version number
324 * const rpcvers_t vers_high; -- high version number
325 * const char *nettype; -- network type
326 * const struct timeval *tp -- timeout
330 * Generic client creation routine. It takes a netconfig structure
333 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t,
334 const rpcvers_t, const struct netconfig *);
336 * const char *hostname; -- hostname
337 * const rpcprog_t prog; -- program number
338 * const rpcvers_t vers; -- version number
339 * const struct netconfig *netconf; -- network config structure
343 * Generic client creation routine. Just like clnt_tp_create(), except
344 * it takes an additional timeout parameter.
346 extern CLIENT * clnt_tp_create_timed(const char *, const rpcprog_t,
347 const rpcvers_t, const struct netconfig *, const struct timeval *);
349 * const char *hostname; -- hostname
350 * const rpcprog_t prog; -- program number
351 * const rpcvers_t vers; -- version number
352 * const struct netconfig *netconf; -- network config structure
353 * const struct timeval *tp -- timeout
357 * Generic TLI create routine. Only provided for compatibility.
360 extern CLIENT *clnt_tli_create(const int, const struct netconfig *,
361 struct netbuf *, const rpcprog_t,
362 const rpcvers_t, const u_int, const u_int);
364 * const register int fd; -- fd
365 * const struct netconfig *nconf; -- netconfig structure
366 * struct netbuf *svcaddr; -- servers address
367 * const u_long prog; -- program number
368 * const u_long vers; -- version number
369 * const u_int sendsz; -- send size
370 * const u_int recvsz; -- recv size
374 * Low level clnt create routine for connectionful transports, e.g. tcp.
376 extern CLIENT *clnt_vc_create(const int, const struct netbuf *,
377 const rpcprog_t, const rpcvers_t,
380 * Added for compatibility to old rpc 4.0. Obsoleted by clnt_vc_create().
382 extern CLIENT *clntunix_create(struct sockaddr_un *,
383 u_long, u_long, int *, u_int, u_int);
385 * const int fd; -- open file descriptor
386 * const struct netbuf *svcaddr; -- servers address
387 * const rpcprog_t prog; -- program number
388 * const rpcvers_t vers; -- version number
389 * const u_int sendsz; -- buffer recv size
390 * const u_int recvsz; -- buffer send size
394 * Low level clnt create routine for connectionless transports, e.g. udp.
396 extern CLIENT *clnt_dg_create(const int, const struct netbuf *,
397 const rpcprog_t, const rpcvers_t,
398 const u_int, const u_int);
400 * const int fd; -- open file descriptor
401 * const struct netbuf *svcaddr; -- servers address
402 * const rpcprog_t program; -- program number
403 * const rpcvers_t version; -- version number
404 * const u_int sendsz; -- buffer recv size
405 * const u_int recvsz; -- buffer send size
409 * Memory based rpc (for speed check and testing)
411 * clnt_raw_create(prog, vers)
415 extern CLIENT *clnt_raw_create(rpcprog_t, rpcvers_t);
421 * Print why creation failed
424 extern void clnt_pcreateerror(const char *); /* stderr */
425 extern char *clnt_spcreateerror(const char *); /* string */
429 * Like clnt_perror(), but is more verbose in its output
432 extern void clnt_perrno(enum clnt_stat); /* stderr */
433 extern char *clnt_sperrno(enum clnt_stat); /* string */
437 * Print an English error message, given the client error code
440 extern void clnt_perror(CLIENT *, const char *); /* stderr */
441 extern char *clnt_sperror(CLIENT *, const char *); /* string */
446 * If a creation fails, the following allows the user to figure out why.
448 struct rpc_createerr {
449 enum clnt_stat cf_stat;
450 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
454 extern struct rpc_createerr *__rpc_createerr(void);
456 #define get_rpc_createerr() (*(__rpc_createerr()))
457 #define rpc_createerr (*(__rpc_createerr()))
460 * The simplified interface:
462 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
464 * const rpcprog_t prognum;
465 * const rpcvers_t versnum;
466 * const rpcproc_t procnum;
467 * const xdrproc_t inproc, outproc;
470 * const char *nettype;
473 extern enum clnt_stat rpc_call(const char *, const rpcprog_t,
474 const rpcvers_t, const rpcproc_t,
475 const xdrproc_t, const char *,
476 const xdrproc_t, char *, const char *);
480 * RPC broadcast interface
481 * The call is broadcasted to all locally connected nets.
483 * extern enum clnt_stat
484 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
485 * eachresult, nettype)
486 * const rpcprog_t prog; -- program number
487 * const rpcvers_t vers; -- version number
488 * const rpcproc_t proc; -- procedure number
489 * const xdrproc_t xargs; -- xdr routine for args
490 * caddr_t argsp; -- pointer to args
491 * const xdrproc_t xresults; -- xdr routine for results
492 * caddr_t resultsp; -- pointer to results
493 * const resultproc_t eachresult; -- call with each result
494 * const char *nettype; -- Transport type
496 * For each valid response received, the procedure eachresult is called.
498 * done = eachresult(resp, raddr, nconf)
501 * struct netbuf *raddr;
502 * struct netconfig *nconf;
503 * where resp points to the results of the call and raddr is the
504 * address if the responder to the broadcast. nconf is the transport
505 * on which the response was received.
507 * extern enum clnt_stat
508 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
509 * eachresult, inittime, waittime, nettype)
510 * const rpcprog_t prog; -- program number
511 * const rpcvers_t vers; -- version number
512 * const rpcproc_t proc; -- procedure number
513 * const xdrproc_t xargs; -- xdr routine for args
514 * caddr_t argsp; -- pointer to args
515 * const xdrproc_t xresults; -- xdr routine for results
516 * caddr_t resultsp; -- pointer to results
517 * const resultproc_t eachresult; -- call with each result
518 * const int inittime; -- how long to wait initially
519 * const int waittime; -- maximum time to wait
520 * const char *nettype; -- Transport type
523 typedef bool_t (*resultproc_t)(caddr_t, ...);
526 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
527 const rpcproc_t, const xdrproc_t,
528 caddr_t, const xdrproc_t, caddr_t,
529 const resultproc_t, const char *);
530 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
531 const rpcproc_t, const xdrproc_t,
532 caddr_t, const xdrproc_t, caddr_t,
533 const resultproc_t, const int,
534 const int, const char *);
537 /* For backward compatibility */
538 #include <rpc/clnt_soc.h>
540 #endif /* !_TIRPC_CLNT_H_ */