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