xref: /illumos-gate/usr/src/uts/common/rpc/svc.h (revision ec14ab0836cae822dfbc08b0d971d65179a2d06b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2012 Marcel Telka <marcel@telka.sk>
24  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
25  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
26  */
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29 /*
30  * Portions of this source code were derived from Berkeley
31  * 4.3 BSD under license from the Regents of the University of
32  * California.
33  */
34 
35 /*
36  * svc.h, Server-side remote procedure call interface.
37  */
38 
39 #ifndef	_RPC_SVC_H
40 #define	_RPC_SVC_H
41 
42 #include <rpc/rpc_com.h>
43 #include <rpc/rpc_msg.h>
44 #include <sys/tihdr.h>
45 #include <sys/poll.h>
46 #include <sys/tsol/label.h>
47 
48 #ifdef	_KERNEL
49 #include <rpc/svc_auth.h>
50 #include <rpc/rpc_tags.h>
51 #include <sys/callb.h>
52 #endif	/* _KERNEL */
53 
54 /*
55  * This interface must manage two items concerning remote procedure calling:
56  *
57  * 1) An arbitrary number of transport connections upon which rpc requests
58  * are received. They are created and registered by routines in svc_generic.c,
59  * svc_vc.c and svc_dg.c; they in turn call xprt_register and
60  * xprt_unregister.
61  *
62  * 2) An arbitrary number of locally registered services.  Services are
63  * described by the following four data: program number, version number,
64  * "service dispatch" function, a transport handle, and a boolean that
65  * indicates whether or not the exported program should be registered with a
66  * local binder service;  if true the program's number and version and the
67  * address from the transport handle are registered with the binder.
68  * These data are registered with rpcbind via svc_reg().
69  *
70  * A service's dispatch function is called whenever an rpc request comes in
71  * on a transport.  The request's program and version numbers must match
72  * those of the registered service.  The dispatch function is passed two
73  * parameters, struct svc_req * and SVCXPRT *, defined below.
74  */
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
80 /*
81  * Server-side transport handles.
82  * The actual type definitions are below.
83  */
84 #ifdef	_KERNEL
85 typedef struct __svcmasterxprt	SVCMASTERXPRT;	/* Master transport handle */
86 typedef struct __svcxprt	SVCXPRT;	/* Per-thread clone handle */
87 typedef	struct __svcpool	SVCPOOL;	/* Kernel thread pool	   */
88 #else	/* _KERNEL */
89 typedef struct __svcxprt	SVCXPRT;	/* Server transport handle */
90 #endif	/* _KERNEL */
91 
92 /*
93  *  Prototype of error handler callback
94  */
95 #ifndef _KERNEL
96 typedef void (*svc_errorhandler_t)(const SVCXPRT* svc, const bool_t isAConn);
97 #endif
98 
99 /*
100  * Service request.
101  *
102  * PSARC 2003/523 Contract Private Interface
103  * svc_req
104  * Changes must be reviewed by Solaris File Sharing
105  * Changes must be communicated to contract-2003-523@sun.com
106  */
107 struct svc_req {
108 	rpcprog_t	rq_prog;	/* service program number */
109 	rpcvers_t	rq_vers;	/* service protocol version */
110 	rpcproc_t	rq_proc;	/* the desired procedure */
111 	struct opaque_auth rq_cred;	/* raw creds from the wire */
112 	caddr_t		rq_clntcred;	/* read only cooked cred */
113 	SVCXPRT		*rq_xprt;	/* associated transport */
114 	bslabel_t	*rq_label;	/* TSOL label of the request */
115 };
116 
117 #ifdef _KERNEL
118 struct dupreq {
119 	uint32_t	dr_xid;
120 	rpcproc_t	dr_proc;
121 	rpcvers_t	dr_vers;
122 	rpcprog_t	dr_prog;
123 	struct netbuf	dr_addr;
124 	struct netbuf	dr_resp;
125 	void		(*dr_resfree)();
126 	int		dr_status;
127 	struct dupreq	*dr_next;
128 	struct dupreq	*dr_chain;
129 };
130 
131 /*
132  * States of requests for duplicate request caching.
133  */
134 #define	DUP_NEW			0x00	/* new entry */
135 #define	DUP_INPROGRESS		0x01	/* request already going */
136 #define	DUP_DONE		0x02	/* request done */
137 #define	DUP_DROP		0x03	/* request dropped */
138 #define	DUP_ERROR		0x04	/* error in dup req cache */
139 
140 /*
141  * Prototype for a service dispatch routine.
142  */
143 typedef void (SVC_DISPATCH)(struct svc_req *, SVCXPRT *);
144 
145 /*
146  * The service provider callout.
147  * Each entry identifies a dispatch routine to be called
148  * for a given RPC program number and a version fitting
149  * into the registered range.
150  */
151 typedef struct {
152 	rpcprog_t	sc_prog;	/* RPC Program number */
153 	rpcvers_t	sc_versmin;	/* Min version number */
154 	rpcvers_t	sc_versmax;	/* Max version number */
155 	SVC_DISPATCH	*sc_dispatch;	/* Dispatch routine   */
156 } SVC_CALLOUT;
157 
158 /*
159  * Table of service provider `callouts' for an RPC
160  * transport handle. If sct_free is TRUE then transport
161  * destructor is supposed to deallocate this table.
162  */
163 typedef struct {
164 	size_t		sct_size;	/* Number of entries  */
165 	bool_t		sct_free;	/* Deallocate if true */
166 	SVC_CALLOUT	*sct_sc;	/* Callout entries    */
167 } SVC_CALLOUT_TABLE;
168 
169 struct svc_ops {
170 	bool_t	(*xp_recv)(SVCXPRT *, mblk_t *, struct rpc_msg *);
171 		/* receive incoming requests */
172 	bool_t	(*xp_getargs)(SVCXPRT *, xdrproc_t, caddr_t);
173 		/* get arguments */
174 	bool_t	(*xp_reply)(SVCXPRT *, struct rpc_msg *);
175 		/* send reply */
176 	bool_t	(*xp_freeargs)(SVCXPRT *, xdrproc_t, caddr_t);
177 		/* free mem allocated for args */
178 	void	(*xp_destroy)(SVCMASTERXPRT *);
179 		/* destroy this struct */
180 	int	(*xp_dup)(struct svc_req *, caddr_t, int,
181 				struct dupreq **, bool_t *);
182 		/* check for dup */
183 	void	(*xp_dupdone)(struct dupreq *, caddr_t, void (*)(), int, int);
184 		/* mark dup entry as completed */
185 	int32_t *(*xp_getres)(SVCXPRT *, int);
186 		/* get pointer to response buffer */
187 	void	(*xp_freeres)(SVCXPRT *);
188 		/* destroy pre-serialized response */
189 	void	(*xp_clone_destroy)(SVCXPRT *);
190 		/* destroy a clone xprt */
191 	void	(*xp_start)(SVCMASTERXPRT *);
192 		/* `ready-to-receive' */
193 	void	(*xp_clone_xprt)(SVCXPRT *, SVCXPRT *);
194 		/* transport specific clone function */
195 	void	(*xp_tattrs)(SVCXPRT *, int, void **);
196 		/* kernel level control */
197 	int	(*xp_ctl)(SVCXPRT *, int, void *);
198 		/* transport specific hold function */
199 	void	(*xp_hold)(queue_t *);
200 		/* transport specific release function */
201 	void	(*xp_release)(queue_t *, mblk_t *, bool_t);
202 };
203 
204 /*
205  * Kernel SVC Control Requests.
206  */
207 #define	SVCCTL_SET_ASD		1
208 #define	SVCCTL_GET_ASD		2
209 #define	SVCCTL_SET_CBCONN	3
210 #define	SVCCTL_SET_TAG		4
211 #define	SVCCTL_SET_TAG_CLEAR	5
212 #define	SVCCTL_CMP_TAG		6
213 
214 #define	SVC_TATTR_ADDRMASK	1
215 
216 #else	/* _KERNEL */
217 /*
218  *	Service control requests
219  */
220 #define	SVCGET_VERSQUIET	1
221 #define	SVCSET_VERSQUIET	2
222 #define	SVCGET_XID		4
223 #define	SVCSET_KEEPALIVE	5
224 #define	SVCSET_CONNMAXREC	6
225 #define	SVCGET_CONNMAXREC	7
226 #define	SVCGET_RECVERRHANDLER	8
227 #define	SVCSET_RECVERRHANDLER	9
228 
229 enum xprt_stat {
230 	XPRT_DIED,
231 	XPRT_MOREREQS,
232 	XPRT_IDLE
233 };
234 
235 struct xp_ops {
236 #ifdef	__STDC__
237 	bool_t	(*xp_recv)(SVCXPRT *, struct rpc_msg *);
238 		/* receive incoming requests */
239 	enum xprt_stat (*xp_stat)(SVCXPRT *);
240 		/* get transport status */
241 	bool_t	(*xp_getargs)(SVCXPRT *, xdrproc_t, caddr_t);
242 		/* get arguments */
243 	bool_t	(*xp_reply)(SVCXPRT *,	struct rpc_msg *);
244 		/* send reply */
245 	bool_t	(*xp_freeargs)(SVCXPRT *, xdrproc_t, caddr_t);
246 		/* free mem allocated for args */
247 	void	(*xp_destroy)(SVCXPRT *);
248 		/* destroy this struct */
249 	bool_t	(*xp_control)(SVCXPRT *, const uint_t,	void *);
250 		/* catch-all control function */
251 #else	/* __STDC__ */
252 	bool_t	(*xp_recv)(); /* receive incoming requests */
253 	enum xprt_stat (*xp_stat)(); /* get transport status */
254 	bool_t	(*xp_getargs)(); /* get arguments */
255 	bool_t	(*xp_reply)(); /* send reply */
256 	bool_t	(*xp_freeargs)(); /* free mem allocated for args */
257 	void	(*xp_destroy)(); /* destroy this struct */
258 	bool_t	(*xp_control)(); /* catch-all control function */
259 #endif	/* __STDC__ */
260 };
261 #endif	/* _KERNEL */
262 
263 #ifdef	_KERNEL
264 /*
265  * SVCPOOL
266  * Kernel RPC server-side thread pool structure.
267  */
268 typedef struct __svcxprt_qnode __SVCXPRT_QNODE;	/* Defined in svc.c */
269 
270 struct __svcpool {
271 	/*
272 	 * Thread pool variables.
273 	 *
274 	 * The pool's thread lock p_thread_lock protects:
275 	 * - p_threads, p_detached_threads, p_reserved_threads and p_closing
276 	 * The pool's request lock protects:
277 	 * - p_asleep, p_drowsy, p_reqs, p_size, p_walkers, p_req_cv.
278 	 * The following fields are `initialized constants':
279 	 * - p_id, p_stksize, p_timeout.
280 	 * Access to p_next and p_prev is protected by the pool
281 	 * list lock.
282 	 */
283 	SVCPOOL		*p_next;		/* Next pool in the list  */
284 	SVCPOOL		*p_prev;		/* Prev pool in the list  */
285 	int		p_id;			/* Pool id		  */
286 	int		p_threads;		/* Non-detached threads	  */
287 	int		p_detached_threads;	/* Detached threads	  */
288 	int		p_maxthreads;		/* Max threads in the pool */
289 	int		p_redline;		/* `Redline' for the pool */
290 	int		p_reserved_threads;	/* Reserved threads	  */
291 	kmutex_t	p_thread_lock;		/* Thread lock		  */
292 	int		p_asleep;		/* Asleep threads	  */
293 	int		p_drowsy;		/* Drowsy flag		  */
294 	kcondvar_t	p_req_cv;		/* svc_poll() sleep var.  */
295 	clock_t		p_timeout;		/* svc_poll() timeout	  */
296 	kmutex_t	p_req_lock;		/* Request lock		  */
297 	int		p_reqs;			/* Pending requests	  */
298 	int		p_walkers;		/* Walking threads	  */
299 	int		p_max_same_xprt;	/* Max reqs from the xprt */
300 	int		p_stksize;		/* Stack size for svc_run */
301 	bool_t		p_closing : 1;		/* Pool is closing	  */
302 
303 	/*
304 	 * Thread creator variables.
305 	 * The `creator signaled' flag is turned on when a signal is send
306 	 * to the creator thread (to create a new service thread). The
307 	 * creator clears when the thread is created. The protocol is not
308 	 * to signal the creator thread when the flag is on. However,
309 	 * a new thread should signal the creator if there are more
310 	 * requests in the queue.
311 	 *
312 	 * When the pool is closing (ie it has been already unregistered from
313 	 * the pool list) the last thread on the last transport should turn
314 	 * the p_creator_exit flag on. This tells the creator thread to
315 	 * free the pool structure and exit.
316 	 */
317 	bool_t		p_creator_signaled : 1;	/* Create requested flag  */
318 	bool_t		p_creator_exit : 1;	/* If true creator exits  */
319 	kcondvar_t	p_creator_cv;		/* Creator cond. variable */
320 	kmutex_t	p_creator_lock;		/* Creator lock		  */
321 
322 	/*
323 	 * Doubly linked list containing `registered' master transport handles.
324 	 * There is no special structure for a list node. Instead the
325 	 * SVCMASTERXPRT structure has the xp_next and xp_prev fields.
326 	 *
327 	 * The p_lrwlock protects access to xprt->xp_next and xprt->xp_prev.
328 	 * A service thread should also acquire a reader lock before accessing
329 	 * any transports it is no longer linked to (to prevent them from
330 	 * being destroyed).
331 	 *
332 	 * The list lock governs also the `pool is closing' flag.
333 	 */
334 	size_t		p_lcount;		/* Current count	  */
335 	SVCMASTERXPRT	*p_lhead;		/* List head		  */
336 	krwlock_t	p_lrwlock;		/* R/W lock		  */
337 
338 	/*
339 	 * Circular linked list for the `xprt-ready' queue (FIFO).
340 	 * Must be initialized with svc_xprt_qinit() before it is used.
341 	 *
342 	 * The writer's end is protected by the pool's request lock
343 	 * (pool->p_req_lock). The reader's end is protected by q_end_lock.
344 	 *
345 	 * When the queue is full the p_qoverflow flag is raised. It stays
346 	 * on until all the pending request are drained.
347 	 */
348 	size_t		p_qsize;		/* Number of queue nodes  */
349 	int		p_qoverflow : 1;	/* Overflow flag	  */
350 	__SVCXPRT_QNODE *p_qbody;		/* Queue body (array)	  */
351 	__SVCXPRT_QNODE *p_qtop;		/* Writer's end of FIFO   */
352 	__SVCXPRT_QNODE *p_qend;		/* Reader's end of FIFO	  */
353 	kmutex_t	p_qend_lock;		/* Reader's end lock	  */
354 
355 	/*
356 	 * Userspace thread creator variables.
357 	 * Thread creation is actually done in userland, via a thread
358 	 * that is parked in the kernel. When that thread is signaled,
359 	 * it returns back down to the daemon from whence it came and
360 	 * does the lwp create.
361 	 *
362 	 * A parallel "creator" thread runs in the kernel. That is the
363 	 * thread that will signal for the user thread to return to
364 	 * userland and do its work.
365 	 *
366 	 * Since the thread doesn't always exist (there could be a race
367 	 * if two threads are created in rapid succession), we set
368 	 * p_signal_create_thread to FALSE when we're ready to accept work.
369 	 *
370 	 * p_user_exit is set to true when the service pool is about
371 	 * to close. This is done so that the user creation thread
372 	 * can be informed and cleanup any userland state.
373 	 */
374 
375 	bool_t		p_signal_create_thread : 1; /* Create requested flag  */
376 	bool_t		p_user_exit : 1;	/* If true creator exits  */
377 	bool_t		p_user_waiting : 1;	/* Thread waiting for work */
378 	kcondvar_t	p_user_cv;		/* Creator cond. variable */
379 	kmutex_t	p_user_lock;		/* Creator lock		  */
380 	void		(*p_offline)();		/* callout for unregister */
381 	void		(*p_shutdown)();	/* callout for shutdown */
382 
383 	size_t		p_size;			/* Total size of queued msgs */
384 };
385 
386 /*
387  * Server side transport handle (SVCMASTERXPRT).
388  * xprt->xp_req_lock governs the following fields in xprt:
389  *		xp_req_head, xp_req_tail.
390  * xprt->xp_thread_lock governs the following fields in xprt:
391  *		xp_threads, xp_detached_threads.
392  *
393  * xp_req_tail is only valid if xp_req_head is non-NULL
394  *
395  * The xp_threads count is the number of attached threads.  These threads
396  * are able to handle new requests, and it is expected that they will not
397  * block for a very long time handling a given request. The
398  * xp_detached_threads count is the number of threads that have detached
399  * themselves from the transport. These threads can block indefinitely
400  * while handling a request.  Once they complete the request, they exit.
401  *
402  * A kernel service provider may register a callback function "closeproc"
403  * for a transport.  When the transport is closing the last exiting attached
404  * thread - xp_threads goes to zero - it calls the callback function, passing
405  * it a reference to the transport.  This call is made with xp_thread_lock
406  * held, so any cleanup bookkeeping it does should be done quickly.
407  *
408  * When the transport is closing the last exiting thread is supposed
409  * to destroy/free the data structure.
410  */
411 typedef struct __svcxprt_common {
412 	struct file	*xpc_fp;
413 	struct svc_ops	*xpc_ops;
414 	queue_t		*xpc_wq;	/* queue to write onto		*/
415 	cred_t		*xpc_cred;	/* cached cred for server to use */
416 	int32_t		xpc_type;	/* transport type		*/
417 	int		xpc_msg_size;	/* TSDU or TIDU size		*/
418 	struct netbuf	xpc_rtaddr;	/* remote transport address	*/
419 	struct netbuf	xpc_lcladdr;	/* local transport address	*/
420 	char		*xpc_netid;	/* network token		*/
421 	void		*xpc_tags;	/* network token		*/
422 	SVC_CALLOUT_TABLE *xpc_sct;
423 } __SVCXPRT_COMMON;
424 
425 #define	xp_fp		xp_xpc.xpc_fp
426 #define	xp_ops		xp_xpc.xpc_ops
427 #define	xp_wq		xp_xpc.xpc_wq
428 #define	xp_cred		xp_xpc.xpc_cred
429 #define	xp_type		xp_xpc.xpc_type
430 #define	xp_msg_size	xp_xpc.xpc_msg_size
431 #define	xp_rtaddr	xp_xpc.xpc_rtaddr
432 #define	xp_lcladdr	xp_xpc.xpc_lcladdr
433 #define	xp_sct		xp_xpc.xpc_sct
434 #define	xp_netid	xp_xpc.xpc_netid
435 #define	xp_tags		xp_xpc.xpc_tags
436 
437 struct __svcmasterxprt {
438 	SVCMASTERXPRT	*xp_next;	/* Next transport in the list	*/
439 	SVCMASTERXPRT	*xp_prev;	/* Prev transport in the list	*/
440 	__SVCXPRT_COMMON xp_xpc;	/* Fields common with the clone	*/
441 	SVCPOOL		*xp_pool;	/* Pointer to the pool		*/
442 	mblk_t		*xp_req_head;	/* Request queue head		*/
443 	mblk_t		*xp_req_tail;	/* Request queue tail		*/
444 	kmutex_t	xp_req_lock;	/* Request lock			*/
445 	int		xp_threads;	/* Current num. of attached threads */
446 	int		xp_detached_threads; /* num. of detached threads */
447 	kmutex_t	xp_thread_lock;	/* Thread count lock		*/
448 	void		(*xp_closeproc)(const SVCMASTERXPRT *);
449 					/* optional; see comments above	*/
450 	struct netbuf	xp_addrmask;	/* address mask			*/
451 
452 	caddr_t		xp_p2;		/* private: for use by svc ops  */
453 
454 	int		xp_full : 1;	/* xprt is full			*/
455 	int		xp_enable : 1;	/* xprt needs to be enabled	*/
456 	int		xp_reqs;	/* number of requests queued	*/
457 	size_t		xp_size;	/* total size of queued msgs	*/
458 };
459 
460 typedef struct __svccb_args {
461 	SVCMASTERXPRT *xprt;
462 	rpcprog_t prog;
463 	rpcvers_t vers;
464 	int family;
465 	void *tag;
466 } SVCCB_ARGS;
467 
468 /*
469  * Service thread `clone' transport handle (SVCXPRT)
470  *
471  * PSARC 2003/523 Contract Private Interface
472  * SVCXPRT
473  * Changes must be reviewed by Solaris File Sharing
474  * Changes must be communicated to contract-2003-523@sun.com
475  *
476  * The xp_p2buf buffer is used as the storage for a transport type
477  * specific structure. It is private for the svc ops for a given
478  * transport type.
479  */
480 
481 #define	SVC_P2LEN   128
482 
483 struct __svcxprt {
484 	__SVCXPRT_COMMON xp_xpc;
485 	SVCMASTERXPRT	*xp_master;	/* back ptr to master		*/
486 
487 	/* The following fileds are on a per-thread basis */
488 	callb_cpr_t	*xp_cprp;	/* unused padding for Contract	*/
489 	bool_t		xp_reserved : 1; /* is thread reserved?		*/
490 	bool_t		xp_detached : 1; /* is thread detached?		*/
491 	int		xp_same_xprt;	/* Reqs from the same xprt	*/
492 
493 	/* The following fields are used on a per-request basis */
494 	struct opaque_auth xp_verf;	/* raw response verifier	*/
495 	SVCAUTH		xp_auth;	/* auth flavor of current req	*/
496 	void		*xp_cookie;	/* a cookie			*/
497 	uint32_t	xp_xid;		/* id				*/
498 	XDR		xp_xdrin;	/* input xdr stream		*/
499 	XDR		xp_xdrout;	/* output xdr stream		*/
500 
501 	/* Private for svc ops */
502 	char		xp_p2buf[SVC_P2LEN]; /* udp_data or cots_data_t */
503 						/* or clone_rdma_data_t */
504 	void		*xp_asd;
505 };
506 #else	/* _KERNEL */
507 struct __svcxprt {
508 	int		xp_fd;
509 #define	xp_sock		xp_fd
510 	ushort_t	xp_port;
511 	/*
512 	 * associated port number.
513 	 * Obsolete, but still used to
514 	 * specify whether rendezvouser
515 	 * or normal connection
516 	 */
517 	struct	xp_ops	*xp_ops;
518 	int		xp_addrlen;	/* length of remote addr. Obsoleted */
519 	char		*xp_tp;		/* transport provider device name */
520 	char		*xp_netid;	/* network token */
521 	struct netbuf	xp_ltaddr;	/* local transport address */
522 	struct netbuf	xp_rtaddr;	/* remote transport address */
523 	char		xp_raddr[16];	/* remote address. Now obsoleted */
524 	struct opaque_auth xp_verf;	/* raw response verifier */
525 	caddr_t		xp_p1;		/* private: for use by svc ops */
526 	caddr_t		xp_p2;		/* private: for use by svc ops */
527 	caddr_t		xp_p3;		/* private: for use by svc lib */
528 	int		xp_type;	/* transport type */
529 	/*
530 	 * callback on client death
531 	 * First parameter is the current structure,
532 	 * Second parameter :
533 	 *	- FALSE for the service listener
534 	 *	- TRUE for a real connected socket
535 	 */
536 	svc_errorhandler_t xp_closeclnt;
537 };
538 #endif	/* _KERNEL */
539 
540 /*
541  *  Approved way of getting address of caller,
542  *  address mask, and netid of transport.
543  */
544 #define	svc_getrpccaller(x) (&(x)->xp_rtaddr)
545 #define	svc_getrpchost(x) (&(x)->xp_lcladdr)
546 #ifdef _KERNEL
547 #define	svc_getcaller(x) (&(x)->xp_rtaddr.buf)
548 #define	svc_getaddrmask(x) (&(x)->xp_master->xp_addrmask)
549 #define	svc_getnetid(x) ((x)->xp_netid)
550 #endif	/* _KERNEL */
551 
552 /*
553  * Operations defined on an SVCXPRT handle
554  */
555 
556 #ifdef	_KERNEL
557 
558 #define	SVC_GETADDRMASK(clone_xprt, attrflag, tattr) \
559 (*(clone_xprt)->xp_ops->xp_tattrs)((clone_xprt), (attrflag), (tattr))
560 
561 #define	SVC_CLONE_XPRT(src_xprt, dst_xprt) \
562 	if ((src_xprt)->xp_ops->xp_clone_xprt) \
563 		(*(src_xprt)->xp_ops->xp_clone_xprt) \
564 		    (src_xprt, dst_xprt)
565 
566 #define	SVC_HOLD(xprt) \
567 	if ((xprt)->xp_ops->xp_hold) \
568 		(*(xprt)->xp_ops->xp_hold)((xprt)->xp_wq)
569 
570 #define	SVC_RELE(xprt, mp, enable) \
571 	if ((xprt)->xp_ops->xp_release) \
572 		(*(xprt)->xp_ops->xp_release)((xprt)->xp_wq, (mp), (enable))
573 
574 #define	SVC_RECV(clone_xprt, mp, msg) \
575 	(*(clone_xprt)->xp_ops->xp_recv)((clone_xprt), (mp), (msg))
576 
577 /*
578  * PSARC 2003/523 Contract Private Interface
579  * SVC_GETARGS
580  * Changes must be reviewed by Solaris File Sharing
581  * Changes must be communicated to contract-2003-523@sun.com
582  */
583 #define	SVC_GETARGS(clone_xprt, xargs, argsp) \
584 	(*(clone_xprt)->xp_ops->xp_getargs)((clone_xprt), (xargs), (argsp))
585 
586 #define	SVC_REPLY(clone_xprt, msg) \
587 	(*(clone_xprt)->xp_ops->xp_reply) ((clone_xprt), (msg))
588 
589 #define	SVC_FREEARGS(clone_xprt, xargs, argsp) \
590 	(*(clone_xprt)->xp_ops->xp_freeargs)((clone_xprt), (xargs), (argsp))
591 
592 #define	SVC_GETRES(clone_xprt, size) \
593 	(*(clone_xprt)->xp_ops->xp_getres)((clone_xprt), (size))
594 
595 #define	SVC_FREERES(clone_xprt)	\
596 	(*(clone_xprt)->xp_ops->xp_freeres)(clone_xprt)
597 
598 #define	SVC_DESTROY(xprt) \
599 	(*(xprt)->xp_ops->xp_destroy)(xprt)
600 
601 /*
602  * PSARC 2003/523 Contract Private Interfaces
603  * SVC_DUP, SVC_DUPDONE, SVC_DUP_EXT, SVC_DUPDONE_EXT
604  * Changes must be reviewed by Solaris File Sharing
605  * Changes must be communicated to contract-2003-523@sun.com
606  *
607  * SVC_DUP and SVC_DUPDONE are defined here for backward compatibility.
608  */
609 #define	SVC_DUP_EXT(clone_xprt, req, res, size, drpp, dupcachedp) \
610 	(*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, dupcachedp)
611 
612 #define	SVC_DUPDONE_EXT(clone_xprt, dr, res, resfree, size, status) \
613 	(*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, resfree, size, status)
614 
615 #define	SVC_DUP(clone_xprt, req, res, size, drpp) \
616 	(*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, NULL)
617 
618 #define	SVC_DUPDONE(clone_xprt, dr, res, size, status) \
619 	(*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, NULL, size, status)
620 
621 #define	SVC_CLONE_DESTROY(clone_xprt) \
622 	(*(clone_xprt)->xp_ops->xp_clone_destroy)(clone_xprt)
623 
624 
625 #define	SVC_START(xprt) \
626 	(*(xprt)->xp_ops->xp_start)(xprt)
627 
628 #define	SVC_CTL(clone_xprt, rq, arg) \
629 	(*(clone_xprt)->xp_ops->xp_ctl)((clone_xprt), (rq), (arg))
630 
631 #else	/* _KERNEL */
632 
633 #define	SVC_RECV(xprt, msg) \
634 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
635 #define	svc_recv(xprt, msg) \
636 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
637 
638 #define	SVC_STAT(xprt) \
639 	(*(xprt)->xp_ops->xp_stat)(xprt)
640 #define	svc_stat(xprt) \
641 	(*(xprt)->xp_ops->xp_stat)(xprt)
642 
643 #define	SVC_GETARGS(xprt, xargs, argsp) \
644 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
645 #define	svc_getargs(xprt, xargs, argsp)	\
646 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
647 
648 #define	SVC_REPLY(xprt, msg) \
649 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
650 #define	svc_reply(xprt, msg) \
651 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
652 
653 #define	SVC_FREEARGS(xprt, xargs, argsp) \
654 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
655 #define	svc_freeargs(xprt, xargs, argsp) \
656 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
657 
658 #define	SVC_GETRES(xprt, size) \
659 	(*(xprt)->xp_ops->xp_getres)((xprt), (size))
660 #define	svc_getres(xprt, size) \
661 	(*(xprt)->xp_ops->xp_getres)((xprt), (size))
662 
663 #define	SVC_FREERES(xprt) \
664 	(*(xprt)->xp_ops->xp_freeres)(xprt)
665 #define	svc_freeres(xprt) \
666 	(*(xprt)->xp_ops->xp_freeres)(xprt)
667 
668 #define	SVC_DESTROY(xprt) \
669 	(*(xprt)->xp_ops->xp_destroy)(xprt)
670 #define	svc_destroy(xprt) \
671 	(*(xprt)->xp_ops->xp_destroy)(xprt)
672 
673 /*
674  * PSARC 2003/523 Contract Private Interface
675  * SVC_CONTROL
676  * Changes must be reviewed by Solaris File Sharing
677  * Changes must be communicated to contract-2003-523@sun.com
678  */
679 #define	SVC_CONTROL(xprt, rq, in) \
680 	(*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
681 #endif	/* _KERNEL */
682 
683 /*
684  * Pool id's reserved for NFS, NLM, and the NFSv4 callback program.
685  */
686 #define	NFS_SVCPOOL_ID		0x01
687 #define	NLM_SVCPOOL_ID		0x02
688 #define	NFS_CB_SVCPOOL_ID	0x03
689 #define	RDC_SVCPOOL_ID		0x05	/* SNDR, PSARC 2001/699 */
690 
691 struct svcpool_args {
692 	uint32_t	id;		/* Pool id */
693 	uint32_t	maxthreads;	/* Max threads in the pool */
694 	uint32_t	redline;	/* `Redline' for the pool */
695 	uint32_t	qsize;		/* `xprt-ready' queue size */
696 	uint32_t	timeout;	/* svc_poll() timeout */
697 	uint32_t	stksize;	/* svc_run() stack size */
698 	uint32_t	max_same_xprt;	/* Max reqs from the same xprt */
699 };
700 
701 
702 #ifdef	_KERNEL
703 /*
704  * Transport registration and thread pool creation.
705  */
706 extern int	svc_xprt_register(SVCMASTERXPRT *, int);
707 extern void	svc_xprt_unregister(SVCMASTERXPRT *);
708 extern int	svc_pool_create(struct svcpool_args *);
709 extern int	svc_wait(int);
710 extern int	svc_do_run(int);
711 #define	SVCPSET_SHUTDOWN_PROC	1
712 #define	SVCPSET_UNREGISTER_PROC	2
713 extern int	svc_pool_control(int, int, void *);
714 #else	/* _KERNEL */
715 #ifdef	__STDC__
716 extern bool_t	rpc_reg(const rpcprog_t, const rpcvers_t, const rpcproc_t,
717 			char *(*)(char *), const xdrproc_t, const xdrproc_t,
718 			const char *);
719 
720 /*
721  * Service registration
722  *
723  * svc_reg(xprt, prog, vers, dispatch, nconf)
724  *	const SVCXPRT *xprt;
725  *	const rpcprog_t prog;
726  *	const rpcvers_t vers;
727  *	const void (*dispatch)();
728  *	const struct netconfig *nconf;
729  */
730 extern bool_t	svc_reg(const SVCXPRT *, const rpcprog_t, const rpcvers_t,
731 			void (*)(struct svc_req *, SVCXPRT *),
732 			const struct netconfig *);
733 
734 /*
735  * Service authentication registration
736  *
737  * svc_auth_reg(cred_flavor, handler)
738  *    int cred_flavor;
739  *    enum auth_stat (*handler)();
740  */
741 extern int	svc_auth_reg(int, enum auth_stat (*)());
742 
743 /*
744  * Service un-registration
745  *
746  * svc_unreg(prog, vers)
747  *	const rpcprog_t prog;
748  *	const rpcvers_t vers;
749  */
750 extern void	svc_unreg(const rpcprog_t, const rpcvers_t);
751 
752 /*
753  * Transport registration/unregistration.
754  *
755  * xprt_register(xprt)
756  *	const SVCXPRT *xprt;
757  *
758  * xprt_unregister(xprt)
759  *	const SVCXPRT *xprt;
760  */
761 extern void	xprt_register(const SVCXPRT *);
762 extern void	xprt_unregister(const SVCXPRT *);
763 #else	/* __STDC__ */
764 extern bool_t	rpc_reg();
765 extern bool_t	svc_reg();
766 extern bool_t	svc_auth_reg();
767 extern void	svc_unreg();
768 extern void	xprt_register();
769 extern void	xprt_unregister();
770 #endif /* __STDC__ */
771 #endif	/* _KERNEL */
772 
773 #ifdef _KERNEL
774 /*
775  * Transport hold and release.
776  */
777 extern void rpcmod_hold(queue_t *);
778 extern void rpcmod_release(queue_t *, mblk_t *, bool_t);
779 extern void mir_svc_hold(queue_t *);
780 extern void mir_svc_release(queue_t *, mblk_t *, bool_t);
781 #endif /* _KERNEL */
782 
783 /*
784  * When the service routine is called, it must first check to see if it
785  * knows about the procedure;  if not, it should call svcerr_noproc
786  * and return.  If so, it should deserialize its arguments via
787  * SVC_GETARGS (defined above).  If the deserialization does not work,
788  * svcerr_decode should be called followed by a return.  Successful
789  * decoding of the arguments should be followed the execution of the
790  * procedure's code and a call to svc_sendreply.
791  *
792  * Also, if the service refuses to execute the procedure due to too-
793  * weak authentication parameters, svcerr_weakauth should be called.
794  * Note: do not confuse access-control failure with weak authentication!
795  *
796  * NB: In pure implementations of rpc, the caller always waits for a reply
797  * msg.  This message is sent when svc_sendreply is called.
798  * Therefore pure service implementations should always call
799  * svc_sendreply even if the function logically returns void;  use
800  * xdr.h - xdr_void for the xdr routine.  HOWEVER, connectionful rpc allows
801  * for the abuse of pure rpc via batched calling or pipelining.  In the
802  * case of a batched call, svc_sendreply should NOT be called since
803  * this would send a return message, which is what batching tries to avoid.
804  * It is the service/protocol writer's responsibility to know which calls are
805  * batched and which are not.  Warning: responding to batch calls may
806  * deadlock the caller and server processes!
807  */
808 #ifdef	__STDC__
809 extern bool_t	svc_sendreply(const SVCXPRT *, const xdrproc_t,	const caddr_t);
810 extern void	svcerr_decode(const SVCXPRT *);
811 extern void	svcerr_weakauth(const SVCXPRT *);
812 extern void	svcerr_noproc(const SVCXPRT *);
813 extern void	svcerr_progvers(const SVCXPRT *, const rpcvers_t,
814     const rpcvers_t);
815 extern void	svcerr_auth(const SVCXPRT *, const enum auth_stat);
816 extern void	svcerr_noprog(const SVCXPRT *);
817 extern void	svcerr_systemerr(const SVCXPRT *);
818 extern void	svcerr_badcred(const SVCXPRT *);
819 #else	/* __STDC__ */
820 extern bool_t	svc_sendreply();
821 extern void	svcerr_decode();
822 extern void	svcerr_weakauth();
823 extern void	svcerr_noproc();
824 extern void	svcerr_progvers();
825 extern void	svcerr_auth();
826 extern void	svcerr_noprog();
827 extern void	svcerr_systemerr();
828 extern void	svcerr_badcred();
829 #endif	/* __STDC__ */
830 
831 #ifdef	_KERNEL
832 /*
833  * Kernel RPC functions.
834  */
835 extern void	svc_init(void);
836 extern void	svc_cots_init(void);
837 extern void	svc_clts_init(void);
838 extern void	mt_kstat_init(void);
839 extern void	mt_kstat_fini(void);
840 extern int	svc_tli_kcreate(struct file *, uint_t, char *,
841 				struct netbuf *, SVCMASTERXPRT **,
842 				SVC_CALLOUT_TABLE *,
843 				void (*closeproc)(const SVCMASTERXPRT *),
844 				int, bool_t);
845 extern int	svc_clts_kcreate(struct file *, uint_t, struct T_info_ack *,
846 				SVCMASTERXPRT **);
847 extern int	svc_cots_kcreate(struct file *, uint_t, struct T_info_ack *,
848 				SVCMASTERXPRT **);
849 extern bool_t	svc_queuereq(queue_t *, mblk_t *, bool_t);
850 extern void	svc_queueclean(queue_t *);
851 extern void	svc_queueclose(queue_t *);
852 extern int	svc_reserve_thread(SVCXPRT *);
853 extern void	svc_unreserve_thread(SVCXPRT *);
854 extern callb_cpr_t *svc_detach_thread(SVCXPRT *);
855 
856 /*
857  * For RDMA based kRPC.
858  * "rdma_xprt_record" is a reference to master transport handles
859  * in kRPC thread pools. This is an easy way of tracking and shuting
860  * down rdma based kRPC transports on demand.
861  * "rdma_xprt_group" is a list of RDMA based mster transport handles
862  * or records in a kRPC thread pool.
863  */
864 typedef struct rdma_xprt_record		rdma_xprt_record_t;
865 struct rdma_xprt_record {
866 	int			rtr_type;	/* Type of rdma; IB/VI/RDDP */
867 	SVCMASTERXPRT		*rtr_xprt_ptr;	/* Ptr to master xprt handle */
868 	rdma_xprt_record_t	*rtr_next;	/* Ptr to next record */
869 };
870 
871 typedef struct {
872 	int			rtg_count;	/* Number transport records */
873 	int			rtg_poolid;	/* Pool Id for this group */
874 	rdma_xprt_record_t	*rtg_listhead;	/* Head of the records list */
875 } rdma_xprt_group_t;
876 
877 extern int	svc_rdma_kcreate(char *, SVC_CALLOUT_TABLE *, int,
878 			rdma_xprt_group_t *);
879 extern void	svc_rdma_kstop(SVCMASTERXPRT *);
880 extern void	svc_rdma_kdestroy(SVCMASTERXPRT *);
881 extern void	rdma_stop(rdma_xprt_group_t *);
882 
883 /*
884  * GSS cleanup method.
885  */
886 extern void	rpc_gss_cleanup(SVCXPRT *);
887 #else	/* _KERNEL */
888 /*
889  * Lowest level dispatching -OR- who owns this process anyway.
890  * Somebody has to wait for incoming requests and then call the correct
891  * service routine.  The routine svc_run does infinite waiting; i.e.,
892  * svc_run never returns.
893  * Since another (co-existant) package may wish to selectively wait for
894  * incoming calls or other events outside of the rpc architecture, the
895  * routine svc_getreq_poll is provided.  It must be passed pollfds, the
896  * "in-place" results of a poll call (see poll, section 2).
897  */
898 
899 /*
900  * Global keeper of rpc service descriptors in use
901  * dynamic; must be inspected before each call to select or poll
902  */
903 extern pollfd_t	*svc_pollfd;
904 extern int	svc_max_pollfd;
905 extern fd_set	svc_fdset;
906 #define	svc_fds svc_fdset.fds_bits[0]	/* compatibility */
907 
908 /*
909  * A small program implemented by the svc_rpc implementation itself.
910  * Also see clnt.h for protocol numbers.
911  */
912 #ifdef __STDC__
913 extern void	svc_getreq(int);
914 extern void	svc_getreq_common(const int);
915 extern void	svc_getreqset(fd_set *); /* takes fdset instead of int */
916 extern void	svc_getreq_poll(struct pollfd *, const int);
917 extern void	svc_run(void);
918 extern void	svc_exit(void);
919 #else	/* __STDC__ */
920 extern void	rpctest_service();
921 extern void	svc_getreqset();
922 extern void	svc_getreq();
923 extern void	svc_getreq_common();
924 extern void	svc_getreqset();	 /* takes fdset instead of int */
925 extern void	svc_getreq_poll();
926 extern void	svc_run();
927 extern void	svc_exit();
928 #endif	/* __STDC__ */
929 
930 /*
931  *  Functions used to manage user file descriptors
932  */
933 typedef int svc_input_id_t;
934 typedef void (*svc_callback_t)(svc_input_id_t id, int fd,
935 				unsigned int events, void* cookie);
936 
937 #ifdef __STDC__
938 extern svc_input_id_t svc_add_input(int fd, unsigned int events,
939 				svc_callback_t user_callback,
940 				void* cookie);
941 extern int svc_remove_input(svc_input_id_t id);
942 #else	/* __STDC__ */
943 extern svc_input_id_t svc_add_input();
944 extern int	svc_remove_input();
945 #endif
946 
947 /*
948  * These are the existing service side transport implementations.
949  *
950  * Transport independent svc_create routine.
951  */
952 #ifdef __STDC__
953 extern int	svc_create(void (*)(struct svc_req *, SVCXPRT *),
954 				const rpcprog_t, const rpcvers_t,
955 				const char *);
956 	/*
957 	 *	void (*dispatch)();		-- dispatch routine
958 	 *	const rpcprog_t prognum;	-- program number
959 	 *	const rpcvers_t versnum;	-- version number
960 	 *	const char *nettype;		-- network type
961 	 */
962 
963 /*
964  * Generic server creation routine. It takes a netconfig structure
965  * instead of a nettype.
966  */
967 extern SVCXPRT	*svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
968 				const rpcprog_t, const rpcvers_t,
969 				const struct netconfig *);
970 	/*
971 	 * void (*dispatch)();			-- dispatch routine
972 	 * const rpcprog_t prognum;		-- program number
973 	 * const rpcvers_t versnum;		-- version number
974 	 * const struct netconfig *nconf;	-- netconfig structure
975 	 */
976 
977 /*
978  * Variant of svc_tp_create that accepts a binding address.
979  * If addr == NULL, this is the same as svc_tp_create().
980  */
981 extern SVCXPRT	*svc_tp_create_addr(void (*)(struct svc_req *, SVCXPRT *),
982 				const rpcprog_t, const rpcvers_t,
983 				const struct netconfig *,
984 				const struct netbuf *);
985 	/*
986 	 * void (*dispatch)();			-- dispatch routine
987 	 * const rpcprog_t prognum;		-- program number
988 	 * const rpcvers_t versnum;		-- version number
989 	 * const struct netconfig *nconf;	-- netconfig structure
990 	 * const struct netbuf *addr;		-- address to bind
991 	 */
992 
993 /*
994  * Generic TLI create routine
995  */
996 extern  SVCXPRT	*svc_tli_create(const int, const struct netconfig *,
997 				const struct t_bind *, const uint_t,
998 				const uint_t);
999 	/*
1000 	 *	const int fd;			-- connection end point
1001 	 *	const struct netconfig *nconf;	-- netconfig structure
1002 	 *	const struct t_bind *bindaddr;	-- local bind address
1003 	 *	const uint_t sendsz;		-- max sendsize
1004 	 *	const uint_t recvsz;		-- max recvsize
1005 	 */
1006 
1007 /*
1008  * Connectionless and connectionful create routines.
1009  */
1010 extern SVCXPRT	*svc_vc_create(const int, const uint_t, const uint_t);
1011 	/*
1012 	 *	const int fd;			-- open connection end point
1013 	 *	const uint_t sendsize;		-- max send size
1014 	 *	const uint_t recvsize;		-- max recv size
1015 	 */
1016 
1017 extern SVCXPRT	*svc_dg_create(const int, const uint_t, const uint_t);
1018 	/*
1019 	 * const int fd;			-- open connection
1020 	 * const uint_t sendsize;		-- max send size
1021 	 * const uint_t recvsize;		-- max recv size
1022 	 */
1023 
1024 /*
1025  * the routine takes any *open* TLI file
1026  * descriptor as its first input and is used for open connections.
1027  */
1028 extern  SVCXPRT	*svc_fd_create(const int, const uint_t, const uint_t);
1029 	/*
1030 	 *	const int fd;			-- open connection end point
1031 	 *	const uint_t sendsize;		-- max send size
1032 	 *	const uint_t recvsize;		-- max recv size
1033 	 */
1034 
1035 /*
1036  * Memory based rpc (for speed check and testing)
1037  */
1038 extern SVCXPRT	*svc_raw_create(void);
1039 
1040 /*
1041  * Creation of service over doors transport.
1042  */
1043 extern SVCXPRT	*svc_door_create(void (*)(struct svc_req *, SVCXPRT *),
1044 				const rpcprog_t, const rpcvers_t,
1045 				const uint_t);
1046 	/*
1047 	 *	void (*dispatch)();		-- dispatch routine
1048 	 *	const rpcprog_t prognum;	-- program number
1049 	 *	const rpcvers_t versnum;	-- version number
1050 	 *	const uint_t sendsize;		-- send buffer size
1051 	 */
1052 
1053 /*
1054  * Service control interface
1055  */
1056 extern	bool_t	svc_control(SVCXPRT *, const uint_t, void *);
1057 	/*
1058 	 *	SVCXPRT *svc;			-- service to manipulate
1059 	 *	const uint_t req;		-- request
1060 	 *	void *info;			-- argument to request
1061 	 */
1062 
1063 /*
1064  * svc_dg_enable_cache() enables the cache on dg transports.
1065  */
1066 extern int svc_dg_enablecache(SVCXPRT *, const uint_t);
1067 #else	/* __STDC__ */
1068 extern int	svc_create();
1069 extern SVCXPRT	*svc_tp_create();
1070 extern SVCXPRT	*svc_tli_create();
1071 extern SVCXPRT	*svc_vc_create();
1072 extern SVCXPRT	*svc_dg_create();
1073 extern SVCXPRT	*svc_fd_create();
1074 extern SVCXPRT	*svc_raw_create();
1075 extern SVCXPRT	*svc_door_create();
1076 extern int svc_dg_enablecache();
1077 #endif	/* __STDC__ */
1078 
1079 extern boolean_t is_multilevel(rpcprog_t);
1080 
1081 #ifdef	PORTMAP
1082 /* For backward compatibility */
1083 #include <rpc/svc_soc.h>
1084 #endif	/* PORTMAP */
1085 
1086 /*
1087  * For user level MT hot server functions
1088  */
1089 
1090 /*
1091  * Different MT modes
1092  */
1093 #define	RPC_SVC_MT_NONE		0	/* default, single-threaded */
1094 #define	RPC_SVC_MT_AUTO		1	/* automatic MT mode */
1095 #define	RPC_SVC_MT_USER		2	/* user MT mode */
1096 
1097 #ifdef	__STDC__
1098 extern void	svc_done(SVCXPRT *);
1099 #else
1100 extern void	svc_done();
1101 #endif	/* __STDC__ */
1102 
1103 /*
1104  * Obtaining local credentials.
1105  */
1106 typedef struct __svc_local_cred_t {
1107 	uid_t	euid;	/* effective uid */
1108 	gid_t	egid;	/* effective gid */
1109 	uid_t	ruid;	/* real uid */
1110 	gid_t	rgid;	/* real gid */
1111 	pid_t	pid;	/* caller's pid, or -1 if not available */
1112 } svc_local_cred_t;
1113 
1114 #ifdef __STDC__
1115 struct ucred_s;
1116 extern void	svc_fd_negotiate_ucred(int);
1117 extern int	svc_getcallerucred(const SVCXPRT *, struct ucred_s **);
1118 extern bool_t	svc_get_local_cred(SVCXPRT *, svc_local_cred_t *);
1119 #else
1120 extern void	svc_fd_negotiate_ucred();
1121 extern int	svc_getcallerucred();
1122 extern bool_t	svc_get_local_cred();
1123 #endif	/* __STDC__ */
1124 
1125 /*
1126  * Private interfaces and structures for user level duplicate request caching.
1127  * The interfaces and data structures are not committed and subject to
1128  * change in future releases. Currently only intended for use by automountd.
1129  */
1130 struct dupreq {
1131 	uint32_t	dr_xid;
1132 	rpcproc_t	dr_proc;
1133 	rpcvers_t	dr_vers;
1134 	rpcprog_t	dr_prog;
1135 	struct netbuf	dr_addr;
1136 	struct netbuf	dr_resp;
1137 	int		dr_status;
1138 	time_t		dr_time;
1139 	uint_t		dr_hash;
1140 	struct dupreq	*dr_next;
1141 	struct dupreq	*dr_prev;
1142 	struct dupreq	*dr_chain;
1143 	struct dupreq	*dr_prevchain;
1144 };
1145 
1146 /*
1147  * The fixedtime state is defined if we want to expand the routines to
1148  * handle and encompass fixed size caches.
1149  */
1150 #define	DUPCACHE_FIXEDTIME	0
1151 
1152 /*
1153  * States of requests for duplicate request caching.
1154  * These are the same as defined for the kernel.
1155  */
1156 #define	DUP_NEW			0x00	/* new entry */
1157 #define	DUP_INPROGRESS		0x01	/* request already going */
1158 #define	DUP_DONE		0x02	/* request done */
1159 #define	DUP_DROP		0x03	/* request dropped */
1160 #define	DUP_ERROR		0x04	/* error in dup req cache */
1161 
1162 #ifdef __STDC__
1163 extern bool_t	__svc_dupcache_init(void *, int, char **);
1164 extern int	__svc_dup(struct svc_req *, caddr_t *, uint_t *, char *);
1165 extern int	__svc_dupdone(struct svc_req *, caddr_t, uint_t, int, char *);
1166 extern bool_t	__svc_vc_dupcache_init(SVCXPRT *, void *, int);
1167 extern int	__svc_vc_dup(struct svc_req *, caddr_t *, uint_t *);
1168 extern int	__svc_vc_dupdone(struct svc_req *, caddr_t, uint_t, int);
1169 #else
1170 extern bool_t	__svc_dupcache_init();
1171 extern int	__svc_dup();
1172 extern int	__svc_dupdone();
1173 extern bool_t	__svc_vc_dupcache_init();
1174 extern int	__svc_vc_dup();
1175 extern int	__svc_vc_dupdone();
1176 #endif	/* __STDC__ */
1177 #endif	/* _KERNEL */
1178 
1179 #ifdef	_KERNEL
1180 /*
1181  * Private interfaces and structures for SVCXPRT cloning.
1182  * The interfaces and data structures are not committed and subject to
1183  * change in future releases.
1184  */
1185 extern SVCXPRT *svc_clone_init(void);
1186 extern void svc_init_clone_xprt(SVCXPRT *, queue_t *);
1187 extern void svc_clone_free(SVCXPRT *);
1188 extern void svc_clone_link(SVCMASTERXPRT *, SVCXPRT *, SVCXPRT *);
1189 extern void svc_clone_unlink(SVCXPRT *);
1190 
1191 /* Get cached preallocated cred */
1192 extern cred_t *svc_xprt_cred(SVCXPRT *);
1193 #endif	/* _KERNEL */
1194 
1195 #ifdef	__cplusplus
1196 }
1197 #endif
1198 
1199 #endif	/* !_RPC_SVC_H */
1200