xref: /csrg-svn/lib/librpc/rpc/svc.h (revision 57882)
145069Smckusick /* @(#)svc.h	2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
245069Smckusick /*
345069Smckusick  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
445069Smckusick  * unrestricted use provided that this legend is included on all tape
545069Smckusick  * media and as a part of the software program in whole or part.  Users
645069Smckusick  * may copy or modify Sun RPC without charge, but are not authorized
745069Smckusick  * to license or distribute it to anyone else except as part of a product or
845069Smckusick  * program developed by the user.
945069Smckusick  *
1045069Smckusick  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
1145069Smckusick  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1245069Smckusick  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1345069Smckusick  *
1445069Smckusick  * Sun RPC is provided with no support and without any obligation on the
1545069Smckusick  * part of Sun Microsystems, Inc. to assist in its use, correction,
1645069Smckusick  * modification or enhancement.
1745069Smckusick  *
1845069Smckusick  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
1945069Smckusick  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
2045069Smckusick  * OR ANY PART THEREOF.
2145069Smckusick  *
2245069Smckusick  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
2345069Smckusick  * or profits or other special, indirect and consequential damages, even if
2445069Smckusick  * Sun has been advised of the possibility of such damages.
2545069Smckusick  *
2645069Smckusick  * Sun Microsystems, Inc.
2745069Smckusick  * 2550 Garcia Avenue
2845069Smckusick  * Mountain View, California  94043
2945069Smckusick  */
3045069Smckusick 
3145069Smckusick /*
3245069Smckusick  * svc.h, Server-side remote procedure call interface.
3345069Smckusick  *
3445069Smckusick  * Copyright (C) 1984, Sun Microsystems, Inc.
3545069Smckusick  */
3645069Smckusick 
3745069Smckusick #ifndef __SVC_HEADER__
3845069Smckusick #define __SVC_HEADER__
3945069Smckusick 
4045069Smckusick /*
4145069Smckusick  * This interface must manage two items concerning remote procedure calling:
4245069Smckusick  *
4345069Smckusick  * 1) An arbitrary number of transport connections upon which rpc requests
4445069Smckusick  * are received.  The two most notable transports are TCP and UDP;  they are
4545069Smckusick  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
4645069Smckusick  * they in turn call xprt_register and xprt_unregister.
4745069Smckusick  *
4845069Smckusick  * 2) An arbitrary number of locally registered services.  Services are
4945069Smckusick  * described by the following four data: program number, version number,
5045069Smckusick  * "service dispatch" function, a transport handle, and a boolean that
5145069Smckusick  * indicates whether or not the exported program should be registered with a
5245069Smckusick  * local binder service;  if true the program's number and version and the
5345069Smckusick  * port number from the transport handle are registered with the binder.
5445069Smckusick  * These data are registered with the rpc svc system via svc_register.
5545069Smckusick  *
5645069Smckusick  * A service's dispatch function is called whenever an rpc request comes in
5745069Smckusick  * on a transport.  The request's program and version numbers must match
5845069Smckusick  * those of the registered service.  The dispatch function is passed two
5945069Smckusick  * parameters, struct svc_req * and SVCXPRT *, defined below.
6045069Smckusick  */
6145069Smckusick 
6245069Smckusick enum xprt_stat {
6345069Smckusick 	XPRT_DIED,
6445069Smckusick 	XPRT_MOREREQS,
6545069Smckusick 	XPRT_IDLE
6645069Smckusick };
6745069Smckusick 
6845069Smckusick /*
6945069Smckusick  * Server side transport handle
7045069Smckusick  */
7145069Smckusick typedef struct {
7245069Smckusick 	int		xp_sock;
7345069Smckusick 	u_short		xp_port;	 /* associated port number */
7445069Smckusick 	struct xp_ops {
7545069Smckusick 	    bool_t	(*xp_recv)();	 /* receive incomming requests */
7645069Smckusick 	    enum xprt_stat (*xp_stat)(); /* get transport status */
7745069Smckusick 	    bool_t	(*xp_getargs)(); /* get arguments */
7845069Smckusick 	    bool_t	(*xp_reply)();	 /* send reply */
7945069Smckusick 	    bool_t	(*xp_freeargs)();/* free mem allocated for args */
8045069Smckusick 	    void	(*xp_destroy)(); /* destroy this struct */
8145069Smckusick 	} *xp_ops;
8245069Smckusick 	int		xp_addrlen;	 /* length of remote address */
8345069Smckusick 	struct sockaddr_in xp_raddr;	 /* remote address */
8445069Smckusick 	struct opaque_auth xp_verf;	 /* raw response verifier */
8545069Smckusick 	caddr_t		xp_p1;		 /* private */
8645069Smckusick 	caddr_t		xp_p2;		 /* private */
8745069Smckusick } SVCXPRT;
8845069Smckusick 
8945069Smckusick /*
9045069Smckusick  *  Approved way of getting address of caller
9145069Smckusick  */
9245069Smckusick #define svc_getcaller(x) (&(x)->xp_raddr)
9345069Smckusick 
9445069Smckusick /*
9545069Smckusick  * Operations defined on an SVCXPRT handle
9645069Smckusick  *
9745069Smckusick  * SVCXPRT		*xprt;
9845069Smckusick  * struct rpc_msg	*msg;
9945069Smckusick  * xdrproc_t		 xargs;
10045069Smckusick  * caddr_t		 argsp;
10145069Smckusick  */
10245069Smckusick #define SVC_RECV(xprt, msg)				\
10345069Smckusick 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
10445069Smckusick #define svc_recv(xprt, msg)				\
10545069Smckusick 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
10645069Smckusick 
10745069Smckusick #define SVC_STAT(xprt)					\
10845069Smckusick 	(*(xprt)->xp_ops->xp_stat)(xprt)
10945069Smckusick #define svc_stat(xprt)					\
11045069Smckusick 	(*(xprt)->xp_ops->xp_stat)(xprt)
11145069Smckusick 
11245069Smckusick #define SVC_GETARGS(xprt, xargs, argsp)			\
11345069Smckusick 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
11445069Smckusick #define svc_getargs(xprt, xargs, argsp)			\
11545069Smckusick 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
11645069Smckusick 
11745069Smckusick #define SVC_REPLY(xprt, msg)				\
11845069Smckusick 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
11945069Smckusick #define svc_reply(xprt, msg)				\
12045069Smckusick 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
12145069Smckusick 
12245069Smckusick #define SVC_FREEARGS(xprt, xargs, argsp)		\
12345069Smckusick 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
12445069Smckusick #define svc_freeargs(xprt, xargs, argsp)		\
12545069Smckusick 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
12645069Smckusick 
12745069Smckusick #define SVC_DESTROY(xprt)				\
12845069Smckusick 	(*(xprt)->xp_ops->xp_destroy)(xprt)
12945069Smckusick #define svc_destroy(xprt)				\
13045069Smckusick 	(*(xprt)->xp_ops->xp_destroy)(xprt)
13145069Smckusick 
13245069Smckusick 
13345069Smckusick /*
13445069Smckusick  * Service request
13545069Smckusick  */
13645069Smckusick struct svc_req {
13745069Smckusick 	u_long		rq_prog;	/* service program number */
13845069Smckusick 	u_long		rq_vers;	/* service protocol version */
13945069Smckusick 	u_long		rq_proc;	/* the desired procedure */
14045069Smckusick 	struct opaque_auth rq_cred;	/* raw creds from the wire */
14145069Smckusick 	caddr_t		rq_clntcred;	/* read only cooked cred */
14245069Smckusick 	SVCXPRT	*rq_xprt;		/* associated transport */
14345069Smckusick };
14445069Smckusick 
14545069Smckusick 
14645069Smckusick /*
14745069Smckusick  * Service registration
14845069Smckusick  *
14945069Smckusick  * svc_register(xprt, prog, vers, dispatch, protocol)
15045069Smckusick  *	SVCXPRT *xprt;
15145069Smckusick  *	u_long prog;
15245069Smckusick  *	u_long vers;
15345069Smckusick  *	void (*dispatch)();
154*57882Storek  *	int protocol;  (like TCP or UDP, zero means do not register)
15545069Smckusick  */
15645069Smckusick extern bool_t	svc_register();
15745069Smckusick 
15845069Smckusick /*
15945069Smckusick  * Service un-registration
16045069Smckusick  *
16145069Smckusick  * svc_unregister(prog, vers)
16245069Smckusick  *	u_long prog;
16345069Smckusick  *	u_long vers;
16445069Smckusick  */
16545069Smckusick extern void	svc_unregister();
16645069Smckusick 
16745069Smckusick /*
16845069Smckusick  * Transport registration.
16945069Smckusick  *
17045069Smckusick  * xprt_register(xprt)
17145069Smckusick  *	SVCXPRT *xprt;
17245069Smckusick  */
17345069Smckusick extern void	xprt_register();
17445069Smckusick 
17545069Smckusick /*
17645069Smckusick  * Transport un-register
17745069Smckusick  *
17845069Smckusick  * xprt_unregister(xprt)
17945069Smckusick  *	SVCXPRT *xprt;
18045069Smckusick  */
18145069Smckusick extern void	xprt_unregister();
18245069Smckusick 
18345069Smckusick 
18445069Smckusick 
18545069Smckusick 
18645069Smckusick /*
18745069Smckusick  * When the service routine is called, it must first check to see if it
18845069Smckusick  * knows about the procedure;  if not, it should call svcerr_noproc
18945069Smckusick  * and return.  If so, it should deserialize its arguments via
19045069Smckusick  * SVC_GETARGS (defined above).  If the deserialization does not work,
19145069Smckusick  * svcerr_decode should be called followed by a return.  Successful
19245069Smckusick  * decoding of the arguments should be followed the execution of the
19345069Smckusick  * procedure's code and a call to svc_sendreply.
19445069Smckusick  *
19545069Smckusick  * Also, if the service refuses to execute the procedure due to too-
19645069Smckusick  * weak authentication parameters, svcerr_weakauth should be called.
19745069Smckusick  * Note: do not confuse access-control failure with weak authentication!
19845069Smckusick  *
19945069Smckusick  * NB: In pure implementations of rpc, the caller always waits for a reply
20045069Smckusick  * msg.  This message is sent when svc_sendreply is called.
20145069Smckusick  * Therefore pure service implementations should always call
20245069Smckusick  * svc_sendreply even if the function logically returns void;  use
20345069Smckusick  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
20445069Smckusick  * for the abuse of pure rpc via batched calling or pipelining.  In the
20545069Smckusick  * case of a batched call, svc_sendreply should NOT be called since
20645069Smckusick  * this would send a return message, which is what batching tries to avoid.
20745069Smckusick  * It is the service/protocol writer's responsibility to know which calls are
20845069Smckusick  * batched and which are not.  Warning: responding to batch calls may
20945069Smckusick  * deadlock the caller and server processes!
21045069Smckusick  */
21145069Smckusick 
21245069Smckusick extern bool_t	svc_sendreply();
21345069Smckusick extern void	svcerr_decode();
21445069Smckusick extern void	svcerr_weakauth();
21545069Smckusick extern void	svcerr_noproc();
21645069Smckusick extern void	svcerr_progvers();
21745069Smckusick extern void	svcerr_auth();
21845069Smckusick extern void	svcerr_noprog();
21945069Smckusick extern void	svcerr_systemerr();
22045069Smckusick 
22145069Smckusick /*
22245069Smckusick  * Lowest level dispatching -OR- who owns this process anyway.
22345069Smckusick  * Somebody has to wait for incoming requests and then call the correct
22445069Smckusick  * service routine.  The routine svc_run does infinite waiting; i.e.,
22545069Smckusick  * svc_run never returns.
22645069Smckusick  * Since another (co-existant) package may wish to selectively wait for
22745069Smckusick  * incoming calls or other events outside of the rpc architecture, the
22845069Smckusick  * routine svc_getreq is provided.  It must be passed readfds, the
22945069Smckusick  * "in-place" results of a select system call (see select, section 2).
23045069Smckusick  */
23145069Smckusick 
23245069Smckusick /*
23345069Smckusick  * Global keeper of rpc service descriptors in use
23445069Smckusick  * dynamic; must be inspected before each call to select
23545069Smckusick  */
23645069Smckusick #ifdef FD_SETSIZE
23745069Smckusick extern fd_set svc_fdset;
23845069Smckusick #define svc_fds svc_fdset.fds_bits[0]	/* compatibility */
23945069Smckusick #else
24045069Smckusick extern int svc_fds;
24145069Smckusick #endif /* def FD_SETSIZE */
24245069Smckusick 
24345069Smckusick /*
24445069Smckusick  * a small program implemented by the svc_rpc implementation itself;
24545069Smckusick  * also see clnt.h for protocol numbers.
24645069Smckusick  */
24745069Smckusick extern void rpctest_service();
24845069Smckusick 
24945069Smckusick extern void	svc_getreq();
25045069Smckusick extern void	svc_getreqset();	/* takes fdset instead of int */
25145069Smckusick extern void	svc_run(); 	 /* never returns */
25245069Smckusick 
25345069Smckusick /*
25445069Smckusick  * Socket to use on svcxxx_create call to get default socket
25545069Smckusick  */
25645069Smckusick #define	RPC_ANYSOCK	-1
25745069Smckusick 
25845069Smckusick /*
25945069Smckusick  * These are the existing service side transport implementations
26045069Smckusick  */
26145069Smckusick 
26245069Smckusick /*
26345069Smckusick  * Memory based rpc for testing and timing.
26445069Smckusick  */
26545069Smckusick extern SVCXPRT *svcraw_create();
26645069Smckusick 
26745069Smckusick /*
26845069Smckusick  * Udp based rpc.
26945069Smckusick  */
27045069Smckusick extern SVCXPRT *svcudp_create();
27145069Smckusick extern SVCXPRT *svcudp_bufcreate();
27245069Smckusick 
27345069Smckusick /*
27445069Smckusick  * Tcp based rpc.
27545069Smckusick  */
27645069Smckusick extern SVCXPRT *svctcp_create();
27745069Smckusick 
27845069Smckusick 
27945069Smckusick 
28045069Smckusick #endif !__SVC_HEADER__
281