Update.
[glibc.git] / sunrpc / rpc / svc.h
blob6b308f356e3556e03dd3da2a4c65197bd87aec85
1 /* @(#)svc.h 2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
2 /*
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
32 * svc.h, Server-side remote procedure call interface.
34 * Copyright (C) 1984, Sun Microsystems, Inc.
37 #ifndef __SVC_HEADER__
38 #define __SVC_HEADER__
40 #include <features.h>
41 #include <rpc/rpc_msg.h>
43 __BEGIN_DECLS
46 * This interface must manage two items concerning remote procedure calling:
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.
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.
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.
67 enum xprt_stat {
68 XPRT_DIED,
69 XPRT_MOREREQS,
70 XPRT_IDLE
74 * Server side transport handle
76 typedef struct SVCXPRT SVCXPRT;
77 struct SVCXPRT {
78 int xp_sock;
79 u_short xp_port; /* associated port number */
80 const struct xp_ops {
81 bool_t (*xp_recv) __P ((SVCXPRT *__xprt, struct rpc_msg *__msg));
82 /* receive incoming requests */
83 enum xprt_stat (*xp_stat) __P ((SVCXPRT *__xprt));
84 /* get transport status */
85 bool_t (*xp_getargs) __P ((SVCXPRT *__xprt, xdrproc_t __xdr_args,
86 caddr_t args_ptr)); /* get arguments */
87 bool_t (*xp_reply) __P ((SVCXPRT *__xprt, struct rpc_msg *__msg));
88 /* send reply */
89 bool_t (*xp_freeargs) __P ((SVCXPRT *__xprt, xdrproc_t __xdr_args,
90 caddr_t args_ptr));
91 /* free mem allocated for args */
92 void (*xp_destroy) __P ((SVCXPRT *__xprt));
93 /* destroy this struct */
94 } *xp_ops;
95 int xp_addrlen; /* length of remote address */
96 struct sockaddr_in xp_raddr; /* remote address */
97 struct opaque_auth xp_verf; /* raw response verifier */
98 caddr_t xp_p1; /* private */
99 caddr_t xp_p2; /* private */
103 * Approved way of getting address of caller
105 #define svc_getcaller(x) (&(x)->xp_raddr)
108 * Operations defined on an SVCXPRT handle
110 * SVCXPRT *xprt;
111 * struct rpc_msg *msg;
112 * xdrproc_t xargs;
113 * caddr_t argsp;
115 #define SVC_RECV(xprt, msg) \
116 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
117 #define svc_recv(xprt, msg) \
118 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
120 #define SVC_STAT(xprt) \
121 (*(xprt)->xp_ops->xp_stat)(xprt)
122 #define svc_stat(xprt) \
123 (*(xprt)->xp_ops->xp_stat)(xprt)
125 #define SVC_GETARGS(xprt, xargs, argsp) \
126 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
127 #define svc_getargs(xprt, xargs, argsp) \
128 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
130 #define SVC_REPLY(xprt, msg) \
131 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
132 #define svc_reply(xprt, msg) \
133 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
135 #define SVC_FREEARGS(xprt, xargs, argsp) \
136 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
137 #define svc_freeargs(xprt, xargs, argsp) \
138 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
140 #define SVC_DESTROY(xprt) \
141 (*(xprt)->xp_ops->xp_destroy)(xprt)
142 #define svc_destroy(xprt) \
143 (*(xprt)->xp_ops->xp_destroy)(xprt)
147 * Service request
149 struct svc_req {
150 u_long rq_prog; /* service program number */
151 u_long rq_vers; /* service protocol version */
152 u_long rq_proc; /* the desired procedure */
153 struct opaque_auth rq_cred; /* raw creds from the wire */
154 caddr_t rq_clntcred; /* read only cooked cred */
155 SVCXPRT *rq_xprt; /* associated transport */
160 * Service registration
162 * svc_register(xprt, prog, vers, dispatch, protocol)
163 * SVCXPRT *xprt;
164 * u_long prog;
165 * u_long vers;
166 * void (*dispatch)();
167 * u_long protocol; like TCP or UDP, zero means do not register
169 extern bool_t svc_register __P ((SVCXPRT *__xprt, u_long __prog,
170 u_long __vers, void (*__dispatch)
171 __P ((struct svc_req *, SVCXPRT *)),
172 u_long __protocol));
175 * Service un-registration
177 * svc_unregister(prog, vers)
178 * u_long prog;
179 * u_long vers;
181 extern void svc_unregister __P ((u_long __prog, u_long __vers));
184 * Transport registration.
186 * xprt_register(xprt)
187 * SVCXPRT *xprt;
189 extern void xprt_register __P ((SVCXPRT *__xprt));
192 * Transport un-register
194 * xprt_unregister(xprt)
195 * SVCXPRT *xprt;
197 extern void xprt_unregister __P ((SVCXPRT *__xprt));
203 * When the service routine is called, it must first check to see if it
204 * knows about the procedure; if not, it should call svcerr_noproc
205 * and return. If so, it should deserialize its arguments via
206 * SVC_GETARGS (defined above). If the deserialization does not work,
207 * svcerr_decode should be called followed by a return. Successful
208 * decoding of the arguments should be followed the execution of the
209 * procedure's code and a call to svc_sendreply.
211 * Also, if the service refuses to execute the procedure due to too-
212 * weak authentication parameters, svcerr_weakauth should be called.
213 * Note: do not confuse access-control failure with weak authentication!
215 * NB: In pure implementations of rpc, the caller always waits for a reply
216 * msg. This message is sent when svc_sendreply is called.
217 * Therefore pure service implementations should always call
218 * svc_sendreply even if the function logically returns void; use
219 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
220 * for the abuse of pure rpc via batched calling or pipelining. In the
221 * case of a batched call, svc_sendreply should NOT be called since
222 * this would send a return message, which is what batching tries to avoid.
223 * It is the service/protocol writer's responsibility to know which calls are
224 * batched and which are not. Warning: responding to batch calls may
225 * deadlock the caller and server processes!
228 extern bool_t svc_sendreply __P ((SVCXPRT *xprt, xdrproc_t __xdr_results,
229 caddr_t __xdr_location));
231 extern void svcerr_decode __P ((SVCXPRT *__xprt));
233 extern void svcerr_weakauth __P ((SVCXPRT *__xprt));
235 extern void svcerr_noproc __P ((SVCXPRT *__xprt));
237 extern void svcerr_progvers __P ((SVCXPRT *__xprt, u_long __low_vers,
238 u_long __high_vers));
240 extern void svcerr_auth __P ((SVCXPRT *__xprt, enum auth_stat __why));
242 extern void svcerr_noprog __P ((SVCXPRT *__xprt));
244 extern void svcerr_systemerr __P ((SVCXPRT *__xprt));
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 (coexistent) 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).
258 * Global keeper of rpc service descriptors in use
259 * dynamic; must be inspected before each call to select
261 #ifdef FD_SETSIZE
262 extern fd_set svc_fdset;
263 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
264 #else
265 extern int svc_fds;
266 #endif /* def FD_SETSIZE */
269 * a small program implemented by the svc_rpc implementation itself;
270 * also see clnt.h for protocol numbers.
272 extern void svc_getreq __P ((int __rdfds));
273 extern void svc_getreqset __P ((fd_set *__readfds));
274 extern void svc_exit __P ((void));
275 extern void svc_run __P ((void));
278 * Socket to use on svcxxx_create call to get default socket
280 #define RPC_ANYSOCK -1
283 * These are the existing service side transport implementations
287 * Memory based rpc for testing and timing.
289 extern SVCXPRT *svcraw_create __P ((void));
292 * Udp based rpc.
294 extern SVCXPRT *svcudp_create __P ((int __sock));
295 extern SVCXPRT *svcudp_bufcreate __P ((int __sock, u_int __sendsz,
296 u_int __recvsz));
299 * Tcp based rpc.
301 extern SVCXPRT *svctcp_create __P ((int __sock, u_int __sendsize,
302 u_int __recvsize));
305 __END_DECLS
307 #endif /* !__SVC_HEADER__ */