ReactOS 0.4.16-dev-106-g10b08aa
svc.h
Go to the documentation of this file.
1/* $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $ */
2
3/*
4 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * from: @(#)svc.h 1.35 88/12/17 SMI
31 * from: @(#)svc.h 1.27 94/04/25 SMI
32 * $FreeBSD: src/include/rpc/svc.h,v 1.24 2003/06/15 10:32:01 mbr Exp $
33 */
34
35/*
36 * svc.h, Server-side remote procedure call interface.
37 *
38 * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
39 */
40
41#ifndef _TIRPC_SVC_H
42#define _TIRPC_SVC_H
43//#include <sys/cdefs.h>
44
45/*
46 * This interface must manage two items concerning remote procedure calling:
47 *
48 * 1) An arbitrary number of transport connections upon which rpc requests
49 * are received. The two most notable transports are TCP and UDP; they are
50 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
51 * they in turn call xprt_register and xprt_unregister.
52 *
53 * 2) An arbitrary number of locally registered services. Services are
54 * described by the following four data: program number, version number,
55 * "service dispatch" function, a transport handle, and a boolean that
56 * indicates whether or not the exported program should be registered with a
57 * local binder service; if true the program's number and version and the
58 * port number from the transport handle are registered with the binder.
59 * These data are registered with the rpc svc system via svc_register.
60 *
61 * A service's dispatch function is called whenever an rpc request comes in
62 * on a transport. The request's program and version numbers must match
63 * those of the registered service. The dispatch function is passed two
64 * parameters, struct svc_req * and SVCXPRT *, defined below.
65 */
66
67/*
68 * Service control requests
69 */
70#define SVCGET_VERSQUIET 1
71#define SVCSET_VERSQUIET 2
72#define SVCGET_CONNMAXREC 3
73#define SVCSET_CONNMAXREC 4
74
75/*
76 * Operations for rpc_control().
77 */
78#define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */
79#define RPC_SVC_CONNMAXREC_GET 1
80
85};
86
87/*
88 * Server side transport handle
89 */
90typedef struct __rpc_svcxprt {
92 u_short xp_port; /* associated port number */
93 const struct xp_ops {
94 /* receive incoming requests */
95 bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
96 /* get transport status */
97 enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
98 /* get arguments */
100 void *);
101 /* send reply */
102 bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
103 /* free mem allocated for args */
105 void *);
106 /* destroy this struct */
108 } *xp_ops;
109 int xp_addrlen; /* length of remote address */
110 struct sockaddr_in6 xp_raddr; /* remote addr. (backward ABI compat) */
111 /* XXX - fvdl stick this here for ABI backward compat reasons */
112 const struct xp_ops2 {
113 /* catch-all function */
115 void *);
116 } *xp_ops2;
117 char *xp_tp; /* transport provider device name */
118 char *xp_netid; /* network token */
119 struct netbuf xp_ltaddr; /* local transport address */
120 struct netbuf xp_rtaddr; /* remote transport address */
121 struct opaque_auth xp_verf; /* raw response verifier */
122 SVCAUTH *xp_auth; /* auth handle of current req */
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 */
128
129/*
130 * Service request
131 */
132struct svc_req {
133 /* ORDER: compatibility with legacy RPC */
134 u_int32_t rq_prog; /* service program number */
135 u_int32_t rq_vers; /* service protocol version */
136 u_int32_t rq_proc; /* the desired procedure */
137 struct opaque_auth rq_cred; /* raw creds from the wire */
138 void *rq_clntcred; /* read only cooked cred */
139 SVCXPRT *rq_xprt; /* associated transport */
140
141 /* New with TI-RPC */
142 caddr_t rq_clntname; /* read only client name */
143 caddr_t rq_svcname; /* read only cooked service cred */
144};
145
146/*
147 * Approved way of getting address of caller
148 */
149#define svc_getrpccaller(x) (&(x)->xp_rtaddr)
150
151/*
152 * Operations defined on an SVCXPRT handle
153 *
154 * SVCXPRT *xprt;
155 * struct rpc_msg *msg;
156 * xdrproc_t xargs;
157 * void * argsp;
158 */
159#define SVC_RECV(xprt, msg) \
160 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
161#define svc_recv(xprt, msg) \
162 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
163
164#define SVC_STAT(xprt) \
165 (*(xprt)->xp_ops->xp_stat)(xprt)
166#define svc_stat(xprt) \
167 (*(xprt)->xp_ops->xp_stat)(xprt)
168
169#define SVC_GETARGS(xprt, xargs, argsp) \
170 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
171#define svc_getargs(xprt, xargs, argsp) \
172 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
173
174#define SVC_REPLY(xprt, msg) \
175 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
176#define svc_reply(xprt, msg) \
177 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
178
179#define SVC_FREEARGS(xprt, xargs, argsp) \
180 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
181#define svc_freeargs(xprt, xargs, argsp) \
182 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
183
184#define SVC_DESTROY(xprt) \
185 (*(xprt)->xp_ops->xp_destroy)(xprt)
186#define svc_destroy(xprt) \
187 (*(xprt)->xp_ops->xp_destroy)(xprt)
188
189#define SVC_CONTROL(xprt, rq, in) \
190 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
191
192/*
193 * Service registration
194 *
195 * svc_reg(xprt, prog, vers, dispatch, nconf)
196 * const SVCXPRT *xprt;
197 * const rpcprog_t prog;
198 * const rpcvers_t vers;
199 * const void (*dispatch)();
200 * const struct netconfig *nconf;
201 */
202
204extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
205 void (*)(struct svc_req *, SVCXPRT *),
206 const struct netconfig *);
208
209/*
210 * Service un-registration
211 *
212 * svc_unreg(prog, vers)
213 * const rpcprog_t prog;
214 * const rpcvers_t vers;
215 */
216
218extern void svc_unreg(const rpcprog_t, const rpcvers_t);
220
221/*
222 * Transport registration.
223 *
224 * xprt_register(xprt)
225 * SVCXPRT *xprt;
226 */
228extern void xprt_register(SVCXPRT *);
230
231/*
232 * Transport un-register
233 *
234 * xprt_unregister(xprt)
235 * SVCXPRT *xprt;
236 */
238extern void xprt_unregister(SVCXPRT *);
240
241
242/*
243 * When the service routine is called, it must first check to see if it
244 * knows about the procedure; if not, it should call svcerr_noproc
245 * and return. If so, it should deserialize its arguments via
246 * SVC_GETARGS (defined above). If the deserialization does not work,
247 * svcerr_decode should be called followed by a return. Successful
248 * decoding of the arguments should be followed the execution of the
249 * procedure's code and a call to svc_sendreply.
250 *
251 * Also, if the service refuses to execute the procedure due to too-
252 * weak authentication parameters, svcerr_weakauth should be called.
253 * Note: do not confuse access-control failure with weak authentication!
254 *
255 * NB: In pure implementations of rpc, the caller always waits for a reply
256 * msg. This message is sent when svc_sendreply is called.
257 * Therefore pure service implementations should always call
258 * svc_sendreply even if the function logically returns void; use
259 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
260 * for the abuse of pure rpc via batched calling or pipelining. In the
261 * case of a batched call, svc_sendreply should NOT be called since
262 * this would send a return message, which is what batching tries to avoid.
263 * It is the service/protocol writer's responsibility to know which calls are
264 * batched and which are not. Warning: responding to batch calls may
265 * deadlock the caller and server processes!
266 */
267
269extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
270extern void svcerr_decode(SVCXPRT *);
271extern void svcerr_weakauth(SVCXPRT *);
272extern void svcerr_noproc(SVCXPRT *);
274extern void svcerr_auth(SVCXPRT *, enum auth_stat);
275extern void svcerr_noprog(SVCXPRT *);
276extern void svcerr_systemerr(SVCXPRT *);
278 char *(*)(char *), xdrproc_t, xdrproc_t,
279 char *);
281
282/*
283 * Lowest level dispatching -OR- who owns this process anyway.
284 * Somebody has to wait for incoming requests and then call the correct
285 * service routine. The routine svc_run does infinite waiting; i.e.,
286 * svc_run never returns.
287 * Since another (co-existant) package may wish to selectively wait for
288 * incoming calls or other events outside of the rpc architecture, the
289 * routine svc_getreq is provided. It must be passed readfds, the
290 * "in-place" results of a select system call (see select, section 2).
291 */
292
293/*
294 * Global keeper of rpc service descriptors in use
295 * dynamic; must be inspected before each call to select
296 */
297extern int svc_maxfd;
298#ifdef FD_SETSIZE
299extern fd_set svc_fdset;
300#define svc_fds svc_fdset.fds_bits[0] /* compatibility */
301#else
302extern int svc_fds;
303#endif /* def FD_SETSIZE */
304
305/*
306 * a small program implemented by the svc_rpc implementation itself;
307 * also see clnt.h for protocol numbers.
308 */
310extern void rpctest_service(void);
312
314extern void svc_getreq(int);
315extern void svc_getreqset(fd_set *);
316extern void svc_getreq_common(SOCKET);
317struct pollfd;
318extern void svc_getreq_poll(struct pollfd *, int);
319
320extern void svc_run(void);
321extern void svc_exit(void);
323
324/*
325 * Socket to use on svcxxx_create call to get default socket
326 */
327#define RPC_ANYSOCK INVALID_SOCKET /* -1 */
328#define RPC_ANYFD RPC_ANYSOCK
329
330/*
331 * These are the existing service side transport implementations
332 */
333
335/*
336 * Transport independent svc_create routine.
337 */
338extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
339 const rpcprog_t, const rpcvers_t, const char *);
340/*
341 * void (*dispatch)(); -- dispatch routine
342 * const rpcprog_t prognum; -- program number
343 * const rpcvers_t versnum; -- version number
344 * const char *nettype; -- network type
345 */
346
347
348/*
349 * Generic server creation routine. It takes a netconfig structure
350 * instead of a nettype.
351 */
352
353extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
354 const rpcprog_t, const rpcvers_t,
355 const struct netconfig *);
356 /*
357 * void (*dispatch)(); -- dispatch routine
358 * const rpcprog_t prognum; -- program number
359 * const rpcvers_t versnum; -- version number
360 * const struct netconfig *nconf; -- netconfig structure
361 */
362
363
364/*
365 * Generic TLI create routine
366 */
367extern SVCXPRT *svc_tli_create(const SOCKET, const struct netconfig *,
368 const struct t_bind *, const u_int,
369 const u_int);
370/*
371 * const SOCKET fd; -- connection end point
372 * const struct netconfig *nconf; -- netconfig structure for network
373 * const struct t_bind *bindaddr; -- local bind address
374 * const u_int sendsz; -- max sendsize
375 * const u_int recvsz; -- max recvsize
376 */
377
378/*
379 * Connectionless and connectionful create routines
380 */
381#ifndef __REACTOS__
382extern SVCXPRT *svc_vc_create(const SOCKET, const u_int, const u_int);
383#else
384extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
385#endif
386/*
387 * const SOCKET fd; -- open connection end point
388 * const u_int sendsize; -- max send size
389 * const u_int recvsize; -- max recv size
390 */
391
392/*
393 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
394 */
395extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
396
397#ifndef __REACTOS__
398extern SVCXPRT *svc_dg_create(const SOCKET, const u_int, const u_int);
399#else
400extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
401#endif
402 /*
403 * const SOCKET fd; -- open connection
404 * const u_int sendsize; -- max send size
405 * const u_int recvsize; -- max recv size
406 */
407
408
409/*
410 * the routine takes any *open* connection
411 * descriptor as its first input and is used for open connections.
412 */
413extern SVCXPRT *svc_fd_create(const SOCKET, const u_int, const u_int);
414/*
415 * const SOCKET fd; -- open connection end point
416 * const u_int sendsize; -- max send size
417 * const u_int recvsize; -- max recv size
418 */
419
420/*
421 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
422 */
424
425/*
426 * Memory based rpc (for speed check and testing)
427 */
428extern SVCXPRT *svc_raw_create(void);
429
430/*
431 * svc_dg_enable_cache() enables the cache on dg transports.
432 */
433int svc_dg_enablecache(SVCXPRT *, const u_int);
434
435int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
436
438
439
440/* for backward compatibility */
441#include <rpc/svc_soc.h>
442
443
444
445#endif /* !_TIRPC_SVC_H */
long uid_t
Definition: various.h:8
auth_stat
Definition: auth.h:144
SVCXPRT * svcunix_create(int, u_int, u_int, char *)
__END_DECLS __BEGIN_DECLS void svc_unreg(const rpcprog_t, const rpcvers_t)
void svc_run(void)
Definition: svc_run.c:48
void svcerr_auth(SVCXPRT *, enum auth_stat)
Definition: svc.c:517
__BEGIN_DECLS bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t, void(*)(struct svc_req *, SVCXPRT *), const struct netconfig *)
SVCXPRT * svc_vc_create(const SOCKET, const u_int, const u_int)
void svcerr_weakauth(SVCXPRT *)
Definition: svc.c:536
int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t, char *(*)(char *), xdrproc_t, xdrproc_t, char *)
__END_DECLS __BEGIN_DECLS void svc_getreq(int)
Definition: svc.c:604
SVCXPRT * svc_dg_create(const SOCKET, const u_int, const u_int)
__END_DECLS __BEGIN_DECLS void xprt_unregister(SVCXPRT *)
Definition: svc.c:128
void svcerr_noproc(SVCXPRT *)
Definition: svc.c:421
SVCXPRT * svc_tp_create(void(*)(struct svc_req *, SVCXPRT *), const rpcprog_t, const rpcvers_t, const struct netconfig *)
void svcerr_systemerr(SVCXPRT *)
Definition: svc.c:457
void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t)
Definition: svc.c:567
void svc_exit(void)
Definition: svc_run.c:84
__END_DECLS __BEGIN_DECLS void xprt_register(SVCXPRT *)
Definition: svc.c:97
SVCXPRT * svcunixfd_create(int, u_int, u_int)
xprt_stat
Definition: svc.h:81
@ XPRT_IDLE
Definition: svc.h:84
@ XPRT_DIED
Definition: svc.h:82
@ XPRT_MOREREQS
Definition: svc.h:83
void svcerr_decode(SVCXPRT *)
Definition: svc.c:439
void svc_getreq_poll(struct pollfd *, int)
Definition: svc.c:745
__END_DECLS __BEGIN_DECLS bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *)
Definition: svc.c:399
struct __rpc_svcxprt SVCXPRT
int svc_fds
__BEGIN_DECLS void rpctest_service(void)
void svc_getreq_common(SOCKET)
Definition: svc.c:641
void svcerr_noprog(SVCXPRT *)
Definition: svc.c:549
__END_DECLS int svc_maxfd
void svc_getreqset(fd_set *)
Definition: svc.c:615
SVCXPRT * svc_tli_create(const SOCKET, const struct netconfig *, const struct t_bind *, const u_int, const u_int)
Definition: svc_generic.c:182
__BEGIN_DECLS int svc_create(void(*)(struct svc_req *, SVCXPRT *), const rpcprog_t, const rpcvers_t, const char *)
SVCXPRT * svc_raw_create(void)
Definition: svc_raw.c:76
SVCXPRT * svc_fd_create(const SOCKET, const u_int, const u_int)
Definition: svc_vc.c:204
int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid)
Definition: svc_vc.c:783
int svc_dg_enablecache(SVCXPRT *, const u_int)
Definition: svc_dg.c:386
UINT32 u_int
Definition: types.h:82
u_int32_t rpcprog_t
Definition: types.h:104
int32_t bool_t
Definition: types.h:101
unsigned short u_short
Definition: types.h:81
u_int32_t rpcvers_t
Definition: types.h:105
u_int32_t rpcproc_t
Definition: types.h:106
unsigned int u_int32_t
Definition: rosdhcp.h:35
char * caddr_t
Definition: rosdhcp.h:36
fd_set svc_fdset
bool_t(* xp_control)(struct __rpc_svcxprt *, const u_int, void *)
Definition: svc.h:114
bool_t(* xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *)
Definition: svc.h:95
bool_t(* xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, void *)
Definition: svc.h:99
enum xprt_stat(* xp_stat)(struct __rpc_svcxprt *)
Definition: svc.h:97
void(* xp_destroy)(struct __rpc_svcxprt *)
Definition: svc.h:107
bool_t(* xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *)
Definition: svc.h:102
bool_t(* xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, void *)
Definition: svc.h:104
struct netbuf xp_rtaddr
Definition: svc.h:120
char * xp_netid
Definition: svc.h:118
void * xp_p3
Definition: svc.h:125
u_short xp_port
Definition: svc.h:92
SVCAUTH * xp_auth
Definition: svc.h:122
char * xp_tp
Definition: svc.h:117
struct sockaddr_in6 xp_raddr
Definition: svc.h:110
int xp_type
Definition: svc.h:126
void * xp_p2
Definition: svc.h:124
SOCKET xp_fd
Definition: svc.h:91
struct opaque_auth xp_verf
Definition: svc.h:121
int xp_addrlen
Definition: svc.h:109
struct netbuf xp_ltaddr
Definition: svc.h:119
void * xp_p1
Definition: svc.h:123
Definition: winsock.h:66
Definition: types.h:144
Definition: linux.h:1867
Definition: svc.h:132
u_int32_t rq_prog
Definition: svc.h:134
caddr_t rq_clntname
Definition: svc.h:142
void * rq_clntcred
Definition: svc.h:138
struct opaque_auth rq_cred
Definition: svc.h:137
u_int32_t rq_proc
Definition: svc.h:136
caddr_t rq_svcname
Definition: svc.h:143
SVCXPRT * rq_xprt
Definition: svc.h:139
u_int32_t rq_vers
Definition: svc.h:135
Definition: types.h:155
UINT_PTR SOCKET
Definition: winsock.h:47
#define __END_DECLS
Definition: wintirpc.h:63
#define __BEGIN_DECLS
Definition: wintirpc.h:62
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144