xref: /onnv-gate/usr/src/uts/common/rpc/svc.h (revision 12553:e64e5d843075)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51676Sjpk  * Common Development and Distribution License (the "License").
61676Sjpk  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12553SKaren.Rochford@Sun.COM  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
250Sstevel@tonic-gate /* All Rights Reserved */
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley
280Sstevel@tonic-gate  * 4.3 BSD under license from the Regents of the University of
290Sstevel@tonic-gate  * California.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * svc.h, Server-side remote procedure call interface.
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifndef	_RPC_SVC_H
370Sstevel@tonic-gate #define	_RPC_SVC_H
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <rpc/rpc_com.h>
400Sstevel@tonic-gate #include <rpc/rpc_msg.h>
410Sstevel@tonic-gate #include <sys/tihdr.h>
420Sstevel@tonic-gate #include <sys/poll.h>
431676Sjpk #include <sys/tsol/label.h>
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #ifdef	_KERNEL
460Sstevel@tonic-gate #include <rpc/svc_auth.h>
470Sstevel@tonic-gate #include <sys/callb.h>
480Sstevel@tonic-gate #endif	/* _KERNEL */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * This interface must manage two items concerning remote procedure calling:
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * 1) An arbitrary number of transport connections upon which rpc requests
540Sstevel@tonic-gate  * are received. They are created and registered by routines in svc_generic.c,
550Sstevel@tonic-gate  * svc_vc.c and svc_dg.c; they in turn call xprt_register and
560Sstevel@tonic-gate  * xprt_unregister.
570Sstevel@tonic-gate  *
580Sstevel@tonic-gate  * 2) An arbitrary number of locally registered services.  Services are
590Sstevel@tonic-gate  * described by the following four data: program number, version number,
600Sstevel@tonic-gate  * "service dispatch" function, a transport handle, and a boolean that
610Sstevel@tonic-gate  * indicates whether or not the exported program should be registered with a
620Sstevel@tonic-gate  * local binder service;  if true the program's number and version and the
630Sstevel@tonic-gate  * address from the transport handle are registered with the binder.
640Sstevel@tonic-gate  * These data are registered with rpcbind via svc_reg().
650Sstevel@tonic-gate  *
660Sstevel@tonic-gate  * A service's dispatch function is called whenever an rpc request comes in
670Sstevel@tonic-gate  * on a transport.  The request's program and version numbers must match
680Sstevel@tonic-gate  * those of the registered service.  The dispatch function is passed two
690Sstevel@tonic-gate  * parameters, struct svc_req * and SVCXPRT *, defined below.
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #ifdef __cplusplus
730Sstevel@tonic-gate extern "C" {
740Sstevel@tonic-gate #endif
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * Server-side transport handles.
780Sstevel@tonic-gate  * The actual type definitions are below.
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate #ifdef	_KERNEL
810Sstevel@tonic-gate typedef struct __svcmasterxprt	SVCMASTERXPRT;	/* Master transport handle */
820Sstevel@tonic-gate typedef struct __svcxprt	SVCXPRT;	/* Per-thread clone handle */
830Sstevel@tonic-gate typedef	struct __svcpool	SVCPOOL;	/* Kernel thread pool	   */
840Sstevel@tonic-gate #else	/* _KERNEL */
850Sstevel@tonic-gate typedef struct __svcxprt	SVCXPRT;	/* Server transport handle */
860Sstevel@tonic-gate #endif	/* _KERNEL */
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  *  Prototype of error handler callback
900Sstevel@tonic-gate  */
910Sstevel@tonic-gate #ifndef _KERNEL
920Sstevel@tonic-gate typedef void (*svc_errorhandler_t)(const SVCXPRT* svc, const bool_t isAConn);
930Sstevel@tonic-gate #endif
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate  * Service request.
970Sstevel@tonic-gate  *
980Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
990Sstevel@tonic-gate  * svc_req
1000Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
1010Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
1020Sstevel@tonic-gate  */
1030Sstevel@tonic-gate struct svc_req {
1040Sstevel@tonic-gate 	rpcprog_t	rq_prog;	/* service program number */
1050Sstevel@tonic-gate 	rpcvers_t	rq_vers;	/* service protocol version */
1060Sstevel@tonic-gate 	rpcproc_t	rq_proc;	/* the desired procedure */
1070Sstevel@tonic-gate 	struct opaque_auth rq_cred;	/* raw creds from the wire */
1080Sstevel@tonic-gate 	caddr_t		rq_clntcred;	/* read only cooked cred */
1090Sstevel@tonic-gate 	SVCXPRT		*rq_xprt;	/* associated transport */
1101676Sjpk 	bslabel_t	*rq_label;	/* TSOL label of the request */
1110Sstevel@tonic-gate };
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate #ifdef _KERNEL
1140Sstevel@tonic-gate struct dupreq {
1150Sstevel@tonic-gate 	uint32_t	dr_xid;
1160Sstevel@tonic-gate 	rpcproc_t	dr_proc;
1170Sstevel@tonic-gate 	rpcvers_t	dr_vers;
1180Sstevel@tonic-gate 	rpcprog_t	dr_prog;
1190Sstevel@tonic-gate 	struct netbuf	dr_addr;
1200Sstevel@tonic-gate 	struct netbuf	dr_resp;
1210Sstevel@tonic-gate 	void		(*dr_resfree)();
1220Sstevel@tonic-gate 	int		dr_status;
1230Sstevel@tonic-gate 	struct dupreq	*dr_next;
1240Sstevel@tonic-gate 	struct dupreq	*dr_chain;
1250Sstevel@tonic-gate };
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate /*
1280Sstevel@tonic-gate  * States of requests for duplicate request caching.
1290Sstevel@tonic-gate  */
1300Sstevel@tonic-gate #define	DUP_NEW			0x00	/* new entry */
1310Sstevel@tonic-gate #define	DUP_INPROGRESS		0x01	/* request already going */
1320Sstevel@tonic-gate #define	DUP_DONE		0x02	/* request done */
1330Sstevel@tonic-gate #define	DUP_DROP		0x03	/* request dropped */
1340Sstevel@tonic-gate #define	DUP_ERROR		0x04	/* error in dup req cache */
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate  * Prototype for a service dispatch routine.
1380Sstevel@tonic-gate  */
1390Sstevel@tonic-gate typedef void (SVC_DISPATCH)(struct svc_req *, SVCXPRT *);
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate  * The service provider callout.
1430Sstevel@tonic-gate  * Each entry identifies a dispatch routine to be called
1440Sstevel@tonic-gate  * for a given RPC program number and a version fitting
1450Sstevel@tonic-gate  * into the registered range.
1460Sstevel@tonic-gate  */
1470Sstevel@tonic-gate typedef struct {
1480Sstevel@tonic-gate 	rpcprog_t	sc_prog;	/* RPC Program number */
1490Sstevel@tonic-gate 	rpcvers_t	sc_versmin;	/* Min version number */
1500Sstevel@tonic-gate 	rpcvers_t	sc_versmax;	/* Max version number */
1510Sstevel@tonic-gate 	SVC_DISPATCH	*sc_dispatch;	/* Dispatch routine   */
1520Sstevel@tonic-gate } SVC_CALLOUT;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate  * Table of service provider `callouts' for an RPC
1560Sstevel@tonic-gate  * transport handle. If sct_free is TRUE then transport
1570Sstevel@tonic-gate  * destructor is supposed to deallocate this table.
1580Sstevel@tonic-gate  */
1590Sstevel@tonic-gate typedef struct {
1600Sstevel@tonic-gate 	size_t		sct_size;	/* Number of entries  */
1610Sstevel@tonic-gate 	bool_t		sct_free;	/* Deallocate if true */
1620Sstevel@tonic-gate 	SVC_CALLOUT	*sct_sc;	/* Callout entries    */
1630Sstevel@tonic-gate } SVC_CALLOUT_TABLE;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate struct svc_ops {
1660Sstevel@tonic-gate 	bool_t	(*xp_recv)(SVCXPRT *, mblk_t *, struct rpc_msg *);
1670Sstevel@tonic-gate 		/* receive incoming requests */
1680Sstevel@tonic-gate 	bool_t	(*xp_getargs)(SVCXPRT *, xdrproc_t, caddr_t);
1690Sstevel@tonic-gate 		/* get arguments */
1700Sstevel@tonic-gate 	bool_t	(*xp_reply)(SVCXPRT *, struct rpc_msg *);
1710Sstevel@tonic-gate 		/* send reply */
1720Sstevel@tonic-gate 	bool_t	(*xp_freeargs)(SVCXPRT *, xdrproc_t, caddr_t);
1730Sstevel@tonic-gate 		/* free mem allocated for args */
1740Sstevel@tonic-gate 	void	(*xp_destroy)(SVCMASTERXPRT *);
1750Sstevel@tonic-gate 		/* destroy this struct */
1760Sstevel@tonic-gate 	int	(*xp_dup)(struct svc_req *, caddr_t, int,
1770Sstevel@tonic-gate 				struct dupreq **, bool_t *);
1780Sstevel@tonic-gate 		/* check for dup */
1790Sstevel@tonic-gate 	void	(*xp_dupdone)(struct dupreq *, caddr_t, void (*)(), int, int);
1800Sstevel@tonic-gate 		/* mark dup entry as completed */
1810Sstevel@tonic-gate 	int32_t *(*xp_getres)(SVCXPRT *, int);
1820Sstevel@tonic-gate 		/* get pointer to response buffer */
1830Sstevel@tonic-gate 	void	(*xp_freeres)(SVCXPRT *);
1840Sstevel@tonic-gate 		/* destroy pre-serialized response */
1850Sstevel@tonic-gate 	void	(*xp_clone_destroy)(SVCXPRT *);
1860Sstevel@tonic-gate 		/* destroy a clone xprt */
1870Sstevel@tonic-gate 	void	(*xp_start)(SVCMASTERXPRT *);
1880Sstevel@tonic-gate 		/* `ready-to-receive' */
18911967SKaren.Rochford@Sun.COM 	void	(*xp_clone_xprt)(SVCXPRT *, SVCXPRT *);
19011967SKaren.Rochford@Sun.COM 		/* transport specific clone function */
191*12553SKaren.Rochford@Sun.COM 	void	(*xp_tattrs) (SVCXPRT *, int, void **);
1920Sstevel@tonic-gate };
193*12553SKaren.Rochford@Sun.COM 
194*12553SKaren.Rochford@Sun.COM #define	SVC_TATTR_ADDRMASK	1
195*12553SKaren.Rochford@Sun.COM 
1960Sstevel@tonic-gate #else	/* _KERNEL */
1970Sstevel@tonic-gate /*
1980Sstevel@tonic-gate  *	Service control requests
1990Sstevel@tonic-gate  */
2000Sstevel@tonic-gate #define	SVCGET_VERSQUIET	1
2010Sstevel@tonic-gate #define	SVCSET_VERSQUIET	2
2020Sstevel@tonic-gate #define	SVCGET_XID		4
2030Sstevel@tonic-gate #define	SVCSET_KEEPALIVE	5
2040Sstevel@tonic-gate #define	SVCSET_CONNMAXREC	6
2050Sstevel@tonic-gate #define	SVCGET_CONNMAXREC	7
2060Sstevel@tonic-gate #define	SVCGET_RECVERRHANDLER	8
2070Sstevel@tonic-gate #define	SVCSET_RECVERRHANDLER	9
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate enum xprt_stat {
2100Sstevel@tonic-gate 	XPRT_DIED,
2110Sstevel@tonic-gate 	XPRT_MOREREQS,
2120Sstevel@tonic-gate 	XPRT_IDLE
2130Sstevel@tonic-gate };
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate struct xp_ops {
2160Sstevel@tonic-gate #ifdef	__STDC__
2170Sstevel@tonic-gate 	bool_t	(*xp_recv)(SVCXPRT *, struct rpc_msg *);
2180Sstevel@tonic-gate 		/* receive incoming requests */
2190Sstevel@tonic-gate 	enum xprt_stat (*xp_stat)(SVCXPRT *);
2200Sstevel@tonic-gate 		/* get transport status */
2210Sstevel@tonic-gate 	bool_t	(*xp_getargs)(SVCXPRT *, xdrproc_t, caddr_t);
2220Sstevel@tonic-gate 		/* get arguments */
2230Sstevel@tonic-gate 	bool_t	(*xp_reply)(SVCXPRT *,	struct rpc_msg *);
2240Sstevel@tonic-gate 		/* send reply */
2250Sstevel@tonic-gate 	bool_t	(*xp_freeargs)(SVCXPRT *, xdrproc_t, caddr_t);
2260Sstevel@tonic-gate 		/* free mem allocated for args */
2270Sstevel@tonic-gate 	void	(*xp_destroy)(SVCXPRT *);
2280Sstevel@tonic-gate 		/* destroy this struct */
2290Sstevel@tonic-gate 	bool_t	(*xp_control)(SVCXPRT *, const uint_t,	void *);
2300Sstevel@tonic-gate 		/* catch-all control function */
2310Sstevel@tonic-gate #else	/* __STDC__ */
2320Sstevel@tonic-gate 	bool_t	(*xp_recv)(); /* receive incoming requests */
2330Sstevel@tonic-gate 	enum xprt_stat (*xp_stat)(); /* get transport status */
2340Sstevel@tonic-gate 	bool_t	(*xp_getargs)(); /* get arguments */
2350Sstevel@tonic-gate 	bool_t	(*xp_reply)(); /* send reply */
2360Sstevel@tonic-gate 	bool_t	(*xp_freeargs)(); /* free mem allocated for args */
2370Sstevel@tonic-gate 	void	(*xp_destroy)(); /* destroy this struct */
2380Sstevel@tonic-gate 	bool_t	(*xp_control)(); /* catch-all control function */
2390Sstevel@tonic-gate #endif	/* __STDC__ */
2400Sstevel@tonic-gate };
2410Sstevel@tonic-gate #endif	/* _KERNEL */
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate #ifdef	_KERNEL
2440Sstevel@tonic-gate /*
2450Sstevel@tonic-gate  * SVCPOOL
2460Sstevel@tonic-gate  * Kernel RPC server-side thread pool structure.
2470Sstevel@tonic-gate  */
2480Sstevel@tonic-gate typedef struct __svcxprt_qnode __SVCXPRT_QNODE;	/* Defined in svc.c */
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate struct __svcpool {
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * Thread pool variables.
2530Sstevel@tonic-gate 	 *
2540Sstevel@tonic-gate 	 * The pool's thread lock p_thread_lock protects:
2550Sstevel@tonic-gate 	 * - p_threads, p_detached_threads, p_reserved_threads and p_closing
2560Sstevel@tonic-gate 	 * The pool's request lock protects:
2570Sstevel@tonic-gate 	 * - p_asleep, p_drowsy, p_reqs, p_walkers, p_req_cv.
2580Sstevel@tonic-gate 	 * The following fields are `initialized constants':
2590Sstevel@tonic-gate 	 * - p_id, p_stksize, p_timeout.
2600Sstevel@tonic-gate 	 * Access to p_next and p_prev is protected by the pool
2610Sstevel@tonic-gate 	 * list lock.
2620Sstevel@tonic-gate 	 */
2630Sstevel@tonic-gate 	SVCPOOL		*p_next;		/* Next pool in the list  */
2640Sstevel@tonic-gate 	SVCPOOL		*p_prev;		/* Prev pool in the list  */
2650Sstevel@tonic-gate 	int		p_id;			/* Pool id		  */
2660Sstevel@tonic-gate 	int		p_threads;		/* Non-detached threads	  */
2670Sstevel@tonic-gate 	int		p_detached_threads;	/* Detached threads	  */
2680Sstevel@tonic-gate 	int		p_maxthreads;		/* Max threads in the pool */
2690Sstevel@tonic-gate 	int		p_redline;		/* `Redline' for the pool */
2700Sstevel@tonic-gate 	int		p_reserved_threads;	/* Reserved threads	  */
2710Sstevel@tonic-gate 	kmutex_t	p_thread_lock;		/* Thread lock		  */
2720Sstevel@tonic-gate 	int		p_asleep;		/* Asleep threads	  */
2730Sstevel@tonic-gate 	int		p_drowsy;		/* Drowsy flag		  */
2740Sstevel@tonic-gate 	kcondvar_t 	p_req_cv;		/* svc_poll() sleep var.  */
2750Sstevel@tonic-gate 	clock_t		p_timeout;		/* svc_poll() timeout	  */
2760Sstevel@tonic-gate 	kmutex_t	p_req_lock;		/* Request lock		  */
2770Sstevel@tonic-gate 	int		p_reqs;			/* Pending requests	  */
2780Sstevel@tonic-gate 	int		p_walkers;		/* Walking threads	  */
2790Sstevel@tonic-gate 	int		p_max_same_xprt;	/* Max reqs from the xprt */
2800Sstevel@tonic-gate 	int		p_stksize;		/* Stack size for svc_run */
2810Sstevel@tonic-gate 	bool_t		p_closing : 1;		/* Pool is closing	  */
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	/*
2840Sstevel@tonic-gate 	 * Thread creator variables.
2850Sstevel@tonic-gate 	 * The `creator signaled' flag is turned on when a signal is send
2860Sstevel@tonic-gate 	 * to the creator thread (to create a new service thread). The
2870Sstevel@tonic-gate 	 * creator clears when the thread is created. The protocol is not
2880Sstevel@tonic-gate 	 * to signal the creator thread when the flag is on. However,
2890Sstevel@tonic-gate 	 * a new thread should signal the creator if there are more
2900Sstevel@tonic-gate 	 * requests in the queue.
2910Sstevel@tonic-gate 	 *
2920Sstevel@tonic-gate 	 * When the pool is closing (ie it has been already unregistered from
2930Sstevel@tonic-gate 	 * the pool list) the last thread on the last transport should turn
2940Sstevel@tonic-gate 	 * the p_creator_exit flag on. This tells the creator thread to
2950Sstevel@tonic-gate 	 * free the pool structure and exit.
2960Sstevel@tonic-gate 	 */
2970Sstevel@tonic-gate 	bool_t		p_creator_signaled : 1;	/* Create requested flag  */
2980Sstevel@tonic-gate 	bool_t		p_creator_exit : 1;	/* If true creator exits  */
2990Sstevel@tonic-gate 	kcondvar_t	p_creator_cv;		/* Creator cond. variable */
3000Sstevel@tonic-gate 	kmutex_t	p_creator_lock;		/* Creator lock		  */
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	/*
3030Sstevel@tonic-gate 	 * Doubly linked list containing `registered' master transport handles.
3040Sstevel@tonic-gate 	 * There is no special structure for a list node. Instead the
3050Sstevel@tonic-gate 	 * SVCMASTERXPRT structure has the xp_next and xp_prev fields.
3060Sstevel@tonic-gate 	 *
3070Sstevel@tonic-gate 	 * The p_lrwlock protects access to xprt->xp_next and xprt->xp_prev.
3080Sstevel@tonic-gate 	 * A service thread should also acquire a reader lock before accessing
3090Sstevel@tonic-gate 	 * any transports it is no longer linked to (to prevent them from
3100Sstevel@tonic-gate 	 * being destroyed).
3110Sstevel@tonic-gate 	 *
3120Sstevel@tonic-gate 	 * The list lock governs also the `pool is closing' flag.
3130Sstevel@tonic-gate 	 */
3140Sstevel@tonic-gate 	size_t		p_lcount;		/* Current count	  */
3150Sstevel@tonic-gate 	SVCMASTERXPRT	*p_lhead;		/* List head		  */
3160Sstevel@tonic-gate 	krwlock_t	p_lrwlock;		/* R/W lock		  */
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate 	/*
3190Sstevel@tonic-gate 	 * Circular linked list for the `xprt-ready' queue (FIFO).
3200Sstevel@tonic-gate 	 * Must be initialized with svc_xprt_qinit() before it is used.
3210Sstevel@tonic-gate 	 *
3220Sstevel@tonic-gate 	 * The writer's end is protected by the pool's request lock
3230Sstevel@tonic-gate 	 * (pool->p_req_lock). The reader's end is protected by q_end_lock.
3240Sstevel@tonic-gate 	 *
3250Sstevel@tonic-gate 	 * When the queue is full the p_qoverflow flag is raised. It stays
3260Sstevel@tonic-gate 	 * on until all the pending request are drained.
3270Sstevel@tonic-gate 	 */
3280Sstevel@tonic-gate 	size_t		p_qsize;		/* Number of queue nodes  */
3290Sstevel@tonic-gate 	int		p_qoverflow : 1;	/* Overflow flag	  */
3300Sstevel@tonic-gate 	__SVCXPRT_QNODE *p_qbody;		/* Queue body (array)	  */
3310Sstevel@tonic-gate 	__SVCXPRT_QNODE *p_qtop;		/* Writer's end of FIFO   */
3320Sstevel@tonic-gate 	__SVCXPRT_QNODE *p_qend;		/* Reader's end of FIFO	  */
3330Sstevel@tonic-gate 	kmutex_t	p_qend_lock;		/* Reader's end lock	  */
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 	/*
3360Sstevel@tonic-gate 	 * Userspace thread creator variables.
3370Sstevel@tonic-gate 	 * Thread creation is actually done in userland, via a thread
3380Sstevel@tonic-gate 	 * that is parked in the kernel. When that thread is signaled,
3390Sstevel@tonic-gate 	 * it returns back down to the daemon from whence it came and
3400Sstevel@tonic-gate 	 * does the lwp create.
3410Sstevel@tonic-gate 	 *
3420Sstevel@tonic-gate 	 * A parallel "creator" thread runs in the kernel. That is the
3430Sstevel@tonic-gate 	 * thread that will signal for the user thread to return to
3440Sstevel@tonic-gate 	 * userland and do its work.
3450Sstevel@tonic-gate 	 *
3460Sstevel@tonic-gate 	 * Since the thread doesn't always exist (there could be a race
3470Sstevel@tonic-gate 	 * if two threads are created in rapid succession), we set
3480Sstevel@tonic-gate 	 * p_signal_create_thread to FALSE when we're ready to accept work.
3490Sstevel@tonic-gate 	 *
3500Sstevel@tonic-gate 	 * p_user_exit is set to true when the service pool is about
3510Sstevel@tonic-gate 	 * to close. This is done so that the user creation thread
3520Sstevel@tonic-gate 	 * can be informed and cleanup any userland state.
3530Sstevel@tonic-gate 	 */
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	bool_t		p_signal_create_thread : 1; /* Create requested flag  */
3560Sstevel@tonic-gate 	bool_t		p_user_exit : 1;	/* If true creator exits  */
3570Sstevel@tonic-gate 	bool_t		p_user_waiting : 1;	/* Thread waiting for work */
3580Sstevel@tonic-gate 	kcondvar_t	p_user_cv;		/* Creator cond. variable */
3590Sstevel@tonic-gate 	kmutex_t	p_user_lock;		/* Creator lock		  */
3600Sstevel@tonic-gate 	void		(*p_offline)();		/* callout for unregister */
3610Sstevel@tonic-gate 	void		(*p_shutdown)();	/* callout for shutdown */
3620Sstevel@tonic-gate };
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate /*
3650Sstevel@tonic-gate  * Server side transport handle (SVCMASTERXPRT).
3660Sstevel@tonic-gate  * xprt->xp_req_lock governs the following fields in xprt:
3670Sstevel@tonic-gate  *		xp_req_head, xp_req_tail.
3680Sstevel@tonic-gate  * xprt->xp_thread_lock governs the following fields in xprt:
3690Sstevel@tonic-gate  *		xp_threads, xp_detached_threads.
3700Sstevel@tonic-gate  *
3710Sstevel@tonic-gate  * xp_req_tail is only valid if xp_req_head is non-NULL
3720Sstevel@tonic-gate  *
3730Sstevel@tonic-gate  * The xp_threads count is the number of attached threads.  These threads
3740Sstevel@tonic-gate  * are able to handle new requests, and it is expected that they will not
3750Sstevel@tonic-gate  * block for a very long time handling a given request. The
3760Sstevel@tonic-gate  * xp_detached_threads count is the number of threads that have detached
3770Sstevel@tonic-gate  * themselves from the transport. These threads can block indefinitely
3780Sstevel@tonic-gate  * while handling a request.  Once they complete the request, they exit.
3790Sstevel@tonic-gate  *
3800Sstevel@tonic-gate  * A kernel service provider may register a callback function "closeproc"
3810Sstevel@tonic-gate  * for a transport.  When the transport is closing the last exiting attached
3820Sstevel@tonic-gate  * thread - xp_threads goes to zero - it calls the callback function, passing
3830Sstevel@tonic-gate  * it a reference to the transport.  This call is made with xp_thread_lock
3840Sstevel@tonic-gate  * held, so any cleanup bookkeeping it does should be done quickly.
3850Sstevel@tonic-gate  *
3860Sstevel@tonic-gate  * When the transport is closing the last exiting thread is supposed
3870Sstevel@tonic-gate  * to destroy/free the data structure.
3880Sstevel@tonic-gate  */
3890Sstevel@tonic-gate typedef struct __svcxprt_common {
3900Sstevel@tonic-gate 	struct file	*xpc_fp;
3910Sstevel@tonic-gate 	struct svc_ops	*xpc_ops;
3920Sstevel@tonic-gate 	queue_t		*xpc_wq;	/* queue to write onto		*/
3930Sstevel@tonic-gate 	cred_t		*xpc_cred;	/* cached cred for server to use */
3940Sstevel@tonic-gate 	int32_t		xpc_type;	/* transport type		*/
3950Sstevel@tonic-gate 	int		xpc_msg_size;	/* TSDU or TIDU size		*/
3960Sstevel@tonic-gate 	struct netbuf	xpc_rtaddr;	/* remote transport address	*/
3977208Svv149972 	struct netbuf	xpc_lcladdr;	/* local transport address	*/
39810326SSiddheshwar.Mahesh@Sun.COM 	char		*xpc_netid;	/* network token		*/
3990Sstevel@tonic-gate 	SVC_CALLOUT_TABLE *xpc_sct;
4000Sstevel@tonic-gate } __SVCXPRT_COMMON;
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate #define	xp_fp		xp_xpc.xpc_fp
4030Sstevel@tonic-gate #define	xp_ops		xp_xpc.xpc_ops
4040Sstevel@tonic-gate #define	xp_wq		xp_xpc.xpc_wq
4050Sstevel@tonic-gate #define	xp_cred		xp_xpc.xpc_cred
4060Sstevel@tonic-gate #define	xp_type		xp_xpc.xpc_type
4070Sstevel@tonic-gate #define	xp_msg_size	xp_xpc.xpc_msg_size
4080Sstevel@tonic-gate #define	xp_rtaddr	xp_xpc.xpc_rtaddr
4097208Svv149972 #define	xp_lcladdr	xp_xpc.xpc_lcladdr
4100Sstevel@tonic-gate #define	xp_sct		xp_xpc.xpc_sct
41110326SSiddheshwar.Mahesh@Sun.COM #define	xp_netid	xp_xpc.xpc_netid
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate struct __svcmasterxprt {
4140Sstevel@tonic-gate 	SVCMASTERXPRT 	*xp_next;	/* Next transport in the list	*/
4150Sstevel@tonic-gate 	SVCMASTERXPRT 	*xp_prev;	/* Prev transport in the list	*/
4160Sstevel@tonic-gate 	__SVCXPRT_COMMON xp_xpc;	/* Fields common with the clone	*/
4170Sstevel@tonic-gate 	SVCPOOL		*xp_pool;	/* Pointer to the pool		*/
4180Sstevel@tonic-gate 	mblk_t		*xp_req_head;	/* Request queue head		*/
4190Sstevel@tonic-gate 	mblk_t		*xp_req_tail;	/* Request queue tail		*/
4200Sstevel@tonic-gate 	kmutex_t	xp_req_lock;	/* Request lock			*/
4210Sstevel@tonic-gate 	int		xp_threads;	/* Current num. of attached threads */
4220Sstevel@tonic-gate 	int		xp_detached_threads; /* num. of detached threads */
4230Sstevel@tonic-gate 	kmutex_t	xp_thread_lock;	/* Thread count lock		*/
4240Sstevel@tonic-gate 	void		(*xp_closeproc)(const SVCMASTERXPRT *);
4250Sstevel@tonic-gate 					/* optional; see comments above	*/
4260Sstevel@tonic-gate 	struct netbuf	xp_addrmask;	/* address mask			*/
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate 	caddr_t		xp_p2;		/* private: for use by svc ops  */
4290Sstevel@tonic-gate };
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate /*
4320Sstevel@tonic-gate  * Service thread `clone' transport handle (SVCXPRT)
4330Sstevel@tonic-gate  *
4340Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
4350Sstevel@tonic-gate  * SVCXPRT
4360Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
4370Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
4380Sstevel@tonic-gate  *
4390Sstevel@tonic-gate  * The xp_p2buf buffer is used as the storage for a transport type
4400Sstevel@tonic-gate  * specific structure. It is private for the svc ops for a given
4410Sstevel@tonic-gate  * transport type.
4420Sstevel@tonic-gate  */
4430Sstevel@tonic-gate 
4447387SRobert.Gordon@Sun.COM #define	SVC_P2LEN   128
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate struct __svcxprt {
4470Sstevel@tonic-gate 	__SVCXPRT_COMMON xp_xpc;
4480Sstevel@tonic-gate 	SVCMASTERXPRT	*xp_master;	/* back ptr to master		*/
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 	/* The following fileds are on a per-thread basis */
4510Sstevel@tonic-gate 	callb_cpr_t	*xp_cprp;	/* unused padding for Contract	*/
4520Sstevel@tonic-gate 	bool_t		xp_reserved : 1; /* is thread reserved?		*/
4530Sstevel@tonic-gate 	bool_t		xp_detached : 1; /* is thread detached?		*/
4540Sstevel@tonic-gate 	int		xp_same_xprt;	/* Reqs from the same xprt	*/
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate 	/* The following fields are used on a per-request basis */
4570Sstevel@tonic-gate 	struct opaque_auth xp_verf;	/* raw response verifier	*/
4580Sstevel@tonic-gate 	SVCAUTH		xp_auth;	/* auth flavor of current req	*/
4590Sstevel@tonic-gate 	void		*xp_cookie;	/* a cookie			*/
4600Sstevel@tonic-gate 	uint32_t	xp_xid;		/* id				*/
4610Sstevel@tonic-gate 	XDR		xp_xdrin;	/* input xdr stream		*/
4620Sstevel@tonic-gate 	XDR		xp_xdrout;	/* output xdr stream		*/
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 	/* Private for svc ops */
4650Sstevel@tonic-gate 	char		xp_p2buf[SVC_P2LEN]; /* udp_data or cots_data_t */
4660Sstevel@tonic-gate 						/* or clone_rdma_data_t */
4670Sstevel@tonic-gate };
4680Sstevel@tonic-gate #else	/* _KERNEL */
4690Sstevel@tonic-gate struct __svcxprt {
4700Sstevel@tonic-gate 	int		xp_fd;
4710Sstevel@tonic-gate #define	xp_sock		xp_fd
4720Sstevel@tonic-gate 	ushort_t	xp_port;
4730Sstevel@tonic-gate 	/*
4740Sstevel@tonic-gate 	 * associated port number.
4750Sstevel@tonic-gate 	 * Obsolete, but still used to
4760Sstevel@tonic-gate 	 * specify whether rendezvouser
4770Sstevel@tonic-gate 	 * or normal connection
4780Sstevel@tonic-gate 	 */
4790Sstevel@tonic-gate 	struct	xp_ops	*xp_ops;
4800Sstevel@tonic-gate 	int		xp_addrlen;	/* length of remote addr. Obsoleted */
4810Sstevel@tonic-gate 	char		*xp_tp;		/* transport provider device name */
4820Sstevel@tonic-gate 	char		*xp_netid;	/* network token */
4830Sstevel@tonic-gate 	struct netbuf	xp_ltaddr;	/* local transport address */
4840Sstevel@tonic-gate 	struct netbuf	xp_rtaddr;	/* remote transport address */
4850Sstevel@tonic-gate 	char		xp_raddr[16];	/* remote address. Now obsoleted */
4860Sstevel@tonic-gate 	struct opaque_auth xp_verf;	/* raw response verifier */
4870Sstevel@tonic-gate 	caddr_t		xp_p1;		/* private: for use by svc ops */
4880Sstevel@tonic-gate 	caddr_t		xp_p2;		/* private: for use by svc ops */
4890Sstevel@tonic-gate 	caddr_t		xp_p3;		/* private: for use by svc lib */
4900Sstevel@tonic-gate 	int		xp_type;	/* transport type */
4910Sstevel@tonic-gate 	/*
4920Sstevel@tonic-gate 	 * callback on client death
4930Sstevel@tonic-gate 	 * First parameter is the current structure,
4940Sstevel@tonic-gate 	 * Second parameter :
4950Sstevel@tonic-gate 	 *	- FALSE for the service listener
4960Sstevel@tonic-gate 	 *	- TRUE for a real connected socket
4970Sstevel@tonic-gate 	 */
4980Sstevel@tonic-gate 	svc_errorhandler_t xp_closeclnt;
4990Sstevel@tonic-gate };
5000Sstevel@tonic-gate #endif	/* _KERNEL */
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate /*
5030Sstevel@tonic-gate  *  Approved way of getting address of caller,
5040Sstevel@tonic-gate  *  address mask, and netid of transport.
5050Sstevel@tonic-gate  */
5060Sstevel@tonic-gate #define	svc_getrpccaller(x) (&(x)->xp_rtaddr)
5070Sstevel@tonic-gate #ifdef _KERNEL
5080Sstevel@tonic-gate #define	svc_getcaller(x) (&(x)->xp_rtaddr.buf)
5090Sstevel@tonic-gate #define	svc_getaddrmask(x) (&(x)->xp_master->xp_addrmask)
51010326SSiddheshwar.Mahesh@Sun.COM #define	svc_getnetid(x) ((x)->xp_netid)
5110Sstevel@tonic-gate #endif	/* _KERNEL */
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate /*
5140Sstevel@tonic-gate  * Operations defined on an SVCXPRT handle
5150Sstevel@tonic-gate  */
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate #ifdef	_KERNEL
51811967SKaren.Rochford@Sun.COM 
519*12553SKaren.Rochford@Sun.COM #define	SVC_GETADDRMASK(clone_xprt, attrflag, tattr) \
520*12553SKaren.Rochford@Sun.COM (*(clone_xprt)->xp_ops->xp_tattrs)((clone_xprt), (attrflag), (tattr))
521*12553SKaren.Rochford@Sun.COM 
52211967SKaren.Rochford@Sun.COM #define	SVC_CLONE_XPRT(src_xprt, dst_xprt) \
52311967SKaren.Rochford@Sun.COM 	if ((src_xprt)->xp_ops->xp_clone_xprt) \
52411967SKaren.Rochford@Sun.COM 		(*(src_xprt)->xp_ops->xp_clone_xprt) \
52511967SKaren.Rochford@Sun.COM 		    (src_xprt, dst_xprt)
52611967SKaren.Rochford@Sun.COM 
5270Sstevel@tonic-gate #define	SVC_RECV(clone_xprt, mp, msg) \
5280Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_recv)((clone_xprt), (mp), (msg))
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate /*
5310Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
5320Sstevel@tonic-gate  * SVC_GETARGS
5330Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
5340Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
5350Sstevel@tonic-gate  */
5360Sstevel@tonic-gate #define	SVC_GETARGS(clone_xprt, xargs, argsp) \
5370Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_getargs)((clone_xprt), (xargs), (argsp))
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate #define	SVC_REPLY(clone_xprt, msg) \
5400Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_reply) ((clone_xprt), (msg))
5410Sstevel@tonic-gate 
5420Sstevel@tonic-gate #define	SVC_FREEARGS(clone_xprt, xargs, argsp) \
5430Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_freeargs)((clone_xprt), (xargs), (argsp))
5440Sstevel@tonic-gate 
5450Sstevel@tonic-gate #define	SVC_GETRES(clone_xprt, size) \
5460Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_getres)((clone_xprt), (size))
5470Sstevel@tonic-gate 
5480Sstevel@tonic-gate #define	SVC_FREERES(clone_xprt)	\
5490Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_freeres)(clone_xprt)
5500Sstevel@tonic-gate 
5510Sstevel@tonic-gate #define	SVC_DESTROY(xprt) \
5520Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate /*
5550Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interfaces
5560Sstevel@tonic-gate  * SVC_DUP, SVC_DUPDONE, SVC_DUP_EXT, SVC_DUPDONE_EXT
5570Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
5580Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
5590Sstevel@tonic-gate  *
5600Sstevel@tonic-gate  * SVC_DUP and SVC_DUPDONE are defined here for backward compatibility.
5610Sstevel@tonic-gate  */
5620Sstevel@tonic-gate #define	SVC_DUP_EXT(clone_xprt, req, res, size, drpp, dupcachedp) \
5630Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, dupcachedp)
5640Sstevel@tonic-gate 
5650Sstevel@tonic-gate #define	SVC_DUPDONE_EXT(clone_xprt, dr, res, resfree, size, status) \
5660Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, resfree, size, status)
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate #define	SVC_DUP(clone_xprt, req, res, size, drpp) \
5690Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, NULL)
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate #define	SVC_DUPDONE(clone_xprt, dr, res, size, status) \
5720Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, NULL, size, status)
5730Sstevel@tonic-gate 
5740Sstevel@tonic-gate #define	SVC_CLONE_DESTROY(clone_xprt) \
5750Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_clone_destroy)(clone_xprt)
5760Sstevel@tonic-gate 
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate #define	SVC_START(xprt) \
5790Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_start)(xprt)
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate #else	/* _KERNEL */
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate #define	SVC_RECV(xprt, msg) \
5840Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
5850Sstevel@tonic-gate #define	svc_recv(xprt, msg) \
5860Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
5870Sstevel@tonic-gate 
5880Sstevel@tonic-gate #define	SVC_STAT(xprt) \
5890Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_stat)(xprt)
5900Sstevel@tonic-gate #define	svc_stat(xprt) \
5910Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_stat)(xprt)
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate #define	SVC_GETARGS(xprt, xargs, argsp) \
5940Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
5950Sstevel@tonic-gate #define	svc_getargs(xprt, xargs, argsp)	\
5960Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate #define	SVC_REPLY(xprt, msg) \
5990Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
6000Sstevel@tonic-gate #define	svc_reply(xprt, msg) \
6010Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate #define	SVC_FREEARGS(xprt, xargs, argsp) \
6040Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
6050Sstevel@tonic-gate #define	svc_freeargs(xprt, xargs, argsp) \
6060Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate #define	SVC_GETRES(xprt, size) \
6090Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getres)((xprt), (size))
6100Sstevel@tonic-gate #define	svc_getres(xprt, size) \
6110Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getres)((xprt), (size))
6120Sstevel@tonic-gate 
6130Sstevel@tonic-gate #define	SVC_FREERES(xprt) \
6140Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeres)(xprt)
6150Sstevel@tonic-gate #define	svc_freeres(xprt) \
6160Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeres)(xprt)
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate #define	SVC_DESTROY(xprt) \
6190Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
6200Sstevel@tonic-gate #define	svc_destroy(xprt) \
6210Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
6220Sstevel@tonic-gate 
6230Sstevel@tonic-gate /*
6240Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
6250Sstevel@tonic-gate  * SVC_CONTROL
6260Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
6270Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
6280Sstevel@tonic-gate  */
6290Sstevel@tonic-gate #define	SVC_CONTROL(xprt, rq, in) \
6300Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
6310Sstevel@tonic-gate #endif	/* _KERNEL */
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate /*
6340Sstevel@tonic-gate  * Pool id's reserved for NFS, NLM, and the NFSv4 callback program.
6350Sstevel@tonic-gate  */
6360Sstevel@tonic-gate #define	NFS_SVCPOOL_ID		0x01
6370Sstevel@tonic-gate #define	NLM_SVCPOOL_ID		0x02
6380Sstevel@tonic-gate #define	NFS_CB_SVCPOOL_ID	0x03
6390Sstevel@tonic-gate #define	RDC_SVCPOOL_ID		0x05	/* SNDR, PSARC 2001/699 */
6400Sstevel@tonic-gate 
6410Sstevel@tonic-gate struct svcpool_args {
6420Sstevel@tonic-gate 	uint32_t	id;		/* Pool id */
6430Sstevel@tonic-gate 	uint32_t	maxthreads;	/* Max threads in the pool */
6440Sstevel@tonic-gate 	uint32_t	redline;	/* `Redline' for the pool */
6450Sstevel@tonic-gate 	uint32_t	qsize;		/* `xprt-ready' queue size */
6460Sstevel@tonic-gate 	uint32_t	timeout;	/* svc_poll() timeout */
6470Sstevel@tonic-gate 	uint32_t	stksize;	/* svc_run() stack size */
6480Sstevel@tonic-gate 	uint32_t	max_same_xprt;	/* Max reqs from the same xprt */
6490Sstevel@tonic-gate };
6500Sstevel@tonic-gate 
6510Sstevel@tonic-gate 
6520Sstevel@tonic-gate #ifdef	_KERNEL
6530Sstevel@tonic-gate /*
6540Sstevel@tonic-gate  * Transport registration and thread pool creation.
6550Sstevel@tonic-gate  */
6560Sstevel@tonic-gate extern int	svc_xprt_register(SVCMASTERXPRT *, int);
6570Sstevel@tonic-gate extern void	svc_xprt_unregister(SVCMASTERXPRT *);
6580Sstevel@tonic-gate extern int	svc_pool_create(struct svcpool_args *);
6590Sstevel@tonic-gate extern int	svc_wait(int);
6600Sstevel@tonic-gate extern int	svc_do_run(int);
6610Sstevel@tonic-gate #define	SVCPSET_SHUTDOWN_PROC	1
6620Sstevel@tonic-gate #define	SVCPSET_UNREGISTER_PROC	2
6630Sstevel@tonic-gate extern int	svc_pool_control(int, int, void *);
6640Sstevel@tonic-gate #else	/* _KERNEL */
6650Sstevel@tonic-gate #ifdef	__STDC__
6660Sstevel@tonic-gate extern bool_t	rpc_reg(const rpcprog_t, const rpcvers_t, const rpcproc_t,
6670Sstevel@tonic-gate 			char *(*)(char *), const xdrproc_t, const xdrproc_t,
6680Sstevel@tonic-gate 			const char *);
6690Sstevel@tonic-gate 
6700Sstevel@tonic-gate /*
6710Sstevel@tonic-gate  * Service registration
6720Sstevel@tonic-gate  *
6730Sstevel@tonic-gate  * svc_reg(xprt, prog, vers, dispatch, nconf)
6740Sstevel@tonic-gate  *	const SVCXPRT *xprt;
6750Sstevel@tonic-gate  *	const rpcprog_t prog;
6760Sstevel@tonic-gate  *	const rpcvers_t vers;
6770Sstevel@tonic-gate  *	const void (*dispatch)();
6780Sstevel@tonic-gate  *	const struct netconfig *nconf;
6790Sstevel@tonic-gate  */
6800Sstevel@tonic-gate extern bool_t	svc_reg(const SVCXPRT *, const rpcprog_t, const rpcvers_t,
6810Sstevel@tonic-gate 			void (*)(struct svc_req *, SVCXPRT *),
6820Sstevel@tonic-gate 			const struct netconfig *);
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate /*
6850Sstevel@tonic-gate  * Service authentication registration
6860Sstevel@tonic-gate  *
6870Sstevel@tonic-gate  * svc_auth_reg(cred_flavor, handler)
6880Sstevel@tonic-gate  *    int cred_flavor;
6890Sstevel@tonic-gate  *    enum auth_stat (*handler)();
6900Sstevel@tonic-gate  */
6910Sstevel@tonic-gate extern int	svc_auth_reg(int, enum auth_stat (*)());
6920Sstevel@tonic-gate 
6930Sstevel@tonic-gate /*
6940Sstevel@tonic-gate  * Service un-registration
6950Sstevel@tonic-gate  *
6960Sstevel@tonic-gate  * svc_unreg(prog, vers)
6970Sstevel@tonic-gate  *	const rpcprog_t prog;
6980Sstevel@tonic-gate  *	const rpcvers_t vers;
6990Sstevel@tonic-gate  */
7000Sstevel@tonic-gate extern void	svc_unreg(const rpcprog_t, const rpcvers_t);
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate /*
7030Sstevel@tonic-gate  * Transport registration/unregistration.
7040Sstevel@tonic-gate  *
7050Sstevel@tonic-gate  * xprt_register(xprt)
7060Sstevel@tonic-gate  *	const SVCXPRT *xprt;
7070Sstevel@tonic-gate  *
7080Sstevel@tonic-gate  * xprt_unregister(xprt)
7090Sstevel@tonic-gate  *	const SVCXPRT *xprt;
7100Sstevel@tonic-gate  */
7110Sstevel@tonic-gate extern void	xprt_register(const SVCXPRT *);
7120Sstevel@tonic-gate extern void	xprt_unregister(const SVCXPRT *);
7130Sstevel@tonic-gate #else	/* __STDC__ */
7140Sstevel@tonic-gate extern bool_t	rpc_reg();
7150Sstevel@tonic-gate extern bool_t	svc_reg();
7160Sstevel@tonic-gate extern bool_t	svc_auth_reg();
7170Sstevel@tonic-gate extern void	svc_unreg();
7180Sstevel@tonic-gate extern void	xprt_register();
7190Sstevel@tonic-gate extern void	xprt_unregister();
7200Sstevel@tonic-gate #endif /* __STDC__ */
7210Sstevel@tonic-gate #endif	/* _KERNEL */
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate 
7240Sstevel@tonic-gate /*
7250Sstevel@tonic-gate  * When the service routine is called, it must first check to see if it
7260Sstevel@tonic-gate  * knows about the procedure;  if not, it should call svcerr_noproc
7270Sstevel@tonic-gate  * and return.  If so, it should deserialize its arguments via
7280Sstevel@tonic-gate  * SVC_GETARGS (defined above).  If the deserialization does not work,
7290Sstevel@tonic-gate  * svcerr_decode should be called followed by a return.  Successful
7300Sstevel@tonic-gate  * decoding of the arguments should be followed the execution of the
7310Sstevel@tonic-gate  * procedure's code and a call to svc_sendreply.
7320Sstevel@tonic-gate  *
7330Sstevel@tonic-gate  * Also, if the service refuses to execute the procedure due to too-
7340Sstevel@tonic-gate  * weak authentication parameters, svcerr_weakauth should be called.
7350Sstevel@tonic-gate  * Note: do not confuse access-control failure with weak authentication!
7360Sstevel@tonic-gate  *
7370Sstevel@tonic-gate  * NB: In pure implementations of rpc, the caller always waits for a reply
7380Sstevel@tonic-gate  * msg.  This message is sent when svc_sendreply is called.
7390Sstevel@tonic-gate  * Therefore pure service implementations should always call
7400Sstevel@tonic-gate  * svc_sendreply even if the function logically returns void;  use
7410Sstevel@tonic-gate  * xdr.h - xdr_void for the xdr routine.  HOWEVER, connectionful rpc allows
7420Sstevel@tonic-gate  * for the abuse of pure rpc via batched calling or pipelining.  In the
7430Sstevel@tonic-gate  * case of a batched call, svc_sendreply should NOT be called since
7440Sstevel@tonic-gate  * this would send a return message, which is what batching tries to avoid.
7450Sstevel@tonic-gate  * It is the service/protocol writer's responsibility to know which calls are
7460Sstevel@tonic-gate  * batched and which are not.  Warning: responding to batch calls may
7470Sstevel@tonic-gate  * deadlock the caller and server processes!
7480Sstevel@tonic-gate  */
7490Sstevel@tonic-gate #ifdef	__STDC__
7500Sstevel@tonic-gate extern bool_t	svc_sendreply(const SVCXPRT *, const xdrproc_t,	const caddr_t);
7510Sstevel@tonic-gate extern void	svcerr_decode(const SVCXPRT *);
7520Sstevel@tonic-gate extern void	svcerr_weakauth(const SVCXPRT *);
7530Sstevel@tonic-gate extern void	svcerr_noproc(const SVCXPRT *);
7540Sstevel@tonic-gate extern void	svcerr_progvers(const SVCXPRT *, const rpcvers_t,
7550Sstevel@tonic-gate     const rpcvers_t);
7560Sstevel@tonic-gate extern void	svcerr_auth(const SVCXPRT *, const enum auth_stat);
7570Sstevel@tonic-gate extern void	svcerr_noprog(const SVCXPRT *);
7580Sstevel@tonic-gate extern void	svcerr_systemerr(const SVCXPRT *);
7596786Srmesta extern void	svcerr_badcred(const SVCXPRT *);
7600Sstevel@tonic-gate #else	/* __STDC__ */
7610Sstevel@tonic-gate extern bool_t	svc_sendreply();
7620Sstevel@tonic-gate extern void	svcerr_decode();
7630Sstevel@tonic-gate extern void	svcerr_weakauth();
7640Sstevel@tonic-gate extern void	svcerr_noproc();
7650Sstevel@tonic-gate extern void	svcerr_progvers();
7660Sstevel@tonic-gate extern void	svcerr_auth();
7670Sstevel@tonic-gate extern void	svcerr_noprog();
7680Sstevel@tonic-gate extern void	svcerr_systemerr();
7696786Srmesta extern void	svcerr_badcred();
7700Sstevel@tonic-gate #endif	/* __STDC__ */
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate #ifdef	_KERNEL
7730Sstevel@tonic-gate /*
7740Sstevel@tonic-gate  * Kernel RPC functions.
7750Sstevel@tonic-gate  */
7760Sstevel@tonic-gate extern void	svc_init(void);
7770Sstevel@tonic-gate extern void	svc_cots_init(void);
7780Sstevel@tonic-gate extern void	svc_clts_init(void);
7790Sstevel@tonic-gate extern void	mt_kstat_init(void);
7800Sstevel@tonic-gate extern void	mt_kstat_fini(void);
7810Sstevel@tonic-gate extern int	svc_tli_kcreate(struct file *, uint_t, char *,
7820Sstevel@tonic-gate 				struct netbuf *, SVCMASTERXPRT **,
7830Sstevel@tonic-gate 				SVC_CALLOUT_TABLE *,
7840Sstevel@tonic-gate 				void (*closeproc)(const SVCMASTERXPRT *),
7850Sstevel@tonic-gate 				int, bool_t);
7860Sstevel@tonic-gate extern int	svc_clts_kcreate(struct file *, uint_t, struct T_info_ack *,
7870Sstevel@tonic-gate 				SVCMASTERXPRT **);
7880Sstevel@tonic-gate extern int	svc_cots_kcreate(struct file *, uint_t, struct T_info_ack *,
7890Sstevel@tonic-gate 				SVCMASTERXPRT **);
7900Sstevel@tonic-gate extern void	svc_queuereq(queue_t *, mblk_t *);
7910Sstevel@tonic-gate extern void	svc_queueclean(queue_t *);
7920Sstevel@tonic-gate extern void	svc_queueclose(queue_t *);
7930Sstevel@tonic-gate extern int	svc_reserve_thread(SVCXPRT *);
7940Sstevel@tonic-gate extern void	svc_unreserve_thread(SVCXPRT *);
7950Sstevel@tonic-gate extern callb_cpr_t *svc_detach_thread(SVCXPRT *);
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate /*
7980Sstevel@tonic-gate  * For RDMA based kRPC.
7990Sstevel@tonic-gate  * "rdma_xprt_record" is a reference to master transport handles
8000Sstevel@tonic-gate  * in kRPC thread pools. This is an easy way of tracking and shuting
8010Sstevel@tonic-gate  * down rdma based kRPC transports on demand.
8020Sstevel@tonic-gate  * "rdma_xprt_group" is a list of RDMA based mster transport handles
8030Sstevel@tonic-gate  * or records in a kRPC thread pool.
8040Sstevel@tonic-gate  */
8050Sstevel@tonic-gate typedef struct rdma_xprt_record		rdma_xprt_record_t;
8060Sstevel@tonic-gate struct rdma_xprt_record {
8070Sstevel@tonic-gate 	int			rtr_type;	/* Type of rdma; IB/VI/RDDP */
8080Sstevel@tonic-gate 	SVCMASTERXPRT		*rtr_xprt_ptr;	/* Ptr to master xprt handle */
8090Sstevel@tonic-gate 	rdma_xprt_record_t	*rtr_next;	/* Ptr to next record */
8100Sstevel@tonic-gate };
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate typedef struct {
8130Sstevel@tonic-gate 	int			rtg_count;	/* Number transport records */
8140Sstevel@tonic-gate 	int			rtg_poolid;	/* Pool Id for this group */
8150Sstevel@tonic-gate 	rdma_xprt_record_t	*rtg_listhead;	/* Head of the records list */
8160Sstevel@tonic-gate } rdma_xprt_group_t;
8170Sstevel@tonic-gate 
8180Sstevel@tonic-gate extern int	svc_rdma_kcreate(char *, SVC_CALLOUT_TABLE *, int,
8190Sstevel@tonic-gate 			rdma_xprt_group_t *);
8200Sstevel@tonic-gate extern void	svc_rdma_kstop(SVCMASTERXPRT *);
8210Sstevel@tonic-gate extern void	svc_rdma_kdestroy(SVCMASTERXPRT *);
8228695SRajkumar.Sivaprakasam@Sun.COM extern void	rdma_stop(rdma_xprt_group_t *);
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate /*
8250Sstevel@tonic-gate  * GSS cleanup method.
8260Sstevel@tonic-gate  */
8270Sstevel@tonic-gate extern void	rpc_gss_cleanup(SVCXPRT *);
8280Sstevel@tonic-gate #else	/* _KERNEL */
8290Sstevel@tonic-gate /*
8300Sstevel@tonic-gate  * Lowest level dispatching -OR- who owns this process anyway.
8310Sstevel@tonic-gate  * Somebody has to wait for incoming requests and then call the correct
8320Sstevel@tonic-gate  * service routine.  The routine svc_run does infinite waiting; i.e.,
8330Sstevel@tonic-gate  * svc_run never returns.
8340Sstevel@tonic-gate  * Since another (co-existant) package may wish to selectively wait for
8350Sstevel@tonic-gate  * incoming calls or other events outside of the rpc architecture, the
8360Sstevel@tonic-gate  * routine svc_getreq_poll is provided.  It must be passed pollfds, the
8370Sstevel@tonic-gate  * "in-place" results of a poll call (see poll, section 2).
8380Sstevel@tonic-gate  */
8390Sstevel@tonic-gate 
8400Sstevel@tonic-gate /*
8410Sstevel@tonic-gate  * Global keeper of rpc service descriptors in use
8420Sstevel@tonic-gate  * dynamic; must be inspected before each call to select or poll
8430Sstevel@tonic-gate  */
8440Sstevel@tonic-gate extern pollfd_t	*svc_pollfd;
8450Sstevel@tonic-gate extern int	svc_max_pollfd;
8460Sstevel@tonic-gate extern fd_set	svc_fdset;
8470Sstevel@tonic-gate #if !defined(_LP64) && FD_SETSIZE > 1024
8480Sstevel@tonic-gate extern fd_set	_new_svc_fdset;
8490Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
8500Sstevel@tonic-gate #pragma redefine_extname	svc_fdset	_new_svc_fdset
8510Sstevel@tonic-gate #else   /* __PRAGMA_REDEFINE_EXTNAME */
8520Sstevel@tonic-gate #define	svc_fdset	_new_svc_fdset
8530Sstevel@tonic-gate #endif  /* __PRAGMA_REDEFINE_EXTNAME */
8540Sstevel@tonic-gate #endif	/* LP64 && FD_SETSIZE > 1024 */
8550Sstevel@tonic-gate #define	svc_fds svc_fdset.fds_bits[0]	/* compatibility */
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate /*
8580Sstevel@tonic-gate  * A small program implemented by the svc_rpc implementation itself.
8590Sstevel@tonic-gate  * Also see clnt.h for protocol numbers.
8600Sstevel@tonic-gate  */
8610Sstevel@tonic-gate #ifdef __STDC__
8620Sstevel@tonic-gate extern void	svc_getreq(int);
8630Sstevel@tonic-gate extern void	svc_getreq_common(const int);
8640Sstevel@tonic-gate extern void	svc_getreqset(fd_set *); /* takes fdset instead of int */
8650Sstevel@tonic-gate extern void	svc_getreq_poll(struct pollfd *, const int);
8660Sstevel@tonic-gate extern void	svc_run(void);
8670Sstevel@tonic-gate extern void	svc_exit(void);
8680Sstevel@tonic-gate #else	/* __STDC__ */
8690Sstevel@tonic-gate extern void	rpctest_service();
8700Sstevel@tonic-gate extern void	svc_getreqset();
8710Sstevel@tonic-gate extern void	svc_getreq();
8720Sstevel@tonic-gate extern void	svc_getreq_common();
8730Sstevel@tonic-gate extern void	svc_getreqset();	 /* takes fdset instead of int */
8740Sstevel@tonic-gate extern void	svc_getreq_poll();
8750Sstevel@tonic-gate extern void	svc_run();
8760Sstevel@tonic-gate extern void	svc_exit();
8770Sstevel@tonic-gate #endif	/* __STDC__ */
8780Sstevel@tonic-gate 
8790Sstevel@tonic-gate /*
8800Sstevel@tonic-gate  *  Functions used to manage user file descriptors
8810Sstevel@tonic-gate  */
8820Sstevel@tonic-gate typedef int svc_input_id_t;
8830Sstevel@tonic-gate typedef void (*svc_callback_t)(svc_input_id_t id, int fd,
8840Sstevel@tonic-gate 				unsigned int events, void* cookie);
8850Sstevel@tonic-gate 
8860Sstevel@tonic-gate #ifdef __STDC__
8870Sstevel@tonic-gate extern svc_input_id_t svc_add_input(int fd, unsigned int events,
8880Sstevel@tonic-gate 				svc_callback_t user_callback,
8890Sstevel@tonic-gate 				void* cookie);
8900Sstevel@tonic-gate extern int svc_remove_input(svc_input_id_t id);
8910Sstevel@tonic-gate #else	/* __STDC__ */
8920Sstevel@tonic-gate extern svc_input_id_t svc_add_input();
8930Sstevel@tonic-gate extern int	svc_remove_input();
8940Sstevel@tonic-gate #endif
8950Sstevel@tonic-gate 
8960Sstevel@tonic-gate /*
8970Sstevel@tonic-gate  * These are the existing service side transport implementations.
8980Sstevel@tonic-gate  *
8990Sstevel@tonic-gate  * Transport independent svc_create routine.
9000Sstevel@tonic-gate  */
9010Sstevel@tonic-gate #ifdef __STDC__
9020Sstevel@tonic-gate extern int	svc_create(void (*)(struct svc_req *, SVCXPRT *),
9030Sstevel@tonic-gate 				const rpcprog_t, const rpcvers_t,
9040Sstevel@tonic-gate 				const char *);
9050Sstevel@tonic-gate 	/*
9060Sstevel@tonic-gate 	 * 	void (*dispatch)();		-- dispatch routine
9070Sstevel@tonic-gate 	 *	const rpcprog_t prognum;	-- program number
9080Sstevel@tonic-gate 	 *	const rpcvers_t versnum;	-- version number
9090Sstevel@tonic-gate 	 *	const char *nettype;		-- network type
9100Sstevel@tonic-gate 	 */
9110Sstevel@tonic-gate 
9120Sstevel@tonic-gate /*
9130Sstevel@tonic-gate  * Generic server creation routine. It takes a netconfig structure
9140Sstevel@tonic-gate  * instead of a nettype.
9150Sstevel@tonic-gate  */
9160Sstevel@tonic-gate extern SVCXPRT	*svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
9170Sstevel@tonic-gate 				const rpcprog_t, const rpcvers_t,
9180Sstevel@tonic-gate 				const struct netconfig *);
9190Sstevel@tonic-gate 	/*
9200Sstevel@tonic-gate 	 * void (*dispatch)();			-- dispatch routine
9210Sstevel@tonic-gate 	 * const rpcprog_t prognum;		-- program number
9220Sstevel@tonic-gate 	 * const rpcvers_t versnum;		-- version number
9230Sstevel@tonic-gate 	 * const struct netconfig *nconf;	-- netconfig structure
9240Sstevel@tonic-gate 	 */
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate /*
9270Sstevel@tonic-gate  * Generic TLI create routine
9280Sstevel@tonic-gate  */
9290Sstevel@tonic-gate extern  SVCXPRT	*svc_tli_create(const int, const struct netconfig *,
9300Sstevel@tonic-gate 				const struct t_bind *, const uint_t,
9310Sstevel@tonic-gate 				const uint_t);
9320Sstevel@tonic-gate 	/*
9330Sstevel@tonic-gate 	 *	const int fd;			-- connection end point
9340Sstevel@tonic-gate 	 *	const struct netconfig *nconf;	-- netconfig structure
9350Sstevel@tonic-gate 	 *	const struct t_bind *bindaddr;	-- local bind address
9360Sstevel@tonic-gate 	 *	const uint_t sendsz;		-- max sendsize
9370Sstevel@tonic-gate 	 *	const uint_t recvsz;		-- max recvsize
9380Sstevel@tonic-gate 	 */
9390Sstevel@tonic-gate 
9400Sstevel@tonic-gate /*
9410Sstevel@tonic-gate  * Connectionless and connectionful create routines.
9420Sstevel@tonic-gate  */
9430Sstevel@tonic-gate extern SVCXPRT	*svc_vc_create(const int, const uint_t, const uint_t);
9440Sstevel@tonic-gate 	/*
9450Sstevel@tonic-gate 	 *	const int fd;			-- open connection end point
9460Sstevel@tonic-gate 	 *	const uint_t sendsize;		-- max send size
9470Sstevel@tonic-gate 	 *	const uint_t recvsize;		-- max recv size
9480Sstevel@tonic-gate 	 */
9490Sstevel@tonic-gate 
9500Sstevel@tonic-gate extern SVCXPRT	*svc_dg_create(const int, const uint_t, const uint_t);
9510Sstevel@tonic-gate 	/*
9520Sstevel@tonic-gate 	 * const int fd;			-- open connection
9530Sstevel@tonic-gate 	 * const uint_t sendsize;		-- max send size
9540Sstevel@tonic-gate 	 * const uint_t recvsize;		-- max recv size
9550Sstevel@tonic-gate 	 */
9560Sstevel@tonic-gate 
9570Sstevel@tonic-gate /*
9580Sstevel@tonic-gate  * the routine takes any *open* TLI file
9590Sstevel@tonic-gate  * descriptor as its first input and is used for open connections.
9600Sstevel@tonic-gate  */
9610Sstevel@tonic-gate extern  SVCXPRT	*svc_fd_create(const int, const uint_t, const uint_t);
9620Sstevel@tonic-gate 	/*
9630Sstevel@tonic-gate 	 * 	const int fd;			-- open connection end point
9640Sstevel@tonic-gate 	 * 	const uint_t sendsize;		-- max send size
9650Sstevel@tonic-gate 	 * 	const uint_t recvsize;		-- max recv size
9660Sstevel@tonic-gate 	 */
9670Sstevel@tonic-gate 
9680Sstevel@tonic-gate /*
9690Sstevel@tonic-gate  * Memory based rpc (for speed check and testing)
9700Sstevel@tonic-gate  */
9710Sstevel@tonic-gate extern SVCXPRT	*svc_raw_create(void);
9720Sstevel@tonic-gate 
9730Sstevel@tonic-gate /*
9740Sstevel@tonic-gate  * Creation of service over doors transport.
9750Sstevel@tonic-gate  */
9760Sstevel@tonic-gate extern SVCXPRT	*svc_door_create(void (*)(struct svc_req *, SVCXPRT *),
9770Sstevel@tonic-gate 				const rpcprog_t, const rpcvers_t,
9780Sstevel@tonic-gate 				const uint_t);
9790Sstevel@tonic-gate 	/*
9800Sstevel@tonic-gate 	 * 	void (*dispatch)();		-- dispatch routine
9810Sstevel@tonic-gate 	 *	const rpcprog_t prognum;	-- program number
9820Sstevel@tonic-gate 	 *	const rpcvers_t versnum;	-- version number
9830Sstevel@tonic-gate 	 *	const uint_t sendsize;		-- send buffer size
9840Sstevel@tonic-gate 	 */
9850Sstevel@tonic-gate 
9860Sstevel@tonic-gate /*
9870Sstevel@tonic-gate  * Service control interface
9880Sstevel@tonic-gate  */
9890Sstevel@tonic-gate extern	bool_t	svc_control(SVCXPRT *, const uint_t, void *);
9900Sstevel@tonic-gate 	/*
9910Sstevel@tonic-gate 	 *	SVCXPRT *svc;			-- service to manipulate
9920Sstevel@tonic-gate 	 *	const uint_t req;		-- request
9930Sstevel@tonic-gate 	 *	void *info;			-- argument to request
9940Sstevel@tonic-gate 	 */
9950Sstevel@tonic-gate 
9960Sstevel@tonic-gate /*
9970Sstevel@tonic-gate  * svc_dg_enable_cache() enables the cache on dg transports.
9980Sstevel@tonic-gate  */
9990Sstevel@tonic-gate extern int svc_dg_enablecache(SVCXPRT *, const uint_t);
10000Sstevel@tonic-gate #else	/* __STDC__ */
10010Sstevel@tonic-gate extern int	svc_create();
10020Sstevel@tonic-gate extern SVCXPRT	*svc_tp_create();
10030Sstevel@tonic-gate extern SVCXPRT	*svc_tli_create();
10040Sstevel@tonic-gate extern SVCXPRT	*svc_vc_create();
10050Sstevel@tonic-gate extern SVCXPRT	*svc_dg_create();
10060Sstevel@tonic-gate extern SVCXPRT	*svc_fd_create();
10070Sstevel@tonic-gate extern SVCXPRT	*svc_raw_create();
10080Sstevel@tonic-gate extern SVCXPRT	*svc_door_create();
10090Sstevel@tonic-gate extern int svc_dg_enablecache();
10100Sstevel@tonic-gate #endif	/* __STDC__ */
10110Sstevel@tonic-gate 
10121676Sjpk extern boolean_t is_multilevel(rpcprog_t);
10131676Sjpk 
10140Sstevel@tonic-gate #ifdef	PORTMAP
10150Sstevel@tonic-gate /* For backward compatibility */
10160Sstevel@tonic-gate #include <rpc/svc_soc.h>
10170Sstevel@tonic-gate #endif	/* PORTMAP */
10180Sstevel@tonic-gate 
10190Sstevel@tonic-gate /*
10200Sstevel@tonic-gate  * For user level MT hot server functions
10210Sstevel@tonic-gate  */
10220Sstevel@tonic-gate 
10230Sstevel@tonic-gate /*
10240Sstevel@tonic-gate  * Different MT modes
10250Sstevel@tonic-gate  */
10260Sstevel@tonic-gate #define	RPC_SVC_MT_NONE		0	/* default, single-threaded */
10270Sstevel@tonic-gate #define	RPC_SVC_MT_AUTO		1	/* automatic MT mode */
10280Sstevel@tonic-gate #define	RPC_SVC_MT_USER		2	/* user MT mode */
10290Sstevel@tonic-gate 
10300Sstevel@tonic-gate #ifdef	__STDC__
10310Sstevel@tonic-gate extern void	svc_done(SVCXPRT *);
10320Sstevel@tonic-gate #else
10330Sstevel@tonic-gate extern void	svc_done();
10340Sstevel@tonic-gate #endif	/* __STDC__ */
10350Sstevel@tonic-gate 
10360Sstevel@tonic-gate /*
10370Sstevel@tonic-gate  * Obtaining local credentials.
10380Sstevel@tonic-gate  */
10390Sstevel@tonic-gate typedef struct __svc_local_cred_t {
10400Sstevel@tonic-gate 	uid_t	euid;	/* effective uid */
10410Sstevel@tonic-gate 	gid_t	egid;	/* effective gid */
10420Sstevel@tonic-gate 	uid_t	ruid;	/* real uid */
10430Sstevel@tonic-gate 	gid_t	rgid;	/* real gid */
10440Sstevel@tonic-gate 	pid_t	pid;	/* caller's pid, or -1 if not available */
10450Sstevel@tonic-gate } svc_local_cred_t;
10460Sstevel@tonic-gate 
10470Sstevel@tonic-gate #ifdef __STDC__
10480Sstevel@tonic-gate struct ucred_s;
10490Sstevel@tonic-gate extern void	svc_fd_negotiate_ucred(int);
10500Sstevel@tonic-gate extern int	svc_getcallerucred(const SVCXPRT *, struct ucred_s **);
10510Sstevel@tonic-gate extern bool_t	svc_get_local_cred(SVCXPRT *, svc_local_cred_t *);
10520Sstevel@tonic-gate #else
10530Sstevel@tonic-gate extern void	svc_fd_negotiate_ucred();
10540Sstevel@tonic-gate extern int	svc_getcallerucred();
10550Sstevel@tonic-gate extern bool_t	svc_get_local_cred();
10560Sstevel@tonic-gate #endif	/* __STDC__ */
10570Sstevel@tonic-gate 
10580Sstevel@tonic-gate /*
10590Sstevel@tonic-gate  * Private interfaces and structures for user level duplicate request caching.
10600Sstevel@tonic-gate  * The interfaces and data structures are not committed and subject to
10610Sstevel@tonic-gate  * change in future releases. Currently only intended for use by automountd.
10620Sstevel@tonic-gate  */
10630Sstevel@tonic-gate struct dupreq {
10640Sstevel@tonic-gate 	uint32_t	dr_xid;
10650Sstevel@tonic-gate 	rpcproc_t	dr_proc;
10660Sstevel@tonic-gate 	rpcvers_t	dr_vers;
10670Sstevel@tonic-gate 	rpcprog_t	dr_prog;
10680Sstevel@tonic-gate 	struct netbuf	dr_addr;
10690Sstevel@tonic-gate 	struct netbuf	dr_resp;
10700Sstevel@tonic-gate 	int		dr_status;
10710Sstevel@tonic-gate 	time_t		dr_time;
10720Sstevel@tonic-gate 	uint_t		dr_hash;
10730Sstevel@tonic-gate 	struct dupreq	*dr_next;
10740Sstevel@tonic-gate 	struct dupreq	*dr_prev;
10750Sstevel@tonic-gate 	struct dupreq	*dr_chain;
10760Sstevel@tonic-gate 	struct dupreq	*dr_prevchain;
10770Sstevel@tonic-gate };
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate /*
10800Sstevel@tonic-gate  * The fixedtime state is defined if we want to expand the routines to
10810Sstevel@tonic-gate  * handle and encompass fixed size caches.
10820Sstevel@tonic-gate  */
10830Sstevel@tonic-gate #define	DUPCACHE_FIXEDTIME	0
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate /*
10860Sstevel@tonic-gate  * States of requests for duplicate request caching.
10870Sstevel@tonic-gate  * These are the same as defined for the kernel.
10880Sstevel@tonic-gate  */
10890Sstevel@tonic-gate #define	DUP_NEW			0x00	/* new entry */
10900Sstevel@tonic-gate #define	DUP_INPROGRESS		0x01	/* request already going */
10910Sstevel@tonic-gate #define	DUP_DONE		0x02	/* request done */
10920Sstevel@tonic-gate #define	DUP_DROP		0x03	/* request dropped */
10930Sstevel@tonic-gate #define	DUP_ERROR		0x04	/* error in dup req cache */
10940Sstevel@tonic-gate 
10950Sstevel@tonic-gate #ifdef __STDC__
10960Sstevel@tonic-gate extern bool_t	__svc_dupcache_init(void *, int, char **);
10970Sstevel@tonic-gate extern int	__svc_dup(struct svc_req *, caddr_t *, uint_t *, char *);
10980Sstevel@tonic-gate extern int	__svc_dupdone(struct svc_req *, caddr_t, uint_t, int, char *);
10990Sstevel@tonic-gate extern bool_t	__svc_vc_dupcache_init(SVCXPRT *, void *, int);
11000Sstevel@tonic-gate extern int	__svc_vc_dup(struct svc_req *, caddr_t *, uint_t *);
11010Sstevel@tonic-gate extern int	__svc_vc_dupdone(struct svc_req *, caddr_t, uint_t, int);
11020Sstevel@tonic-gate #else
11030Sstevel@tonic-gate extern bool_t	__svc_dupcache_init();
11040Sstevel@tonic-gate extern int	__svc_dup();
11050Sstevel@tonic-gate extern int	__svc_dupdone();
11060Sstevel@tonic-gate extern bool_t	__svc_vc_dupcache_init();
11070Sstevel@tonic-gate extern int	__svc_vc_dup();
11080Sstevel@tonic-gate extern int	__svc_vc_dupdone();
11090Sstevel@tonic-gate #endif	/* __STDC__ */
11100Sstevel@tonic-gate #endif	/* _KERNEL */
11110Sstevel@tonic-gate 
111210721SGlenn.Barry@Sun.COM #ifdef	_KERNEL
111310721SGlenn.Barry@Sun.COM /*
111410721SGlenn.Barry@Sun.COM  * Private interfaces and structures for SVCXPRT cloning.
111510721SGlenn.Barry@Sun.COM  * The interfaces and data structures are not committed and subject to
111610721SGlenn.Barry@Sun.COM  * change in future releases.
111710721SGlenn.Barry@Sun.COM  */
111810721SGlenn.Barry@Sun.COM extern SVCXPRT *svc_clone_init(void);
111910721SGlenn.Barry@Sun.COM extern void svc_clone_free(SVCXPRT *);
112011967SKaren.Rochford@Sun.COM extern void svc_clone_link(SVCMASTERXPRT *, SVCXPRT *, SVCXPRT *);
112110721SGlenn.Barry@Sun.COM extern void svc_clone_unlink(SVCXPRT *);
112210721SGlenn.Barry@Sun.COM #endif	/* _KERNEL */
112310721SGlenn.Barry@Sun.COM 
11240Sstevel@tonic-gate #ifdef	__cplusplus
11250Sstevel@tonic-gate }
11260Sstevel@tonic-gate #endif
11270Sstevel@tonic-gate 
11280Sstevel@tonic-gate #endif	/* !_RPC_SVC_H */
1129