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