Watt-32 tcp/ip  2.2 dev-rel.10
svc.h
Go to the documentation of this file.
1 
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_W32API_H
48 #include <sys/w32api.h>
49 #endif
50 
51 #ifndef __SYS_WTYPES_H
52 #include <sys/wtypes.h>
53 #endif
54 
55 #ifndef __SYS_CDEFS_H
56 #include <sys/cdefs.h>
57 #endif
58 
59 /*
60  * This interface must manage two items concerning remote procedure calling:
61  *
62  * 1) An arbitrary number of transport connections upon which rpc requests
63  * are received. The two most notable transports are TCP and UDP; they are
64  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
65  * they in turn call xprt_register and xprt_unregister.
66  *
67  * 2) An arbitrary number of locally registered services. Services are
68  * described by the following four data: program number, version number,
69  * "service dispatch" function, a transport handle, and a boolean that
70  * indicates whether or not the exported program should be registered with a
71  * local binder service; if true the program's number and version and the
72  * port number from the transport handle are registered with the binder.
73  * These data are registered with the rpc svc system via svc_register.
74  *
75  * A service's dispatch function is called whenever an rpc request comes in
76  * on a transport. The request's program and version numbers must match
77  * those of the registered service. The dispatch function is passed two
78  * parameters, struct svc_req * and SVCXPRT *, defined below.
79  */
80 
81 enum xprt_stat {
82  XPRT_DIED,
83  XPRT_MOREREQS,
84  XPRT_IDLE
85  };
86 
87 /*
88  * Server side transport handle
89  */
90 typedef struct {
91  int xp_sock;
92  u_short xp_port; /* associated port number */
93  struct xp_ops {
94  bool_t (*xp_recv)(); /* receive incoming requests */
95  enum xprt_stat (*xp_stat)(); /* get transport status */
96  bool_t (*xp_getargs)(); /* get arguments */
97  bool_t (*xp_reply)(); /* send reply */
98  bool_t (*xp_freeargs)(); /* free mem allocated for args */
99  void (*xp_destroy)(); /* destroy this struct */
100  } *xp_ops;
101  int xp_addrlen; /* length of remote address */
102  struct sockaddr_in xp_raddr; /* remote address */
103  struct opaque_auth xp_verf; /* raw response verifier */
104  caddr_t xp_p1; /* private */
105  caddr_t xp_p2; /* private */
106  } SVCXPRT;
107 
108 /*
109  * Approved way of getting address of caller
110  */
111 #define svc_getcaller(x) (&(x)->xp_raddr)
112 
113 /*
114  * Operations defined on an SVCXPRT handle
115  *
116  * SVCXPRT *xprt;
117  * struct rpc_msg *msg;
118  * xdrproc_t xargs;
119  * caddr_t argsp;
120  */
121 #define SVC_RECV(xprt, msg) \
122  (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
123 
124 #define svc_recv(xprt, msg) \
125  (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
126 
127 #define SVC_STAT(xprt) \
128  (*(xprt)->xp_ops->xp_stat)(xprt)
129 
130 #define svc_stat(xprt) \
131  (*(xprt)->xp_ops->xp_stat)(xprt)
132 
133 #define SVC_GETARGS(xprt, xargs, argsp) \
134  (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
135 
136 #define svc_getargs(xprt, xargs, argsp) \
137  (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
138 
139 #define SVC_REPLY(xprt, msg) \
140  (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
141 
142 #define svc_reply(xprt, msg) \
143  (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
144 
145 #define SVC_FREEARGS(xprt, xargs, argsp) \
146  (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
147 
148 #define svc_freeargs(xprt, xargs, argsp) \
149  (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
150 
151 #define SVC_DESTROY(xprt) \
152  (*(xprt)->xp_ops->xp_destroy)(xprt)
153 
154 #define svc_destroy(xprt) \
155  (*(xprt)->xp_ops->xp_destroy)(xprt)
156 
157 
158 /*
159  * Service request
160  */
161 struct svc_req {
162  u_long rq_prog; /* service program number */
163  u_long rq_vers; /* service protocol version */
164  u_long rq_proc; /* the desired procedure */
165  struct opaque_auth rq_cred; /* raw creds from the wire */
166  caddr_t rq_clntcred; /* read only cooked cred */
167  SVCXPRT *rq_xprt; /* associated transport */
168  };
169 
170 __BEGIN_DECLS
171 
172 /*
173  * Service registration
174  *
175  * svc_register(xprt, prog, vers, dispatch, protocol)
176  * SVCXPRT *xprt;
177  * u_long prog;
178  * u_long vers;
179  * void (*dispatch)();
180  * int protocol; // like TCP or UDP, zero means do not register
181  */
182 W32_FUNC bool_t W32_CALL svc_register (SVCXPRT *, u_long, u_long, void (*)(), int);
183 
184 /*
185  * Service un-registration
186  *
187  * svc_unregister(prog, vers)
188  * u_long prog;
189  * u_long vers;
190  */
191 W32_FUNC void W32_CALL svc_unregister (u_long, u_long);
192 
193 /*
194  * Transport registration.
195  *
196  * xprt_register(xprt)
197  * SVCXPRT *xprt;
198  */
199 W32_FUNC void W32_CALL xprt_register (SVCXPRT *);
200 
201 /*
202  * Transport un-register
203  *
204  * xprt_unregister(xprt)
205  * SVCXPRT *xprt;
206  */
207 W32_FUNC void W32_CALL xprt_unregister (SVCXPRT *);
208 
209 
210 
211 /*
212  * When the service routine is called, it must first check to see if it
213  * knows about the procedure; if not, it should call svcerr_noproc
214  * and return. If so, it should deserialize its arguments via
215  * SVC_GETARGS (defined above). If the deserialization does not work,
216  * svcerr_decode should be called followed by a return. Successful
217  * decoding of the arguments should be followed the execution of the
218  * procedure's code and a call to svc_sendreply.
219  *
220  * Also, if the service refuses to execute the procedure due to too-
221  * weak authentication parameters, svcerr_weakauth should be called.
222  * Note: do not confuse access-control failure with weak authentication!
223  *
224  * NB: In pure implementations of rpc, the caller always waits for a reply
225  * msg. This message is sent when svc_sendreply is called.
226  * Therefore pure service implementations should always call
227  * svc_sendreply even if the function logically returns void; use
228  * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
229  * for the abuse of pure rpc via batched calling or pipelining. In the
230  * case of a batched call, svc_sendreply should NOT be called since
231  * this would send a return message, which is what batching tries to avoid.
232  * It is the service/protocol writer's responsibility to know which calls are
233  * batched and which are not. Warning: responding to batch calls may
234  * deadlock the caller and server processes!
235  */
236 
237 W32_FUNC bool_t W32_CALL svc_sendreply (SVCXPRT *, xdrproc_t, char *);
238 W32_FUNC void W32_CALL svcerr_decode (SVCXPRT *);
239 W32_FUNC void W32_CALL svcerr_weakauth (SVCXPRT *);
240 W32_FUNC void W32_CALL svcerr_noproc (SVCXPRT *);
241 W32_FUNC void W32_CALL svcerr_progvers (SVCXPRT *, u_long, u_long);
242 W32_FUNC void W32_CALL svcerr_auth (SVCXPRT *, enum auth_stat);
243 W32_FUNC void W32_CALL svcerr_noprog (SVCXPRT *);
244 W32_FUNC void W32_CALL svcerr_systemerr(SVCXPRT *);
245 
246 /*
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 (co-existant) 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).
255  */
256 
257 /*
258  * Global keeper of rpc service descriptors in use
259  * dynamic; must be inspected before each call to select
260  */
261 #ifdef FD_SETSIZE
262  W32_FUNC void svc_getreqset (fd_set *);
263  W32_DATA fd_set svc_fdset;
264  #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
265 #else
266  W32_DATA int svc_fds;
267 #endif
268 
269 /*
270  * a small program implemented by the svc_rpc implementation itself;
271  * also see clnt.h for protocol numbers.
272  */
273 W32_FUNC void W32_CALL rpctest_service();
274 W32_FUNC void W32_CALL svc_getreq (int);
275 W32_FUNC void W32_CALL svc_run (void);
276 
277 /*
278  * Socket to use on svcxxx_create call to get default socket
279  */
280 #define RPC_ANYSOCK -1
281 
282 /*
283  * These are the existing service side transport implementations
284  */
285 
286 /*
287  * Memory based rpc for testing and timing.
288  */
289 W32_FUNC SVCXPRT * W32_CALL svcraw_create (void);
290 
291 
292 /*
293  * Udp based rpc.
294  */
295 W32_FUNC SVCXPRT * W32_CALL svcudp_create (int);
296 W32_FUNC SVCXPRT * W32_CALL svcudp_bufcreate (int, u_int, u_int);
297 
298 /*
299  * Tcp based rpc.
300  */
301 W32_FUNC SVCXPRT * W32_CALL svctcp_create (int, u_int, u_int);
302 
303 __END_DECLS
304 
305 #endif
Definition: wtypes.h:197
Definition: svc.h:90
Definition: svc.h:161