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