2 * RPC server-side interface.
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.
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.
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.
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.
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.
29 * Sun Microsystems, Inc.
31 * Mountain View, California 94043
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 $
39 * svc.h, Server-side remote procedure call interface.
41 * Copyright (C) 1984, Sun Microsystems, Inc.
48 #include <sys/cdefs.h>
52 * This interface must manage two items concerning remote procedure calling:
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.
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.
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.
80 * Server side transport handle
84 u_short xp_port; /* associated port number */
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 */
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 */
101 * Approved way of getting address of caller
103 #define svc_getcaller(x) (&(x)->xp_raddr)
106 * Operations defined on an SVCXPRT handle
109 * struct rpc_msg *msg;
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))
118 #define SVC_STAT(xprt) \
119 (*(xprt)->xp_ops->xp_stat)(xprt)
120 #define svc_stat(xprt) \
121 (*(xprt)->xp_ops->xp_stat)(xprt)
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))
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))
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))
138 #define SVC_DESTROY(xprt) \
139 (*(xprt)->xp_ops->xp_destroy)(xprt)
140 #define svc_destroy(xprt) \
141 (*(xprt)->xp_ops->xp_destroy)(xprt)
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 */
159 * Service registration
161 * svc_register(xprt, prog, vers, dispatch, protocol)
165 * void (*dispatch)();
166 * int protocol; // like TCP or UDP, zero means do not register
168 extern bool_t svc_register (SVCXPRT *, u_long, u_long, void (*)(), int);
171 * Service un-registration
173 * svc_unregister(prog, vers)
177 extern void svc_unregister (u_long, u_long);
180 * Transport registration.
182 * xprt_register(xprt)
185 extern void xprt_register (SVCXPRT *);
188 * Transport un-register
190 * xprt_unregister(xprt)
193 extern void xprt_unregister (SVCXPRT *);
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.
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!
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!
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 *);
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).
244 * Global keeper of rpc service descriptors in use
245 * dynamic; must be inspected before each call to select
248 extern void svc_getreqset (fd_set *);
249 extern fd_set svc_fdset;
250 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
256 * a small program implemented by the svc_rpc implementation itself;
257 * also see clnt.h for protocol numbers.
259 extern void rpctest_service();
260 extern void svc_getreq (int);
261 extern void svc_run (void);
264 * Socket to use on svcxxx_create call to get default socket
266 #define RPC_ANYSOCK -1
269 * These are the existing service side transport implementations
273 * Memory based rpc for testing and timing.
275 extern SVCXPRT *svcraw_create (void);
281 extern SVCXPRT *svcudp_create (int);
282 extern SVCXPRT *svcudp_bufcreate (int, u_int, u_int);
287 extern SVCXPRT *svctcp_create (int, u_int, u_int);