Back to index

glibc  2.9
Classes | Defines | Functions | Variables
svc.c File Reference
#include <errno.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <rpc/svc.h>
#include <rpc/pmap_clnt.h>
#include <sys/poll.h>

Go to the source code of this file.

Classes

struct  svc_callout

Defines

#define NULL_SVC   ((struct svc_callout *)0)
#define RQCRED_SIZE   400 /* this size is excessive */

Functions

void xprt_register (SVCXPRT *xprt)
 libc_hidden_def (xprt_register)
 libc_hidden_def (xprt_unregister)
static bool_t svc_is_mapped (rpcprog_t prog, rpcvers_t vers)
bool_t svc_register (SVCXPRT *xprt, rpcprog_t prog, rpcvers_t vers, void(*dispatch)(struct svc_req *, SVCXPRT *), rpcproc_t protocol)
 libc_hidden_def (svc_register)
 libc_hidden_def (svc_unregister)
void svcerr_noproc (register SVCXPRT *xprt)
void svcerr_decode (register SVCXPRT *xprt)
void svcerr_systemerr (register SVCXPRT *xprt)
void svcerr_auth (SVCXPRT *xprt, enum auth_stat why)
 libc_hidden_def (svcerr_auth)
void svcerr_noprog (register SVCXPRT *xprt)
 libc_hidden_def (svcerr_noprog)
 libc_hidden_def (svcerr_progvers)
void svc_getreqset (fd_set *readfds)
void svc_getreq_poll (struct pollfd *pfdp, int pollretval)
void svc_getreq_common (const int fd)

Variables

static SVCXPRT ** xports
static struct svc_calloutsvc_head

Define Documentation

#define NULL_SVC   ((struct svc_callout *)0)

Definition at line 52 of file svc.c.

#define RQCRED_SIZE   400 /* this size is excessive */

Definition at line 53 of file svc.c.


Function Documentation

Definition at line 119 of file svc.c.

{
  register int sock = xprt->xp_sock;
  register int i;

  if ((sock < _rpc_dtablesize ()) && (xports[sock] == xprt))
    {
      xports[sock] = (SVCXPRT *) 0;

      if (sock < FD_SETSIZE)
       FD_CLR (sock, &svc_fdset);

      for (i = 0; i < svc_max_pollfd; ++i)
       if (svc_pollfd[i].fd == sock)
         svc_pollfd[i].fd = -1;
    }
}

Here is the call graph for this function:

Definition at line 140 of file svc.c.

{
  register struct svc_callout *s, *p;

  p = NULL_SVC;
  for (s = svc_head; s != NULL_SVC; s = s->sc_next)
    {
      if ((s->sc_prog == prog) && (s->sc_vers == vers))
       goto done;
      p = s;
    }
done:
  *prev = p;
  return s;
}

Definition at line 215 of file svc.c.

{
  struct svc_callout *prev;
  register struct svc_callout *s;

  if ((s = svc_find (prog, vers, &prev)) == NULL_SVC)
    return;

  if (prev == NULL_SVC)
    svc_head = s->sc_next;
  else
    prev->sc_next = s->sc_next;

  s->sc_next = NULL_SVC;
  mem_free ((char *) s, (u_int) sizeof (struct svc_callout));
  /* now unregister the information with the local binder service */
  if (! svc_is_mapped (prog, vers))
    pmap_unset (prog, vers);
}

Here is the call graph for this function:

Definition at line 238 of file svc.c.

{
  struct rpc_msg rply;

  rply.rm_direction = REPLY;
  rply.rm_reply.rp_stat = MSG_ACCEPTED;
  rply.acpted_rply.ar_verf = xprt->xp_verf;
  rply.acpted_rply.ar_stat = SUCCESS;
  rply.acpted_rply.ar_results.where = xdr_location;
  rply.acpted_rply.ar_results.proc = xdr_results;
  return SVC_REPLY (xprt, &rply);
}

Definition at line 311 of file svc.c.

Here is the call graph for this function:

Definition at line 332 of file svc.c.

{
  struct rpc_msg rply;

  rply.rm_direction = REPLY;
  rply.rm_reply.rp_stat = MSG_ACCEPTED;
  rply.acpted_rply.ar_verf = xprt->xp_verf;
  rply.acpted_rply.ar_stat = PROG_MISMATCH;
  rply.acpted_rply.ar_vers.low = low_vers;
  rply.acpted_rply.ar_vers.high = high_vers;
  SVC_REPLY (xprt, &rply);
}

Definition at line 349 of file svc.c.

{
  fd_set readfds;

  FD_ZERO (&readfds);
  readfds.fds_bits[0] = rdfds;
  INTUSE(svc_getreqset) (&readfds);
}

