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