uipc: Use token for rights counting
[dragonfly.git] / include / rpc / svc.h
blob4757c4c53c382d1cef97f942719768f5d202bf8c
1 /*-
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
28 * from: @(#)svc.h 1.35 88/12/17 SMI
29 * from: @(#)svc.h 1.27 94/04/25 SMI
30 * $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $
31 * $FreeBSD: src/include/rpc/svc.h,v 1.24 2003/06/15 10:32:01 mbr 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) 1986-1993 by 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.
69 * Service control requests
71 #define SVCGET_VERSQUIET 1
72 #define SVCSET_VERSQUIET 2
73 #define SVCGET_CONNMAXREC 3
74 #define SVCSET_CONNMAXREC 4
77 * Operations for rpc_control().
79 #define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */
80 #define RPC_SVC_CONNMAXREC_GET 1
82 enum xprt_stat {
83 XPRT_DIED,
84 XPRT_MOREREQS,
85 XPRT_IDLE
89 * Server side transport handle
91 typedef struct __rpc_svcxprt {
92 int xp_fd;
93 u_short xp_port; /* associated port number */
94 const struct xp_ops {
95 /* receive incoming requests */
96 bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
97 /* get transport status */
98 enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
99 /* get arguments */
100 bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
101 void *);
102 /* send reply */
103 bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
104 /* free mem allocated for args */
105 bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
106 void *);
107 /* destroy this struct */
108 void (*xp_destroy)(struct __rpc_svcxprt *);
109 } *xp_ops;
110 int xp_addrlen; /* length of remote address */
111 struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */
112 /* XXX - fvdl stick this here for ABI backward compat reasons */
113 const struct xp_ops2 {
114 /* catch-all function */
115 bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int,
116 void *);
117 } *xp_ops2;
118 char *xp_tp; /* transport provider device name */
119 char *xp_netid; /* network token */
120 struct netbuf xp_ltaddr; /* local transport address */
121 struct netbuf xp_rtaddr; /* remote transport address */
122 struct opaque_auth xp_verf; /* raw response verifier */
123 void *xp_p1; /* private: for use by svc ops */
124 void *xp_p2; /* private: for use by svc ops */
125 void *xp_p3; /* private: for use by svc lib */
126 int xp_type; /* transport type */
127 } SVCXPRT;
130 * Service request
132 struct svc_req {
133 u_int32_t rq_prog; /* service program number */
134 u_int32_t rq_vers; /* service protocol version */
135 u_int32_t rq_proc; /* the desired procedure */
136 struct opaque_auth rq_cred; /* raw creds from the wire */
137 void *rq_clntcred; /* read only cooked cred */
138 SVCXPRT *rq_xprt; /* associated transport */
142 * Approved way of getting address of caller
144 #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
147 * Operations defined on an SVCXPRT handle
149 * SVCXPRT *xprt;
150 * struct rpc_msg *msg;
151 * xdrproc_t xargs;
152 * void * argsp;
154 #define SVC_RECV(xprt, msg) \
155 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
156 #define svc_recv(xprt, msg) \
157 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
159 #define SVC_STAT(xprt) \
160 (*(xprt)->xp_ops->xp_stat)(xprt)
161 #define svc_stat(xprt) \
162 (*(xprt)->xp_ops->xp_stat)(xprt)
164 #define SVC_GETARGS(xprt, xargs, argsp) \
165 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
166 #define svc_getargs(xprt, xargs, argsp) \
167 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
169 #define SVC_REPLY(xprt, msg) \
170 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
171 #define svc_reply(xprt, msg) \
172 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
174 #define SVC_FREEARGS(xprt, xargs, argsp) \
175 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
176 #define svc_freeargs(xprt, xargs, argsp) \
177 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
179 #define SVC_DESTROY(xprt) \
180 (*(xprt)->xp_ops->xp_destroy)(xprt)
181 #define svc_destroy(xprt) \
182 (*(xprt)->xp_ops->xp_destroy)(xprt)
184 #define SVC_CONTROL(xprt, rq, in) \
185 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
188 * Service registration
190 * svc_reg(xprt, prog, vers, dispatch, nconf)
191 * const SVCXPRT *xprt;
192 * const rpcprog_t prog;
193 * const rpcvers_t vers;
194 * const void (*dispatch)();
195 * const struct netconfig *nconf;
198 __BEGIN_DECLS
199 extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
200 void (*)(struct svc_req *, SVCXPRT *),
201 const struct netconfig *);
202 __END_DECLS
205 * Service un-registration
207 * svc_unreg(prog, vers)
208 * const rpcprog_t prog;
209 * const rpcvers_t vers;
212 __BEGIN_DECLS
213 extern void svc_unreg(const rpcprog_t, const rpcvers_t);
214 __END_DECLS
217 * Transport registration.
219 * xprt_register(xprt)
220 * SVCXPRT *xprt;
222 __BEGIN_DECLS
223 extern void xprt_register(SVCXPRT *);
224 __END_DECLS
227 * Transport un-register
229 * xprt_unregister(xprt)
230 * SVCXPRT *xprt;
232 __BEGIN_DECLS
233 extern void xprt_unregister(SVCXPRT *);
234 __END_DECLS
238 * When the service routine is called, it must first check to see if it
239 * knows about the procedure; if not, it should call svcerr_noproc
240 * and return. If so, it should deserialize its arguments via
241 * SVC_GETARGS (defined above). If the deserialization does not work,
242 * svcerr_decode should be called followed by a return. Successful
243 * decoding of the arguments should be followed the execution of the
244 * procedure's code and a call to svc_sendreply.
246 * Also, if the service refuses to execute the procedure due to too-
247 * weak authentication parameters, svcerr_weakauth should be called.
248 * Note: do not confuse access-control failure with weak authentication!
250 * NB: In pure implementations of rpc, the caller always waits for a reply
251 * msg. This message is sent when svc_sendreply is called.
252 * Therefore pure service implementations should always call
253 * svc_sendreply even if the function logically returns void; use
254 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
255 * for the abuse of pure rpc via batched calling or pipelining. In the
256 * case of a batched call, svc_sendreply should NOT be called since
257 * this would send a return message, which is what batching tries to avoid.
258 * It is the service/protocol writer's responsibility to know which calls are
259 * batched and which are not. Warning: responding to batch calls may
260 * deadlock the caller and server processes!
263 __BEGIN_DECLS
264 extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
265 extern void svcerr_decode(SVCXPRT *);
266 extern void svcerr_weakauth(SVCXPRT *);
267 extern void svcerr_noproc(SVCXPRT *);
268 extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
269 extern void svcerr_auth(SVCXPRT *, enum auth_stat);
270 extern void svcerr_noprog(SVCXPRT *);
271 extern void svcerr_systemerr(SVCXPRT *);
272 extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
273 char *(*)(char *), xdrproc_t, xdrproc_t,
274 char *);
275 __END_DECLS
278 * Lowest level dispatching -OR- who owns this process anyway.
279 * Somebody has to wait for incoming requests and then call the correct
280 * service routine. The routine svc_run does infinite waiting; i.e.,
281 * svc_run never returns.
282 * Since another (co-existant) package may wish to selectively wait for
283 * incoming calls or other events outside of the rpc architecture, the
284 * routine svc_getreq is provided. It must be passed readfds, the
285 * "in-place" results of a select system call (see select, section 2).
289 * Global keeper of rpc service descriptors in use
290 * dynamic; must be inspected before each call to select
292 extern int svc_maxfd;
293 #ifdef FD_SETSIZE
294 extern fd_set svc_fdset;
295 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
296 #else
297 extern int svc_fds;
298 #endif /* def FD_SETSIZE */
301 * a small program implemented by the svc_rpc implementation itself;
302 * also see clnt.h for protocol numbers.
304 __BEGIN_DECLS
305 extern void rpctest_service(void);
306 __END_DECLS
308 __BEGIN_DECLS
309 extern void svc_getreq(int);
310 extern void svc_getreqset(fd_set *);
311 extern void svc_getreq_common(int);
312 struct pollfd;
313 extern void svc_getreq_poll(struct pollfd *, int);
315 extern void svc_run(void);
316 extern void svc_exit(void);
317 __END_DECLS
320 * Socket to use on svcxxx_create call to get default socket
322 #define RPC_ANYSOCK -1
323 #define RPC_ANYFD RPC_ANYSOCK
326 * These are the existing service side transport implementations
329 __BEGIN_DECLS
331 * Transport independent svc_create routine.
333 extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
334 const rpcprog_t, const rpcvers_t, const char *);
336 * void (*dispatch)(); -- dispatch routine
337 * const rpcprog_t prognum; -- program number
338 * const rpcvers_t versnum; -- version number
339 * const char *nettype; -- network type
344 * Generic server creation routine. It takes a netconfig structure
345 * instead of a nettype.
348 extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
349 const rpcprog_t, const rpcvers_t,
350 const struct netconfig *);
352 * void (*dispatch)(); -- dispatch routine
353 * const rpcprog_t prognum; -- program number
354 * const rpcvers_t versnum; -- version number
355 * const struct netconfig *nconf; -- netconfig structure
360 * Generic TLI create routine
362 extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
363 const struct t_bind *, const u_int,
364 const u_int);
366 * const int fd; -- connection end point
367 * const struct netconfig *nconf; -- netconfig structure for network
368 * const struct t_bind *bindaddr; -- local bind address
369 * const u_int sendsz; -- max sendsize
370 * const u_int recvsz; -- max recvsize
374 * Connectionless and connectionful create routines
377 extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
379 * const int fd; -- open connection end point
380 * const u_int sendsize; -- max send size
381 * const u_int recvsize; -- max recv size
385 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
387 extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
389 extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
391 * const int fd; -- open connection
392 * const u_int sendsize; -- max send size
393 * const u_int recvsize; -- max recv size
398 * the routine takes any *open* connection
399 * descriptor as its first input and is used for open connections.
401 extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
403 * const int fd; -- open connection end point
404 * const u_int sendsize; -- max send size
405 * const u_int recvsize; -- max recv size
409 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
411 extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
414 * Memory based rpc (for speed check and testing)
416 extern SVCXPRT *svc_raw_create(void);
419 * svc_dg_enable_cache() enables the cache on dg transports.
421 int svc_dg_enablecache(SVCXPRT *, const u_int);
423 int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
425 __END_DECLS
428 /* for backward compatibility */
429 #include <rpc/svc_soc.h>
431 #endif /* !_RPC_SVC_H */