The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/rpc/svc.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $    */
    2 
    3 /*-
    4  * Copyright (c) 2009, Sun Microsystems, Inc.
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without 
    8  * modification, are permitted provided that the following conditions are met:
    9  * - Redistributions of source code must retain the above copyright notice, 
   10  *   this list of conditions and the following disclaimer.
   11  * - Redistributions in binary form must reproduce the above copyright notice, 
   12  *   this list of conditions and the following disclaimer in the documentation 
   13  *   and/or other materials provided with the distribution.
   14  * - Neither the name of Sun Microsystems, Inc. nor the names of its 
   15  *   contributors may be used to endorse or promote products derived 
   16  *   from this software without specific prior written permission.
   17  * 
   18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
   19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
   20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
   21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
   22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
   23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
   24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
   25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
   26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
   27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
   28  * POSSIBILITY OF SUCH DAMAGE.
   29  *
   30  *      from: @(#)svc.h 1.35 88/12/17 SMI
   31  *      from: @(#)svc.h      1.27    94/04/25 SMI
   32  * $FreeBSD$
   33  */
   34 
   35 /*
   36  * svc.h, Server-side remote procedure call interface.
   37  *
   38  * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
   39  */
   40 
   41 #ifndef _RPC_SVC_H
   42 #define _RPC_SVC_H
   43 #include <sys/cdefs.h>
   44 
   45 #ifdef _KERNEL
   46 #include <sys/queue.h>
   47 #include <sys/_lock.h>
   48 #include <sys/_mutex.h>
   49 #include <sys/_sx.h>
   50 #include <sys/condvar.h>
   51 #include <sys/sysctl.h>
   52 #endif
   53 
   54 /*
   55  * This interface must manage two items concerning remote procedure calling:
   56  *
   57  * 1) An arbitrary number of transport connections upon which rpc requests
   58  * are received.  The two most notable transports are TCP and UDP;  they are
   59  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
   60  * they in turn call xprt_register and xprt_unregister.
   61  *
   62  * 2) An arbitrary number of locally registered services.  Services are
   63  * described by the following four data: program number, version number,
   64  * "service dispatch" function, a transport handle, and a boolean that
   65  * indicates whether or not the exported program should be registered with a
   66  * local binder service;  if true the program's number and version and the
   67  * port number from the transport handle are registered with the binder.
   68  * These data are registered with the rpc svc system via svc_register.
   69  *
   70  * A service's dispatch function is called whenever an rpc request comes in
   71  * on a transport.  The request's program and version numbers must match
   72  * those of the registered service.  The dispatch function is passed two
   73  * parameters, struct svc_req * and SVCXPRT *, defined below.
   74  */
   75 
   76 /*
   77  *      Service control requests
   78  */
   79 #define SVCGET_VERSQUIET        1
   80 #define SVCSET_VERSQUIET        2
   81 #define SVCGET_CONNMAXREC       3
   82 #define SVCSET_CONNMAXREC       4
   83 
   84 /*
   85  * Operations for rpc_control().
   86  */
   87 #define RPC_SVC_CONNMAXREC_SET  0       /* set max rec size, enable nonblock */
   88 #define RPC_SVC_CONNMAXREC_GET  1
   89 
   90 enum xprt_stat {
   91         XPRT_DIED,
   92         XPRT_MOREREQS,
   93         XPRT_IDLE
   94 };
   95 
   96 struct __rpc_svcxprt;
   97 struct mbuf;
   98 
   99 struct xp_ops {
  100 #ifdef _KERNEL
  101         /* receive incoming requests */
  102         bool_t  (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *,
  103             struct sockaddr **, struct mbuf **);
  104         /* get transport status */
  105         enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
  106         /* get transport acknowledge sequence */
  107         bool_t (*xp_ack)(struct __rpc_svcxprt *, uint32_t *);
  108         /* send reply */
  109         bool_t  (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *,
  110             struct sockaddr *, struct mbuf *, uint32_t *);
  111         /* destroy this struct */
  112         void    (*xp_destroy)(struct __rpc_svcxprt *);
  113         /* catch-all function */
  114         bool_t  (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
  115 #else
  116         /* receive incoming requests */
  117         bool_t  (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
  118         /* get transport status */
  119         enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
  120         /* get arguments */
  121         bool_t  (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
  122         /* send reply */
  123         bool_t  (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
  124         /* free mem allocated for args */
  125         bool_t  (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, void *);
  126         /* destroy this struct */
  127         void    (*xp_destroy)(struct __rpc_svcxprt *);
  128 #endif
  129 };
  130 
  131 #ifndef _KERNEL
  132 struct xp_ops2 {
  133         /* catch-all function */
  134         bool_t  (*xp_control)(struct __rpc_svcxprt *, const u_int, void *);
  135 };
  136 #endif
  137 
  138 #ifdef _KERNEL
  139 struct __rpc_svcpool;
  140 struct __rpc_svcgroup;
  141 struct __rpc_svcthread;
  142 #endif
  143 
  144 /*
  145  * Server side transport handle. In the kernel, transports have a
  146  * reference count which tracks the number of currently assigned
  147  * worker threads plus one for the service pool's reference.
  148  */
  149 typedef struct __rpc_svcxprt {
  150 #ifdef _KERNEL
  151         volatile u_int  xp_refs;
  152         struct sx       xp_lock;
  153         struct __rpc_svcpool *xp_pool;  /* owning pool (see below) */
  154         struct __rpc_svcgroup *xp_group; /* owning group (see below) */
  155         TAILQ_ENTRY(__rpc_svcxprt) xp_link;
  156         TAILQ_ENTRY(__rpc_svcxprt) xp_alink;
  157         bool_t          xp_registered;  /* xprt_register has been called */
  158         bool_t          xp_active;      /* xprt_active has been called */
  159         struct __rpc_svcthread *xp_thread; /* assigned service thread */
  160         struct socket*  xp_socket;
  161         const struct xp_ops *xp_ops;
  162         char            *xp_netid;      /* network token */
  163         struct sockaddr_storage xp_ltaddr; /* local transport address */
  164         struct sockaddr_storage xp_rtaddr; /* remote transport address */
  165         void            *xp_p1;         /* private: for use by svc ops */
  166         void            *xp_p2;         /* private: for use by svc ops */
  167         void            *xp_p3;         /* private: for use by svc lib */
  168         int             xp_type;        /* transport type */
  169         int             xp_idletimeout; /* idle time before closing */
  170         time_t          xp_lastactive;  /* time of last RPC */
  171         u_int64_t       xp_sockref;     /* set by nfsv4 to identify socket */
  172         int             xp_upcallset;   /* socket upcall is set up */
  173         uint32_t        xp_snd_cnt;     /* # of bytes to send to socket */
  174         uint32_t        xp_snt_cnt;     /* # of bytes sent to socket */
  175 #else
  176         int             xp_fd;
  177         u_short         xp_port;         /* associated port number */
  178         const struct xp_ops *xp_ops;
  179         int             xp_addrlen;      /* length of remote address */
  180         struct sockaddr_in xp_raddr;     /* remote addr. (backward ABI compat) */
  181         /* XXX - fvdl stick this here for ABI backward compat reasons */
  182         const struct xp_ops2 *xp_ops2;
  183         char            *xp_tp;          /* transport provider device name */
  184         char            *xp_netid;       /* network token */
  185         struct netbuf   xp_ltaddr;       /* local transport address */
  186         struct netbuf   xp_rtaddr;       /* remote transport address */
  187         struct opaque_auth xp_verf;      /* raw response verifier */
  188         void            *xp_p1;          /* private: for use by svc ops */
  189         void            *xp_p2;          /* private: for use by svc ops */
  190         void            *xp_p3;          /* private: for use by svc lib */
  191         int             xp_type;         /* transport type */
  192 #endif
  193 } SVCXPRT;
  194 
  195 /*
  196  * Interface to server-side authentication flavors.
  197  */
  198 typedef struct __rpc_svcauth {
  199         struct svc_auth_ops {
  200 #ifdef _KERNEL
  201                 int   (*svc_ah_wrap)(struct __rpc_svcauth *,  struct mbuf **);
  202                 int   (*svc_ah_unwrap)(struct __rpc_svcauth *, struct mbuf **);
  203                 void  (*svc_ah_release)(struct __rpc_svcauth *);
  204 #else
  205                 int   (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *,
  206                     xdrproc_t, caddr_t);
  207                 int   (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *,
  208                     xdrproc_t, caddr_t);
  209 #endif
  210         } *svc_ah_ops;
  211         void *svc_ah_private;
  212 } SVCAUTH;
  213 
  214 /*
  215  * Server transport extensions (accessed via xp_p3).
  216  */
  217 typedef struct __rpc_svcxprt_ext {
  218         int             xp_flags;       /* versquiet */
  219         SVCAUTH         xp_auth;        /* interface to auth methods */
  220 } SVCXPRT_EXT;
  221 
  222 #ifdef _KERNEL
  223 
  224 /*
  225  * The services list
  226  * Each entry represents a set of procedures (an rpc program).
  227  * The dispatch routine takes request structs and runs the
  228  * apropriate procedure.
  229  */
  230 struct svc_callout {
  231         TAILQ_ENTRY(svc_callout) sc_link;
  232         rpcprog_t           sc_prog;
  233         rpcvers_t           sc_vers;
  234         char               *sc_netid;
  235         void                (*sc_dispatch)(struct svc_req *, SVCXPRT *);
  236 };
  237 TAILQ_HEAD(svc_callout_list, svc_callout);
  238 
  239 /*
  240  * The services connection loss list
  241  * The dispatch routine takes request structs and runs the
  242  * apropriate procedure.
  243  */
  244 struct svc_loss_callout {
  245         TAILQ_ENTRY(svc_loss_callout) slc_link;
  246         void                (*slc_dispatch)(SVCXPRT *);
  247 };
  248 TAILQ_HEAD(svc_loss_callout_list, svc_loss_callout);
  249 
  250 /*
  251  * Service request
  252  */
  253 struct svc_req {
  254         STAILQ_ENTRY(svc_req) rq_link;  /* list of requests for a thread */
  255         struct __rpc_svcthread *rq_thread; /* thread which is to execute this */
  256         uint32_t        rq_xid;         /* RPC transaction ID */
  257         uint32_t        rq_prog;        /* service program number */
  258         uint32_t        rq_vers;        /* service protocol version */
  259         uint32_t        rq_proc;        /* the desired procedure */
  260         size_t          rq_size;        /* space used by request */
  261         struct mbuf     *rq_args;       /* XDR-encoded procedure arguments */
  262         struct opaque_auth rq_cred;     /* raw creds from the wire */
  263         struct opaque_auth rq_verf;     /* verifier for the reply */
  264         void            *rq_clntcred;   /* read only cooked cred */
  265         SVCAUTH         rq_auth;        /* interface to auth methods */
  266         SVCXPRT         *rq_xprt;       /* associated transport */
  267         struct sockaddr *rq_addr;       /* reply address or NULL if connected */
  268         void            *rq_p1;         /* application workspace */
  269         int             rq_p2;          /* application workspace */
  270         uint64_t        rq_p3;          /* application workspace */
  271         uint32_t        rq_reply_seq;   /* reply socket sequence # */
  272         char            rq_credarea[3*MAX_AUTH_BYTES];
  273 };
  274 STAILQ_HEAD(svc_reqlist, svc_req);
  275 
  276 #define svc_getrpccaller(rq)                                    \
  277         ((rq)->rq_addr ? (rq)->rq_addr :                        \
  278             (struct sockaddr *) &(rq)->rq_xprt->xp_rtaddr)
  279 
  280 /*
  281  * This structure is used to manage a thread which is executing
  282  * requests from a service pool. A service thread is in one of three
  283  * states:
  284  *
  285  *      SVCTHREAD_SLEEPING      waiting for a request to process
  286  *      SVCTHREAD_ACTIVE        processing a request
  287  *      SVCTHREAD_EXITING       exiting after finishing current request
  288  *
  289  * Threads which have no work to process sleep on the pool's sp_active
  290  * list. When a transport becomes active, it is assigned a service
  291  * thread to read and execute pending RPCs.
  292  */
  293 typedef struct __rpc_svcthread {
  294         struct mtx              st_lock; /* protects st_reqs field */
  295         struct __rpc_svcpool    *st_pool;
  296         SVCXPRT                 *st_xprt; /* transport we are processing */
  297         struct svc_reqlist      st_reqs;  /* RPC requests to execute */
  298         struct cv               st_cond; /* sleeping for work */
  299         LIST_ENTRY(__rpc_svcthread) st_ilink; /* idle threads list */
  300         LIST_ENTRY(__rpc_svcthread) st_alink; /* application thread list */
  301         int             st_p2;          /* application workspace */
  302         uint64_t        st_p3;          /* application workspace */
  303 } SVCTHREAD;
  304 LIST_HEAD(svcthread_list, __rpc_svcthread);
  305 
  306 /*
  307  * A thread group contain all information needed to assign subset of
  308  * transports to subset of threads.  On systems with many CPUs and many
  309  * threads that allows to reduce lock congestion and improve performance.
  310  * Hundreds of threads on dozens of CPUs sharing the single pool lock do
  311  * not scale well otherwise.
  312  */
  313 TAILQ_HEAD(svcxprt_list, __rpc_svcxprt);
  314 enum svcpool_state {
  315         SVCPOOL_INIT,           /* svc_run not called yet */
  316         SVCPOOL_ACTIVE,         /* normal running state */
  317         SVCPOOL_THREADWANTED,   /* new service thread requested */
  318         SVCPOOL_THREADSTARTING, /* new service thread started */
  319         SVCPOOL_CLOSING         /* svc_exit called */
  320 };
  321 typedef struct __rpc_svcgroup {
  322         struct mtx      sg_lock;        /* protect the thread/req lists */
  323         struct __rpc_svcpool    *sg_pool;
  324         enum svcpool_state sg_state;    /* current pool state */
  325         struct svcxprt_list sg_xlist;   /* all transports in the group */
  326         struct svcxprt_list sg_active;  /* transports needing service */
  327         struct svcthread_list sg_idlethreads; /* idle service threads */
  328 
  329         int             sg_minthreads;  /* minimum service thread count */
  330         int             sg_maxthreads;  /* maximum service thread count */
  331         int             sg_threadcount; /* current service thread count */
  332         time_t          sg_lastcreatetime; /* when we last started a thread */
  333         time_t          sg_lastidlecheck;  /* when we last checked idle transports */
  334 } SVCGROUP;
  335 
  336 /*
  337  * In the kernel, we can't use global variables to store lists of
  338  * transports etc. since otherwise we could not have two unrelated RPC
  339  * services running, each on its own thread. We solve this by
  340  * importing a tiny part of a Solaris kernel concept, SVCPOOL.
  341  *
  342  * A service pool contains a set of transports and service callbacks
  343  * for a set of related RPC services. The pool handle should be passed
  344  * when creating new transports etc. Future work may include extending
  345  * this to support something similar to the Solaris multi-threaded RPC
  346  * server.
  347  */
  348 typedef SVCTHREAD *pool_assign_fn(SVCTHREAD *, struct svc_req *);
  349 typedef void pool_done_fn(SVCTHREAD *, struct svc_req *);
  350 #define SVC_MAXGROUPS   16
  351 typedef struct __rpc_svcpool {
  352         struct mtx      sp_lock;        /* protect the transport lists */
  353         const char      *sp_name;       /* pool name (e.g. "nfsd", "NLM" */
  354         enum svcpool_state sp_state;    /* current pool state */
  355         struct proc     *sp_proc;       /* process which is in svc_run */
  356         struct svc_callout_list sp_callouts; /* (prog,vers)->dispatch list */
  357         struct svc_loss_callout_list sp_lcallouts; /* loss->dispatch list */
  358         int             sp_minthreads;  /* minimum service thread count */
  359         int             sp_maxthreads;  /* maximum service thread count */
  360 
  361         /*
  362          * Hooks to allow an application to control request to thread
  363          * placement.
  364          */
  365         pool_assign_fn  *sp_assign;
  366         pool_done_fn    *sp_done;
  367 
  368         /*
  369          * These variables are used to put an upper bound on the
  370          * amount of memory used by RPC requests which are queued
  371          * waiting for execution.
  372          */
  373         unsigned int    sp_space_low;
  374         unsigned int    sp_space_high;
  375         unsigned int    sp_space_used;
  376         unsigned int    sp_space_used_highest;
  377         bool_t          sp_space_throttled;
  378         int             sp_space_throttle_count;
  379 
  380         struct replay_cache *sp_rcache; /* optional replay cache */
  381         struct sysctl_ctx_list sp_sysctl;
  382 
  383         int             sp_groupcount;  /* Number of groups in the pool. */
  384         int             sp_nextgroup;   /* Next group to assign port. */
  385         SVCGROUP        sp_groups[SVC_MAXGROUPS]; /* Thread/port groups. */
  386 } SVCPOOL;
  387 
  388 #else
  389 
  390 /*
  391  * Service request
  392  */
  393 struct svc_req {
  394         uint32_t        rq_prog;        /* service program number */
  395         uint32_t        rq_vers;        /* service protocol version */
  396         uint32_t        rq_proc;        /* the desired procedure */
  397         struct opaque_auth rq_cred;     /* raw creds from the wire */
  398         void            *rq_clntcred;   /* read only cooked cred */
  399         SVCXPRT         *rq_xprt;       /* associated transport */
  400 };
  401 
  402 /*
  403  *  Approved way of getting address of caller
  404  */
  405 #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
  406 
  407 #endif
  408 
  409 /*
  410  * Operations defined on an SVCXPRT handle
  411  *
  412  * SVCXPRT              *xprt;
  413  * struct rpc_msg       *msg;
  414  * xdrproc_t             xargs;
  415  * void *                argsp;
  416  */
  417 #ifdef _KERNEL
  418 
  419 #define SVC_ACQUIRE(xprt)                       \
  420         refcount_acquire(&(xprt)->xp_refs)
  421 
  422 #define SVC_RELEASE(xprt)                       \
  423         if (refcount_release(&(xprt)->xp_refs)) \
  424                 SVC_DESTROY(xprt)
  425 
  426 #define SVC_RECV(xprt, msg, addr, args)                 \
  427         (*(xprt)->xp_ops->xp_recv)((xprt), (msg), (addr), (args))
  428 
  429 #define SVC_STAT(xprt)                                  \
  430         (*(xprt)->xp_ops->xp_stat)(xprt)
  431 
  432 #define SVC_ACK(xprt, ack)                              \
  433         ((xprt)->xp_ops->xp_ack == NULL ? FALSE :       \
  434             ((ack) == NULL ? TRUE : (*(xprt)->xp_ops->xp_ack)((xprt), (ack))))
  435 
  436 #define SVC_REPLY(xprt, msg, addr, m, seq)                      \
  437         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg), (addr), (m), (seq))
  438 
  439 #define SVC_DESTROY(xprt)                               \
  440         (*(xprt)->xp_ops->xp_destroy)(xprt)
  441 
  442 #define SVC_CONTROL(xprt, rq, in)                       \
  443         (*(xprt)->xp_ops->xp_control)((xprt), (rq), (in))
  444 
  445 #else
  446 
  447 #define SVC_RECV(xprt, msg)                             \
  448         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  449 #define svc_recv(xprt, msg)                             \
  450         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  451 
  452 #define SVC_STAT(xprt)                                  \
  453         (*(xprt)->xp_ops->xp_stat)(xprt)
  454 #define svc_stat(xprt)                                  \
  455         (*(xprt)->xp_ops->xp_stat)(xprt)
  456 
  457 #define SVC_GETARGS(xprt, xargs, argsp)                 \
  458         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  459 #define svc_getargs(xprt, xargs, argsp)                 \
  460         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  461 
  462 #define SVC_REPLY(xprt, msg)                            \
  463         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  464 #define svc_reply(xprt, msg)                            \
  465         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  466 
  467 #define SVC_FREEARGS(xprt, xargs, argsp)                \
  468         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  469 #define svc_freeargs(xprt, xargs, argsp)                \
  470         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  471 
  472 #define SVC_DESTROY(xprt)                               \
  473         (*(xprt)->xp_ops->xp_destroy)(xprt)
  474 #define svc_destroy(xprt)                               \
  475         (*(xprt)->xp_ops->xp_destroy)(xprt)
  476 
  477 #define SVC_CONTROL(xprt, rq, in)                       \
  478         (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
  479 
  480 #endif
  481 
  482 #define SVC_EXT(xprt)                                   \
  483         ((SVCXPRT_EXT *) xprt->xp_p3)
  484 
  485 #define SVC_AUTH(xprt)                                  \
  486         (SVC_EXT(xprt)->xp_auth)
  487 
  488 /*
  489  * Operations defined on an SVCAUTH handle
  490  */
  491 #ifdef _KERNEL
  492 #define SVCAUTH_WRAP(auth, mp)          \
  493         ((auth)->svc_ah_ops->svc_ah_wrap(auth, mp))
  494 #define SVCAUTH_UNWRAP(auth, mp)        \
  495         ((auth)->svc_ah_ops->svc_ah_unwrap(auth, mp))
  496 #define SVCAUTH_RELEASE(auth)   \
  497         ((auth)->svc_ah_ops->svc_ah_release(auth))
  498 #else
  499 #define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere)         \
  500         ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere))
  501 #define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere)       \
  502         ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere))
  503 #endif
  504 
  505 /*
  506  * Service registration
  507  *
  508  * svc_reg(xprt, prog, vers, dispatch, nconf)
  509  *      const SVCXPRT *xprt;
  510  *      const rpcprog_t prog;
  511  *      const rpcvers_t vers;
  512  *      const void (*dispatch)();
  513  *      const struct netconfig *nconf;
  514  */
  515 
  516 __BEGIN_DECLS
  517 extern bool_t   svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
  518                         void (*)(struct svc_req *, SVCXPRT *),
  519                         const struct netconfig *);
  520 __END_DECLS
  521 
  522 /*
  523  * Service un-registration
  524  *
  525  * svc_unreg(prog, vers)
  526  *      const rpcprog_t prog;
  527  *      const rpcvers_t vers;
  528  */
  529 
  530 __BEGIN_DECLS
  531 #ifdef _KERNEL
  532 extern void     svc_unreg(SVCPOOL *, const rpcprog_t, const rpcvers_t);
  533 #else
  534 extern void     svc_unreg(const rpcprog_t, const rpcvers_t);
  535 #endif
  536 __END_DECLS
  537 
  538 #ifdef _KERNEL
  539 /*
  540  * Service connection loss registration
  541  *
  542  * svc_loss_reg(xprt, dispatch)
  543  *      const SVCXPRT *xprt;
  544  *      const void (*dispatch)();
  545  */
  546 
  547 __BEGIN_DECLS
  548 extern bool_t   svc_loss_reg(SVCXPRT *, void (*)(SVCXPRT *));
  549 __END_DECLS
  550 
  551 /*
  552  * Service connection loss un-registration
  553  *
  554  * svc_loss_unreg(xprt, dispatch)
  555  *      const SVCXPRT *xprt;
  556  *      const void (*dispatch)();
  557  */
  558 
  559 __BEGIN_DECLS
  560 extern void     svc_loss_unreg(SVCPOOL *, void (*)(SVCXPRT *));
  561 __END_DECLS
  562 #endif
  563 
  564 /*
  565  * Transport registration.
  566  *
  567  * xprt_register(xprt)
  568  *      SVCXPRT *xprt;
  569  */
  570 __BEGIN_DECLS
  571 extern void     xprt_register(SVCXPRT *);
  572 __END_DECLS
  573 
  574 /*
  575  * Transport un-register
  576  *
  577  * xprt_unregister(xprt)
  578  *      SVCXPRT *xprt;
  579  */
  580 __BEGIN_DECLS
  581 extern void     xprt_unregister(SVCXPRT *);
  582 extern void     __xprt_unregister_unlocked(SVCXPRT *);
  583 __END_DECLS
  584 
  585 #ifdef _KERNEL
  586 
  587 /*
  588  * Called when a transport has pending requests.
  589  */
  590 __BEGIN_DECLS
  591 extern void     xprt_active(SVCXPRT *);
  592 extern void     xprt_inactive(SVCXPRT *);
  593 extern void     xprt_inactive_locked(SVCXPRT *);
  594 extern void     xprt_inactive_self(SVCXPRT *);
  595 __END_DECLS
  596 
  597 #endif
  598 
  599 /*
  600  * When the service routine is called, it must first check to see if it
  601  * knows about the procedure;  if not, it should call svcerr_noproc
  602  * and return.  If so, it should deserialize its arguments via
  603  * SVC_GETARGS (defined above).  If the deserialization does not work,
  604  * svcerr_decode should be called followed by a return.  Successful
  605  * decoding of the arguments should be followed the execution of the
  606  * procedure's code and a call to svc_sendreply.
  607  *
  608  * Also, if the service refuses to execute the procedure due to too-
  609  * weak authentication parameters, svcerr_weakauth should be called.
  610  * Note: do not confuse access-control failure with weak authentication!
  611  *
  612  * NB: In pure implementations of rpc, the caller always waits for a reply
  613  * msg.  This message is sent when svc_sendreply is called.
  614  * Therefore pure service implementations should always call
  615  * svc_sendreply even if the function logically returns void;  use
  616  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  617  * for the abuse of pure rpc via batched calling or pipelining.  In the
  618  * case of a batched call, svc_sendreply should NOT be called since
  619  * this would send a return message, which is what batching tries to avoid.
  620  * It is the service/protocol writer's responsibility to know which calls are
  621  * batched and which are not.  Warning: responding to batch calls may
  622  * deadlock the caller and server processes!
  623  */
  624 
  625 __BEGIN_DECLS
  626 #ifdef _KERNEL
  627 extern bool_t   svc_sendreply(struct svc_req *, xdrproc_t, void *);
  628 extern bool_t   svc_sendreply_mbuf(struct svc_req *, struct mbuf *);
  629 extern void     svcerr_decode(struct svc_req *);
  630 extern void     svcerr_weakauth(struct svc_req *);
  631 extern void     svcerr_noproc(struct svc_req *);
  632 extern void     svcerr_progvers(struct svc_req *, rpcvers_t, rpcvers_t);
  633 extern void     svcerr_auth(struct svc_req *, enum auth_stat);
  634 extern void     svcerr_noprog(struct svc_req *);
  635 extern void     svcerr_systemerr(struct svc_req *);
  636 #else
  637 extern bool_t   svc_sendreply(SVCXPRT *, xdrproc_t, void *);
  638 extern void     svcerr_decode(SVCXPRT *);
  639 extern void     svcerr_weakauth(SVCXPRT *);
  640 extern void     svcerr_noproc(SVCXPRT *);
  641 extern void     svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
  642 extern void     svcerr_auth(SVCXPRT *, enum auth_stat);
  643 extern void     svcerr_noprog(SVCXPRT *);
  644 extern void     svcerr_systemerr(SVCXPRT *);
  645 #endif
  646 extern int      rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
  647                         char *(*)(char *), xdrproc_t, xdrproc_t,
  648                         char *);
  649 __END_DECLS
  650 
  651 /*
  652  * Lowest level dispatching -OR- who owns this process anyway.
  653  * Somebody has to wait for incoming requests and then call the correct
  654  * service routine.  The routine svc_run does infinite waiting; i.e.,
  655  * svc_run never returns.
  656  * Since another (co-existant) package may wish to selectively wait for
  657  * incoming calls or other events outside of the rpc architecture, the
  658  * routine svc_getreq is provided.  It must be passed readfds, the
  659  * "in-place" results of a select system call (see select, section 2).
  660  */
  661 
  662 #ifndef _KERNEL
  663 /*
  664  * Global keeper of rpc service descriptors in use
  665  * dynamic; must be inspected before each call to select
  666  */
  667 extern int svc_maxfd;
  668 #ifdef FD_SETSIZE
  669 extern fd_set svc_fdset;
  670 #define svc_fds svc_fdset.fds_bits[0]   /* compatibility */
  671 #else
  672 extern int svc_fds;
  673 #endif /* def FD_SETSIZE */
  674 #endif
  675 
  676 /*
  677  * a small program implemented by the svc_rpc implementation itself;
  678  * also see clnt.h for protocol numbers.
  679  */
  680 __BEGIN_DECLS
  681 extern void rpctest_service(void);
  682 __END_DECLS
  683 
  684 __BEGIN_DECLS
  685 extern SVCXPRT *svc_xprt_alloc(void);
  686 extern void     svc_xprt_free(SVCXPRT *);
  687 #ifndef _KERNEL
  688 extern void     svc_getreq(int);
  689 extern void     svc_getreqset(fd_set *);
  690 extern void     svc_getreq_common(int);
  691 struct pollfd;
  692 extern void     svc_getreq_poll(struct pollfd *, int);
  693 extern void     svc_run(void);
  694 extern void     svc_exit(void);
  695 #else
  696 extern void     svc_run(SVCPOOL *);
  697 extern void     svc_exit(SVCPOOL *);
  698 extern bool_t   svc_getargs(struct svc_req *, xdrproc_t, void *);
  699 extern bool_t   svc_freeargs(struct svc_req *, xdrproc_t, void *);
  700 extern void     svc_freereq(struct svc_req *);
  701 
  702 #endif
  703 __END_DECLS
  704 
  705 /*
  706  * Socket to use on svcxxx_create call to get default socket
  707  */
  708 #define RPC_ANYSOCK     -1
  709 #define RPC_ANYFD       RPC_ANYSOCK
  710 
  711 /*
  712  * These are the existing service side transport implementations
  713  */
  714 
  715 __BEGIN_DECLS
  716 
  717 #ifdef _KERNEL
  718 
  719 /*
  720  * Create a new service pool.
  721  */
  722 extern SVCPOOL* svcpool_create(const char *name,
  723     struct sysctl_oid_list *sysctl_base);
  724 
  725 /*
  726  * Destroy a service pool, including all registered transports.
  727  */
  728 extern void svcpool_destroy(SVCPOOL *pool);
  729 
  730 /*
  731  * Transport independent svc_create routine.
  732  */
  733 extern int svc_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
  734     const rpcprog_t, const rpcvers_t, const char *);
  735 /*
  736  *      void (*dispatch)();             -- dispatch routine
  737  *      const rpcprog_t prognum;        -- program number
  738  *      const rpcvers_t versnum;        -- version number
  739  *      const char *nettype;            -- network type
  740  */
  741 
  742 
  743 /*
  744  * Generic server creation routine. It takes a netconfig structure
  745  * instead of a nettype.
  746  */
  747 
  748 extern SVCXPRT *svc_tp_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *),
  749     const rpcprog_t, const rpcvers_t, const char *uaddr,
  750     const struct netconfig *);
  751         /*
  752          * void (*dispatch)();            -- dispatch routine
  753          * const rpcprog_t prognum;       -- program number
  754          * const rpcvers_t versnum;       -- version number
  755          * const char *uaddr;             -- universal address of service
  756          * const struct netconfig *nconf; -- netconfig structure
  757          */
  758 
  759 extern SVCXPRT *svc_dg_create(SVCPOOL *, struct socket *,
  760     const size_t, const size_t);
  761         /*
  762          * struct socket *;                             -- open connection
  763          * const size_t sendsize;                        -- max send size
  764          * const size_t recvsize;                        -- max recv size
  765          */
  766 
  767 extern SVCXPRT *svc_vc_create(SVCPOOL *, struct socket *,
  768     const size_t, const size_t);
  769         /*
  770          * struct socket *;                             -- open connection
  771          * const size_t sendsize;                        -- max send size
  772          * const size_t recvsize;                        -- max recv size
  773          */
  774 
  775 extern SVCXPRT *svc_vc_create_backchannel(SVCPOOL *);
  776 
  777 /*
  778  * Generic TLI create routine
  779  */
  780 extern SVCXPRT *svc_tli_create(SVCPOOL *, struct socket *,
  781     const struct netconfig *, const struct t_bind *, const size_t, const size_t);
  782 /*
  783  *      struct socket * so;             -- connection end point
  784  *      const struct netconfig *nconf;  -- netconfig structure for network
  785  *      const struct t_bind *bindaddr;  -- local bind address
  786  *      const size_t sendsz;             -- max sendsize
  787  *      const size_t recvsz;             -- max recvsize
  788  */
  789 
  790 #else /* !_KERNEL */
  791 
  792 /*
  793  * Transport independent svc_create routine.
  794  */
  795 extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
  796                            const rpcprog_t, const rpcvers_t, const char *);
  797 /*
  798  *      void (*dispatch)();             -- dispatch routine
  799  *      const rpcprog_t prognum;        -- program number
  800  *      const rpcvers_t versnum;        -- version number
  801  *      const char *nettype;            -- network type
  802  */
  803 
  804 
  805 /*
  806  * Generic server creation routine. It takes a netconfig structure
  807  * instead of a nettype.
  808  */
  809 
  810 extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
  811                                    const rpcprog_t, const rpcvers_t,
  812                                    const struct netconfig *);
  813         /*
  814          * void (*dispatch)();            -- dispatch routine
  815          * const rpcprog_t prognum;       -- program number
  816          * const rpcvers_t versnum;       -- version number
  817          * const struct netconfig *nconf; -- netconfig structure
  818          */
  819 
  820 /*
  821  * Generic TLI create routine
  822  */
  823 extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
  824                                const struct t_bind *, const u_int,
  825                                const u_int);
  826 /*
  827  *      const int fd;                   -- connection end point
  828  *      const struct netconfig *nconf;  -- netconfig structure for network
  829  *      const struct t_bind *bindaddr;  -- local bind address
  830  *      const u_int sendsz;             -- max sendsize
  831  *      const u_int recvsz;             -- max recvsize
  832  */
  833 
  834 /*
  835  * Connectionless and connectionful create routines
  836  */
  837 
  838 extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
  839 /*
  840  *      const int fd;                           -- open connection end point
  841  *      const u_int sendsize;                   -- max send size
  842  *      const u_int recvsize;                   -- max recv size
  843  */
  844 
  845 /*
  846  * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
  847  */
  848 extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
  849 
  850 extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
  851         /*
  852          * const int fd;                                -- open connection
  853          * const u_int sendsize;                        -- max send size
  854          * const u_int recvsize;                        -- max recv size
  855          */
  856 
  857 
  858 /*
  859  * the routine takes any *open* connection
  860  * descriptor as its first input and is used for open connections.
  861  */
  862 extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
  863 /*
  864  *      const int fd;                           -- open connection end point
  865  *      const u_int sendsize;                   -- max send size
  866  *      const u_int recvsize;                   -- max recv size
  867  */
  868 
  869 /*
  870  * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
  871  */
  872 extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
  873 
  874 /*
  875  * Memory based rpc (for speed check and testing)
  876  */
  877 extern SVCXPRT *svc_raw_create(void);
  878 
  879 /*
  880  * svc_dg_enable_cache() enables the cache on dg transports.
  881  */
  882 int svc_dg_enablecache(SVCXPRT *, const u_int);
  883 
  884 int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
  885 
  886 #endif  /* !_KERNEL */
  887 
  888 __END_DECLS
  889 
  890 #ifndef _KERNEL
  891 /* for backward compatibility */
  892 #include <rpc/svc_soc.h>
  893 #endif
  894 
  895 #endif /* !_RPC_SVC_H */

Cache object: d4fc2377b79c5dde204211f42b249f9c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.