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