Commit Diff
Diff:
09fdca2378471d8cff1156f65973c7c0f10a6719
8c01150efc2749507593f662295f2f37b4ea51a6
Commit:
8c01150efc2749507593f662295f2f37b4ea51a6
Tree:
bee912fa4f52363cab1344af2d996c2f43bbccba
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Sat Sep 25 16:07:07 2010 UTC
Message:
* recursive queries now do AAAA records tested on OpenBSD
blob - 3c23cd375ae1362950103ff10d17e4f080f2b2a9
blob + 06ef52d7157aa5f3662e948fa681257c3c1579c7
--- recurse.c
+++ recurse.c
@@ -50,6 +50,7 @@ void reply_raw(DB *db, struct recurses *sr, struct dom
void reply_raw_noerror(DB *, struct recurses *, struct domain *, int *);
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 *);
+extern void reply_aaaa(struct sreply *, DB *);
extern void reply_ns(struct sreply *, DB *);
extern int memcasecmp(u_char *, u_char *, int);
extern int get_soa(DB *, struct question *, struct domain *, int);
@@ -68,7 +69,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.18 2010/09/25 13:18:58 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.19 2010/09/25 16:07:07 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -1112,16 +1113,65 @@ again:
}
p += sizeof(in_addr_t);
+ if (pointer > 2) {
+ syslog(LOG_ERR, "there is more records than indicated in the header!!!");
+ return (-1);
+ }
rrcount[pointer]--;
if (rrcount[pointer] == 0)
pointer++;
+
+ break;
+ case DNS_TYPE_AAAA:
+ /*
+ * scan addresses in this struct domain and check if
+ * this one exists already...
+ */
+
+ update = 1;
+ for (j = 0; j < sdomain.aaaa_count; j++) {
+ if (memcmp(sdomain.aaaa[j], p, sizeof(struct in6_addr)) == 0) {
+#if 0
+ syslog(LOG_INFO, "record exists already");
+#endif
+ update = 0;
+ }
+ }
+
+ if (j >= RECORD_COUNT) {
+ syslog(LOG_INFO, "db can't hold any more records\n");
+ update = 0;
+ }
+
+ if (update) {
+ sdomain.aaaa[j] = malloc(sizeof(struct in6_addr));
+ if (sdomain.aaaa[j] == NULL) {
+ syslog(LOG_ERR, "malloc: %m");
+ return(-1);
+ }
+ memcpy(sdomain.aaaa[j], p, sizeof(struct in6_addr));
+ sdomain.aaaa_count++;
+ sdomain.aaaa_ptr = 0;
+ sdomain.flags |= DOMAIN_HAVE_AAAA;
+ sdomain.flags &= ~(DOMAIN_NEGATIVE_CACHE);
+ sdomain.created = time(NULL);
+ sdomain.ttl = ntohl(a->ttl);
+
+ if (! (sdomain.flags & DOMAIN_STATIC_ZONE)) {
+ update_db(db, &sdomain);
+ inet_ntop(AF_INET6, p, abuf, sizeof(abuf));
+ syslog(LOG_DEBUG, "updateing zone %s with address %s ttl= %u\n", converted_name[i], abuf, sdomain.ttl);
+ }
+ }
+
if (pointer > 2) {
syslog(LOG_ERR, "there is more records than indicated in the header!!!");
return (-1);
}
+ rrcount[pointer]--;
+ if (rrcount[pointer] == 0)
+ pointer++;
- break;
- case DNS_TYPE_AAAA:
p += 16; /* sizeof 4 * 32 bit */
break;
case DNS_TYPE_TXT:
@@ -1191,16 +1241,16 @@ again:
#endif
}
} /* if update */
+ if (pointer > 2) {
+ syslog(LOG_ERR, "there is more records than indicated in the header!!!");
+ return (-1);
+ }
rrcount[pointer]--;
if (pointer == 1) /* authoritative */
sr->authoritative = DNS_TYPE_NS;
if (rrcount[pointer] == 0)
pointer++;
- if (pointer > 2) {
- syslog(LOG_ERR, "there is more records than indicated in the header!!!");
- return (-1);
- }
} /* if type ns */
@@ -1271,16 +1321,17 @@ again:
update_db(db, &sdomain);
}
+ if (pointer > 2) {
+ syslog(LOG_ERR, "there is more records than indicated in the header!!!");
+ return (-1);
+ }
+
rrcount[pointer]--;
if (pointer == 1) /* authoritative */
sr->authoritative = DNS_TYPE_SOA;
if (rrcount[pointer] == 0)
pointer++;
- if (pointer > 2) {
- syslog(LOG_ERR, "there is more records than indicated in the header!!!");
- return (-1);
- }
break;
default:
@@ -1509,6 +1560,9 @@ reply_raw(DB *db, struct recurses *sr, struct domain *
switch (ntohs(sr->question->hdr->qtype)) {
case DNS_TYPE_A:
reply_a(&sreply, db);
+ break;
+ case DNS_TYPE_AAAA:
+ reply_aaaa(&sreply, db);
break;
case DNS_TYPE_NS:
reply_ns(&sreply, db);
blob - 9859bf4eea6beb0854276064e9314550fdec7f2b
blob + 0e5107fe6f24d3ed3b37c31098a15e40e5a4b1e6
--- reply.c
+++ reply.c
@@ -75,7 +75,7 @@ struct collects {
} *cn1, *cn2, *cnp;
-static const char rcsid[] = "$Id: reply.c,v 1.30 2010/09/25 13:18:58 pbug Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.31 2010/09/25 16:07:07 pbug Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -288,7 +288,10 @@ reply_aaaa(struct sreply *sreply, DB *db)
outlen += (q->hdr->namelen + 4);
SET_DNS_REPLY(odh);
- SET_DNS_AUTHORITATIVE(odh);
+ if (sreply->sr == NULL)
+ SET_DNS_AUTHORITATIVE(odh);
+ else
+ SET_DNS_RECURSION_AVAIL(odh);
HTONS(odh->query);
@@ -311,7 +314,10 @@ reply_aaaa(struct sreply *sreply, DB *db)
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- answer->ttl = htonl(sd->ttl);
+ if (sreply->sr != NULL)
+ answer->ttl = htonl(sd->ttl - (time(NULL) - sd->created));
+ else
+ answer->ttl = htonl(sd->ttl); /* 10 bytes */
answer->rdlength = htons(sizeof(struct in6_addr));
@@ -333,26 +339,30 @@ reply_aaaa(struct sreply *sreply, DB *db)
} while (aaaa_count < RECORD_COUNT && --sd->aaaa_count);
out:
- if (istcp) {
- char *tmpbuf;
- u_int16_t *plen;
+ if (sreply->sr != NULL) {
+ reply_raw2(so, reply, outlen, sreply->sr);
+ } else {
+ if (istcp) {
+ char *tmpbuf;
+ u_int16_t *plen;
- tmpbuf = malloc(outlen + 2);
- if (tmpbuf == NULL) {
- syslog(LOG_INFO, "malloc: %m");
- }
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(outlen);
+ tmpbuf = malloc(outlen + 2);
+ if (tmpbuf == NULL) {
+ syslog(LOG_INFO, "malloc: %m");
+ }
+ plen = (u_int16_t *)tmpbuf;
+ *plen = htons(outlen);
- memcpy(&tmpbuf[2], reply, outlen);
+ memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
- syslog(LOG_INFO, "send: %m");
- }
- free(tmpbuf);
- } else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
- syslog(LOG_INFO, "sendto: %m");
+ if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ syslog(LOG_INFO, "send: %m");
+ }
+ free(tmpbuf);
+ } else {
+ if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ syslog(LOG_INFO, "sendto: %m");
+ }
}
}
repomaster@centroid.eu