1 /* $NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 fvdl Exp $ */
4 * The contents of this file are subject to the Sun Standards
5 * License Version 1.0 the (the "License";) You may not use
6 * this file except in compliance with the License. You may
7 * obtain a copy of the License at lib/libc/rpc/LICENSE
9 * Software distributed under the License is distributed on
10 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
11 * express or implied. See the License for the specific
12 * language governing rights and limitations under the License.
14 * The Original Code is Copyright 1998 by Sun Microsystems, Inc
16 * The Initial Developer of the Original Code is: Sun
19 * All Rights Reserved.
21 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
22 * unrestricted use provided that this legend is included on all tape
23 * media and as a part of the software program in whole or part. Users
24 * may copy or modify Sun RPC without charge, but are not authorized
25 * to license or distribute it to anyone else except as part of a product or
26 * program developed by the user.
28 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
29 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
32 * Sun RPC is provided with no support and without any obligation on the
33 * part of Sun Microsystems, Inc. to assist in its use, correction,
34 * modification or enhancement.
36 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
37 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
38 * OR ANY PART THEREOF.
40 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
41 * or profits or other special, indirect and consequential damages, even if
42 * Sun has been advised of the possibility of such damages.
44 * Sun Microsystems, Inc.
46 * Mountain View, California 94043
48 * from: @(#)clnt.h 1.31 94/04/29 SMI
49 * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
54 * clnt.h - Client side remote procedure call interface.
56 * Copyright (c) 1986-1991,1994-1999 by Sun Microsystems, Inc.
57 * All rights reserved.
62 #include <rpc/clnt_stat.h>
63 #include <sys/cdefs.h>
65 #include <sys/refcount.h>
66 #include <rpc/netconfig.h>
68 #include <netconfig.h>
73 * Well-known IPV6 RPC broadcast address.
75 #define RPCB_MULTICAST_ADDR "ff02::202"
78 * the following errors are in general unrecoverable. The caller
79 * should give up rather than retry.
81 #define IS_UNRECOVERABLE_RPC(s) (((s) == RPC_AUTHERROR) || \
82 ((s) == RPC_CANTENCODEARGS) || \
83 ((s) == RPC_CANTDECODERES) || \
84 ((s) == RPC_VERSMISMATCH) || \
85 ((s) == RPC_PROCUNAVAIL) || \
86 ((s) == RPC_PROGUNAVAIL) || \
87 ((s) == RPC_PROGVERSMISMATCH) || \
88 ((s) == RPC_CANTDECODEARGS))
94 enum clnt_stat re_status;
96 int RE_errno; /* related system error */
97 enum auth_stat RE_why; /* why the auth error occurred */
99 rpcvers_t low; /* lowest version supported */
100 rpcvers_t high; /* highest version supported */
102 struct { /* maybe meaningful if RPC_FAILED */
105 } RE_lb; /* life boot & debugging only */
107 #define re_errno ru.RE_errno
108 #define re_why ru.RE_why
109 #define re_vers ru.RE_vers
110 #define re_lb ru.RE_lb
115 * Functions of this type may be used to receive notification when RPC
116 * calls have to be re-transmitted etc.
118 typedef void rpc_feedback(int cmd, int procnum, void *);
121 * Timers used for the pseudo-transport protocol when using datagrams
124 u_short rt_srtt; /* smoothed round-trip time */
125 u_short rt_deviate; /* estimated deviation */
126 u_long rt_rtxcur; /* current (backed-off) rto */
130 * A structure used with CLNT_CALL_EXT to pass extra information used
131 * while processing an RPC call.
133 struct rpc_callextra {
134 AUTH *rc_auth; /* auth handle to use for this call */
135 rpc_feedback *rc_feedback; /* callback for retransmits etc. */
136 void *rc_feedback_arg; /* argument for callback */
137 struct rpc_timers *rc_timers; /* optional RTT timers */
138 struct rpc_err rc_err; /* detailed call status */
144 * Created by individual implementations
145 * Client is responsible for initializing auth, see e.g. auth_none.c.
147 typedef struct __rpc_client {
149 volatile u_int cl_refs; /* reference count */
150 AUTH *cl_auth; /* authenticator */
152 /* call remote procedure */
153 enum clnt_stat (*cl_call)(struct __rpc_client *,
154 struct rpc_callextra *, rpcproc_t,
155 struct mbuf *, struct mbuf **, struct timeval);
157 void (*cl_abort)(struct __rpc_client *);
158 /* get specific error code */
159 void (*cl_geterr)(struct __rpc_client *,
162 bool_t (*cl_freeres)(struct __rpc_client *,
164 /* close the connection and terminate pending RPCs */
165 void (*cl_close)(struct __rpc_client *);
166 /* destroy this structure */
167 void (*cl_destroy)(struct __rpc_client *);
168 /* the ioctl() of rpc */
169 bool_t (*cl_control)(struct __rpc_client *, u_int,
173 AUTH *cl_auth; /* authenticator */
175 /* call remote procedure */
176 enum clnt_stat (*cl_call)(struct __rpc_client *,
177 rpcproc_t, xdrproc_t, void *, xdrproc_t,
178 void *, struct timeval);
180 void (*cl_abort)(struct __rpc_client *);
181 /* get specific error code */
182 void (*cl_geterr)(struct __rpc_client *,
185 bool_t (*cl_freeres)(struct __rpc_client *,
187 /* destroy this structure */
188 void (*cl_destroy)(struct __rpc_client *);
189 /* the ioctl() of rpc */
190 bool_t (*cl_control)(struct __rpc_client *, u_int,
194 void *cl_private; /* private stuff */
195 char *cl_netid; /* network token */
196 char *cl_tp; /* device name */
200 * Feedback values used for possible congestion and rate control
202 #define FEEDBACK_OK 1 /* no retransmits */
203 #define FEEDBACK_REXMIT1 2 /* first retransmit */
204 #define FEEDBACK_REXMIT2 3 /* second and subsequent retransmit */
205 #define FEEDBACK_RECONNECT 4 /* client reconnect */
207 /* Used to set version of portmapper used in broadcast */
209 #define CLCR_SET_LOWVERS 3
210 #define CLCR_GET_LOWVERS 4
212 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
215 * client side rpc interface ops
217 * Parameter types are:
222 #define CLNT_ACQUIRE(rh) \
223 refcount_acquire(&(rh)->cl_refs)
224 #define CLNT_RELEASE(rh) \
225 if (refcount_release(&(rh)->cl_refs)) \
233 #define CLNT_CLOSE(rh) ((*(rh)->cl_ops->cl_close)(rh))
235 enum clnt_stat clnt_call_private(CLIENT *, struct rpc_callextra *, rpcproc_t,
236 xdrproc_t, void *, xdrproc_t, void *, struct timeval);
240 * CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, timeout)
242 * struct rpc_callextra *ext;
245 * struct mbuf **mrepp;
246 * struct timeval timeout;
248 * Call arguments in mreq which is consumed by the call (even if there
249 * is an error). Results returned in *mrepp.
251 #define CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, secs) \
252 ((*(rh)->cl_ops->cl_call)(rh, ext, proc, mreq, mrepp, secs))
256 * CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, timeout)
258 * struct rpc_callextra *ext;
264 * struct timeval timeout;
266 #define CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, secs) \
267 clnt_call_private(rh, ext, proc, xargs, \
268 argsp, xres, resp, secs)
273 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
280 * struct timeval timeout;
283 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
284 clnt_call_private(rh, NULL, proc, xargs, \
285 argsp, xres, resp, secs)
286 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
287 clnt_call_private(rh, NULL, proc, xargs, \
288 argsp, xres, resp, secs)
290 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
291 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
292 argsp, xres, resp, secs))
293 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
294 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
295 argsp, xres, resp, secs))
303 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
304 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
311 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
312 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
317 * CLNT_FREERES(rh, xres, resp);
322 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
323 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
327 * CLNT_CONTROL(cl, request, info)
332 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
333 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
336 * control operations that apply to both udp and tcp transports
338 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
339 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
340 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
341 #define CLGET_FD 6 /* get connections file descriptor */
342 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
343 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
344 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
345 #define CLGET_XID 10 /* Get xid */
346 #define CLSET_XID 11 /* Set xid */
347 #define CLGET_VERS 12 /* Get version number */
348 #define CLSET_VERS 13 /* Set version number */
349 #define CLGET_PROG 14 /* Get program number */
350 #define CLSET_PROG 15 /* Set program number */
351 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */
352 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */
353 #define CLSET_POP_TIMOD 18 /* pop timod */
355 * Connectionless only control operations
357 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
358 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
359 #define CLSET_ASYNC 19
360 #define CLSET_CONNECT 20 /* Use connect() for UDP. (int) */
364 * Kernel control operations. The default msleep string is "rpcrecv",
365 * and sleeps are non-interruptible by default.
367 #define CLSET_WAITCHAN 21 /* set string to use in msleep call */
368 #define CLGET_WAITCHAN 22 /* get string used in msleep call */
369 #define CLSET_INTERRUPTIBLE 23 /* set interruptible flag */
370 #define CLGET_INTERRUPTIBLE 24 /* set interruptible flag */
371 #define CLSET_RETRIES 25 /* set retry count for reconnect */
372 #define CLGET_RETRIES 26 /* get retry count for reconnect */
373 #define CLSET_PRIVPORT 27 /* set privileged source port flag */
374 #define CLGET_PRIVPORT 28 /* get privileged source port flag */
375 #define CLSET_BACKCHANNEL 29 /* set backchannel for socket */
384 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
385 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
389 * RPCTEST is a test program which is accessible on every rpc
390 * transport/port. It is used for testing, performance evaluation,
391 * and network administration.
394 #define RPCTEST_PROGRAM ((rpcprog_t)1)
395 #define RPCTEST_VERSION ((rpcvers_t)1)
396 #define RPCTEST_NULL_PROC ((rpcproc_t)2)
397 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
400 * By convention, procedure 0 takes null arguments and returns them
403 #define NULLPROC ((rpcproc_t)0)
406 * Below are the client handle creation routines for the various
407 * implementations of client side rpc. They can return NULL if a
408 * creation failure occurs.
412 * Generic client creation routine. Supported protocols are those that
413 * belong to the nettype namespace (/etc/netconfig).
419 * struct socket *so; -- socket
420 * struct sockaddr *svcaddr; -- servers address
421 * rpcprog_t prog; -- program number
422 * rpcvers_t vers; -- version number
423 * size_t sendsz; -- buffer recv size
424 * size_t recvsz; -- buffer send size
426 extern CLIENT *clnt_dg_create(struct socket *so,
427 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version,
428 size_t sendsz, size_t recvsz);
431 * struct socket *so; -- socket
432 * struct sockaddr *svcaddr; -- servers address
433 * rpcprog_t prog; -- program number
434 * rpcvers_t vers; -- version number
435 * size_t sendsz; -- buffer recv size
436 * size_t recvsz; -- buffer send size
437 * int intrflag; -- is it interruptible
439 extern CLIENT *clnt_vc_create(struct socket *so,
440 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version,
441 size_t sendsz, size_t recvsz, int intrflag);
444 * struct netconfig *nconf; -- network type
445 * struct sockaddr *svcaddr; -- servers address
446 * rpcprog_t prog; -- program number
447 * rpcvers_t vers; -- version number
448 * size_t sendsz; -- buffer recv size
449 * size_t recvsz; -- buffer send size
451 extern CLIENT *clnt_reconnect_create(struct netconfig *nconf,
452 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version,
453 size_t sendsz, size_t recvsz);
457 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
461 * const char *hostname; -- hostname
462 * const rpcprog_t prog; -- program number
463 * const rpcvers_t vers; -- version number
464 * const char *nettype; -- network type
468 * Generic client creation routine. Just like clnt_create(), except
469 * it takes an additional timeout parameter.
471 extern CLIENT * clnt_create_timed(const char *, const rpcprog_t,
472 const rpcvers_t, const char *, const struct timeval *);
475 * const char *hostname; -- hostname
476 * const rpcprog_t prog; -- program number
477 * const rpcvers_t vers; -- version number
478 * const char *nettype; -- network type
479 * const struct timeval *tp; -- timeout
483 * Generic client creation routine. Supported protocols are which belong
484 * to the nettype name space.
486 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
487 const rpcvers_t, const rpcvers_t,
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
499 * Generic client creation routine. Supported protocols are which belong
500 * to the nettype name space.
502 extern CLIENT * clnt_create_vers_timed(const char *, const rpcprog_t,
503 rpcvers_t *, const rpcvers_t, const rpcvers_t, const char *,
504 const struct timeval *);
506 * const char *host; -- hostname
507 * const rpcprog_t prog; -- program number
508 * rpcvers_t *vers_out; -- servers highest available version
509 * const rpcvers_t vers_low; -- low version number
510 * const rpcvers_t vers_high; -- high version number
511 * const char *nettype; -- network type
512 * const struct timeval *tp -- timeout
516 * Generic client creation routine. It takes a netconfig structure
519 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t,
520 const rpcvers_t, const struct netconfig *);
522 * const char *hostname; -- hostname
523 * const rpcprog_t prog; -- program number
524 * const rpcvers_t vers; -- version number
525 * const struct netconfig *netconf; -- network config structure
529 * Generic client creation routine. Just like clnt_tp_create(), except
530 * it takes an additional timeout parameter.
532 extern CLIENT * clnt_tp_create_timed(const char *, const rpcprog_t,
533 const rpcvers_t, const struct netconfig *, const struct timeval *);
535 * const char *hostname; -- hostname
536 * const rpcprog_t prog; -- program number
537 * const rpcvers_t vers; -- version number
538 * const struct netconfig *netconf; -- network config structure
539 * const struct timeval *tp -- timeout
543 * Generic TLI create routine. Only provided for compatibility.
546 extern CLIENT *clnt_tli_create(const int, const struct netconfig *,
547 struct netbuf *, const rpcprog_t,
548 const rpcvers_t, const u_int, const u_int);
550 * const register int fd; -- fd
551 * const struct netconfig *nconf; -- netconfig structure
552 * struct netbuf *svcaddr; -- servers address
553 * const u_long prog; -- program number
554 * const u_long vers; -- version number
555 * const u_int sendsz; -- send size
556 * const u_int recvsz; -- recv size
560 * Low level clnt create routine for connectionful transports, e.g. tcp.
562 extern CLIENT *clnt_vc_create(const int, const struct netbuf *,
563 const rpcprog_t, const rpcvers_t,
566 * Added for compatibility to old rpc 4.0. Obsoleted by clnt_vc_create().
568 extern CLIENT *clntunix_create(struct sockaddr_un *,
569 u_long, u_long, int *, u_int, u_int);
571 * const int fd; -- open file descriptor
572 * const struct netbuf *svcaddr; -- servers address
573 * const rpcprog_t prog; -- program number
574 * const rpcvers_t vers; -- version number
575 * const u_int sendsz; -- buffer recv size
576 * const u_int recvsz; -- buffer send size
580 * Low level clnt create routine for connectionless transports, e.g. udp.
582 extern CLIENT *clnt_dg_create(const int, const struct netbuf *,
583 const rpcprog_t, const rpcvers_t,
584 const u_int, const u_int);
586 * const int fd; -- open file descriptor
587 * const struct netbuf *svcaddr; -- servers address
588 * const rpcprog_t program; -- program number
589 * const rpcvers_t version; -- version number
590 * const u_int sendsz; -- buffer recv size
591 * const u_int recvsz; -- buffer send size
595 * Memory based rpc (for speed check and testing)
597 * clnt_raw_create(prog, vers)
601 extern CLIENT *clnt_raw_create(rpcprog_t, rpcvers_t);
608 * Print why creation failed
611 extern void clnt_pcreateerror(const char *); /* stderr */
612 extern char *clnt_spcreateerror(const char *); /* string */
616 * Like clnt_perror(), but is more verbose in its output
619 extern void clnt_perrno(enum clnt_stat); /* stderr */
620 extern char *clnt_sperrno(enum clnt_stat); /* string */
624 * Print an English error message, given the client error code
627 extern void clnt_perror(CLIENT *, const char *); /* stderr */
628 extern char *clnt_sperror(CLIENT *, const char *); /* string */
633 * If a creation fails, the following allows the user to figure out why.
635 struct rpc_createerr {
636 enum clnt_stat cf_stat;
637 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
641 extern struct rpc_createerr rpc_createerr;
644 extern struct rpc_createerr *__rpc_createerr(void);
646 #define rpc_createerr (*(__rpc_createerr()))
651 * The simplified interface:
653 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
655 * const rpcprog_t prognum;
656 * const rpcvers_t versnum;
657 * const rpcproc_t procnum;
658 * const xdrproc_t inproc, outproc;
661 * const char *nettype;
664 extern enum clnt_stat rpc_call(const char *, const rpcprog_t,
665 const rpcvers_t, const rpcproc_t,
666 const xdrproc_t, const char *,
667 const xdrproc_t, char *, const char *);
671 * RPC broadcast interface
672 * The call is broadcasted to all locally connected nets.
674 * extern enum clnt_stat
675 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
676 * eachresult, nettype)
677 * const rpcprog_t prog; -- program number
678 * const rpcvers_t vers; -- version number
679 * const rpcproc_t proc; -- procedure number
680 * const xdrproc_t xargs; -- xdr routine for args
681 * caddr_t argsp; -- pointer to args
682 * const xdrproc_t xresults; -- xdr routine for results
683 * caddr_t resultsp; -- pointer to results
684 * const resultproc_t eachresult; -- call with each result
685 * const char *nettype; -- Transport type
687 * For each valid response received, the procedure eachresult is called.
689 * done = eachresult(resp, raddr, nconf)
692 * struct netbuf *raddr;
693 * struct netconfig *nconf;
694 * where resp points to the results of the call and raddr is the
695 * address if the responder to the broadcast. nconf is the transport
696 * on which the response was received.
698 * extern enum clnt_stat
699 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
700 * eachresult, inittime, waittime, nettype)
701 * const rpcprog_t prog; -- program number
702 * const rpcvers_t vers; -- version number
703 * const rpcproc_t proc; -- procedure number
704 * const xdrproc_t xargs; -- xdr routine for args
705 * caddr_t argsp; -- pointer to args
706 * const xdrproc_t xresults; -- xdr routine for results
707 * caddr_t resultsp; -- pointer to results
708 * const resultproc_t eachresult; -- call with each result
709 * const int inittime; -- how long to wait initially
710 * const int waittime; -- maximum time to wait
711 * const char *nettype; -- Transport type
714 typedef bool_t (*resultproc_t)(caddr_t, ...);
717 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
718 const rpcproc_t, const xdrproc_t,
719 caddr_t, const xdrproc_t, caddr_t,
720 const resultproc_t, const char *);
721 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
722 const rpcproc_t, const xdrproc_t,
723 caddr_t, const xdrproc_t, caddr_t,
724 const resultproc_t, const int,
725 const int, const char *);
728 /* For backward compatibility */
729 #include <rpc/clnt_soc.h>
732 #endif /* !_RPC_CLNT_H_ */