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