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