clnt.h revision 74462
1/*	$NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 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, MERCHANTABILITY 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 *	from: @(#)clnt.h	2.1 88/07/29 4.0 RPCSRC
33 * $FreeBSD: head/include/rpc/clnt.h 74462 2001-03-19 12:50:13Z alfred $
34 */
35
36/*
37 * clnt.h - Client side remote procedure call interface.
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 */
41
42#ifndef _RPC_CLNT_H_
43#define _RPC_CLNT_H_
44#include <rpc/clnt_stat.h>
45#include <sys/cdefs.h>
46#include <netconfig.h>
47#include <sys/un.h>
48
49/*
50 * Well-known IPV6 RPC broadcast address.
51 */
52#define RPCB_MULTICAST_ADDR "ff02::202"
53
54/*
55 * the following errors are in general unrecoverable.  The caller
56 * should give up rather than retry.
57 */
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))
66
67/*
68 * Error info.
69 */
70struct rpc_err {
71	enum clnt_stat re_status;
72	union {
73		int RE_errno;		/* related system error */
74		enum auth_stat RE_why;	/* why the auth error occurred */
75		struct {
76			rpcvers_t low;	/* lowest version supported */
77			rpcvers_t high;	/* highest version supported */
78		} RE_vers;
79		struct {		/* maybe meaningful if RPC_FAILED */
80			int32_t s1;
81			int32_t s2;
82		} RE_lb;		/* life boot & debugging only */
83	} ru;
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
88};
89
90
91/*
92 * Client rpc handle.
93 * Created by individual implementations
94 * Client is responsible for initializing auth, see e.g. auth_none.c.
95 */
96typedef struct __rpc_client {
97	AUTH	*cl_auth;			/* authenticator */
98	struct clnt_ops {
99		/* call remote procedure */
100		enum clnt_stat	(*cl_call) __P((struct __rpc_client *,
101				    rpcproc_t, xdrproc_t, caddr_t, xdrproc_t,
102					caddr_t, struct timeval));
103		/* abort a call */
104		void		(*cl_abort) __P((struct __rpc_client *));
105		/* get specific error code */
106		void		(*cl_geterr) __P((struct __rpc_client *,
107					struct rpc_err *));
108		/* frees results */
109		bool_t		(*cl_freeres) __P((struct __rpc_client *,
110					xdrproc_t, caddr_t));
111		/* destroy this structure */
112		void		(*cl_destroy) __P((struct __rpc_client *));
113		/* the ioctl() of rpc */
114		bool_t          (*cl_control) __P((struct __rpc_client *, u_int,
115				    char *));
116	} *cl_ops;
117	void 			*cl_private;	/* private stuff */
118	char			*cl_netid;	/* network token */
119	char			*cl_tp;		/* device name */
120} CLIENT;
121
122
123/*
124 * Timers used for the pseudo-transport protocol when using datagrams
125 */
126struct rpc_timers {
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 */
130};
131
132/*
133 * Feedback values used for possible congestion and rate control
134 */
135#define FEEDBACK_REXMIT1	1	/* first retransmit */
136#define FEEDBACK_OK		2	/* no retransmits */
137
138/* Used to set version of portmapper used in broadcast */
139
140#define CLCR_SET_LOWVERS	3
141#define CLCR_GET_LOWVERS	4
142
143#define RPCSMALLMSGSIZE 400	/* a more reasonable packet size */
144
145/*
146 * client side rpc interface ops
147 *
148 * Parameter types are:
149 *
150 */
151
152/*
153 * enum clnt_stat
154 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
155 * 	CLIENT *rh;
156 *	rpcproc_t proc;
157 *	xdrproc_t xargs;
158 *	caddr_t argsp;
159 *	xdrproc_t xres;
160 *	caddr_t resp;
161 *	struct timeval timeout;
162 */
163#define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
164	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
165		(caddr_t)(void *)argsp,	xres, (caddr_t)(void *)resp, secs))
166#define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
167	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
168		(caddr_t)(void *)argsp, xres, (caddr_t)(void *)resp, secs))
169
170/*
171 * void
172 * CLNT_ABORT(rh);
173 * 	CLIENT *rh;
174 */
175#define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
176#define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
177
178/*
179 * struct rpc_err
180 * CLNT_GETERR(rh);
181 * 	CLIENT *rh;
182 */
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))
185
186
187/*
188 * bool_t
189 * CLNT_FREERES(rh, xres, resp);
190 * 	CLIENT *rh;
191 *	xdrproc_t xres;
192 *	caddr_t resp;
193 */
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))
196
197/*
198 * bool_t
199 * CLNT_CONTROL(cl, request, info)
200 *      CLIENT *cl;
201 *      u_int request;
202 *      char *info;
203 */
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))
206
207/*
208 * control operations that apply to both udp and tcp transports
209 */
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 */
226/*
227 * Connectionless only control operations
228 */
229#define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
230#define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
231
232/*
233 * void
234 * CLNT_DESTROY(rh);
235 * 	CLIENT *rh;
236 */
237#define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
238#define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
239
240
241/*
242 * RPCTEST is a test program which is accessible on every rpc
243 * transport/port.  It is used for testing, performance evaluation,
244 * and network administration.
245 */
246
247#define RPCTEST_PROGRAM		((rpcprog_t)1)
248#define RPCTEST_VERSION		((rpcvers_t)1)
249#define RPCTEST_NULL_PROC	((rpcproc_t)2)
250#define RPCTEST_NULL_BATCH_PROC	((rpcproc_t)3)
251
252/*
253 * By convention, procedure 0 takes null arguments and returns them
254 */
255
256#define NULLPROC ((rpcproc_t)0)
257
258/*
259 * Below are the client handle creation routines for the various
260 * implementations of client side rpc.  They can return NULL if a
261 * creation failure occurs.
262 */
263
264/*
265 * Generic client creation routine. Supported protocols are those that
266 * belong to the nettype namespace (/etc/netconfig).
267 * CLIENT *
268 * clnt_create(host, prog, vers, prot);
269 *	const char *host; 	-- hostname
270 *	const rpcprog_t prog;	-- program number
271 *	const rpcvers_t vers;	-- version number
272 *	const char *prot;	-- protocol
273 */
274__BEGIN_DECLS
275extern CLIENT *clnt_create __P((const char *, const rpcprog_t, const rpcvers_t,
276				const char *));
277/*
278 *
279 * 	const char *hostname;			-- hostname
280 *	const rpcprog_t prog;			-- program number
281 *	const rpcvers_t vers;			-- version number
282 *	const char *nettype;			-- network type
283 */
284
285/*
286 * Generic client creation routine. Supported protocols are which belong
287 * to the nettype name space.
288 */
289extern CLIENT *clnt_create_vers __P((const char *, const rpcprog_t, rpcvers_t *,
290				     const rpcvers_t, const rpcvers_t,
291				     const char *));
292/*
293 *	const char *host;		-- hostname
294 *	const rpcprog_t prog;		-- program number
295 *	rpcvers_t *vers_out;		-- servers highest available version
296 *	const rpcvers_t vers_low;	-- low version number
297 *	const rpcvers_t vers_high;	-- high version number
298 *	const char *nettype;		-- network type
299 */
300
301
302/*
303 * Generic client creation routine. It takes a netconfig structure
304 * instead of nettype
305 */
306extern CLIENT *clnt_tp_create __P((const char *, const rpcprog_t,
307				   const rpcvers_t, const struct netconfig *));
308/*
309 *	const char *hostname;			-- hostname
310 *	const rpcprog_t prog;			-- program number
311 *	const rpcvers_t vers;			-- version number
312 *	const struct netconfig *netconf; 	-- network config structure
313 */
314
315/*
316 * Generic TLI create routine. Only provided for compatibility.
317 */
318
319extern CLIENT *clnt_tli_create __P((const int, const struct netconfig *,
320				    const struct netbuf *, const rpcprog_t,
321				    const rpcvers_t, const u_int, const u_int));
322/*
323 *	const register int fd;		-- fd
324 *	const struct netconfig *nconf;	-- netconfig structure
325 *	const struct netbuf *svcaddr;		-- servers address
326 *	const u_long prog;			-- program number
327 *	const u_long vers;			-- version number
328 *	const u_int sendsz;			-- send size
329 *	const u_int recvsz;			-- recv size
330 */
331
332/*
333 * Low level clnt create routine for connectionful transports, e.g. tcp.
334 */
335extern CLIENT *clnt_vc_create __P((const int, const struct netbuf *,
336				   const rpcprog_t, const rpcvers_t,
337				   const u_int, const u_int));
338/*
339 *	const int fd;				-- open file descriptor
340 *	const struct netbuf *svcaddr;		-- servers address
341 *	const rpcprog_t prog;			-- program number
342 *	const rpcvers_t vers;			-- version number
343 *	const u_int sendsz;			-- buffer recv size
344 *	const u_int recvsz;			-- buffer send size
345 */
346
347/*
348 * Low level clnt create routine for connectionless transports, e.g. udp.
349 */
350extern CLIENT *clnt_dg_create __P((const int, const struct netbuf *,
351				   const rpcprog_t, const rpcvers_t,
352				   const u_int, const u_int));
353/*
354 *	const int fd;				-- open file descriptor
355 *	const struct netbuf *svcaddr;		-- servers address
356 *	const rpcprog_t program;		-- program number
357 *	const rpcvers_t version;		-- version number
358 *	const u_int sendsz;			-- buffer recv size
359 *	const u_int recvsz;			-- buffer send size
360 */
361
362/*
363 * Memory based rpc (for speed check and testing)
364 * CLIENT *
365 * clnt_raw_create(prog, vers)
366 *	u_long prog;
367 *	u_long vers;
368 */
369extern CLIENT *clnt_raw_create	__P((rpcprog_t, rpcvers_t));
370
371__END_DECLS
372
373
374/*
375 * Print why creation failed
376 */
377__BEGIN_DECLS
378extern void clnt_pcreateerror	__P((const char *));			/* stderr */
379extern char *clnt_spcreateerror	__P((const char *));			/* string */
380__END_DECLS
381
382/*
383 * Like clnt_perror(), but is more verbose in its output
384 */
385__BEGIN_DECLS
386extern void clnt_perrno		__P((enum clnt_stat));		/* stderr */
387extern char *clnt_sperrno	__P((enum clnt_stat));		/* string */
388__END_DECLS
389
390/*
391 * Print an English error message, given the client error code
392 */
393__BEGIN_DECLS
394extern void clnt_perror		__P((CLIENT *, const char *));	 	/* stderr */
395extern char *clnt_sperror	__P((CLIENT *, const char *));		/* string */
396__END_DECLS
397
398
399/*
400 * If a creation fails, the following allows the user to figure out why.
401 */
402struct rpc_createerr {
403	enum clnt_stat cf_stat;
404	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
405};
406
407#ifdef _THREAD_SAFE
408__BEGIN_DECLS
409extern struct rpc_createerr	*__rpc_createerr __P((void));
410__END_DECLS
411#define rpc_createerr		(*(__rpc_createerr()))
412#else
413extern struct rpc_createerr rpc_createerr;
414#endif /* _THREAD_SAFE */
415
416/*
417 * The simplified interface:
418 * enum clnt_stat
419 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
420 *	const char *host;
421 *	const rpcprog_t prognum;
422 *	const rpcvers_t versnum;
423 *	const rpcproc_t procnum;
424 *	const xdrproc_t inproc, outproc;
425 *	const char *in;
426 *	char *out;
427 *	const char *nettype;
428 */
429__BEGIN_DECLS
430extern enum clnt_stat rpc_call __P((const char *, const rpcprog_t,
431				    const rpcvers_t, const rpcproc_t,
432				    const xdrproc_t, const char *,
433				    const xdrproc_t, char *, const char *));
434__END_DECLS
435
436/*
437 * RPC broadcast interface
438 * The call is broadcasted to all locally connected nets.
439 *
440 * extern enum clnt_stat
441 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
442 *			eachresult, nettype)
443 *	const rpcprog_t		prog;		-- program number
444 *	const rpcvers_t		vers;		-- version number
445 *	const rpcproc_t		proc;		-- procedure number
446 *	const xdrproc_t	xargs;		-- xdr routine for args
447 *	caddr_t		argsp;		-- pointer to args
448 *	const xdrproc_t	xresults;	-- xdr routine for results
449 *	caddr_t		resultsp;	-- pointer to results
450 *	const resultproc_t	eachresult;	-- call with each result
451 *	const char		*nettype;	-- Transport type
452 *
453 * For each valid response received, the procedure eachresult is called.
454 * Its form is:
455 *		done = eachresult(resp, raddr, nconf)
456 *			bool_t done;
457 *			caddr_t resp;
458 *			struct netbuf *raddr;
459 *			struct netconfig *nconf;
460 * where resp points to the results of the call and raddr is the
461 * address if the responder to the broadcast.  nconf is the transport
462 * on which the response was received.
463 *
464 * extern enum clnt_stat
465 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
466 *			eachresult, inittime, waittime, nettype)
467 *	const rpcprog_t		prog;		-- program number
468 *	const rpcvers_t		vers;		-- version number
469 *	const rpcproc_t		proc;		-- procedure number
470 *	const xdrproc_t	xargs;		-- xdr routine for args
471 *	caddr_t		argsp;		-- pointer to args
472 *	const xdrproc_t	xresults;	-- xdr routine for results
473 *	caddr_t		resultsp;	-- pointer to results
474 *	const resultproc_t	eachresult;	-- call with each result
475 *	const int 		inittime;	-- how long to wait initially
476 *	const int 		waittime;	-- maximum time to wait
477 *	const char		*nettype;	-- Transport type
478 */
479
480typedef bool_t (*resultproc_t) __P((caddr_t, ...));
481
482__BEGIN_DECLS
483extern enum clnt_stat rpc_broadcast __P((const rpcprog_t, const rpcvers_t,
484					 const rpcproc_t, const xdrproc_t,
485					 caddr_t, const xdrproc_t, caddr_t,
486					 const resultproc_t, const char *));
487extern enum clnt_stat rpc_broadcast_exp __P((const rpcprog_t, const rpcvers_t,
488					     const rpcproc_t, const xdrproc_t,
489					     caddr_t, const xdrproc_t, caddr_t,
490					     const resultproc_t, const int,
491					     const int, const char *));
492__END_DECLS
493
494/* For backward compatibility */
495#include <rpc/clnt_soc.h>
496
497#endif /* !_RPC_CLNT_H_ */
498