xref: /csrg-svn/lib/librpc/rpc/clnt.h (revision 45065)
1*45065Smckusick /* @(#)clnt.h	2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/
2*45065Smckusick /*
3*45065Smckusick  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4*45065Smckusick  * unrestricted use provided that this legend is included on all tape
5*45065Smckusick  * media and as a part of the software program in whole or part.  Users
6*45065Smckusick  * may copy or modify Sun RPC without charge, but are not authorized
7*45065Smckusick  * to license or distribute it to anyone else except as part of a product or
8*45065Smckusick  * program developed by the user.
9*45065Smckusick  *
10*45065Smckusick  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11*45065Smckusick  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12*45065Smckusick  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13*45065Smckusick  *
14*45065Smckusick  * Sun RPC is provided with no support and without any obligation on the
15*45065Smckusick  * part of Sun Microsystems, Inc. to assist in its use, correction,
16*45065Smckusick  * modification or enhancement.
17*45065Smckusick  *
18*45065Smckusick  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19*45065Smckusick  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20*45065Smckusick  * OR ANY PART THEREOF.
21*45065Smckusick  *
22*45065Smckusick  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23*45065Smckusick  * or profits or other special, indirect and consequential damages, even if
24*45065Smckusick  * Sun has been advised of the possibility of such damages.
25*45065Smckusick  *
26*45065Smckusick  * Sun Microsystems, Inc.
27*45065Smckusick  * 2550 Garcia Avenue
28*45065Smckusick  * Mountain View, California  94043
29*45065Smckusick  */
30*45065Smckusick 
31*45065Smckusick /*
32*45065Smckusick  * clnt.h - Client side remote procedure call interface.
33*45065Smckusick  *
34*45065Smckusick  * Copyright (C) 1984, Sun Microsystems, Inc.
35*45065Smckusick  */
36*45065Smckusick 
37*45065Smckusick #ifndef _CLNT_
38*45065Smckusick #define _CLNT_
39*45065Smckusick 
40*45065Smckusick /*
41*45065Smckusick  * Rpc calls return an enum clnt_stat.  This should be looked at more,
42*45065Smckusick  * since each implementation is required to live with this (implementation
43*45065Smckusick  * independent) list of errors.
44*45065Smckusick  */
45*45065Smckusick enum clnt_stat {
46*45065Smckusick 	RPC_SUCCESS=0,			/* call succeeded */
47*45065Smckusick 	/*
48*45065Smckusick 	 * local errors
49*45065Smckusick 	 */
50*45065Smckusick 	RPC_CANTENCODEARGS=1,		/* can't encode arguments */
51*45065Smckusick 	RPC_CANTDECODERES=2,		/* can't decode results */
52*45065Smckusick 	RPC_CANTSEND=3,			/* failure in sending call */
53*45065Smckusick 	RPC_CANTRECV=4,			/* failure in receiving result */
54*45065Smckusick 	RPC_TIMEDOUT=5,			/* call timed out */
55*45065Smckusick 	/*
56*45065Smckusick 	 * remote errors
57*45065Smckusick 	 */
58*45065Smckusick 	RPC_VERSMISMATCH=6,		/* rpc versions not compatible */
59*45065Smckusick 	RPC_AUTHERROR=7,		/* authentication error */
60*45065Smckusick 	RPC_PROGUNAVAIL=8,		/* program not available */
61*45065Smckusick 	RPC_PROGVERSMISMATCH=9,		/* program version mismatched */
62*45065Smckusick 	RPC_PROCUNAVAIL=10,		/* procedure unavailable */
63*45065Smckusick 	RPC_CANTDECODEARGS=11,		/* decode arguments error */
64*45065Smckusick 	RPC_SYSTEMERROR=12,		/* generic "other problem" */
65*45065Smckusick 
66*45065Smckusick 	/*
67*45065Smckusick 	 * callrpc & clnt_create errors
68*45065Smckusick 	 */
69*45065Smckusick 	RPC_UNKNOWNHOST=13,		/* unknown host name */
70*45065Smckusick 	RPC_UNKNOWNPROTO=17,		/* unkown protocol */
71*45065Smckusick 
72*45065Smckusick 	/*
73*45065Smckusick 	 * _ create errors
74*45065Smckusick 	 */
75*45065Smckusick 	RPC_PMAPFAILURE=14,		/* the pmapper failed in its call */
76*45065Smckusick 	RPC_PROGNOTREGISTERED=15,	/* remote program is not registered */
77*45065Smckusick 	/*
78*45065Smckusick 	 * unspecified error
79*45065Smckusick 	 */
80*45065Smckusick 	RPC_FAILED=16
81*45065Smckusick };
82*45065Smckusick 
83*45065Smckusick 
84*45065Smckusick /*
85*45065Smckusick  * Error info.
86*45065Smckusick  */
87*45065Smckusick struct rpc_err {
88*45065Smckusick 	enum clnt_stat re_status;
89*45065Smckusick 	union {
90*45065Smckusick 		int RE_errno;		/* realated system error */
91*45065Smckusick 		enum auth_stat RE_why;	/* why the auth error occurred */
92*45065Smckusick 		struct {
93*45065Smckusick 			u_long low;	/* lowest verion supported */
94*45065Smckusick 			u_long high;	/* highest verion supported */
95*45065Smckusick 		} RE_vers;
96*45065Smckusick 		struct {		/* maybe meaningful if RPC_FAILED */
97*45065Smckusick 			long s1;
98*45065Smckusick 			long s2;
99*45065Smckusick 		} RE_lb;		/* life boot & debugging only */
100*45065Smckusick 	} ru;
101*45065Smckusick #define	re_errno	ru.RE_errno
102*45065Smckusick #define	re_why		ru.RE_why
103*45065Smckusick #define	re_vers		ru.RE_vers
104*45065Smckusick #define	re_lb		ru.RE_lb
105*45065Smckusick };
106*45065Smckusick 
107*45065Smckusick 
108*45065Smckusick /*
109*45065Smckusick  * Client rpc handle.
110*45065Smckusick  * Created by individual implementations, see e.g. rpc_udp.c.
111*45065Smckusick  * Client is responsible for initializing auth, see e.g. auth_none.c.
112*45065Smckusick  */
113*45065Smckusick typedef struct {
114*45065Smckusick 	AUTH	*cl_auth;			/* authenticator */
115*45065Smckusick 	struct clnt_ops {
116*45065Smckusick 		enum clnt_stat	(*cl_call)();	/* call remote procedure */
117*45065Smckusick 		void		(*cl_abort)();	/* abort a call */
118*45065Smckusick 		void		(*cl_geterr)();	/* get specific error code */
119*45065Smckusick 		bool_t		(*cl_freeres)(); /* frees results */
120*45065Smckusick 		void		(*cl_destroy)();/* destroy this structure */
121*45065Smckusick 		bool_t          (*cl_control)();/* the ioctl() of rpc */
122*45065Smckusick 	} *cl_ops;
123*45065Smckusick 	caddr_t			cl_private;	/* private stuff */
124*45065Smckusick } CLIENT;
125*45065Smckusick 
126*45065Smckusick 
127*45065Smckusick /*
128*45065Smckusick  * client side rpc interface ops
129*45065Smckusick  *
130*45065Smckusick  * Parameter types are:
131*45065Smckusick  *
132*45065Smckusick  */
133*45065Smckusick 
134*45065Smckusick /*
135*45065Smckusick  * enum clnt_stat
136*45065Smckusick  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
137*45065Smckusick  * 	CLIENT *rh;
138*45065Smckusick  *	u_long proc;
139*45065Smckusick  *	xdrproc_t xargs;
140*45065Smckusick  *	caddr_t argsp;
141*45065Smckusick  *	xdrproc_t xres;
142*45065Smckusick  *	caddr_t resp;
143*45065Smckusick  *	struct timeval timeout;
144*45065Smckusick  */
145*45065Smckusick #define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)	\
146*45065Smckusick 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
147*45065Smckusick #define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)	\
148*45065Smckusick 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
149*45065Smckusick 
150*45065Smckusick /*
151*45065Smckusick  * void
152*45065Smckusick  * CLNT_ABORT(rh);
153*45065Smckusick  * 	CLIENT *rh;
154*45065Smckusick  */
155*45065Smckusick #define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
156*45065Smckusick #define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
157*45065Smckusick 
158*45065Smckusick /*
159*45065Smckusick  * struct rpc_err
160*45065Smckusick  * CLNT_GETERR(rh);
161*45065Smckusick  * 	CLIENT *rh;
162*45065Smckusick  */
163*45065Smckusick #define	CLNT_GETERR(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
164*45065Smckusick #define	clnt_geterr(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
165*45065Smckusick 
166*45065Smckusick 
167*45065Smckusick /*
168*45065Smckusick  * bool_t
169*45065Smckusick  * CLNT_FREERES(rh, xres, resp);
170*45065Smckusick  * 	CLIENT *rh;
171*45065Smckusick  *	xdrproc_t xres;
172*45065Smckusick  *	caddr_t resp;
173*45065Smckusick  */
174*45065Smckusick #define	CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
175*45065Smckusick #define	clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
176*45065Smckusick 
177*45065Smckusick /*
178*45065Smckusick  * bool_t
179*45065Smckusick  * CLNT_CONTROL(cl, request, info)
180*45065Smckusick  *      CLIENT *cl;
181*45065Smckusick  *      u_int request;
182*45065Smckusick  *      char *info;
183*45065Smckusick  */
184*45065Smckusick #define	CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
185*45065Smckusick #define	clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
186*45065Smckusick 
187*45065Smckusick /*
188*45065Smckusick  * control operations that apply to both udp and tcp transports
189*45065Smckusick  */
190*45065Smckusick #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
191*45065Smckusick #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
192*45065Smckusick #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
193*45065Smckusick /*
194*45065Smckusick  * udp only control operations
195*45065Smckusick  */
196*45065Smckusick #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
197*45065Smckusick #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
198*45065Smckusick 
199*45065Smckusick /*
200*45065Smckusick  * void
201*45065Smckusick  * CLNT_DESTROY(rh);
202*45065Smckusick  * 	CLIENT *rh;
203*45065Smckusick  */
204*45065Smckusick #define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
205*45065Smckusick #define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
206*45065Smckusick 
207*45065Smckusick 
208*45065Smckusick /*
209*45065Smckusick  * RPCTEST is a test program which is accessable on every rpc
210*45065Smckusick  * transport/port.  It is used for testing, performance evaluation,
211*45065Smckusick  * and network administration.
212*45065Smckusick  */
213*45065Smckusick 
214*45065Smckusick #define RPCTEST_PROGRAM		((u_long)1)
215*45065Smckusick #define RPCTEST_VERSION		((u_long)1)
216*45065Smckusick #define RPCTEST_NULL_PROC	((u_long)2)
217*45065Smckusick #define RPCTEST_NULL_BATCH_PROC	((u_long)3)
218*45065Smckusick 
219*45065Smckusick /*
220*45065Smckusick  * By convention, procedure 0 takes null arguments and returns them
221*45065Smckusick  */
222*45065Smckusick 
223*45065Smckusick #define NULLPROC ((u_long)0)
224*45065Smckusick 
225*45065Smckusick /*
226*45065Smckusick  * Below are the client handle creation routines for the various
227*45065Smckusick  * implementations of client side rpc.  They can return NULL if a
228*45065Smckusick  * creation failure occurs.
229*45065Smckusick  */
230*45065Smckusick 
231*45065Smckusick /*
232*45065Smckusick  * Memory based rpc (for speed check and testing)
233*45065Smckusick  * CLIENT *
234*45065Smckusick  * clntraw_create(prog, vers)
235*45065Smckusick  *	u_long prog;
236*45065Smckusick  *	u_long vers;
237*45065Smckusick  */
238*45065Smckusick extern CLIENT *clntraw_create();
239*45065Smckusick 
240*45065Smckusick 
241*45065Smckusick /*
242*45065Smckusick  * Generic client creation routine. Supported protocols are "udp" and "tcp"
243*45065Smckusick  */
244*45065Smckusick extern CLIENT *
245*45065Smckusick clnt_create(/*host, prog, vers, prot*/); /*
246*45065Smckusick 	char *host; 	-- hostname
247*45065Smckusick 	u_long prog;	-- program number
248*45065Smckusick 	u_long vers;	-- version number
249*45065Smckusick 	char *prot;	-- protocol
250*45065Smckusick */
251*45065Smckusick 
252*45065Smckusick 
253*45065Smckusick 
254*45065Smckusick 
255*45065Smckusick /*
256*45065Smckusick  * TCP based rpc
257*45065Smckusick  * CLIENT *
258*45065Smckusick  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
259*45065Smckusick  *	struct sockaddr_in *raddr;
260*45065Smckusick  *	u_long prog;
261*45065Smckusick  *	u_long version;
262*45065Smckusick  *	register int *sockp;
263*45065Smckusick  *	u_int sendsz;
264*45065Smckusick  *	u_int recvsz;
265*45065Smckusick  */
266*45065Smckusick extern CLIENT *clnttcp_create();
267*45065Smckusick 
268*45065Smckusick /*
269*45065Smckusick  * UDP based rpc.
270*45065Smckusick  * CLIENT *
271*45065Smckusick  * clntudp_create(raddr, program, version, wait, sockp)
272*45065Smckusick  *	struct sockaddr_in *raddr;
273*45065Smckusick  *	u_long program;
274*45065Smckusick  *	u_long version;
275*45065Smckusick  *	struct timeval wait;
276*45065Smckusick  *	int *sockp;
277*45065Smckusick  *
278*45065Smckusick  * Same as above, but you specify max packet sizes.
279*45065Smckusick  * CLIENT *
280*45065Smckusick  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
281*45065Smckusick  *	struct sockaddr_in *raddr;
282*45065Smckusick  *	u_long program;
283*45065Smckusick  *	u_long version;
284*45065Smckusick  *	struct timeval wait;
285*45065Smckusick  *	int *sockp;
286*45065Smckusick  *	u_int sendsz;
287*45065Smckusick  *	u_int recvsz;
288*45065Smckusick  */
289*45065Smckusick extern CLIENT *clntudp_create();
290*45065Smckusick extern CLIENT *clntudp_bufcreate();
291*45065Smckusick 
292*45065Smckusick /*
293*45065Smckusick  * Print why creation failed
294*45065Smckusick  */
295*45065Smckusick void clnt_pcreateerror(/* char *msg */);	/* stderr */
296*45065Smckusick char *clnt_spcreateerror(/* char *msg */);	/* string */
297*45065Smckusick 
298*45065Smckusick /*
299*45065Smckusick  * Like clnt_perror(), but is more verbose in its output
300*45065Smckusick  */
301*45065Smckusick void clnt_perrno(/* enum clnt_stat num */);	/* stderr */
302*45065Smckusick 
303*45065Smckusick /*
304*45065Smckusick  * Print an English error message, given the client error code
305*45065Smckusick  */
306*45065Smckusick void clnt_perror(/* CLIENT *clnt, char *msg */); 	/* stderr */
307*45065Smckusick char *clnt_sperror(/* CLIENT *clnt, char *msg */);	/* string */
308*45065Smckusick 
309*45065Smckusick /*
310*45065Smckusick  * If a creation fails, the following allows the user to figure out why.
311*45065Smckusick  */
312*45065Smckusick struct rpc_createerr {
313*45065Smckusick 	enum clnt_stat cf_stat;
314*45065Smckusick 	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
315*45065Smckusick };
316*45065Smckusick 
317*45065Smckusick extern struct rpc_createerr rpc_createerr;
318*45065Smckusick 
319*45065Smckusick 
320*45065Smckusick 
321*45065Smckusick /*
322*45065Smckusick  * Copy error message to buffer.
323*45065Smckusick  */
324*45065Smckusick char *clnt_sperrno(/* enum clnt_stat num */);	/* string */
325*45065Smckusick 
326*45065Smckusick 
327*45065Smckusick 
328*45065Smckusick #define UDPMSGSIZE	8800	/* rpc imposed limit on udp msg size */
329*45065Smckusick #define RPCSMALLMSGSIZE	400	/* a more reasonable packet size */
330*45065Smckusick 
331*45065Smckusick #endif /*!_CLNT_*/
332