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