Beispiel #1
0
void
u_new (void)
{
    int i = 0, j = 0, len = 0;
    struct udpclient *x = NULL;

    static char *q = 0;
    char qtype[2], qclass[2];

    for (j = 0; j < MAXUDP; j++)
        if (!u[j].active)
            break;

    if (j >= MAXUDP)
    {
        j = 0;
        for (i = 1; i < MAXUDP; i++)
            if (taia_less (&u[i].start, &u[j].start))
                j = i;
        errno = error_timeout;
        u_drop (j);
    }

    x = u + j;
    taia_now (&x->start);

    len = socket_recv4 (udp53, buf, sizeof (buf), x->ip, &x->port, &odst);
    if (len == -1)
        return;
    if ((unsigned)len >= sizeof buf)
        return;
    if (x->port < 1024 && x->port != 53)
        return;
    if (!okclient (x->ip))
        return;
    if (!packetquery (buf, len, &q, qtype, qclass, x->id))
        return;

    x->active = ++numqueries;
    ++uactive;

    if (debug_level)
        log_query (x->active, x->ip, x->port, x->id, q, qtype);

    switch (query_start (&x->q, q, qtype, qclass, myipoutgoing))
    {
    case -1:
        u_drop (j);
        return;

    case 1:
        u_respond (j);
    }
}
Beispiel #2
0
void
t_new (void)
{
    int i = 0, j = 0;
    struct tcpclient *x = NULL;

    for (j = 0; j < MAXTCP; ++j)
        if (!t[j].active)
          break;

    if (j >= MAXTCP)
    {
        j = 0;
        for (i = 1; i < MAXTCP; ++i)
            if (taia_less (&t[i].start, &t[j].start))
                j = i;
        errno = error_timeout;
        if (t[j].state == 0)
          t_drop (j);
        else
          t_close (j);
    }

    x = t + j;
    taia_now (&x->start);

    x->tcp = socket_accept4 (tcp53, x->ip, &x->port);
    if (x->tcp == -1)
        return;
    if (x->port < 1024 && x->port != 53)
    {
        close (x->tcp);
        return;
    }
    if (!okclient (x->ip))
    {
        close (x->tcp);
        return;
    }
    if (ndelay_on (x->tcp) == -1)
    {
        close(x->tcp);
        return;
    } /* Linux bug */

    x->active = 1;
    ++tactive;
    x->state = 1;
    t_timeout (j);

    if (debug_level > 2)
        log_tcpopen (x->ip, x->port);
}
Beispiel #3
0
void u_new(void)
{
  int j;
  int i;
  struct udpclient *x;
  int len;
  static char *q = 0;
  char qtype[2];
  char qclass[2];

  for (j = 0;j < MAXUDP;++j)
    if (!u[j].active)
      break;

  if (j >= MAXUDP) {
    j = 0;
    for (i = 1;i < MAXUDP;++i)
      if (taia_less(&u[i].start,&u[j].start))
	j = i;
    errno = error_timeout;
    u_drop(j);
  }

  x = u + j;
  taia_now(&x->start);

  len = socket_recv6(udp53,buf,sizeof buf,x->ip,&x->port,&x->scope_id);
  if (len == -1) return;
  if (len >= sizeof buf) return;
  if (x->port < 1024) if (x->port != 53) return;
  if (!okclient(x->ip)) return;

  if (!packetquery(buf,len,&q,qtype,qclass,x->id)) return;

  x->active = ++numqueries; ++uactive;
  log_query(&x->active,x->ip,x->port,x->id,q,qtype);
  switch(query_start(&x->q,q,qtype,qclass,myipoutgoing,interface)) {
    case -1:
      u_drop(j);
      return;
    case 1:
      u_respond(j);
  }
}