Commit Diff
Diff:
dbd9100e293bdccffbcd52128add650688c0e459
fe3d3220bb9078aa22b0b439a6770036643baf96
Commit:
fe3d3220bb9078aa22b0b439a6770036643baf96
Tree:
2f73115a326c0f5f56ccf7aa5a9ab2c882e51caf
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Tue Sep 21 18:58:06 2010 UTC
Message:
* remove_zone function, note wildcarddnsd has a bug and is broken in the recurse function
blob - 282727a42f70b64f7f4bdc01714bd72c963f7447
blob + ec2a2521adf94315bb1ef9dd1c6561a3d042f3fd
--- recurse.c
+++ recurse.c
@@ -49,6 +49,7 @@ int fakerecurse(DB *db, struct recurses *sr, struct ns
void reply_raw(DB *db, struct recurses *sr, struct domain *sd, int *raw);
extern void build_reply(struct sreply *reply, int so, char *buf, int len, struct question *q, struct sockaddr *sa, socklen_t slen, struct domain *sd1, struct domain *sd2, u_int8_t region, int istcp, int wildcard, struct recurses *sr);
extern void reply_a(struct sreply *, DB *);
+void remove_zone(DB *db, struct domain *sd);
SLIST_HEAD(listhead, recurseentry) recursehead;
@@ -62,7 +63,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.11 2010/09/19 17:53:52 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.12 2010/09/21 18:58:06 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -284,11 +285,24 @@ recurseloop(int sp, int *raw, DB *db)
if (netlookup(db, sr) < 0)
continue;
- syslog(LOG_DEBUG, "adding sr %lx to list\n", (void*)sr);
SLIST_INSERT_HEAD(&recurseshead, sr, entries);
} else {
syslog(LOG_DEBUG, "we had the record in our cache, reply action");
+ /* check if zone is expired */
+ if ((! (sd.flags & DOMAIN_STATIC_ZONE)) &&
+ (sd.created + sd.ttl < time(NULL))) {
+ remove_zone(db, &sd);
+
+ /* continue with netlookup */
+
+ if (netlookup(db, sr) < 0)
+ continue;
+
+ SLIST_INSERT_HEAD(&recurseshead, sr, entries);
+ continue;
+ }
+
reply_raw(db, sr, &sd, raw);
free_question(sr->question);
free(sr);
@@ -388,7 +402,6 @@ remove:
* outstanding...
*/
if (! sr1->hascallback) {
- syslog(LOG_DEBUG, "removing sr %lx from list\n", sr1);
SLIST_REMOVE(&recurseshead, sr1, recurses, entries);
free_question(sr1->question);
free(sr1);
@@ -514,9 +527,12 @@ again:
/*
* If we're not a static zone (like hints) and we're
* expired then we go on to the next indicator..
+ * .. but first we must remove this zone...
*/
if ((! (sd->flags & DOMAIN_STATIC_ZONE)) &&
(time(NULL) > (sd->created + sd->ttl))) {
+
+ remove_zone(db, sd);
if (*p != 0) {
plen -= (*p + 1);
@@ -576,8 +592,6 @@ lookup_a(DB *db, struct recurses *sr, struct ns *ns)
DBT key, data;
struct domain *sd, sdomain;
- in_addr_t tmp;
- char buf[INET_ADDRSTRLEN];
int found = 0;
p = ns->nsserver;
@@ -614,11 +628,6 @@ lookup_a(DB *db, struct recurses *sr, struct ns *ns)
sd->a_count++;
found = 1;
-#if 0
- tmp = sr->a[sr->a_count];
- inet_ntop(AF_INET, (char*)&tmp, (char *)&buf, sizeof(buf));
- syslog(LOG_DEBUG, "address %s\n", buf);
-#endif
}
}
@@ -1345,7 +1354,6 @@ fakerecurse(DB *db, struct recurses *sr, struct ns *ns
return (0);
}
- syslog(LOG_DEBUG, "adding fake sr %lx to list", fakesr);
SLIST_INSERT_HEAD(&recurseshead, fakesr, entries);
return (0);
@@ -1354,7 +1362,6 @@ fakerecurse(DB *db, struct recurses *sr, struct ns *ns
void
reply_raw(DB *db, struct recurses *sr, struct domain *sd, int *raw)
{
- char buf[2048];
int so;
struct sreply sreply;
@@ -1372,6 +1379,14 @@ reply_raw(DB *db, struct recurses *sr, struct domain *
return;
}
+ switch (sr->proto) {
+ case IPPROTO_UDP:
+ break;
+ default:
+ syslog(LOG_ERR, "reply_raw(): can't do any protocol other than udp right now");
+ return;
+ }
+
build_reply(&sreply, so, sr->query, sr->len, sr->question, NULL, 0, sd, NULL, 0xff, 0, 0, sr);
switch (ntohs(sr->question->hdr->qtype)) {
@@ -1384,4 +1399,63 @@ reply_raw(DB *db, struct recurses *sr, struct domain *
}
return;
+}
+
+/*
+ * REMOVE_ZONE - remove a zone from the database (it probably expired)
+ *
+ *
+ */
+
+void
+remove_zone(DB *db, struct domain *sd)
+{
+ DBT key;
+ char *zone;
+ int zonelen;
+ int i;
+
+ zone = sd->zone;
+ zonelen = sd->zonelen;
+
+ if (sd->zonename != NULL)
+ free(sd->zonename);
+
+ if ((sd->flags & DOMAIN_HAVE_SOA) == DOMAIN_HAVE_SOA) {
+ free(sd->soa);
+ }
+ if ((sd->flags & DOMAIN_HAVE_AAAA) == DOMAIN_HAVE_AAAA) {
+ for (i = 0; i < sd->aaaa_count; i++)
+ free(sd->aaaa[i]);
+ }
+ if ((sd->flags & DOMAIN_HAVE_MX) == DOMAIN_HAVE_MX) {
+ for (i = 0; i < sd->mx_count; i++)
+ free(sd->mx[i]);
+ }
+ if ((sd->flags & DOMAIN_HAVE_NS) == DOMAIN_HAVE_NS) {
+ for (i = 0; i < sd->ns_count; i++)
+ free(sd->ns[i]);
+ }
+ if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
+ free(sd->cname);
+ }
+ if ((sd->flags & DOMAIN_HAVE_PTR) == DOMAIN_HAVE_PTR) {
+ free(sd->ptr);
+ }
+ if ((sd->flags & DOMAIN_HAVE_TXT) == DOMAIN_HAVE_TXT) {
+ free(sd->txt);
+ }
+
+ key.data = (char *)zone;
+ key.size = zonelen;
+
+ if (db->del(db, &key, 0) != 0) {
+ syslog(LOG_ERR, "could not delete zone %s: %m", zone);
+ }
+
+ syslog(LOG_DEBUG, "deleting zone %s\n", zone);
+
+ free(zone);
+
+ return;
}
repomaster@centroid.eu