Skip to content

Commit

Permalink
import djbdns 1.05
Browse files Browse the repository at this point in the history
  • Loading branch information
D. J. Bernstein authored and abh committed Dec 3, 2008
1 parent 81d4346 commit 0715ca5
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 29 deletions.
15 changes: 15 additions & 0 deletions CHANGES
Expand Up @@ -359,3 +359,18 @@
ui: dnstrace uses a ``start'' IP address for the root glue. ui: dnstrace uses a ``start'' IP address for the root glue.
20010121 20010121
version: djbdns 1.04. version: djbdns 1.04.
20010206
internal: response_query() takes a class argument.
internal: query_start() takes a class argument.
internal: packetquery() takes a class argument.
ui: tinydns et al., axfrdns, and dnscache repeat qclass * in
response to bogus * queries. tnx Mike Batchelor.
ui: axfrdns rejects queries for weird classes.
ui: axfrdns uses query ID instead of ID 0 in the series of AXFR
response messages between the SOAs, to support the AXFR
client in BIND 9.
ui: axfrdns sets AA in the series of AXFR response messages.
20010211
ui: servers print starting message.
internal: some respond() declarations.
version: djbdns 1.05.
7 changes: 4 additions & 3 deletions Makefile
Expand Up @@ -771,9 +771,10 @@ choose compile trysysel.c select.h1 select.h2
./choose c trysysel select.h1 select.h2 > select.h ./choose c trysysel select.h1 select.h2 > select.h


server.o: \ server.o: \
compile server.c byte.h case.h env.h strerr.h ip4.h uint16.h ndelay.h \ compile server.c byte.h case.h env.h buffer.h strerr.h ip4.h uint16.h \
socket.h uint16.h droproot.h qlog.h uint16.h response.h uint32.h \ ndelay.h socket.h uint16.h droproot.h qlog.h uint16.h response.h \
dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h uint32.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h \
taia.h
./compile server.c ./compile server.c


setup: \ setup: \
Expand Down
4 changes: 2 additions & 2 deletions README
@@ -1,5 +1,5 @@
djbdns 1.04 djbdns 1.05
20010121 20010211
Copyright 2001 Copyright 2001
D. J. Bernstein D. J. Bernstein


Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
djbdns 1.04 djbdns 1.05
22 changes: 15 additions & 7 deletions axfrdns.c
Expand Up @@ -22,6 +22,8 @@
#include "qlog.h" #include "qlog.h"
#include "response.h" #include "response.h"


extern int respond(char *,char *,char *);

#define FATAL "axfrdns: fatal: " #define FATAL "axfrdns: fatal: "


void nomem() void nomem()
Expand Down Expand Up @@ -144,7 +146,7 @@ void doname(stralloc *sa)
if (!stralloc_catb(sa,d,dns_domain_length(d))) nomem(); if (!stralloc_catb(sa,d,dns_domain_length(d))) nomem();
} }


