Commit Diff
Diff:
8bd942da4f99292a4fcdc1b14b5a5669101fdd7e
b55adb0c8e519c884d80e7ea12a174d5e2dfd5ed
Commit:
b55adb0c8e519c884d80e7ea12a174d5e2dfd5ed
Tree:
f50b8841241210cf5c2e05e3a6f81cdea7c6aba7
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Sun Sep 26 16:20:08 2010 UTC
Message:
* finish all the remaining RR's for recursion * this finishes AF_INET/udp functionality of recursion tested on OpenBSD
blob - f978eff5d07f95a8b71e3c23fcc4a0ac81c24134
blob + 8c7b93bbe1a951a36ef10625c50bc0ff0136f888
--- recurse.c
+++ recurse.c
@@ -47,6 +47,7 @@ int negative_cache(DB *db, struct recurses *sr);
int netlookup(DB *db, struct recurses *sr);
int fakerecurse(DB *db, struct recurses *sr, struct ns *ns);
void reply_raw(DB *db, struct recurses *sr, struct domain *sd, int *raw);
+void reply_raw_cname(DB *db, struct recurses *sr, struct domain *sd, int *raw);
void reply_raw_noerror(DB *, struct recurses *, struct domain *, int *);
void reply_raw_nxdomain(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);
@@ -54,8 +55,11 @@ extern void reply_a(struct sreply *, DB *);
extern void reply_aaaa(struct sreply *, DB *);
extern void reply_ns(struct sreply *, DB *);
extern void reply_mx(struct sreply *, DB *);
+extern void reply_cname(struct sreply *);
extern void reply_nxdomain(struct sreply *);
extern void reply_ptr(struct sreply *);
+extern void reply_soa(struct sreply *);
+extern void reply_txt(struct sreply *sreply);
extern int memcasecmp(u_char *, u_char *, int);
extern int get_soa(DB *, struct question *, struct domain *, int);
extern void reply_noerror(struct sreply *);
@@ -73,7 +77,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.23 2010/09/26 14:01:15 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.24 2010/09/26 16:20:08 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -359,7 +363,11 @@ recurseloop(int sp, int *raw, DB *db)
continue;
}
- reply_raw(db, sr, &sd, raw);
+ if (type == DNS_TYPE_CNAME)
+ reply_raw_cname(db, sr, &sd, raw);
+ else
+ reply_raw(db, sr, &sd, raw);
+
free_question(sr->question);
free(sr);
continue;
@@ -471,10 +479,10 @@ recurseloop(int sp, int *raw, DB *db)
} else {
- reply_raw(db, sr1, &sd, raw);
-#if 0
- syslog(LOG_DEBUG, "record found but no action");
-#endif
+ if (type == DNS_TYPE_CNAME)
+ reply_raw_cname(db, sr, &sd, raw);
+ else
+ reply_raw(db, sr1, &sd, raw);
}
}
remove:
@@ -787,6 +795,7 @@ recurse_parse(DB *db, struct recurses *sr, u_char *buf
int update;
int rrcount[3]; /* RR count answer, authoritative, additional */
int pointer = 0; /* default answer */
+ int txtlen;
char abuf[INET6_ADDRSTRLEN];
@@ -1219,6 +1228,35 @@ again:
p += 16; /* sizeof 4 * 32 bit */
break;
case DNS_TYPE_TXT:
+ txtlen = (*p);
+ sdomain.txt = malloc(txtlen);
+ if (sdomain.txt == NULL) {
+ syslog(LOG_ERR, "malloc: %m");
+ return (-1);
+ }
+
+ memcpy(sdomain.txt, (p + 1), txtlen);
+ sdomain.txtlen = txtlen;
+
+ sdomain.flags |= DOMAIN_HAVE_TXT;
+ sdomain.flags &= ~(DOMAIN_NEGATIVE_CACHE);
+ sdomain.created = time(NULL);
+ sdomain.ttl = ntohl(a->ttl);
+
+ if (! (sdomain.flags & DOMAIN_STATIC_ZONE)) {
+ update_db(db, &sdomain);
+ }
+
+ if (pointer > 2) {
+ syslog(LOG_ERR, "there is more records than indicated in the header!!!");
+ return (-1);
+ }
+
+ rrcount[pointer]--;
+ if (rrcount[pointer] == 0)
+ pointer++;
+
+
p += *p;
p++;
break;
@@ -1242,8 +1280,39 @@ again:
goto end;
}
- if (ntohs(a->type) == DNS_TYPE_PTR) {
+ if (ntohs(a->type) == DNS_TYPE_CNAME) {
+ sdomain.cname = malloc(cn_len[i]);
+ if (sdomain.cname == NULL) {
+ syslog(LOG_ERR, "malloc: %m");
+ return (-1);
+ }
+
+ memcpy(sdomain.cname, converted_name[i], cn_len[i]);
+ sdomain.cnamelen = cn_len[i];
+
+ sdomain.flags |= DOMAIN_HAVE_CNAME;
+ sdomain.flags &= ~(DOMAIN_NEGATIVE_CACHE);
+ sdomain.created = time(NULL);
+ sdomain.ttl = ntohl(a->ttl);
+
+ if (! (sdomain.flags & DOMAIN_STATIC_ZONE)) {
+ update_db(db, &sdomain);
+#if 1
+ syslog(LOG_DEBUG, "updateing zone %s with PTR name %s ttl= %u\n", converted_name[i - 1], converted_name[i], sdomain.ttl);
+#endif
+ }
+
+ if (pointer > 2) {
+ syslog(LOG_ERR, "there is more records than indicated in the header!!!");
+ return (-1);
+ }
+
+ rrcount[pointer]--;
+ if (rrcount[pointer] == 0)
+ pointer++;
+ } else if (ntohs(a->type) == DNS_TYPE_PTR) {
+
sdomain.ptr = malloc(cn_len[i]);
if (sdomain.ptr == NULL) {
syslog(LOG_ERR, "malloc: %m");
@@ -1725,10 +1794,54 @@ reply_raw(DB *db, struct recurses *sr, struct domain *
case DNS_TYPE_MX:
reply_mx(&sreply, db);
break;
+ case DNS_TYPE_SOA:
+ reply_soa(&sreply);
+ break;
+ case DNS_TYPE_CNAME:
+ reply_cname(&sreply);
+ break;
+ case DNS_TYPE_TXT:
+ reply_txt(&sreply);
+ break;
default:
syslog(LOG_ERR, "other types have not been implemented yet");
break;
}
+
+ return;
+}
+
+void
+reply_raw_cname(DB *db, struct recurses *sr, struct domain *sd, int *raw)
+{
+ int so;
+ struct sreply sreply;
+
+ syslog(LOG_DEBUG, "reply_raw called");
+
+ switch (sr->af) {
+ case AF_INET:
+ so = raw[0];
+ break;
+ case AF_INET6:
+ so = raw[1];
+ break;
+ default:
+ syslog(LOG_ERR, "reply_raw_cname(): unknown address family in struct recurses");
+ return;
+ }
+
+ switch (sr->proto) {
+ case IPPROTO_UDP:
+ break;
+ default:
+ syslog(LOG_ERR, "reply_raw_cname(): 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);
+
+ reply_cname(&sreply);
return;
}
blob - 117dc14a6d668e8ab56011677affa873ccde7597
blob + 5f4d27804cdf07340788a6cdaa69da8c5c00d9fd
--- reply.c
+++ reply.c
@@ -38,6 +38,7 @@ void reply_nxdomain(struct sreply *);
void reply_noerror(struct sreply *);
void reply_soa(struct sreply *);
void reply_ptr(struct sreply *);
+void reply_txt(struct sreply *sreply);
void reply_cname(struct sreply *);
void reply_fmterror(struct sreply *);
void reply_raw2(int so, char *reply, int outlen, struct recurses *sr);
@@ -75,7 +76,7 @@ struct collects {
} *cn1, *cn2, *cnp;
-static const char rcsid[] = "$Id: reply.c,v 1.34 2010/09/26 14:01:16 pbug Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.35 2010/09/26 16:20:08 pbug Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -778,7 +779,6 @@ out:
if (sreply->sr != NULL) {
reply_raw2(so, reply, outlen, sreply->sr);
} else {
-
if (istcp) {
char *tmpbuf;
@@ -867,7 +867,10 @@ reply_cname(struct sreply *sreply)
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);
@@ -883,7 +886,10 @@ reply_cname(struct sreply *sreply)
answer->name[1] = 0x0c;
answer->type = htons(DNS_TYPE_CNAME);
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);
outlen += 12; /* up to rdata length */
@@ -954,26 +960,30 @@ reply_cname(struct sreply *sreply)
HTONS(odh->answer);
}
- if (istcp) {
- char *tmpbuf;
+ if (sreply->sr != NULL) {
+ reply_raw2(so, reply, outlen, sreply->sr);
+ } else {
+ if (istcp) {
+ char *tmpbuf;
- 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);
+ 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);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
- syslog(LOG_INFO, "send: %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");
+ }
}
- free(tmpbuf);
- } else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
- syslog(LOG_INFO, "sendto: %m");
- }
}
return;
@@ -1181,7 +1191,10 @@ reply_soa(struct sreply *sreply)
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);
NTOHS(odh->query);
@@ -1197,17 +1210,15 @@ reply_soa(struct sreply *sreply)
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);
outlen += 12; /* up to rdata length */
p = (char *)&answer->rdata;
-#if 0
- label = dns_label((char *)mysoa->nsserver, &labellen);
- if (label == NULL)
- return;
-#endif
label = sd->soa->nsserver;
labellen = sd->soa->nsserver_len;
@@ -1297,27 +1308,31 @@ reply_soa(struct sreply *sreply)
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
- 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);
-
- memcpy(&tmpbuf[2], reply, 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);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
- syslog(LOG_INFO, "send: %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");
+ }
}
- free(tmpbuf);
- } else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
- syslog(LOG_INFO, "sendto: %m");
- }
}
return;
@@ -1374,7 +1389,10 @@ reply_txt(struct sreply *sreply)
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);
@@ -1390,7 +1408,10 @@ reply_txt(struct sreply *sreply)
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);
outlen += 12; /* up to rdata length */
@@ -1402,26 +1423,30 @@ reply_txt(struct sreply *sreply)
answer->rdlength = htons(sd->txtlen + 1);
- 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);
-
- memcpy(&tmpbuf[2], reply, 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);
- 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