Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

svc.h

Go to the documentation of this file.
00001 /*  $Id$ */
00002 /*      $OpenBSD: svc.h,v 1.2 1997/09/21 10:46:16 niklas Exp $  */
00003 /*      $NetBSD: svc.h,v 1.9 1995/04/29 05:28:01 cgd Exp $      */
00004 
00005 /*
00006  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00007  * unrestricted use provided that this legend is included on all tape
00008  * media and as a part of the software program in whole or part.  Users
00009  * may copy or modify Sun RPC without charge, but are not authorized
00010  * to license or distribute it to anyone else except as part of a product or
00011  * program developed by the user.
00012  * 
00013  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00014  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00015  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00016  * 
00017  * Sun RPC is provided with no support and without any obligation on the
00018  * part of Sun Microsystems, Inc. to assist in its use, correction,
00019  * modification or enhancement.
00020  * 
00021  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00022  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00023  * OR ANY PART THEREOF.
00024  * 
00025  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00026  * or profits or other special, indirect and consequential damages, even if
00027  * Sun has been advised of the possibility of such damages.
00028  * 
00029  * Sun Microsystems, Inc.
00030  * 2550 Garcia Avenue
00031  * Mountain View, California  94043
00032  *
00033  *      from: @(#)svc.h 1.20 88/02/08 SMI 
00034  *      @(#)svc.h       2.2 88/07/29 4.0 RPCSRC
00035  */
00036 
00037 /*
00038  * svc.h, Server-side remote procedure call interface.
00039  *
00040  * Copyright (C) 1984, Sun Microsystems, Inc.
00041  */
00042 
00043 #ifndef _RPC_SVC_H
00044 #define _RPC_SVC_H
00045 #include <sys/cdefs.h>
00046 
00047 /*
00048  * This interface must manage two items concerning remote procedure calling:
00049  *
00050  * 1) An arbitrary number of transport connections upon which rpc requests
00051  * are received.  The two most notable transports are TCP and UDP;  they are
00052  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
00053  * they in turn call xprt_register and xprt_unregister.
00054  *
00055  * 2) An arbitrary number of locally registered services.  Services are
00056  * described by the following four data: program number, version number,
00057  * "service dispatch" function, a transport handle, and a boolean that
00058  * indicates whether or not the exported program should be registered with a
00059  * local binder service;  if true the program's number and version and the
00060  * port number from the transport handle are registered with the binder.
00061  * These data are registered with the rpc svc system via svc_register.
00062  *
00063  * A service's dispatch function is called whenever an rpc request comes in
00064  * on a transport.  The request's program and version numbers must match
00065  * those of the registered service.  The dispatch function is passed two
00066  * parameters, struct svc_req * and SVCXPRT *, defined below.
00067  */
00068 
00069 enum xprt_stat {
00070         XPRT_DIED,
00071         XPRT_MOREREQS,
00072         XPRT_IDLE
00073 };
00074 
00075 /*
00076  * Server side transport handle
00077  */
00078 typedef struct __rpc_svcxprt {
00079         int             xp_sock;
00080         u_short         xp_port;         /* associated port number */
00081         struct xp_ops {
00082                 /* receive incomming requests */
00083                 bool_t  (*xp_recv) __P((struct __rpc_svcxprt *,
00084                             struct rpc_msg *));
00085                 /* get transport status */
00086                 enum xprt_stat (*xp_stat) __P((struct __rpc_svcxprt *));
00087                 /* get arguments */
00088                 bool_t  (*xp_getargs) __P((struct __rpc_svcxprt *, xdrproc_t,
00089                             caddr_t));
00090                 /* send reply */
00091                 bool_t  (*xp_reply) __P((struct __rpc_svcxprt *,
00092                             struct rpc_msg *));
00093                 /* free mem allocated for args */
00094                 bool_t  (*xp_freeargs) __P((struct __rpc_svcxprt *, xdrproc_t,
00095                             caddr_t));
00096                 /* destroy this struct */
00097                 void    (*xp_destroy) __P((struct __rpc_svcxprt *));
00098         } *xp_ops;
00099         int             xp_addrlen;      /* length of remote address */
00100         struct sockaddr_in xp_raddr;     /* remote address */
00101         struct opaque_auth xp_verf;      /* raw response verifier */
00102         caddr_t         xp_p1;           /* private */
00103         caddr_t         xp_p2;           /* private */
00104 } SVCXPRT;
00105 
00106 /*
00107  *  Approved way of getting address of caller
00108  */
00109 #define svc_getcaller(x) (&(x)->xp_raddr)
00110 
00111 /*
00112  * Operations defined on an SVCXPRT handle
00113  *
00114  * SVCXPRT              *xprt;
00115  * struct rpc_msg       *msg;
00116  * xdrproc_t             xargs;
00117  * caddr_t               argsp;
00118  */
00119 #define SVC_RECV(xprt, msg)                             \
00120         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
00121 #define svc_recv(xprt, msg)                             \
00122         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
00123 
00124 #define SVC_STAT(xprt)                                  \
00125         (*(xprt)->xp_ops->xp_stat)(xprt)
00126 #define svc_stat(xprt)                                  \
00127         (*(xprt)->xp_ops->xp_stat)(xprt)
00128 
00129 #define SVC_GETARGS(xprt, xargs, argsp)                 \
00130         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
00131 #define svc_getargs(xprt, xargs, argsp)                 \
00132         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
00133 
00134 #define SVC_REPLY(xprt, msg)                            \
00135         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
00136 #define svc_reply(xprt, msg)                            \
00137         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
00138 
00139 #define SVC_FREEARGS(xprt, xargs, argsp)                \
00140         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
00141 #define svc_freeargs(xprt, xargs, argsp)                \
00142         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
00143 
00144 #define SVC_DESTROY(xprt)                               \
00145         (*(xprt)->xp_ops->xp_destroy)(xprt)
00146 #define svc_destroy(xprt)                               \
00147         (*(xprt)->xp_ops->xp_destroy)(xprt)
00148 
00149 
00150 /*
00151  * Service request
00152  */
00153 struct svc_req {
00154         u_int32_t       rq_prog;        /* service program number */
00155         u_int32_t       rq_vers;        /* service protocol version */
00156         u_int32_t       rq_proc;        /* the desired procedure */
00157         struct opaque_auth rq_cred;     /* raw creds from the wire */
00158         caddr_t         rq_clntcred;    /* read only cooked cred */
00159         SVCXPRT *rq_xprt;               /* associated transport */
00160 };
00161 
00162 
00163 /*
00164  * Service registration
00165  *
00166  * svc_register(xprt, prog, vers, dispatch, protocol)
00167  *      SVCXPRT *xprt;
00168  *      u_long prog;
00169  *      u_long vers;
00170  *      void (*dispatch)();
00171  *      int protocol;    like TCP or UDP, zero means do not register 
00172  */
00173 __BEGIN_DECLS
00174 extern bool_t   svc_register __P((SVCXPRT *, u_long, u_long,
00175                     void (*) __P((struct svc_req *, SVCXPRT *)), int));
00176 __END_DECLS
00177 
00178 /*
00179  * Service un-registration
00180  *
00181  * svc_unregister(prog, vers)
00182  *      u_long prog;
00183  *      u_long vers;
00184  */
00185 __BEGIN_DECLS
00186 extern void     svc_unregister __P((u_long, u_long));
00187 __END_DECLS
00188 
00189 /*
00190  * Transport registration.
00191  *
00192  * xprt_register(xprt)
00193  *      SVCXPRT *xprt;
00194  */
00195 __BEGIN_DECLS
00196 extern void     xprt_register   __P((SVCXPRT *));
00197 __END_DECLS
00198 
00199 /*
00200  * Transport un-register
00201  *
00202  * xprt_unregister(xprt)
00203  *      SVCXPRT *xprt;
00204  */
00205 __BEGIN_DECLS
00206 extern void     xprt_unregister __P((SVCXPRT *));
00207 __END_DECLS
00208 
00209 
00210 
00211 
00212 /*
00213  * When the service routine is called, it must first check to see if it
00214  * knows about the procedure;  if not, it should call svcerr_noproc
00215  * and return.  If so, it should deserialize its arguments via 
00216  * SVC_GETARGS (defined above).  If the deserialization does not work,
00217  * svcerr_decode should be called followed by a return.  Successful
00218  * decoding of the arguments should be followed the execution of the
00219  * procedure's code and a call to svc_sendreply.
00220  *
00221  * Also, if the service refuses to execute the procedure due to too-
00222  * weak authentication parameters, svcerr_weakauth should be called.
00223  * Note: do not confuse access-control failure with weak authentication!
00224  *
00225  * NB: In pure implementations of rpc, the caller always waits for a reply
00226  * msg.  This message is sent when svc_sendreply is called.  
00227  * Therefore pure service implementations should always call
00228  * svc_sendreply even if the function logically returns void;  use
00229  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
00230  * for the abuse of pure rpc via batched calling or pipelining.  In the
00231  * case of a batched call, svc_sendreply should NOT be called since
00232  * this would send a return message, which is what batching tries to avoid.
00233  * It is the service/protocol writer's responsibility to know which calls are
00234  * batched and which are not.  Warning: responding to batch calls may
00235  * deadlock the caller and server processes!
00236  */
00237 
00238 __BEGIN_DECLS
00239 extern bool_t   svc_sendreply   __P((SVCXPRT *, xdrproc_t, char *));
00240 extern void     svcerr_decode   __P((SVCXPRT *));
00241 extern void     svcerr_weakauth __P((SVCXPRT *));
00242 extern void     svcerr_noproc   __P((SVCXPRT *));
00243 extern void     svcerr_progvers __P((SVCXPRT *, u_long, u_long));
00244 extern void     svcerr_auth     __P((SVCXPRT *, enum auth_stat));
00245 extern void     svcerr_noprog   __P((SVCXPRT *));
00246 extern void     svcerr_systemerr __P((SVCXPRT *));
00247 __END_DECLS
00248     
00249 /*
00250  * Lowest level dispatching -OR- who owns this process anyway.
00251  * Somebody has to wait for incoming requests and then call the correct
00252  * service routine.  The routine svc_run does infinite waiting; i.e.,
00253  * svc_run never returns.
00254  * Since another (co-existant) package may wish to selectively wait for
00255  * incoming calls or other events outside of the rpc architecture, the
00256  * routine svc_getreq is provided.  It must be passed readfds, the
00257  * "in-place" results of a select system call (see select, section 2).
00258  */
00259 
00260 /*
00261  * Global keeper of rpc service descriptors in use
00262  * dynamic; must be inspected before each call to select 
00263  */
00264 extern int svc_maxfd;
00265 #ifdef FD_SETSIZE
00266 extern fd_set svc_fdset;
00267 #define svc_fds svc_fdset.fds_bits[0]   /* compatibility */
00268 #else
00269 extern int svc_fds;
00270 #endif /* def FD_SETSIZE */
00271 
00272 /*
00273  * a small program implemented by the svc_rpc implementation itself;
00274  * also see clnt.h for protocol numbers.
00275  */
00276 extern void rpctest_service();                          /* XXX relic? */
00277 
00278 __BEGIN_DECLS
00279 extern void     svc_getreq      __P((int));
00280 extern void     svc_getreqset   __P((fd_set *));
00281 extern void     svc_run         __P((void));
00282 __END_DECLS
00283 
00284 /*
00285  * Socket to use on svcxxx_create call to get default socket
00286  */
00287 #define RPC_ANYSOCK     -1
00288 
00289 /*
00290  * These are the existing service side transport implementations
00291  */
00292 
00293 /*
00294  * Memory based rpc for testing and timing.
00295  */
00296 __BEGIN_DECLS
00297 extern SVCXPRT *svcraw_create __P((void));
00298 __END_DECLS
00299 
00300 
00301 /*
00302  * Udp based rpc.
00303  */
00304 __BEGIN_DECLS
00305 extern SVCXPRT *svcudp_create __P((int));
00306 extern SVCXPRT *svcudp_bufcreate __P((int, u_int, u_int));
00307 __END_DECLS
00308 
00309 
00310 /*
00311  * Tcp based rpc.
00312  */
00313 __BEGIN_DECLS
00314 extern SVCXPRT *svctcp_create __P((int, u_int, u_int));
00315 __END_DECLS
00316 
00317 /*
00318  * Fd based rpc.
00319  */
00320 __BEGIN_DECLS
00321 extern SVCXPRT *svcfd_create __P((int, u_int, u_int));
00322 __END_DECLS
00323 
00324 #endif /* !_RPC_SVC_H */

Generated on Sun May 14 14:51:20 2006 by  doxygen 1.4.2