int build(stralloc *sa,char *q,int flagsoa) int build(stralloc *sa,char *q,int flagsoa,char id[2])
{ {
unsigned int rdatapos; unsigned int rdatapos;
char misc[20]; char misc[20];
Expand All @@ -159,7 +161,8 @@ int build(stralloc *sa,char *q,int flagsoa)
if (flagsoa) if (byte_diff(type,2,DNS_T_SOA)) return 0; if (flagsoa) if (byte_diff(type,2,DNS_T_SOA)) return 0;
if (!flagsoa) if (byte_equal(type,2,DNS_T_SOA)) return 0; if (!flagsoa) if (byte_equal(type,2,DNS_T_SOA)) return 0;


if (!stralloc_copyb(sa,"\0\0\200\200\0\0\0\1\0\0\0\0",12)) nomem(); if (!stralloc_copyb(sa,id,2)) nomem();
if (!stralloc_catb(sa,"\204\000\0\0\0\1\0\0\0\0",10)) nomem();
copy(misc,1); copy(misc,1);
if ((misc[0] == '=' + 1) || (misc[0] == '*' + 1)) { if ((misc[0] == '=' + 1) || (misc[0] == '*' + 1)) {
--misc[0]; --misc[0];
Expand Down Expand Up @@ -217,7 +220,7 @@ static char *q;
static stralloc soa; static stralloc soa;
static stralloc message; static stralloc message;


void doaxfr(void) void doaxfr(char id[2])
{ {
char key[512]; char key[512];
uint32 klen; uint32 klen;
Expand Down Expand Up @@ -252,7 +255,7 @@ void doaxfr(void)
dlen = cdb_datalen(&c); dlen = cdb_datalen(&c);
if (dlen > sizeof data) die_cdbformat(); if (dlen > sizeof data) die_cdbformat();
if (cdb_read(&c,data,dlen,cdb_datapos(&c)) == -1) die_cdbformat(); if (cdb_read(&c,data,dlen,cdb_datapos(&c)) == -1) die_cdbformat();
if (build(&soa,zone,1)) break; if (build(&soa,zone,1,id)) break;
} }


cdb_free(&c); cdb_free(&c);
Expand Down Expand Up @@ -286,7 +289,7 @@ void doaxfr(void)
if (klen < 1) die_cdbformat(); if (klen < 1) die_cdbformat();
if (dns_packet_getname(key,klen,0,&q) != klen) die_cdbformat(); if (dns_packet_getname(key,klen,0,&q) != klen) die_cdbformat();
if (!dns_domain_suffix(q,zone)) continue; if (!dns_domain_suffix(q,zone)) continue;
if (!build(&message,q,0)) continue; if (!build(&message,q,0,id)) continue;
print(message.s,message.len); print(message.s,message.len);
} }


Expand Down Expand Up @@ -316,6 +319,7 @@ int main()
unsigned int pos; unsigned int pos;
char header[12]; char header[12];
char qtype[2]; char qtype[2];
char qclass[2];
const char *x; const char *x;


droproot(FATAL); droproot(FATAL);
Expand Down Expand Up @@ -346,18 +350,22 @@ int main()
pos = dns_packet_getname(buf,len,pos,&zone); if (!pos) die_truncated(); pos = dns_packet_getname(buf,len,pos,&zone); if (!pos) die_truncated();
zonelen = dns_domain_length(zone); zonelen = dns_domain_length(zone);
pos = dns_packet_copy(buf,len,pos,qtype,2); if (!pos) die_truncated(); pos = dns_packet_copy(buf,len,pos,qtype,2); if (!pos) die_truncated();
pos = dns_packet_copy(buf,len,pos,qclass,2); if (!pos) die_truncated();

if (byte_diff(qclass,2,DNS_C_IN) && byte_diff(qclass,2,DNS_C_ANY))
strerr_die2x(111,FATAL,"bogus query: bad class");


qlog(ip,port,header,zone,qtype," "); qlog(ip,port,header,zone,qtype," ");


if (byte_equal(qtype,2,DNS_T_AXFR)) { if (byte_equal(qtype,2,DNS_T_AXFR)) {
case_lowerb(zone,zonelen); case_lowerb(zone,zonelen);
fdcdb = open_read("data.cdb"); fdcdb = open_read("data.cdb");
if (fdcdb == -1) die_cdbread(); if (fdcdb == -1) die_cdbread();
doaxfr(); doaxfr(header);
close(fdcdb); close(fdcdb);
} }
else { else {
if (!response_query(zone,qtype)) nomem(); if (!response_query(zone,qtype,qclass)) nomem();
response[2] |= 4; response[2] |= 4;
case_lowerb(zone,zonelen); case_lowerb(zone,zonelen);
response_id(header); response_id(header);
Expand Down
13 changes: 7 additions & 6 deletions dnscache.c
Expand Up @@ -23,10 +23,9 @@
#include "okclient.h" #include "okclient.h"
#include "droproot.h" #include "droproot.h"


static int packetquery(char *buf,unsigned int len,char **q,char qtype[2],char id[2]) static int packetquery(char *buf,unsigned int len,char **q,char qtype[2],char qclass[2],char id[2])
{ {
unsigned int pos; unsigned int pos;
char qclass[2];
char header[12]; char header[12];


errno = error_proto; errno = error_proto;
Expand Down Expand Up @@ -92,6 +91,7 @@ void u_new(void)
int len; int len;
static char *q = 0; static char *q = 0;
char qtype[2]; char qtype[2];
char qclass[2];


for (j = 0;j < MAXUDP;++j) for (j = 0;j < MAXUDP;++j)
if (!u[j].active) if (!u[j].active)
Expand All @@ -115,11 +115,11 @@ void u_new(void)
if (x->port < 1024) if (x->port != 53) return; if (x->port < 1024) if (x->port != 53) return;
if (!okclient(x->ip)) return; if (!okclient(x->ip)) return;


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


x->active = ++numqueries; ++uactive; x->active = ++numqueries; ++uactive;
log_query(&x->active,x->ip,x->port,x->id,q,qtype); log_query(&x->active,x->ip,x->port,x->id,q,qtype);
switch(query_start(&x->q,q,qtype,myipoutgoing)) { switch(query_start(&x->q,q,qtype,qclass,myipoutgoing)) {
case -1: case -1:
u_drop(j); u_drop(j);
return; return;
Expand Down Expand Up @@ -210,6 +210,7 @@ void t_rw(int j)
char ch; char ch;
static char *q = 0; static char *q = 0;
char qtype[2]; char qtype[2];
char qclass[2];
int r; int r;


x = t + j; x = t + j;
Expand Down Expand Up @@ -249,11 +250,11 @@ void t_rw(int j)
x->buf[x->pos++] = ch; x->buf[x->pos++] = ch;
if (x->pos < x->len) return; if (x->pos < x->len) return;


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


x->active = ++numqueries; x->active = ++numqueries;
log_query(&x->active,x->ip,x->port,x->id,q,qtype); log_query(&x->active,x->ip,x->port,x->id,q,qtype);
switch(query_start(&x->q,q,qtype,myipoutgoing)) { switch(query_start(&x->q,q,qtype,qclass,myipoutgoing)) {
case -1: case -1:
t_drop(j); t_drop(j);
return; return;
Expand Down
1 change: 1 addition & 0 deletions pickdns.c
Expand Up @@ -7,6 +7,7 @@
#include "response.h" #include "response.h"


const char *fatal = "pickdns: fatal: "; const char *fatal = "pickdns: fatal: ";
const char *starting = "starting pickdns\n";


static char seed[128]; static char seed[128];


Expand Down
7 changes: 4 additions & 3 deletions query.c
Expand Up @@ -97,7 +97,7 @@ static int rqa(struct query *z)


for (i = QUERY_MAXALIAS - 1;i >= 0;--i) for (i = QUERY_MAXALIAS - 1;i >= 0;--i)
if (z->alias[i]) { if (z->alias[i]) {
if (!response_query(z->alias[i],z->type)) return 0; if (!response_query(z->alias[i],z->type,z->class)) return 0;
while (i > 0) { while (i > 0) {
if (!response_cname(z->alias[i],z->alias[i - 1],z->aliasttl[i])) return 0; if (!response_cname(z->alias[i],z->alias[i - 1],z->aliasttl[i])) return 0;
--i; --i;
Expand All @@ -106,7 +106,7 @@ static int rqa(struct query *z)
return 1; return 1;
} }


if (!response_query(z->name[0],z->type)) return 0; if (!response_query(z->name[0],z->type,z->class)) return 0;
return 1; return 1;
} }


Expand Down Expand Up @@ -818,7 +818,7 @@ static int doit(struct query *z,int state)
return -1; return -1;
} }


int query_start(struct query *z,char *dn,char type[2],char localip[4]) int query_start(struct query *z,char *dn,char type[2],char class[2],char localip[4])
{ {
if (byte_equal(type,2,DNS_T_AXFR)) { errno = error_perm; return -1; } if (byte_equal(type,2,DNS_T_AXFR)) { errno = error_perm; return -1; }


Expand All @@ -828,6 +828,7 @@ int query_start(struct query *z,char *dn,char type[2],char localip[4])


if (!dns_domain_copy(&z->name[0],dn)) return -1; if (!dns_domain_copy(&z->name[0],dn)) return -1;
byte_copy(z->type,2,type); byte_copy(z->type,2,type);
byte_copy(z->class,2,class);
byte_copy(z->localip,4,localip); byte_copy(z->localip,4,localip);


return doit(z,0); return doit(z,0);
Expand Down
3 changes: 2 additions & 1 deletion query.h
Expand Up @@ -19,10 +19,11 @@ struct query {
uint32 aliasttl[QUERY_MAXALIAS]; uint32 aliasttl[QUERY_MAXALIAS];
char localip[4]; char localip[4];
char type[2]; char type[2];
char class[2];
struct dns_transmit dt; struct dns_transmit dt;
} ; } ;


extern int query_start(struct query *,char *,char *,char *); extern int query_start(struct query *,char *,char *,char *,char *);
extern void query_io(struct query *,iopause_fd *,struct taia *); extern void query_io(struct query *,iopause_fd *,struct taia *);
extern int query_get(struct query *,iopause_fd *,struct taia *); extern int query_get(struct query *,iopause_fd *,struct taia *);


Expand Down
1 change: 1 addition & 0 deletions rbldns.c
Expand Up @@ -102,6 +102,7 @@ int respond(char *q,char qtype[2],char ip[4])
} }


const char *fatal = "rbldns: fatal: "; const char *fatal = "rbldns: fatal: ";
const char *starting = "starting rbldns\n";


void initialize(void) void initialize(void)
{ {
Expand Down
4 changes: 2 additions & 2 deletions response.c
Expand Up @@ -49,14 +49,14 @@ int response_addname(const char *d)
return response_addbytes(d,1); return response_addbytes(d,1);
} }


int response_query(const char *q,const char qtype[2]) int response_query(const char *q,const char qtype[2],const char qclass[2])
{ {
response_len = 0; response_len = 0;
name_num = 0; name_num = 0;
if (!response_addbytes("\0\0\201\200\0\1\0\0\0\0\0\0",12)) return 0; if (!response_addbytes("\0\0\201\200\0\1\0\0\0\0\0\0",12)) return 0;
if (!response_addname(q)) return 0; if (!response_addname(q)) return 0;
if (!response_addbytes(qtype,2)) return 0; if (!response_addbytes(qtype,2)) return 0;
if (!response_addbytes(DNS_C_IN,2)) return 0; if (!response_addbytes(qclass,2)) return 0;
tctarget = response_len; tctarget = response_len;
return 1; return 1;
} }
Expand Down
2 changes: 1 addition & 1 deletion response.h
Expand Up @@ -6,7 +6,7 @@
extern char response[]; extern char response[];
extern unsigned int response_len; extern unsigned int response_len;


extern int response_query(const char *,const char *); extern int response_query(const char *,const char *,const char *);
extern void response_nxdomain(void); extern void response_nxdomain(void);
extern void response_servfail(void); extern void response_servfail(void);
extern void response_id(const char *); extern void response_id(const char *);
Expand Down
7 changes: 5 additions & 2 deletions server.c
@@ -1,6 +1,7 @@
#include "byte.h" #include "byte.h"
#include "case.h" #include "case.h"
#include "env.h" #include "env.h"
#include "buffer.h"
#include "strerr.h" #include "strerr.h"
#include "ip4.h" #include "ip4.h"
#include "uint16.h" #include "uint16.h"
Expand All @@ -12,6 +13,7 @@
#include "dns.h" #include "dns.h"


extern char *fatal; extern char *fatal;
extern char *starting;
extern int respond(char *,char *,char *); extern int respond(char *,char *,char *);
extern void initialize(void); extern void initialize(void);


Expand Down Expand Up @@ -40,7 +42,7 @@ static int doit(void)
pos = dns_packet_copy(buf,len,pos,qtype,2); if (!pos) goto NOQ; pos = dns_packet_copy(buf,len,pos,qtype,2); if (!pos) goto NOQ;
pos = dns_packet_copy(buf,len,pos,qclass,2); if (!pos) goto NOQ; pos = dns_packet_copy(buf,len,pos,qclass,2); if (!pos) goto NOQ;


if (!response_query(q,qtype)) goto NOQ; if (!response_query(q,qtype,qclass)) goto NOQ;
response_id(header); response_id(header);
if (byte_equal(qclass,2,DNS_C_IN)) if (byte_equal(qclass,2,DNS_C_IN))
response[2] |= 4; response[2] |= 4;
Expand Down Expand Up @@ -69,7 +71,6 @@ static int doit(void)
WEIRDCLASS: WEIRDCLASS:
response[3] &= ~15; response[3] &= ~15;
response[3] |= 1; response[3] |= 1;
byte_copy(response + response_len - 2,2,qclass);
qlog(ip,port,header,q,qtype," C "); qlog(ip,port,header,q,qtype," C ");
return 1; return 1;


Expand Down Expand Up @@ -102,6 +103,8 @@ int main()
ndelay_off(udp53); ndelay_off(udp53);
socket_tryreservein(udp53,65536); socket_tryreservein(udp53,65536);


buffer_putsflush(buffer_2,starting);

for (;;) { for (;;) {
len = socket_recv4(udp53,buf,sizeof buf,ip,&port); len = socket_recv4(udp53,buf,sizeof buf,ip,&port);
if (len < 0) continue; if (len < 0) continue;
Expand Down
4 changes: 3 additions & 1 deletion tinydns-get.c
Expand Up @@ -13,6 +13,8 @@
#include "ip4.h" #include "ip4.h"
#include "dns.h" #include "dns.h"


extern int respond(char *,char *,char *);

#define FATAL "tinydns-get: fatal: " #define FATAL "tinydns-get: fatal: "


void usage(void) void usage(void)
Expand Down Expand Up @@ -53,7 +55,7 @@ int main(int argc,char **argv)
if (!dns_domain_todot_cat(&out,q)) oops(); if (!dns_domain_todot_cat(&out,q)) oops();
if (!stralloc_cats(&out,":\n")) oops(); if (!stralloc_cats(&out,":\n")) oops();


if (!response_query(q,type)) oops(); if (!response_query(q,type,DNS_C_IN)) oops();
response[3] &= ~128; response[3] &= ~128;
response[2] &= ~1; response[2] &= ~1;
response[2] |= 4; response[2] |= 4;
Expand Down
1 change: 1 addition & 0 deletions tinydns.c
@@ -1,6 +1,7 @@
#include "dns.h" #include "dns.h"


const char *fatal = "tinydns: fatal: "; const char *fatal = "tinydns: fatal: ";
const char *starting = "starting tinydns\n";


static char seed[128]; static char seed[128];


Expand Down
1 change: 1 addition & 0 deletions walldns.c
Expand Up @@ -4,6 +4,7 @@
#include "response.h" #include "response.h"


const char *fatal = "walldns: fatal: "; const char *fatal = "walldns: fatal: ";
const char *starting = "starting walldns\n";


void initialize(void) void initialize(void)
{ {
Expand Down

0 comments on commit 0715ca5

Please sign in to comment.