svc.h revision 1.4 1 1.4 cgd /* $NetBSD: svc.h,v 1.4 1994/10/26 00:57:04 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.1 deraadt typedef struct {
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.1 deraadt bool_t (*xp_recv)(); /* receive incomming requests */
81 1.1 deraadt enum xprt_stat (*xp_stat)(); /* get transport status */
82 1.1 deraadt bool_t (*xp_getargs)(); /* get arguments */
83 1.1 deraadt bool_t (*xp_reply)(); /* send reply */
84 1.1 deraadt bool_t (*xp_freeargs)();/* free mem allocated for args */
85 1.1 deraadt void (*xp_destroy)(); /* destroy this struct */
86 1.1 deraadt } *xp_ops;
87 1.1 deraadt int xp_addrlen; /* length of remote address */
88 1.1 deraadt struct sockaddr_in xp_raddr; /* remote address */
89 1.1 deraadt struct opaque_auth xp_verf; /* raw response verifier */
90 1.1 deraadt caddr_t xp_p1; /* private */
91 1.1 deraadt caddr_t xp_p2; /* private */
92 1.1 deraadt } SVCXPRT;
93 1.1 deraadt
94 1.1 deraadt /*
95 1.1 deraadt * Approved way of getting address of caller
96 1.1 deraadt */
97 1.1 deraadt #define svc_getcaller(x) (&(x)->xp_raddr)
98 1.1 deraadt
99 1.1 deraadt /*
100 1.1 deraadt * Operations defined on an SVCXPRT handle
101 1.1 deraadt *
102 1.1 deraadt * SVCXPRT *xprt;
103 1.1 deraadt * struct rpc_msg *msg;
104 1.1 deraadt * xdrproc_t xargs;
105 1.1 deraadt * caddr_t argsp;
106 1.1 deraadt */
107 1.1 deraadt #define SVC_RECV(xprt, msg) \
108 1.1 deraadt (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
109 1.1 deraadt #define svc_recv(xprt, msg) \
110 1.1 deraadt (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
111 1.1 deraadt
112 1.1 deraadt #define SVC_STAT(xprt) \
113 1.1 deraadt (*(xprt)->xp_ops->xp_stat)(xprt)
114 1.1 deraadt #define svc_stat(xprt) \
115 1.1 deraadt (*(xprt)->xp_ops->xp_stat)(xprt)
116 1.1 deraadt
117 1.1 deraadt #define SVC_GETARGS(xprt, xargs, argsp) \
118 1.1 deraadt (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
119 1.1 deraadt #define svc_getargs(xprt, xargs, argsp) \
120 1.1 deraadt (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
121 1.1 deraadt
122 1.1 deraadt #define SVC_REPLY(xprt, msg) \
123 1.1 deraadt (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
124 1.1 deraadt #define svc_reply(xprt, msg) \
125 1.1 deraadt (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
126 1.1 deraadt
127 1.1 deraadt #define SVC_FREEARGS(xprt, xargs, argsp) \
128 1.1 deraadt (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
129 1.1 deraadt #define svc_freeargs(xprt, xargs, argsp) \
130 1.1 deraadt (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
131 1.1 deraadt
132 1.1 deraadt #define SVC_DESTROY(xprt) \
133 1.1 deraadt (*(xprt)->xp_ops->xp_destroy)(xprt)
134 1.1 deraadt #define svc_destroy(xprt) \
135 1.1 deraadt (*(xprt)->xp_ops->xp_destroy)(xprt)
136 1.1 deraadt
137 1.1 deraadt
138 1.1 deraadt /*
139 1.1 deraadt * Service request
140 1.1 deraadt */
141 1.1 deraadt struct svc_req {
142 1.1 deraadt u_long rq_prog; /* service program number */
143 1.1 deraadt u_long rq_vers; /* service protocol version */
144 1.1 deraadt u_long rq_proc; /* the desired procedure */
145 1.1 deraadt struct opaque_auth rq_cred; /* raw creds from the wire */
146 1.1 deraadt caddr_t rq_clntcred; /* read only cooked cred */
147 1.1 deraadt SVCXPRT *rq_xprt; /* associated transport */
148 1.1 deraadt };
149 1.1 deraadt
150 1.1 deraadt
151 1.1 deraadt /*
152 1.1 deraadt * Service registration
153 1.1 deraadt *
154 1.1 deraadt * svc_register(xprt, prog, vers, dispatch, protocol)
155 1.1 deraadt * SVCXPRT *xprt;
156 1.1 deraadt * u_long prog;
157 1.1 deraadt * u_long vers;
158 1.1 deraadt * void (*dispatch)();
159 1.1 deraadt * int protocol; /* like TCP or UDP, zero means do not register
160 1.1 deraadt */
161 1.2 brezak __BEGIN_DECLS
162 1.2 brezak extern bool_t svc_register __P((SVCXPRT *, u_long, u_long, void (*)(), int));
163 1.2 brezak __END_DECLS
164 1.1 deraadt
165 1.1 deraadt /*
166 1.1 deraadt * Service un-registration
167 1.1 deraadt *
168 1.1 deraadt * svc_unregister(prog, vers)
169 1.1 deraadt * u_long prog;
170 1.1 deraadt * u_long vers;
171 1.1 deraadt */
172 1.2 brezak __BEGIN_DECLS
173 1.2 brezak extern void svc_unregister __P((u_long, u_long));
174 1.2 brezak __END_DECLS
175 1.1 deraadt
176 1.1 deraadt /*
177 1.1 deraadt * Transport registration.
178 1.1 deraadt *
179 1.1 deraadt * xprt_register(xprt)
180 1.1 deraadt * SVCXPRT *xprt;
181 1.1 deraadt */
182 1.2 brezak __BEGIN_DECLS
183 1.2 brezak extern void xprt_register __P((SVCXPRT *));
184 1.2 brezak __END_DECLS
185 1.1 deraadt
186 1.1 deraadt /*
187 1.1 deraadt * Transport un-register
188 1.1 deraadt *
189 1.1 deraadt * xprt_unregister(xprt)
190 1.1 deraadt * SVCXPRT *xprt;
191 1.1 deraadt */
192 1.2 brezak __BEGIN_DECLS
193 1.2 brezak extern void xprt_unregister __P((SVCXPRT *));
194 1.2 brezak __END_DECLS
195 1.1 deraadt
196 1.1 deraadt
197 1.1 deraadt
198 1.1 deraadt
199 1.1 deraadt /*
200 1.1 deraadt * When the service routine is called, it must first check to see if it
201 1.1 deraadt * knows about the procedure; if not, it should call svcerr_noproc
202 1.1 deraadt * and return. If so, it should deserialize its arguments via
203 1.1 deraadt * SVC_GETARGS (defined above). If the deserialization does not work,
204 1.1 deraadt * svcerr_decode should be called followed by a return. Successful
205 1.1 deraadt * decoding of the arguments should be followed the execution of the
206 1.1 deraadt * procedure's code and a call to svc_sendreply.
207 1.1 deraadt *
208 1.1 deraadt * Also, if the service refuses to execute the procedure due to too-
209 1.1 deraadt * weak authentication parameters, svcerr_weakauth should be called.
210 1.1 deraadt * Note: do not confuse access-control failure with weak authentication!
211 1.1 deraadt *
212 1.1 deraadt * NB: In pure implementations of rpc, the caller always waits for a reply
213 1.1 deraadt * msg. This message is sent when svc_sendreply is called.
214 1.1 deraadt * Therefore pure service implementations should always call
215 1.1 deraadt * svc_sendreply even if the function logically returns void; use
216 1.1 deraadt * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
217 1.1 deraadt * for the abuse of pure rpc via batched calling or pipelining. In the
218 1.1 deraadt * case of a batched call, svc_sendreply should NOT be called since
219 1.1 deraadt * this would send a return message, which is what batching tries to avoid.
220 1.1 deraadt * It is the service/protocol writer's responsibility to know which calls are
221 1.1 deraadt * batched and which are not. Warning: responding to batch calls may
222 1.1 deraadt * deadlock the caller and server processes!
223 1.1 deraadt */
224 1.1 deraadt
225 1.2 brezak __BEGIN_DECLS
226 1.2 brezak extern bool_t svc_sendreply __P((SVCXPRT *, xdrproc_t, char *));
227 1.2 brezak extern void svcerr_decode __P((SVCXPRT *));
228 1.2 brezak extern void svcerr_weakauth __P((SVCXPRT *));
229 1.2 brezak extern void svcerr_noproc __P((SVCXPRT *));
230 1.2 brezak extern void svcerr_progvers __P((SVCXPRT *, u_long, u_long));
231 1.2 brezak extern void svcerr_auth __P((SVCXPRT *, enum auth_stat));
232 1.2 brezak extern void svcerr_noprog __P((SVCXPRT *));
233 1.2 brezak extern void svcerr_systemerr __P((SVCXPRT *));
234 1.2 brezak __END_DECLS
235 1.1 deraadt
236 1.1 deraadt /*
237 1.1 deraadt * Lowest level dispatching -OR- who owns this process anyway.
238 1.1 deraadt * Somebody has to wait for incoming requests and then call the correct
239 1.1 deraadt * service routine. The routine svc_run does infinite waiting; i.e.,
240 1.1 deraadt * svc_run never returns.
241 1.1 deraadt * Since another (co-existant) package may wish to selectively wait for
242 1.1 deraadt * incoming calls or other events outside of the rpc architecture, the
243 1.1 deraadt * routine svc_getreq is provided. It must be passed readfds, the
244 1.1 deraadt * "in-place" results of a select system call (see select, section 2).
245 1.1 deraadt */
246 1.1 deraadt
247 1.1 deraadt /*
248 1.1 deraadt * Global keeper of rpc service descriptors in use
249 1.1 deraadt * dynamic; must be inspected before each call to select
250 1.1 deraadt */
251 1.1 deraadt #ifdef FD_SETSIZE
252 1.1 deraadt extern fd_set svc_fdset;
253 1.1 deraadt #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
254 1.1 deraadt #else
255 1.1 deraadt extern int svc_fds;
256 1.1 deraadt #endif /* def FD_SETSIZE */
257 1.1 deraadt
258 1.1 deraadt /*
259 1.1 deraadt * a small program implemented by the svc_rpc implementation itself;
260 1.1 deraadt * also see clnt.h for protocol numbers.
261 1.1 deraadt */
262 1.1 deraadt extern void rpctest_service();
263 1.1 deraadt
264 1.2 brezak __BEGIN_DECLS
265 1.2 brezak extern void svc_getreq __P((int));
266 1.2 brezak extern void svc_getreqset __P((fd_set *));
267 1.2 brezak extern void svc_run __P((void));
268 1.2 brezak __END_DECLS
269 1.1 deraadt
270 1.1 deraadt /*
271 1.1 deraadt * Socket to use on svcxxx_create call to get default socket
272 1.1 deraadt */
273 1.1 deraadt #define RPC_ANYSOCK -1
274 1.1 deraadt
275 1.1 deraadt /*
276 1.1 deraadt * These are the existing service side transport implementations
277 1.1 deraadt */
278 1.1 deraadt
279 1.1 deraadt /*
280 1.1 deraadt * Memory based rpc for testing and timing.
281 1.1 deraadt */
282 1.2 brezak __BEGIN_DECLS
283 1.2 brezak extern SVCXPRT *svcraw_create __P((void));
284 1.2 brezak __END_DECLS
285 1.1 deraadt
286 1.2 brezak
287 1.1 deraadt /*
288 1.1 deraadt * Udp based rpc.
289 1.1 deraadt */
290 1.2 brezak __BEGIN_DECLS
291 1.2 brezak extern SVCXPRT *svcudp_create __P((int));
292 1.2 brezak extern SVCXPRT *svcudp_bufcreate __P((int, u_int, u_int));
293 1.2 brezak __END_DECLS
294 1.2 brezak
295 1.1 deraadt
296 1.1 deraadt /*
297 1.1 deraadt * Tcp based rpc.
298 1.1 deraadt */
299 1.2 brezak __BEGIN_DECLS
300 1.2 brezak extern SVCXPRT *svctcp_create __P((int, u_int, u_int));
301 1.2 brezak __END_DECLS
302 1.1 deraadt
303 1.2 brezak #endif /* !_RPC_SVC_H */
304