Commit Diff
Diff:
540c2bc2b7a1f78d6a5a44c042e549d799bfea3f
33a0a60db7cb8c2f6d47e03788dddf9e638c9d5c
Commit:
33a0a60db7cb8c2f6d47e03788dddf9e638c9d5c
Tree:
428074a930509ee49c43a83eb163feb8b1951e4d
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Tue Nov 3 17:03:54 2009 UTC
Message:
* merge the ROUNDROBIN tree into BETA_2/HEAD, the TTLPATCH branch is broken from merging by now just as a reminder. * A, AAAA and NS records now do round-robin'ing of records. This could slow down wildcarddnsd a little bit.
blob - 76e264beafc23654f4b7cb00fb4ccd78246967f0
blob + ef3237c1992db2abadf0ad1b7acb3f3d7c04f23f
--- db.h
+++ db.h
@@ -61,6 +61,7 @@ struct ns {
struct domain {
char zone[DNS_MAXNAME]; /* name of zone in dns name format */
+ int zonelen; /* length of zone, above */
char zonename[DNS_MAXNAME + 1]; /* name of zone in human readable */
u_int16_t flags; /* flags of zone */
#define DOMAIN_HAVE_A 0x1
blob - 8105052a2ec4c1458c583b0e11c9cc81fa0faa17
blob + 88b2eff8bb5a515ac6d6ff859be3151cde83684f
--- main.c
+++ main.c
@@ -42,13 +42,13 @@ extern void reply_notimpl(struct sreply *);
extern void reply_nxdomain(struct sreply *);
extern void reply_noerror(struct sreply *);
extern void reply_fmterror(struct sreply *);
-extern void reply_a(struct sreply *);
-extern void reply_aaaa(struct sreply *);
+extern void reply_a(struct sreply *, DB *);
+extern void reply_aaaa(struct sreply *, DB *);
extern void reply_soa(struct sreply *);
extern void reply_ptr(struct sreply *);
extern void reply_cname(struct sreply *);
extern void reply_mx(struct sreply *);
-extern void reply_ns(struct sreply *);
+extern void reply_ns(struct sreply *, DB *);
char * dns_label(char *, int *);
int compress_label(char *, int, int);
int memcasecmp(char *, char *, int);
@@ -82,7 +82,7 @@ extern char *__progname;
static int Wflag = 0;
static int lflag = 0;
-static const char rcsid[] = "$Id: main.c,v 1.27 2009/10/24 18:41:04 pbug Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.28 2009/11/03 17:03:54 pbug Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -673,7 +673,7 @@ nxdomain:
reply_cname(&sreply);
} else if (type0 == DNS_TYPE_A) {
BUILD_REPLY(sreply, so, buf, len, question, from, fromlen, &sd0, NULL);
- reply_a(&sreply);
+ reply_a(&sreply, db);
break; /* must break here */
}
@@ -685,7 +685,7 @@ nxdomain:
reply_cname(&sreply);
} else if (type0 == DNS_TYPE_AAAA) {
BUILD_REPLY(sreply, so, buf, len, question, from, fromlen, &sd0, NULL);
- reply_aaaa(&sreply);
+ reply_aaaa(&sreply, db);
break; /* must break here */
}
@@ -711,7 +711,7 @@ nxdomain:
case DNS_TYPE_NS:
if (type0 == DNS_TYPE_NS) {
BUILD_REPLY(sreply, so, buf, len, question, from, fromlen, &sd0, NULL);
- reply_ns(&sreply);
+ reply_ns(&sreply, db);
}
break;
blob - 9967a16270e82bc0a3c3bd5c6a5d1d707efcf29a
blob + ef1bd4e3ae7ae91d5f0fb52c5773e9bbad9bc4ac
--- parse.c
+++ parse.c
@@ -45,7 +45,7 @@ struct myrr_lookup {
{ NULL, 0 },
};
-static const char rcsid[] = "$Id: parse.c,v 1.15 2009/10/24 18:41:04 pbug Exp $";
+static const char rcsid[] = "$Id: parse.c,v 1.16 2009/11/03 17:03:54 pbug Exp $";
/*
* PARSE_FILE - parse the configfile XXX rewrite me in yacc :(
@@ -335,6 +335,7 @@ parse_file(DB *db, char *file)
*p = save;
+ sdomain.a_ptr = 0;
sdomain.flags |= DOMAIN_HAVE_A;
break;
case DNS_TYPE_AAAA:
@@ -360,6 +361,7 @@ parse_file(DB *db, char *file)
*p = save;
+ sdomain.aaaa_ptr = 0;
sdomain.flags |= DOMAIN_HAVE_AAAA;
break;
case DNS_TYPE_MX:
@@ -630,6 +632,7 @@ parse_file(DB *db, char *file)
*p = save;
+ sdomain.ns_ptr = 0;
sdomain.flags |= DOMAIN_HAVE_NS;
break;
@@ -667,6 +670,9 @@ parse_file(DB *db, char *file)
key.data = (char *)converted_name;
key.size = converted_namelen;
+
+ memcpy(sdomain.zone, converted_name, converted_namelen);
+ sdomain.zonelen = converted_namelen;
data.data = (void *)&sdomain;
data.size = sizeof(struct domain);
blob - 7ed8f9d21e90311f84db5964cb8c0254c7500197
blob + d77cacda159760a31269ec6fb83ad2e54a934c73
--- reply.c
+++ reply.c
@@ -29,10 +29,10 @@
#include "dns.h"
#include "db.h"
-void reply_a(struct sreply *);
-void reply_aaaa(struct sreply *);
+void reply_a(struct sreply *, DB *);
+void reply_aaaa(struct sreply *, DB *);
void reply_mx(struct sreply *);
-void reply_ns(struct sreply *);
+void reply_ns(struct sreply *, DB *);
void reply_notimpl(struct sreply *);
void reply_nxdomain(struct sreply *);
void reply_noerror(struct sreply *);
@@ -47,20 +47,23 @@ extern int additional_aaaa(char *, int, struct domain
extern int additional_mx(char *, int, struct domain *, char *, int, int, int *);
extern int additional_ptr(char *, int, struct domain *, char *, int, int, int *);
-static const char rcsid[] = "$Id: reply.c,v 1.10 2009/10/24 18:41:04 pbug Exp $";
+void update_db(DB *, struct domain *);
+static const char rcsid[] = "$Id: reply.c,v 1.11 2009/11/03 17:03:54 pbug Exp $";
+
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
*
*/
void
-reply_a(struct sreply *sreply)
+reply_a(struct sreply *sreply, DB *db)
{
char reply[512];
struct dns_header *odh;
int outlen;
int a_count;
+ int mod, pos;
struct answer {
char name[2];
@@ -113,6 +116,9 @@ reply_a(struct sreply *sreply)
q->hdr->namelen + 4);
a_count = 0;
+ pos = sd->a_ptr;
+ mod = sd->a_count;
+
do {
/*
* answer->name is a pointer to the request (0xc00c)
@@ -126,8 +132,10 @@ reply_a(struct sreply *sreply)
answer->rdlength = htons(sizeof(in_addr_t)); /* 12 bytes */
- memcpy((char *)&answer->rdata, (char *)&sd->a[a_count++],
+ memcpy((char *)&answer->rdata, (char *)&sd->a[pos++ % mod],
sizeof(in_addr_t)); /* 16 bytes */
+
+ a_count++;
outlen += 16;
/* can we afford to write another header? if no truncate */
@@ -147,6 +155,14 @@ out:
syslog(LOG_INFO, "sendto: %m");
}
+ /*
+ * update a_ptr setting
+ */
+
+ sd->a_ptr = (sd->a_ptr + 1) % mod;
+ sd->a_count = mod; /* I know I know */
+ update_db(db, sd);
+
return;
}
@@ -156,12 +172,13 @@ out:
*/
void
-reply_aaaa(struct sreply *sreply)
+reply_aaaa(struct sreply *sreply, DB *db)
{
char reply[512];
struct dns_header *odh;
int outlen;
int aaaa_count;
+ int mod, pos;
struct answer {
char name[2];
@@ -214,6 +231,8 @@ reply_aaaa(struct sreply *sreply)
q->hdr->namelen + 4);
aaaa_count = 0;
+ pos = sd->aaaa_ptr;
+ mod = sd->aaaa_count;
do {
answer->name[0] = 0xc0;
@@ -224,7 +243,7 @@ reply_aaaa(struct sreply *sreply)
answer->rdlength = htons(sizeof(struct in6_addr));
- memcpy((char *)&answer->rdata, (char *)&sd->aaaa[aaaa_count++], sizeof(struct in6_addr));
+ memcpy((char *)&answer->rdata, (char *)&sd->aaaa[pos++ % mod], sizeof(struct in6_addr));
outlen += 28;
/* can we afford to write another header? if no truncate */
@@ -235,6 +254,8 @@ reply_aaaa(struct sreply *sreply)
goto out;
}
+ aaaa_count++;
+
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
} while (aaaa_count < 10 && --sd->aaaa_count);
@@ -244,6 +265,10 @@ out:
syslog(LOG_INFO, "sendto: %m");
}
+ sd->aaaa_ptr = (sd->aaaa_ptr + 1) % mod;
+ sd->aaaa_count = mod;
+ update_db(db, sd);
+
return;
}
@@ -347,12 +372,13 @@ out:
*/
void
-reply_ns(struct sreply *sreply)
+reply_ns(struct sreply *sreply, DB *db)
{
char reply[512];
struct dns_header *odh;
int outlen;
int ns_count;
+ int mod, pos;
struct answer {
char name[2];
@@ -404,6 +430,9 @@ reply_ns(struct sreply *sreply)
q->hdr->namelen + 4);
ns_count = 0;
+ mod = sd->ns_count;
+ pos = sd->ns_ptr;
+
do {
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
@@ -411,19 +440,22 @@ reply_ns(struct sreply *sreply)
answer->class = q->hdr->qclass;
answer->ttl = htonl(sd->ttl);
- answer->rdlength = htons(sd->ns[ns_count].nslen);
+ answer->rdlength = htons(sd->ns[pos % mod].nslen);
- memcpy((char *)&answer->ns, (char *)&sd->ns[ns_count].nsserver, sd->ns[ns_count].nslen);
- outlen += (12 + sd->ns[ns_count].nslen);
+ memcpy((char *)&answer->ns, (char *)&sd->ns[pos % mod].nsserver, sd->ns[pos % mod].nslen);
+ outlen += (12 + sd->ns[pos % mod].nslen);
+
/* can we afford to write another header? if no truncate */
- if (sd->ns_count > 1 && (outlen + 12 + sd->ns[ns_count].nslen) > DNS_MAXUDP) {
+ if (sd->ns_count > 1 && (outlen + 12 + sd->ns[pos % mod].nslen) > DNS_MAXUDP) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
goto out;
}
+ ns_count++;
+ pos++;
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
} while (++ns_count < 10 && --sd->ns_count);
@@ -433,6 +465,11 @@ out:
syslog(LOG_INFO, "sendto: %m");
}
+ sd->ns_ptr = (sd->ns_ptr + 1) % mod;
+ sd->ns_count = mod;
+
+ update_db(db, sd);
+
return;
}
@@ -1380,4 +1417,28 @@ reply_noerror(struct sreply *sreply)
}
return;
+}
+
+void
+update_db(DB *db, struct domain *sd)
+{
+ int ret;
+ DBT key, data;
+
+
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+
+ key.data = sd->zone;
+ key.size = sd->zonelen;
+
+ data.data = (char *)sd;
+ data.size = sizeof(struct domain);
+
+#if DB_VERSION_MAJOR > 3
+ /* XXX */
+ ret = db->put(db, NULL, &key, &data, 0);
+#else
+ ret = db->put(db, &key, &data, 0) ;
+#endif
}
repomaster@centroid.eu