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

55-freebsd-126-freebsd-12
Last change on this file since 18fa92c was bb80d9d, checked in by Sebastian Huber <sebastian.huber@…>, on 08/09/18 at 12:02:09

Update to FreeBSD head 2017-12-01

Git mirror commit e724f51f811a4b2bd29447f8b85ab5c2f9b88266.

Update #3472.

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