Here is the call graph for this function:

void svc_getreq_common ( const int  fd)

Definition at line 427 of file svc.c.

{
  enum xprt_stat stat;
  struct rpc_msg msg;
  register SVCXPRT *xprt;
  char cred_area[2 * MAX_AUTH_BYTES + RQCRED_SIZE];
  msg.rm_call.cb_cred.oa_base = cred_area;
  msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);

  xprt = xports[fd];
  /* Do we control fd? */
  if (xprt == NULL)
     return;

  /* now receive msgs from xprtprt (support batch calls) */
  do
    {
      if (SVC_RECV (xprt, &msg))
       {
         /* now find the exported program and call it */
         struct svc_callout *s;
         struct svc_req r;
         enum auth_stat why;
         rpcvers_t low_vers;
         rpcvers_t high_vers;
         int prog_found;

         r.rq_clntcred = &(cred_area[2 * MAX_AUTH_BYTES]);
         r.rq_xprt = xprt;
         r.rq_prog = msg.rm_call.cb_prog;
         r.rq_vers = msg.rm_call.cb_vers;
         r.rq_proc = msg.rm_call.cb_proc;
         r.rq_cred = msg.rm_call.cb_cred;

         /* first authenticate the message */
         /* Check for null flavor and bypass these calls if possible */

         if (msg.rm_call.cb_cred.oa_flavor == AUTH_NULL)
           {
             r.rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
             r.rq_xprt->xp_verf.oa_length = 0;
           }
         else if ((why = INTUSE(_authenticate) (&r, &msg)) != AUTH_OK)
           {
             svcerr_auth (xprt, why);
             goto call_done;
           }

         /* now match message with a registered service */
         prog_found = FALSE;
         low_vers = 0 - 1;
         high_vers = 0;

         for (s = svc_head; s != NULL_SVC; s = s->sc_next)
           {
             if (s->sc_prog == r.rq_prog)
              {
                if (s->sc_vers == r.rq_vers)
                  {
                    (*s->sc_dispatch) (&r, xprt);
                    goto call_done;
                  }
                /* found correct version */
                prog_found = TRUE;
                if (s->sc_vers < low_vers)
                  low_vers = s->sc_vers;
                if (s->sc_vers > high_vers)
                  high_vers = s->sc_vers;
              }
             /* found correct program */
           }
         /* if we got here, the program or version
            is not served ... */
         if (prog_found)
           svcerr_progvers (xprt, low_vers, high_vers);
         else
           svcerr_noprog (xprt);
         /* Fall through to ... */
       }
    call_done:
      if ((stat = SVC_STAT (xprt)) == XPRT_DIED)
       {
         SVC_DESTROY (xprt);
         break;
       }
    }
  while (stat == XPRT_MOREREQS);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void svc_getreq_poll ( struct pollfd pfdp,
int  pollretval 
)

Definition at line 400 of file svc.c.

