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