Import TBBT (NFS trace replay).
[bluesky.git] / TBBT / trace_play / rpc / svc.h
1 /*
2  * @(#)svc.h     2.1     97/10/23
3  */
4 /* @(#)svc.h    2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Warrenton, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23 /*
24  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25  * unrestricted use provided that this legend is included on all tape
26  * media and as a part of the software program in whole or part.  Users
27  * may copy or modify Sun RPC without charge, but are not authorized
28  * to license or distribute it to anyone else except as part of a product or
29  * program developed by the user.
30  * 
31  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
34  * 
35  * Sun RPC is provided with no support and without any obligation on the
36  * part of Sun Microsystems, Inc. to assist in its use, correction,
37  * modification or enhancement.
38  * 
39  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41  * OR ANY PART THEREOF.
42  * 
43  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44  * or profits or other special, indirect and consequential damages, even if
45  * Sun has been advised of the possibility of such damages.
46  * 
47  * Sun Microsystems, Inc.
48  * 2550 Garcia Avenue
49  * Mountain View, California  94043
50  */
51
52 /*
53  * svc.h, Server-side remote procedure call interface.
54  *
55  * Copyright (C) 1984, Sun Microsystems, Inc.
56  */
57
58 #ifndef __SVC_HEADER__
59 #define __SVC_HEADER__
60
61 #include "rpc/rpc_msg.h"
62 #include "rpc/xdr.h"
63
64 /*
65  * This interface must manage two items concerning remote procedure calling:
66  *
67  * 1) An arbitrary number of transport connections upon which rpc requests
68  * are received.  The two most notable transports are TCP and UDP;  they are
69  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
70  * they in turn call xprt_register and xprt_unregister.
71  *
72  * 2) An arbitrary number of locally registered services.  Services are
73  * described by the following four data: program number, version number,
74  * "service dispatch" function, a transport handle, and a boolean that
75  * indicates whether or not the exported program should be registered with a
76  * local binder service;  if true the program's number and version and the
77  * port number from the transport handle are registered with the binder.
78  * These data are registered with the rpc svc system via svc_register.
79  *
80  * A service's dispatch function is called whenever an rpc request comes in
81  * on a transport.  The request's program and version numbers must match
82  * those of the registered service.  The dispatch function is passed two
83  * parameters, struct svc_req * and SVCXPRT *, defined below.
84  */
85
86 enum xprt_stat {
87         XPRT_DIED,
88         XPRT_MOREREQS,
89         XPRT_IDLE
90 };
91
92 /*
93  * Server side transport handle
94  */
95 typedef struct SVCXPRT {
96         int             xp_sock;
97         uint16_t        xp_port;         /* associated port number */
98         struct xp_ops   *xp_ops;
99 #if defined(AIX)
100         size_t          xp_addrlen;      /* length of remote address */
101 #else
102         int             xp_addrlen;      /* length of remote address */
103 #endif
104         struct sockaddr_in xp_raddr;     /* remote address */
105         struct opaque_auth xp_verf;      /* raw response verifier */
106         void *          xp_p1;           /* private */
107         void *          xp_p2;           /* private */
108 } SVCXPRT;
109
110 struct xp_ops {
111         bool_t  (*xp_recv)(SVCXPRT *, struct rpc_msg *);
112         enum xprt_stat (*xp_stat)(SVCXPRT *);
113         bool_t  (*xp_getargs)(SVCXPRT *, xdrproc_t, void *);
114         bool_t  (*xp_reply)(SVCXPRT *, struct rpc_msg *);
115         bool_t  (*xp_freeargs)(SVCXPRT *, xdrproc_t, void *);
116         void    (*xp_destroy)(SVCXPRT *);
117 };
118 /*
119  *  Approved way of getting address of caller
120  */
121 #define svc_getcaller(x) (&(x)->xp_raddr)
122
123 /*
124  * Operations defined on an SVCXPRT handle
125  *
126  * SVCXPRT              *xprt;
127  * struct rpc_msg       *msg;
128  * xdrproc_t             xargs;
129  * void *                argsp;
130  */
131 #define SVC_RECV(xprt, msg)                             \
132         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
133 #define svc_recv(xprt, msg)                             \
134         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
135
136 #define SVC_STAT(xprt)                                  \
137         (*(xprt)->xp_ops->xp_stat)(xprt)
138 #define svc_stat(xprt)                                  \
139         (*(xprt)->xp_ops->xp_stat)(xprt)
140
141 #define SVC_GETARGS(xprt, xargs, argsp)                 \
142         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
143 #define svc_getargs(xprt, xargs, argsp)                 \
144         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
145
146 #define SVC_REPLY(xprt, msg)                            \
147         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
148 #define svc_reply(xprt, msg)                            \
149         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
150
151 #define SVC_FREEARGS(xprt, xargs, argsp)                \
152         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
153 #define svc_freeargs(xprt, xargs, argsp)                \
154         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
155
156 #define SVC_DESTROY(xprt)                               \
157         (*(xprt)->xp_ops->xp_destroy)(xprt)
158 #define svc_destroy(xprt)                               \
159         (*(xprt)->xp_ops->xp_destroy)(xprt)
160
161
162 /*
163  * Service request
164  */
165 struct svc_req {
166         uint32_t        rq_prog;        /* service program number */
167         uint32_t        rq_vers;        /* service protocol version */
168         uint32_t        rq_proc;        /* the desired procedure */
169         struct opaque_auth rq_cred;     /* raw creds from the wire */
170         void *          rq_clntcred;    /* read only cooked cred */
171         SVCXPRT *rq_xprt;               /* associated transport */
172 };
173
174
175 /*
176  * Service registration
177  *
178  * svc_register(xprt, prog, vers, dispatch, protocol)
179  *      SVCXPRT *xprt;
180  *      uint32_t prog;
181  *      uint32_t vers;
182  *      void (*dispatch)();
183  *      int protocol;
184  */
185 extern bool_t   svc_register(SVCXPRT *, uint32_t, uint32_t, void (*)(), int);
186
187 /*
188  * Service un-registration
189  *
190  * svc_unregister(prog, vers)
191  *      uint32_t prog;
192  *      uint32_t vers;
193  */
194 extern void     svc_unregister(uint32_t, uint32_t);
195
196 /*
197  * Transport registration.
198  *
199  * xprt_register(xprt)
200  *      SVCXPRT *xprt;
201  */
202 extern void     xprt_register(SVCXPRT *);
203
204 /*
205  * Transport un-register
206  *
207  * xprt_unregister(xprt)
208  *      SVCXPRT *xprt;
209  */
210 extern void     xprt_unregister(SVCXPRT *);
211
212
213
214
215 /*
216  * When the service routine is called, it must first check to see if it
217  * knows about the procedure;  if not, it should call svcerr_noproc
218  * and return.  If so, it should deserialize its arguments via 
219  * SVC_GETARGS (defined above).  If the deserialization does not work,
220  * svcerr_decode should be called followed by a return.  Successful
221  * decoding of the arguments should be followed the execution of the
222  * procedure's code and a call to svc_sendreply.
223  *
224  * Also, if the service refuses to execute the procedure due to too-
225  * weak authentication parameters, svcerr_weakauth should be called.
226  * Note: do not confuse access-control failure with weak authentication!
227  *
228  * NB: In pure implementations of rpc, the caller always waits for a reply
229  * msg.  This message is sent when svc_sendreply is called.  
230  * Therefore pure service implementations should always call
231  * svc_sendreply even if the function logically returns void;  use
232  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
233  * for the abuse of pure rpc via batched calling or pipelining.  In the
234  * case of a batched call, svc_sendreply should NOT be called since
235  * this would send a return message, which is what batching tries to avoid.
236  * It is the service/protocol writer's responsibility to know which calls are
237  * batched and which are not.  Warning: responding to batch calls may
238  * deadlock the caller and server processes!
239  */
240
241 extern bool_t   svc_sendreply(SVCXPRT *, xdrproc_t, void *);
242 extern void     svcerr_decode(SVCXPRT *);
243 extern void     svcerr_weakauth(SVCXPRT *);
244 extern void     svcerr_noproc(SVCXPRT *);
245 extern void     svcerr_progvers(SVCXPRT *, uint32_t, uint32_t);
246 extern void     svcerr_auth(SVCXPRT *, enum auth_stat);
247 extern void     svcerr_noprog(SVCXPRT *);
248 extern void     svcerr_systemerr(SVCXPRT *);
249     
250 /*
251  * Lowest level dispatching -OR- who owns this process anyway.
252  * Somebody has to wait for incoming requests and then call the correct
253  * service routine.  The routine svc_run does infinite waiting; i.e.,
254  * svc_run never returns.
255  * Since another (co-existant) package may wish to selectively wait for
256  * incoming calls or other events outside of the rpc architecture, the
257  * routine svc_getreq is provided.  It must be passed readfds, the
258  * "in-place" results of a select system call (see select, section 2).
259  */
260
261 /*
262  * Global keeper of rpc service descriptors in use
263  * dynamic; must be inspected before each call to select 
264  */
265 #ifdef FD_SETSIZE
266 extern fd_set svc_fdset;
267 #define svc_fds svc_fdset.fds_bits[0]   /* compatibility */
268 #else
269 extern int svc_fds;
270 #endif /* def FD_SETSIZE */
271
272 /*
273  * a small program implemented by the svc_rpc implementation itself;
274  * also see clnt.h for protocol numbers.
275  */
276 extern void rpctest_service();
277
278 extern void     svc_getreq(int);
279 #ifdef FD_SETSIZE
280 extern void     svc_getreqset(fd_set *);/* takes fdset instead of int */
281 #else
282 extern void     svc_getreqset(int *);
283 #endif
284 extern void     svc_run(void);   /* never returns */
285
286 /*
287  * Socket to use on svcxxx_create call to get default socket
288  */
289 #define RPC_ANYSOCK     -1
290
291 /*
292  * These are the existing service side transport implementations
293  */
294
295 /*
296  * Memory based rpc for testing and timing.
297  */
298 extern SVCXPRT *svcraw_create(void);
299
300 /*
301  * Udp based rpc.
302  */
303 extern SVCXPRT *svcudp_create(int);
304 extern SVCXPRT *svcudp_bufcreate(int, uint_t, uint_t);
305
306 /*
307  * Tcp based rpc.
308  */
309 extern SVCXPRT *svctcp_create(int, uint_t, uint_t);
310
311 extern int svcudp_enablecache(SVCXPRT *, uint32_t);
312
313
314 #endif /* !__SVC_HEADER__ */