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.
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.
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]
22 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
28 * Portions of this source code were derived from Berkeley
29 * 4.3 BSD under license from the Regents of the University of
34 * svc.h, Server-side remote procedure call interface.
40 #include <rpc/rpc_com.h>
41 #include <rpc/rpc_msg.h>
42 #include <sys/tihdr.h>
46 #include <rpc/svc_auth.h>
47 #include <sys/callb.h>
51 * This interface must manage two items concerning remote procedure calling:
53 * 1) An arbitrary number of transport connections upon which rpc requests
54 * are received. They are created and registered by routines in svc_generic.c,
55 * svc_vc.c and svc_dg.c; they in turn call xprt_register and
58 * 2) An arbitrary number of locally registered services. Services are
59 * described by the following four data: program number, version number,
60 * "service dispatch" function, a transport handle, and a boolean that
61 * indicates whether or not the exported program should be registered with a
62 * local binder service; if true the program's number and version and the
63 * address from the transport handle are registered with the binder.
64 * These data are registered with rpcbind via svc_reg().
66 * A service's dispatch function is called whenever an rpc request comes in
67 * on a transport. The request's program and version numbers must match
68 * those of the registered service. The dispatch function is passed two
69 * parameters, struct svc_req * and SVCXPRT *, defined below.
77 * Server-side transport handles.
78 * The actual type definitions are below.
81 typedef struct __svcmasterxprt SVCMASTERXPRT
; /* Master transport handle */
82 typedef struct __svcxprt SVCXPRT
; /* Per-thread clone handle */
83 typedef struct __svcpool SVCPOOL
; /* Kernel thread pool */
85 typedef struct __svcxprt SVCXPRT
; /* Server transport handle */
89 * Prototype of error handler callback
92 typedef void (*svc_errorhandler_t
)(const SVCXPRT
* svc
, const bool_t isAConn
);
98 * PSARC 2003/523 Contract Private Interface
100 * Changes must be reviewed by Solaris File Sharing
101 * Changes must be communicated to contract-2003-523@sun.com
104 rpcprog_t rq_prog
; /* service program number */
105 rpcvers_t rq_vers
; /* service protocol version */
106 rpcproc_t rq_proc
; /* the desired procedure */
107 struct opaque_auth rq_cred
; /* raw creds from the wire */
108 caddr_t rq_clntcred
; /* read only cooked cred */
109 SVCXPRT
*rq_xprt
; /* associated transport */
118 struct netbuf dr_addr
;
119 struct netbuf dr_resp
;
120 void (*dr_resfree
)();
122 struct dupreq
*dr_next
;
123 struct dupreq
*dr_chain
;
127 * States of requests for duplicate request caching.
129 #define DUP_NEW 0x00 /* new entry */
130 #define DUP_INPROGRESS 0x01 /* request already going */
131 #define DUP_DONE 0x02 /* request done */
132 #define DUP_DROP 0x03 /* request dropped */
133 #define DUP_ERROR 0x04 /* error in dup req cache */
136 * Prototype for a service dispatch routine.
138 typedef void (SVC_DISPATCH
)(struct svc_req
*, SVCXPRT
*);
141 * The service provider callout.
142 * Each entry identifies a dispatch routine to be called
143 * for a given RPC program number and a version fitting
144 * into the registered range.
147 rpcprog_t sc_prog
; /* RPC Program number */
148 rpcvers_t sc_versmin
; /* Min version number */
149 rpcvers_t sc_versmax
; /* Max version number */
150 SVC_DISPATCH
*sc_dispatch
; /* Dispatch routine */
154 * Table of service provider `callouts' for an RPC
155 * transport handle. If sct_free is TRUE then transport
156 * destructor is supposed to deallocate this table.
159 size_t sct_size
; /* Number of entries */
160 bool_t sct_free
; /* Deallocate if true */
161 SVC_CALLOUT
*sct_sc
; /* Callout entries */
165 bool_t (*xp_recv
)(SVCXPRT
*, mblk_t
*, struct rpc_msg
*);
166 /* receive incoming requests */
167 bool_t (*xp_getargs
)(SVCXPRT
*, xdrproc_t
, caddr_t
);
169 bool_t (*xp_reply
)(SVCXPRT
*, struct rpc_msg
*);
171 bool_t (*xp_freeargs
)(SVCXPRT
*, xdrproc_t
, caddr_t
);
172 /* free mem allocated for args */
173 void (*xp_destroy
)(SVCMASTERXPRT
*);
174 /* destroy this struct */
175 int (*xp_dup
)(struct svc_req
*, caddr_t
, int,
176 struct dupreq
**, bool_t
*);
178 void (*xp_dupdone
)(struct dupreq
*, caddr_t
, void (*)(), int, int);
179 /* mark dup entry as completed */
180 int32_t *(*xp_getres
)(SVCXPRT
*, int);
181 /* get pointer to response buffer */
182 void (*xp_freeres
)(SVCXPRT
*);
183 /* destroy pre-serialized response */
184 void (*xp_clone_destroy
)(SVCXPRT
*);
185 /* destroy a clone xprt */
186 void (*xp_start
)(SVCMASTERXPRT
*);
187 /* `ready-to-receive' */
188 void (*xp_clone_xprt
)(SVCXPRT
*, SVCXPRT
*);
189 /* transport specific clone function */
190 void (*xp_tattrs
) (SVCXPRT
*, int, void **);
193 #define SVC_TATTR_ADDRMASK 1
197 * Service control requests
199 #define SVCGET_VERSQUIET 1
200 #define SVCSET_VERSQUIET 2
202 #define SVCSET_KEEPALIVE 5
203 #define SVCSET_CONNMAXREC 6
204 #define SVCGET_CONNMAXREC 7
205 #define SVCGET_RECVERRHANDLER 8
206 #define SVCSET_RECVERRHANDLER 9
216 bool_t (*xp_recv
)(SVCXPRT
*, struct rpc_msg
*);
217 /* receive incoming requests */
218 enum xprt_stat (*xp_stat
)(SVCXPRT
*);
219 /* get transport status */
220 bool_t (*xp_getargs
)(SVCXPRT
*, xdrproc_t
, caddr_t
);
222 bool_t (*xp_reply
)(SVCXPRT
*, struct rpc_msg
*);
224 bool_t (*xp_freeargs
)(SVCXPRT
*, xdrproc_t
, caddr_t
);
225 /* free mem allocated for args */
226 void (*xp_destroy
)(SVCXPRT
*);
227 /* destroy this struct */
228 bool_t (*xp_control
)(SVCXPRT
*, const uint_t
, void *);
229 /* catch-all control function */
231 bool_t (*xp_recv
)(); /* receive incoming requests */
232 enum xprt_stat (*xp_stat
)(); /* get transport status */
233 bool_t (*xp_getargs
)(); /* get arguments */
234 bool_t (*xp_reply
)(); /* send reply */
235 bool_t (*xp_freeargs
)(); /* free mem allocated for args */
236 void (*xp_destroy
)(); /* destroy this struct */
237 bool_t (*xp_control
)(); /* catch-all control function */
238 #endif /* __STDC__ */
245 * Kernel RPC server-side thread pool structure.
247 typedef struct __svcxprt_qnode __SVCXPRT_QNODE
; /* Defined in svc.c */
251 * Thread pool variables.
253 * The pool's thread lock p_thread_lock protects:
254 * - p_threads, p_detached_threads, p_reserved_threads and p_closing
255 * The pool's request lock protects:
256 * - p_asleep, p_drowsy, p_reqs, p_size, p_walkers, p_req_cv.
257 * The following fields are `initialized constants':
258 * - p_id, p_stksize, p_timeout.
259 * Access to p_next and p_prev is protected by the pool
262 SVCPOOL
*p_next
; /* Next pool in the list */
263 SVCPOOL
*p_prev
; /* Prev pool in the list */
264 int p_id
; /* Pool id */
265 int p_threads
; /* Non-detached threads */
266 int p_detached_threads
; /* Detached threads */
267 int p_maxthreads
; /* Max threads in the pool */
268 int p_redline
; /* `Redline' for the pool */
269 int p_reserved_threads
; /* Reserved threads */
270 kmutex_t p_thread_lock
; /* Thread lock */
271 int p_asleep
; /* Asleep threads */
272 int p_drowsy
; /* Drowsy flag */
273 kcondvar_t p_req_cv
; /* svc_poll() sleep var. */
274 clock_t p_timeout
; /* svc_poll() timeout */
275 kmutex_t p_req_lock
; /* Request lock */
276 int p_reqs
; /* Pending requests */
277 int p_walkers
; /* Walking threads */
278 int p_max_same_xprt
; /* Max reqs from the xprt */
279 int p_stksize
; /* Stack size for svc_run */
280 bool_t p_closing
: 1; /* Pool is closing */
283 * Thread creator variables.
284 * The `creator signaled' flag is turned on when a signal is send
285 * to the creator thread (to create a new service thread). The
286 * creator clears when the thread is created. The protocol is not
287 * to signal the creator thread when the flag is on. However,
288 * a new thread should signal the creator if there are more
289 * requests in the queue.
291 * When the pool is closing (ie it has been already unregistered from
292 * the pool list) the last thread on the last transport should turn
293 * the p_creator_exit flag on. This tells the creator thread to
294 * free the pool structure and exit.
296 bool_t p_creator_signaled
: 1; /* Create requested flag */
297 bool_t p_creator_exit
: 1; /* If true creator exits */
298 kcondvar_t p_creator_cv
; /* Creator cond. variable */
299 kmutex_t p_creator_lock
; /* Creator lock */
302 * Doubly linked list containing `registered' master transport handles.
303 * There is no special structure for a list node. Instead the
304 * SVCMASTERXPRT structure has the xp_next and xp_prev fields.
306 * The p_lrwlock protects access to xprt->xp_next and xprt->xp_prev.
307 * A service thread should also acquire a reader lock before accessing
308 * any transports it is no longer linked to (to prevent them from
311 * The list lock governs also the `pool is closing' flag.
313 size_t p_lcount
; /* Current count */
314 SVCMASTERXPRT
*p_lhead
; /* List head */
315 krwlock_t p_lrwlock
; /* R/W lock */
318 * Circular linked list for the `xprt-ready' queue (FIFO).
319 * Must be initialized with svc_xprt_qinit() before it is used.
321 * The writer's end is protected by the pool's request lock
322 * (pool->p_req_lock). The reader's end is protected by q_end_lock.
324 * When the queue is full the p_qoverflow flag is raised. It stays
325 * on until all the pending request are drained.
327 size_t p_qsize
; /* Number of queue nodes */
328 int p_qoverflow
: 1; /* Overflow flag */
329 __SVCXPRT_QNODE
*p_qbody
; /* Queue body (array) */
330 __SVCXPRT_QNODE
*p_qtop
; /* Writer's end of FIFO */
331 __SVCXPRT_QNODE
*p_qend
; /* Reader's end of FIFO */
332 kmutex_t p_qend_lock
; /* Reader's end lock */
335 * Userspace thread creator variables.
336 * Thread creation is actually done in userland, via a thread
337 * that is parked in the kernel. When that thread is signaled,
338 * it returns back down to the daemon from whence it came and
339 * does the lwp create.
341 * A parallel "creator" thread runs in the kernel. That is the
342 * thread that will signal for the user thread to return to
343 * userland and do its work.
345 * Since the thread doesn't always exist (there could be a race
346 * if two threads are created in rapid succession), we set
347 * p_signal_create_thread to FALSE when we're ready to accept work.
349 * p_user_exit is set to true when the service pool is about
350 * to close. This is done so that the user creation thread
351 * can be informed and cleanup any userland state.
354 bool_t p_signal_create_thread
: 1; /* Create requested flag */
355 bool_t p_user_exit
: 1; /* If true creator exits */
356 bool_t p_user_waiting
: 1; /* Thread waiting for work */
357 kcondvar_t p_user_cv
; /* Creator cond. variable */
358 kmutex_t p_user_lock
; /* Creator lock */
359 void (*p_offline
)(); /* callout for unregister */
360 void (*p_shutdown
)(); /* callout for shutdown */
362 size_t p_size
; /* Total size of queued msgs */
366 * Server side transport handle (SVCMASTERXPRT).
367 * xprt->xp_req_lock governs the following fields in xprt:
368 * xp_req_head, xp_req_tail.
369 * xprt->xp_thread_lock governs the following fields in xprt:
370 * xp_threads, xp_detached_threads.
372 * xp_req_tail is only valid if xp_req_head is non-NULL
374 * The xp_threads count is the number of attached threads. These threads
375 * are able to handle new requests, and it is expected that they will not
376 * block for a very long time handling a given request. The
377 * xp_detached_threads count is the number of threads that have detached
378 * themselves from the transport. These threads can block indefinitely
379 * while handling a request. Once they complete the request, they exit.
381 * A kernel service provider may register a callback function "closeproc"
382 * for a transport. When the transport is closing the last exiting attached
383 * thread - xp_threads goes to zero - it calls the callback function, passing
384 * it a reference to the transport. This call is made with xp_thread_lock
385 * held, so any cleanup bookkeeping it does should be done quickly.
387 * When the transport is closing the last exiting thread is supposed
388 * to destroy/free the data structure.
390 typedef struct __svcxprt_common
{
392 struct svc_ops
*xpc_ops
;
393 queue_t
*xpc_wq
; /* queue to write onto */
394 cred_t
*xpc_cred
; /* cached cred for server to use */
395 int32_t xpc_type
; /* transport type */
396 int xpc_msg_size
; /* TSDU or TIDU size */
397 struct netbuf xpc_rtaddr
; /* remote transport address */
398 struct netbuf xpc_lcladdr
; /* local transport address */
399 char *xpc_netid
; /* network token */
400 SVC_CALLOUT_TABLE
*xpc_sct
;
403 #define xp_fp xp_xpc.xpc_fp
404 #define xp_ops xp_xpc.xpc_ops
405 #define xp_wq xp_xpc.xpc_wq
406 #define xp_cred xp_xpc.xpc_cred
407 #define xp_type xp_xpc.xpc_type
408 #define xp_msg_size xp_xpc.xpc_msg_size
409 #define xp_rtaddr xp_xpc.xpc_rtaddr
410 #define xp_lcladdr xp_xpc.xpc_lcladdr
411 #define xp_sct xp_xpc.xpc_sct
412 #define xp_netid xp_xpc.xpc_netid
414 struct __svcmasterxprt
{
415 SVCMASTERXPRT
*xp_next
; /* Next transport in the list */
416 SVCMASTERXPRT
*xp_prev
; /* Prev transport in the list */
417 __SVCXPRT_COMMON xp_xpc
; /* Fields common with the clone */
418 SVCPOOL
*xp_pool
; /* Pointer to the pool */
419 mblk_t
*xp_req_head
; /* Request queue head */
420 mblk_t
*xp_req_tail
; /* Request queue tail */
421 kmutex_t xp_req_lock
; /* Request lock */
422 int xp_threads
; /* Current num. of attached threads */
423 int xp_detached_threads
; /* num. of detached threads */
424 kmutex_t xp_thread_lock
; /* Thread count lock */
425 void (*xp_closeproc
)(const SVCMASTERXPRT
*);
426 /* optional; see comments above */
427 struct netbuf xp_addrmask
; /* address mask */
429 caddr_t xp_p2
; /* private: for use by svc ops */
431 int xp_full
: 1; /* xprt is full */
432 int xp_enable
: 1; /* xprt needs to be enabled */
433 int xp_reqs
; /* number of requests queued */
434 size_t xp_size
; /* total size of queued msgs */
438 * Service thread `clone' transport handle (SVCXPRT)
440 * PSARC 2003/523 Contract Private Interface
442 * Changes must be reviewed by Solaris File Sharing
443 * Changes must be communicated to contract-2003-523@sun.com
445 * The xp_p2buf buffer is used as the storage for a transport type
446 * specific structure. It is private for the svc ops for a given
450 #define SVC_P2LEN 128
453 __SVCXPRT_COMMON xp_xpc
;
454 SVCMASTERXPRT
*xp_master
; /* back ptr to master */
456 /* The following fileds are on a per-thread basis */
457 callb_cpr_t
*xp_cprp
; /* unused padding for Contract */
458 bool_t xp_reserved
: 1; /* is thread reserved? */
459 bool_t xp_detached
: 1; /* is thread detached? */
460 int xp_same_xprt
; /* Reqs from the same xprt */
462 /* The following fields are used on a per-request basis */
463 struct opaque_auth xp_verf
; /* raw response verifier */
464 SVCAUTH xp_auth
; /* auth flavor of current req */
465 void *xp_cookie
; /* a cookie */
466 uint32_t xp_xid
; /* id */
467 XDR xp_xdrin
; /* input xdr stream */
468 XDR xp_xdrout
; /* output xdr stream */
470 /* Private for svc ops */
471 char xp_p2buf
[SVC_P2LEN
]; /* udp_data or cots_data_t */
472 /* or clone_rdma_data_t */
477 #define xp_sock xp_fd
480 * associated port number.
481 * Obsolete, but still used to
482 * specify whether rendezvouser
483 * or normal connection
485 struct xp_ops
*xp_ops
;
486 int xp_addrlen
; /* length of remote addr. Obsoleted */
487 char *xp_tp
; /* transport provider device name */
488 char *xp_netid
; /* network token */
489 struct netbuf xp_ltaddr
; /* local transport address */
490 struct netbuf xp_rtaddr
; /* remote transport address */
491 char xp_raddr
[16]; /* remote address. Now obsoleted */
492 struct opaque_auth xp_verf
; /* raw response verifier */
493 caddr_t xp_p1
; /* private: for use by svc ops */
494 caddr_t xp_p2
; /* private: for use by svc ops */
495 caddr_t xp_p3
; /* private: for use by svc lib */
496 int xp_type
; /* transport type */
498 * callback on client death
499 * First parameter is the current structure,
501 * - FALSE for the service listener
502 * - TRUE for a real connected socket
504 svc_errorhandler_t xp_closeclnt
;
509 * Approved way of getting address of caller,
510 * address mask, and netid of transport.
512 #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
514 #define svc_getcaller(x) (&(x)->xp_rtaddr.buf)
515 #define svc_getaddrmask(x) (&(x)->xp_master->xp_addrmask)
516 #define svc_getnetid(x) ((x)->xp_netid)
520 * Operations defined on an SVCXPRT handle
525 #define SVC_GETADDRMASK(clone_xprt, attrflag, tattr) \
526 (*(clone_xprt)->xp_ops->xp_tattrs)((clone_xprt), (attrflag), (tattr))
528 #define SVC_CLONE_XPRT(src_xprt, dst_xprt) \
529 if ((src_xprt)->xp_ops->xp_clone_xprt) \
530 (*(src_xprt)->xp_ops->xp_clone_xprt) \
533 #define SVC_RECV(clone_xprt, mp, msg) \
534 (*(clone_xprt)->xp_ops->xp_recv)((clone_xprt), (mp), (msg))
537 * PSARC 2003/523 Contract Private Interface
539 * Changes must be reviewed by Solaris File Sharing
540 * Changes must be communicated to contract-2003-523@sun.com
542 #define SVC_GETARGS(clone_xprt, xargs, argsp) \
543 (*(clone_xprt)->xp_ops->xp_getargs)((clone_xprt), (xargs), (argsp))
545 #define SVC_REPLY(clone_xprt, msg) \
546 (*(clone_xprt)->xp_ops->xp_reply) ((clone_xprt), (msg))
548 #define SVC_FREEARGS(clone_xprt, xargs, argsp) \
549 (*(clone_xprt)->xp_ops->xp_freeargs)((clone_xprt), (xargs), (argsp))
551 #define SVC_GETRES(clone_xprt, size) \
552 (*(clone_xprt)->xp_ops->xp_getres)((clone_xprt), (size))
554 #define SVC_FREERES(clone_xprt) \
555 (*(clone_xprt)->xp_ops->xp_freeres)(clone_xprt)
557 #define SVC_DESTROY(xprt) \
558 (*(xprt)->xp_ops->xp_destroy)(xprt)
561 * PSARC 2003/523 Contract Private Interfaces
562 * SVC_DUP, SVC_DUPDONE, SVC_DUP_EXT, SVC_DUPDONE_EXT
563 * Changes must be reviewed by Solaris File Sharing
564 * Changes must be communicated to contract-2003-523@sun.com
566 * SVC_DUP and SVC_DUPDONE are defined here for backward compatibility.
568 #define SVC_DUP_EXT(clone_xprt, req, res, size, drpp, dupcachedp) \
569 (*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, dupcachedp)
571 #define SVC_DUPDONE_EXT(clone_xprt, dr, res, resfree, size, status) \
572 (*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, resfree, size, status)
574 #define SVC_DUP(clone_xprt, req, res, size, drpp) \
575 (*(clone_xprt)->xp_ops->xp_dup)(req, res, size, drpp, NULL)
577 #define SVC_DUPDONE(clone_xprt, dr, res, size, status) \
578 (*(clone_xprt)->xp_ops->xp_dupdone)(dr, res, NULL, size, status)
580 #define SVC_CLONE_DESTROY(clone_xprt) \
581 (*(clone_xprt)->xp_ops->xp_clone_destroy)(clone_xprt)
584 #define SVC_START(xprt) \
585 (*(xprt)->xp_ops->xp_start)(xprt)
589 #define SVC_RECV(xprt, msg) \
590 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
591 #define svc_recv(xprt, msg) \
592 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
594 #define SVC_STAT(xprt) \
595 (*(xprt)->xp_ops->xp_stat)(xprt)
596 #define svc_stat(xprt) \
597 (*(xprt)->xp_ops->xp_stat)(xprt)
599 #define SVC_GETARGS(xprt, xargs, argsp) \
600 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
601 #define svc_getargs(xprt, xargs, argsp) \
602 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
604 #define SVC_REPLY(xprt, msg) \
605 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
606 #define svc_reply(xprt, msg) \
607 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
609 #define SVC_FREEARGS(xprt, xargs, argsp) \
610 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
611 #define svc_freeargs(xprt, xargs, argsp) \
612 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
614 #define SVC_GETRES(xprt, size) \
615 (*(xprt)->xp_ops->xp_getres)((xprt), (size))
616 #define svc_getres(xprt, size) \
617 (*(xprt)->xp_ops->xp_getres)((xprt), (size))
619 #define SVC_FREERES(xprt) \
620 (*(xprt)->xp_ops->xp_freeres)(xprt)
621 #define svc_freeres(xprt) \
622 (*(xprt)->xp_ops->xp_freeres)(xprt)
624 #define SVC_DESTROY(xprt) \
625 (*(xprt)->xp_ops->xp_destroy)(xprt)
626 #define svc_destroy(xprt) \
627 (*(xprt)->xp_ops->xp_destroy)(xprt)
630 * PSARC 2003/523 Contract Private Interface
632 * Changes must be reviewed by Solaris File Sharing
633 * Changes must be communicated to contract-2003-523@sun.com
635 #define SVC_CONTROL(xprt, rq, in) \
636 (*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
640 * Pool id's reserved for NFS, NLM, and the NFSv4 callback program.
642 #define NFS_SVCPOOL_ID 0x01
643 #define NLM_SVCPOOL_ID 0x02
644 #define NFS_CB_SVCPOOL_ID 0x03
645 #define RDC_SVCPOOL_ID 0x05 /* SNDR, PSARC 2001/699 */
647 struct svcpool_args
{
648 uint32_t id
; /* Pool id */
649 uint32_t maxthreads
; /* Max threads in the pool */
650 uint32_t redline
; /* `Redline' for the pool */
651 uint32_t qsize
; /* `xprt-ready' queue size */
652 uint32_t timeout
; /* svc_poll() timeout */
653 uint32_t stksize
; /* svc_run() stack size */
654 uint32_t max_same_xprt
; /* Max reqs from the same xprt */
660 * Transport registration and thread pool creation.
662 extern int svc_xprt_register(SVCMASTERXPRT
*, int);
663 extern void svc_xprt_unregister(SVCMASTERXPRT
*);
664 extern int svc_pool_create(struct svcpool_args
*);
665 extern int svc_wait(int);
666 extern int svc_do_run(int);
667 #define SVCPSET_SHUTDOWN_PROC 1
668 #define SVCPSET_UNREGISTER_PROC 2
669 extern int svc_pool_control(int, int, void *);
672 extern bool_t
rpc_reg(const rpcprog_t
, const rpcvers_t
, const rpcproc_t
,
673 char *(*)(char *), const xdrproc_t
, const xdrproc_t
,
677 * Service registration
679 * svc_reg(xprt, prog, vers, dispatch, nconf)
680 * const SVCXPRT *xprt;
681 * const rpcprog_t prog;
682 * const rpcvers_t vers;
683 * const void (*dispatch)();
684 * const struct netconfig *nconf;
686 extern bool_t
svc_reg(const SVCXPRT
*, const rpcprog_t
, const rpcvers_t
,
687 void (*)(struct svc_req
*, SVCXPRT
*),
688 const struct netconfig
*);
691 * Service authentication registration
693 * svc_auth_reg(cred_flavor, handler)
695 * enum auth_stat (*handler)();
697 extern int svc_auth_reg(int, enum auth_stat (*)());
700 * Service un-registration
702 * svc_unreg(prog, vers)
703 * const rpcprog_t prog;
704 * const rpcvers_t vers;
706 extern void svc_unreg(const rpcprog_t
, const rpcvers_t
);
709 * Transport registration/unregistration.
711 * xprt_register(xprt)
712 * const SVCXPRT *xprt;
714 * xprt_unregister(xprt)
715 * const SVCXPRT *xprt;
717 extern void xprt_register(const SVCXPRT
*);
718 extern void xprt_unregister(const SVCXPRT
*);
720 extern bool_t
rpc_reg();
721 extern bool_t
svc_reg();
722 extern bool_t
svc_auth_reg();
723 extern void svc_unreg();
724 extern void xprt_register();
725 extern void xprt_unregister();
726 #endif /* __STDC__ */
731 * When the service routine is called, it must first check to see if it
732 * knows about the procedure; if not, it should call svcerr_noproc
733 * and return. If so, it should deserialize its arguments via
734 * SVC_GETARGS (defined above). If the deserialization does not work,
735 * svcerr_decode should be called followed by a return. Successful
736 * decoding of the arguments should be followed the execution of the
737 * procedure's code and a call to svc_sendreply.
739 * Also, if the service refuses to execute the procedure due to too-
740 * weak authentication parameters, svcerr_weakauth should be called.
741 * Note: do not confuse access-control failure with weak authentication!
743 * NB: In pure implementations of rpc, the caller always waits for a reply
744 * msg. This message is sent when svc_sendreply is called.
745 * Therefore pure service implementations should always call
746 * svc_sendreply even if the function logically returns void; use
747 * xdr.h - xdr_void for the xdr routine. HOWEVER, connectionful rpc allows
748 * for the abuse of pure rpc via batched calling or pipelining. In the
749 * case of a batched call, svc_sendreply should NOT be called since
750 * this would send a return message, which is what batching tries to avoid.
751 * It is the service/protocol writer's responsibility to know which calls are
752 * batched and which are not. Warning: responding to batch calls may
753 * deadlock the caller and server processes!
756 extern bool_t
svc_sendreply(const SVCXPRT
*, const xdrproc_t
, const caddr_t
);
757 extern void svcerr_decode(const SVCXPRT
*);
758 extern void svcerr_weakauth(const SVCXPRT
*);
759 extern void svcerr_noproc(const SVCXPRT
*);
760 extern void svcerr_progvers(const SVCXPRT
*, const rpcvers_t
,
762 extern void svcerr_auth(const SVCXPRT
*, const enum auth_stat
);
763 extern void svcerr_noprog(const SVCXPRT
*);
764 extern void svcerr_systemerr(const SVCXPRT
*);
765 extern void svcerr_badcred(const SVCXPRT
*);
767 extern bool_t
svc_sendreply();
768 extern void svcerr_decode();
769 extern void svcerr_weakauth();
770 extern void svcerr_noproc();
771 extern void svcerr_progvers();
772 extern void svcerr_auth();
773 extern void svcerr_noprog();
774 extern void svcerr_systemerr();
775 extern void svcerr_badcred();
776 #endif /* __STDC__ */
780 * Kernel RPC functions.
782 extern void svc_init(void);
783 extern void svc_cots_init(void);
784 extern void svc_clts_init(void);
785 extern void mt_kstat_init(void);
786 extern void mt_kstat_fini(void);
787 extern int svc_tli_kcreate(struct file
*, uint_t
, char *,
788 struct netbuf
*, SVCMASTERXPRT
**,
790 void (*closeproc
)(const SVCMASTERXPRT
*),
792 extern int svc_clts_kcreate(struct file
*, uint_t
, struct T_info_ack
*,
794 extern int svc_cots_kcreate(struct file
*, uint_t
, struct T_info_ack
*,
796 extern bool_t
svc_queuereq(queue_t
*, mblk_t
*, bool_t
);
797 extern void svc_queueclean(queue_t
*);
798 extern void svc_queueclose(queue_t
*);
799 extern int svc_reserve_thread(SVCXPRT
*);
800 extern void svc_unreserve_thread(SVCXPRT
*);
801 extern callb_cpr_t
*svc_detach_thread(SVCXPRT
*);
804 * For RDMA based kRPC.
805 * "rdma_xprt_record" is a reference to master transport handles
806 * in kRPC thread pools. This is an easy way of tracking and shuting
807 * down rdma based kRPC transports on demand.
808 * "rdma_xprt_group" is a list of RDMA based mster transport handles
809 * or records in a kRPC thread pool.
811 typedef struct rdma_xprt_record rdma_xprt_record_t
;
812 struct rdma_xprt_record
{
813 int rtr_type
; /* Type of rdma; IB/VI/RDDP */
814 SVCMASTERXPRT
*rtr_xprt_ptr
; /* Ptr to master xprt handle */
815 rdma_xprt_record_t
*rtr_next
; /* Ptr to next record */
819 int rtg_count
; /* Number transport records */
820 int rtg_poolid
; /* Pool Id for this group */
821 rdma_xprt_record_t
*rtg_listhead
; /* Head of the records list */
824 extern int svc_rdma_kcreate(char *, SVC_CALLOUT_TABLE
*, int,
825 rdma_xprt_group_t
*);
826 extern void svc_rdma_kstop(SVCMASTERXPRT
*);
827 extern void svc_rdma_kdestroy(SVCMASTERXPRT
*);
828 extern void rdma_stop(rdma_xprt_group_t
*);
831 * GSS cleanup method.
833 extern void rpc_gss_cleanup(SVCXPRT
*);
836 * Lowest level dispatching -OR- who owns this process anyway.
837 * Somebody has to wait for incoming requests and then call the correct
838 * service routine. The routine svc_run does infinite waiting; i.e.,
839 * svc_run never returns.
840 * Since another (co-existant) package may wish to selectively wait for
841 * incoming calls or other events outside of the rpc architecture, the
842 * routine svc_getreq_poll is provided. It must be passed pollfds, the
843 * "in-place" results of a poll call (see poll, section 2).
847 * Global keeper of rpc service descriptors in use
848 * dynamic; must be inspected before each call to select or poll
850 extern pollfd_t
*svc_pollfd
;
851 extern int svc_max_pollfd
;
852 extern fd_set svc_fdset
;
853 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
856 * A small program implemented by the svc_rpc implementation itself.
857 * Also see clnt.h for protocol numbers.
860 extern void svc_getreq(int);
861 extern void svc_getreq_common(const int);
862 extern void svc_getreqset(fd_set
*); /* takes fdset instead of int */
863 extern void svc_getreq_poll(struct pollfd
*, const int);
864 extern void svc_run(void);
865 extern void svc_exit(void);
867 extern void rpctest_service();
868 extern void svc_getreqset();
869 extern void svc_getreq();
870 extern void svc_getreq_common();
871 extern void svc_getreqset(); /* takes fdset instead of int */
872 extern void svc_getreq_poll();
873 extern void svc_run();
874 extern void svc_exit();
875 #endif /* __STDC__ */
878 * Functions used to manage user file descriptors
880 typedef int svc_input_id_t
;
881 typedef void (*svc_callback_t
)(svc_input_id_t id
, int fd
,
882 unsigned int events
, void* cookie
);
885 extern svc_input_id_t
svc_add_input(int fd
, unsigned int events
,
886 svc_callback_t user_callback
,
888 extern int svc_remove_input(svc_input_id_t id
);
890 extern svc_input_id_t
svc_add_input();
891 extern int svc_remove_input();
895 * These are the existing service side transport implementations.
897 * Transport independent svc_create routine.
900 extern int svc_create(void (*)(struct svc_req
*, SVCXPRT
*),
901 const rpcprog_t
, const rpcvers_t
,
904 * void (*dispatch)(); -- dispatch routine
905 * const rpcprog_t prognum; -- program number
906 * const rpcvers_t versnum; -- version number
907 * const char *nettype; -- network type
911 * Generic server creation routine. It takes a netconfig structure
912 * instead of a nettype.
914 extern SVCXPRT
*svc_tp_create(void (*)(struct svc_req
*, SVCXPRT
*),
915 const rpcprog_t
, const rpcvers_t
,
916 const struct netconfig
*);
918 * void (*dispatch)(); -- dispatch routine
919 * const rpcprog_t prognum; -- program number
920 * const rpcvers_t versnum; -- version number
921 * const struct netconfig *nconf; -- netconfig structure
925 * Generic TLI create routine
927 extern SVCXPRT
*svc_tli_create(const int, const struct netconfig
*,
928 const struct t_bind
*, const uint_t
,
931 * const int fd; -- connection end point
932 * const struct netconfig *nconf; -- netconfig structure
933 * const struct t_bind *bindaddr; -- local bind address
934 * const uint_t sendsz; -- max sendsize
935 * const uint_t recvsz; -- max recvsize
939 * Connectionless and connectionful create routines.
941 extern SVCXPRT
*svc_vc_create(const int, const uint_t
, const uint_t
);
943 * const int fd; -- open connection end point
944 * const uint_t sendsize; -- max send size
945 * const uint_t recvsize; -- max recv size
948 extern SVCXPRT
*svc_dg_create(const int, const uint_t
, const uint_t
);
950 * const int fd; -- open connection
951 * const uint_t sendsize; -- max send size
952 * const uint_t recvsize; -- max recv size
956 * the routine takes any *open* TLI file
957 * descriptor as its first input and is used for open connections.
959 extern SVCXPRT
*svc_fd_create(const int, const uint_t
, const uint_t
);
961 * const int fd; -- open connection end point
962 * const uint_t sendsize; -- max send size
963 * const uint_t recvsize; -- max recv size
967 * Memory based rpc (for speed check and testing)
969 extern SVCXPRT
*svc_raw_create(void);
972 * Creation of service over doors transport.
974 extern SVCXPRT
*svc_door_create(void (*)(struct svc_req
*, SVCXPRT
*),
975 const rpcprog_t
, const rpcvers_t
,
978 * void (*dispatch)(); -- dispatch routine
979 * const rpcprog_t prognum; -- program number
980 * const rpcvers_t versnum; -- version number
981 * const uint_t sendsize; -- send buffer size
985 * Service control interface
987 extern bool_t
svc_control(SVCXPRT
*, const uint_t
, void *);
989 * SVCXPRT *svc; -- service to manipulate
990 * const uint_t req; -- request
991 * void *info; -- argument to request
995 * svc_dg_enable_cache() enables the cache on dg transports.
997 extern int svc_dg_enablecache(SVCXPRT
*, const uint_t
);
999 extern int svc_create();
1000 extern SVCXPRT
*svc_tp_create();
1001 extern SVCXPRT
*svc_tli_create();
1002 extern SVCXPRT
*svc_vc_create();
1003 extern SVCXPRT
*svc_dg_create();
1004 extern SVCXPRT
*svc_fd_create();
1005 extern SVCXPRT
*svc_raw_create();
1006 extern SVCXPRT
*svc_door_create();
1007 extern int svc_dg_enablecache();
1008 #endif /* __STDC__ */
1010 extern boolean_t
is_multilevel(rpcprog_t
);
1013 /* For backward compatibility */
1014 #include <rpc/svc_soc.h>
1015 #endif /* PORTMAP */
1018 * For user level MT hot server functions
1022 * Different MT modes
1024 #define RPC_SVC_MT_NONE 0 /* default, single-threaded */
1025 #define RPC_SVC_MT_AUTO 1 /* automatic MT mode */
1026 #define RPC_SVC_MT_USER 2 /* user MT mode */
1029 extern void svc_done(SVCXPRT
*);
1031 extern void svc_done();
1032 #endif /* __STDC__ */
1035 * Obtaining local credentials.
1037 typedef struct __svc_local_cred_t
{
1038 uid_t euid
; /* effective uid */
1039 gid_t egid
; /* effective gid */
1040 uid_t ruid
; /* real uid */
1041 gid_t rgid
; /* real gid */
1042 pid_t pid
; /* caller's pid, or -1 if not available */
1047 extern void svc_fd_negotiate_ucred(int);
1048 extern int svc_getcallerucred(const SVCXPRT
*, struct ucred_s
**);
1049 extern bool_t
svc_get_local_cred(SVCXPRT
*, svc_local_cred_t
*);
1051 extern void svc_fd_negotiate_ucred();
1052 extern int svc_getcallerucred();
1053 extern bool_t
svc_get_local_cred();
1054 #endif /* __STDC__ */
1057 * Private interfaces and structures for user level duplicate request caching.
1058 * The interfaces and data structures are not committed and subject to
1059 * change in future releases. Currently only intended for use by automountd.
1066 struct netbuf dr_addr
;
1067 struct netbuf dr_resp
;
1071 struct dupreq
*dr_next
;
1072 struct dupreq
*dr_prev
;
1073 struct dupreq
*dr_chain
;
1074 struct dupreq
*dr_prevchain
;
1078 * The fixedtime state is defined if we want to expand the routines to
1079 * handle and encompass fixed size caches.
1081 #define DUPCACHE_FIXEDTIME 0
1084 * States of requests for duplicate request caching.
1085 * These are the same as defined for the kernel.
1087 #define DUP_NEW 0x00 /* new entry */
1088 #define DUP_INPROGRESS 0x01 /* request already going */
1089 #define DUP_DONE 0x02 /* request done */
1090 #define DUP_DROP 0x03 /* request dropped */
1091 #define DUP_ERROR 0x04 /* error in dup req cache */
1094 extern bool_t
__svc_dupcache_init(void *, int, char **);
1095 extern int __svc_dup(struct svc_req
*, caddr_t
*, uint_t
*, char *);
1096 extern int __svc_dupdone(struct svc_req
*, caddr_t
, uint_t
, int, char *);
1097 extern bool_t
__svc_vc_dupcache_init(SVCXPRT
*, void *, int);
1098 extern int __svc_vc_dup(struct svc_req
*, caddr_t
*, uint_t
*);
1099 extern int __svc_vc_dupdone(struct svc_req
*, caddr_t
, uint_t
, int);
1101 extern bool_t
__svc_dupcache_init();
1102 extern int __svc_dup();
1103 extern int __svc_dupdone();
1104 extern bool_t
__svc_vc_dupcache_init();
1105 extern int __svc_vc_dup();
1106 extern int __svc_vc_dupdone();
1107 #endif /* __STDC__ */
1108 #endif /* _KERNEL */
1112 * Private interfaces and structures for SVCXPRT cloning.
1113 * The interfaces and data structures are not committed and subject to
1114 * change in future releases.
1116 extern SVCXPRT
*svc_clone_init(void);
1117 extern void svc_clone_free(SVCXPRT
*);
1118 extern void svc_clone_link(SVCMASTERXPRT
*, SVCXPRT
*, SVCXPRT
*);
1119 extern void svc_clone_unlink(SVCXPRT
*);
1120 #endif /* _KERNEL */
1126 #endif /* !_RPC_SVC_H */