Commit Diff
Diff:
1a591502e2b903b178997ed1871067fe50f6368c
b0a7237623dfb5cf90944a52d5067ad769096efb
Commit:
b0a7237623dfb5cf90944a52d5067ad769096efb
Tree:
c2f4a30a36df2ab73aee3582ed9356319d340311
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Thu Apr 1 20:05:04 2010 UTC
Message:
* add a root "hint" RR, much like in BIND this is for the DNS root database a "hint" is like a "ns" RR only that it's never authoritative * fix a bug introduced in reply.c version 1.11 where in reply_ns() only 5 NS hosts could be served instead of 10. * instead of 10 RR's allow 20 and alias this as RECORD_COUNT, this allows all 13 root nameservers to be served now. * in reply_ns() compress NS answers, which we didn't do before.
blob - f976411a123fab5433ef557411e8225928e8d148
blob + 5024a20779a141091b6116ca46f265731204018f
--- TODO
+++ TODO
@@ -6,7 +6,7 @@ Here are a few things nice to have but not necessarily
* access lists (with recursing/caching)
* EDNS0 support
* DNSSEC support
-* change struct domain to use pointers, this would cut memory by a lot
+* change struct domain to use pointers, this would cut memory by a lot [done]
Here are some ideas for the config file:
blob - be9905a731cd75f0f93b62d8b852f4efd3b00a60
blob + 962cadc2fa58b11aeff5a892e4436795aece7df8
--- db.h
+++ db.h
@@ -34,6 +34,8 @@
#define ERR_NXDOMAIN 0x2
#define ERR_NOERROR 0x4
+#define RECORD_COUNT 20
+
/* db stuff */
struct soa {
@@ -74,20 +76,22 @@ struct domain {
#define DOMAIN_HAVE_TXT 0x80
struct soa *soa; /* start of authority */
u_int32_t ttl; /* time to live */
- in_addr_t a[10]; /* IP addresses */
- u_int8_t region[10]; /* region of IP address */
+ in_addr_t a[RECORD_COUNT]; /* IP addresses */
+ u_int8_t region[RECORD_COUNT]; /* region of IP address */
int a_count; /* IP address count (max 10) */
int a_ptr; /* pointer to last used address */
- struct in6_addr *aaaa[10]; /* IPv6 addresses */
+ struct in6_addr *aaaa[RECORD_COUNT]; /* IPv6 addresses */
int aaaa_count; /* IPv6 address count (max 10) */
int aaaa_ptr; /* pointer to last used IPv6 address */
- struct smx *mx[10]; /* MX addresses */
+ struct smx *mx[RECORD_COUNT]; /* MX addresses */
int mx_count; /* MX address count, max 10 */
int mx_ptr; /* pointer to last used MX adddress */
- struct ns *ns[10]; /* NS resource records (max 10) */
+ struct ns *ns[RECORD_COUNT]; /* NS resource records (max 10) */
int ns_count; /* count of NS records, (max 10) */
int ns_ptr; /* pointer to last used NS address */
- int ns_delegate; /* set if it's a delegation */
+ int ns_type; /* set if it's a delegation */
+#define NS_TYPE_DELEGATE 0x1
+#define NS_TYPE_HINT 0x2
char *cname; /* CNAME RR */
int cnamelen; /* len of CNAME */
char *ptr; /* PTR RR */
blob - 04327d23d4d934fe12821638f795b1634347f35c
blob + dd16a38869c6d3a48c2b6a27d39b0b361d7b3d3f
--- dns.h
+++ dns.h
@@ -126,6 +126,7 @@ struct dns_question_hdr {
#define DNS_TYPE_BALANCE 0xfffe /* split horizon dns */
#define DNS_TYPE_DELEGATE 0xfffd /* ns delegations */
+#define DNS_TYPE_HINT 0xfffc /* root hint */
/* quad A - RFC 3596 */
#define DNS_TYPE_AAAA 28
blob - 620beefcbfe8e76f023a08e4c0129387ff1d00ae
blob + df009e872ba8dc3d52009ec3030dae66a391dc84
--- example4.conf
+++ example4.conf
@@ -69,3 +69,39 @@ zone "centroid.eu" {
centroid.eu,txt,3600,1234
text.centroid.eu,txt,3600,,,,this is valid,,,too,,,
}
+
+zone "root hints" {
+ .,hint,3600000,A.ROOT-SERVERS.NET.
+ A.ROOT-SERVERS.NET.,a,3600000,198.41.0.4
+ A.ROOT-SERVERS.NET.,aaaa,3600000,2001:503:BA3E::2:30
+ .,hint,3600000,B.ROOT-SERVERS.NET.
+ B.ROOT-SERVERS.NET.,a,3600000,192.228.79.201
+ .,hint,3600000,C.ROOT-SERVERS.NET.
+ C.ROOT-SERVERS.NET.,a,3600000,192.33.4.12
+ .,hint,3600000,D.ROOT-SERVERS.NET.
+ D.ROOT-SERVERS.NET.,a,3600000,128.8.10.90
+ .,hint,3600000,E.ROOT-SERVERS.NET.
+ E.ROOT-SERVERS.NET.,a,3600000,192.203.230.10
+ .,hint,3600000,F.ROOT-SERVERS.NET.
+ F.ROOT-SERVERS.NET.,a,3600000,192.5.5.241
+ F.ROOT-SERVERS.NET.,aaaa,3600000,2001:500:2f::f
+ .,hint,3600000,G.ROOT-SERVERS.NET.
+ G.ROOT-SERVERS.NET.,a,3600000,192.112.36.4
+ .,hint,3600000,H.ROOT-SERVERS.NET.
+ H.ROOT-SERVERS.NET.,a,3600000,128.63.2.53
+ H.ROOT-SERVERS.NET.,aaaa,3600000,2001:500:1::803f:235
+ .,hint,3600000,I.ROOT-SERVERS.NET.
+ I.ROOT-SERVERS.NET.,a,3600000,192.36.148.17
+ .,hint,3600000,J.ROOT-SERVERS.NET.
+ J.ROOT-SERVERS.NET.,a,3600000,192.58.128.30
+ J.ROOT-SERVERS.NET.,aaaa,3600000,2001:503:C27::2:30
+ .,hint,3600000,K.ROOT-SERVERS.NET.
+ K.ROOT-SERVERS.NET.,a,3600000,193.0.14.129
+ K.ROOT-SERVERS.NET.,aaaa,3600000,2001:7fd::1
+ .,hint,3600000,L.ROOT-SERVERS.NET.
+ L.ROOT-SERVERS.NET.,a,3600000,199.7.83.42
+ L.ROOT-SERVERS.NET.,aaaa,3600000,2001:500:3::42
+ .,hint,3600000,M.ROOT-SERVERS.NET.
+ M.ROOT-SERVERS.NET.,a,3600000,202.12.27.33
+ M.ROOT-SERVERS.NET.,aaaa,3600000,2001:dc3::35
+}
blob - 9b6458a41631c57ab446714ad0540f6dc0b8caa0
blob + 62aa5cea195e551109bbf8f01b8f5b0e14e59789
--- main.c
+++ main.c
@@ -104,7 +104,7 @@ struct tcps {
} *tn1, *tn2, *tnp;
-static const char rcsid[] = "$Id: main.c,v 1.48 2010/03/28 20:18:26 pbug Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.49 2010/04/01 20:05:04 pbug Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -975,13 +975,13 @@ lookup_zone(DB *db, struct question *question, struct
snprintf(replystring, DNS_MAXNAME, "%s", sd->zonename);
if (Wflag) {
- if (wildcarding && !sd->ns_delegate) {
+ if (wildcarding && !sd->ns_type) {
*lzerrno = ERR_NXDOMAIN;
return -1;
}
}
- if (sd->ns_delegate == 1) {
+ if (sd->ns_type > 0) {
returnval = DNS_TYPE_NS;
*lzerrno = ERR_NOERROR;
goto out;
@@ -1109,7 +1109,7 @@ lookup_zone(DB *db, struct question *question, struct
memcpy((char *)sd, (char *)data.data, data.size);
- if (sd->ns_delegate) {
+ if (sd->ns_type > 0) {
returnval = DNS_TYPE_NS;
goto out;
}
blob - 52a0517a11cfcece55d19568ac920d31387a62b5
blob + 863cb7f7c59a0637cb3b537514b588dddbef73bf
--- parse.c
+++ parse.c
@@ -46,6 +46,7 @@ struct myrr_lookup {
{ "aaaa", DNS_TYPE_AAAA },
{ "ns", DNS_TYPE_NS },
{ "txt", DNS_TYPE_TXT },
+ { "hint", DNS_TYPE_HINT },
{ "delegate", DNS_TYPE_DELEGATE },
{ "balance", DNS_TYPE_BALANCE },
{ NULL, 0 },
@@ -74,7 +75,7 @@ struct cmd_lookup {
static u_int32_t config = 0;
-static const char rcsid[] = "$Id: parse.c,v 1.22 2010/03/28 20:18:26 pbug Exp $";
+static const char rcsid[] = "$Id: parse.c,v 1.23 2010/04/01 20:05:04 pbug Exp $";
/*
* PARSE_FILE - parse the configfile XXX rewrite me in yacc :(
@@ -334,6 +335,14 @@ parse_file(DB *db, char *file)
}
*converted_name = '*';
converted_namelen = 1;
+ } else if (tokenlen == 1 && domainname[0] == '.') {
+ converted_name = (char *)malloc(1);
+ if (converted_name == NULL) {
+ syslog(LOG_INFO, "malloc: %m");
+ exit(1);
+ }
+ *converted_name = '\0';
+ converted_namelen = 1;
} else {
converted_name = dns_label(domainname, &converted_namelen);
if (converted_name == NULL) {
@@ -461,12 +470,13 @@ parse_file(DB *db, char *file)
p = endline;
save = *p;
*p = '\0';
- if (sdomain.a_count < 10) {
+ if (sdomain.a_count < RECORD_COUNT) {
ia = (in_addr_t *) &sdomain.a[sdomain.a_count];
sdomain.a_count++;
} else {
- fprintf(stderr, "too many a records for zone \"%s\", skipping line %d\n", domainname, line);
- break;
+ syslog(LOG_INFO, "too many a records for zone \"%s\", skipping line %d\n", domainname, line);
+ fclose(f);
+ return (-1);
}
@@ -493,12 +503,13 @@ parse_file(DB *db, char *file)
p = endline;
save = *p;
*p = '\0';
- if (sdomain.a_count < 10) {
+ if (sdomain.a_count < RECORD_COUNT) {
ia = (in_addr_t *) &sdomain.a[sdomain.a_count];
sdomain.a_count++;
} else {
- fprintf(stderr, "too many a records for zone \"%s\", skipping line %d\n", domainname, line);
- break;
+ syslog(LOG_INFO, "too many a records for zone \"%s\", skipping line %d\n", domainname, line);
+ fclose(f);
+ return (-1);
}
@@ -522,7 +533,7 @@ parse_file(DB *db, char *file)
p = endline;
save = *p;
*p = 0;
- if (sdomain.aaaa_count < 10) {
+ if (sdomain.aaaa_count < RECORD_COUNT) {
if (sdomain.aaaa[sdomain.aaaa_count] == NULL) {
sdomain.aaaa[sdomain.aaaa_count] = (struct in6_addr *)malloc(sizeof(struct in6_addr));
if (sdomain.aaaa[sdomain.aaaa_count] == NULL) {
@@ -534,8 +545,9 @@ parse_file(DB *db, char *file)
ia6 = (struct in6_addr *)sdomain.aaaa[sdomain.aaaa_count];
sdomain.aaaa_count++;
} else {
- fprintf(stderr, "too many aaaa records for zone \"%s\", skipping line %d\n", domainname, line);
- break;
+ syslog(LOG_INFO, "too many aaaa records for zone \"%s\", skipping line %d\n", domainname, line);
+ fclose(f);
+ return (-1);
}
#ifdef DEBUG
@@ -574,11 +586,12 @@ parse_file(DB *db, char *file)
}
}
- if (sdomain.mx_count < 10) {
+ if (sdomain.mx_count < RECORD_COUNT) {
sdomain.mx[sdomain.mx_count]->preference = atoi(starttoken);
} else {
- fprintf(stderr, "too many mx records for zone \"%s\", skipping line %d\n", domainname, line);
- break;
+ syslog(LOG_INFO, "too many mx records for zone \"%s\", skipping line %d\n", domainname, line);
+ fclose(f);
+ return (-1);
}
*p = save;
@@ -825,11 +838,18 @@ parse_file(DB *db, char *file)
break;
case DNS_TYPE_NS:
+ case DNS_TYPE_HINT:
case DNS_TYPE_DELEGATE:
p = endline;
save = *p;
*p = 0;
+ if (sdomain.ns_count >= RECORD_COUNT) {
+ syslog(LOG_INFO, "too many ns records for zone \"%s\", skipping line %d\n", domainname, line);
+ fclose(f);
+ return (-1);
+ }
+
if (sdomain.ns[sdomain.ns_count] == NULL) {
sdomain.ns[sdomain.ns_count] = (struct ns*)malloc(sizeof(struct ns));
if (sdomain.ns[sdomain.ns_count] == NULL) {
@@ -844,7 +864,7 @@ parse_file(DB *db, char *file)
char *n;
if ((name = dns_label(starttoken, &(sdomain.ns[sdomain.ns_count]->nslen))) == NULL) {
- fprintf(stderr, "illegal mx server, skipping line %d\n", line);
+ fprintf(stderr, "illegal ns server, skipping line %d\n", line);
goto skip;
}
n = (char *)sdomain.ns[sdomain.ns_count]->nsserver;
@@ -854,15 +874,17 @@ parse_file(DB *db, char *file)
}
sdomain.ns_count++;
-
+
*p = save;
sdomain.ns_ptr = 0;
if (type == DNS_TYPE_DELEGATE)
- sdomain.ns_delegate = 1;
+ sdomain.ns_type = NS_TYPE_DELEGATE;
+ else if (type == DNS_TYPE_HINT)
+ sdomain.ns_type = NS_TYPE_HINT;
else
- sdomain.ns_delegate = 0;
+ sdomain.ns_type = 0;
sdomain.flags |= DOMAIN_HAVE_NS;
break;
blob - f86de02b0dd340cbf6d7106de51b6de5a76d08e3
blob + 6efb93559ff0284bc143dff749afccac649b82c6
--- reply.c
+++ reply.c
@@ -67,7 +67,7 @@ struct collects {
} *cn1, *cn2, *cnp;
-static const char rcsid[] = "$Id: reply.c,v 1.20 2010/03/28 20:18:26 pbug Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.21 2010/04/01 20:05:04 pbug Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -192,7 +192,7 @@ reply_a(struct sreply *sreply, DB *db)
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (a_count < 10 && --sd->a_count);
+ } while (a_count < RECORD_COUNT && --sd->a_count);
if (ttlhack) {
odh->answer = htons(a_count);
@@ -330,7 +330,7 @@ reply_aaaa(struct sreply *sreply, DB *db)
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (aaaa_count < 10 && --sd->aaaa_count);
+ } while (aaaa_count < RECORD_COUNT && --sd->aaaa_count);
out:
if (istcp) {
@@ -478,7 +478,7 @@ reply_mx(struct sreply *sreply, DB *db)
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (++mx_count < 10 && --sd->mx_count);
+ } while (++mx_count < RECORD_COUNT && --sd->mx_count);
/* write additional */
@@ -549,6 +549,7 @@ reply_ns(struct sreply *sreply, DB *db)
struct dns_header *odh;
struct domain *sd0;
int outlen;
+ int tmplen;
int ns_count;
int mod, pos;
u_int16_t *plen;
@@ -596,20 +597,28 @@ reply_ns(struct sreply *sreply, DB *db)
SET_DNS_REPLY(odh);
- if (sd->ns_delegate == 0)
+ switch (sd->ns_type) {
+ case 0:
SET_DNS_AUTHORITATIVE(odh);
- else
+ break;
+ default:
SET_DNS_RECURSION(odh);
+ break;
+ }
+
HTONS(odh->query);
odh->question = htons(1);
- if (sd->ns_delegate == 0) {
- odh->answer = htons(sd->ns_count);
- odh->nsrr = 0;
- } else {
+ switch (sd->ns_type) {
+ case NS_TYPE_DELEGATE:
odh->answer = 0;
odh->nsrr = htons(sd->ns_count);
+ break;
+ default:
+ odh->answer = htons(sd->ns_count);
+ odh->nsrr = 0;
+ break;
}
odh->additional = 0;
@@ -671,7 +680,15 @@ reply_ns(struct sreply *sreply, DB *db)
outlen += (12 + namelen);
+ /* compress the label if possible */
+ if ((tmplen = compress_label(reply, outlen, namelen)) > 0) {
+ /* XXX */
+ outlen = tmplen;
+ }
+ answer->rdlength = htons(&reply[outlen] - &answer->ns);
+
+
/* can we afford to write another header? if no truncate */
if (sd->ns_count > 1 && (outlen + 12 + sd->ns[pos % mod]->nslen) > DNS_MAXUDP) {
NTOHS(odh->query);
@@ -680,11 +697,10 @@ reply_ns(struct sreply *sreply, DB *db)
goto out;
}
- ns_count++;
pos++;
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (++ns_count < 10 && --sd->ns_count);
+ } while (++ns_count < RECORD_COUNT && --sd->ns_count);
/* shuffle through our linked collect structure and add additional */
repomaster@centroid.eu