xref: /netbsd-src/include/rpc/clnt.h (revision ae9172d6cd9432a6a1a56760d86b32c57a66c39c)
1 /*	$NetBSD: clnt.h,v 1.5 1994/12/04 01:12:40 cgd 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 88/02/08 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  * Rpc calls return an enum clnt_stat.  This should be looked at more,
47  * since each implementation is required to live with this (implementation
48  * independent) list of errors.
49  */
50 enum clnt_stat {
51 	RPC_SUCCESS=0,			/* call succeeded */
52 	/*
53 	 * local errors
54 	 */
55 	RPC_CANTENCODEARGS=1,		/* can't encode arguments */
56 	RPC_CANTDECODERES=2,		/* can't decode results */
57 	RPC_CANTSEND=3,			/* failure in sending call */
58 	RPC_CANTRECV=4,			/* failure in receiving result */
59 	RPC_TIMEDOUT=5,			/* call timed out */
60 	/*
61 	 * remote errors
62 	 */
63 	RPC_VERSMISMATCH=6,		/* rpc versions not compatible */
64 	RPC_AUTHERROR=7,		/* authentication error */
65 	RPC_PROGUNAVAIL=8,		/* program not available */
66 	RPC_PROGVERSMISMATCH=9,		/* program version mismatched */
67 	RPC_PROCUNAVAIL=10,		/* procedure unavailable */
68 	RPC_CANTDECODEARGS=11,		/* decode arguments error */
69 	RPC_SYSTEMERROR=12,		/* generic "other problem" */
70 
71 	/*
72 	 * callrpc & clnt_create errors
73 	 */
74 	RPC_UNKNOWNHOST=13,		/* unknown host name */
75 	RPC_UNKNOWNPROTO=17,		/* unkown protocol */
76 
77 	/*
78 	 * _ create errors
79 	 */
80 	RPC_PMAPFAILURE=14,		/* the pmapper failed in its call */
81 	RPC_PROGNOTREGISTERED=15,	/* remote program is not registered */
82 	/*
83 	 * unspecified error
84 	 */
85 	RPC_FAILED=16
86 };
87 
88 
89 /*
90  * Error info.
91  */
92 struct rpc_err {
93 	enum clnt_stat re_status;
94 	union {
95 		int RE_errno;		/* realated system error */
96 		enum auth_stat RE_why;	/* why the auth error occurred */
97 		struct {
98 			u_long low;	/* lowest verion supported */
99 			u_long high;	/* highest verion supported */
100 		} RE_vers;
101 		struct {		/* maybe meaningful if RPC_FAILED */
102 			long s1;
103 			long s2;
104 		} RE_lb;		/* life boot & debugging only */
105 	} ru;
106 #define	re_errno	ru.RE_errno
107 #define	re_why		ru.RE_why
108 #define	re_vers		ru.RE_vers
109 #define	re_lb		ru.RE_lb
110 };
111 
112 
113 /*
114  * Client rpc handle.
115  * Created by individual implementations, see e.g. rpc_udp.c.
116  * Client is responsible for initializing auth, see e.g. auth_none.c.
117  */
118 typedef struct __rpc_client {
119 	AUTH	*cl_auth;			/* authenticator */
120 	struct clnt_ops {
121 		/* call remote procedure */
122 		enum clnt_stat	(*cl_call) __P((struct __rpc_client *,
123 				    u_long, xdrproc_t, caddr_t, xdrproc_t,
124 				    caddr_t, struct timeval));
125 		/* abort a call */
126 		void		(*cl_abort) __P((struct __rpc_client *));
127 		/* get specific error code */
128 		void		(*cl_geterr) __P((struct __rpc_client *,
129 				    struct rpc_err *));
130 		/* frees results */
131 		bool_t		(*cl_freeres) __P((struct __rpc_client *,
132 				    xdrproc_t, caddr_t));
133 		/* destroy this structure */
134 		void		(*cl_destroy) __P((struct __rpc_client *));
135 		/* the ioctl() of rpc */
136 		bool_t          (*cl_control) __P((struct __rpc_client *, u_int,
137 				    char *));
138 	} *cl_ops;
139 	caddr_t			cl_private;	/* private stuff */
140 } CLIENT;
141 
142 
143 /*
144  * client side rpc interface ops
145  *
146  * Parameter types are:
147  *
148  */
149 
150 /*
151  * enum clnt_stat
152  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
153  * 	CLIENT *rh;
154  *	u_long proc;
155  *	xdrproc_t xargs;
156  *	caddr_t argsp;
157  *	xdrproc_t xres;
158  *	caddr_t resp;
159  *	struct timeval timeout;
160  */
161 #define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)		\
162 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp,	\
163 	    xres, (caddr_t)resp, secs))
164 #define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)		\
165 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp,	\
166 	    xres, (caddr_t)resp, secs))
167 
168 /*
169  * void
170  * CLNT_ABORT(rh);
171  * 	CLIENT *rh;
172  */
173 #define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
174 #define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
175 
176 /*
177  * struct rpc_err
178  * CLNT_GETERR(rh);
179  * 	CLIENT *rh;
180  */
181 #define	CLNT_GETERR(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
182 #define	clnt_geterr(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
183 
184 
185 /*
186  * bool_t
187  * CLNT_FREERES(rh, xres, resp);
188  * 	CLIENT *rh;
189  *	xdrproc_t xres;
190  *	caddr_t resp;
191  */
192 #define	CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
193 #define	clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
194 
195 /*
196  * bool_t
197  * CLNT_CONTROL(cl, request, info)
198  *      CLIENT *cl;
199  *      u_int request;
200  *      char *info;
201  */
202 #define	CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
203 #define	clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
204 
205 /*
206  * control operations that apply to both udp and tcp transports
207  */
208 #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
209 #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
210 #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
211 /*
212  * udp only control operations
213  */
214 #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
215 #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
216 
217 /*
218  * void
219  * CLNT_DESTROY(rh);
220  * 	CLIENT *rh;
221  */
222 #define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
223 #define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
224 
225 
226 /*
227  * RPCTEST is a test program which is accessable on every rpc
228  * transport/port.  It is used for testing, performance evaluation,
229  * and network administration.
230  */
231 
232 #define RPCTEST_PROGRAM		((u_long)1)
233 #define RPCTEST_VERSION		((u_long)1)
234 #define RPCTEST_NULL_PROC	((u_long)2)
235 #define RPCTEST_NULL_BATCH_PROC	((u_long)3)
236 
237 /*
238  * By convention, procedure 0 takes null arguments and returns them
239  */
240 
241 #define NULLPROC ((u_long)0)
242 
243 /*
244  * Below are the client handle creation routines for the various
245  * implementations of client side rpc.  They can return NULL if a
246  * creation failure occurs.
247  */
248 
249 /*
250  * Memory based rpc (for speed check and testing)
251  * CLIENT *
252  * clntraw_create(prog, vers)
253  *	u_long prog;
254  *	u_long vers;
255  */
256 __BEGIN_DECLS
257 extern CLIENT *clntraw_create	__P((u_long, u_long));
258 __END_DECLS
259 
260 
261 /*
262  * Generic client creation routine. Supported protocols are "udp" and "tcp"
263  * CLIENT *
264  * clnt_create(host, prog, vers, prot);
265  *	char *host; 	-- hostname
266  *	u_long prog;	-- program number
267  *	u_long vers;	-- version number
268  *	char *prot;	-- protocol
269  */
270 __BEGIN_DECLS
271 extern CLIENT *clnt_create	__P((char *, u_long, u_long, char *));
272 __END_DECLS
273 
274 
275 /*
276  * TCP based rpc
277  * CLIENT *
278  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
279  *	struct sockaddr_in *raddr;
280  *	u_long prog;
281  *	u_long version;
282  *	register int *sockp;
283  *	u_int sendsz;
284  *	u_int recvsz;
285  */
286 __BEGIN_DECLS
287 extern CLIENT *clnttcp_create	__P((struct sockaddr_in *,
288 				     u_long,
289 				     u_long,
290 				     int *,
291 				     u_int,
292 				     u_int));
293 __END_DECLS
294 
295 
296 /*
297  * UDP based rpc.
298  * CLIENT *
299  * clntudp_create(raddr, program, version, wait, sockp)
300  *	struct sockaddr_in *raddr;
301  *	u_long program;
302  *	u_long version;
303  *	struct timeval wait;
304  *	int *sockp;
305  *
306  * Same as above, but you specify max packet sizes.
307  * CLIENT *
308  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
309  *	struct sockaddr_in *raddr;
310  *	u_long program;
311  *	u_long version;
312  *	struct timeval wait;
313  *	int *sockp;
314  *	u_int sendsz;
315  *	u_int recvsz;
316  */
317 __BEGIN_DECLS
318 extern CLIENT *clntudp_create	__P((struct sockaddr_in *,
319 				     u_long,
320 				     u_long,
321 				     struct timeval,
322 				     int *));
323 extern CLIENT *clntudp_bufcreate __P((struct sockaddr_in *,
324 				     u_long,
325 				     u_long,
326 				     struct timeval,
327 				     int *,
328 				     u_int,
329 				     u_int));
330 __END_DECLS
331 
332 
333 /*
334  * Print why creation failed
335  */
336 __BEGIN_DECLS
337 extern void clnt_pcreateerror	__P((char *));			/* stderr */
338 extern char *clnt_spcreateerror	__P((char *));			/* string */
339 __END_DECLS
340 
341 /*
342  * Like clnt_perror(), but is more verbose in its output
343  */
344 __BEGIN_DECLS
345 extern void clnt_perrno		__P((enum clnt_stat));		/* stderr */
346 extern char *clnt_sperrno	__P((enum clnt_stat));		/* string */
347 __END_DECLS
348 
349 /*
350  * Print an English error message, given the client error code
351  */
352 __BEGIN_DECLS
353 extern void clnt_perror		__P((CLIENT *, char *)); 	/* stderr */
354 extern char *clnt_sperror	__P((CLIENT *, char *));	/* string */
355 __END_DECLS
356 
357 
358 /*
359  * If a creation fails, the following allows the user to figure out why.
360  */
361 struct rpc_createerr {
362 	enum clnt_stat cf_stat;
363 	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
364 };
365 
366 extern struct rpc_createerr rpc_createerr;
367 
368 
369 #define UDPMSGSIZE	8800	/* rpc imposed limit on udp msg size */
370 #define RPCSMALLMSGSIZE	400	/* a more reasonable packet size */
371 
372 #endif /* !_RPC_CLNT_H */
373