Fix `option INCLUDE_CONFIG_FILE',
[dragonfly.git] / include / rpc / svc.h
blobd5aa807c5debcd2083f615bf801c417fb3baf371
1 /*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
29 * from: @(#)svc.h 1.20 88/02/08 SMI
30 * from: @(#)svc.h 2.2 88/07/29 4.0 RPCSRC
31 * $FreeBSD: src/include/rpc/svc.h,v 1.16 1999/12/29 05:00:43 peter Exp $
32 * $DragonFly: src/include/rpc/svc.h,v 1.4 2008/05/19 10:19:49 corecode Exp $
36 * svc.h, Server-side remote procedure call interface.
38 * Copyright (C) 1984, Sun Microsystems, Inc.
41 #ifndef _RPC_SVC_H
42 #define _RPC_SVC_H
43 #include <sys/cdefs.h>
44 #include <sys/select.h>
47 * This interface must manage two items concerning remote procedure calling:
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.
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.
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.
68 enum xprt_stat {
69 XPRT_DIED,
70 XPRT_MOREREQS,
71 XPRT_IDLE
74 struct rpc_msg;
77 * Server side transport handle
79 typedef struct __rpc_svcxprt {
80 int xp_sock;
81 u_short xp_port; /* associated port number */
82 struct xp_ops {
83 /* receive incoming requests */
84 bool_t (*xp_recv) (struct __rpc_svcxprt *,
85 struct rpc_msg *);
86 /* get transport status */
87 enum xprt_stat (*xp_stat) (struct __rpc_svcxprt *);
88 /* get arguments */
89 bool_t (*xp_getargs) (struct __rpc_svcxprt *, xdrproc_t,
90 caddr_t);
91 /* send reply */
92 bool_t (*xp_reply) (struct __rpc_svcxprt *,
93 struct rpc_msg *);
94 /* free mem allocated for args */
95 bool_t (*xp_freeargs) (struct __rpc_svcxprt *, xdrproc_t,
96 caddr_t);
97 /* destroy this struct */
98 void (*xp_destroy) (struct __rpc_svcxprt *);
99 } *xp_ops;
100 int xp_addrlen; /* length of remote address */
101 struct sockaddr_in xp_raddr; /* remote address */
102 struct opaque_auth xp_verf; /* raw response verifier */
103 caddr_t xp_p1; /* private */
104 caddr_t xp_p2; /* private */
105 } SVCXPRT;
108 * Approved way of getting address of caller
110 #define svc_getcaller(x) (&(x)->xp_raddr)
113 * Operations defined on an SVCXPRT handle
115 * SVCXPRT *xprt;
116 * struct rpc_msg *msg;
117 * xdrproc_t xargs;
118 * caddr_t argsp;
120 #define SVC_RECV(xprt, msg) \
121 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
122 #define svc_recv(xprt, msg) \
123 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
125 #define SVC_STAT(xprt) \
126 (*(xprt)->xp_ops->xp_stat)(xprt)
127 #define svc_stat(xprt) \
128 (*(xprt)->xp_ops->xp_stat)(xprt)
130 #define SVC_GETARGS(xprt, xargs, argsp) \
131 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
132 #define svc_getargs(xprt, xargs, argsp) \
133 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
135 #define SVC_REPLY(xprt, msg) \
136 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
137 #define svc_reply(xprt, msg) \
138 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
140 #define SVC_FREEARGS(xprt, xargs, argsp) \
141 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
142 #define svc_freeargs(xprt, xargs, argsp) \
143 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
145 #define SVC_DESTROY(xprt) \
146 (*(xprt)->xp_ops->xp_destroy)(xprt)
147 #define svc_destroy(xprt) \
148 (*(xprt)->xp_ops->xp_destroy)(xprt)
152 * Service request
154 struct svc_req {
155 u_int32_t rq_prog; /* service program number */
156 u_int32_t rq_vers; /* service protocol version */
157 u_int32_t rq_proc; /* the desired procedure */
158 struct opaque_auth rq_cred; /* raw creds from the wire */
159 caddr_t rq_clntcred; /* read only cooked cred */
160 SVCXPRT *rq_xprt; /* associated transport */
165 * Service registration
167 * svc_register(xprt, prog, vers, dispatch, protocol)
168 * SVCXPRT *xprt;
169 * u_long prog;
170 * u_long vers;
171 * void (*dispatch)();
172 * int protocol; (like TCP or UDP, zero means do not register)
174 __BEGIN_DECLS
175 extern bool_t svc_register (SVCXPRT *, u_long, u_long,
176 void (*) (struct svc_req *, SVCXPRT *), int);
177 __END_DECLS
180 * Service un-registration
182 * svc_unregister(prog, vers)
183 * u_long prog;
184 * u_long vers;
186 __BEGIN_DECLS
187 extern void svc_unregister (u_long, u_long);
188 __END_DECLS
191 * Transport registration.
193 * xprt_register(xprt)
194 * SVCXPRT *xprt;
196 __BEGIN_DECLS
197 extern void xprt_register (SVCXPRT *);
198 __END_DECLS
201 * Transport un-register
203 * xprt_unregister(xprt)
204 * SVCXPRT *xprt;
206 __BEGIN_DECLS
207 extern void xprt_unregister (SVCXPRT *);
208 __END_DECLS
214 * When the service routine is called, it must first check to see if it
215 * knows about the procedure; if not, it should call svcerr_noproc
216 * and return. If so, it should deserialize its arguments via
217 * SVC_GETARGS (defined above). If the deserialization does not work,
218 * svcerr_decode should be called followed by a return. Successful
219 * decoding of the arguments should be followed the execution of the
220 * procedure's code and a call to svc_sendreply.
222 * Also, if the service refuses to execute the procedure due to too-
223 * weak authentication parameters, svcerr_weakauth should be called.
224 * Note: do not confuse access-control failure with weak authentication!
226 * NB: In pure implementations of rpc, the caller always waits for a reply
227 * msg. This message is sent when svc_sendreply is called.
228 * Therefore pure service implementations should always call
229 * svc_sendreply even if the function logically returns void; use
230 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
231 * for the abuse of pure rpc via batched calling or pipelining. In the
232 * case of a batched call, svc_sendreply should NOT be called since
233 * this would send a return message, which is what batching tries to avoid.
234 * It is the service/protocol writer's responsibility to know which calls are
235 * batched and which are not. Warning: responding to batch calls may
236 * deadlock the caller and server processes!
239 __BEGIN_DECLS
240 extern bool_t svc_sendreply (SVCXPRT *, xdrproc_t, char *);
241 extern void svcerr_decode (SVCXPRT *);
242 extern void svcerr_weakauth (SVCXPRT *);
243 extern void svcerr_noproc (SVCXPRT *);
244 extern void svcerr_progvers (SVCXPRT *, u_long, u_long);
245 extern void svcerr_auth (SVCXPRT *, enum auth_stat);
246 extern void svcerr_noprog (SVCXPRT *);
247 extern void svcerr_systemerr (SVCXPRT *);
248 __END_DECLS
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).
262 * Global keeper of rpc service descriptors in use
263 * dynamic; must be inspected before each call to select
265 extern int svc_maxfd;
266 extern fd_set svc_fdset;
267 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
269 #ifndef _KERNEL
271 * a small program implemented by the svc_rpc implementation itself;
272 * also see clnt.h for protocol numbers.
274 extern void rpctest_service();
275 #endif
277 __BEGIN_DECLS
278 extern void svc_getreq (int);
279 extern void svc_getreqset (fd_set *);
280 extern void svc_getreqset2 (fd_set *, int); /* XXX: nonstd, undoc */
281 extern void svc_run (void);
282 __END_DECLS
285 * Socket to use on svcxxx_create call to get default socket
287 #define RPC_ANYSOCK -1
290 * These are the existing service side transport implementations
294 * Memory based rpc for testing and timing.
296 __BEGIN_DECLS
297 extern SVCXPRT *svcraw_create (void);
298 __END_DECLS
302 * Udp based rpc.
304 __BEGIN_DECLS
305 extern SVCXPRT *svcudp_create (int);
306 extern SVCXPRT *svcudp_bufcreate (int, u_int, u_int);
307 __END_DECLS
311 * Tcp based rpc.
313 __BEGIN_DECLS
314 extern SVCXPRT *svctcp_create (int, u_int, u_int);
315 extern SVCXPRT *svcfd_create (int, u_int, u_int);
316 __END_DECLS
319 * AF_UNIX socket based rpc.
321 __BEGIN_DECLS
322 extern SVCXPRT *svcunix_create (int, u_int, u_int, char *);
323 extern SVCXPRT *svcunixfd_create (int, u_int, u_int);
324 __END_DECLS
326 #endif /* !_RPC_SVC_H */