svc.h revision 1.26 1 1.26 christos /* $NetBSD: svc.h,v 1.26 2015/11/06 19:35:40 christos Exp $ */
2 1.4 cgd
3 1.1 deraadt /*
4 1.1 deraadt * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 1.1 deraadt * unrestricted use provided that this legend is included on all tape
6 1.1 deraadt * media and as a part of the software program in whole or part. Users
7 1.1 deraadt * may copy or modify Sun RPC without charge, but are not authorized
8 1.1 deraadt * to license or distribute it to anyone else except as part of a product or
9 1.1 deraadt * program developed by the user.
10 1.19 simonb *
11 1.1 deraadt * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 1.1 deraadt * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 1.1 deraadt * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 1.19 simonb *
15 1.1 deraadt * Sun RPC is provided with no support and without any obligation on the
16 1.1 deraadt * part of Sun Microsystems, Inc. to assist in its use, correction,
17 1.1 deraadt * modification or enhancement.
18 1.19 simonb *
19 1.1 deraadt * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 1.1 deraadt * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 1.1 deraadt * OR ANY PART THEREOF.
22 1.19 simonb *
23 1.1 deraadt * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 1.1 deraadt * or profits or other special, indirect and consequential damages, even if
25 1.1 deraadt * Sun has been advised of the possibility of such damages.
26 1.19 simonb *
27 1.1 deraadt * Sun Microsystems, Inc.
28 1.1 deraadt * 2550 Garcia Avenue
29 1.1 deraadt * Mountain View, California 94043
30 1.3 mycroft *
31 1.17 fvdl * from: @(#)svc.h 1.35 88/12/17 SMI
32 1.17 fvdl * @(#)svc.h 1.27 94/04/25 SMI
33 1.1 deraadt */
34 1.1 deraadt
35 1.1 deraadt /*
36 1.1 deraadt * svc.h, Server-side remote procedure call interface.
37 1.1 deraadt *
38 1.17 fvdl * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
39 1.1 deraadt */
40 1.1 deraadt
41 1.11 perry #ifndef _RPC_SVC_H_
42 1.11 perry #define _RPC_SVC_H_
43 1.2 brezak #include <sys/cdefs.h>
44 1.1 deraadt
45 1.20 fvdl #include <rpc/rpc_com.h>
46 1.20 fvdl
47 1.1 deraadt /*
48 1.1 deraadt * This interface must manage two items concerning remote procedure calling:
49 1.1 deraadt *
50 1.13 lukem * 1) An arbitrary number of transport connections upon which rpc requests
51 1.1 deraadt * are received. The two most notable transports are TCP and UDP; they are
52 1.1 deraadt * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
53 1.1 deraadt * they in turn call xprt_register and xprt_unregister.
54 1.1 deraadt *
55 1.1 deraadt * 2) An arbitrary number of locally registered services. Services are
56 1.1 deraadt * described by the following four data: program number, version number,
57 1.1 deraadt * "service dispatch" function, a transport handle, and a boolean that
58 1.1 deraadt * indicates whether or not the exported program should be registered with a
59 1.1 deraadt * local binder service; if true the program's number and version and the
60 1.1 deraadt * port number from the transport handle are registered with the binder.
61 1.13 lukem * These data are registered with the rpc svc system via svc_register.
62 1.1 deraadt *
63 1.13 lukem * A service's dispatch function is called whenever an rpc request comes in
64 1.1 deraadt * on a transport. The request's program and version numbers must match
65 1.1 deraadt * those of the registered service. The dispatch function is passed two
66 1.1 deraadt * parameters, struct svc_req * and SVCXPRT *, defined below.
67 1.1 deraadt */
68 1.1 deraadt
69 1.17 fvdl /*
70 1.19 simonb * Service control requests
71 1.17 fvdl */
72 1.17 fvdl #define SVCGET_VERSQUIET 1
73 1.17 fvdl #define SVCSET_VERSQUIET 2
74 1.20 fvdl #define SVCGET_CONNMAXREC 3
75 1.20 fvdl #define SVCSET_CONNMAXREC 4
76 1.17 fvdl
77 1.17 fvdl
78 1.1 deraadt enum xprt_stat {
79 1.1 deraadt XPRT_DIED,
80 1.1 deraadt XPRT_MOREREQS,
81 1.1 deraadt XPRT_IDLE
82 1.1 deraadt };
83 1.1 deraadt
84 1.1 deraadt /*
85 1.1 deraadt * Server side transport handle
86 1.1 deraadt */
87 1.5 cgd typedef struct __rpc_svcxprt {
88 1.17 fvdl int xp_fd;
89 1.13 lukem u_short xp_port; /* associated port number */
90 1.14 mycroft const struct xp_ops {
91 1.5 cgd /* receive incomming requests */
92 1.21 perry bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
93 1.5 cgd /* get transport status */
94 1.21 perry enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
95 1.5 cgd /* get arguments */
96 1.21 perry bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
97 1.21 perry caddr_t);
98 1.5 cgd /* send reply */
99 1.21 perry bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
100 1.5 cgd /* free mem allocated for args */
101 1.21 perry bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
102 1.21 perry caddr_t);
103 1.5 cgd /* destroy this struct */
104 1.21 perry void (*xp_destroy)(struct __rpc_svcxprt *);
105 1.1 deraadt } *xp_ops;
106 1.13 lukem int xp_addrlen; /* length of remote address */
107 1.17 fvdl struct sockaddr_in xp_raddr; /* rem. addr. (backward ABI compat) */
108 1.17 fvdl /* XXX - fvdl stick this here for ABI backward compat reasons */
109 1.17 fvdl const struct xp_ops2 {
110 1.17 fvdl /* catch-all function */
111 1.21 perry bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int,
112 1.21 perry void *);
113 1.17 fvdl } *xp_ops2;
114 1.17 fvdl char *xp_tp; /* transport provider device name */
115 1.17 fvdl char *xp_netid; /* network token */
116 1.17 fvdl struct netbuf xp_ltaddr; /* local transport address */
117 1.17 fvdl struct netbuf xp_rtaddr; /* remote transport address */
118 1.13 lukem struct opaque_auth xp_verf; /* raw response verifier */
119 1.17 fvdl void *xp_p1; /* private: for use by svc ops */
120 1.17 fvdl void *xp_p2; /* private: for use by svc ops */
121 1.17 fvdl void *xp_p3; /* private: for use by svc lib */
122 1.17 fvdl int xp_type; /* transport type */
123 1.1 deraadt } SVCXPRT;
124 1.1 deraadt
125 1.1 deraadt /*
126 1.17 fvdl * Service request
127 1.17 fvdl */
128 1.17 fvdl struct svc_req {
129 1.23 perry uint32_t rq_prog; /* service program number */
130 1.23 perry uint32_t rq_vers; /* service protocol version */
131 1.23 perry uint32_t rq_proc; /* the desired procedure */
132 1.17 fvdl struct opaque_auth rq_cred; /* raw creds from the wire */
133 1.17 fvdl void *rq_clntcred; /* read only cooked cred */
134 1.17 fvdl SVCXPRT *rq_xprt; /* associated transport */
135 1.17 fvdl };
136 1.17 fvdl
137 1.17 fvdl /*
138 1.19 simonb * Approved way of getting address of caller
139 1.1 deraadt */
140 1.17 fvdl #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
141 1.17 fvdl
142 1.17 fvdl /*
143 1.17 fvdl * NetBSD-only definition to get the creds of the caller (AF_LOCAL).
144 1.17 fvdl */
145 1.17 fvdl #define __svc_getcallercreds(x) ((struct sockcred *)(x)->xp_p2)
146 1.1 deraadt
147 1.1 deraadt /*
148 1.1 deraadt * Operations defined on an SVCXPRT handle
149 1.1 deraadt *
150 1.1 deraadt * SVCXPRT *xprt;
151 1.1 deraadt * struct rpc_msg *msg;
152 1.1 deraadt * xdrproc_t xargs;
153 1.1 deraadt * caddr_t argsp;
154 1.1 deraadt */
155 1.1 deraadt #define SVC_RECV(xprt, msg) \
156 1.1 deraadt (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
157 1.1 deraadt #define svc_recv(xprt, msg) \
158 1.1 deraadt (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
159 1.1 deraadt
160 1.1 deraadt #define SVC_STAT(xprt) \
161 1.1 deraadt (*(xprt)->xp_ops->xp_stat)(xprt)
162 1.1 deraadt #define svc_stat(xprt) \
163 1.1 deraadt (*(xprt)->xp_ops->xp_stat)(xprt)
164 1.1 deraadt
165 1.1 deraadt #define SVC_GETARGS(xprt, xargs, argsp) \
166 1.24 plunky (*(xprt)->xp_ops->xp_getargs)((xprt), ((xdrproc_t)(xargs)), (argsp))
167 1.1 deraadt #define svc_getargs(xprt, xargs, argsp) \
168 1.24 plunky (*(xprt)->xp_ops->xp_getargs)((xprt), ((xdrproc_t)(xargs)), (argsp))
169 1.1 deraadt
170 1.1 deraadt #define SVC_REPLY(xprt, msg) \
171 1.1 deraadt (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
172 1.1 deraadt #define svc_reply(xprt, msg) \
173 1.1 deraadt (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
174 1.1 deraadt
175 1.1 deraadt #define SVC_FREEARGS(xprt, xargs, argsp) \
176 1.24 plunky (*(xprt)->xp_ops->xp_freeargs)((xprt), ((xdrproc_t)(xargs)), (argsp))
177 1.1 deraadt #define svc_freeargs(xprt, xargs, argsp) \
178 1.24 plunky (*(xprt)->xp_ops->xp_freeargs)((xprt), ((xdrproc_t)(xargs)), (argsp))
179 1.1 deraadt
180 1.1 deraadt #define SVC_DESTROY(xprt) \
181 1.1 deraadt (*(xprt)->xp_ops->xp_destroy)(xprt)
182 1.1 deraadt #define svc_destroy(xprt) \
183 1.1 deraadt (*(xprt)->xp_ops->xp_destroy)(xprt)
184 1.1 deraadt
185 1.17 fvdl #define SVC_CONTROL(xprt, rq, in) \
186 1.17 fvdl (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
187 1.1 deraadt
188 1.1 deraadt /*
189 1.1 deraadt * Service registration
190 1.1 deraadt *
191 1.17 fvdl * svc_reg(xprt, prog, vers, dispatch, nconf)
192 1.17 fvdl * const SVCXPRT *xprt;
193 1.17 fvdl * const rpcprog_t prog;
194 1.17 fvdl * const rpcvers_t vers;
195 1.19 simonb * const void (*dispatch)(...);
196 1.17 fvdl * const struct netconfig *nconf;
197 1.1 deraadt */
198 1.17 fvdl
199 1.2 brezak __BEGIN_DECLS
200 1.21 perry extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
201 1.21 perry void (*)(struct svc_req *, SVCXPRT *),
202 1.21 perry const struct netconfig *);
203 1.2 brezak __END_DECLS
204 1.1 deraadt
205 1.1 deraadt /*
206 1.1 deraadt * Service un-registration
207 1.1 deraadt *
208 1.17 fvdl * svc_unreg(prog, vers)
209 1.17 fvdl * const rpcprog_t prog;
210 1.17 fvdl * const rpcvers_t vers;
211 1.1 deraadt */
212 1.17 fvdl
213 1.2 brezak __BEGIN_DECLS
214 1.21 perry extern void svc_unreg(const rpcprog_t, const rpcvers_t);
215 1.2 brezak __END_DECLS
216 1.1 deraadt
217 1.1 deraadt /*
218 1.1 deraadt * Transport registration.
219 1.1 deraadt *
220 1.1 deraadt * xprt_register(xprt)
221 1.1 deraadt * SVCXPRT *xprt;
222 1.1 deraadt */
223 1.2 brezak __BEGIN_DECLS
224 1.25 christos extern bool_t xprt_register (SVCXPRT *);
225 1.2 brezak __END_DECLS
226 1.1 deraadt
227 1.1 deraadt /*
228 1.1 deraadt * Transport un-register
229 1.1 deraadt *
230 1.1 deraadt * xprt_unregister(xprt)
231 1.1 deraadt * SVCXPRT *xprt;
232 1.1 deraadt */
233 1.2 brezak __BEGIN_DECLS
234 1.21 perry extern void xprt_unregister (SVCXPRT *);
235 1.2 brezak __END_DECLS
236 1.1 deraadt
237 1.1 deraadt
238 1.1 deraadt /*
239 1.1 deraadt * When the service routine is called, it must first check to see if it
240 1.1 deraadt * knows about the procedure; if not, it should call svcerr_noproc
241 1.19 simonb * and return. If so, it should deserialize its arguments via
242 1.1 deraadt * SVC_GETARGS (defined above). If the deserialization does not work,
243 1.1 deraadt * svcerr_decode should be called followed by a return. Successful
244 1.1 deraadt * decoding of the arguments should be followed the execution of the
245 1.1 deraadt * procedure's code and a call to svc_sendreply.
246 1.1 deraadt *
247 1.1 deraadt * Also, if the service refuses to execute the procedure due to too-
248 1.1 deraadt * weak authentication parameters, svcerr_weakauth should be called.
249 1.1 deraadt * Note: do not confuse access-control failure with weak authentication!
250 1.1 deraadt *
251 1.13 lukem * NB: In pure implementations of rpc, the caller always waits for a reply
252 1.19 simonb * msg. This message is sent when svc_sendreply is called.
253 1.1 deraadt * Therefore pure service implementations should always call
254 1.1 deraadt * svc_sendreply even if the function logically returns void; use
255 1.13 lukem * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
256 1.13 lukem * for the abuse of pure rpc via batched calling or pipelining. In the
257 1.1 deraadt * case of a batched call, svc_sendreply should NOT be called since
258 1.1 deraadt * this would send a return message, which is what batching tries to avoid.
259 1.1 deraadt * It is the service/protocol writer's responsibility to know which calls are
260 1.1 deraadt * batched and which are not. Warning: responding to batch calls may
261 1.1 deraadt * deadlock the caller and server processes!
262 1.1 deraadt */
263 1.1 deraadt
264 1.2 brezak __BEGIN_DECLS
265 1.22 yamt extern bool_t svc_sendreply (SVCXPRT *, xdrproc_t, const char *);
266 1.21 perry extern void svcerr_decode (SVCXPRT *);
267 1.21 perry extern void svcerr_weakauth (SVCXPRT *);
268 1.21 perry extern void svcerr_noproc (SVCXPRT *);
269 1.21 perry extern void svcerr_progvers (SVCXPRT *, rpcvers_t, rpcvers_t);
270 1.21 perry extern void svcerr_auth (SVCXPRT *, enum auth_stat);
271 1.21 perry extern void svcerr_noprog (SVCXPRT *);
272 1.21 perry extern void svcerr_systemerr(SVCXPRT *);
273 1.21 perry extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
274 1.21 perry char *(*)(char *), xdrproc_t, xdrproc_t,
275 1.21 perry char *);
276 1.2 brezak __END_DECLS
277 1.19 simonb
278 1.1 deraadt /*
279 1.1 deraadt * Lowest level dispatching -OR- who owns this process anyway.
280 1.1 deraadt * Somebody has to wait for incoming requests and then call the correct
281 1.1 deraadt * service routine. The routine svc_run does infinite waiting; i.e.,
282 1.1 deraadt * svc_run never returns.
283 1.18 wiz * Since another (co-existent) package may wish to selectively wait for
284 1.13 lukem * incoming calls or other events outside of the rpc architecture, the
285 1.1 deraadt * routine svc_getreq is provided. It must be passed readfds, the
286 1.1 deraadt * "in-place" results of a select system call (see select, section 2).
287 1.1 deraadt */
288 1.1 deraadt
289 1.1 deraadt /*
290 1.13 lukem * Global keeper of rpc service descriptors in use
291 1.19 simonb * dynamic; must be inspected before each call to select
292 1.1 deraadt */
293 1.8 pk extern int svc_maxfd;
294 1.13 lukem #ifdef FD_SETSIZE
295 1.1 deraadt extern fd_set svc_fdset;
296 1.1 deraadt #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
297 1.13 lukem #else
298 1.13 lukem extern int svc_fds;
299 1.13 lukem #endif /* def FD_SETSIZE */
300 1.1 deraadt
301 1.26 christos
302 1.1 deraadt /*
303 1.1 deraadt * a small program implemented by the svc_rpc implementation itself;
304 1.1 deraadt * also see clnt.h for protocol numbers.
305 1.1 deraadt */
306 1.16 christos __BEGIN_DECLS
307 1.21 perry extern void rpctest_service(void);
308 1.16 christos __END_DECLS
309 1.1 deraadt
310 1.2 brezak __BEGIN_DECLS
311 1.26 christos
312 1.26 christos #define SVC_FDSET_MT 1
313 1.26 christos extern void svc_fdset_init(int);
314 1.26 christos extern fd_set *svc_fdset_copy(const fd_set *);
315 1.26 christos
316 1.26 christos extern void svc_fdset_zero(void);
317 1.26 christos extern int svc_fdset_isset(int);
318 1.26 christos extern void svc_fdset_clr(int);
319 1.26 christos extern void svc_fdset_set(int);
320 1.26 christos
321 1.26 christos extern fd_set *svc_fdset_get(void);
322 1.26 christos extern int svc_fdset_getsize(int);
323 1.26 christos extern int *svc_fdset_getmax(void);
324 1.26 christos
325 1.21 perry extern void svc_getreq (int);
326 1.21 perry extern void svc_getreqset (fd_set *);
327 1.26 christos extern void svc_getreqset2 (fd_set *, int);
328 1.21 perry extern void svc_getreq_common (int);
329 1.17 fvdl struct pollfd;
330 1.21 perry extern void svc_getreq_poll(struct pollfd *, int);
331 1.17 fvdl
332 1.21 perry extern void svc_run (void);
333 1.21 perry extern void svc_exit (void);
334 1.2 brezak __END_DECLS
335 1.1 deraadt
336 1.1 deraadt /*
337 1.1 deraadt * Socket to use on svcxxx_create call to get default socket
338 1.1 deraadt */
339 1.1 deraadt #define RPC_ANYSOCK -1
340 1.17 fvdl #define RPC_ANYFD RPC_ANYSOCK
341 1.1 deraadt
342 1.1 deraadt /*
343 1.1 deraadt * These are the existing service side transport implementations
344 1.1 deraadt */
345 1.1 deraadt
346 1.17 fvdl __BEGIN_DECLS
347 1.17 fvdl /*
348 1.17 fvdl * Transport independent svc_create routine.
349 1.17 fvdl */
350 1.21 perry extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
351 1.21 perry const rpcprog_t, const rpcvers_t, const char *);
352 1.17 fvdl /*
353 1.19 simonb * void (*dispatch)(...); -- dispatch routine
354 1.19 simonb * const rpcprog_t prognum; -- program number
355 1.19 simonb * const rpcvers_t versnum; -- version number
356 1.19 simonb * const char *nettype; -- network type
357 1.17 fvdl */
358 1.17 fvdl
359 1.17 fvdl
360 1.1 deraadt /*
361 1.17 fvdl * Generic server creation routine. It takes a netconfig structure
362 1.17 fvdl * instead of a nettype.
363 1.17 fvdl */
364 1.17 fvdl
365 1.21 perry extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
366 1.17 fvdl const rpcprog_t, const rpcvers_t,
367 1.21 perry const struct netconfig *);
368 1.19 simonb /*
369 1.19 simonb * void (*dispatch)(...); -- dispatch routine
370 1.19 simonb * const rpcprog_t prognum; -- program number
371 1.19 simonb * const rpcvers_t versnum; -- version number
372 1.19 simonb * const struct netconfig *nconf; -- netconfig structure
373 1.19 simonb */
374 1.17 fvdl
375 1.17 fvdl
376 1.17 fvdl /*
377 1.17 fvdl * Generic TLI create routine
378 1.17 fvdl */
379 1.21 perry extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
380 1.17 fvdl const struct t_bind *, const u_int,
381 1.21 perry const u_int);
382 1.17 fvdl /*
383 1.19 simonb * const int fd; -- connection end point
384 1.19 simonb * const struct netconfig *nconf; -- netconfig structure for network
385 1.19 simonb * const struct t_bind *bindaddr; -- local bind address
386 1.19 simonb * const u_int sendsz; -- max sendsize
387 1.19 simonb * const u_int recvsz; -- max recvsize
388 1.1 deraadt */
389 1.1 deraadt
390 1.17 fvdl /*
391 1.17 fvdl * Connectionless and connectionful create routines
392 1.17 fvdl */
393 1.2 brezak
394 1.21 perry extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
395 1.1 deraadt /*
396 1.19 simonb * const int fd; -- open connection end point
397 1.19 simonb * const u_int sendsize; -- max send size
398 1.19 simonb * const u_int recvsize; -- max recv size
399 1.1 deraadt */
400 1.17 fvdl
401 1.21 perry extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
402 1.19 simonb /*
403 1.19 simonb * const int fd; -- open connection
404 1.19 simonb * const u_int sendsize; -- max send size
405 1.19 simonb * const u_int recvsize; -- max recv size
406 1.19 simonb */
407 1.2 brezak
408 1.1 deraadt
409 1.1 deraadt /*
410 1.17 fvdl * the routine takes any *open* connection
411 1.17 fvdl * descriptor as its first input and is used for open connections.
412 1.17 fvdl */
413 1.21 perry extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
414 1.17 fvdl /*
415 1.19 simonb * const int fd; -- open connection end point
416 1.19 simonb * const u_int sendsize; -- max send size
417 1.19 simonb * const u_int recvsize; -- max recv size
418 1.1 deraadt */
419 1.6 cgd
420 1.6 cgd /*
421 1.17 fvdl * Memory based rpc (for speed check and testing)
422 1.17 fvdl */
423 1.21 perry extern SVCXPRT *svc_raw_create(void);
424 1.17 fvdl
425 1.17 fvdl /*
426 1.17 fvdl * svc_dg_enable_cache() enables the cache on dg transports.
427 1.6 cgd */
428 1.21 perry int svc_dg_enablecache(SVCXPRT *, const u_int);
429 1.17 fvdl
430 1.2 brezak __END_DECLS
431 1.17 fvdl
432 1.17 fvdl
433 1.17 fvdl /* for backward compatibility */
434 1.17 fvdl #include <rpc/svc_soc.h>
435 1.1 deraadt
436 1.11 perry #endif /* !_RPC_SVC_H_ */
437