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