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