1 /*********************************************************************
2 * RPC for the Windows NT Operating System
3 * 1993 by Martin F. Gergeleit
4 * Users may use, copy or modify Sun RPC for the Windows NT Operating
5 * System according to the Sun copyright below.
7 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
8 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
9 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10 *********************************************************************/
12 /* @(#)svc.h 2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
14 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
15 * unrestricted use provided that this legend is included on all tape
16 * media and as a part of the software program in whole or part. Users
17 * may copy or modify Sun RPC without charge, but are not authorized
18 * to license or distribute it to anyone else except as part of a product or
19 * program developed by the user.
21 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
22 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
25 * Sun RPC is provided with no support and without any obligation on the
26 * part of Sun Microsystems, Inc. to assist in its use, correction,
27 * modification or enhancement.
29 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
30 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
31 * OR ANY PART THEREOF.
33 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
34 * or profits or other special, indirect and consequential damages, even if
35 * Sun has been advised of the possibility of such damages.
37 * Sun Microsystems, Inc.
39 * Mountain View, California 94043
43 * svc.h, Server-side remote procedure call interface.
45 * Copyright (C) 1984, Sun Microsystems, Inc.
48 #ifndef __SVC_HEADER__
49 #define __SVC_HEADER__
60 * This interface must manage two items concerning remote procedure calling:
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.
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.
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.
88 * Server side transport handle
92 u_short xp_port; /* associated port number */
94 bool_t (*xp_recv)(DOTS); /* receive incomming requests */
95 enum xprt_stat (*xp_stat)(DOTS); /* get transport status */
96 bool_t (*xp_getargs)(DOTS); /* get arguments */
97 bool_t (*xp_reply)(DOTS); /* send reply */
98 bool_t (*xp_freeargs)(DOTS);/* free mem allocated for args */
99 void (*xp_destroy)(DOTS); /* destroy this struct */
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 */
109 * Approved way of getting address of caller
111 #define svc_getcaller(x) (&(x)->xp_raddr)
114 * Operations defined on an SVCXPRT handle
117 * struct rpc_msg *msg;
121 #define SVC_RECV(xprt, msg) \
122 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
123 #define svc_recv(xprt, msg) \
124 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
126 #define SVC_STAT(xprt) \
127 (*(xprt)->xp_ops->xp_stat)(xprt)
128 #define svc_stat(xprt) \
129 (*(xprt)->xp_ops->xp_stat)(xprt)
131 #define SVC_GETARGS(xprt, xargs, argsp) \
132 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
133 #define svc_getargs(xprt, xargs, argsp) \
134 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
136 #define SVC_REPLY(xprt, msg) \
137 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
138 #define svc_reply(xprt, msg) \
139 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
141 #define SVC_FREEARGS(xprt, xargs, argsp) \
142 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
143 #define svc_freeargs(xprt, xargs, argsp) \
144 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
146 #define SVC_DESTROY(xprt) \
147 (*(xprt)->xp_ops->xp_destroy)(xprt)
148 #define svc_destroy(xprt) \
149 (*(xprt)->xp_ops->xp_destroy)(xprt)
156 u_long rq_prog; /* service program number */
157 u_long rq_vers; /* service protocol version */
158 u_long rq_proc; /* the desired procedure */
159 struct opaque_auth rq_cred; /* raw creds from the wire */
160 caddr_t rq_clntcred; /* read only cooked cred */
161 SVCXPRT *rq_xprt; /* associated transport */
166 * Service registration
168 * svc_register(xprt, prog, vers, dispatch, protocol)
172 * void (*dispatch)(DOTS);
173 * int protocol; /* like TCP or UDP, zero means do not register
175 extern bool_t svc_register(DOTS);
178 * Service un-registration
180 * svc_unregister(prog, vers)
184 extern void svc_unregister(DOTS);
187 * Transport registration.
189 * xprt_register(xprt)
192 extern void xprt_register(DOTS);
195 * Transport un-register
197 * xprt_unregister(xprt)
200 extern void xprt_unregister(DOTS);
206 * When the service routine is called, it must first check to see if it
207 * knows about the procedure; if not, it should call svcerr_noproc
208 * and return. If so, it should deserialize its arguments via
209 * SVC_GETARGS (defined above). If the deserialization does not work,
210 * svcerr_decode should be called followed by a return. Successful
211 * decoding of the arguments should be followed the execution of the
212 * procedure's code and a call to svc_sendreply.
214 * Also, if the service refuses to execute the procedure due to too-
215 * weak authentication parameters, svcerr_weakauth should be called.
216 * Note: do not confuse access-control failure with weak authentication!
218 * NB: In pure implementations of rpc, the caller always waits for a reply
219 * msg. This message is sent when svc_sendreply is called.
220 * Therefore pure service implementations should always call
221 * svc_sendreply even if the function logically returns void; use
222 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
223 * for the abuse of pure rpc via batched calling or pipelining. In the
224 * case of a batched call, svc_sendreply should NOT be called since
225 * this would send a return message, which is what batching tries to avoid.
226 * It is the service/protocol writer's responsibility to know which calls are
227 * batched and which are not. Warning: responding to batch calls may
228 * deadlock the caller and server processes!
231 extern bool_t svc_sendreply(DOTS);
232 extern void svcerr_decode(DOTS);
233 extern void svcerr_weakauth(DOTS);
234 extern void svcerr_noproc(DOTS);
235 extern void svcerr_progvers(DOTS);
236 extern void svcerr_auth(DOTS);
237 extern void svcerr_noprog(DOTS);
238 extern void svcerr_systemerr(DOTS);
241 * Lowest level dispatching -OR- who owns this process anyway.
242 * Somebody has to wait for incoming requests and then call the correct
243 * service routine. The routine svc_run does infinite waiting; i.e.,
244 * svc_run never returns.
245 * Since another (co-existant) package may wish to selectively wait for
246 * incoming calls or other events outside of the rpc architecture, the
247 * routine svc_getreq is provided. It must be passed readfds, the
248 * "in-place" results of a select system call (see select, section 2).
252 * Global keeper of rpc service descriptors in use
253 * dynamic; must be inspected before each call to select
256 #define svc_fdset (*_thr_svc_fdset())
258 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
262 #endif /* def FD_SETSIZE */
265 * a small program implemented by the svc_rpc implementation itself;
266 * also see clnt.h for protocol numbers.
268 extern void rpctest_service(DOTS);
270 extern void svc_getreq(DOTS);
271 extern void svc_getreqset(DOTS); /* takes fdset instead of int */
272 extern void svc_run(DOTS); /* never returns */
275 * Socket to use on svcxxx_create call to get default socket
277 #define RPC_ANYSOCK -1
280 * These are the existing service side transport implementations
284 * Memory based rpc for testing and timing.
286 extern SVCXPRT *svcraw_create(DOTS);
291 extern SVCXPRT *svcudp_create(DOTS);
292 extern SVCXPRT *svcudp_bufcreate(DOTS);
297 extern SVCXPRT *svctcp_create(DOTS);
302 extern SVCXPRT *svcfd_create(DOTS);
308 #endif /* __SVC_HEADER__ */