{
  if (pollretval == 0)
    return;

  register int fds_found;
  for (int i = fds_found = 0; i < svc_max_pollfd; ++i)
    {
      register struct pollfd *p = &pfdp[i];

      if (p->fd != -1 && p->revents)
       {
         /* fd has input waiting */
         if (p->revents & POLLNVAL)
           xprt_unregister (xports[p->fd]);
         else
           INTUSE(svc_getreq_common) (p->fd);

         if (++fds_found >= pollretval)
           break;
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void svc_getreqset ( fd_set readfds)

Definition at line 381 of file svc.c.

{
  register fd_mask mask;
  register fd_mask *maskp;
  register int setsize;
  register int sock;
  register int bit;

  setsize = _rpc_dtablesize ();
  if (setsize > FD_SETSIZE)
    setsize = FD_SETSIZE;
  maskp = readfds->fds_bits;
  for (sock = 0; sock < setsize; sock += NFDBITS)
    for (mask = *maskp++; (bit = ffsl (mask)); mask ^= (1L << (bit - 1)))
      INTUSE(svc_getreq_common) (sock + bit - 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool_t svc_is_mapped ( rpcprog_t  prog,
rpcvers_t  vers 
) [static]

Definition at line 166 of file svc.c.

{
  struct svc_callout *prev;
  register struct svc_callout *s;
  s = svc_find (prog, vers, &prev);
  return s!= NULL_SVC && s->sc_mapped;
}

Here is the caller graph for this function:

bool_t svc_register ( SVCXPRT xprt,
rpcprog_t  prog,
rpcvers_t  vers,
void(*)(struct svc_req *, SVCXPRT *)  dispatch,
rpcproc_t  protocol 
)

Definition at line 179 of file svc.c.

{
  struct svc_callout *prev;
  register struct svc_callout *s;

  if ((s = svc_find (prog, vers, &prev)) != NULL_SVC)
    {
      if (s->sc_dispatch == dispatch)
       goto pmap_it;        /* he is registering another xptr */
      return FALSE;
    }
  s = (struct svc_callout *) mem_alloc (sizeof (struct svc_callout));
  if (s == (struct svc_callout *) 0)
    return FALSE;

  s->sc_prog = prog;
  s->sc_vers = vers;
  s->sc_dispatch = dispatch;
  s->sc_next = svc_head;
  s->sc_mapped = FALSE;
  svc_head = s;

pmap_it:
  /* now register the information with the local binder service */
  if (protocol)
    {
      if (! pmap_set (prog, vers, protocol, xprt->xp_port))
       return FALSE;

      s->sc_mapped = TRUE;
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void svcerr_auth ( SVCXPRT xprt,
enum auth_stat  why 
)

Definition at line 301 of file svc.c.

{
  struct rpc_msg rply;

  rply.rm_direction = REPLY;
  rply.rm_reply.rp_stat = MSG_DENIED;
  rply.rjcted_rply.rj_stat = AUTH_ERROR;
  rply.rjcted_rply.rj_why = why;
  SVC_REPLY (xprt, &rply);
}

Here is the caller graph for this function:

void svcerr_decode ( register SVCXPRT xprt)

Definition at line 274 of file svc.c.

{
  struct rpc_msg rply;

  rply.rm_direction = REPLY;
  rply.rm_reply.rp_stat = MSG_ACCEPTED;
  rply.acpted_rply.ar_verf = xprt->xp_verf;
  rply.acpted_rply.ar_stat = GARBAGE_ARGS;
  SVC_REPLY (xprt, &rply);
}
void svcerr_noproc ( register SVCXPRT xprt)

Definition at line 261 of file svc.c.

{
  struct rpc_msg rply;

  rply.rm_direction = REPLY;
  rply.rm_reply.rp_stat = MSG_ACCEPTED;
  rply.acpted_rply.ar_verf = xprt->xp_verf;
  rply.acpted_rply.ar_stat = PROC_UNAVAIL;
  SVC_REPLY (xprt, &rply);
}
void svcerr_noprog ( register SVCXPRT xprt)

Definition at line 322 of file svc.c.

{
  struct rpc_msg rply;

  rply.rm_direction = REPLY;
  rply.rm_reply.rp_stat = MSG_ACCEPTED;
  rply.acpted_rply.ar_verf = xprt->xp_verf;
  rply.acpted_rply.ar_stat = PROG_UNAVAIL;
  SVC_REPLY (xprt, &rply);
}
void svcerr_systemerr ( register SVCXPRT xprt)

Definition at line 288 of file svc.c.

{
  struct rpc_msg rply;

  rply.rm_direction = REPLY;
  rply.rm_reply.rp_stat = MSG_ACCEPTED;
  rply.acpted_rply.ar_verf = xprt->xp_verf;
  rply.acpted_rply.ar_stat = SYSTEM_ERR;
  SVC_REPLY (xprt, &rply);
}
void xprt_register ( SVCXPRT xprt)

Definition at line 76 of file svc.c.

{
  register int sock = xprt->xp_sock;
  register int i;

  if (xports == NULL)
    {
      xports = (SVCXPRT **) malloc (_rpc_dtablesize () * sizeof (SVCXPRT *));
      if (xports == NULL) /* Donīt add handle */
       return;
    }

  if (sock < _rpc_dtablesize ())
    {
      struct pollfd *new_svc_pollfd;

      xports[sock] = xprt;
      if (sock < FD_SETSIZE)
       FD_SET (sock, &svc_fdset);

      /* Check if we have an empty slot */
      for (i = 0; i < svc_max_pollfd; ++i)
       if (svc_pollfd[i].fd == -1)
         {
           svc_pollfd[i].fd = sock;
           svc_pollfd[i].events = (POLLIN | POLLPRI |
                                POLLRDNORM | POLLRDBAND);
           return;
         }

      new_svc_pollfd = (struct pollfd *) realloc (svc_pollfd,
                                            sizeof (struct pollfd)
                                            * (svc_max_pollfd + 1));
      if (new_svc_pollfd == NULL) /* Out of memory */
       return;
      svc_pollfd = new_svc_pollfd;
      ++svc_max_pollfd;

      svc_pollfd[svc_max_pollfd - 1].fd = sock;
      svc_pollfd[svc_max_pollfd - 1].events = (POLLIN | POLLPRI |
                                          POLLRDNORM | POLLRDBAND);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct svc_callout* svc_head [static]

Definition at line 69 of file svc.c.

SVCXPRT** xports [static]

Definition at line 49 of file svc.c.