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