source: rtems/cpukit/librpc/include/rpc/svc.h @ 94c76bc

4.104.114.84.95
Last change on this file since 94c76bc was 94c76bc, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/10/05 at 08:56:01

Cosmetical update from FreeBSD.

  • Property mode set to 100644
File size: 9.8 KB
RevLine 
[4721cf1]1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part.  Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
[df49c60]8 *
[4721cf1]9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
[df49c60]10 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
[4721cf1]11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
[df49c60]12 *
[4721cf1]13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
[df49c60]16 *
[4721cf1]17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
[df49c60]20 *
[4721cf1]21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
[df49c60]24 *
[4721cf1]25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
[df49c60]28 *
[94c76bc]29 *      from: @(#)svc.h 1.35 88/12/17 SMI
30 *      from: @(#)svc.h      1.27    94/04/25 SMI
31 * $FreeBSD: src/include/rpc/svc.h,v 1.24 2003/06/15 10:32:01 mbr Exp $
[4721cf1]32 */
33
34/*
35 * svc.h, Server-side remote procedure call interface.
36 *
[94c76bc]37 * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
[4721cf1]38 */
39
[df49c60]40#ifndef _RPC_SVC_H
41#define _RPC_SVC_H
42#include <sys/cdefs.h>
[4721cf1]43
44/*
45 * This interface must manage two items concerning remote procedure calling:
46 *
47 * 1) An arbitrary number of transport connections upon which rpc requests
48 * are received.  The two most notable transports are TCP and UDP;  they are
49 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
50 * they in turn call xprt_register and xprt_unregister.
51 *
52 * 2) An arbitrary number of locally registered services.  Services are
53 * described by the following four data: program number, version number,
54 * "service dispatch" function, a transport handle, and a boolean that
55 * indicates whether or not the exported program should be registered with a
56 * local binder service;  if true the program's number and version and the
57 * port number from the transport handle are registered with the binder.
58 * These data are registered with the rpc svc system via svc_register.
59 *
60 * A service's dispatch function is called whenever an rpc request comes in
61 * on a transport.  The request's program and version numbers must match
62 * those of the registered service.  The dispatch function is passed two
63 * parameters, struct svc_req * and SVCXPRT *, defined below.
64 */
65
66enum xprt_stat {
67        XPRT_DIED,
68        XPRT_MOREREQS,
69        XPRT_IDLE
70};
71
[df49c60]72struct rpc_msg;
73
[4721cf1]74/*
75 * Server side transport handle
76 */
[df49c60]77typedef struct __rpc_svcxprt {
[4721cf1]78        int             xp_sock;
79        u_short         xp_port;         /* associated port number */
80        struct xp_ops {
[df49c60]81            /* receive incoming requests */
[94c76bc]82            bool_t      (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
[df49c60]83            /* get transport status */
[94c76bc]84            enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
[df49c60]85            /* get arguments */
[94c76bc]86            bool_t      (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
[8faf4bd]87                                caddr_t);
[df49c60]88            /* send reply */
[94c76bc]89            bool_t      (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
[df49c60]90            /* free mem allocated for args */
[94c76bc]91            bool_t      (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
[8faf4bd]92                                caddr_t);
[df49c60]93            /* destroy this struct */
[94c76bc]94            void        (*xp_destroy)(struct __rpc_svcxprt *);
[4721cf1]95        } *xp_ops;
96        int             xp_addrlen;      /* length of remote address */
[94c76bc]97        struct sockaddr_in xp_raddr;     /* remote addr. (backward ABI compat) */
[4721cf1]98        struct opaque_auth xp_verf;      /* raw response verifier */
99        caddr_t         xp_p1;           /* private */
100        caddr_t         xp_p2;           /* private */
101} SVCXPRT;
102
[94c76bc]103/*
104 * Service request
105 */
106struct svc_req {
107        u_int32_t       rq_prog;        /* service program number */
108        u_int32_t       rq_vers;        /* service protocol version */
109        u_int32_t       rq_proc;        /* the desired procedure */
110        struct opaque_auth rq_cred;     /* raw creds from the wire */
111        caddr_t         rq_clntcred;    /* read only cooked cred */
112        SVCXPRT *rq_xprt;               /* associated transport */
113};
114
115
[4721cf1]116/*
117 *  Approved way of getting address of caller
118 */
119#define svc_getcaller(x) (&(x)->xp_raddr)
120
121/*
122 * Operations defined on an SVCXPRT handle
123 *
124 * SVCXPRT              *xprt;
125 * struct rpc_msg       *msg;
126 * xdrproc_t             xargs;
127 * caddr_t               argsp;
128 */
129#define SVC_RECV(xprt, msg)                             \
130        (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
131#define svc_recv(xprt, msg)                             \
132        (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
133
134#define SVC_STAT(xprt)                                  \
135        (*(xprt)->xp_ops->xp_stat)(xprt)
136#define svc_stat(xprt)                                  \
137        (*(xprt)->xp_ops->xp_stat)(xprt)
138
139#define SVC_GETARGS(xprt, xargs, argsp)                 \
140        (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
141#define svc_getargs(xprt, xargs, argsp)                 \
142        (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
143
144#define SVC_REPLY(xprt, msg)                            \
145        (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
146#define svc_reply(xprt, msg)                            \
147        (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
148
149#define SVC_FREEARGS(xprt, xargs, argsp)                \
150        (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
151#define svc_freeargs(xprt, xargs, argsp)                \
152        (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
153
154#define SVC_DESTROY(xprt)                               \
155        (*(xprt)->xp_ops->xp_destroy)(xprt)
156#define svc_destroy(xprt)                               \
157        (*(xprt)->xp_ops->xp_destroy)(xprt)
158
159
160/*
161 * Service registration
162 *
163 * svc_register(xprt, prog, vers, dispatch, protocol)
164 *      SVCXPRT *xprt;
165 *      u_long prog;
166 *      u_long vers;
167 *      void (*dispatch)();
[df49c60]168 *      int protocol;        (like TCP or UDP, zero means do not register)
[4721cf1]169 */
[df49c60]170__BEGIN_DECLS
[8faf4bd]171extern bool_t   svc_register (SVCXPRT *, u_long, u_long,
172                        void (*) (struct svc_req *, SVCXPRT *), int);
[df49c60]173__END_DECLS
[4721cf1]174
175/*
176 * Service un-registration
177 *
178 * svc_unregister(prog, vers)
179 *      u_long prog;
180 *      u_long vers;
181 */
[df49c60]182__BEGIN_DECLS
[8faf4bd]183extern void     svc_unregister (u_long, u_long);
[df49c60]184__END_DECLS
[4721cf1]185
186/*
187 * Transport registration.
188 *
189 * xprt_register(xprt)
190 *      SVCXPRT *xprt;
191 */
[df49c60]192__BEGIN_DECLS
[94c76bc]193extern void     xprt_register(SVCXPRT *);
[df49c60]194__END_DECLS
[4721cf1]195
196/*
197 * Transport un-register
198 *
199 * xprt_unregister(xprt)
200 *      SVCXPRT *xprt;
201 */
[df49c60]202__BEGIN_DECLS
[94c76bc]203extern void     xprt_unregister(SVCXPRT *);
[df49c60]204__END_DECLS
[4721cf1]205
206
207
208
209/*
210 * When the service routine is called, it must first check to see if it
211 * knows about the procedure;  if not, it should call svcerr_noproc
[df49c60]212 * and return.  If so, it should deserialize its arguments via
[4721cf1]213 * SVC_GETARGS (defined above).  If the deserialization does not work,
214 * svcerr_decode should be called followed by a return.  Successful
215 * decoding of the arguments should be followed the execution of the
216 * procedure's code and a call to svc_sendreply.
217 *
218 * Also, if the service refuses to execute the procedure due to too-
219 * weak authentication parameters, svcerr_weakauth should be called.
220 * Note: do not confuse access-control failure with weak authentication!
221 *
222 * NB: In pure implementations of rpc, the caller always waits for a reply
[df49c60]223 * msg.  This message is sent when svc_sendreply is called.
[4721cf1]224 * Therefore pure service implementations should always call
225 * svc_sendreply even if the function logically returns void;  use
226 * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
227 * for the abuse of pure rpc via batched calling or pipelining.  In the
228 * case of a batched call, svc_sendreply should NOT be called since
229 * this would send a return message, which is what batching tries to avoid.
230 * It is the service/protocol writer's responsibility to know which calls are
231 * batched and which are not.  Warning: responding to batch calls may
232 * deadlock the caller and server processes!
233 */
234
[df49c60]235__BEGIN_DECLS
[94c76bc]236extern bool_t   svc_sendreply(SVCXPRT *, xdrproc_t, char *);
237extern void     svcerr_decode(SVCXPRT *);
238extern void     svcerr_weakauth(SVCXPRT *);
239extern void     svcerr_noproc(SVCXPRT *);
240extern void     svcerr_progvers(SVCXPRT *, u_long, u_long);
241extern void     svcerr_auth(SVCXPRT *, enum auth_stat);
242extern void     svcerr_noprog(SVCXPRT *);
243extern void     svcerr_systemerr(SVCXPRT *);
[df49c60]244__END_DECLS
245
[4721cf1]246/*
247 * Lowest level dispatching -OR- who owns this process anyway.
248 * Somebody has to wait for incoming requests and then call the correct
249 * service routine.  The routine svc_run does infinite waiting; i.e.,
250 * svc_run never returns.
251 * Since another (co-existant) package may wish to selectively wait for
252 * incoming calls or other events outside of the rpc architecture, the
253 * routine svc_getreq is provided.  It must be passed readfds, the
254 * "in-place" results of a select system call (see select, section 2).
255 */
256
257/*
258 * Global keeper of rpc service descriptors in use
[df49c60]259 * dynamic; must be inspected before each call to select
[4721cf1]260 */
[df49c60]261extern int svc_maxfd;
[4721cf1]262extern fd_set svc_fdset;
263#define svc_fds svc_fdset.fds_bits[0]   /* compatibility */
264
[df49c60]265#ifndef _KERNEL
[4721cf1]266/*
267 * a small program implemented by the svc_rpc implementation itself;
268 * also see clnt.h for protocol numbers.
269 */
[94c76bc]270__BEGIN_DECLS
271extern void rpctest_service(void);
272__END_DECLS
[df49c60]273#endif
[4721cf1]274
[df49c60]275__BEGIN_DECLS
[94c76bc]276extern void     svc_getreq(int);
277extern void     svc_getreqset(fd_set *);
278extern void     svc_getreqset2(fd_set *, int); /* XXX: nonstd, undoc */
279extern void     svc_run(void);
[df49c60]280__END_DECLS
[4721cf1]281
282/*
283 * Socket to use on svcxxx_create call to get default socket
284 */
285#define RPC_ANYSOCK     -1
[94c76bc]286#define RPC_ANYFD       RPC_ANYSOCK
[4721cf1]287
288/*
289 * These are the existing service side transport implementations
290 */
291
292/*
293 * Memory based rpc for testing and timing.
294 */
[df49c60]295__BEGIN_DECLS
[8faf4bd]296extern SVCXPRT *svcraw_create (void);
[df49c60]297__END_DECLS
298
[4721cf1]299
300/*
301 * Udp based rpc.
302 */
[df49c60]303__BEGIN_DECLS
[8faf4bd]304extern SVCXPRT *svcudp_create (int);
305extern SVCXPRT *svcudp_bufcreate (int, u_int, u_int);
[df49c60]306__END_DECLS
307
[4721cf1]308
309/*
310 * Tcp based rpc.
311 */
[df49c60]312__BEGIN_DECLS
[8faf4bd]313extern SVCXPRT *svctcp_create (int, u_int, u_int);
314extern SVCXPRT *svcfd_create (int, u_int, u_int);
[df49c60]315__END_DECLS
[4721cf1]316
[df49c60]317/*
318 * AF_UNIX socket based rpc.
319 */
320__BEGIN_DECLS
[8faf4bd]321extern SVCXPRT *svcunix_create (int, u_int, u_int, char *);
322extern SVCXPRT *svcunixfd_create (int, u_int, u_int);
[df49c60]323__END_DECLS
[4721cf1]324
[df49c60]325#endif /* !_RPC_SVC_H */
Note: See TracBrowser for help on using the repository browser.