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