1 /* $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2009, Sun Microsystems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * svc.h, Server-side remote procedure call interface.
36 * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
41 #include <sys/cdefs.h>
44 #include <sys/queue.h>
45 #include <sys/_lock.h>
46 #include <sys/_mutex.h>
48 #include <sys/condvar.h>
49 #include <sys/sysctl.h>
53 * This interface must manage two items concerning remote procedure calling:
55 * 1) An arbitrary number of transport connections upon which rpc requests
56 * are received. The two most notable transports are TCP and UDP; they are
57 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
58 * they in turn call xprt_register and xprt_unregister.
60 * 2) An arbitrary number of locally registered services. Services are
61 * described by the following four data: program number, version number,
62 * "service dispatch" function, a transport handle, and a boolean that
63 * indicates whether or not the exported program should be registered with a
64 * local binder service; if true the program's number and version and the
65 * port number from the transport handle are registered with the binder.
66 * These data are registered with the rpc svc system via svc_register.
68 * A service's dispatch function is called whenever an rpc request comes in
69 * on a transport. The request's program and version numbers must match
70 * those of the registered service. The dispatch function is passed two
71 * parameters, struct svc_req * and SVCXPRT *, defined below.
75 * Service control requests
77 #define SVCGET_VERSQUIET 1
78 #define SVCSET_VERSQUIET 2
79 #define SVCGET_CONNMAXREC 3
80 #define SVCSET_CONNMAXREC 4
83 * Operations for rpc_control().
85 #define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */
86 #define RPC_SVC_CONNMAXREC_GET 1
99 /* receive incoming requests */
100 bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *,
101 struct sockaddr **, struct mbuf **);
102 /* get transport status */
103 enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
104 /* get transport acknowledge sequence */
105 bool_t (*xp_ack)(struct __rpc_svcxprt *, uint32_t *);
107 bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *,
108 struct sockaddr *, struct mbuf *, uint32_t *);
109 /* destroy this struct */
110 void (*xp_destroy)(struct __rpc_svcxprt *);
111 /* catch-all function */
112 bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
114 /* receive incoming requests */
115 bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
116 /* get transport status */
117 enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
119 bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
121 bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
122 /* free mem allocated for args */
123 bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
124 /* destroy this struct */
125 void (*xp_destroy)(struct __rpc_svcxprt *);
131 /* catch-all function */
132 bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
137 struct __rpc_svcpool;
138 struct __rpc_svcgroup;
139 struct __rpc_svcthread;
143 * Server side transport handle. In the kernel, transports have a
144 * reference count which tracks the number of currently assigned
145 * worker threads plus one for the service pool's reference.
146 * For NFSv4.1 sessions, a reference is also held for a backchannel.
147 * xp_p2 - Points to the CLIENT structure for the RPC server end
148 * (the client end for callbacks).
149 * Points to the private structure (cl_private) for the
150 * CLIENT structure for the RPC client end (the server
151 * end for callbacks).
153 typedef struct __rpc_svcxprt {
155 volatile u_int xp_refs;
157 struct __rpc_svcpool *xp_pool; /* owning pool (see below) */
158 struct __rpc_svcgroup *xp_group; /* owning group (see below) */
159 TAILQ_ENTRY(__rpc_svcxprt) xp_link;
160 TAILQ_ENTRY(__rpc_svcxprt) xp_alink;
161 bool_t xp_registered; /* xprt_register has been called */
162 bool_t xp_active; /* xprt_active has been called */
163 struct __rpc_svcthread *xp_thread; /* assigned service thread */
164 struct socket* xp_socket;
165 const struct xp_ops *xp_ops;
166 char *xp_netid; /* network token */
167 struct sockaddr_storage xp_ltaddr; /* local transport address */
168 struct sockaddr_storage xp_rtaddr; /* remote transport address */
169 void *xp_p1; /* private: for use by svc ops */
170 void *xp_p2; /* private: for use by svc ops */
171 void *xp_p3; /* private: for use by svc lib */
172 int xp_type; /* transport type */
173 int xp_idletimeout; /* idle time before closing */
174 time_t xp_lastactive; /* time of last RPC */
175 uint64_t xp_sockref; /* set by nfsv4 to identify socket */
176 int xp_upcallset; /* socket upcall is set up */
177 uint32_t xp_snd_cnt; /* # of bytes to send to socket */
178 uint32_t xp_snt_cnt; /* # of bytes sent to socket */
179 bool_t xp_dontrcv; /* Do not receive on the socket */
180 uint32_t xp_tls; /* RPC-over-TLS on socket */
181 uint64_t xp_sslsec; /* Userland SSL * */
183 uint64_t xp_sslrefno;
184 int xp_sslproc; /* Which upcall daemon being used */
185 int xp_ngrps; /* Cred. from TLS cert. */
190 u_short xp_port; /* associated port number */
191 const struct xp_ops *xp_ops;
192 int xp_addrlen; /* length of remote address */
193 struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */
194 /* XXX - fvdl stick this here for ABI backward compat reasons */
195 const struct xp_ops2 *xp_ops2;
196 char *xp_tp; /* transport provider device name */
197 char *xp_netid; /* network token */
198 struct netbuf xp_ltaddr; /* local transport address */
199 struct netbuf xp_rtaddr; /* remote transport address */
200 struct opaque_auth xp_verf; /* raw response verifier */
201 void *xp_p1; /* private: for use by svc ops */
202 void *xp_p2; /* private: for use by svc ops */
203 void *xp_p3; /* private: for use by svc lib */
204 int xp_type; /* transport type */
209 * Interface to server-side authentication flavors.
211 typedef struct __rpc_svcauth {
212 const struct svc_auth_ops {
214 int (*svc_ah_wrap)(struct __rpc_svcauth *, struct mbuf **);
215 int (*svc_ah_unwrap)(struct __rpc_svcauth *, struct mbuf **);
216 void (*svc_ah_release)(struct __rpc_svcauth *);
218 int (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *,
220 int (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *,
224 void *svc_ah_private;
228 * Server transport extensions (accessed via xp_p3).
230 typedef struct __rpc_svcxprt_ext {
231 int xp_flags; /* versquiet */
232 SVCAUTH xp_auth; /* interface to auth methods */
239 * Each entry represents a set of procedures (an rpc program).
240 * The dispatch routine takes request structs and runs the
241 * appropriate procedure.
244 TAILQ_ENTRY(svc_callout) sc_link;
248 void (*sc_dispatch)(struct svc_req *, SVCXPRT *);
250 TAILQ_HEAD(svc_callout_list, svc_callout);
253 * The services connection loss list
254 * The dispatch routine takes request structs and runs the
255 * appropriate procedure.
257 struct svc_loss_callout {
258 TAILQ_ENTRY(svc_loss_callout) slc_link;
259 void (*slc_dispatch)(SVCXPRT *);
261 TAILQ_HEAD(svc_loss_callout_list, svc_loss_callout);
267 STAILQ_ENTRY(svc_req) rq_link; /* list of requests for a thread */
268 struct __rpc_svcthread *rq_thread; /* thread which is to execute this */
269 uint32_t rq_xid; /* RPC transaction ID */
270 uint32_t rq_prog; /* service program number */
271 uint32_t rq_vers; /* service protocol version */
272 uint32_t rq_proc; /* the desired procedure */
273 size_t rq_size; /* space used by request */
274 struct mbuf *rq_args; /* XDR-encoded procedure arguments */
275 struct opaque_auth rq_cred; /* raw creds from the wire */
276 struct opaque_auth rq_verf; /* verifier for the reply */
277 void *rq_clntcred; /* read only cooked cred */
278 SVCAUTH rq_auth; /* interface to auth methods */
279 SVCXPRT *rq_xprt; /* associated transport */
280 struct sockaddr *rq_addr; /* reply address or NULL if connected */
281 void *rq_p1; /* application workspace */
282 int rq_p2; /* application workspace */
283 uint64_t rq_p3; /* application workspace */
284 uint32_t rq_reply_seq; /* reply socket sequence # */
285 char rq_credarea[3*MAX_AUTH_BYTES];
287 STAILQ_HEAD(svc_reqlist, svc_req);
289 #define svc_getrpccaller(rq) \
290 ((rq)->rq_addr ? (rq)->rq_addr : \
291 (struct sockaddr *) &(rq)->rq_xprt->xp_rtaddr)
294 * This structure is used to manage a thread which is executing
295 * requests from a service pool. A service thread is in one of three
298 * SVCTHREAD_SLEEPING waiting for a request to process
299 * SVCTHREAD_ACTIVE processing a request
300 * SVCTHREAD_EXITING exiting after finishing current request
302 * Threads which have no work to process sleep on the pool's sp_active
303 * list. When a transport becomes active, it is assigned a service
304 * thread to read and execute pending RPCs.
306 typedef struct __rpc_svcthread {
307 struct mtx_padalign st_lock; /* protects st_reqs field */
308 struct __rpc_svcpool *st_pool;
309 SVCXPRT *st_xprt; /* transport we are processing */
310 struct svc_reqlist st_reqs; /* RPC requests to execute */
311 struct cv st_cond; /* sleeping for work */
312 LIST_ENTRY(__rpc_svcthread) st_ilink; /* idle threads list */
313 LIST_ENTRY(__rpc_svcthread) st_alink; /* application thread list */
314 int st_p2; /* application workspace */
315 uint64_t st_p3; /* application workspace */
317 LIST_HEAD(svcthread_list, __rpc_svcthread);
320 * A thread group contain all information needed to assign subset of
321 * transports to subset of threads. On systems with many CPUs and many
322 * threads that allows to reduce lock congestion and improve performance.
323 * Hundreds of threads on dozens of CPUs sharing the single pool lock do
324 * not scale well otherwise.
326 TAILQ_HEAD(svcxprt_list, __rpc_svcxprt);
328 SVCPOOL_INIT, /* svc_run not called yet */
329 SVCPOOL_ACTIVE, /* normal running state */
330 SVCPOOL_THREADWANTED, /* new service thread requested */
331 SVCPOOL_THREADSTARTING, /* new service thread started */
332 SVCPOOL_CLOSING /* svc_exit called */
334 typedef struct __rpc_svcgroup {
335 struct mtx_padalign sg_lock; /* protect the thread/req lists */
336 struct __rpc_svcpool *sg_pool;
337 enum svcpool_state sg_state; /* current pool state */
338 struct svcxprt_list sg_xlist; /* all transports in the group */
339 struct svcxprt_list sg_active; /* transports needing service */
340 struct svcthread_list sg_idlethreads; /* idle service threads */
342 int sg_minthreads; /* minimum service thread count */
343 int sg_maxthreads; /* maximum service thread count */
344 int sg_threadcount; /* current service thread count */
345 time_t sg_lastcreatetime; /* when we last started a thread */
346 time_t sg_lastidlecheck; /* when we last checked idle transports */
350 * In the kernel, we can't use global variables to store lists of
351 * transports etc. since otherwise we could not have two unrelated RPC
352 * services running, each on its own thread. We solve this by
353 * importing a tiny part of a Solaris kernel concept, SVCPOOL.
355 * A service pool contains a set of transports and service callbacks
356 * for a set of related RPC services. The pool handle should be passed
357 * when creating new transports etc. Future work may include extending
358 * this to support something similar to the Solaris multi-threaded RPC
361 typedef SVCTHREAD *pool_assign_fn(SVCTHREAD *, struct svc_req *);
362 typedef void pool_done_fn(SVCTHREAD *, struct svc_req *);
363 #define SVC_MAXGROUPS 16
364 typedef struct __rpc_svcpool {
365 struct mtx_padalign sp_lock; /* protect the transport lists */
366 const char *sp_name; /* pool name (e.g. "nfsd", "NLM" */
367 enum svcpool_state sp_state; /* current pool state */
368 struct proc *sp_proc; /* process which is in svc_run */
369 struct svc_callout_list sp_callouts; /* (prog,vers)->dispatch list */
370 struct svc_loss_callout_list sp_lcallouts; /* loss->dispatch list */
371 int sp_minthreads; /* minimum service thread count */
372 int sp_maxthreads; /* maximum service thread count */
375 * Hooks to allow an application to control request to thread
378 pool_assign_fn *sp_assign;
379 pool_done_fn *sp_done;
382 * These variables are used to put an upper bound on the
383 * amount of memory used by RPC requests which are queued
384 * waiting for execution.
386 unsigned long sp_space_low;
387 unsigned long sp_space_high;
388 unsigned long sp_space_used;
389 unsigned long sp_space_used_highest;
390 bool_t sp_space_throttled;
391 int sp_space_throttle_count;
393 struct replay_cache *sp_rcache; /* optional replay cache */
394 struct sysctl_ctx_list sp_sysctl;
396 int sp_groupcount; /* Number of groups in the pool. */
397 int sp_nextgroup; /* Next group to assign port. */
398 SVCGROUP sp_groups[SVC_MAXGROUPS]; /* Thread/port groups. */
407 uint32_t rq_prog; /* service program number */
408 uint32_t rq_vers; /* service protocol version */
409 uint32_t rq_proc; /* the desired procedure */
410 struct opaque_auth rq_cred; /* raw creds from the wire */
411 void *rq_clntcred; /* read only cooked cred */
412 SVCXPRT *rq_xprt; /* associated transport */
416 * Approved way of getting address of caller
418 #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
423 * Operations defined on an SVCXPRT handle
426 * struct rpc_msg *msg;
432 #define SVC_ACQUIRE(xprt) \
433 refcount_acquire(&(xprt)->xp_refs)
435 #define SVC_RELEASE(xprt) \
436 if (refcount_release(&(xprt)->xp_refs)) \
439 #define SVC_RECV(xprt, msg, addr, args) \
440 (*(xprt)->xp_ops->xp_recv)((xprt), (msg), (addr), (args))
442 #define SVC_STAT(xprt) \
443 (*(xprt)->xp_ops->xp_stat)(xprt)
445 #define SVC_ACK(xprt, ack) \
446 ((xprt)->xp_ops->xp_ack == NULL ? FALSE : \
447 ((ack) == NULL ? TRUE : (*(xprt)->xp_ops->xp_ack)((xprt), (ack))))
449 #define SVC_REPLY(xprt, msg, addr, m, seq) \
450 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg), (addr), (m), (seq))
452 #define SVC_DESTROY(xprt) \
453 (*(xprt)->xp_ops->xp_destroy)(xprt)
455 #define SVC_CONTROL(xprt, rq, in) \
456 (*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
460 #define SVC_RECV(xprt, msg) \
461 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
462 #define svc_recv(xprt, msg) \
463 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
465 #define SVC_STAT(xprt) \
466 (*(xprt)->xp_ops->xp_stat)(xprt)
467 #define svc_stat(xprt) \
468 (*(xprt)->xp_ops->xp_stat)(xprt)
470 #define SVC_GETARGS(xprt, xargs, argsp) \
471 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
472 #define svc_getargs(xprt, xargs, argsp) \
473 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
475 #define SVC_REPLY(xprt, msg) \
476 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
477 #define svc_reply(xprt, msg) \
478 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
480 #define SVC_FREEARGS(xprt, xargs, argsp) \
481 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
482 #define svc_freeargs(xprt, xargs, argsp) \
483 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
485 #define SVC_DESTROY(xprt) \
486 (*(xprt)->xp_ops->xp_destroy)(xprt)
487 #define svc_destroy(xprt) \
488 (*(xprt)->xp_ops->xp_destroy)(xprt)
490 #define SVC_CONTROL(xprt, rq, in) \
491 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
495 #define SVC_EXT(xprt) \
496 ((SVCXPRT_EXT *) xprt->xp_p3)
498 #define SVC_AUTH(xprt) \
499 (SVC_EXT(xprt)->xp_auth)
502 * Operations defined on an SVCAUTH handle
505 #define SVCAUTH_WRAP(auth, mp) \
506 ((auth)->svc_ah_ops->svc_ah_wrap(auth, mp))
507 #define SVCAUTH_UNWRAP(auth, mp) \
508 ((auth)->svc_ah_ops->svc_ah_unwrap(auth, mp))
509 #define SVCAUTH_RELEASE(auth) \
510 ((auth)->svc_ah_ops->svc_ah_release(auth))
512 #define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere) \
513 ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere))
514 #define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
515 ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere))
519 * Service registration
521 * svc_reg(xprt, prog, vers, dispatch, nconf)
522 * const SVCXPRT *xprt;
523 * const rpcprog_t prog;
524 * const rpcvers_t vers;
525 * const void (*dispatch)();
526 * const struct netconfig *nconf;
530 extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
531 void (*)(struct svc_req *, SVCXPRT *),
532 const struct netconfig *);
536 * Service un-registration
538 * svc_unreg(prog, vers)
539 * const rpcprog_t prog;
540 * const rpcvers_t vers;
545 extern void svc_unreg(SVCPOOL *, const rpcprog_t, const rpcvers_t);
547 extern void svc_unreg(const rpcprog_t, const rpcvers_t);
553 * Service connection loss registration
555 * svc_loss_reg(xprt, dispatch)
556 * const SVCXPRT *xprt;
557 * const void (*dispatch)();
561 extern bool_t svc_loss_reg(SVCXPRT *, void (*)(SVCXPRT *));
565 * Service connection loss un-registration
567 * svc_loss_unreg(xprt, dispatch)
568 * const SVCXPRT *xprt;
569 * const void (*dispatch)();
573 extern void svc_loss_unreg(SVCPOOL *, void (*)(SVCXPRT *));
578 * Transport registration.
580 * xprt_register(xprt)
584 extern void xprt_register(SVCXPRT *);
588 * Transport un-register
590 * xprt_unregister(xprt)
594 extern void xprt_unregister(SVCXPRT *);
595 extern void __xprt_unregister_unlocked(SVCXPRT *);
601 * Called when a transport has pending requests.
604 extern void xprt_active(SVCXPRT *);
605 extern void xprt_inactive(SVCXPRT *);
606 extern void xprt_inactive_locked(SVCXPRT *);
607 extern void xprt_inactive_self(SVCXPRT *);
613 * When the service routine is called, it must first check to see if it
614 * knows about the procedure; if not, it should call svcerr_noproc
615 * and return. If so, it should deserialize its arguments via
616 * SVC_GETARGS (defined above). If the deserialization does not work,
617 * svcerr_decode should be called followed by a return. Successful
618 * decoding of the arguments should be followed the execution of the
619 * procedure's code and a call to svc_sendreply.
621 * Also, if the service refuses to execute the procedure due to too-
622 * weak authentication parameters, svcerr_weakauth should be called.
623 * Note: do not confuse access-control failure with weak authentication!
625 * NB: In pure implementations of rpc, the caller always waits for a reply
626 * msg. This message is sent when svc_sendreply is called.
627 * Therefore pure service implementations should always call
628 * svc_sendreply even if the function logically returns void; use
629 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
630 * for the abuse of pure rpc via batched calling or pipelining. In the
631 * case of a batched call, svc_sendreply should NOT be called since
632 * this would send a return message, which is what batching tries to avoid.
633 * It is the service/protocol writer's responsibility to know which calls are
634 * batched and which are not. Warning: responding to batch calls may
635 * deadlock the caller and server processes!
640 extern bool_t svc_sendreply(struct svc_req *, xdrproc_t, void *);
641 extern bool_t svc_sendreply_mbuf(struct svc_req *, struct mbuf *);
642 extern void svcerr_decode(struct svc_req *);
643 extern void svcerr_weakauth(struct svc_req *);
644 extern void svcerr_noproc(struct svc_req *);
645 extern void svcerr_progvers(struct svc_req *, rpcvers_t, rpcvers_t);
646 extern void svcerr_auth(struct svc_req *, enum auth_stat);
647 extern void svcerr_noprog(struct svc_req *);
648 extern void svcerr_systemerr(struct svc_req *);
650 extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
651 extern void svcerr_decode(SVCXPRT *);
652 extern void svcerr_weakauth(SVCXPRT *);
653 extern void svcerr_noproc(SVCXPRT *);
654 extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
655 extern void svcerr_auth(SVCXPRT *, enum auth_stat);
656 extern void svcerr_noprog(SVCXPRT *);
657 extern void svcerr_systemerr(SVCXPRT *);
659 extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
660 char *(*)(char *), xdrproc_t, xdrproc_t,
665 * Lowest level dispatching -OR- who owns this process anyway.
666 * Somebody has to wait for incoming requests and then call the correct
667 * service routine. The routine svc_run does infinite waiting; i.e.,
668 * svc_run never returns.
669 * Since another (co-existent) package may wish to selectively wait for
670 * incoming calls or other events outside of the rpc architecture, the
671 * routine svc_getreq is provided. It must be passed readfds, the
672 * "in-place" results of a select system call (see select, section 2).
677 * Global keeper of rpc service descriptors in use
678 * dynamic; must be inspected before each call to select
680 extern int svc_maxfd;
682 extern fd_set svc_fdset;
683 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
686 #endif /* def FD_SETSIZE */
690 * a small program implemented by the svc_rpc implementation itself;
691 * also see clnt.h for protocol numbers.
694 extern void rpctest_service(void);
698 extern SVCXPRT *svc_xprt_alloc(void);
699 extern void svc_xprt_free(SVCXPRT *);
701 extern void svc_getreq(int);
702 extern void svc_getreqset(fd_set *);
703 extern void svc_getreq_common(int);
705 extern void svc_getreq_poll(struct pollfd *, int);
706 extern void svc_run(void);
707 extern void svc_exit(void);
709 extern void svc_run(SVCPOOL *);
710 extern void svc_exit(SVCPOOL *);
711 extern bool_t svc_getargs(struct svc_req *, xdrproc_t, void *);
712 extern bool_t svc_freeargs(struct svc_req *, xdrproc_t, void *);
713 extern void svc_freereq(struct svc_req *);
719 * Socket to use on svcxxx_create call to get default socket
721 #define RPC_ANYSOCK -1
722 #define RPC_ANYFD RPC_ANYSOCK
725 * These are the existing service side transport implementations
733 * Create a new service pool.
735 extern SVCPOOL* svcpool_create(const char *name,
736 struct sysctl_oid_list *sysctl_base);
739 * Destroy a service pool, including all registered transports.
741 extern void svcpool_destroy(SVCPOOL *pool);
744 * Close a service pool. Similar to svcpool_destroy(), but it does not
745 * free the data structures. As such, the pool can be used again.
747 extern void svcpool_close(SVCPOOL *pool);
750 * Transport independent svc_create routine.
752 extern int svc_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
753 const rpcprog_t, const rpcvers_t, const char *);
755 * void (*dispatch)(); -- dispatch routine
756 * const rpcprog_t prognum; -- program number
757 * const rpcvers_t versnum; -- version number
758 * const char *nettype; -- network type
763 * Generic server creation routine. It takes a netconfig structure
764 * instead of a nettype.
767 extern SVCXPRT *svc_tp_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
768 const rpcprog_t, const rpcvers_t, const char *uaddr,
769 const struct netconfig *);
771 * void (*dispatch)(); -- dispatch routine
772 * const rpcprog_t prognum; -- program number
773 * const rpcvers_t versnum; -- version number
774 * const char *uaddr; -- universal address of service
775 * const struct netconfig *nconf; -- netconfig structure
778 extern SVCXPRT *svc_dg_create(SVCPOOL *, struct socket *,
779 const size_t, const size_t);
781 * struct socket *; -- open connection
782 * const size_t sendsize; -- max send size
783 * const size_t recvsize; -- max recv size
786 extern SVCXPRT *svc_vc_create(SVCPOOL *, struct socket *,
787 const size_t, const size_t);
789 * struct socket *; -- open connection
790 * const size_t sendsize; -- max send size
791 * const size_t recvsize; -- max recv size
794 extern SVCXPRT *svc_vc_create_backchannel(SVCPOOL *);
796 extern void *clnt_bck_create(struct socket *, const rpcprog_t, const rpcvers_t);
798 * struct socket *; -- server transport socket
799 * const rpcprog_t prog; -- RPC program number
800 * const rpcvers_t vers; -- RPC program version
804 * Generic TLI create routine
806 extern SVCXPRT *svc_tli_create(SVCPOOL *, struct socket *,
807 const struct netconfig *, const struct t_bind *, const size_t, const size_t);
809 * struct socket * so; -- connection end point
810 * const struct netconfig *nconf; -- netconfig structure for network
811 * const struct t_bind *bindaddr; -- local bind address
812 * const size_t sendsz; -- max sendsize
813 * const size_t recvsz; -- max recvsize
819 * Transport independent svc_create routine.
821 extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
822 const rpcprog_t, const rpcvers_t, const char *);
824 * void (*dispatch)(); -- dispatch routine
825 * const rpcprog_t prognum; -- program number
826 * const rpcvers_t versnum; -- version number
827 * const char *nettype; -- network type
832 * Generic server creation routine. It takes a netconfig structure
833 * instead of a nettype.
836 extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
837 const rpcprog_t, const rpcvers_t,
838 const struct netconfig *);
840 * void (*dispatch)(); -- dispatch routine
841 * const rpcprog_t prognum; -- program number
842 * const rpcvers_t versnum; -- version number
843 * const struct netconfig *nconf; -- netconfig structure
847 * Generic TLI create routine
849 extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
850 const struct t_bind *, const u_int,
853 * const int fd; -- connection end point
854 * const struct netconfig *nconf; -- netconfig structure for network
855 * const struct t_bind *bindaddr; -- local bind address
856 * const u_int sendsz; -- max sendsize
857 * const u_int recvsz; -- max recvsize
861 * Connectionless and connectionful create routines
864 extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
866 * const int fd; -- open connection end point
867 * const u_int sendsize; -- max send size
868 * const u_int recvsize; -- max recv size
872 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
874 extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
876 extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
878 * const int fd; -- open connection
879 * const u_int sendsize; -- max send size
880 * const u_int recvsize; -- max recv size
885 * the routine takes any *open* connection
886 * descriptor as its first input and is used for open connections.
888 extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
890 * const int fd; -- open connection end point
891 * const u_int sendsize; -- max send size
892 * const u_int recvsize; -- max recv size
896 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
898 extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
901 * Memory based rpc (for speed check and testing)
903 extern SVCXPRT *svc_raw_create(void);
906 * svc_dg_enable_cache() enables the cache on dg transports.
908 int svc_dg_enablecache(SVCXPRT *, const u_int);
910 int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
912 #endif /* !_KERNEL */
917 /* for backward compatibility */
918 #include <rpc/svc_soc.h>
921 #endif /* !_RPC_SVC_H */