xref: /netbsd/include/rpc/clnt.h (revision bf9ec67e)
1 /*	$NetBSD: clnt.h,v 1.16 2001/06/19 12:52:20 wiz Exp $	*/
2 
3 /*
4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5  * unrestricted use provided that this legend is included on all tape
6  * media and as a part of the software program in whole or part.  Users
7  * may copy or modify Sun RPC without charge, but are not authorized
8  * to license or distribute it to anyone else except as part of a product or
9  * program developed by the user.
10  *
11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14  *
15  * Sun RPC is provided with no support and without any obligation on the
16  * part of Sun Microsystems, Inc. to assist in its use, correction,
17  * modification or enhancement.
18  *
19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21  * OR ANY PART THEREOF.
22  *
23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24  * or profits or other special, indirect and consequential damages, even if
25  * Sun has been advised of the possibility of such damages.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  *
31  *	from: @(#)clnt.h 1.31 94/04/29 SMI
32  *	@(#)clnt.h	2.1 88/07/29 4.0 RPCSRC
33  */
34 
35 /*
36  * clnt.h - Client side remote procedure call interface.
37  *
38  * Copyright (C) 1984, Sun Microsystems, Inc.
39  */
40 
41 #ifndef _RPC_CLNT_H_
42 #define _RPC_CLNT_H_
43 #include <sys/cdefs.h>
44 
45 /*
46  * Well-known IPV6 RPC broadcast address.
47  */
48 #define RPCB_MULTICAST_ADDR "ff02::202"
49 
50 /*
51  * Rpc calls return an enum clnt_stat.  This should be looked at more,
52  * since each implementation is required to live with this (implementation
53  * independent) list of errors.
54  */
55 enum clnt_stat {
56 	RPC_SUCCESS=0,			/* call succeeded */
57 	/*
58 	 * local errors
59 	 */
60 	RPC_CANTENCODEARGS=1,		/* can't encode arguments */
61 	RPC_CANTDECODERES=2,		/* can't decode results */
62 	RPC_CANTSEND=3,			/* failure in sending call */
63 	RPC_CANTRECV=4,			/* failure in receiving result */
64 	RPC_TIMEDOUT=5,			/* call timed out */
65 	/*
66 	 * remote errors
67 	 */
68 	RPC_VERSMISMATCH=6,		/* rpc versions not compatible */
69 	RPC_AUTHERROR=7,		/* authentication error */
70 	RPC_PROGUNAVAIL=8,		/* program not available */
71 	RPC_PROGVERSMISMATCH=9,		/* program version mismatched */
72 	RPC_PROCUNAVAIL=10,		/* procedure unavailable */
73 	RPC_CANTDECODEARGS=11,		/* decode arguments error */
74 	RPC_SYSTEMERROR=12,		/* generic "other problem" */
75 
76 	/*
77 	 * rpc_call & clnt_create errors
78 	 */
79 	RPC_UNKNOWNHOST=13,		/* unknown host name */
80 	RPC_UNKNOWNPROTO=17,		/* unkown protocol */
81 	RPC_UNKNOWNADDR = 19,		/* Remote address unknown */
82 	RPC_NOBROADCAST = 21,		/* Broadcasting not supported */
83 
84 	/*
85 	 * rpcbind errors
86 	 */
87 	RPC_RPCBFAILURE=14,		/* the pmapper failed in its call */
88 #define RPC_PMAPFAILURE RPC_RPCBFAILURE
89 	RPC_PROGNOTREGISTERED=15,	/* remote program is not registered */
90 	RPC_N2AXLATEFAILURE = 22,	/* name -> addr translation failed */
91 
92 	/*
93 	 * Misc error in the TLI library (provided for compatibility)
94 	 */
95 	RPC_TLIERROR = 20,
96 
97 	/*
98 	 * unspecified error
99 	 */
100 	RPC_FAILED=16,
101 
102 	/*
103 	 * asynchronous errors
104 	 */
105 	RPC_INPROGRESS = 24,
106 	RPC_STALERACHANDLE = 25
107 };
108 
109 
110 /*
111  * Error info.
112  */
113 struct rpc_err {
114 	enum clnt_stat re_status;
115 	union {
116 		int RE_errno;		/* related system error */
117 		enum auth_stat RE_why;	/* why the auth error occurred */
118 		struct {
119 			rpcvers_t low;	/* lowest version supported */
120 			rpcvers_t high;	/* highest version supported */
121 		} RE_vers;
122 		struct {		/* maybe meaningful if RPC_FAILED */
123 			int32_t s1;
124 			int32_t s2;
125 		} RE_lb;		/* life boot & debugging only */
126 	} ru;
127 #define	re_errno	ru.RE_errno
128 #define	re_why		ru.RE_why
129 #define	re_vers		ru.RE_vers
130 #define	re_lb		ru.RE_lb
131 };
132 
133 
134 /*
135  * Client rpc handle.
136  * Created by individual implementations
137  * Client is responsible for initializing auth, see e.g. auth_none.c.
138  */
139 typedef struct __rpc_client {
140 	AUTH	*cl_auth;			/* authenticator */
141 	const struct clnt_ops {
142 		/* call remote procedure */
143 		enum clnt_stat	(*cl_call) __P((struct __rpc_client *,
144 				    rpcproc_t, xdrproc_t, caddr_t, xdrproc_t,
145 				    caddr_t, struct timeval));
146 		/* abort a call */
147 		void		(*cl_abort) __P((struct __rpc_client *));
148 		/* get specific error code */
149 		void		(*cl_geterr) __P((struct __rpc_client *,
150 				    struct rpc_err *));
151 		/* frees results */
152 		bool_t		(*cl_freeres) __P((struct __rpc_client *,
153 				    xdrproc_t, caddr_t));
154 		/* destroy this structure */
155 		void		(*cl_destroy) __P((struct __rpc_client *));
156 		/* the ioctl() of rpc */
157 		bool_t          (*cl_control) __P((struct __rpc_client *, u_int,
158 				    char *));
159 	} *cl_ops;
160 	void 			*cl_private;	/* private stuff */
161 	char			*cl_netid;	/* network token */
162 	char			*cl_tp;		/* device name */
163 } CLIENT;
164 
165 
166 /*
167  * Timers used for the pseudo-transport protocol when using datagrams
168  */
169 struct rpc_timers {
170 	u_short		rt_srtt;	/* smoothed round-trip time */
171 	u_short		rt_deviate;	/* estimated deviation */
172 	u_long		rt_rtxcur;	/* current (backed-off) rto */
173 };
174 
175 /*
176  * Feedback values used for possible congestion and rate control
177  */
178 #define FEEDBACK_REXMIT1	1	/* first retransmit */
179 #define FEEDBACK_OK		2	/* no retransmits */
180 
181 /* Used to set version of portmapper used in broadcast */
182 
183 #define CLCR_SET_LOWVERS	3
184 #define CLCR_GET_LOWVERS	4
185 
186 #define RPCSMALLMSGSIZE 400	/* a more reasonable packet size */
187 
188 /*
189  * client side rpc interface ops
190  *
191  * Parameter types are:
192  *
193  */
194 
195 /*
196  * enum clnt_stat
197  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
198  * 	CLIENT *rh;
199  *	rpcproc_t proc;
200  *	xdrproc_t xargs;
201  *	caddr_t argsp;
202  *	xdrproc_t xres;
203  *	caddr_t resp;
204  *	struct timeval timeout;
205  */
206 #define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)		\
207 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, 			\
208 	(caddr_t)(void *)argsp,	xres, (caddr_t)(void *)resp, secs))
209 #define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)		\
210 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, 			\
211 	 (caddr_t)(void *)argsp, xres, (caddr_t)(void *)resp, secs))
212 
213 /*
214  * void
215  * CLNT_ABORT(rh);
216  * 	CLIENT *rh;
217  */
218 #define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
219 #define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
220 
221 /*
222  * struct rpc_err
223  * CLNT_GETERR(rh);
224  * 	CLIENT *rh;
225  */
226 #define	CLNT_GETERR(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
227 #define	clnt_geterr(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
228 
229 
230 /*
231  * bool_t
232  * CLNT_FREERES(rh, xres, resp);
233  * 	CLIENT *rh;
234  *	xdrproc_t xres;
235  *	caddr_t resp;
236  */
237 #define	CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
238 #define	clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
239 
240 /*
241  * bool_t
242  * CLNT_CONTROL(cl, request, info)
243  *      CLIENT *cl;
244  *      u_int request;
245  *      char *info;
246  */
247 #define	CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
248 #define	clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
249 
250 /*
251  * control operations that apply to both udp and tcp transports
252  */
253 #define CLSET_TIMEOUT		1	/* set timeout (timeval) */
254 #define CLGET_TIMEOUT		2	/* get timeout (timeval) */
255 #define CLGET_SERVER_ADDR	3	/* get server's address (sockaddr) */
256 #define	CLGET_FD		6	/* get connections file descriptor */
257 #define	CLGET_SVC_ADDR		7	/* get server's address (netbuf) */
258 #define	CLSET_FD_CLOSE		8	/* close fd while clnt_destroy */
259 #define	CLSET_FD_NCLOSE		9	/* Do not close fd while clnt_destroy */
260 #define	CLGET_XID 		10	/* Get xid */
261 #define	CLSET_XID		11	/* Set xid */
262 #define	CLGET_VERS		12	/* Get version number */
263 #define	CLSET_VERS		13	/* Set version number */
264 #define	CLGET_PROG		14	/* Get program number */
265 #define	CLSET_PROG		15	/* Set program number */
266 #define	CLSET_SVC_ADDR		16	/* get server's address (netbuf) */
267 #define	CLSET_PUSH_TIMOD	17	/* push timod if not already present */
268 #define	CLSET_POP_TIMOD		18	/* pop timod */
269 /*
270  * Connectionless only control operations
271  */
272 #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
273 #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
274 
275 /*
276  * void
277  * CLNT_DESTROY(rh);
278  * 	CLIENT *rh;
279  */
280 #define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
281 #define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
282 
283 
284 /*
285  * RPCTEST is a test program which is accessible on every rpc
286  * transport/port.  It is used for testing, performance evaluation,
287  * and network administration.
288  */
289 
290 #define RPCTEST_PROGRAM		((rpcprog_t)1)
291 #define RPCTEST_VERSION		((rpcvers_t)1)
292 #define RPCTEST_NULL_PROC	((rpcproc_t)2)
293 #define RPCTEST_NULL_BATCH_PROC	((rpcproc_t)3)
294 
295 /*
296  * By convention, procedure 0 takes null arguments and returns them
297  */
298 
299 #define NULLPROC ((rpcproc_t)0)
300 
301 /*
302  * Below are the client handle creation routines for the various
303  * implementations of client side rpc.  They can return NULL if a
304  * creation failure occurs.
305  */
306 
307 /*
308  * Generic client creation routine. Supported protocols are those that
309  * belong to the nettype namespace (/etc/netconfig).
310  * CLIENT *
311  * clnt_create(host, prog, vers, prot);
312  *	const char *host; 	-- hostname
313  *	const rpcprog_t prog;	-- program number
314  *	const rpcvers_t vers;	-- version number
315  *	const char *prot;	-- protocol
316  */
317 __BEGIN_DECLS
318 extern CLIENT *clnt_create __P((const char *, const rpcprog_t, const rpcvers_t,
319 				const char *));
320 /*
321  *
322  * 	const char *hostname;			-- hostname
323  *	const rpcprog_t prog;			-- program number
324  *	const rpcvers_t vers;			-- version number
325  *	const char *nettype;			-- network type
326  */
327 
328 /*
329  * Generic client creation routine. Supported protocols are which belong
330  * to the nettype name space.
331  */
332 extern CLIENT *clnt_create_vers __P((const char *, const rpcprog_t, rpcvers_t *,
333 				     const rpcvers_t, const rpcvers_t,
334 				     const char *));
335 /*
336  *	const char *host;		-- hostname
337  *	const rpcprog_t prog;		-- program number
338  *	rpcvers_t *vers_out;		-- servers highest available version
339  *	const rpcvers_t vers_low;	-- low version number
340  *	const rpcvers_t vers_high;	-- high version number
341  *	const char *nettype;		-- network type
342  */
343 
344 
345 /*
346  * Generic client creation routine. It takes a netconfig structure
347  * instead of nettype
348  */
349 extern CLIENT *clnt_tp_create __P((const char *, const rpcprog_t,
350 				   const rpcvers_t, const struct netconfig *));
351 /*
352  *	const char *hostname;			-- hostname
353  *	const rpcprog_t prog;			-- program number
354  *	const rpcvers_t vers;			-- version number
355  *	const struct netconfig *netconf; 	-- network config structure
356  */
357 
358 /*
359  * Generic TLI create routine. Only provided for compatibility.
360  */
361 
362 extern CLIENT *clnt_tli_create __P((const int, const struct netconfig *,
363 				    const struct netbuf *, const rpcprog_t,
364 				    const rpcvers_t, const u_int, const u_int));
365 /*
366  *	const register int fd;		-- fd
367  *	const struct netconfig *nconf;	-- netconfig structure
368  *	const struct netbuf *svcaddr;		-- servers address
369  *	const u_long prog;			-- program number
370  *	const u_long vers;			-- version number
371  *	const u_int sendsz;			-- send size
372  *	const u_int recvsz;			-- recv size
373  */
374 
375 /*
376  * Low level clnt create routine for connectionful transports, e.g. tcp.
377  */
378 extern CLIENT *clnt_vc_create __P((const int, const struct netbuf *,
379 				   const rpcprog_t, const rpcvers_t,
380 				   const u_int, const u_int));
381 /*
382  *	const int fd;				-- open file descriptor
383  *	const struct netbuf *svcaddr;		-- servers address
384  *	const rpcprog_t prog;			-- program number
385  *	const rpcvers_t vers;			-- version number
386  *	const u_int sendsz;			-- buffer recv size
387  *	const u_int recvsz;			-- buffer send size
388  */
389 
390 /*
391  * Low level clnt create routine for connectionless transports, e.g. udp.
392  */
393 extern CLIENT *clnt_dg_create __P((const int, const struct netbuf *,
394 				   const rpcprog_t, const rpcvers_t,
395 				   const u_int, const u_int));
396 /*
397  *	const int fd;				-- open file descriptor
398  *	const struct netbuf *svcaddr;		-- servers address
399  *	const rpcprog_t program;		-- program number
400  *	const rpcvers_t version;		-- version number
401  *	const u_int sendsz;			-- buffer recv size
402  *	const u_int recvsz;			-- buffer send size
403  */
404 
405 /*
406  * Memory based rpc (for speed check and testing)
407  * CLIENT *
408  * clnt_raw_create(prog, vers)
409  *	u_long prog;
410  *	u_long vers;
411  */
412 extern CLIENT *clnt_raw_create	__P((rpcprog_t, rpcvers_t));
413 
414 __END_DECLS
415 
416 
417 /*
418  * Print why creation failed
419  */
420 __BEGIN_DECLS
421 extern void clnt_pcreateerror	__P((const char *));		/* stderr */
422 extern char *clnt_spcreateerror	__P((const char *));		/* string */
423 __END_DECLS
424 
425 /*
426  * Like clnt_perror(), but is more verbose in its output
427  */
428 __BEGIN_DECLS
429 extern void clnt_perrno		__P((enum clnt_stat));		/* stderr */
430 extern char *clnt_sperrno	__P((enum clnt_stat));		/* string */
431 __END_DECLS
432 
433 /*
434  * Print an English error message, given the client error code
435  */
436 __BEGIN_DECLS
437 extern void clnt_perror		__P((CLIENT *, const char *)); 	/* stderr */
438 extern char *clnt_sperror	__P((CLIENT *, const char *));	/* string */
439 __END_DECLS
440 
441 
442 /*
443  * If a creation fails, the following allows the user to figure out why.
444  */
445 struct rpc_createerr {
446 	enum clnt_stat cf_stat;
447 	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
448 };
449 
450 #ifdef _REENTRANT
451 __BEGIN_DECLS
452 extern struct rpc_createerr	*__rpc_createerr __P((void));
453 __END_DECLS
454 #define rpc_createerr		(*(__rpc_createerr()))
455 #else
456 extern struct rpc_createerr rpc_createerr;
457 #endif /* _REENTRANT */
458 
459 /*
460  * The simplified interface:
461  * enum clnt_stat
462  * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
463  *	const char *host;
464  *	const rpcprog_t prognum;
465  *	const rpcvers_t versnum;
466  *	const rpcproc_t procnum;
467  *	const xdrproc_t inproc, outproc;
468  *	const char *in;
469  *	char *out;
470  *	const char *nettype;
471  */
472 __BEGIN_DECLS
473 extern enum clnt_stat rpc_call __P((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 *));
477 __END_DECLS
478 
479 /*
480  * RPC broadcast interface
481  * The call is broadcasted to all locally connected nets.
482  *
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
495  *
496  * For each valid response received, the procedure eachresult is called.
497  * Its form is:
498  *		done = eachresult(resp, raddr, nconf)
499  *			bool_t done;
500  *			caddr_t resp;
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.
506  *
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
521  */
522 
523 typedef bool_t (*resultproc_t) __P((caddr_t, ...));
524 
525 __BEGIN_DECLS
526 extern enum clnt_stat rpc_broadcast __P((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 __P((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 *));
535 __END_DECLS
536 
537 /* For backward compatibility */
538 #include <rpc/clnt_soc.h>
539 
540 #endif /* !_RPC_CLNT_H_ */
541