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