FreeBSD/Linux Kernel Cross Reference
sys/rpc/svc.h
1 /* $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $ */
2
3 /*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * from: @(#)svc.h 1.35 88/12/17 SMI
33 * from: @(#)svc.h 1.27 94/04/25 SMI
34 * $FreeBSD$
35 */
36
37 /*
38 * svc.h, Server-side remote procedure call interface.
39 *
40 * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
41 */
42
43 #ifndef _RPC_SVC_H
44 #define _RPC_SVC_H
45 #include <sys/cdefs.h>
46
47 #ifdef _KERNEL
48 #include <sys/queue.h>
49 #include <sys/_lock.h>
50 #include <sys/_mutex.h>
51 #include <sys/_sx.h>
52 #include <sys/condvar.h>
53 #include <sys/sysctl.h>
54 #endif
55
56 /*
57 * This interface must manage two items concerning remote procedure calling:
58 *
59 * 1) An arbitrary number of transport connections upon which rpc requests
60 * are received. The two most notable transports are TCP and UDP; they are
61 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
62 * they in turn call xprt_register and xprt_unregister.
63 *
64 * 2) An arbitrary number of locally registered services. Services are
65 * described by the following four data: program number, version number,
66 * "service dispatch" function, a transport handle, and a boolean that
67 * indicates whether or not the exported program should be registered with a
68 * local binder service; if true the program's number and version and the
69 * port number from the transport handle are registered with the binder.
70 * These data are registered with the rpc svc system via svc_register.
71 *
72 * A service's dispatch function is called whenever an rpc request comes in
73 * on a transport. The request's program and version numbers must match
74 * those of the registered service. The dispatch function is passed two
75 * parameters, struct svc_req * and SVCXPRT *, defined below.
76 */
77
78 /*
79 * Service control requests
80 */
81 #define SVCGET_VERSQUIET 1
82 #define SVCSET_VERSQUIET 2
83 #define SVCGET_CONNMAXREC 3
84 #define SVCSET_CONNMAXREC 4
85
86 /*
87 * Operations for rpc_control().
88 */
89 #define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */
90 #define RPC_SVC_CONNMAXREC_GET 1
91
92 enum xprt_stat {
93 XPRT_DIED,
94 XPRT_MOREREQS,
95 XPRT_IDLE
96 };
97
98 struct __rpc_svcxprt;
99 struct mbuf;
100
101 struct xp_ops {
102 #ifdef _KERNEL
103 /* receive incoming requests */
104 bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *,
105 struct sockaddr **, struct mbuf **);
106 /* get transport status */
107 enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
108 /* get transport acknowledge sequence */
109 bool_t (*xp_ack)(struct __rpc_svcxprt *, uint32_t *);
110 /* send reply */
111 bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *,
112 struct sockaddr *, struct mbuf *, uint32_t *);
113 /* destroy this struct */
114 void (*xp_destroy)(struct __rpc_svcxprt *);
115 /* catch-all function */
116 bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
117 #else
118 /* receive incoming requests */
119 bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
120 /* get transport status */
121 enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
122 /* get arguments */
123 bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
124 /* send reply */
125 bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
126 /* free mem allocated for args */
127 bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
128 /* destroy this struct */
129 void (*xp_destroy)(struct __rpc_svcxprt *);
130 #endif
131 };
132
133 #ifndef _KERNEL
134 struct xp_ops2 {
135 /* catch-all function */
136 bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
137 };
138 #endif
139
140 #ifdef _KERNEL
141 struct __rpc_svcpool;
142 struct __rpc_svcgroup;
143 struct __rpc_svcthread;
144 #endif
145
146 /*
147 * Server side transport handle. In the kernel, transports have a
148 * reference count which tracks the number of currently assigned
149 * worker threads plus one for the service pool's reference.
150 * For NFSv4.1 sessions, a reference is also held for a backchannel.
151 * xp_p2 - Points to the CLIENT structure for the RPC server end
152 * (the client end for callbacks).
153 * Points to the private structure (cl_private) for the
154 * CLIENT structure for the RPC client end (the server
155 * end for callbacks).
156 */
157 typedef struct __rpc_svcxprt {
158 #ifdef _KERNEL
159 volatile u_int xp_refs;
160 struct sx xp_lock;
161 struct __rpc_svcpool *xp_pool; /* owning pool (see below) */
162 struct __rpc_svcgroup *xp_group; /* owning group (see below) */
163 TAILQ_ENTRY(__rpc_svcxprt) xp_link;
164 TAILQ_ENTRY(__rpc_svcxprt) xp_alink;
165 bool_t xp_registered; /* xprt_register has been called */
166 bool_t xp_active; /* xprt_active has been called */
167 struct __rpc_svcthread *xp_thread; /* assigned service thread */
168 struct socket* xp_socket;
169 const struct xp_ops *xp_ops;
170 char *xp_netid; /* network token */
171 struct sockaddr_storage xp_ltaddr; /* local transport address */
172 struct sockaddr_storage xp_rtaddr; /* remote transport address */
173 void *xp_p1; /* private: for use by svc ops */
174 void *xp_p2; /* private: for use by svc ops */
175 void *xp_p3; /* private: for use by svc lib */
176 int xp_type; /* transport type */
177 int xp_idletimeout; /* idle time before closing */
178 time_t xp_lastactive; /* time of last RPC */
179 u_int64_t xp_sockref; /* set by nfsv4 to identify socket */
180 int xp_upcallset; /* socket upcall is set up */
181 uint32_t xp_snd_cnt; /* # of bytes to send to socket */
182 uint32_t xp_snt_cnt; /* # of bytes sent to socket */
183 #else
184 int xp_fd;
185 u_short xp_port; /* associated port number */
186 const struct xp_ops *xp_ops;
187 int xp_addrlen; /* length of remote address */
188 struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */
189 /* XXX - fvdl stick this here for ABI backward compat reasons */
190 const struct xp_ops2 *xp_ops2;
191 char *xp_tp; /* transport provider device name */
192 char *xp_netid; /* network token */
193 struct netbuf xp_ltaddr; /* local transport address */
194 struct netbuf xp_rtaddr; /* remote transport address */
195 struct opaque_auth xp_verf; /* raw response verifier */
196 void *xp_p1; /* private: for use by svc ops */
197 void *xp_p2; /* private: for use by svc ops */
198 void *xp_p3; /* private: for use by svc lib */
199 int xp_type; /* transport type */
200 #endif
201 } SVCXPRT;
202
203 /*
204 * Interface to server-side authentication flavors.
205 */
206 typedef struct __rpc_svcauth {
207 struct svc_auth_ops {
208 #ifdef _KERNEL
209 int (*svc_ah_wrap)(struct __rpc_svcauth *, struct mbuf **);
210 int (*svc_ah_unwrap)(struct __rpc_svcauth *, struct mbuf **);
211 void (*svc_ah_release)(struct __rpc_svcauth *);
212 #else
213 int (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *,
214 xdrproc_t, caddr_t);
215 int (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *,
216 xdrproc_t, caddr_t);
217 #endif
218 } *svc_ah_ops;
219 void *svc_ah_private;
220 } SVCAUTH;
221
222 /*
223 * Server transport extensions (accessed via xp_p3).
224 */
225 typedef struct __rpc_svcxprt_ext {
226 int xp_flags; /* versquiet */
227 SVCAUTH xp_auth; /* interface to auth methods */
228 } SVCXPRT_EXT;
229
230 #ifdef _KERNEL
231
232 /*
233 * The services list
234 * Each entry represents a set of procedures (an rpc program).
235 * The dispatch routine takes request structs and runs the
236 * appropriate procedure.
237 */
238 struct svc_callout {
239 TAILQ_ENTRY(svc_callout) sc_link;
240 rpcprog_t sc_prog;
241 rpcvers_t sc_vers;
242 char *sc_netid;
243 void (*sc_dispatch)(struct svc_req *, SVCXPRT *);
244 };
245 TAILQ_HEAD(svc_callout_list, svc_callout);
246
247 /*
248 * The services connection loss list
249 * The dispatch routine takes request structs and runs the
250 * appropriate procedure.
251 */
252 struct svc_loss_callout {
253 TAILQ_ENTRY(svc_loss_callout) slc_link;
254 void (*slc_dispatch)(SVCXPRT *);
255 };
256 TAILQ_HEAD(svc_loss_callout_list, svc_loss_callout);
257
258 /*
259 * Service request
260 */
261 struct svc_req {
262 STAILQ_ENTRY(svc_req) rq_link; /* list of requests for a thread */
263 struct __rpc_svcthread *rq_thread; /* thread which is to execute this */
264 uint32_t rq_xid; /* RPC transaction ID */
265 uint32_t rq_prog; /* service program number */
266 uint32_t rq_vers; /* service protocol version */
267 uint32_t rq_proc; /* the desired procedure */
268 size_t rq_size; /* space used by request */
269 struct mbuf *rq_args; /* XDR-encoded procedure arguments */
270 struct opaque_auth rq_cred; /* raw creds from the wire */
271 struct opaque_auth rq_verf; /* verifier for the reply */
272 void *rq_clntcred; /* read only cooked cred */
273 SVCAUTH rq_auth; /* interface to auth methods */
274 SVCXPRT *rq_xprt; /* associated transport */
275 struct sockaddr *rq_addr; /* reply address or NULL if connected */
276 void *rq_p1; /* application workspace */
277 int rq_p2; /* application workspace */
278 uint64_t rq_p3; /* application workspace */
279 uint32_t rq_reply_seq; /* reply socket sequence # */
280 char rq_credarea[3*MAX_AUTH_BYTES];
281 };
282 STAILQ_HEAD(svc_reqlist, svc_req);
283
284 #define svc_getrpccaller(rq) \
285 ((rq)->rq_addr ? (rq)->rq_addr : \
286 (struct sockaddr *) &(rq)->rq_xprt->xp_rtaddr)
287
288 /*
289 * This structure is used to manage a thread which is executing
290 * requests from a service pool. A service thread is in one of three
291 * states:
292 *
293 * SVCTHREAD_SLEEPING waiting for a request to process
294 * SVCTHREAD_ACTIVE processing a request
295 * SVCTHREAD_EXITING exiting after finishing current request
296 *
297 * Threads which have no work to process sleep on the pool's sp_active
298 * list. When a transport becomes active, it is assigned a service
299 * thread to read and execute pending RPCs.
300 */
301 typedef struct __rpc_svcthread {
302 struct mtx_padalign st_lock; /* protects st_reqs field */
303 struct __rpc_svcpool *st_pool;
304 SVCXPRT *st_xprt; /* transport we are processing */
305 struct svc_reqlist st_reqs; /* RPC requests to execute */
306 struct cv st_cond; /* sleeping for work */
307 LIST_ENTRY(__rpc_svcthread) st_ilink; /* idle threads list */
308 LIST_ENTRY(__rpc_svcthread) st_alink; /* application thread list */
309 int st_p2; /* application workspace */
310 uint64_t st_p3; /* application workspace */
311 } SVCTHREAD;
312 LIST_HEAD(svcthread_list, __rpc_svcthread);
313
314 /*
315 * A thread group contain all information needed to assign subset of
316 * transports to subset of threads. On systems with many CPUs and many
317 * threads that allows to reduce lock congestion and improve performance.
318 * Hundreds of threads on dozens of CPUs sharing the single pool lock do
319 * not scale well otherwise.
320 */
321 TAILQ_HEAD(svcxprt_list, __rpc_svcxprt);
322 enum svcpool_state {
323 SVCPOOL_INIT, /* svc_run not called yet */
324 SVCPOOL_ACTIVE, /* normal running state */
325 SVCPOOL_THREADWANTED, /* new service thread requested */
326 SVCPOOL_THREADSTARTING, /* new service thread started */
327 SVCPOOL_CLOSING /* svc_exit called */
328 };
329 typedef struct __rpc_svcgroup {
330 struct mtx_padalign sg_lock; /* protect the thread/req lists */
331 struct __rpc_svcpool *sg_pool;
332 enum svcpool_state sg_state; /* current pool state */
333 struct svcxprt_list sg_xlist; /* all transports in the group */
334 struct svcxprt_list sg_active; /* transports needing service */
335 struct svcthread_list sg_idlethreads; /* idle service threads */
336
337 int sg_minthreads; /* minimum service thread count */
338 int sg_maxthreads; /* maximum service thread count */
339 int sg_threadcount; /* current service thread count */
340 time_t sg_lastcreatetime; /* when we last started a thread */
341 time_t sg_lastidlecheck; /* when we last checked idle transports */
342 } SVCGROUP;
343
344 /*
345 * In the kernel, we can't use global variables to store lists of
346 * transports etc. since otherwise we could not have two unrelated RPC
347 * services running, each on its own thread. We solve this by
348 * importing a tiny part of a Solaris kernel concept, SVCPOOL.
349 *
350 * A service pool contains a set of transports and service callbacks
351 * for a set of related RPC services. The pool handle should be passed
352 * when creating new transports etc. Future work may include extending
353 * this to support something similar to the Solaris multi-threaded RPC
354 * server.
355 */
356 typedef SVCTHREAD *pool_assign_fn(SVCTHREAD *, struct svc_req *);
357 typedef void pool_done_fn(SVCTHREAD *, struct svc_req *);
358 #define SVC_MAXGROUPS 16
359 typedef struct __rpc_svcpool {
360 struct mtx_padalign sp_lock; /* protect the transport lists */
361 const char *sp_name; /* pool name (e.g. "nfsd", "NLM" */
362 enum svcpool_state sp_state; /* current pool state */
363 struct proc *sp_proc; /* process which is in svc_run */
364 struct svc_callout_list sp_callouts; /* (prog,vers)->dispatch list */
365 struct svc_loss_callout_list sp_lcallouts; /* loss->dispatch list */
366 int sp_minthreads; /* minimum service thread count */
367 int sp_maxthreads; /* maximum service thread count */
368
369 /*
370 * Hooks to allow an application to control request to thread
371 * placement.
372 */
373 pool_assign_fn *sp_assign;
374 pool_done_fn *sp_done;
375
376 /*
377 * These variables are used to put an upper bound on the
378 * amount of memory used by RPC requests which are queued
379 * waiting for execution.
380 */
381 unsigned long sp_space_low;
382 unsigned long sp_space_high;
383 unsigned long sp_space_used;
384 unsigned long sp_space_used_highest;
385 bool_t sp_space_throttled;
386 int sp_space_throttle_count;
387
388 struct replay_cache *sp_rcache; /* optional replay cache */
389 struct sysctl_ctx_list sp_sysctl;
390
391 int sp_groupcount; /* Number of groups in the pool. */
392 int sp_nextgroup; /* Next group to assign port. */
393 SVCGROUP sp_groups[SVC_MAXGROUPS]; /* Thread/port groups. */
394 } SVCPOOL;
395
396 #else
397
398 /*
399 * Service request
400 */
401 struct svc_req {
402 uint32_t rq_prog; /* service program number */
403 uint32_t rq_vers; /* service protocol version */
404 uint32_t rq_proc; /* the desired procedure */
405 struct opaque_auth rq_cred; /* raw creds from the wire */
406 void *rq_clntcred; /* read only cooked cred */
407 SVCXPRT *rq_xprt; /* associated transport */
408 };
409
410 /*
411 * Approved way of getting address of caller
412 */
413 #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
414
415 #endif
416
417 /*
418 * Operations defined on an SVCXPRT handle
419 *
420 * SVCXPRT *xprt;
421 * struct rpc_msg *msg;
422 * xdrproc_t xargs;
423 * void * argsp;
424 */
425 #ifdef _KERNEL
426
427 #define SVC_ACQUIRE(xprt) \
428 refcount_acquire(&(xprt)->xp_refs)
429
430 #define SVC_RELEASE(xprt) \
431 if (refcount_release(&(xprt)->xp_refs)) \
432 SVC_DESTROY(xprt)
433
434 #define SVC_RECV(xprt, msg, addr, args) \
435 (*(xprt)->xp_ops->xp_recv)((xprt), (msg), (addr), (args))
436
437 #define SVC_STAT(xprt) \
438 (*(xprt)->xp_ops->xp_stat)(xprt)
439
440 #define SVC_ACK(xprt, ack) \
441 ((xprt)->xp_ops->xp_ack == NULL ? FALSE : \
442 ((ack) == NULL ? TRUE : (*(xprt)->xp_ops->xp_ack)((xprt), (ack))))
443
444 #define SVC_REPLY(xprt, msg, addr, m, seq) \
445 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg), (addr), (m), (seq))
446
447 #define SVC_DESTROY(xprt) \
448 (*(xprt)->xp_ops->xp_destroy)(xprt)
449
450 #define SVC_CONTROL(xprt, rq, in) \
451 (*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
452
453 #else
454
455 #define SVC_RECV(xprt, msg) \
456 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
457 #define svc_recv(xprt, msg) \
458 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
459
460 #define SVC_STAT(xprt) \
461 (*(xprt)->xp_ops->xp_stat)(xprt)
462 #define svc_stat(xprt) \
463 (*(xprt)->xp_ops->xp_stat)(xprt)
464
465 #define SVC_GETARGS(xprt, xargs, argsp) \
466 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
467 #define svc_getargs(xprt, xargs, argsp) \
468 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
469
470 #define SVC_REPLY(xprt, msg) \
471 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
472 #define svc_reply(xprt, msg) \
473 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
474
475 #define SVC_FREEARGS(xprt, xargs, argsp) \
476 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
477 #define svc_freeargs(xprt, xargs, argsp) \
478 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
479
480 #define SVC_DESTROY(xprt) \
481 (*(xprt)->xp_ops->xp_destroy)(xprt)
482 #define svc_destroy(xprt) \
483 (*(xprt)->xp_ops->xp_destroy)(xprt)
484
485 #define SVC_CONTROL(xprt, rq, in) \
486 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
487
488 #endif
489
490 #define SVC_EXT(xprt) \
491 ((SVCXPRT_EXT *) xprt->xp_p3)
492
493 #define SVC_AUTH(xprt) \
494 (SVC_EXT(xprt)->xp_auth)
495
496 /*
497 * Operations defined on an SVCAUTH handle
498 */
499 #ifdef _KERNEL
500 #define SVCAUTH_WRAP(auth, mp) \
501 ((auth)->svc_ah_ops->svc_ah_wrap(auth, mp))
502 #define SVCAUTH_UNWRAP(auth, mp) \
503 ((auth)->svc_ah_ops->svc_ah_unwrap(auth, mp))
504 #define SVCAUTH_RELEASE(auth) \
505 ((auth)->svc_ah_ops->svc_ah_release(auth))
506 #else
507 #define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere) \
508 ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere))
509 #define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
510 ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere))
511 #endif
512
513 /*
514 * Service registration
515 *
516 * svc_reg(xprt, prog, vers, dispatch, nconf)
517 * const SVCXPRT *xprt;
518 * const rpcprog_t prog;
519 * const rpcvers_t vers;
520 * const void (*dispatch)();
521 * const struct netconfig *nconf;
522 */
523
524 __BEGIN_DECLS
525 extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
526 void (*)(struct svc_req *, SVCXPRT *),
527 const struct netconfig *);
528 __END_DECLS
529
530 /*
531 * Service un-registration
532 *
533 * svc_unreg(prog, vers)
534 * const rpcprog_t prog;
535 * const rpcvers_t vers;
536 */
537
538 __BEGIN_DECLS
539 #ifdef _KERNEL
540 extern void svc_unreg(SVCPOOL *, const rpcprog_t, const rpcvers_t);
541 #else
542 extern void svc_unreg(const rpcprog_t, const rpcvers_t);
543 #endif
544 __END_DECLS
545
546 #ifdef _KERNEL
547 /*
548 * Service connection loss registration
549 *
550 * svc_loss_reg(xprt, dispatch)
551 * const SVCXPRT *xprt;
552 * const void (*dispatch)();
553 */
554
555 __BEGIN_DECLS
556 extern bool_t svc_loss_reg(SVCXPRT *, void (*)(SVCXPRT *));
557 __END_DECLS
558
559 /*
560 * Service connection loss un-registration
561 *
562 * svc_loss_unreg(xprt, dispatch)
563 * const SVCXPRT *xprt;
564 * const void (*dispatch)();
565 */
566
567 __BEGIN_DECLS
568 extern void svc_loss_unreg(SVCPOOL *, void (*)(SVCXPRT *));
569 __END_DECLS
570 #endif
571
572 /*
573 * Transport registration.
574 *
575 * xprt_register(xprt)
576 * SVCXPRT *xprt;
577 */
578 __BEGIN_DECLS
579 extern void xprt_register(SVCXPRT *);
580 __END_DECLS
581
582 /*
583 * Transport un-register
584 *
585 * xprt_unregister(xprt)
586 * SVCXPRT *xprt;
587 */
588 __BEGIN_DECLS
589 extern void xprt_unregister(SVCXPRT *);
590 extern void __xprt_unregister_unlocked(SVCXPRT *);
591 __END_DECLS
592
593 #ifdef _KERNEL
594
595 /*
596 * Called when a transport has pending requests.
597 */
598 __BEGIN_DECLS
599 extern void xprt_active(SVCXPRT *);
600 extern void xprt_inactive(SVCXPRT *);
601 extern void xprt_inactive_locked(SVCXPRT *);
602 extern void xprt_inactive_self(SVCXPRT *);
603 __END_DECLS
604
605 #endif
606
607 /*
608 * When the service routine is called, it must first check to see if it
609 * knows about the procedure; if not, it should call svcerr_noproc
610 * and return. If so, it should deserialize its arguments via
611 * SVC_GETARGS (defined above). If the deserialization does not work,
612 * svcerr_decode should be called followed by a return. Successful
613 * decoding of the arguments should be followed the execution of the
614 * procedure's code and a call to svc_sendreply.
615 *
616 * Also, if the service refuses to execute the procedure due to too-
617 * weak authentication parameters, svcerr_weakauth should be called.
618 * Note: do not confuse access-control failure with weak authentication!
619 *
620 * NB: In pure implementations of rpc, the caller always waits for a reply
621 * msg. This message is sent when svc_sendreply is called.
622 * Therefore pure service implementations should always call
623 * svc_sendreply even if the function logically returns void; use
624 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
625 * for the abuse of pure rpc via batched calling or pipelining. In the
626 * case of a batched call, svc_sendreply should NOT be called since
627 * this would send a return message, which is what batching tries to avoid.
628 * It is the service/protocol writer's responsibility to know which calls are
629 * batched and which are not. Warning: responding to batch calls may
630 * deadlock the caller and server processes!
631 */
632
633 __BEGIN_DECLS
634 #ifdef _KERNEL
635 extern bool_t svc_sendreply(struct svc_req *, xdrproc_t, void *);
636 extern bool_t svc_sendreply_mbuf(struct svc_req *, struct mbuf *);
637 extern void svcerr_decode(struct svc_req *);
638 extern void svcerr_weakauth(struct svc_req *);
639 extern void svcerr_noproc(struct svc_req *);
640 extern void svcerr_progvers(struct svc_req *, rpcvers_t, rpcvers_t);
641 extern void svcerr_auth(struct svc_req *, enum auth_stat);
642 extern void svcerr_noprog(struct svc_req *);
643 extern void svcerr_systemerr(struct svc_req *);
644 #else
645 extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
646 extern void svcerr_decode(SVCXPRT *);
647 extern void svcerr_weakauth(SVCXPRT *);
648 extern void svcerr_noproc(SVCXPRT *);
649 extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
650 extern void svcerr_auth(SVCXPRT *, enum auth_stat);
651 extern void svcerr_noprog(SVCXPRT *);
652 extern void svcerr_systemerr(SVCXPRT *);
653 #endif
654 extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
655 char *(*)(char *), xdrproc_t, xdrproc_t,
656 char *);
657 __END_DECLS
658
659 /*
660 * Lowest level dispatching -OR- who owns this process anyway.
661 * Somebody has to wait for incoming requests and then call the correct
662 * service routine. The routine svc_run does infinite waiting; i.e.,
663 * svc_run never returns.
664 * Since another (co-existent) package may wish to selectively wait for
665 * incoming calls or other events outside of the rpc architecture, the
666 * routine svc_getreq is provided. It must be passed readfds, the
667 * "in-place" results of a select system call (see select, section 2).
668 */
669
670 #ifndef _KERNEL
671 /*
672 * Global keeper of rpc service descriptors in use
673 * dynamic; must be inspected before each call to select
674 */
675 extern int svc_maxfd;
676 #ifdef FD_SETSIZE
677 extern fd_set svc_fdset;
678 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
679 #else
680 extern int svc_fds;
681 #endif /* def FD_SETSIZE */
682 #endif
683
684 /*
685 * a small program implemented by the svc_rpc implementation itself;
686 * also see clnt.h for protocol numbers.
687 */
688 __BEGIN_DECLS
689 extern void rpctest_service(void);
690 __END_DECLS
691
692 __BEGIN_DECLS
693 extern SVCXPRT *svc_xprt_alloc(void);
694 extern void svc_xprt_free(SVCXPRT *);
695 #ifndef _KERNEL
696 extern void svc_getreq(int);
697 extern void svc_getreqset(fd_set *);
698 extern void svc_getreq_common(int);
699 struct pollfd;
700 extern void svc_getreq_poll(struct pollfd *, int);
701 extern void svc_run(void);
702 extern void svc_exit(void);
703 #else
704 extern void svc_run(SVCPOOL *);
705 extern void svc_exit(SVCPOOL *);
706 extern bool_t svc_getargs(struct svc_req *, xdrproc_t, void *);
707 extern bool_t svc_freeargs(struct svc_req *, xdrproc_t, void *);
708 extern void svc_freereq(struct svc_req *);
709
710 #endif
711 __END_DECLS
712
713 /*
714 * Socket to use on svcxxx_create call to get default socket
715 */
716 #define RPC_ANYSOCK -1
717 #define RPC_ANYFD RPC_ANYSOCK
718
719 /*
720 * These are the existing service side transport implementations
721 */
722
723 __BEGIN_DECLS
724
725 #ifdef _KERNEL
726
727 /*
728 * Create a new service pool.
729 */
730 extern SVCPOOL* svcpool_create(const char *name,
731 struct sysctl_oid_list *sysctl_base);
732
733 /*
734 * Destroy a service pool, including all registered transports.
735 */
736 extern void svcpool_destroy(SVCPOOL *pool);
737
738 /*
739 * Close a service pool. Similar to svcpool_destroy(), but it does not
740 * free the data structures. As such, the pool can be used again.
741 */
742 extern void svcpool_close(SVCPOOL *pool);
743
744 /*
745 * Transport independent svc_create routine.
746 */
747 extern int svc_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
748 const rpcprog_t, const rpcvers_t, const char *);
749 /*
750 * void (*dispatch)(); -- dispatch routine
751 * const rpcprog_t prognum; -- program number
752 * const rpcvers_t versnum; -- version number
753 * const char *nettype; -- network type
754 */
755
756
757 /*
758 * Generic server creation routine. It takes a netconfig structure
759 * instead of a nettype.
760 */
761
762 extern SVCXPRT *svc_tp_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
763 const rpcprog_t, const rpcvers_t, const char *uaddr,
764 const struct netconfig *);
765 /*
766 * void (*dispatch)(); -- dispatch routine
767 * const rpcprog_t prognum; -- program number
768 * const rpcvers_t versnum; -- version number
769 * const char *uaddr; -- universal address of service
770 * const struct netconfig *nconf; -- netconfig structure
771 */
772
773 extern SVCXPRT *svc_dg_create(SVCPOOL *, struct socket *,
774 const size_t, const size_t);
775 /*
776 * struct socket *; -- open connection
777 * const size_t sendsize; -- max send size
778 * const size_t recvsize; -- max recv size
779 */
780
781 extern SVCXPRT *svc_vc_create(SVCPOOL *, struct socket *,
782 const size_t, const size_t);
783 /*
784 * struct socket *; -- open connection
785 * const size_t sendsize; -- max send size
786 * const size_t recvsize; -- max recv size
787 */
788
789 extern SVCXPRT *svc_vc_create_backchannel(SVCPOOL *);
790
791 extern void *clnt_bck_create(struct socket *, const rpcprog_t, const rpcvers_t);
792 /*
793 * struct socket *; -- server transport socket
794 * const rpcprog_t prog; -- RPC program number
795 * const rpcvers_t vers; -- RPC program version
796 */
797
798 /*
799 * Generic TLI create routine
800 */
801 extern SVCXPRT *svc_tli_create(SVCPOOL *, struct socket *,
802 const struct netconfig *, const struct t_bind *, const size_t, const size_t);
803 /*
804 * struct socket * so; -- connection end point
805 * const struct netconfig *nconf; -- netconfig structure for network
806 * const struct t_bind *bindaddr; -- local bind address
807 * const size_t sendsz; -- max sendsize
808 * const size_t recvsz; -- max recvsize
809 */
810
811 #else /* !_KERNEL */
812
813 /*
814 * Transport independent svc_create routine.
815 */
816 extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
817 const rpcprog_t, const rpcvers_t, const char *);
818 /*
819 * void (*dispatch)(); -- dispatch routine
820 * const rpcprog_t prognum; -- program number
821 * const rpcvers_t versnum; -- version number
822 * const char *nettype; -- network type
823 */
824
825
826 /*
827 * Generic server creation routine. It takes a netconfig structure
828 * instead of a nettype.
829 */
830
831 extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
832 const rpcprog_t, const rpcvers_t,
833 const struct netconfig *);
834 /*
835 * void (*dispatch)(); -- dispatch routine
836 * const rpcprog_t prognum; -- program number
837 * const rpcvers_t versnum; -- version number
838 * const struct netconfig *nconf; -- netconfig structure
839 */
840
841 /*
842 * Generic TLI create routine
843 */
844 extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
845 const struct t_bind *, const u_int,
846 const u_int);
847 /*
848 * const int fd; -- connection end point
849 * const struct netconfig *nconf; -- netconfig structure for network
850 * const struct t_bind *bindaddr; -- local bind address
851 * const u_int sendsz; -- max sendsize
852 * const u_int recvsz; -- max recvsize
853 */
854
855 /*
856 * Connectionless and connectionful create routines
857 */
858
859 extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
860 /*
861 * const int fd; -- open connection end point
862 * const u_int sendsize; -- max send size
863 * const u_int recvsize; -- max recv size
864 */
865
866 /*
867 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
868 */
869 extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
870
871 extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
872 /*
873 * const int fd; -- open connection
874 * const u_int sendsize; -- max send size
875 * const u_int recvsize; -- max recv size
876 */
877
878
879 /*
880 * the routine takes any *open* connection
881 * descriptor as its first input and is used for open connections.
882 */
883 extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
884 /*
885 * const int fd; -- open connection end point
886 * const u_int sendsize; -- max send size
887 * const u_int recvsize; -- max recv size
888 */
889
890 /*
891 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
892 */
893 extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
894
895 /*
896 * Memory based rpc (for speed check and testing)
897 */
898 extern SVCXPRT *svc_raw_create(void);
899
900 /*
901 * svc_dg_enable_cache() enables the cache on dg transports.
902 */
903 int svc_dg_enablecache(SVCXPRT *, const u_int);
904
905 int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
906
907 #endif /* !_KERNEL */
908
909 __END_DECLS
910
911 #ifndef _KERNEL
912 /* for backward compatibility */
913 #include <rpc/svc_soc.h>
914 #endif
915
916 #endif /* !_RPC_SVC_H */
Cache object: 9a2a07294e1291c2ccaa52421f29a818
|