FreeBSD/Linux Kernel Cross Reference
sys/rpc/svc.h
1 /* $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl 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, MERCHANTABILITY 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 * from: @(#)svc.h 1.27 94/04/25 SMI
33 * $FreeBSD: releng/7.3/sys/rpc/svc.h 192142 2009-05-15 13:58:45Z dfr $
34 */
35
36 /*
37 * svc.h, Server-side remote procedure call interface.
38 *
39 * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
40 */
41
42 #ifndef _RPC_SVC_H
43 #define _RPC_SVC_H
44 #include <sys/cdefs.h>
45
46 #ifdef _KERNEL
47 #include <sys/queue.h>
48 #include <sys/_lock.h>
49 #include <sys/_mutex.h>
50 #include <sys/_sx.h>
51 #endif
52
53 /*
54 * This interface must manage two items concerning remote procedure calling:
55 *
56 * 1) An arbitrary number of transport connections upon which rpc requests
57 * are received. The two most notable transports are TCP and UDP; they are
58 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
59 * they in turn call xprt_register and xprt_unregister.
60 *
61 * 2) An arbitrary number of locally registered services. Services are
62 * described by the following four data: program number, version number,
63 * "service dispatch" function, a transport handle, and a boolean that
64 * indicates whether or not the exported program should be registered with a
65 * local binder service; if true the program's number and version and the
66 * port number from the transport handle are registered with the binder.
67 * These data are registered with the rpc svc system via svc_register.
68 *
69 * A service's dispatch function is called whenever an rpc request comes in
70 * on a transport. The request's program and version numbers must match
71 * those of the registered service. The dispatch function is passed two
72 * parameters, struct svc_req * and SVCXPRT *, defined below.
73 */
74
75 /*
76 * Service control requests
77 */
78 #define SVCGET_VERSQUIET 1
79 #define SVCSET_VERSQUIET 2
80 #define SVCGET_CONNMAXREC 3
81 #define SVCSET_CONNMAXREC 4
82
83 /*
84 * Operations for rpc_control().
85 */
86 #define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */
87 #define RPC_SVC_CONNMAXREC_GET 1
88
89 enum xprt_stat {
90 XPRT_DIED,
91 XPRT_MOREREQS,
92 XPRT_IDLE
93 };
94
95 struct __rpc_svcxprt;
96
97 struct xp_ops {
98 /* receive incoming requests */
99 bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
100 /* get transport status */
101 enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
102 /* get arguments */
103 bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
104 /* send reply */
105 bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
106 /* free mem allocated for args */
107 bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
108 /* destroy this struct */
109 void (*xp_destroy)(struct __rpc_svcxprt *);
110 #ifdef _KERNEL
111 /* catch-all function */
112 bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
113 #endif
114 };
115
116 #ifndef _KERNEL
117 struct xp_ops2 {
118 /* catch-all function */
119 bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
120 };
121 #endif
122
123 #ifdef _KERNEL
124 struct __rpc_svcpool;
125 #endif
126
127 /*
128 * Server side transport handle
129 */
130 typedef struct __rpc_svcxprt {
131 #ifdef _KERNEL
132 struct sx xp_lock;
133 struct __rpc_svcpool *xp_pool; /* owning pool (see below) */
134 TAILQ_ENTRY(__rpc_svcxprt) xp_link;
135 TAILQ_ENTRY(__rpc_svcxprt) xp_alink;
136 bool_t xp_registered; /* xprt_register has been called */
137 bool_t xp_active; /* xprt_active has been called */
138 struct socket* xp_socket;
139 const struct xp_ops *xp_ops;
140 char *xp_netid; /* network token */
141 struct netbuf xp_ltaddr; /* local transport address */
142 struct netbuf xp_rtaddr; /* remote transport address */
143 struct opaque_auth xp_verf; /* raw response verifier */
144 uint32_t xp_xid; /* current transaction ID */
145 XDR xp_xdrreq; /* xdr stream for decoding request */
146 XDR xp_xdrrep; /* xdr stream for encoding reply */
147 void *xp_p1; /* private: for use by svc ops */
148 void *xp_p2; /* private: for use by svc ops */
149 void *xp_p3; /* private: for use by svc lib */
150 int xp_type; /* transport type */
151 #else
152 int xp_fd;
153 u_short xp_port; /* associated port number */
154 const struct xp_ops *xp_ops;
155 int xp_addrlen; /* length of remote address */
156 struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */
157 /* XXX - fvdl stick this here for ABI backward compat reasons */
158 const struct xp_ops2 *xp_ops2;
159 char *xp_tp; /* transport provider device name */
160 char *xp_netid; /* network token */
161 struct netbuf xp_ltaddr; /* local transport address */
162 struct netbuf xp_rtaddr; /* remote transport address */
163 struct opaque_auth xp_verf; /* raw response verifier */
164 void *xp_p1; /* private: for use by svc ops */
165 void *xp_p2; /* private: for use by svc ops */
166 void *xp_p3; /* private: for use by svc lib */
167 int xp_type; /* transport type */
168 #endif
169 } SVCXPRT;
170
171 #ifdef _KERNEL
172
173 /*
174 * The services list
175 * Each entry represents a set of procedures (an rpc program).
176 * The dispatch routine takes request structs and runs the
177 * apropriate procedure.
178 */
179 struct svc_callout {
180 TAILQ_ENTRY(svc_callout) sc_link;
181 rpcprog_t sc_prog;
182 rpcvers_t sc_vers;
183 char *sc_netid;
184 void (*sc_dispatch)(struct svc_req *, SVCXPRT *);
185 };
186 TAILQ_HEAD(svc_callout_list, svc_callout);
187
188 /*
189 * In the kernel, we can't use global variables to store lists of
190 * transports etc. since otherwise we could not have two unrelated RPC
191 * services running, each on its own thread. We solve this by
192 * importing a tiny part of a Solaris kernel concept, SVCPOOL.
193 *
194 * A service pool contains a set of transports and service callbacks
195 * for a set of related RPC services. The pool handle should be passed
196 * when creating new transports etc. Future work may include extending
197 * this to support something similar to the Solaris multi-threaded RPC
198 * server.
199 */
200 TAILQ_HEAD(svcxprt_list, __rpc_svcxprt);
201 typedef struct __rpc_svcpool {
202 struct mtx sp_lock; /* protect the transport lists */
203 struct svcxprt_list sp_xlist; /* all transports in the pool */
204 struct svcxprt_list sp_active; /* transports needing service */
205 struct svc_callout_list sp_callouts; /* (prog,vers)->dispatch list */
206 bool_t sp_exited; /* true if shutting down */
207 } SVCPOOL;
208
209 #endif
210
211 /*
212 * Service request
213 */
214 struct svc_req {
215 uint32_t rq_prog; /* service program number */
216 uint32_t rq_vers; /* service protocol version */
217 uint32_t rq_proc; /* the desired procedure */
218 struct opaque_auth rq_cred; /* raw creds from the wire */
219 void *rq_clntcred; /* read only cooked cred */
220 SVCXPRT *rq_xprt; /* associated transport */
221 };
222
223 /*
224 * Approved way of getting address of caller
225 */
226 #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
227
228 /*
229 * Operations defined on an SVCXPRT handle
230 *
231 * SVCXPRT *xprt;
232 * struct rpc_msg *msg;
233 * xdrproc_t xargs;
234 * void * argsp;
235 */
236 #define SVC_RECV(xprt, msg) \
237 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
238 #define svc_recv(xprt, msg) \
239 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
240
241 #define SVC_STAT(xprt) \
242 (*(xprt)->xp_ops->xp_stat)(xprt)
243 #define svc_stat(xprt) \
244 (*(xprt)->xp_ops->xp_stat)(xprt)
245
246 #define SVC_GETARGS(xprt, xargs, argsp) \
247 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
248 #define svc_getargs(xprt, xargs, argsp) \
249 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
250
251 #define SVC_REPLY(xprt, msg) \
252 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
253 #define svc_reply(xprt, msg) \
254 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
255
256 #define SVC_FREEARGS(xprt, xargs, argsp) \
257 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
258 #define svc_freeargs(xprt, xargs, argsp) \
259 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
260
261 #define SVC_DESTROY(xprt) \
262 (*(xprt)->xp_ops->xp_destroy)(xprt)
263 #define svc_destroy(xprt) \
264 (*(xprt)->xp_ops->xp_destroy)(xprt)
265
266 #ifdef _KERNEL
267 #define SVC_CONTROL(xprt, rq, in) \
268 (*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
269 #else
270 #define SVC_CONTROL(xprt, rq, in) \
271 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
272 #endif
273
274 /*
275 * Service registration
276 *
277 * svc_reg(xprt, prog, vers, dispatch, nconf)
278 * const SVCXPRT *xprt;
279 * const rpcprog_t prog;
280 * const rpcvers_t vers;
281 * const void (*dispatch)();
282 * const struct netconfig *nconf;
283 */
284
285 __BEGIN_DECLS
286 extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
287 void (*)(struct svc_req *, SVCXPRT *),
288 const struct netconfig *);
289 __END_DECLS
290
291 /*
292 * Service un-registration
293 *
294 * svc_unreg(prog, vers)
295 * const rpcprog_t prog;
296 * const rpcvers_t vers;
297 */
298
299 __BEGIN_DECLS
300 #ifdef _KERNEL
301 extern void svc_unreg(SVCPOOL *, const rpcprog_t, const rpcvers_t);
302 #else
303 extern void svc_unreg(const rpcprog_t, const rpcvers_t);
304 #endif
305 __END_DECLS
306
307 /*
308 * Transport registration.
309 *
310 * xprt_register(xprt)
311 * SVCXPRT *xprt;
312 */
313 __BEGIN_DECLS
314 extern void xprt_register(SVCXPRT *);
315 __END_DECLS
316
317 /*
318 * Transport un-register
319 *
320 * xprt_unregister(xprt)
321 * SVCXPRT *xprt;
322 */
323 __BEGIN_DECLS
324 extern void xprt_unregister(SVCXPRT *);
325 extern void __xprt_unregister_unlocked(SVCXPRT *);
326 __END_DECLS
327
328 #ifdef _KERNEL
329
330 /*
331 * Called when a transport has pending requests.
332 */
333 __BEGIN_DECLS
334 extern void xprt_active(SVCXPRT *);
335 extern void xprt_inactive(SVCXPRT *);
336 extern void xprt_inactive_locked(SVCXPRT *);
337 __END_DECLS
338
339 #endif
340
341 /*
342 * When the service routine is called, it must first check to see if it
343 * knows about the procedure; if not, it should call svcerr_noproc
344 * and return. If so, it should deserialize its arguments via
345 * SVC_GETARGS (defined above). If the deserialization does not work,
346 * svcerr_decode should be called followed by a return. Successful
347 * decoding of the arguments should be followed the execution of the
348 * procedure's code and a call to svc_sendreply.
349 *
350 * Also, if the service refuses to execute the procedure due to too-
351 * weak authentication parameters, svcerr_weakauth should be called.
352 * Note: do not confuse access-control failure with weak authentication!
353 *
354 * NB: In pure implementations of rpc, the caller always waits for a reply
355 * msg. This message is sent when svc_sendreply is called.
356 * Therefore pure service implementations should always call
357 * svc_sendreply even if the function logically returns void; use
358 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
359 * for the abuse of pure rpc via batched calling or pipelining. In the
360 * case of a batched call, svc_sendreply should NOT be called since
361 * this would send a return message, which is what batching tries to avoid.
362 * It is the service/protocol writer's responsibility to know which calls are
363 * batched and which are not. Warning: responding to batch calls may
364 * deadlock the caller and server processes!
365 */
366
367 __BEGIN_DECLS
368 extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
369 extern void svcerr_decode(SVCXPRT *);
370 extern void svcerr_weakauth(SVCXPRT *);
371 extern void svcerr_noproc(SVCXPRT *);
372 extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
373 extern void svcerr_auth(SVCXPRT *, enum auth_stat);
374 extern void svcerr_noprog(SVCXPRT *);
375 extern void svcerr_systemerr(SVCXPRT *);
376 extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
377 char *(*)(char *), xdrproc_t, xdrproc_t,
378 char *);
379 __END_DECLS
380
381 /*
382 * Lowest level dispatching -OR- who owns this process anyway.
383 * Somebody has to wait for incoming requests and then call the correct
384 * service routine. The routine svc_run does infinite waiting; i.e.,
385 * svc_run never returns.
386 * Since another (co-existant) package may wish to selectively wait for
387 * incoming calls or other events outside of the rpc architecture, the
388 * routine svc_getreq is provided. It must be passed readfds, the
389 * "in-place" results of a select system call (see select, section 2).
390 */
391
392 #ifndef _KERNEL
393 /*
394 * Global keeper of rpc service descriptors in use
395 * dynamic; must be inspected before each call to select
396 */
397 extern int svc_maxfd;
398 #ifdef FD_SETSIZE
399 extern fd_set svc_fdset;
400 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
401 #else
402 extern int svc_fds;
403 #endif /* def FD_SETSIZE */
404 #endif
405
406 /*
407 * a small program implemented by the svc_rpc implementation itself;
408 * also see clnt.h for protocol numbers.
409 */
410 __BEGIN_DECLS
411 extern void rpctest_service(void);
412 __END_DECLS
413
414 __BEGIN_DECLS
415 #ifndef _KERNEL
416 extern void svc_getreq(int);
417 extern void svc_getreqset(fd_set *);
418 extern void svc_getreq_common(int);
419 struct pollfd;
420 extern void svc_getreq_poll(struct pollfd *, int);
421 extern void svc_run(void);
422 extern void svc_exit(void);
423 #else
424 extern void svc_run(SVCPOOL *);
425 extern void svc_exit(SVCPOOL *);
426 #endif
427 __END_DECLS
428
429 /*
430 * Socket to use on svcxxx_create call to get default socket
431 */
432 #define RPC_ANYSOCK -1
433 #define RPC_ANYFD RPC_ANYSOCK
434
435 /*
436 * These are the existing service side transport implementations
437 */
438
439 __BEGIN_DECLS
440
441 #ifdef _KERNEL
442
443 /*
444 * Create a new service pool.
445 */
446 extern SVCPOOL* svcpool_create(void);
447
448 /*
449 * Destroy a service pool, including all registered transports.
450 */
451 extern void svcpool_destroy(SVCPOOL *pool);
452
453 /*
454 * Transport independent svc_create routine.
455 */
456 extern int svc_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
457 const rpcprog_t, const rpcvers_t, const char *);
458 /*
459 * void (*dispatch)(); -- dispatch routine
460 * const rpcprog_t prognum; -- program number
461 * const rpcvers_t versnum; -- version number
462 * const char *nettype; -- network type
463 */
464
465
466 /*
467 * Generic server creation routine. It takes a netconfig structure
468 * instead of a nettype.
469 */
470
471 extern SVCXPRT *svc_tp_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
472 const rpcprog_t, const rpcvers_t, const char *uaddr,
473 const struct netconfig *);
474 /*
475 * void (*dispatch)(); -- dispatch routine
476 * const rpcprog_t prognum; -- program number
477 * const rpcvers_t versnum; -- version number
478 * const char *uaddr; -- universal address of service
479 * const struct netconfig *nconf; -- netconfig structure
480 */
481
482 extern SVCXPRT *svc_dg_create(SVCPOOL *, struct socket *,
483 const size_t, const size_t);
484 /*
485 * struct socket *; -- open connection
486 * const size_t sendsize; -- max send size
487 * const size_t recvsize; -- max recv size
488 */
489
490 extern SVCXPRT *svc_vc_create(SVCPOOL *, struct socket *,
491 const size_t, const size_t);
492 /*
493 * struct socket *; -- open connection
494 * const size_t sendsize; -- max send size
495 * const size_t recvsize; -- max recv size
496 */
497
498 /*
499 * Generic TLI create routine
500 */
501 extern SVCXPRT *svc_tli_create(SVCPOOL *, struct socket *,
502 const struct netconfig *, const struct t_bind *, const size_t, const size_t);
503 /*
504 * struct socket * so; -- connection end point
505 * const struct netconfig *nconf; -- netconfig structure for network
506 * const struct t_bind *bindaddr; -- local bind address
507 * const size_t sendsz; -- max sendsize
508 * const size_t recvsz; -- max recvsize
509 */
510
511 #else /* !_KERNEL */
512
513 /*
514 * Transport independent svc_create routine.
515 */
516 extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
517 const rpcprog_t, const rpcvers_t, const char *);
518 /*
519 * void (*dispatch)(); -- dispatch routine
520 * const rpcprog_t prognum; -- program number
521 * const rpcvers_t versnum; -- version number
522 * const char *nettype; -- network type
523 */
524
525
526 /*
527 * Generic server creation routine. It takes a netconfig structure
528 * instead of a nettype.
529 */
530
531 extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
532 const rpcprog_t, const rpcvers_t,
533 const struct netconfig *);
534 /*
535 * void (*dispatch)(); -- dispatch routine
536 * const rpcprog_t prognum; -- program number
537 * const rpcvers_t versnum; -- version number
538 * const struct netconfig *nconf; -- netconfig structure
539 */
540
541 /*
542 * Generic TLI create routine
543 */
544 extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
545 const struct t_bind *, const u_int,
546 const u_int);
547 /*
548 * const int fd; -- connection end point
549 * const struct netconfig *nconf; -- netconfig structure for network
550 * const struct t_bind *bindaddr; -- local bind address
551 * const u_int sendsz; -- max sendsize
552 * const u_int recvsz; -- max recvsize
553 */
554
555 /*
556 * Connectionless and connectionful create routines
557 */
558
559 extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
560 /*
561 * const int fd; -- open connection end point
562 * const u_int sendsize; -- max send size
563 * const u_int recvsize; -- max recv size
564 */
565
566 /*
567 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
568 */
569 extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
570
571 extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
572 /*
573 * const int fd; -- open connection
574 * const u_int sendsize; -- max send size
575 * const u_int recvsize; -- max recv size
576 */
577
578
579 /*
580 * the routine takes any *open* connection
581 * descriptor as its first input and is used for open connections.
582 */
583 extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
584 /*
585 * const int fd; -- open connection end point
586 * const u_int sendsize; -- max send size
587 * const u_int recvsize; -- max recv size
588 */
589
590 /*
591 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
592 */
593 extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
594
595 /*
596 * Memory based rpc (for speed check and testing)
597 */
598 extern SVCXPRT *svc_raw_create(void);
599
600 /*
601 * svc_dg_enable_cache() enables the cache on dg transports.
602 */
603 int svc_dg_enablecache(SVCXPRT *, const u_int);
604
605 int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
606
607 #endif /* !_KERNEL */
608
609 __END_DECLS
610
611 #ifndef _KERNEL
612 /* for backward compatibility */
613 #include <rpc/svc_soc.h>
614 #endif
615
616 #endif /* !_RPC_SVC_H */
Cache object: dba2626d1f079eb5c476e256aa7c2263
|