xref: /freebsd/sys/rpc/svc.h (revision cbd30a72ca196976c1c700400ecd424baa1b9c16)
1 /*	$NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $	*/
2 
3 /*-
4  * Copyright (c) 2009, Sun Microsystems, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * - Redistributions of source code must retain the above copyright notice,
10  *   this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  * - Neither the name of Sun Microsystems, Inc. nor the names of its
15  *   contributors may be used to endorse or promote products derived
16  *   from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  *	from: @(#)svc.h 1.35 88/12/17 SMI
31  *	from: @(#)svc.h      1.27    94/04/25 SMI
32  * $FreeBSD$
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 #ifdef _KERNEL
46 #include <sys/queue.h>
47 #include <sys/_lock.h>
48 #include <sys/_mutex.h>
49 #include <sys/_sx.h>
50 #include <sys/condvar.h>
51 #include <sys/sysctl.h>
52 #endif
53 
54 /*
55  * This interface must manage two items concerning remote procedure calling:
56  *
57  * 1) An arbitrary number of transport connections upon which rpc requests
58  * are received.  The two most notable transports are TCP and UDP;  they are
59  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
60  * they in turn call xprt_register and xprt_unregister.
61  *
62  * 2) An arbitrary number of locally registered services.  Services are
63  * described by the following four data: program number, version number,
64  * "service dispatch" function, a transport handle, and a boolean that
65  * indicates whether or not the exported program should be registered with a
66  * local binder service;  if true the program's number and version and the
67  * port number from the transport handle are registered with the binder.
68  * These data are registered with the rpc svc system via svc_register.
69  *
70  * A service's dispatch function is called whenever an rpc request comes in
71  * on a transport.  The request's program and version numbers must match
72  * those of the registered service.  The dispatch function is passed two
73  * parameters, struct svc_req * and SVCXPRT *, defined below.
74  */
75 
76 /*
77  *      Service control requests
78  */
79 #define SVCGET_VERSQUIET	1
80 #define SVCSET_VERSQUIET	2
81 #define SVCGET_CONNMAXREC	3
82 #define SVCSET_CONNMAXREC	4
83 
84 /*
85  * Operations for rpc_control().
86  */
87 #define RPC_SVC_CONNMAXREC_SET  0	/* set max rec size, enable nonblock */
88 #define RPC_SVC_CONNMAXREC_GET  1
89 
90 enum xprt_stat {
91 	XPRT_DIED,
92 	XPRT_MOREREQS,
93 	XPRT_IDLE
94 };
95 
96 struct __rpc_svcxprt;
97 struct mbuf;
98 
99 struct xp_ops {
100 #ifdef _KERNEL
101 	/* receive incoming requests */
102 	bool_t	(*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *,
103 	    struct sockaddr **, struct mbuf **);
104 	/* get transport status */
105 	enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
106 	/* get transport acknowledge sequence */
107 	bool_t (*xp_ack)(struct __rpc_svcxprt *, uint32_t *);
108 	/* send reply */
109 	bool_t	(*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *,
110 	    struct sockaddr *, struct mbuf *, uint32_t *);
111 	/* destroy this struct */
112 	void	(*xp_destroy)(struct __rpc_svcxprt *);
113 	/* catch-all function */
114 	bool_t  (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
115 #else
116 	/* receive incoming requests */
117 	bool_t	(*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
118 	/* get transport status */
119 	enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
120 	/* get arguments */
121 	bool_t	(*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
122 	/* send reply */
123 	bool_t	(*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
124 	/* free mem allocated for args */
125 	bool_t	(*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
126 	/* destroy this struct */
127 	void	(*xp_destroy)(struct __rpc_svcxprt *);
128 #endif
129 };
130 
131 #ifndef _KERNEL
132 struct xp_ops2 {
133 	/* catch-all function */
134 	bool_t  (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
135 };
136 #endif
137 
138 #ifdef _KERNEL
139 struct __rpc_svcpool;
140 struct __rpc_svcgroup;
141 struct __rpc_svcthread;
142 #endif
143 
144 /*
145  * Server side transport handle. In the kernel, transports have a
146  * reference count which tracks the number of currently assigned
147  * worker threads plus one for the service pool's reference.
148  * For NFSv4.1 sessions, a reference is also held for a backchannel.
149  */
150 typedef struct __rpc_svcxprt {
151 #ifdef _KERNEL
152 	volatile u_int	xp_refs;
153 	struct sx	xp_lock;
154 	struct __rpc_svcpool *xp_pool;  /* owning pool (see below) */
155 	struct __rpc_svcgroup *xp_group; /* owning group (see below) */
156 	TAILQ_ENTRY(__rpc_svcxprt) xp_link;
157 	TAILQ_ENTRY(__rpc_svcxprt) xp_alink;
158 	bool_t		xp_registered;	/* xprt_register has been called */
159 	bool_t		xp_active;	/* xprt_active has been called */
160 	struct __rpc_svcthread *xp_thread; /* assigned service thread */
161 	struct socket*	xp_socket;
162 	const struct xp_ops *xp_ops;
163 	char		*xp_netid;	/* network token */
164 	struct sockaddr_storage xp_ltaddr; /* local transport address */
165 	struct sockaddr_storage	xp_rtaddr; /* remote transport address */
166 	void		*xp_p1;		/* private: for use by svc ops */
167 	void		*xp_p2;		/* private: for use by svc ops */
168 	void		*xp_p3;		/* private: for use by svc lib */
169 	int		xp_type;	/* transport type */
170 	int		xp_idletimeout; /* idle time before closing */
171 	time_t		xp_lastactive;	/* time of last RPC */
172 	u_int64_t	xp_sockref;	/* set by nfsv4 to identify socket */
173 	int		xp_upcallset;	/* socket upcall is set up */
174 	uint32_t	xp_snd_cnt;	/* # of bytes to send to socket */
175 	uint32_t	xp_snt_cnt;	/* # of bytes sent to socket */
176 #else
177 	int		xp_fd;
178 	u_short		xp_port;	 /* associated port number */
179 	const struct xp_ops *xp_ops;
180 	int		xp_addrlen;	 /* length of remote address */
181 	struct sockaddr_in xp_raddr;	 /* remote addr. (backward ABI compat) */
182 	/* XXX - fvdl stick this here for ABI backward compat reasons */
183 	const struct xp_ops2 *xp_ops2;
184 	char		*xp_tp;		 /* transport provider device name */
185 	char		*xp_netid;	 /* network token */
186 	struct netbuf	xp_ltaddr;	 /* local transport address */
187 	struct netbuf	xp_rtaddr;	 /* remote transport address */
188 	struct opaque_auth xp_verf;	 /* raw response verifier */
189 	void		*xp_p1;		 /* private: for use by svc ops */
190 	void		*xp_p2;		 /* private: for use by svc ops */
191 	void		*xp_p3;		 /* private: for use by svc lib */
192 	int		xp_type;	 /* transport type */
193 #endif
194 } SVCXPRT;
195 
196 /*
197  * Interface to server-side authentication flavors.
198  */
199 typedef struct __rpc_svcauth {
200 	struct svc_auth_ops {
201 #ifdef _KERNEL
202 		int   (*svc_ah_wrap)(struct __rpc_svcauth *,  struct mbuf **);
203 		int   (*svc_ah_unwrap)(struct __rpc_svcauth *, struct mbuf **);
204 		void  (*svc_ah_release)(struct __rpc_svcauth *);
205 #else
206 		int   (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *,
207 		    xdrproc_t, caddr_t);
208 		int   (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *,
209 		    xdrproc_t, caddr_t);
210 #endif
211 	} *svc_ah_ops;
212 	void *svc_ah_private;
213 } SVCAUTH;
214 
215 /*
216  * Server transport extensions (accessed via xp_p3).
217  */
218 typedef struct __rpc_svcxprt_ext {
219 	int		xp_flags;	/* versquiet */
220 	SVCAUTH		xp_auth;	/* interface to auth methods */
221 } SVCXPRT_EXT;
222 
223 #ifdef _KERNEL
224 
225 /*
226  * The services list
227  * Each entry represents a set of procedures (an rpc program).
228  * The dispatch routine takes request structs and runs the
229  * appropriate procedure.
230  */
231 struct svc_callout {
232 	TAILQ_ENTRY(svc_callout) sc_link;
233 	rpcprog_t	    sc_prog;
234 	rpcvers_t	    sc_vers;
235 	char		   *sc_netid;
236 	void		    (*sc_dispatch)(struct svc_req *, SVCXPRT *);
237 };
238 TAILQ_HEAD(svc_callout_list, svc_callout);
239 
240 /*
241  * The services connection loss list
242  * The dispatch routine takes request structs and runs the
243  * appropriate procedure.
244  */
245 struct svc_loss_callout {
246 	TAILQ_ENTRY(svc_loss_callout) slc_link;
247 	void		    (*slc_dispatch)(SVCXPRT *);
248 };
249 TAILQ_HEAD(svc_loss_callout_list, svc_loss_callout);
250 
251 /*
252  * Service request
253  */
254 struct svc_req {
255 	STAILQ_ENTRY(svc_req) rq_link;	/* list of requests for a thread */
256 	struct __rpc_svcthread *rq_thread; /* thread which is to execute this */
257 	uint32_t	rq_xid;		/* RPC transaction ID */
258 	uint32_t	rq_prog;	/* service program number */
259 	uint32_t	rq_vers;	/* service protocol version */
260 	uint32_t	rq_proc;	/* the desired procedure */
261 	size_t		rq_size;	/* space used by request */
262 	struct mbuf	*rq_args;	/* XDR-encoded procedure arguments */
263 	struct opaque_auth rq_cred;	/* raw creds from the wire */
264 	struct opaque_auth rq_verf;	/* verifier for the reply */
265 	void		*rq_clntcred;	/* read only cooked cred */
266 	SVCAUTH		rq_auth;	/* interface to auth methods */
267 	SVCXPRT		*rq_xprt;	/* associated transport */
268 	struct sockaddr	*rq_addr;	/* reply address or NULL if connected */
269 	void		*rq_p1;		/* application workspace */
270 	int		rq_p2;		/* application workspace */
271 	uint64_t	rq_p3;		/* application workspace */
272 	uint32_t	rq_reply_seq;	/* reply socket sequence # */
273 	char		rq_credarea[3*MAX_AUTH_BYTES];
274 };
275 STAILQ_HEAD(svc_reqlist, svc_req);
276 
277 #define svc_getrpccaller(rq)					\
278 	((rq)->rq_addr ? (rq)->rq_addr :			\
279 	    (struct sockaddr *) &(rq)->rq_xprt->xp_rtaddr)
280 
281 /*
282  * This structure is used to manage a thread which is executing
283  * requests from a service pool. A service thread is in one of three
284  * states:
285  *
286  *	SVCTHREAD_SLEEPING	waiting for a request to process
287  *	SVCTHREAD_ACTIVE	processing a request
288  *	SVCTHREAD_EXITING	exiting after finishing current request
289  *
290  * Threads which have no work to process sleep on the pool's sp_active
291  * list. When a transport becomes active, it is assigned a service
292  * thread to read and execute pending RPCs.
293  */
294 typedef struct __rpc_svcthread {
295 	struct mtx_padalign	st_lock; /* protects st_reqs field */
296 	struct __rpc_svcpool	*st_pool;
297 	SVCXPRT			*st_xprt; /* transport we are processing */
298 	struct svc_reqlist	st_reqs;  /* RPC requests to execute */
299 	struct cv		st_cond; /* sleeping for work */
300 	LIST_ENTRY(__rpc_svcthread) st_ilink; /* idle threads list */
301 	LIST_ENTRY(__rpc_svcthread) st_alink; /* application thread list */
302 	int		st_p2;		/* application workspace */
303 	uint64_t	st_p3;		/* application workspace */
304 } SVCTHREAD;
305 LIST_HEAD(svcthread_list, __rpc_svcthread);
306 
307 /*
308  * A thread group contain all information needed to assign subset of
309  * transports to subset of threads.  On systems with many CPUs and many
310  * threads that allows to reduce lock congestion and improve performance.
311  * Hundreds of threads on dozens of CPUs sharing the single pool lock do
312  * not scale well otherwise.
313  */
314 TAILQ_HEAD(svcxprt_list, __rpc_svcxprt);
315 enum svcpool_state {
316 	SVCPOOL_INIT,		/* svc_run not called yet */
317 	SVCPOOL_ACTIVE,		/* normal running state */
318 	SVCPOOL_THREADWANTED,	/* new service thread requested */
319 	SVCPOOL_THREADSTARTING,	/* new service thread started */
320 	SVCPOOL_CLOSING		/* svc_exit called */
321 };
322 typedef struct __rpc_svcgroup {
323 	struct mtx_padalign sg_lock;	/* protect the thread/req lists */
324 	struct __rpc_svcpool	*sg_pool;
325 	enum svcpool_state sg_state;	/* current pool state */
326 	struct svcxprt_list sg_xlist;	/* all transports in the group */
327 	struct svcxprt_list sg_active;	/* transports needing service */
328 	struct svcthread_list sg_idlethreads; /* idle service threads */
329 
330 	int		sg_minthreads;	/* minimum service thread count */
331 	int		sg_maxthreads;	/* maximum service thread count */
332 	int		sg_threadcount; /* current service thread count */
333 	time_t		sg_lastcreatetime; /* when we last started a thread */
334 	time_t		sg_lastidlecheck;  /* when we last checked idle transports */
335 } SVCGROUP;
336 
337 /*
338  * In the kernel, we can't use global variables to store lists of
339  * transports etc. since otherwise we could not have two unrelated RPC
340  * services running, each on its own thread. We solve this by
341  * importing a tiny part of a Solaris kernel concept, SVCPOOL.
342  *
343  * A service pool contains a set of transports and service callbacks
344  * for a set of related RPC services. The pool handle should be passed
345  * when creating new transports etc. Future work may include extending
346  * this to support something similar to the Solaris multi-threaded RPC
347  * server.
348  */
349 typedef SVCTHREAD *pool_assign_fn(SVCTHREAD *, struct svc_req *);
350 typedef void pool_done_fn(SVCTHREAD *, struct svc_req *);
351 #define	SVC_MAXGROUPS	16
352 typedef struct __rpc_svcpool {
353 	struct mtx_padalign sp_lock;	/* protect the transport lists */
354 	const char	*sp_name;	/* pool name (e.g. "nfsd", "NLM" */
355 	enum svcpool_state sp_state;	/* current pool state */
356 	struct proc	*sp_proc;	/* process which is in svc_run */
357 	struct svc_callout_list sp_callouts; /* (prog,vers)->dispatch list */
358 	struct svc_loss_callout_list sp_lcallouts; /* loss->dispatch list */
359 	int		sp_minthreads;	/* minimum service thread count */
360 	int		sp_maxthreads;	/* maximum service thread count */
361 
362 	/*
363 	 * Hooks to allow an application to control request to thread
364 	 * placement.
365 	 */
366 	pool_assign_fn	*sp_assign;
367 	pool_done_fn	*sp_done;
368 
369 	/*
370 	 * These variables are used to put an upper bound on the
371 	 * amount of memory used by RPC requests which are queued
372 	 * waiting for execution.
373 	 */
374 	unsigned long	sp_space_low;
375 	unsigned long	sp_space_high;
376 	unsigned long	sp_space_used;
377 	unsigned long	sp_space_used_highest;
378 	bool_t		sp_space_throttled;
379 	int		sp_space_throttle_count;
380 
381 	struct replay_cache *sp_rcache; /* optional replay cache */
382 	struct sysctl_ctx_list sp_sysctl;
383 
384 	int		sp_groupcount;	/* Number of groups in the pool. */
385 	int		sp_nextgroup;	/* Next group to assign port. */
386 	SVCGROUP	sp_groups[SVC_MAXGROUPS]; /* Thread/port groups. */
387 } SVCPOOL;
388 
389 #else
390 
391 /*
392  * Service request
393  */
394 struct svc_req {
395 	uint32_t	rq_prog;	/* service program number */
396 	uint32_t	rq_vers;	/* service protocol version */
397 	uint32_t	rq_proc;	/* the desired procedure */
398 	struct opaque_auth rq_cred;	/* raw creds from the wire */
399 	void		*rq_clntcred;	/* read only cooked cred */
400 	SVCXPRT		*rq_xprt;	/* associated transport */
401 };
402 
403 /*
404  *  Approved way of getting address of caller
405  */
406 #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
407 
408 #endif
409 
410 /*
411  * Operations defined on an SVCXPRT handle
412  *
413  * SVCXPRT		*xprt;
414  * struct rpc_msg	*msg;
415  * xdrproc_t		 xargs;
416  * void *		 argsp;
417  */
418 #ifdef _KERNEL
419 
420 #define SVC_ACQUIRE(xprt)			\
421 	refcount_acquire(&(xprt)->xp_refs)
422 
423 #define SVC_RELEASE(xprt)			\
424 	if (refcount_release(&(xprt)->xp_refs))	\
425 		SVC_DESTROY(xprt)
426 
427 #define SVC_RECV(xprt, msg, addr, args)			\
428 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg), (addr), (args))
429 
430 #define SVC_STAT(xprt)					\
431 	(*(xprt)->xp_ops->xp_stat)(xprt)
432 
433 #define SVC_ACK(xprt, ack)				\
434 	((xprt)->xp_ops->xp_ack == NULL ? FALSE :	\
435 	    ((ack) == NULL ? TRUE : (*(xprt)->xp_ops->xp_ack)((xprt), (ack))))
436 
437 #define SVC_REPLY(xprt, msg, addr, m, seq)			\
438 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg), (addr), (m), (seq))
439 
440 #define SVC_DESTROY(xprt)				\
441 	(*(xprt)->xp_ops->xp_destroy)(xprt)
442 
443 #define SVC_CONTROL(xprt, rq, in)			\
444 	(*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
445 
446 #else
447 
448 #define SVC_RECV(xprt, msg)				\
449 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
450 #define svc_recv(xprt, msg)				\
451 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
452 
453 #define SVC_STAT(xprt)					\
454 	(*(xprt)->xp_ops->xp_stat)(xprt)
455 #define svc_stat(xprt)					\
456 	(*(xprt)->xp_ops->xp_stat)(xprt)
457 
458 #define SVC_GETARGS(xprt, xargs, argsp)			\
459 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
460 #define svc_getargs(xprt, xargs, argsp)			\
461 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
462 
463 #define SVC_REPLY(xprt, msg)				\
464 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
465 #define svc_reply(xprt, msg)				\
466 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
467 
468 #define SVC_FREEARGS(xprt, xargs, argsp)		\
469 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
470 #define svc_freeargs(xprt, xargs, argsp)		\
471 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
472 
473 #define SVC_DESTROY(xprt)				\
474 	(*(xprt)->xp_ops->xp_destroy)(xprt)
475 #define svc_destroy(xprt)				\
476 	(*(xprt)->xp_ops->xp_destroy)(xprt)
477 
478 #define SVC_CONTROL(xprt, rq, in)			\
479 	(*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
480 
481 #endif
482 
483 #define SVC_EXT(xprt)					\
484 	((SVCXPRT_EXT *) xprt->xp_p3)
485 
486 #define SVC_AUTH(xprt)					\
487 	(SVC_EXT(xprt)->xp_auth)
488 
489 /*
490  * Operations defined on an SVCAUTH handle
491  */
492 #ifdef _KERNEL
493 #define SVCAUTH_WRAP(auth, mp)		\
494 	((auth)->svc_ah_ops->svc_ah_wrap(auth, mp))
495 #define SVCAUTH_UNWRAP(auth, mp)	\
496 	((auth)->svc_ah_ops->svc_ah_unwrap(auth, mp))
497 #define SVCAUTH_RELEASE(auth)	\
498 	((auth)->svc_ah_ops->svc_ah_release(auth))
499 #else
500 #define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere)		\
501 	((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere))
502 #define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere)	\
503 	((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere))
504 #endif
505 
506 /*
507  * Service registration
508  *
509  * svc_reg(xprt, prog, vers, dispatch, nconf)
510  *	const SVCXPRT *xprt;
511  *	const rpcprog_t prog;
512  *	const rpcvers_t vers;
513  *	const void (*dispatch)();
514  *	const struct netconfig *nconf;
515  */
516 
517 __BEGIN_DECLS
518 extern bool_t	svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
519 			void (*)(struct svc_req *, SVCXPRT *),
520 			const struct netconfig *);
521 __END_DECLS
522 
523 /*
524  * Service un-registration
525  *
526  * svc_unreg(prog, vers)
527  *	const rpcprog_t prog;
528  *	const rpcvers_t vers;
529  */
530 
531 __BEGIN_DECLS
532 #ifdef _KERNEL
533 extern void	svc_unreg(SVCPOOL *, const rpcprog_t, const rpcvers_t);
534 #else
535 extern void	svc_unreg(const rpcprog_t, const rpcvers_t);
536 #endif
537 __END_DECLS
538 
539 #ifdef _KERNEL
540 /*
541  * Service connection loss registration
542  *
543  * svc_loss_reg(xprt, dispatch)
544  *	const SVCXPRT *xprt;
545  *	const void (*dispatch)();
546  */
547 
548 __BEGIN_DECLS
549 extern bool_t	svc_loss_reg(SVCXPRT *, void (*)(SVCXPRT *));
550 __END_DECLS
551 
552 /*
553  * Service connection loss un-registration
554  *
555  * svc_loss_unreg(xprt, dispatch)
556  *	const SVCXPRT *xprt;
557  *	const void (*dispatch)();
558  */
559 
560 __BEGIN_DECLS
561 extern void	svc_loss_unreg(SVCPOOL *, void (*)(SVCXPRT *));
562 __END_DECLS
563 #endif
564 
565 /*
566  * Transport registration.
567  *
568  * xprt_register(xprt)
569  *	SVCXPRT *xprt;
570  */
571 __BEGIN_DECLS
572 extern void	xprt_register(SVCXPRT *);
573 __END_DECLS
574 
575 /*
576  * Transport un-register
577  *
578  * xprt_unregister(xprt)
579  *	SVCXPRT *xprt;
580  */
581 __BEGIN_DECLS
582 extern void	xprt_unregister(SVCXPRT *);
583 extern void	__xprt_unregister_unlocked(SVCXPRT *);
584 __END_DECLS
585 
586 #ifdef _KERNEL
587 
588 /*
589  * Called when a transport has pending requests.
590  */
591 __BEGIN_DECLS
592 extern void	xprt_active(SVCXPRT *);
593 extern void	xprt_inactive(SVCXPRT *);
594 extern void	xprt_inactive_locked(SVCXPRT *);
595 extern void	xprt_inactive_self(SVCXPRT *);
596 __END_DECLS
597 
598 #endif
599 
600 /*
601  * When the service routine is called, it must first check to see if it
602  * knows about the procedure;  if not, it should call svcerr_noproc
603  * and return.  If so, it should deserialize its arguments via
604  * SVC_GETARGS (defined above).  If the deserialization does not work,
605  * svcerr_decode should be called followed by a return.  Successful
606  * decoding of the arguments should be followed the execution of the
607  * procedure's code and a call to svc_sendreply.
608  *
609  * Also, if the service refuses to execute the procedure due to too-
610  * weak authentication parameters, svcerr_weakauth should be called.
611  * Note: do not confuse access-control failure with weak authentication!
612  *
613  * NB: In pure implementations of rpc, the caller always waits for a reply
614  * msg.  This message is sent when svc_sendreply is called.
615  * Therefore pure service implementations should always call
616  * svc_sendreply even if the function logically returns void;  use
617  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
618  * for the abuse of pure rpc via batched calling or pipelining.  In the
619  * case of a batched call, svc_sendreply should NOT be called since
620  * this would send a return message, which is what batching tries to avoid.
621  * It is the service/protocol writer's responsibility to know which calls are
622  * batched and which are not.  Warning: responding to batch calls may
623  * deadlock the caller and server processes!
624  */
625 
626 __BEGIN_DECLS
627 #ifdef _KERNEL
628 extern bool_t	svc_sendreply(struct svc_req *, xdrproc_t, void *);
629 extern bool_t	svc_sendreply_mbuf(struct svc_req *, struct mbuf *);
630 extern void	svcerr_decode(struct svc_req *);
631 extern void	svcerr_weakauth(struct svc_req *);
632 extern void	svcerr_noproc(struct svc_req *);
633 extern void	svcerr_progvers(struct svc_req *, rpcvers_t, rpcvers_t);
634 extern void	svcerr_auth(struct svc_req *, enum auth_stat);
635 extern void	svcerr_noprog(struct svc_req *);
636 extern void	svcerr_systemerr(struct svc_req *);
637 #else
638 extern bool_t	svc_sendreply(SVCXPRT *, xdrproc_t, void *);
639 extern void	svcerr_decode(SVCXPRT *);
640 extern void	svcerr_weakauth(SVCXPRT *);
641 extern void	svcerr_noproc(SVCXPRT *);
642 extern void	svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
643 extern void	svcerr_auth(SVCXPRT *, enum auth_stat);
644 extern void	svcerr_noprog(SVCXPRT *);
645 extern void	svcerr_systemerr(SVCXPRT *);
646 #endif
647 extern int	rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
648 			char *(*)(char *), xdrproc_t, xdrproc_t,
649 			char *);
650 __END_DECLS
651 
652 /*
653  * Lowest level dispatching -OR- who owns this process anyway.
654  * Somebody has to wait for incoming requests and then call the correct
655  * service routine.  The routine svc_run does infinite waiting; i.e.,
656  * svc_run never returns.
657  * Since another (co-existant) package may wish to selectively wait for
658  * incoming calls or other events outside of the rpc architecture, the
659  * routine svc_getreq is provided.  It must be passed readfds, the
660  * "in-place" results of a select system call (see select, section 2).
661  */
662 
663 #ifndef _KERNEL
664 /*
665  * Global keeper of rpc service descriptors in use
666  * dynamic; must be inspected before each call to select
667  */
668 extern int svc_maxfd;
669 #ifdef FD_SETSIZE
670 extern fd_set svc_fdset;
671 #define svc_fds svc_fdset.fds_bits[0]	/* compatibility */
672 #else
673 extern int svc_fds;
674 #endif /* def FD_SETSIZE */
675 #endif
676 
677 /*
678  * a small program implemented by the svc_rpc implementation itself;
679  * also see clnt.h for protocol numbers.
680  */
681 __BEGIN_DECLS
682 extern void rpctest_service(void);
683 __END_DECLS
684 
685 __BEGIN_DECLS
686 extern SVCXPRT *svc_xprt_alloc(void);
687 extern void	svc_xprt_free(SVCXPRT *);
688 #ifndef _KERNEL
689 extern void	svc_getreq(int);
690 extern void	svc_getreqset(fd_set *);
691 extern void	svc_getreq_common(int);
692 struct pollfd;
693 extern void	svc_getreq_poll(struct pollfd *, int);
694 extern void	svc_run(void);
695 extern void	svc_exit(void);
696 #else
697 extern void	svc_run(SVCPOOL *);
698 extern void	svc_exit(SVCPOOL *);
699 extern bool_t	svc_getargs(struct svc_req *, xdrproc_t, void *);
700 extern bool_t	svc_freeargs(struct svc_req *, xdrproc_t, void *);
701 extern void	svc_freereq(struct svc_req *);
702 
703 #endif
704 __END_DECLS
705 
706 /*
707  * Socket to use on svcxxx_create call to get default socket
708  */
709 #define	RPC_ANYSOCK	-1
710 #define RPC_ANYFD	RPC_ANYSOCK
711 
712 /*
713  * These are the existing service side transport implementations
714  */
715 
716 __BEGIN_DECLS
717 
718 #ifdef _KERNEL
719 
720 /*
721  * Create a new service pool.
722  */
723 extern SVCPOOL* svcpool_create(const char *name,
724     struct sysctl_oid_list *sysctl_base);
725 
726 /*
727  * Destroy a service pool, including all registered transports.
728  */
729 extern void svcpool_destroy(SVCPOOL *pool);
730 
731 /*
732  * Close a service pool.  Similar to svcpool_destroy(), but it does not
733  * free the data structures.  As such, the pool can be used again.
734  */
735 extern void svcpool_close(SVCPOOL *pool);
736 
737 /*
738  * Transport independent svc_create routine.
739  */
740 extern int svc_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
741     const rpcprog_t, const rpcvers_t, const char *);
742 /*
743  *      void (*dispatch)();             -- dispatch routine
744  *      const rpcprog_t prognum;        -- program number
745  *      const rpcvers_t versnum;        -- version number
746  *      const char *nettype;            -- network type
747  */
748 
749 
750 /*
751  * Generic server creation routine. It takes a netconfig structure
752  * instead of a nettype.
753  */
754 
755 extern SVCXPRT *svc_tp_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
756     const rpcprog_t, const rpcvers_t, const char *uaddr,
757     const struct netconfig *);
758         /*
759          * void (*dispatch)();            -- dispatch routine
760          * const rpcprog_t prognum;       -- program number
761          * const rpcvers_t versnum;       -- version number
762 	 * const char *uaddr;		  -- universal address of service
763          * const struct netconfig *nconf; -- netconfig structure
764          */
765 
766 extern SVCXPRT *svc_dg_create(SVCPOOL *, struct socket *,
767     const size_t, const size_t);
768         /*
769          * struct socket *;                             -- open connection
770          * const size_t sendsize;                        -- max send size
771          * const size_t recvsize;                        -- max recv size
772          */
773 
774 extern SVCXPRT *svc_vc_create(SVCPOOL *, struct socket *,
775     const size_t, const size_t);
776         /*
777          * struct socket *;                             -- open connection
778          * const size_t sendsize;                        -- max send size
779          * const size_t recvsize;                        -- max recv size
780          */
781 
782 extern SVCXPRT *svc_vc_create_backchannel(SVCPOOL *);
783 
784 extern void *clnt_bck_create(struct socket *, const rpcprog_t, const rpcvers_t);
785 	/*
786 	 * struct socket *;			-- server transport socket
787 	 * const rpcprog_t prog;		-- RPC program number
788 	 * const rpcvers_t vers;		-- RPC program version
789 	 */
790 
791 /*
792  * Generic TLI create routine
793  */
794 extern SVCXPRT *svc_tli_create(SVCPOOL *, struct socket *,
795     const struct netconfig *, const struct t_bind *, const size_t, const size_t);
796 /*
797  *      struct socket * so;             -- connection end point
798  *      const struct netconfig *nconf;  -- netconfig structure for network
799  *      const struct t_bind *bindaddr;  -- local bind address
800  *      const size_t sendsz;             -- max sendsize
801  *      const size_t recvsz;             -- max recvsize
802  */
803 
804 #else /* !_KERNEL */
805 
806 /*
807  * Transport independent svc_create routine.
808  */
809 extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
810 			   const rpcprog_t, const rpcvers_t, const char *);
811 /*
812  *      void (*dispatch)();             -- dispatch routine
813  *      const rpcprog_t prognum;        -- program number
814  *      const rpcvers_t versnum;        -- version number
815  *      const char *nettype;            -- network type
816  */
817 
818 
819 /*
820  * Generic server creation routine. It takes a netconfig structure
821  * instead of a nettype.
822  */
823 
824 extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
825 				   const rpcprog_t, const rpcvers_t,
826 				   const struct netconfig *);
827         /*
828          * void (*dispatch)();            -- dispatch routine
829          * const rpcprog_t prognum;       -- program number
830          * const rpcvers_t versnum;       -- version number
831          * const struct netconfig *nconf; -- netconfig structure
832          */
833 
834 /*
835  * Generic TLI create routine
836  */
837 extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
838 			       const struct t_bind *, const u_int,
839 			       const u_int);
840 /*
841  *      const int fd;                   -- connection end point
842  *      const struct netconfig *nconf;  -- netconfig structure for network
843  *      const struct t_bind *bindaddr;  -- local bind address
844  *      const u_int sendsz;             -- max sendsize
845  *      const u_int recvsz;             -- max recvsize
846  */
847 
848 /*
849  * Connectionless and connectionful create routines
850  */
851 
852 extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
853 /*
854  *      const int fd;                           -- open connection end point
855  *      const u_int sendsize;                   -- max send size
856  *      const u_int recvsize;                   -- max recv size
857  */
858 
859 /*
860  * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
861  */
862 extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
863 
864 extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
865         /*
866          * const int fd;                                -- open connection
867          * const u_int sendsize;                        -- max send size
868          * const u_int recvsize;                        -- max recv size
869          */
870 
871 
872 /*
873  * the routine takes any *open* connection
874  * descriptor as its first input and is used for open connections.
875  */
876 extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
877 /*
878  *      const int fd;                           -- open connection end point
879  *      const u_int sendsize;                   -- max send size
880  *      const u_int recvsize;                   -- max recv size
881  */
882 
883 /*
884  * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
885  */
886 extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
887 
888 /*
889  * Memory based rpc (for speed check and testing)
890  */
891 extern SVCXPRT *svc_raw_create(void);
892 
893 /*
894  * svc_dg_enable_cache() enables the cache on dg transports.
895  */
896 int svc_dg_enablecache(SVCXPRT *, const u_int);
897 
898 int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
899 
900 #endif	/* !_KERNEL */
901 
902 __END_DECLS
903 
904 #ifndef _KERNEL
905 /* for backward compatibility */
906 #include <rpc/svc_soc.h>
907 #endif
908 
909 #endif /* !_RPC_SVC_H */
910