Home | History | Annotate | Line # | Download | only in rpc
svc.h revision 1.6
      1 /*	$NetBSD: svc.h,v 1.6 1994/12/04 01:15:32 cgd Exp $	*/
      2 
      3 /*
      4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5  * unrestricted use provided that this legend is included on all tape
      6  * media and as a part of the software program in whole or part.  Users
      7  * may copy or modify Sun RPC without charge, but are not authorized
      8  * to license or distribute it to anyone else except as part of a product or
      9  * program developed by the user.
     10  *
     11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14  *
     15  * Sun RPC is provided with no support and without any obligation on the
     16  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17  * modification or enhancement.
     18  *
     19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21  * OR ANY PART THEREOF.
     22  *
     23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24  * or profits or other special, indirect and consequential damages, even if
     25  * Sun has been advised of the possibility of such damages.
     26  *
     27  * Sun Microsystems, Inc.
     28  * 2550 Garcia Avenue
     29  * Mountain View, California  94043
     30  *
     31  *	from: @(#)svc.h 1.20 88/02/08 SMI
     32  *	@(#)svc.h	2.2 88/07/29 4.0 RPCSRC
     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 /*
     74  * Server side transport handle
     75  */
     76 typedef struct __rpc_svcxprt {
     77 	int		xp_sock;
     78 	u_short		xp_port;	 /* associated port number */
     79 	struct xp_ops {
     80 		/* receive incomming requests */
     81 		bool_t	(*xp_recv) __P((struct __rpc_svcxprt *,
     82 			    struct rpc_msg *));
     83 		/* get transport status */
     84 		enum xprt_stat (*xp_stat) __P((struct __rpc_svcxprt *));
     85 		/* get arguments */
     86 		bool_t	(*xp_getargs) __P((struct __rpc_svcxprt *, xdrproc_t,
     87 			    caddr_t));
     88 		/* send reply */
     89 		bool_t	(*xp_reply) __P((struct __rpc_svcxprt *,
     90 			    struct rpc_msg *));
     91 		/* free mem allocated for args */
     92 		bool_t	(*xp_freeargs) __P((struct __rpc_svcxprt *, xdrproc_t,
     93 			    caddr_t));
     94 		/* destroy this struct */
     95 		void	(*xp_destroy) __P((struct __rpc_svcxprt *));
     96 	} *xp_ops;
     97 	int		xp_addrlen;	 /* length of remote address */
     98 	struct sockaddr_in xp_raddr;	 /* remote address */
     99 	struct opaque_auth xp_verf;	 /* raw response verifier */
    100 	caddr_t		xp_p1;		 /* private */
    101 	caddr_t		xp_p2;		 /* private */
    102 } SVCXPRT;
    103 
    104 /*
    105  *  Approved way of getting address of caller
    106  */
    107 #define svc_getcaller(x) (&(x)->xp_raddr)
    108 
    109 /*
    110  * Operations defined on an SVCXPRT handle
    111  *
    112  * SVCXPRT		*xprt;
    113  * struct rpc_msg	*msg;
    114  * xdrproc_t		 xargs;
    115  * caddr_t		 argsp;
    116  */
    117 #define SVC_RECV(xprt, msg)				\
    118 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
    119 #define svc_recv(xprt, msg)				\
    120 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
    121 
    122 #define SVC_STAT(xprt)					\
    123 	(*(xprt)->xp_ops->xp_stat)(xprt)
    124 #define svc_stat(xprt)					\
    125 	(*(xprt)->xp_ops->xp_stat)(xprt)
    126 
    127 #define SVC_GETARGS(xprt, xargs, argsp)			\
    128 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
    129 #define svc_getargs(xprt, xargs, argsp)			\
    130 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
    131 
    132 #define SVC_REPLY(xprt, msg)				\
    133 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
    134 #define svc_reply(xprt, msg)				\
    135 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
    136 
    137 #define SVC_FREEARGS(xprt, xargs, argsp)		\
    138 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
    139 #define svc_freeargs(xprt, xargs, argsp)		\
    140 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
    141 
    142 #define SVC_DESTROY(xprt)				\
    143 	(*(xprt)->xp_ops->xp_destroy)(xprt)
    144 #define svc_destroy(xprt)				\
    145 	(*(xprt)->xp_ops->xp_destroy)(xprt)
    146 
    147 
    148 /*
    149  * Service request
    150  */
    151 struct svc_req {
    152 	u_long		rq_prog;	/* service program number */
    153 	u_long		rq_vers;	/* service protocol version */
    154 	u_long		rq_proc;	/* the desired procedure */
    155 	struct opaque_auth rq_cred;	/* raw creds from the wire */
    156 	caddr_t		rq_clntcred;	/* read only cooked cred */
    157 	SVCXPRT	*rq_xprt;		/* associated transport */
    158 };
    159 
    160 
    161 /*
    162  * Service registration
    163  *
    164  * svc_register(xprt, prog, vers, dispatch, protocol)
    165  *	SVCXPRT *xprt;
    166  *	u_long prog;
    167  *	u_long vers;
    168  *	void (*dispatch)();
    169  *	int protocol;    like TCP or UDP, zero means do not register
    170  */
    171 __BEGIN_DECLS
    172 extern bool_t	svc_register __P((SVCXPRT *, u_long, u_long,
    173 		    void (*) __P((struct svc_req *, SVCXPRT *)), int));
    174 __END_DECLS
    175 
    176 /*
    177  * Service un-registration
    178  *
    179  * svc_unregister(prog, vers)
    180  *	u_long prog;
    181  *	u_long vers;
    182  */
    183 __BEGIN_DECLS
    184 extern void	svc_unregister __P((u_long, u_long));
    185 __END_DECLS
    186 
    187 /*
    188  * Transport registration.
    189  *
    190  * xprt_register(xprt)
    191  *	SVCXPRT *xprt;
    192  */
    193 __BEGIN_DECLS
    194 extern void	xprt_register	__P((SVCXPRT *));
    195 __END_DECLS
    196 
    197 /*
    198  * Transport un-register
    199  *
    200  * xprt_unregister(xprt)
    201  *	SVCXPRT *xprt;
    202  */
    203 __BEGIN_DECLS
    204 extern void	xprt_unregister	__P((SVCXPRT *));
    205 __END_DECLS
    206 
    207 
    208 
    209 
    210 /*
    211  * When the service routine is called, it must first check to see if it
    212  * knows about the procedure;  if not, it should call svcerr_noproc
    213  * and return.  If so, it should deserialize its arguments via
    214  * SVC_GETARGS (defined above).  If the deserialization does not work,
    215  * svcerr_decode should be called followed by a return.  Successful
    216  * decoding of the arguments should be followed the execution of the
    217  * procedure's code and a call to svc_sendreply.
    218  *
    219  * Also, if the service refuses to execute the procedure due to too-
    220  * weak authentication parameters, svcerr_weakauth should be called.
    221  * Note: do not confuse access-control failure with weak authentication!
    222  *
    223  * NB: In pure implementations of rpc, the caller always waits for a reply
    224  * msg.  This message is sent when svc_sendreply is called.
    225  * Therefore pure service implementations should always call
    226  * svc_sendreply even if the function logically returns void;  use
    227  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
    228  * for the abuse of pure rpc via batched calling or pipelining.  In the
    229  * case of a batched call, svc_sendreply should NOT be called since
    230  * this would send a return message, which is what batching tries to avoid.
    231  * It is the service/protocol writer's responsibility to know which calls are
    232  * batched and which are not.  Warning: responding to batch calls may
    233  * deadlock the caller and server processes!
    234  */
    235 
    236 __BEGIN_DECLS
    237 extern bool_t	svc_sendreply	__P((SVCXPRT *, xdrproc_t, char *));
    238 extern void	svcerr_decode	__P((SVCXPRT *));
    239 extern void	svcerr_weakauth	__P((SVCXPRT *));
    240 extern void	svcerr_noproc	__P((SVCXPRT *));
    241 extern void	svcerr_progvers	__P((SVCXPRT *, u_long, u_long));
    242 extern void	svcerr_auth	__P((SVCXPRT *, enum auth_stat));
    243 extern void	svcerr_noprog	__P((SVCXPRT *));
    244 extern void	svcerr_systemerr __P((SVCXPRT *));
    245 __END_DECLS
    246 
    247 /*
    248  * Lowest level dispatching -OR- who owns this process anyway.
    249  * Somebody has to wait for incoming requests and then call the correct
    250  * service routine.  The routine svc_run does infinite waiting; i.e.,
    251  * svc_run never returns.
    252  * Since another (co-existant) package may wish to selectively wait for
    253  * incoming calls or other events outside of the rpc architecture, the
    254  * routine svc_getreq is provided.  It must be passed readfds, the
    255  * "in-place" results of a select system call (see select, section 2).
    256  */
    257 
    258 /*
    259  * Global keeper of rpc service descriptors in use
    260  * dynamic; must be inspected before each call to select
    261  */
    262 #ifdef FD_SETSIZE
    263 extern fd_set svc_fdset;
    264 #define svc_fds svc_fdset.fds_bits[0]	/* compatibility */
    265 #else
    266 extern int svc_fds;
    267 #endif /* def FD_SETSIZE */
    268 
    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();				/* XXX relic? */
    274 
    275 __BEGIN_DECLS
    276 extern void	svc_getreq	__P((int));
    277 extern void	svc_getreqset	__P((fd_set *));
    278 extern void	svc_run		__P((void));
    279 __END_DECLS
    280 
    281 /*
    282  * Socket to use on svcxxx_create call to get default socket
    283  */
    284 #define	RPC_ANYSOCK	-1
    285 
    286 /*
    287  * These are the existing service side transport implementations
    288  */
    289 
    290 /*
    291  * Memory based rpc for testing and timing.
    292  */
    293 __BEGIN_DECLS
    294 extern SVCXPRT *svcraw_create __P((void));
    295 __END_DECLS
    296 
    297 
    298 /*
    299  * Udp based rpc.
    300  */
    301 __BEGIN_DECLS
    302 extern SVCXPRT *svcudp_create __P((int));
    303 extern SVCXPRT *svcudp_bufcreate __P((int, u_int, u_int));
    304 __END_DECLS
    305 
    306 
    307 /*
    308  * Tcp based rpc.
    309  */
    310 __BEGIN_DECLS
    311 extern SVCXPRT *svctcp_create __P((int, u_int, u_int));
    312 __END_DECLS
    313 
    314 /*
    315  * Fd based rpc.
    316  */
    317 __BEGIN_DECLS
    318 extern SVCXPRT *svcfd_create __P((int, u_int, u_int));
    319 __END_DECLS
    320 
    321 #endif /* !_RPC_SVC_H */
    322