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