Home | History | Annotate | Line # | Download | only in rpc
svc.h revision 1.4
      1 /*	$NetBSD: svc.h,v 1.4 1994/10/26 00:57:04 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 {
     77 	int		xp_sock;
     78 	u_short		xp_port;	 /* associated port number */
     79 	struct xp_ops {
     80 	    bool_t	(*xp_recv)();	 /* receive incomming requests */
     81 	    enum xprt_stat (*xp_stat)(); /* get transport status */
     82 	    bool_t	(*xp_getargs)(); /* get arguments */
     83 	    bool_t	(*xp_reply)();	 /* send reply */
     84 	    bool_t	(*xp_freeargs)();/* free mem allocated for args */
     85 	    void	(*xp_destroy)(); /* destroy this struct */
     86 	} *xp_ops;
     87 	int		xp_addrlen;	 /* length of remote address */
     88 	struct sockaddr_in xp_raddr;	 /* remote address */
     89 	struct opaque_auth xp_verf;	 /* raw response verifier */
     90 	caddr_t		xp_p1;		 /* private */
     91 	caddr_t		xp_p2;		 /* private */
     92 } SVCXPRT;
     93 
     94 /*
     95  *  Approved way of getting address of caller
     96  */
     97 #define svc_getcaller(x) (&(x)->xp_raddr)
     98 
     99 /*
    100  * Operations defined on an SVCXPRT handle
    101  *
    102  * SVCXPRT		*xprt;
    103  * struct rpc_msg	*msg;
    104  * xdrproc_t		 xargs;
    105  * caddr_t		 argsp;
    106  */
    107 #define SVC_RECV(xprt, msg)				\
    108 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
    109 #define svc_recv(xprt, msg)				\
    110 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
    111 
    112 #define SVC_STAT(xprt)					\
    113 	(*(xprt)->xp_ops->xp_stat)(xprt)
    114 #define svc_stat(xprt)					\
    115 	(*(xprt)->xp_ops->xp_stat)(xprt)
    116 
    117 #define SVC_GETARGS(xprt, xargs, argsp)			\
    118 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
    119 #define svc_getargs(xprt, xargs, argsp)			\
    120 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
    121 
    122 #define SVC_REPLY(xprt, msg)				\
    123 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
    124 #define svc_reply(xprt, msg)				\
    125 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
    126 
    127 #define SVC_FREEARGS(xprt, xargs, argsp)		\
    128 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
    129 #define svc_freeargs(xprt, xargs, argsp)		\
    130 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
    131 
    132 #define SVC_DESTROY(xprt)				\
    133 	(*(xprt)->xp_ops->xp_destroy)(xprt)
    134 #define svc_destroy(xprt)				\
    135 	(*(xprt)->xp_ops->xp_destroy)(xprt)
    136 
    137 
    138 /*
    139  * Service request
    140  */
    141 struct svc_req {
    142 	u_long		rq_prog;	/* service program number */
    143 	u_long		rq_vers;	/* service protocol version */
    144 	u_long		rq_proc;	/* the desired procedure */
    145 	struct opaque_auth rq_cred;	/* raw creds from the wire */
    146 	caddr_t		rq_clntcred;	/* read only cooked cred */
    147 	SVCXPRT	*rq_xprt;		/* associated transport */
    148 };
    149 
    150 
    151 /*
    152  * Service registration
    153  *
    154  * svc_register(xprt, prog, vers, dispatch, protocol)
    155  *	SVCXPRT *xprt;
    156  *	u_long prog;
    157  *	u_long vers;
    158  *	void (*dispatch)();
    159  *	int protocol;  /* like TCP or UDP, zero means do not register
    160  */
    161 __BEGIN_DECLS
    162 extern bool_t	svc_register __P((SVCXPRT *, u_long, u_long, void (*)(), int));
    163 __END_DECLS
    164 
    165 /*
    166  * Service un-registration
    167  *
    168  * svc_unregister(prog, vers)
    169  *	u_long prog;
    170  *	u_long vers;
    171  */
    172 __BEGIN_DECLS
    173 extern void	svc_unregister __P((u_long, u_long));
    174 __END_DECLS
    175 
    176 /*
    177  * Transport registration.
    178  *
    179  * xprt_register(xprt)
    180  *	SVCXPRT *xprt;
    181  */
    182 __BEGIN_DECLS
    183 extern void	xprt_register	__P((SVCXPRT *));
    184 __END_DECLS
    185 
    186 /*
    187  * Transport un-register
    188  *
    189  * xprt_unregister(xprt)
    190  *	SVCXPRT *xprt;
    191  */
    192 __BEGIN_DECLS
    193 extern void	xprt_unregister	__P((SVCXPRT *));
    194 __END_DECLS
    195 
    196 
    197 
    198 
    199 /*
    200  * When the service routine is called, it must first check to see if it
    201  * knows about the procedure;  if not, it should call svcerr_noproc
    202  * and return.  If so, it should deserialize its arguments via
    203  * SVC_GETARGS (defined above).  If the deserialization does not work,
    204  * svcerr_decode should be called followed by a return.  Successful
    205  * decoding of the arguments should be followed the execution of the
    206  * procedure's code and a call to svc_sendreply.
    207  *
    208  * Also, if the service refuses to execute the procedure due to too-
    209  * weak authentication parameters, svcerr_weakauth should be called.
    210  * Note: do not confuse access-control failure with weak authentication!
    211  *
    212  * NB: In pure implementations of rpc, the caller always waits for a reply
    213  * msg.  This message is sent when svc_sendreply is called.
    214  * Therefore pure service implementations should always call
    215  * svc_sendreply even if the function logically returns void;  use
    216  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
    217  * for the abuse of pure rpc via batched calling or pipelining.  In the
    218  * case of a batched call, svc_sendreply should NOT be called since
    219  * this would send a return message, which is what batching tries to avoid.
    220  * It is the service/protocol writer's responsibility to know which calls are
    221  * batched and which are not.  Warning: responding to batch calls may
    222  * deadlock the caller and server processes!
    223  */
    224 
    225 __BEGIN_DECLS
    226 extern bool_t	svc_sendreply	__P((SVCXPRT *, xdrproc_t, char *));
    227 extern void	svcerr_decode	__P((SVCXPRT *));
    228 extern void	svcerr_weakauth	__P((SVCXPRT *));
    229 extern void	svcerr_noproc	__P((SVCXPRT *));
    230 extern void	svcerr_progvers	__P((SVCXPRT *, u_long, u_long));
    231 extern void	svcerr_auth	__P((SVCXPRT *, enum auth_stat));
    232 extern void	svcerr_noprog	__P((SVCXPRT *));
    233 extern void	svcerr_systemerr __P((SVCXPRT *));
    234 __END_DECLS
    235 
    236 /*
    237  * Lowest level dispatching -OR- who owns this process anyway.
    238  * Somebody has to wait for incoming requests and then call the correct
    239  * service routine.  The routine svc_run does infinite waiting; i.e.,
    240  * svc_run never returns.
    241  * Since another (co-existant) package may wish to selectively wait for
    242  * incoming calls or other events outside of the rpc architecture, the
    243  * routine svc_getreq is provided.  It must be passed readfds, the
    244  * "in-place" results of a select system call (see select, section 2).
    245  */
    246 
    247 /*
    248  * Global keeper of rpc service descriptors in use
    249  * dynamic; must be inspected before each call to select
    250  */
    251 #ifdef FD_SETSIZE
    252 extern fd_set svc_fdset;
    253 #define svc_fds svc_fdset.fds_bits[0]	/* compatibility */
    254 #else
    255 extern int svc_fds;
    256 #endif /* def FD_SETSIZE */
    257 
    258 /*
    259  * a small program implemented by the svc_rpc implementation itself;
    260  * also see clnt.h for protocol numbers.
    261  */
    262 extern void rpctest_service();
    263 
    264 __BEGIN_DECLS
    265 extern void	svc_getreq	__P((int));
    266 extern void	svc_getreqset	__P((fd_set *));
    267 extern void	svc_run		__P((void));
    268 __END_DECLS
    269 
    270 /*
    271  * Socket to use on svcxxx_create call to get default socket
    272  */
    273 #define	RPC_ANYSOCK	-1
    274 
    275 /*
    276  * These are the existing service side transport implementations
    277  */
    278 
    279 /*
    280  * Memory based rpc for testing and timing.
    281  */
    282 __BEGIN_DECLS
    283 extern SVCXPRT *svcraw_create __P((void));
    284 __END_DECLS
    285 
    286 
    287 /*
    288  * Udp based rpc.
    289  */
    290 __BEGIN_DECLS
    291 extern SVCXPRT *svcudp_create __P((int));
    292 extern SVCXPRT *svcudp_bufcreate __P((int, u_int, u_int));
    293 __END_DECLS
    294 
    295 
    296 /*
    297  * Tcp based rpc.
    298  */
    299 __BEGIN_DECLS
    300 extern SVCXPRT *svctcp_create __P((int, u_int, u_int));
    301 __END_DECLS
    302 
    303 #endif /* !_RPC_SVC_H */
    304