xref: /illumos-gate/usr/src/uts/common/rpc/svc.h (revision 51f34d4b950abb3636d536e2250bdc05baba902e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*51f34d4bSRajkumar Sivaprakasam  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
267c478bd9Sstevel@tonic-gate /* All Rights Reserved */
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley
297c478bd9Sstevel@tonic-gate  * 4.3 BSD under license from the Regents of the University of
307c478bd9Sstevel@tonic-gate  * California.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * svc.h, Server-side remote procedure call interface.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifndef	_RPC_SVC_H
387c478bd9Sstevel@tonic-gate #define	_RPC_SVC_H
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <rpc/rpc_com.h>
417c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
427c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
437c478bd9Sstevel@tonic-gate #include <sys/poll.h>
4445916cd2Sjpk #include <sys/tsol/label.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
477c478bd9Sstevel@tonic-gate #include <rpc/svc_auth.h>
487c478bd9Sstevel@tonic-gate #include <sys/callb.h>
497c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * This interface must manage two items concerning remote procedure calling:
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * 1) An arbitrary number of transport connections upon which rpc requests
557c478bd9Sstevel@tonic-gate  * are received. They are created and registered by routines in svc_generic.c,
567c478bd9Sstevel@tonic-gate  * svc_vc.c and svc_dg.c; they in turn call xprt_register and
577c478bd9Sstevel@tonic-gate  * xprt_unregister.
587c478bd9Sstevel@tonic-gate  *
597c478bd9Sstevel@tonic-gate  * 2) An arbitrary number of locally registered services.  Services are
607c478bd9Sstevel@tonic-gate  * described by the following four data: program number, version number,
617c478bd9Sstevel@tonic-gate  * "service dispatch" function, a transport handle, and a boolean that
627c478bd9Sstevel@tonic-gate  * indicates whether or not the exported program should be registered with a
637c478bd9Sstevel@tonic-gate  * local binder service;  if true the program's number and version and the
647c478bd9Sstevel@tonic-gate  * address from the transport handle are registered with the binder.
657c478bd9Sstevel@tonic-gate  * These data are registered with rpcbind via svc_reg().
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * A service's dispatch function is called whenever an rpc request comes in
687c478bd9Sstevel@tonic-gate  * on a transport.  The request's program and version numbers must match
697c478bd9Sstevel@tonic-gate  * those of the registered service.  The dispatch function is passed two
707c478bd9Sstevel@tonic-gate  * parameters, struct svc_req * and SVCXPRT *, defined below.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #ifdef __cplusplus
747c478bd9Sstevel@tonic-gate extern "C" {
757c478bd9Sstevel@tonic-gate #endif
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Server-side transport handles.
797c478bd9Sstevel@tonic-gate  * The actual type definitions are below.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
827c478bd9Sstevel@tonic-gate typedef struct __svcmasterxprt	SVCMASTERXPRT;	/* Master transport handle */
837c478bd9Sstevel@tonic-gate typedef struct __svcxprt	SVCXPRT;	/* Per-thread clone handle */
847c478bd9Sstevel@tonic-gate typedef	struct __svcpool	SVCPOOL;	/* Kernel thread pool	   */
857c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
867c478bd9Sstevel@tonic-gate typedef struct __svcxprt	SVCXPRT;	/* Server transport handle */
877c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  *  Prototype of error handler callback
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #ifndef _KERNEL
937c478bd9Sstevel@tonic-gate typedef void (*svc_errorhandler_t)(const SVCXPRT* svc, const bool_t isAConn);
947c478bd9Sstevel@tonic-gate #endif
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Service request.
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
1007c478bd9Sstevel@tonic-gate  * svc_req
1017c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
1027c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate struct svc_req {
1057c478bd9Sstevel@tonic-gate 	rpcprog_t	rq_prog;	/* service program number */
1067c478bd9Sstevel@tonic-gate 	rpcvers_t	rq_vers;	/* service protocol version */
1077c478bd9Sstevel@tonic-gate 	rpcproc_t	rq_proc;	/* the desired procedure */
1087c478bd9Sstevel@tonic-gate 	struct opaque_auth rq_cred;	/* raw creds from the wire */
1097c478bd9Sstevel@tonic-gate 	caddr_t		rq_clntcred;	/* read only cooked cred */
1107c478bd9Sstevel@tonic-gate 	SVCXPRT		*rq_xprt;	/* associated transport */
11145916cd2Sjpk 	bslabel_t	*rq_label;	/* TSOL label of the request */
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1157c478bd9Sstevel@tonic-gate struct dupreq {
1167c478bd9Sstevel@tonic-gate 	uint32_t	dr_xid;
1177c478bd9Sstevel@tonic-gate 	rpcproc_t	dr_proc;
1187c478bd9Sstevel@tonic-gate 	rpcvers_t	dr_vers;
1197c478bd9Sstevel@tonic-gate 	rpcprog_t	dr_prog;
1207c478bd9Sstevel@tonic-gate 	struct netbuf	dr_addr;
1217c478bd9Sstevel@tonic-gate 	struct netbuf	dr_resp;
1227c478bd9Sstevel@tonic-gate 	void		(*dr_resfree)();
1237c478bd9Sstevel@tonic-gate 	int		dr_status;
1247c478bd9Sstevel@tonic-gate 	struct dupreq	*dr_next;
1257c478bd9Sstevel@tonic-gate 	struct dupreq	*dr_chain;
1267c478bd9Sstevel@tonic-gate };
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * States of requests for duplicate request caching.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	DUP_NEW			0x00	/* new entry */
1327c478bd9Sstevel@tonic-gate #define	DUP_INPROGRESS		0x01	/* request already going */
1337c478bd9Sstevel@tonic-gate #define	DUP_DONE		0x02	/* request done */
1347c478bd9Sstevel@tonic-gate #define	DUP_DROP		0x03	/* request dropped */
1357c478bd9Sstevel@tonic-gate #define	DUP_ERROR		0x04	/* error in dup req cache */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * Prototype for a service dispatch routine.
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate typedef void (SVC_DISPATCH)(struct svc_req *, SVCXPRT *);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * The service provider callout.
1447c478bd9Sstevel@tonic-gate  * Each entry identifies a dispatch routine to be called
1457c478bd9Sstevel@tonic-gate  * for a given RPC program number and a version fitting
1467c478bd9Sstevel@tonic-gate  * into the registered range.
1477c478bd9Sstevel@tonic-gate  */
1487c478bd9Sstevel@tonic-gate typedef struct {
1497c478bd9Sstevel@tonic-gate 	rpcprog_t	sc_prog;	/* RPC Program number */
1507c478bd9Sstevel@tonic-gate 	rpcvers_t	sc_versmin;	/* Min version number */
1517c478bd9Sstevel@tonic-gate 	rpcvers_t	sc_versmax;	/* Max version number */
1527c478bd9Sstevel@tonic-gate 	SVC_DISPATCH	*sc_dispatch;	/* Dispatch routine   */
1537c478bd9Sstevel@tonic-gate } SVC_CALLOUT;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Table of service provider `callouts' for an RPC
1577c478bd9Sstevel@tonic-gate  * transport handle. If sct_free is TRUE then transport
1587c478bd9Sstevel@tonic-gate  * destructor is supposed to deallocate this table.
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate typedef struct {
1617c478bd9Sstevel@tonic-gate 	size_t		sct_size;	/* Number of entries  */
1627c478bd9Sstevel@tonic-gate 	bool_t		sct_free;	/* Deallocate if true */
1637c478bd9Sstevel@tonic-gate 	SVC_CALLOUT	*sct_sc;	/* Callout entries    */
1647c478bd9Sstevel@tonic-gate } SVC_CALLOUT_TABLE;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate struct svc_ops {
1677c478bd9Sstevel@tonic-gate 	bool_t	(*xp_recv)(SVCXPRT *, mblk_t *, struct rpc_msg *);
1687c478bd9Sstevel@tonic-gate 		/* receive incoming requests */
1697c478bd9Sstevel@tonic-gate 	bool_t	(*xp_getargs)(SVCXPRT *, xdrproc_t, caddr_t);
1707c478bd9Sstevel@tonic-gate 		/* get arguments */
1717c478bd9Sstevel@tonic-gate 	bool_t	(*xp_reply)(SVCXPRT *, struct rpc_msg *);
1727c478bd9Sstevel@tonic-gate 		/* send reply */
1737c478bd9Sstevel@tonic-gate 	bool_t	(*xp_freeargs)(SVCXPRT *, xdrproc_t, caddr_t);
1747c478bd9Sstevel@tonic-gate 		/* free mem allocated for args */
1757c478bd9Sstevel@tonic-gate 	void	(*xp_destroy)(SVCMASTERXPRT *);
1767c478bd9Sstevel@tonic-gate 		/* destroy this struct */
1777c478bd9Sstevel@tonic-gate 	int	(*xp_dup)(struct svc_req *, caddr_t, int,
1787c478bd9Sstevel@tonic-gate 				struct dupreq **, bool_t *);
1797c478bd9Sstevel@tonic-gate 		/* check for dup */
1807c478bd9Sstevel@tonic-gate 	void	(*xp_dupdone)(struct dupreq *, caddr_t, void (*)(), int, int);
1817c478bd9Sstevel@tonic-gate 		/* mark dup entry as completed */
1827c478bd9Sstevel@tonic-gate 	int32_t *(*xp_getres)(SVCXPRT *, int);
1837c478bd9Sstevel@tonic-gate 		/* get pointer to response buffer */
1847c478bd9Sstevel@tonic-gate 	void	(*xp_freeres)(SVCXPRT *);
1857c478bd9Sstevel@tonic-gate 		/* destroy pre-serialized response */
1867c478bd9Sstevel@tonic-gate 	void	(*xp_clone_destroy)(SVCXPRT *);
1877c478bd9Sstevel@tonic-gate 		/* destroy a clone xprt */
1887c478bd9Sstevel@tonic-gate 	void	(*xp_start)(SVCMASTERXPRT *);
1897c478bd9Sstevel@tonic-gate 		/* `ready-to-receive' */
1907c478bd9Sstevel@tonic-gate };
1917c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
1927c478bd9Sstevel@tonic-gate /*
1937c478bd9Sstevel@tonic-gate  *	Service control requests
1947c478bd9Sstevel@tonic-gate  */
1957c478bd9Sstevel@tonic-gate #define	SVCGET_VERSQUIET	1
1967c478bd9Sstevel@tonic-gate #define	SVCSET_VERSQUIET	2
1977c478bd9Sstevel@tonic-gate #define	SVCGET_XID		4
1987c478bd9Sstevel@tonic-gate #define	SVCSET_KEEPALIVE	5
1997c478bd9Sstevel@tonic-gate #define	SVCSET_CONNMAXREC	6
2007c478bd9Sstevel@tonic-gate #define	SVCGET_CONNMAXREC	7
2017c478bd9Sstevel@tonic-gate #define	SVCGET_RECVERRHANDLER	8
2027c478bd9Sstevel@tonic-gate #define	SVCSET_RECVERRHANDLER	9
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate enum xprt_stat {
2057c478bd9Sstevel@tonic-gate 	XPRT_DIED,
2067c478bd9Sstevel@tonic-gate 	XPRT_MOREREQS,
2077c478bd9Sstevel@tonic-gate 	XPRT_IDLE
2087c478bd9Sstevel@tonic-gate };
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate struct xp_ops {
2117c478bd9Sstevel@tonic-gate #ifdef	__STDC__
2127c478bd9Sstevel@tonic-gate 	bool_t	(*xp_recv)(SVCXPRT *, struct rpc_msg *);
2137c478bd9Sstevel@tonic-gate 		/* receive incoming requests */
2147c478bd9Sstevel@tonic-gate 	enum xprt_stat (*xp_stat)(SVCXPRT *);
2157c478bd9Sstevel@tonic-gate 		/* get transport status */
2167c478bd9Sstevel@tonic-gate 	bool_t	(*xp_getargs)(SVCXPRT *, xdrproc_t, caddr_t);
2177c478bd9Sstevel@tonic-gate 		/* get arguments */
2187c478bd9Sstevel@tonic-gate 	bool_t	(*xp_reply)(SVCXPRT *,	struct rpc_msg *);
2197c478bd9Sstevel@tonic-gate 		/* send reply */
2207c478bd9Sstevel@tonic-gate 	bool_t	(*xp_freeargs)(SVCXPRT *, xdrproc_t, caddr_t);
2217c478bd9Sstevel@tonic-gate 		/* free mem allocated for args */
2227c478bd9Sstevel@tonic-gate 	void	(*xp_destroy)(SVCXPRT *);
2237c478bd9Sstevel@tonic-gate 		/* destroy this struct */
2247c478bd9Sstevel@tonic-gate 	bool_t	(*xp_control)(SVCXPRT *, const uint_t,	void *);
2257c478bd9Sstevel@tonic-gate 		/* catch-all control function */
2267c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
2277c478bd9Sstevel@tonic-gate 	bool_t	(*xp_recv)(); /* receive incoming requests */
2287c478bd9Sstevel@tonic-gate 	enum xprt_stat (*xp_stat)(); /* get transport status */
2297c478bd9Sstevel@tonic-gate 	bool_t	(*xp_getargs)(); /* get arguments */
2307c478bd9Sstevel@tonic-gate 	bool_t	(*xp_reply)(); /* send reply */
2317c478bd9Sstevel@tonic-gate 	bool_t	(*xp_freeargs)(); /* free mem allocated for args */
2327c478bd9Sstevel@tonic-gate 	void	(*xp_destroy)(); /* destroy this struct */
2337c478bd9Sstevel@tonic-gate 	bool_t	(*xp_control)(); /* catch-all control function */
2347c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
2357c478bd9Sstevel@tonic-gate };
2367c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * SVCPOOL
2417c478bd9Sstevel@tonic-gate  * Kernel RPC server-side thread pool structure.
2427c478bd9Sstevel@tonic-gate  */
2437c478bd9Sstevel@tonic-gate typedef struct __svcxprt_qnode __SVCXPRT_QNODE;	/* Defined in svc.c */
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate struct __svcpool {
2467c478bd9Sstevel@tonic-gate 	/*
2477c478bd9Sstevel@tonic-gate 	 * Thread pool variables.
2487c478bd9Sstevel@tonic-gate 	 *
2497c478bd9Sstevel@tonic-gate 	 * The pool's thread lock p_thread_lock protects:
2507c478bd9Sstevel@tonic-gate 	 * - p_threads, p_detached_threads, p_reserved_threads and p_closing
2517c478bd9Sstevel@tonic-gate 	 * The pool's request lock protects:
2527c478bd9Sstevel@tonic-gate 	 * - p_asleep, p_drowsy, p_reqs, p_walkers, p_req_cv.
2537c478bd9Sstevel@tonic-gate 	 * The following fields are `initialized constants':
2547c478bd9Sstevel@tonic-gate 	 * - p_id, p_stksize, p_timeout.
2557c478bd9Sstevel@tonic-gate 	 * Access to p_next and p_prev is protected by the pool
2567c478bd9Sstevel@tonic-gate 	 * list lock.
2577c478bd9Sstevel@tonic-gate 	 */
2587c478bd9Sstevel@tonic-gate 	SVCPOOL		*p_next;		/* Next pool in the list  */
2597c478bd9Sstevel@tonic-gate 	SVCPOOL		*p_prev;		/* Prev pool in the list  */
2607c478bd9Sstevel@tonic-gate 	int		p_id;			/* Pool id		  */
2617c478bd9Sstevel@tonic-gate 	int		p_threads;		/* Non-detached threads	  */
2627c478bd9Sstevel@tonic-gate 	int		p_detached_threads;	/* Detached threads	  */
2637c478bd9Sstevel@tonic-gate 	int		p_maxthreads;		/* Max threads in the pool */
2647c478bd9Sstevel@tonic-gate 	int		p_redline;		/* `Redline' for the pool */
2657c478bd9Sstevel@tonic-gate 	int		p_reserved_threads;	/* Reserved threads	  */
2667c478bd9Sstevel@tonic-gate 	kmutex_t	p_thread_lock;		/* Thread lock		  */
2677c478bd9Sstevel@tonic-gate 	int		p_asleep;		/* Asleep threads	  */
2687c478bd9Sstevel@tonic-gate 	int		p_drowsy;		/* Drowsy flag		  */
2697c478bd9Sstevel@tonic-gate 	kcondvar_t 	p_req_cv;		/* svc_poll() sleep var.  */
2707c478bd9Sstevel@tonic-gate 	clock_t		p_timeout;		/* svc_poll() timeout	  */
2717c478bd9Sstevel@tonic-gate 	kmutex_t	p_req_lock;		/* Request lock		  */
2727c478bd9Sstevel@tonic-gate 	int		p_reqs;			/* Pending requests	  */
2737c478bd9Sstevel@tonic-gate 	int		p_walkers;		/* Walking threads	  */
2747c478bd9Sstevel@tonic-gate 	int		p_max_same_xprt;	/* Max reqs from the xprt */
2757c478bd9Sstevel@tonic-gate 	int		p_stksize;		/* Stack size for svc_run */
2767c478bd9Sstevel@tonic-gate 	bool_t		p_closing : 1;		/* Pool is closing	  */
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	/*
2797c478bd9Sstevel@tonic-gate 	 * Thread creator variables.
2807c478bd9Sstevel@tonic-gate 	 * The `creator signaled' flag is turned on when a signal is send
2817c478bd9Sstevel@tonic-gate 	 * to the creator thread (to create a new service thread). The
2827c478bd9Sstevel@tonic-gate 	 * creator clears when the thread is created. The protocol is not
2837c478bd9Sstevel@tonic-gate 	 * to signal the creator thread when the flag is on. However,
2847c478bd9Sstevel@tonic-gate 	 * a new thread should signal the creator if there are more
2857c478bd9Sstevel@tonic-gate 	 * requests in the queue.
2867c478bd9Sstevel@tonic-gate 	 *
2877c478bd9Sstevel@tonic-gate 	 * When the pool is closing (ie it has been already unregistered from
2887c478bd9Sstevel@tonic-gate 	 * the pool list) the last thread on the last transport should turn
2897c478bd9Sstevel@tonic-gate 	 * the p_creator_exit flag on. This tells the creator thread to
2907c478bd9Sstevel@tonic-gate 	 * free the pool structure and exit.
2917c478bd9Sstevel@tonic-gate 	 */
2927c478bd9Sstevel@tonic-gate 	bool_t		p_creator_signaled : 1;	/* Create requested flag  */
2937c478bd9Sstevel@tonic-gate 	bool_t		p_creator_exit : 1;	/* If true creator exits  */
2947c478bd9Sstevel@tonic-gate 	kcondvar_t	p_creator_cv;		/* Creator cond. variable */
2957c478bd9Sstevel@tonic-gate 	kmutex_t	p_creator_lock;		/* Creator lock		  */
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	/*
2987c478bd9Sstevel@tonic-gate 	 * Doubly linked list containing `registered' master transport handles.
2997c478bd9Sstevel@tonic-gate 	 * There is no special structure for a list node. Instead the
3007c478bd9Sstevel@tonic-gate 	 * SVCMASTERXPRT structure has the xp_next and xp_prev fields.
3017c478bd9Sstevel@tonic-gate 	 *
3027c478bd9Sstevel@tonic-gate 	 * The p_lrwlock protects access to xprt->xp_next and xprt->xp_prev.
3037c478bd9Sstevel@tonic-gate 	 * A service thread should also acquire a reader lock before accessing
3047c478bd9Sstevel@tonic-gate 	 * any transports it is no longer linked to (to prevent them from
3057c478bd9Sstevel@tonic-gate 	 * being destroyed).
3067c478bd9Sstevel@tonic-gate 	 *
3077c478bd9Sstevel@tonic-gate 	 * The list lock governs also the `pool is closing' flag.
3087c478bd9Sstevel@tonic-gate 	 */
3097c478bd9Sstevel@tonic-gate 	size_t		p_lcount;		/* Current count	  */
3107c478bd9Sstevel@tonic-gate 	SVCMASTERXPRT	*p_lhead;		/* List head		  */
3117c478bd9Sstevel@tonic-gate 	krwlock_t	p_lrwlock;		/* R/W lock		  */
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	/*
3147c478bd9Sstevel@tonic-gate 	 * Circular linked list for the `xprt-ready' queue (FIFO).
3157c478bd9Sstevel@tonic-gate 	 * Must be initialized with svc_xprt_qinit() before it is used.
3167c478bd9Sstevel@tonic-gate 	 *
3177c478bd9Sstevel@tonic-gate 	 * The writer's end is protected by the pool's request lock
3187c478bd9Sstevel@tonic-gate 	 * (pool->p_req_lock). The reader's end is protected by q_end_lock.
3197c478bd9Sstevel@tonic-gate 	 *
3207c478bd9Sstevel@tonic-gate 	 * When the queue is full the p_qoverflow flag is raised. It stays
3217c478bd9Sstevel@tonic-gate 	 * on until all the pending request are drained.
3227c478bd9Sstevel@tonic-gate 	 */
3237c478bd9Sstevel@tonic-gate 	size_t		p_qsize;		/* Number of queue nodes  */
3247c478bd9Sstevel@tonic-gate 	int		p_qoverflow : 1;	/* Overflow flag	  */
3257c478bd9Sstevel@tonic-gate 	__SVCXPRT_QNODE *p_qbody;		/* Queue body (array)	  */
3267c478bd9Sstevel@tonic-gate 	__SVCXPRT_QNODE *p_qtop;		/* Writer's end of FIFO   */
3277c478bd9Sstevel@tonic-gate 	__SVCXPRT_QNODE *p_qend;		/* Reader's end of FIFO	  */
3287c478bd9Sstevel@tonic-gate 	kmutex_t	p_qend_lock;		/* Reader's end lock	  */
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	/*
3317c478bd9Sstevel@tonic-gate 	 * Userspace thread creator variables.
3327c478bd9Sstevel@tonic-gate 	 * Thread creation is actually done in userland, via a thread
3337c478bd9Sstevel@tonic-gate 	 * that is parked in the kernel. When that thread is signaled,
3347c478bd9Sstevel@tonic-gate 	 * it returns back down to the daemon from whence it came and
3357c478bd9Sstevel@tonic-gate 	 * does the lwp create.
3367c478bd9Sstevel@tonic-gate 	 *
3377c478bd9Sstevel@tonic-gate 	 * A parallel "creator" thread runs in the kernel. That is the
3387c478bd9Sstevel@tonic-gate 	 * thread that will signal for the user thread to return to
3397c478bd9Sstevel@tonic-gate 	 * userland and do its work.
3407c478bd9Sstevel@tonic-gate 	 *
3417c478bd9Sstevel@tonic-gate 	 * Since the thread doesn't always exist (there could be a race
3427c478bd9Sstevel@tonic-gate 	 * if two threads are created in rapid succession), we set
3437c478bd9Sstevel@tonic-gate 	 * p_signal_create_thread to FALSE when we're ready to accept work.
3447c478bd9Sstevel@tonic-gate 	 *
3457c478bd9Sstevel@tonic-gate 	 * p_user_exit is set to true when the service pool is about
3467c478bd9Sstevel@tonic-gate 	 * to close. This is done so that the user creation thread
3477c478bd9Sstevel@tonic-gate 	 * can be informed and cleanup any userland state.
3487c478bd9Sstevel@tonic-gate 	 */
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	bool_t		p_signal_create_thread : 1; /* Create requested flag  */
3517c478bd9Sstevel@tonic-gate 	bool_t		p_user_exit : 1;	/* If true creator exits  */
3527c478bd9Sstevel@tonic-gate 	bool_t		p_user_waiting : 1;	/* Thread waiting for work */
3537c478bd9Sstevel@tonic-gate 	kcondvar_t	p_user_cv;		/* Creator cond. variable */
3547c478bd9Sstevel@tonic-gate 	kmutex_t	p_user_lock;		/* Creator lock		  */
3557c478bd9Sstevel@tonic-gate 	void		(*p_offline)();		/* callout for unregister */
3567c478bd9Sstevel@tonic-gate 	void		(*p_shutdown)();	/* callout for shutdown */
3577c478bd9Sstevel@tonic-gate };
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate  * Server side transport handle (SVCMASTERXPRT).
3617c478bd9Sstevel@tonic-gate  * xprt->xp_req_lock governs the following fields in xprt:
3627c478bd9Sstevel@tonic-gate  *		xp_req_head, xp_req_tail.
3637c478bd9Sstevel@tonic-gate  * xprt->xp_thread_lock governs the following fields in xprt:
3647c478bd9Sstevel@tonic-gate  *		xp_threads, xp_detached_threads.
3657c478bd9Sstevel@tonic-gate  *
3667c478bd9Sstevel@tonic-gate  * xp_req_tail is only valid if xp_req_head is non-NULL
3677c478bd9Sstevel@tonic-gate  *
3687c478bd9Sstevel@tonic-gate  * The xp_threads count is the number of attached threads.  These threads
3697c478bd9Sstevel@tonic-gate  * are able to handle new requests, and it is expected that they will not
3707c478bd9Sstevel@tonic-gate  * block for a very long time handling a given request. The
3717c478bd9Sstevel@tonic-gate  * xp_detached_threads count is the number of threads that have detached
3727c478bd9Sstevel@tonic-gate  * themselves from the transport. These threads can block indefinitely
3737c478bd9Sstevel@tonic-gate  * while handling a request.  Once they complete the request, they exit.
3747c478bd9Sstevel@tonic-gate  *
3757c478bd9Sstevel@tonic-gate  * A kernel service provider may register a callback function "closeproc"
3767c478bd9Sstevel@tonic-gate  * for a transport.  When the transport is closing the last exiting attached
3777c478bd9Sstevel@tonic-gate  * thread - xp_threads goes to zero - it calls the callback function, passing
3787c478bd9Sstevel@tonic-gate  * it a reference to the transport.  This call is made with xp_thread_lock
3797c478bd9Sstevel@tonic-gate  * held, so any cleanup bookkeeping it does should be done quickly.
3807c478bd9Sstevel@tonic-gate  *
3817c478bd9Sstevel@tonic-gate  * When the transport is closing the last exiting thread is supposed
3827c478bd9Sstevel@tonic-gate  * to destroy/free the data structure.
3837c478bd9Sstevel@tonic-gate  */
3847c478bd9Sstevel@tonic-gate typedef struct __svcxprt_common {
3857c478bd9Sstevel@tonic-gate 	struct file	*xpc_fp;
3867c478bd9Sstevel@tonic-gate 	struct svc_ops	*xpc_ops;
3877c478bd9Sstevel@tonic-gate 	queue_t		*xpc_wq;	/* queue to write onto		*/
3887c478bd9Sstevel@tonic-gate 	cred_t		*xpc_cred;	/* cached cred for server to use */
3897c478bd9Sstevel@tonic-gate 	int32_t		xpc_type;	/* transport type		*/
3907c478bd9Sstevel@tonic-gate 	int		xpc_msg_size;	/* TSDU or TIDU size		*/
3917c478bd9Sstevel@tonic-gate 	struct netbuf	xpc_rtaddr;	/* remote transport address	*/
392e810a982Svv 	struct netbuf	xpc_lcladdr;	/* local transport address	*/
3937c478bd9Sstevel@tonic-gate 	SVC_CALLOUT_TABLE *xpc_sct;
3947c478bd9Sstevel@tonic-gate } __SVCXPRT_COMMON;
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate #define	xp_fp		xp_xpc.xpc_fp
3977c478bd9Sstevel@tonic-gate #define	xp_ops		xp_xpc.xpc_ops
3987c478bd9Sstevel@tonic-gate #define	xp_wq		xp_xpc.xpc_wq
3997c478bd9Sstevel@tonic-gate #define	xp_cred		xp_xpc.xpc_cred
4007c478bd9Sstevel@tonic-gate #define	xp_type		xp_xpc.xpc_type
4017c478bd9Sstevel@tonic-gate #define	xp_msg_size	xp_xpc.xpc_msg_size
4027c478bd9Sstevel@tonic-gate #define	xp_rtaddr	xp_xpc.xpc_rtaddr
403e810a982Svv #define	xp_lcladdr	xp_xpc.xpc_lcladdr
4047c478bd9Sstevel@tonic-gate #define	xp_sct		xp_xpc.xpc_sct
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate struct __svcmasterxprt {
4077c478bd9Sstevel@tonic-gate 	SVCMASTERXPRT 	*xp_next;	/* Next transport in the list	*/
4087c478bd9Sstevel@tonic-gate 	SVCMASTERXPRT 	*xp_prev;	/* Prev transport in the list	*/
4097c478bd9Sstevel@tonic-gate 	__SVCXPRT_COMMON xp_xpc;	/* Fields common with the clone	*/
4107c478bd9Sstevel@tonic-gate 	SVCPOOL		*xp_pool;	/* Pointer to the pool		*/
4117c478bd9Sstevel@tonic-gate 	mblk_t		*xp_req_head;	/* Request queue head		*/
4127c478bd9Sstevel@tonic-gate 	mblk_t		*xp_req_tail;	/* Request queue tail		*/
4137c478bd9Sstevel@tonic-gate 	kmutex_t	xp_req_lock;	/* Request lock			*/
4147c478bd9Sstevel@tonic-gate 	int		xp_threads;	/* Current num. of attached threads */
4157c478bd9Sstevel@tonic-gate 	int		xp_detached_threads; /* num. of detached threads */
4167c478bd9Sstevel@tonic-gate 	kmutex_t	xp_thread_lock;	/* Thread count lock		*/
4177c478bd9Sstevel@tonic-gate 	void		(*xp_closeproc)(const SVCMASTERXPRT *);
4187c478bd9Sstevel@tonic-gate 					/* optional; see comments above	*/
4197c478bd9Sstevel@tonic-gate 	char		*xp_netid;	/* network token		*/
4207c478bd9Sstevel@tonic-gate 	struct netbuf	xp_addrmask;	/* address mask			*/
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	caddr_t		xp_p2;		/* private: for use by svc ops  */
4237c478bd9Sstevel@tonic-gate };
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate /*
4267c478bd9Sstevel@tonic-gate  * Service thread `clone' transport handle (SVCXPRT)
4277c478bd9Sstevel@tonic-gate  *
4287c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
4297c478bd9Sstevel@tonic-gate  * SVCXPRT
4307c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
4317c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
4327c478bd9Sstevel@tonic-gate  *
4337c478bd9Sstevel@tonic-gate  * The xp_p2buf buffer is used as the storage for a transport type
4347c478bd9Sstevel@tonic-gate  * specific structure. It is private for the svc ops for a given
4357c478bd9Sstevel@tonic-gate  * transport type.
4367c478bd9Sstevel@tonic-gate  */
4377c478bd9Sstevel@tonic-gate 
4380a701b1eSRobert Gordon #define	SVC_P2LEN   128
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate struct __svcxprt {
4417c478bd9Sstevel@tonic-gate 	__SVCXPRT_COMMON xp_xpc;
4427c478bd9Sstevel@tonic-gate 	SVCMASTERXPRT	*xp_master;	/* back ptr to master		*/
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	/* The following fileds are on a per-thread basis */
4457c478bd9Sstevel@tonic-gate 	callb_cpr_t	*xp_cprp;	/* unused padding for Contract	*/
4467c478bd9Sstevel@tonic-gate 	bool_t		xp_reserved : 1; /* is thread reserved?		*/
4477c478bd9Sstevel@tonic-gate 	bool_t		xp_detached : 1; /* is thread detached?		*/
4487c478bd9Sstevel@tonic-gate 	int		xp_same_xprt;	/* Reqs from the same xprt	*/
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	/* The following fields are used on a per-request basis */
4517c478bd9Sstevel@tonic-gate 	struct opaque_auth xp_verf;	/* raw response verifier	*/
4527c478bd9Sstevel@tonic-gate 	SVCAUTH		xp_auth;	/* auth flavor of current req	*/
4537c478bd9Sstevel@tonic-gate 	void		*xp_cookie;	/* a cookie			*/
4547c478bd9Sstevel@tonic-gate 	uint32_t	xp_xid;		/* id				*/
4557c478bd9Sstevel@tonic-gate 	XDR		xp_xdrin;	/* input xdr stream		*/
4567c478bd9Sstevel@tonic-gate 	XDR		xp_xdrout;	/* output xdr stream		*/
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	/* Private for svc ops */
4597c478bd9Sstevel@tonic-gate 	char		xp_p2buf[SVC_P2LEN]; /* udp_data or cots_data_t */
4607c478bd9Sstevel@tonic-gate 						/* or clone_rdma_data_t */
4617c478bd9Sstevel@tonic-gate };
4627c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
4637c478bd9Sstevel@tonic-gate struct __svcxprt {
4647c478bd9Sstevel@tonic-gate 	int		xp_fd;
4657c478bd9Sstevel@tonic-gate #define	xp_sock		xp_fd
4667c478bd9Sstevel@tonic-gate 	ushort_t	xp_port;
4677c478bd9Sstevel@tonic-gate 	/*
4687c478bd9Sstevel@tonic-gate 	 * associated port number.
4697c478bd9Sstevel@tonic-gate 	 * Obsolete, but still used to
4707c478bd9Sstevel@tonic-gate 	 * specify whether rendezvouser
4717c478bd9Sstevel@tonic-gate 	 * or normal connection
4727c478bd9Sstevel@tonic-gate 	 */
4737c478bd9Sstevel@tonic-gate 	struct	xp_ops	*xp_ops;
4747c478bd9Sstevel@tonic-gate 	int		xp_addrlen;	/* length of remote addr. Obsoleted */
4757c478bd9Sstevel@tonic-gate 	char		*xp_tp;		/* transport provider device name */
4767c478bd9Sstevel@tonic-gate 	char		*xp_netid;	/* network token */
4777c478bd9Sstevel@tonic-gate 	struct netbuf	xp_ltaddr;	/* local transport address */
4787c478bd9Sstevel@tonic-gate 	struct netbuf	xp_rtaddr;	/* remote transport address */
4797c478bd9Sstevel@tonic-gate 	char		xp_raddr[16];	/* remote address. Now obsoleted */
4807c478bd9Sstevel@tonic-gate 	struct opaque_auth xp_verf;	/* raw response verifier */
4817c478bd9Sstevel@tonic-gate 	caddr_t		xp_p1;		/* private: for use by svc ops */
4827c478bd9Sstevel@tonic-gate 	caddr_t		xp_p2;		/* private: for use by svc ops */
4837c478bd9Sstevel@tonic-gate 	caddr_t		xp_p3;		/* private: for use by svc lib */
4847c478bd9Sstevel@tonic-gate 	int		xp_type;	/* transport type */
4857c478bd9Sstevel@tonic-gate 	/*
4867c478bd9Sstevel@tonic-gate 	 * callback on client death
4877c478bd9Sstevel@tonic-gate 	 * First parameter is the current structure,
4887c478bd9Sstevel@tonic-gate 	 * Second parameter :
4897c478bd9Sstevel@tonic-gate 	 *	- FALSE for the service listener
4907c478bd9Sstevel@tonic-gate 	 *	- TRUE for a real connected socket
4917c478bd9Sstevel@tonic-gate 	 */
4927c478bd9Sstevel@tonic-gate 	svc_errorhandler_t xp_closeclnt;
4937c478bd9Sstevel@tonic-gate };
4947c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate /*
4977c478bd9Sstevel@tonic-gate  *  Approved way of getting address of caller,
4987c478bd9Sstevel@tonic-gate  *  address mask, and netid of transport.
4997c478bd9Sstevel@tonic-gate  */
5007c478bd9Sstevel@tonic-gate #define	svc_getrpccaller(x) (&(x)->xp_rtaddr)
5017c478bd9Sstevel@tonic-gate #ifdef _KERNEL
5027c478bd9Sstevel@tonic-gate #define	svc_getcaller(x) (&(x)->xp_rtaddr.buf)
5037c478bd9Sstevel@tonic-gate #define	svc_getaddrmask(x) (&(x)->xp_master->xp_addrmask)
5047c478bd9Sstevel@tonic-gate #define	svc_getnetid(x) ((x)->xp_master->xp_netid)
5057c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate  * Operations defined on an SVCXPRT handle
5097c478bd9Sstevel@tonic-gate  */
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
5127c478bd9Sstevel@tonic-gate #define	SVC_RECV(clone_xprt, mp, msg) \
5137c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_recv)((clone_xprt), (mp), (msg))
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate /*
5167c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
5177c478bd9Sstevel@tonic-gate  * SVC_GETARGS
5187c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
5197c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
5207c478bd9Sstevel@tonic-gate  */
5217c478bd9Sstevel@tonic-gate #define	SVC_GETARGS(clone_xprt, xargs, argsp) \
5227c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_getargs)((clone_xprt), (xargs), (argsp))
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate #define	SVC_REPLY(clone_xprt, msg) \
5257c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_reply) ((clone_xprt), (msg))
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate #define	SVC_FREEARGS(clone_xprt, xargs, argsp) \
5287c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_freeargs)((clone_xprt), (xargs), (argsp))
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate #define	SVC_GETRES(clone_xprt, size) \
5317c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_getres)((clone_xprt), (size))
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate #define	SVC_FREERES(clone_xprt)	\
5347c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_freeres)(clone_xprt)
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate #define	SVC_DESTROY(xprt) \
5377c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate /*
5407c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interfaces
5417c478bd9Sstevel@tonic-gate  * SVC_DUP, SVC_DUPDONE, SVC_DUP_EXT, SVC_DUPDONE_EXT
5427c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
5437c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
5447c478bd9Sstevel@tonic-gate  *
5457c478bd9Sstevel@tonic-gate  * SVC_DUP and SVC_DUPDONE are defined here for backward compatibility.
5467c478bd9Sstevel@tonic-gate  */
5477c478bd9Sstevel@tonic-gate #define	SVC_DUP_EXT(clone_xprt, req, res, size, drpp, dupcachedp) \
5487c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, dupcachedp)
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate #define	SVC_DUPDONE_EXT(clone_xprt, dr, res, resfree, size, status) \
5517c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, resfree, size, status)
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate #define	SVC_DUP(clone_xprt, req, res, size, drpp) \
5547c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, NULL)
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate #define	SVC_DUPDONE(clone_xprt, dr, res, size, status) \
5577c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, NULL, size, status)
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate #define	SVC_CLONE_DESTROY(clone_xprt) \
5607c478bd9Sstevel@tonic-gate 	(*(clone_xprt)->xp_ops->xp_clone_destroy)(clone_xprt)
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate #define	SVC_START(xprt) \
5647c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_start)(xprt)
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate #define	SVC_RECV(xprt, msg) \
5697c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
5707c478bd9Sstevel@tonic-gate #define	svc_recv(xprt, msg) \
5717c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate #define	SVC_STAT(xprt) \
5747c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_stat)(xprt)
5757c478bd9Sstevel@tonic-gate #define	svc_stat(xprt) \
5767c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_stat)(xprt)
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate #define	SVC_GETARGS(xprt, xargs, argsp) \
5797c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
5807c478bd9Sstevel@tonic-gate #define	svc_getargs(xprt, xargs, argsp)	\
5817c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate #define	SVC_REPLY(xprt, msg) \
5847c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
5857c478bd9Sstevel@tonic-gate #define	svc_reply(xprt, msg) \
5867c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate #define	SVC_FREEARGS(xprt, xargs, argsp) \
5897c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
5907c478bd9Sstevel@tonic-gate #define	svc_freeargs(xprt, xargs, argsp) \
5917c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate #define	SVC_GETRES(xprt, size) \
5947c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getres)((xprt), (size))
5957c478bd9Sstevel@tonic-gate #define	svc_getres(xprt, size) \
5967c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getres)((xprt), (size))
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate #define	SVC_FREERES(xprt) \
5997c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeres)(xprt)
6007c478bd9Sstevel@tonic-gate #define	svc_freeres(xprt) \
6017c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeres)(xprt)
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate #define	SVC_DESTROY(xprt) \
6047c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
6057c478bd9Sstevel@tonic-gate #define	svc_destroy(xprt) \
6067c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate /*
6097c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
6107c478bd9Sstevel@tonic-gate  * SVC_CONTROL
6117c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
6127c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
6137c478bd9Sstevel@tonic-gate  */
6147c478bd9Sstevel@tonic-gate #define	SVC_CONTROL(xprt, rq, in) \
6157c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
6167c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate /*
6197c478bd9Sstevel@tonic-gate  * Pool id's reserved for NFS, NLM, and the NFSv4 callback program.
6207c478bd9Sstevel@tonic-gate  */
6217c478bd9Sstevel@tonic-gate #define	NFS_SVCPOOL_ID		0x01
6227c478bd9Sstevel@tonic-gate #define	NLM_SVCPOOL_ID		0x02
6237c478bd9Sstevel@tonic-gate #define	NFS_CB_SVCPOOL_ID	0x03
6247c478bd9Sstevel@tonic-gate #define	RDC_SVCPOOL_ID		0x05	/* SNDR, PSARC 2001/699 */
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate struct svcpool_args {
6277c478bd9Sstevel@tonic-gate 	uint32_t	id;		/* Pool id */
6287c478bd9Sstevel@tonic-gate 	uint32_t	maxthreads;	/* Max threads in the pool */
6297c478bd9Sstevel@tonic-gate 	uint32_t	redline;	/* `Redline' for the pool */
6307c478bd9Sstevel@tonic-gate 	uint32_t	qsize;		/* `xprt-ready' queue size */
6317c478bd9Sstevel@tonic-gate 	uint32_t	timeout;	/* svc_poll() timeout */
6327c478bd9Sstevel@tonic-gate 	uint32_t	stksize;	/* svc_run() stack size */
6337c478bd9Sstevel@tonic-gate 	uint32_t	max_same_xprt;	/* Max reqs from the same xprt */
6347c478bd9Sstevel@tonic-gate };
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate  * Transport registration and thread pool creation.
6407c478bd9Sstevel@tonic-gate  */
6417c478bd9Sstevel@tonic-gate extern int	svc_xprt_register(SVCMASTERXPRT *, int);
6427c478bd9Sstevel@tonic-gate extern void	svc_xprt_unregister(SVCMASTERXPRT *);
6437c478bd9Sstevel@tonic-gate extern int	svc_pool_create(struct svcpool_args *);
6447c478bd9Sstevel@tonic-gate extern int	svc_wait(int);
6457c478bd9Sstevel@tonic-gate extern int	svc_do_run(int);
6467c478bd9Sstevel@tonic-gate #define	SVCPSET_SHUTDOWN_PROC	1
6477c478bd9Sstevel@tonic-gate #define	SVCPSET_UNREGISTER_PROC	2
6487c478bd9Sstevel@tonic-gate extern int	svc_pool_control(int, int, void *);
6497c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
6507c478bd9Sstevel@tonic-gate #ifdef	__STDC__
6517c478bd9Sstevel@tonic-gate extern bool_t	rpc_reg(const rpcprog_t, const rpcvers_t, const rpcproc_t,
6527c478bd9Sstevel@tonic-gate 			char *(*)(char *), const xdrproc_t, const xdrproc_t,
6537c478bd9Sstevel@tonic-gate 			const char *);
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate /*
6567c478bd9Sstevel@tonic-gate  * Service registration
6577c478bd9Sstevel@tonic-gate  *
6587c478bd9Sstevel@tonic-gate  * svc_reg(xprt, prog, vers, dispatch, nconf)
6597c478bd9Sstevel@tonic-gate  *	const SVCXPRT *xprt;
6607c478bd9Sstevel@tonic-gate  *	const rpcprog_t prog;
6617c478bd9Sstevel@tonic-gate  *	const rpcvers_t vers;
6627c478bd9Sstevel@tonic-gate  *	const void (*dispatch)();
6637c478bd9Sstevel@tonic-gate  *	const struct netconfig *nconf;
6647c478bd9Sstevel@tonic-gate  */
6657c478bd9Sstevel@tonic-gate extern bool_t	svc_reg(const SVCXPRT *, const rpcprog_t, const rpcvers_t,
6667c478bd9Sstevel@tonic-gate 			void (*)(struct svc_req *, SVCXPRT *),
6677c478bd9Sstevel@tonic-gate 			const struct netconfig *);
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate /*
6707c478bd9Sstevel@tonic-gate  * Service authentication registration
6717c478bd9Sstevel@tonic-gate  *
6727c478bd9Sstevel@tonic-gate  * svc_auth_reg(cred_flavor, handler)
6737c478bd9Sstevel@tonic-gate  *    int cred_flavor;
6747c478bd9Sstevel@tonic-gate  *    enum auth_stat (*handler)();
6757c478bd9Sstevel@tonic-gate  */
6767c478bd9Sstevel@tonic-gate extern int	svc_auth_reg(int, enum auth_stat (*)());
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate /*
6797c478bd9Sstevel@tonic-gate  * Service un-registration
6807c478bd9Sstevel@tonic-gate  *
6817c478bd9Sstevel@tonic-gate  * svc_unreg(prog, vers)
6827c478bd9Sstevel@tonic-gate  *	const rpcprog_t prog;
6837c478bd9Sstevel@tonic-gate  *	const rpcvers_t vers;
6847c478bd9Sstevel@tonic-gate  */
6857c478bd9Sstevel@tonic-gate extern void	svc_unreg(const rpcprog_t, const rpcvers_t);
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate /*
6887c478bd9Sstevel@tonic-gate  * Transport registration/unregistration.
6897c478bd9Sstevel@tonic-gate  *
6907c478bd9Sstevel@tonic-gate  * xprt_register(xprt)
6917c478bd9Sstevel@tonic-gate  *	const SVCXPRT *xprt;
6927c478bd9Sstevel@tonic-gate  *
6937c478bd9Sstevel@tonic-gate  * xprt_unregister(xprt)
6947c478bd9Sstevel@tonic-gate  *	const SVCXPRT *xprt;
6957c478bd9Sstevel@tonic-gate  */
6967c478bd9Sstevel@tonic-gate extern void	xprt_register(const SVCXPRT *);
6977c478bd9Sstevel@tonic-gate extern void	xprt_unregister(const SVCXPRT *);
6987c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
6997c478bd9Sstevel@tonic-gate extern bool_t	rpc_reg();
7007c478bd9Sstevel@tonic-gate extern bool_t	svc_reg();
7017c478bd9Sstevel@tonic-gate extern bool_t	svc_auth_reg();
7027c478bd9Sstevel@tonic-gate extern void	svc_unreg();
7037c478bd9Sstevel@tonic-gate extern void	xprt_register();
7047c478bd9Sstevel@tonic-gate extern void	xprt_unregister();
7057c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
7067c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate /*
7107c478bd9Sstevel@tonic-gate  * When the service routine is called, it must first check to see if it
7117c478bd9Sstevel@tonic-gate  * knows about the procedure;  if not, it should call svcerr_noproc
7127c478bd9Sstevel@tonic-gate  * and return.  If so, it should deserialize its arguments via
7137c478bd9Sstevel@tonic-gate  * SVC_GETARGS (defined above).  If the deserialization does not work,
7147c478bd9Sstevel@tonic-gate  * svcerr_decode should be called followed by a return.  Successful
7157c478bd9Sstevel@tonic-gate  * decoding of the arguments should be followed the execution of the
7167c478bd9Sstevel@tonic-gate  * procedure's code and a call to svc_sendreply.
7177c478bd9Sstevel@tonic-gate  *
7187c478bd9Sstevel@tonic-gate  * Also, if the service refuses to execute the procedure due to too-
7197c478bd9Sstevel@tonic-gate  * weak authentication parameters, svcerr_weakauth should be called.
7207c478bd9Sstevel@tonic-gate  * Note: do not confuse access-control failure with weak authentication!
7217c478bd9Sstevel@tonic-gate  *
7227c478bd9Sstevel@tonic-gate  * NB: In pure implementations of rpc, the caller always waits for a reply
7237c478bd9Sstevel@tonic-gate  * msg.  This message is sent when svc_sendreply is called.
7247c478bd9Sstevel@tonic-gate  * Therefore pure service implementations should always call
7257c478bd9Sstevel@tonic-gate  * svc_sendreply even if the function logically returns void;  use
7267c478bd9Sstevel@tonic-gate  * xdr.h - xdr_void for the xdr routine.  HOWEVER, connectionful rpc allows
7277c478bd9Sstevel@tonic-gate  * for the abuse of pure rpc via batched calling or pipelining.  In the
7287c478bd9Sstevel@tonic-gate  * case of a batched call, svc_sendreply should NOT be called since
7297c478bd9Sstevel@tonic-gate  * this would send a return message, which is what batching tries to avoid.
7307c478bd9Sstevel@tonic-gate  * It is the service/protocol writer's responsibility to know which calls are
7317c478bd9Sstevel@tonic-gate  * batched and which are not.  Warning: responding to batch calls may
7327c478bd9Sstevel@tonic-gate  * deadlock the caller and server processes!
7337c478bd9Sstevel@tonic-gate  */
7347c478bd9Sstevel@tonic-gate #ifdef	__STDC__
7357c478bd9Sstevel@tonic-gate extern bool_t	svc_sendreply(const SVCXPRT *, const xdrproc_t,	const caddr_t);
7367c478bd9Sstevel@tonic-gate extern void	svcerr_decode(const SVCXPRT *);
7377c478bd9Sstevel@tonic-gate extern void	svcerr_weakauth(const SVCXPRT *);
7387c478bd9Sstevel@tonic-gate extern void	svcerr_noproc(const SVCXPRT *);
7397c478bd9Sstevel@tonic-gate extern void	svcerr_progvers(const SVCXPRT *, const rpcvers_t,
7407c478bd9Sstevel@tonic-gate     const rpcvers_t);
7417c478bd9Sstevel@tonic-gate extern void	svcerr_auth(const SVCXPRT *, const enum auth_stat);
7427c478bd9Sstevel@tonic-gate extern void	svcerr_noprog(const SVCXPRT *);
7437c478bd9Sstevel@tonic-gate extern void	svcerr_systemerr(const SVCXPRT *);
7442e9d26a4Srmesta extern void	svcerr_badcred(const SVCXPRT *);
7457c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
7467c478bd9Sstevel@tonic-gate extern bool_t	svc_sendreply();
7477c478bd9Sstevel@tonic-gate extern void	svcerr_decode();
7487c478bd9Sstevel@tonic-gate extern void	svcerr_weakauth();
7497c478bd9Sstevel@tonic-gate extern void	svcerr_noproc();
7507c478bd9Sstevel@tonic-gate extern void	svcerr_progvers();
7517c478bd9Sstevel@tonic-gate extern void	svcerr_auth();
7527c478bd9Sstevel@tonic-gate extern void	svcerr_noprog();
7537c478bd9Sstevel@tonic-gate extern void	svcerr_systemerr();
7542e9d26a4Srmesta extern void	svcerr_badcred();
7557c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
7587c478bd9Sstevel@tonic-gate /*
7597c478bd9Sstevel@tonic-gate  * Kernel RPC functions.
7607c478bd9Sstevel@tonic-gate  */
7617c478bd9Sstevel@tonic-gate extern void	svc_init(void);
7627c478bd9Sstevel@tonic-gate extern void	svc_cots_init(void);
7637c478bd9Sstevel@tonic-gate extern void	svc_clts_init(void);
7647c478bd9Sstevel@tonic-gate extern void	mt_kstat_init(void);
7657c478bd9Sstevel@tonic-gate extern void	mt_kstat_fini(void);
7667c478bd9Sstevel@tonic-gate extern int	svc_tli_kcreate(struct file *, uint_t, char *,
7677c478bd9Sstevel@tonic-gate 				struct netbuf *, SVCMASTERXPRT **,
7687c478bd9Sstevel@tonic-gate 				SVC_CALLOUT_TABLE *,
7697c478bd9Sstevel@tonic-gate 				void (*closeproc)(const SVCMASTERXPRT *),
7707c478bd9Sstevel@tonic-gate 				int, bool_t);
7717c478bd9Sstevel@tonic-gate extern int	svc_clts_kcreate(struct file *, uint_t, struct T_info_ack *,
7727c478bd9Sstevel@tonic-gate 				SVCMASTERXPRT **);
7737c478bd9Sstevel@tonic-gate extern int	svc_cots_kcreate(struct file *, uint_t, struct T_info_ack *,
7747c478bd9Sstevel@tonic-gate 				SVCMASTERXPRT **);
7757c478bd9Sstevel@tonic-gate extern void	svc_queuereq(queue_t *, mblk_t *);
7767c478bd9Sstevel@tonic-gate extern void	svc_queueclean(queue_t *);
7777c478bd9Sstevel@tonic-gate extern void	svc_queueclose(queue_t *);
7787c478bd9Sstevel@tonic-gate extern int	svc_reserve_thread(SVCXPRT *);
7797c478bd9Sstevel@tonic-gate extern void	svc_unreserve_thread(SVCXPRT *);
7807c478bd9Sstevel@tonic-gate extern callb_cpr_t *svc_detach_thread(SVCXPRT *);
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate /*
7837c478bd9Sstevel@tonic-gate  * For RDMA based kRPC.
7847c478bd9Sstevel@tonic-gate  * "rdma_xprt_record" is a reference to master transport handles
7857c478bd9Sstevel@tonic-gate  * in kRPC thread pools. This is an easy way of tracking and shuting
7867c478bd9Sstevel@tonic-gate  * down rdma based kRPC transports on demand.
7877c478bd9Sstevel@tonic-gate  * "rdma_xprt_group" is a list of RDMA based mster transport handles
7887c478bd9Sstevel@tonic-gate  * or records in a kRPC thread pool.
7897c478bd9Sstevel@tonic-gate  */
7907c478bd9Sstevel@tonic-gate typedef struct rdma_xprt_record		rdma_xprt_record_t;
7917c478bd9Sstevel@tonic-gate struct rdma_xprt_record {
7927c478bd9Sstevel@tonic-gate 	int			rtr_type;	/* Type of rdma; IB/VI/RDDP */
7937c478bd9Sstevel@tonic-gate 	SVCMASTERXPRT		*rtr_xprt_ptr;	/* Ptr to master xprt handle */
7947c478bd9Sstevel@tonic-gate 	rdma_xprt_record_t	*rtr_next;	/* Ptr to next record */
7957c478bd9Sstevel@tonic-gate };
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate typedef struct {
7987c478bd9Sstevel@tonic-gate 	int			rtg_count;	/* Number transport records */
7997c478bd9Sstevel@tonic-gate 	int			rtg_poolid;	/* Pool Id for this group */
8007c478bd9Sstevel@tonic-gate 	rdma_xprt_record_t	*rtg_listhead;	/* Head of the records list */
8017c478bd9Sstevel@tonic-gate } rdma_xprt_group_t;
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate extern int	svc_rdma_kcreate(char *, SVC_CALLOUT_TABLE *, int,
8047c478bd9Sstevel@tonic-gate 			rdma_xprt_group_t *);
8057c478bd9Sstevel@tonic-gate extern void	svc_rdma_kstop(SVCMASTERXPRT *);
8067c478bd9Sstevel@tonic-gate extern void	svc_rdma_kdestroy(SVCMASTERXPRT *);
807*51f34d4bSRajkumar Sivaprakasam extern void	rdma_stop(rdma_xprt_group_t *);
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate /*
8107c478bd9Sstevel@tonic-gate  * GSS cleanup method.
8117c478bd9Sstevel@tonic-gate  */
8127c478bd9Sstevel@tonic-gate extern void	rpc_gss_cleanup(SVCXPRT *);
8137c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
8147c478bd9Sstevel@tonic-gate /*
8157c478bd9Sstevel@tonic-gate  * Lowest level dispatching -OR- who owns this process anyway.
8167c478bd9Sstevel@tonic-gate  * Somebody has to wait for incoming requests and then call the correct
8177c478bd9Sstevel@tonic-gate  * service routine.  The routine svc_run does infinite waiting; i.e.,
8187c478bd9Sstevel@tonic-gate  * svc_run never returns.
8197c478bd9Sstevel@tonic-gate  * Since another (co-existant) package may wish to selectively wait for
8207c478bd9Sstevel@tonic-gate  * incoming calls or other events outside of the rpc architecture, the
8217c478bd9Sstevel@tonic-gate  * routine svc_getreq_poll is provided.  It must be passed pollfds, the
8227c478bd9Sstevel@tonic-gate  * "in-place" results of a poll call (see poll, section 2).
8237c478bd9Sstevel@tonic-gate  */
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate /*
8267c478bd9Sstevel@tonic-gate  * Global keeper of rpc service descriptors in use
8277c478bd9Sstevel@tonic-gate  * dynamic; must be inspected before each call to select or poll
8287c478bd9Sstevel@tonic-gate  */
8297c478bd9Sstevel@tonic-gate extern pollfd_t	*svc_pollfd;
8307c478bd9Sstevel@tonic-gate extern int	svc_max_pollfd;
8317c478bd9Sstevel@tonic-gate extern fd_set	svc_fdset;
8327c478bd9Sstevel@tonic-gate #if !defined(_LP64) && FD_SETSIZE > 1024
8337c478bd9Sstevel@tonic-gate extern fd_set	_new_svc_fdset;
8347c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
8357c478bd9Sstevel@tonic-gate #pragma redefine_extname	svc_fdset	_new_svc_fdset
8367c478bd9Sstevel@tonic-gate #else   /* __PRAGMA_REDEFINE_EXTNAME */
8377c478bd9Sstevel@tonic-gate #define	svc_fdset	_new_svc_fdset
8387c478bd9Sstevel@tonic-gate #endif  /* __PRAGMA_REDEFINE_EXTNAME */
8397c478bd9Sstevel@tonic-gate #endif	/* LP64 && FD_SETSIZE > 1024 */
8407c478bd9Sstevel@tonic-gate #define	svc_fds svc_fdset.fds_bits[0]	/* compatibility */
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate /*
8437c478bd9Sstevel@tonic-gate  * A small program implemented by the svc_rpc implementation itself.
8447c478bd9Sstevel@tonic-gate  * Also see clnt.h for protocol numbers.
8457c478bd9Sstevel@tonic-gate  */
8467c478bd9Sstevel@tonic-gate #ifdef __STDC__
8477c478bd9Sstevel@tonic-gate extern void	svc_getreq(int);
8487c478bd9Sstevel@tonic-gate extern void	svc_getreq_common(const int);
8497c478bd9Sstevel@tonic-gate extern void	svc_getreqset(fd_set *); /* takes fdset instead of int */
8507c478bd9Sstevel@tonic-gate extern void	svc_getreq_poll(struct pollfd *, const int);
8517c478bd9Sstevel@tonic-gate extern void	svc_run(void);
8527c478bd9Sstevel@tonic-gate extern void	svc_exit(void);
8537c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
8547c478bd9Sstevel@tonic-gate extern void	rpctest_service();
8557c478bd9Sstevel@tonic-gate extern void	svc_getreqset();
8567c478bd9Sstevel@tonic-gate extern void	svc_getreq();
8577c478bd9Sstevel@tonic-gate extern void	svc_getreq_common();
8587c478bd9Sstevel@tonic-gate extern void	svc_getreqset();	 /* takes fdset instead of int */
8597c478bd9Sstevel@tonic-gate extern void	svc_getreq_poll();
8607c478bd9Sstevel@tonic-gate extern void	svc_run();
8617c478bd9Sstevel@tonic-gate extern void	svc_exit();
8627c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate /*
8657c478bd9Sstevel@tonic-gate  *  Functions used to manage user file descriptors
8667c478bd9Sstevel@tonic-gate  */
8677c478bd9Sstevel@tonic-gate typedef int svc_input_id_t;
8687c478bd9Sstevel@tonic-gate typedef void (*svc_callback_t)(svc_input_id_t id, int fd,
8697c478bd9Sstevel@tonic-gate 				unsigned int events, void* cookie);
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate #ifdef __STDC__
8727c478bd9Sstevel@tonic-gate extern svc_input_id_t svc_add_input(int fd, unsigned int events,
8737c478bd9Sstevel@tonic-gate 				svc_callback_t user_callback,
8747c478bd9Sstevel@tonic-gate 				void* cookie);
8757c478bd9Sstevel@tonic-gate extern int svc_remove_input(svc_input_id_t id);
8767c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
8777c478bd9Sstevel@tonic-gate extern svc_input_id_t svc_add_input();
8787c478bd9Sstevel@tonic-gate extern int	svc_remove_input();
8797c478bd9Sstevel@tonic-gate #endif
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate /*
8827c478bd9Sstevel@tonic-gate  * These are the existing service side transport implementations.
8837c478bd9Sstevel@tonic-gate  *
8847c478bd9Sstevel@tonic-gate  * Transport independent svc_create routine.
8857c478bd9Sstevel@tonic-gate  */
8867c478bd9Sstevel@tonic-gate #ifdef __STDC__
8877c478bd9Sstevel@tonic-gate extern int	svc_create(void (*)(struct svc_req *, SVCXPRT *),
8887c478bd9Sstevel@tonic-gate 				const rpcprog_t, const rpcvers_t,
8897c478bd9Sstevel@tonic-gate 				const char *);
8907c478bd9Sstevel@tonic-gate 	/*
8917c478bd9Sstevel@tonic-gate 	 * 	void (*dispatch)();		-- dispatch routine
8927c478bd9Sstevel@tonic-gate 	 *	const rpcprog_t prognum;	-- program number
8937c478bd9Sstevel@tonic-gate 	 *	const rpcvers_t versnum;	-- version number
8947c478bd9Sstevel@tonic-gate 	 *	const char *nettype;		-- network type
8957c478bd9Sstevel@tonic-gate 	 */
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate /*
8987c478bd9Sstevel@tonic-gate  * Generic server creation routine. It takes a netconfig structure
8997c478bd9Sstevel@tonic-gate  * instead of a nettype.
9007c478bd9Sstevel@tonic-gate  */
9017c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
9027c478bd9Sstevel@tonic-gate 				const rpcprog_t, const rpcvers_t,
9037c478bd9Sstevel@tonic-gate 				const struct netconfig *);
9047c478bd9Sstevel@tonic-gate 	/*
9057c478bd9Sstevel@tonic-gate 	 * void (*dispatch)();			-- dispatch routine
9067c478bd9Sstevel@tonic-gate 	 * const rpcprog_t prognum;		-- program number
9077c478bd9Sstevel@tonic-gate 	 * const rpcvers_t versnum;		-- version number
9087c478bd9Sstevel@tonic-gate 	 * const struct netconfig *nconf;	-- netconfig structure
9097c478bd9Sstevel@tonic-gate 	 */
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate /*
9127c478bd9Sstevel@tonic-gate  * Generic TLI create routine
9137c478bd9Sstevel@tonic-gate  */
9147c478bd9Sstevel@tonic-gate extern  SVCXPRT	*svc_tli_create(const int, const struct netconfig *,
9157c478bd9Sstevel@tonic-gate 				const struct t_bind *, const uint_t,
9167c478bd9Sstevel@tonic-gate 				const uint_t);
9177c478bd9Sstevel@tonic-gate 	/*
9187c478bd9Sstevel@tonic-gate 	 *	const int fd;			-- connection end point
9197c478bd9Sstevel@tonic-gate 	 *	const struct netconfig *nconf;	-- netconfig structure
9207c478bd9Sstevel@tonic-gate 	 *	const struct t_bind *bindaddr;	-- local bind address
9217c478bd9Sstevel@tonic-gate 	 *	const uint_t sendsz;		-- max sendsize
9227c478bd9Sstevel@tonic-gate 	 *	const uint_t recvsz;		-- max recvsize
9237c478bd9Sstevel@tonic-gate 	 */
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate /*
9267c478bd9Sstevel@tonic-gate  * Connectionless and connectionful create routines.
9277c478bd9Sstevel@tonic-gate  */
9287c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_vc_create(const int, const uint_t, const uint_t);
9297c478bd9Sstevel@tonic-gate 	/*
9307c478bd9Sstevel@tonic-gate 	 *	const int fd;			-- open connection end point
9317c478bd9Sstevel@tonic-gate 	 *	const uint_t sendsize;		-- max send size
9327c478bd9Sstevel@tonic-gate 	 *	const uint_t recvsize;		-- max recv size
9337c478bd9Sstevel@tonic-gate 	 */
9347c478bd9Sstevel@tonic-gate 
9357c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_dg_create(const int, const uint_t, const uint_t);
9367c478bd9Sstevel@tonic-gate 	/*
9377c478bd9Sstevel@tonic-gate 	 * const int fd;			-- open connection
9387c478bd9Sstevel@tonic-gate 	 * const uint_t sendsize;		-- max send size
9397c478bd9Sstevel@tonic-gate 	 * const uint_t recvsize;		-- max recv size
9407c478bd9Sstevel@tonic-gate 	 */
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate /*
9437c478bd9Sstevel@tonic-gate  * the routine takes any *open* TLI file
9447c478bd9Sstevel@tonic-gate  * descriptor as its first input and is used for open connections.
9457c478bd9Sstevel@tonic-gate  */
9467c478bd9Sstevel@tonic-gate extern  SVCXPRT	*svc_fd_create(const int, const uint_t, const uint_t);
9477c478bd9Sstevel@tonic-gate 	/*
9487c478bd9Sstevel@tonic-gate 	 * 	const int fd;			-- open connection end point
9497c478bd9Sstevel@tonic-gate 	 * 	const uint_t sendsize;		-- max send size
9507c478bd9Sstevel@tonic-gate 	 * 	const uint_t recvsize;		-- max recv size
9517c478bd9Sstevel@tonic-gate 	 */
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate /*
9547c478bd9Sstevel@tonic-gate  * Memory based rpc (for speed check and testing)
9557c478bd9Sstevel@tonic-gate  */
9567c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_raw_create(void);
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate /*
9597c478bd9Sstevel@tonic-gate  * Creation of service over doors transport.
9607c478bd9Sstevel@tonic-gate  */
9617c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_door_create(void (*)(struct svc_req *, SVCXPRT *),
9627c478bd9Sstevel@tonic-gate 				const rpcprog_t, const rpcvers_t,
9637c478bd9Sstevel@tonic-gate 				const uint_t);
9647c478bd9Sstevel@tonic-gate 	/*
9657c478bd9Sstevel@tonic-gate 	 * 	void (*dispatch)();		-- dispatch routine
9667c478bd9Sstevel@tonic-gate 	 *	const rpcprog_t prognum;	-- program number
9677c478bd9Sstevel@tonic-gate 	 *	const rpcvers_t versnum;	-- version number
9687c478bd9Sstevel@tonic-gate 	 *	const uint_t sendsize;		-- send buffer size
9697c478bd9Sstevel@tonic-gate 	 */
9707c478bd9Sstevel@tonic-gate 
9717c478bd9Sstevel@tonic-gate /*
9727c478bd9Sstevel@tonic-gate  * Service control interface
9737c478bd9Sstevel@tonic-gate  */
9747c478bd9Sstevel@tonic-gate extern	bool_t	svc_control(SVCXPRT *, const uint_t, void *);
9757c478bd9Sstevel@tonic-gate 	/*
9767c478bd9Sstevel@tonic-gate 	 *	SVCXPRT *svc;			-- service to manipulate
9777c478bd9Sstevel@tonic-gate 	 *	const uint_t req;		-- request
9787c478bd9Sstevel@tonic-gate 	 *	void *info;			-- argument to request
9797c478bd9Sstevel@tonic-gate 	 */
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate /*
9827c478bd9Sstevel@tonic-gate  * svc_dg_enable_cache() enables the cache on dg transports.
9837c478bd9Sstevel@tonic-gate  */
9847c478bd9Sstevel@tonic-gate extern int svc_dg_enablecache(SVCXPRT *, const uint_t);
9857c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
9867c478bd9Sstevel@tonic-gate extern int	svc_create();
9877c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_tp_create();
9887c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_tli_create();
9897c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_vc_create();
9907c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_dg_create();
9917c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_fd_create();
9927c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_raw_create();
9937c478bd9Sstevel@tonic-gate extern SVCXPRT	*svc_door_create();
9947c478bd9Sstevel@tonic-gate extern int svc_dg_enablecache();
9957c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
9967c478bd9Sstevel@tonic-gate 
99745916cd2Sjpk extern boolean_t is_multilevel(rpcprog_t);
99845916cd2Sjpk 
9997c478bd9Sstevel@tonic-gate #ifdef	PORTMAP
10007c478bd9Sstevel@tonic-gate /* For backward compatibility */
10017c478bd9Sstevel@tonic-gate #include <rpc/svc_soc.h>
10027c478bd9Sstevel@tonic-gate #endif	/* PORTMAP */
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate /*
10057c478bd9Sstevel@tonic-gate  * For user level MT hot server functions
10067c478bd9Sstevel@tonic-gate  */
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate /*
10097c478bd9Sstevel@tonic-gate  * Different MT modes
10107c478bd9Sstevel@tonic-gate  */
10117c478bd9Sstevel@tonic-gate #define	RPC_SVC_MT_NONE		0	/* default, single-threaded */
10127c478bd9Sstevel@tonic-gate #define	RPC_SVC_MT_AUTO		1	/* automatic MT mode */
10137c478bd9Sstevel@tonic-gate #define	RPC_SVC_MT_USER		2	/* user MT mode */
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate #ifdef	__STDC__
10167c478bd9Sstevel@tonic-gate extern void	svc_done(SVCXPRT *);
10177c478bd9Sstevel@tonic-gate #else
10187c478bd9Sstevel@tonic-gate extern void	svc_done();
10197c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
10207c478bd9Sstevel@tonic-gate 
10217c478bd9Sstevel@tonic-gate /*
10227c478bd9Sstevel@tonic-gate  * Obtaining local credentials.
10237c478bd9Sstevel@tonic-gate  */
10247c478bd9Sstevel@tonic-gate typedef struct __svc_local_cred_t {
10257c478bd9Sstevel@tonic-gate 	uid_t	euid;	/* effective uid */
10267c478bd9Sstevel@tonic-gate 	gid_t	egid;	/* effective gid */
10277c478bd9Sstevel@tonic-gate 	uid_t	ruid;	/* real uid */
10287c478bd9Sstevel@tonic-gate 	gid_t	rgid;	/* real gid */
10297c478bd9Sstevel@tonic-gate 	pid_t	pid;	/* caller's pid, or -1 if not available */
10307c478bd9Sstevel@tonic-gate } svc_local_cred_t;
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate #ifdef __STDC__
10337c478bd9Sstevel@tonic-gate struct ucred_s;
10347c478bd9Sstevel@tonic-gate extern void	svc_fd_negotiate_ucred(int);
10357c478bd9Sstevel@tonic-gate extern int	svc_getcallerucred(const SVCXPRT *, struct ucred_s **);
10367c478bd9Sstevel@tonic-gate extern bool_t	svc_get_local_cred(SVCXPRT *, svc_local_cred_t *);
10377c478bd9Sstevel@tonic-gate #else
10387c478bd9Sstevel@tonic-gate extern void	svc_fd_negotiate_ucred();
10397c478bd9Sstevel@tonic-gate extern int	svc_getcallerucred();
10407c478bd9Sstevel@tonic-gate extern bool_t	svc_get_local_cred();
10417c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate /*
10447c478bd9Sstevel@tonic-gate  * Private interfaces and structures for user level duplicate request caching.
10457c478bd9Sstevel@tonic-gate  * The interfaces and data structures are not committed and subject to
10467c478bd9Sstevel@tonic-gate  * change in future releases. Currently only intended for use by automountd.
10477c478bd9Sstevel@tonic-gate  */
10487c478bd9Sstevel@tonic-gate struct dupreq {
10497c478bd9Sstevel@tonic-gate 	uint32_t	dr_xid;
10507c478bd9Sstevel@tonic-gate 	rpcproc_t	dr_proc;
10517c478bd9Sstevel@tonic-gate 	rpcvers_t	dr_vers;
10527c478bd9Sstevel@tonic-gate 	rpcprog_t	dr_prog;
10537c478bd9Sstevel@tonic-gate 	struct netbuf	dr_addr;
10547c478bd9Sstevel@tonic-gate 	struct netbuf	dr_resp;
10557c478bd9Sstevel@tonic-gate 	int		dr_status;
10567c478bd9Sstevel@tonic-gate 	time_t		dr_time;
10577c478bd9Sstevel@tonic-gate 	uint_t		dr_hash;
10587c478bd9Sstevel@tonic-gate 	struct dupreq	*dr_next;
10597c478bd9Sstevel@tonic-gate 	struct dupreq	*dr_prev;
10607c478bd9Sstevel@tonic-gate 	struct dupreq	*dr_chain;
10617c478bd9Sstevel@tonic-gate 	struct dupreq	*dr_prevchain;
10627c478bd9Sstevel@tonic-gate };
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate /*
10657c478bd9Sstevel@tonic-gate  * The fixedtime state is defined if we want to expand the routines to
10667c478bd9Sstevel@tonic-gate  * handle and encompass fixed size caches.
10677c478bd9Sstevel@tonic-gate  */
10687c478bd9Sstevel@tonic-gate #define	DUPCACHE_FIXEDTIME	0
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate /*
10717c478bd9Sstevel@tonic-gate  * States of requests for duplicate request caching.
10727c478bd9Sstevel@tonic-gate  * These are the same as defined for the kernel.
10737c478bd9Sstevel@tonic-gate  */
10747c478bd9Sstevel@tonic-gate #define	DUP_NEW			0x00	/* new entry */
10757c478bd9Sstevel@tonic-gate #define	DUP_INPROGRESS		0x01	/* request already going */
10767c478bd9Sstevel@tonic-gate #define	DUP_DONE		0x02	/* request done */
10777c478bd9Sstevel@tonic-gate #define	DUP_DROP		0x03	/* request dropped */
10787c478bd9Sstevel@tonic-gate #define	DUP_ERROR		0x04	/* error in dup req cache */
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate #ifdef __STDC__
10817c478bd9Sstevel@tonic-gate extern bool_t	__svc_dupcache_init(void *, int, char **);
10827c478bd9Sstevel@tonic-gate extern int	__svc_dup(struct svc_req *, caddr_t *, uint_t *, char *);
10837c478bd9Sstevel@tonic-gate extern int	__svc_dupdone(struct svc_req *, caddr_t, uint_t, int, char *);
10847c478bd9Sstevel@tonic-gate extern bool_t	__svc_vc_dupcache_init(SVCXPRT *, void *, int);
10857c478bd9Sstevel@tonic-gate extern int	__svc_vc_dup(struct svc_req *, caddr_t *, uint_t *);
10867c478bd9Sstevel@tonic-gate extern int	__svc_vc_dupdone(struct svc_req *, caddr_t, uint_t, int);
10877c478bd9Sstevel@tonic-gate #else
10887c478bd9Sstevel@tonic-gate extern bool_t	__svc_dupcache_init();
10897c478bd9Sstevel@tonic-gate extern int	__svc_dup();
10907c478bd9Sstevel@tonic-gate extern int	__svc_dupdone();
10917c478bd9Sstevel@tonic-gate extern bool_t	__svc_vc_dupcache_init();
10927c478bd9Sstevel@tonic-gate extern int	__svc_vc_dup();
10937c478bd9Sstevel@tonic-gate extern int	__svc_vc_dupdone();
10947c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
10957c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
10987c478bd9Sstevel@tonic-gate }
10997c478bd9Sstevel@tonic-gate #endif
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate #endif	/* !_RPC_SVC_H */
1102