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