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