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