2 * @(#)svc.h 2.1 97/10/23
4 /* @(#)svc.h 2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
6 * Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
8 * Standard Performance Evaluation Corporation (SPEC)
9 * 6585 Merchant Place, Suite 100
12 * This product contains benchmarks acquired from several sources who
13 * understand and agree with SPEC's goal of creating fair and objective
14 * benchmarks to measure computer performance.
16 * This copyright notice is placed here only to protect SPEC in the
17 * event the source is misused in any manner that is contrary to the
18 * spirit, the goals and the intent of SPEC.
20 * The source code is provided to the user or company under the license
21 * agreement for the SPEC Benchmark Suite for this product.
24 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25 * unrestricted use provided that this legend is included on all tape
26 * media and as a part of the software program in whole or part. Users
27 * may copy or modify Sun RPC without charge, but are not authorized
28 * to license or distribute it to anyone else except as part of a product or
29 * program developed by the user.
31 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
35 * Sun RPC is provided with no support and without any obligation on the
36 * part of Sun Microsystems, Inc. to assist in its use, correction,
37 * modification or enhancement.
39 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41 * OR ANY PART THEREOF.
43 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44 * or profits or other special, indirect and consequential damages, even if
45 * Sun has been advised of the possibility of such damages.
47 * Sun Microsystems, Inc.
49 * Mountain View, California 94043
53 * svc.h, Server-side remote procedure call interface.
55 * Copyright (C) 1984, Sun Microsystems, Inc.
58 #ifndef __SVC_HEADER__
59 #define __SVC_HEADER__
61 #include "rpc/rpc_msg.h"
65 * This interface must manage two items concerning remote procedure calling:
67 * 1) An arbitrary number of transport connections upon which rpc requests
68 * are received. The two most notable transports are TCP and UDP; they are
69 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
70 * they in turn call xprt_register and xprt_unregister.
72 * 2) An arbitrary number of locally registered services. Services are
73 * described by the following four data: program number, version number,
74 * "service dispatch" function, a transport handle, and a boolean that
75 * indicates whether or not the exported program should be registered with a
76 * local binder service; if true the program's number and version and the
77 * port number from the transport handle are registered with the binder.
78 * These data are registered with the rpc svc system via svc_register.
80 * A service's dispatch function is called whenever an rpc request comes in
81 * on a transport. The request's program and version numbers must match
82 * those of the registered service. The dispatch function is passed two
83 * parameters, struct svc_req * and SVCXPRT *, defined below.
93 * Server side transport handle
95 typedef struct SVCXPRT {
97 uint16_t xp_port; /* associated port number */
98 struct xp_ops *xp_ops;
100 size_t xp_addrlen; /* length of remote address */
102 int xp_addrlen; /* length of remote address */
104 struct sockaddr_in xp_raddr; /* remote address */
105 struct opaque_auth xp_verf; /* raw response verifier */
106 void * xp_p1; /* private */
107 void * xp_p2; /* private */
111 bool_t (*xp_recv)(SVCXPRT *, struct rpc_msg *);
112 enum xprt_stat (*xp_stat)(SVCXPRT *);
113 bool_t (*xp_getargs)(SVCXPRT *, xdrproc_t, void *);
114 bool_t (*xp_reply)(SVCXPRT *, struct rpc_msg *);
115 bool_t (*xp_freeargs)(SVCXPRT *, xdrproc_t, void *);
116 void (*xp_destroy)(SVCXPRT *);
119 * Approved way of getting address of caller
121 #define svc_getcaller(x) (&(x)->xp_raddr)
124 * Operations defined on an SVCXPRT handle
127 * struct rpc_msg *msg;
131 #define SVC_RECV(xprt, msg) \
132 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
133 #define svc_recv(xprt, msg) \
134 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
136 #define SVC_STAT(xprt) \
137 (*(xprt)->xp_ops->xp_stat)(xprt)
138 #define svc_stat(xprt) \
139 (*(xprt)->xp_ops->xp_stat)(xprt)
141 #define SVC_GETARGS(xprt, xargs, argsp) \
142 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
143 #define svc_getargs(xprt, xargs, argsp) \
144 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
146 #define SVC_REPLY(xprt, msg) \
147 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
148 #define svc_reply(xprt, msg) \
149 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
151 #define SVC_FREEARGS(xprt, xargs, argsp) \
152 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
153 #define svc_freeargs(xprt, xargs, argsp) \
154 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
156 #define SVC_DESTROY(xprt) \
157 (*(xprt)->xp_ops->xp_destroy)(xprt)
158 #define svc_destroy(xprt) \
159 (*(xprt)->xp_ops->xp_destroy)(xprt)
166 uint32_t rq_prog; /* service program number */
167 uint32_t rq_vers; /* service protocol version */
168 uint32_t rq_proc; /* the desired procedure */
169 struct opaque_auth rq_cred; /* raw creds from the wire */
170 void * rq_clntcred; /* read only cooked cred */
171 SVCXPRT *rq_xprt; /* associated transport */
176 * Service registration
178 * svc_register(xprt, prog, vers, dispatch, protocol)
182 * void (*dispatch)();
185 extern bool_t svc_register(SVCXPRT *, uint32_t, uint32_t, void (*)(), int);
188 * Service un-registration
190 * svc_unregister(prog, vers)
194 extern void svc_unregister(uint32_t, uint32_t);
197 * Transport registration.
199 * xprt_register(xprt)
202 extern void xprt_register(SVCXPRT *);
205 * Transport un-register
207 * xprt_unregister(xprt)
210 extern void xprt_unregister(SVCXPRT *);
216 * When the service routine is called, it must first check to see if it
217 * knows about the procedure; if not, it should call svcerr_noproc
218 * and return. If so, it should deserialize its arguments via
219 * SVC_GETARGS (defined above). If the deserialization does not work,
220 * svcerr_decode should be called followed by a return. Successful
221 * decoding of the arguments should be followed the execution of the
222 * procedure's code and a call to svc_sendreply.
224 * Also, if the service refuses to execute the procedure due to too-
225 * weak authentication parameters, svcerr_weakauth should be called.
226 * Note: do not confuse access-control failure with weak authentication!
228 * NB: In pure implementations of rpc, the caller always waits for a reply
229 * msg. This message is sent when svc_sendreply is called.
230 * Therefore pure service implementations should always call
231 * svc_sendreply even if the function logically returns void; use
232 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
233 * for the abuse of pure rpc via batched calling or pipelining. In the
234 * case of a batched call, svc_sendreply should NOT be called since
235 * this would send a return message, which is what batching tries to avoid.
236 * It is the service/protocol writer's responsibility to know which calls are
237 * batched and which are not. Warning: responding to batch calls may
238 * deadlock the caller and server processes!
241 extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
242 extern void svcerr_decode(SVCXPRT *);
243 extern void svcerr_weakauth(SVCXPRT *);
244 extern void svcerr_noproc(SVCXPRT *);
245 extern void svcerr_progvers(SVCXPRT *, uint32_t, uint32_t);
246 extern void svcerr_auth(SVCXPRT *, enum auth_stat);
247 extern void svcerr_noprog(SVCXPRT *);
248 extern void svcerr_systemerr(SVCXPRT *);
251 * Lowest level dispatching -OR- who owns this process anyway.
252 * Somebody has to wait for incoming requests and then call the correct
253 * service routine. The routine svc_run does infinite waiting; i.e.,
254 * svc_run never returns.
255 * Since another (co-existant) package may wish to selectively wait for
256 * incoming calls or other events outside of the rpc architecture, the
257 * routine svc_getreq is provided. It must be passed readfds, the
258 * "in-place" results of a select system call (see select, section 2).
262 * Global keeper of rpc service descriptors in use
263 * dynamic; must be inspected before each call to select
266 extern fd_set svc_fdset;
267 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
270 #endif /* def FD_SETSIZE */
273 * a small program implemented by the svc_rpc implementation itself;
274 * also see clnt.h for protocol numbers.
276 extern void rpctest_service();
278 extern void svc_getreq(int);
280 extern void svc_getreqset(fd_set *);/* takes fdset instead of int */
282 extern void svc_getreqset(int *);
284 extern void svc_run(void); /* never returns */
287 * Socket to use on svcxxx_create call to get default socket
289 #define RPC_ANYSOCK -1
292 * These are the existing service side transport implementations
296 * Memory based rpc for testing and timing.
298 extern SVCXPRT *svcraw_create(void);
303 extern SVCXPRT *svcudp_create(int);
304 extern SVCXPRT *svcudp_bufcreate(int, uint_t, uint_t);
309 extern SVCXPRT *svctcp_create(int, uint_t, uint_t);
311 extern int svcudp_enablecache(SVCXPRT *, uint32_t);
314 #endif /* !__SVC_HEADER__ */