--- djbdns-1.05-pristine/dnscache.c Sun Feb 11 13:11:45 2001 +++ djbdns-1.05/dnscache.c Thu Aug 2 02:18:45 2001 @@ -54,7 +54,7 @@ static int udp53; -#define MAXUDP 200 +#define MAXUDP 1024 static struct udpclient { struct query q; struct taia start; @@ -92,46 +92,57 @@ static char *q = 0; char qtype[2]; char qclass[2]; + uint16 port; + char ip[4]; + char id[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); - } + while (1) { - x = u + j; - taia_now(&x->start); + len = socket_recv4(udp53,buf,sizeof buf,ip,&port); + if (len == -1) break; - len = socket_recv4(udp53,buf,sizeof buf,x->ip,&x->port); - 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)) { - case -1: + if (len >= sizeof buf) continue; + if (port < 1024) if (port != 53) continue; + if (!okclient(ip)) continue; + + if (!packetquery(buf,len,&q,qtype,qclass,id)) continue; + + 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); - return; - case 1: - u_respond(j); + } + + x = u + j; + taia_now(&x->start); + + byte_copy(x->ip,4,ip); + x->port = port; + byte_copy(x->id,2,id); + + 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)) { + case -1: + u_drop(j); + continue; + case 1: + u_respond(j); + } } } static int tcp53; -#define MAXTCP 20 +#define MAXTCP 100 struct tcpclient { struct query q; struct taia start;