source: rtems-libbsd/freebsd/include/rpc/svc.h @ 9880635

5-freebsd-12freebsd-9.3
Last change on this file since 9880635 was 9880635, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 9, 2016 at 8:48:05 AM

RPC(3): Port to RTEMS

  • Property mode set to 100644
File size: 14.9 KB
Line 
1/*      $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $    */
2
3/*-
4 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 *   this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 *   this list of conditions and the following disclaimer in the documentation
13 *   and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 *   contributors may be used to endorse or promote products derived
16 *   from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 *      from: @(#)svc.h 1.35 88/12/17 SMI
31 *      from: @(#)svc.h      1.27    94/04/25 SMI
32 * $FreeBSD$
33 */
34
35/*
36 * svc.h, Server-side remote procedure call interface.
37 *
38 * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
39 */
40
41#ifndef _RPC_SVC_H
42#define _RPC_SVC_H
43#include <sys/cdefs.h>
44
45/*
46 * This interface must manage two items concerning remote procedure calling:
47 *
48 * 1) An arbitrary number of transport connections upon which rpc requests
49 * are received.  The two most notable transports are TCP and UDP;  they are
50 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
51 * they in turn call xprt_register and xprt_unregister.
52 *
53 * 2) An arbitrary number of locally registered services.  Services are
54 * described by the following four data: program number, version number,
55 * "service dispatch" function, a transport handle, and a boolean that
56 * indicates whether or not the exported program should be registered with a
57 * local binder service;  if true the program's number and version and the
58 * port number from the transport handle are registered with the binder.
59 * These data are registered with the rpc svc system via svc_register.
60 *
61 * A service's dispatch function is called whenever an rpc request comes in
62 * on a transport.  The request's program and version numbers must match
63 * those of the registered service.  The dispatch function is passed two
64 * parameters, struct svc_req * and SVCXPRT *, defined below.
65 */
66
67/*
68 *      Service control requests
69 */
70#define SVCGET_VERSQUIET        1
71#define SVCSET_VERSQUIET        2
72#define SVCGET_CONNMAXREC       3
73#define SVCSET_CONNMAXREC       4
74
75/*
76 * Operations for rpc_control().
77 */
78#define RPC_SVC_CONNMAXREC_SET  0       /* set max rec size, enable nonblock */
79#define RPC_SVC_CONNMAXREC_GET  1
80
81enum xprt_stat {
82        XPRT_DIED,
83        XPRT_MOREREQS,
84        XPRT_IDLE,
85        _XPRT_STAT = 0xffffffff
86};
87
88/*
89 * Server side transport handle
90 */
91typedef struct __rpc_svcxprt {
92        int             xp_fd;
93        u_short         xp_port;         /* associated port number */
94        const struct xp_ops {
95            /* receive incoming requests */
96            bool_t      (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
97            /* get transport status */
98            enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
99            /* get arguments */
100            bool_t      (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
101                                void *);
102            /* send reply */
103            bool_t      (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
104            /* free mem allocated for args */
105            bool_t      (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
106                                void *);
107            /* destroy this struct */
108            void        (*xp_destroy)(struct __rpc_svcxprt *);
109        } *xp_ops;
110        int             xp_addrlen;      /* length of remote address */
111        struct sockaddr_in xp_raddr;     /* remote addr. (backward ABI compat) */
112        /* XXX - fvdl stick this here for ABI backward compat reasons */
113        const struct xp_ops2 {
114                /* catch-all function */
115                bool_t  (*xp_control)(struct __rpc_svcxprt *, const u_int,
116                                void *);
117        } *xp_ops2;
118        char            *xp_tp;          /* transport provider device name */
119        char            *xp_netid;       /* network token */
120        struct netbuf   xp_ltaddr;       /* local transport address */
121        struct netbuf   xp_rtaddr;       /* remote transport address */
122        struct opaque_auth xp_verf;      /* raw response verifier */
123        void            *xp_p1;          /* private: for use by svc ops */
124        void            *xp_p2;          /* private: for use by svc ops */
125        void            *xp_p3;          /* private: for use by svc lib */
126        int             xp_type;         /* transport type */
127} SVCXPRT;
128
129/*
130 * Interface to server-side authentication flavors.
131 */
132typedef struct __rpc_svcauth {
133        struct svc_auth_ops {
134                int   (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *,
135                    xdrproc_t, caddr_t);
136                int   (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *,
137                    xdrproc_t, caddr_t);
138        } *svc_ah_ops;
139        void *svc_ah_private;
140} SVCAUTH;
141
142/*
143 * Server transport extensions (accessed via xp_p3).
144 */
145typedef struct __rpc_svcxprt_ext {
146        int             xp_flags;       /* versquiet */
147        SVCAUTH         xp_auth;        /* interface to auth methods */
148} SVCXPRT_EXT;
149
150/*
151 * Service request
152 */
153struct svc_req {
154        u_int32_t       rq_prog;        /* service program number */
155        u_int32_t       rq_vers;        /* service protocol version */
156        u_int32_t       rq_proc;        /* the desired procedure */
157        struct opaque_auth rq_cred;     /* raw creds from the wire */
158        void            *rq_clntcred;   /* read only cooked cred */
159        SVCXPRT         *rq_xprt;       /* associated transport */
160};
161
162/*
163 *  Approved way of getting address of caller
164 */
165#define svc_getrpccaller(x) (&(x)->xp_rtaddr)
166
167/*
168 * Operations defined on an SVCXPRT handle
169 *
170 * SVCXPRT              *xprt;
171 * struct rpc_msg       *msg;
172 * xdrproc_t             xargs;
173 * void *                argsp;
174 */
175#define SVC_RECV(xprt, msg)                             \
176        (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
177#define svc_recv(xprt, msg)                             \
178        (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
179
180#define SVC_STAT(xprt)                                  \
181        (*(xprt)->xp_ops->xp_stat)(xprt)
182#define svc_stat(xprt)                                  \
183        (*(xprt)->xp_ops->xp_stat)(xprt)
184
185#define SVC_GETARGS(xprt, xargs, argsp)                 \
186        (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
187#define svc_getargs(xprt, xargs, argsp)                 \
188        (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
189
190#define SVC_REPLY(xprt, msg)                            \
191        (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
192#define svc_reply(xprt, msg)                            \
193        (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
194
195#define SVC_FREEARGS(xprt, xargs, argsp)                \
196        (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
197#define svc_freeargs(xprt, xargs, argsp)                \
198        (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
199
200#define SVC_DESTROY(xprt)                               \
201        (*(xprt)->xp_ops->xp_destroy)(xprt)
202#define svc_destroy(xprt)                               \
203        (*(xprt)->xp_ops->xp_destroy)(xprt)
204
205#define SVC_CONTROL(xprt, rq, in)                       \
206        (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
207
208#define SVC_EXT(xprt)                                   \
209        ((SVCXPRT_EXT *) xprt->xp_p3)
210
211#define SVC_AUTH(xprt)                                  \
212        (SVC_EXT(xprt)->xp_auth)
213
214/*
215 * Operations defined on an SVCAUTH handle
216 */
217#define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere)         \
218        ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere))
219#define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere)       \
220        ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere))
221
222/*
223 * Service registration
224 *
225 * svc_reg(xprt, prog, vers, dispatch, nconf)
226 *      const SVCXPRT *xprt;
227 *      const rpcprog_t prog;
228 *      const rpcvers_t vers;
229 *      const void (*dispatch)();
230 *      const struct netconfig *nconf;
231 */
232
233__BEGIN_DECLS
234extern bool_t   svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
235                        void (*)(struct svc_req *, SVCXPRT *),
236                        const struct netconfig *);
237__END_DECLS
238
239/*
240 * Service un-registration
241 *
242 * svc_unreg(prog, vers)
243 *      const rpcprog_t prog;
244 *      const rpcvers_t vers;
245 */
246
247__BEGIN_DECLS
248extern void     svc_unreg(const rpcprog_t, const rpcvers_t);
249__END_DECLS
250
251/*
252 * Transport registration.
253 *
254 * xprt_register(xprt)
255 *      SVCXPRT *xprt;
256 */
257__BEGIN_DECLS
258extern void     xprt_register(SVCXPRT *);
259__END_DECLS
260
261/*
262 * Transport un-register
263 *
264 * xprt_unregister(xprt)
265 *      SVCXPRT *xprt;
266 */
267__BEGIN_DECLS
268extern void     xprt_unregister(SVCXPRT *);
269__END_DECLS
270
271
272/*
273 * When the service routine is called, it must first check to see if it
274 * knows about the procedure;  if not, it should call svcerr_noproc
275 * and return.  If so, it should deserialize its arguments via
276 * SVC_GETARGS (defined above).  If the deserialization does not work,
277 * svcerr_decode should be called followed by a return.  Successful
278 * decoding of the arguments should be followed the execution of the
279 * procedure's code and a call to svc_sendreply.
280 *
281 * Also, if the service refuses to execute the procedure due to too-
282 * weak authentication parameters, svcerr_weakauth should be called.
283 * Note: do not confuse access-control failure with weak authentication!
284 *
285 * NB: In pure implementations of rpc, the caller always waits for a reply
286 * msg.  This message is sent when svc_sendreply is called.
287 * Therefore pure service implementations should always call
288 * svc_sendreply even if the function logically returns void;  use
289 * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
290 * for the abuse of pure rpc via batched calling or pipelining.  In the
291 * case of a batched call, svc_sendreply should NOT be called since
292 * this would send a return message, which is what batching tries to avoid.
293 * It is the service/protocol writer's responsibility to know which calls are
294 * batched and which are not.  Warning: responding to batch calls may
295 * deadlock the caller and server processes!
296 */
297
298__BEGIN_DECLS
299extern bool_t   svc_sendreply(SVCXPRT *, xdrproc_t, void *);
300extern void     svcerr_decode(SVCXPRT *);
301extern void     svcerr_weakauth(SVCXPRT *);
302extern void     svcerr_noproc(SVCXPRT *);
303extern void     svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
304extern void     svcerr_auth(SVCXPRT *, enum auth_stat);
305extern void     svcerr_noprog(SVCXPRT *);
306extern void     svcerr_systemerr(SVCXPRT *);
307extern int      rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
308                        char *(*)(char *), xdrproc_t, xdrproc_t,
309                        char *);
310__END_DECLS
311
312/*
313 * Lowest level dispatching -OR- who owns this process anyway.
314 * Somebody has to wait for incoming requests and then call the correct
315 * service routine.  The routine svc_run does infinite waiting; i.e.,
316 * svc_run never returns.
317 * Since another (co-existant) package may wish to selectively wait for
318 * incoming calls or other events outside of the rpc architecture, the
319 * routine svc_getreq is provided.  It must be passed readfds, the
320 * "in-place" results of a select system call (see select, section 2).
321 */
322
323/*
324 * Global keeper of rpc service descriptors in use
325 * dynamic; must be inspected before each call to select
326 */
327extern int svc_maxfd;
328#ifdef FD_SETSIZE
329extern fd_set svc_fdset;
330#define svc_fds svc_fdset.fds_bits[0]   /* compatibility */
331#else
332extern int svc_fds;
333#endif /* def FD_SETSIZE */
334
335/*
336 * A set of null auth methods used by any authentication protocols
337 * that don't need to inspect or modify the message body.
338 */
339extern SVCAUTH _svc_auth_null;
340
341/*
342 * a small program implemented by the svc_rpc implementation itself;
343 * also see clnt.h for protocol numbers.
344 */
345__BEGIN_DECLS
346extern void rpctest_service(void);
347__END_DECLS
348
349__BEGIN_DECLS
350extern SVCXPRT *svc_xprt_alloc(void);
351extern void     svc_xprt_free(SVCXPRT *);
352extern void     svc_getreq(int);
353extern void     svc_getreqset(fd_set *);
354extern void     svc_getreq_common(int);
355struct pollfd;
356extern void     svc_getreq_poll(struct pollfd *, int);
357
358extern void     svc_run(void);
359extern void     svc_exit(void);
360__END_DECLS
361
362/*
363 * Socket to use on svcxxx_create call to get default socket
364 */
365#define RPC_ANYSOCK     -1
366#define RPC_ANYFD       RPC_ANYSOCK
367
368/*
369 * These are the existing service side transport implementations
370 */
371
372__BEGIN_DECLS
373/*
374 * Transport independent svc_create routine.
375 */
376extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
377                           const rpcprog_t, const rpcvers_t, const char *);
378/*
379 *      void (*dispatch)();             -- dispatch routine
380 *      const rpcprog_t prognum;        -- program number
381 *      const rpcvers_t versnum;        -- version number
382 *      const char *nettype;            -- network type
383 */
384
385
386/*
387 * Generic server creation routine. It takes a netconfig structure
388 * instead of a nettype.
389 */
390
391extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
392                                   const rpcprog_t, const rpcvers_t,
393                                   const struct netconfig *);
394        /*
395         * void (*dispatch)();            -- dispatch routine
396         * const rpcprog_t prognum;       -- program number
397         * const rpcvers_t versnum;       -- version number
398         * const struct netconfig *nconf; -- netconfig structure
399         */
400
401
402/*
403 * Generic TLI create routine
404 */
405extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
406                               const struct t_bind *, const u_int,
407                               const u_int);
408/*
409 *      const int fd;                   -- connection end point
410 *      const struct netconfig *nconf;  -- netconfig structure for network
411 *      const struct t_bind *bindaddr;  -- local bind address
412 *      const u_int sendsz;             -- max sendsize
413 *      const u_int recvsz;             -- max recvsize
414 */
415
416/*
417 * Connectionless and connectionful create routines
418 */
419
420extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
421/*
422 *      const int fd;                           -- open connection end point
423 *      const u_int sendsize;                   -- max send size
424 *      const u_int recvsize;                   -- max recv size
425 */
426
427/*
428 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
429 */
430extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
431
432extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
433        /*
434         * const int fd;                                -- open connection
435         * const u_int sendsize;                        -- max send size
436         * const u_int recvsize;                        -- max recv size
437         */
438
439
440/*
441 * the routine takes any *open* connection
442 * descriptor as its first input and is used for open connections.
443 */
444extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
445/*
446 *      const int fd;                           -- open connection end point
447 *      const u_int sendsize;                   -- max send size
448 *      const u_int recvsize;                   -- max recv size
449 */
450
451/*
452 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
453 */
454extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
455
456/*
457 * Memory based rpc (for speed check and testing)
458 */
459extern SVCXPRT *svc_raw_create(void);
460
461/*
462 * svc_dg_enable_cache() enables the cache on dg transports.
463 */
464int svc_dg_enablecache(SVCXPRT *, const u_int);
465
466int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
467
468__END_DECLS
469
470
471/* for backward compatibility */
472#include <rpc/svc_soc.h>
473
474#endif /* !_RPC_SVC_H */
Note: See TracBrowser for help on using the repository browser.