Commit Diff
Diff:
8c01150efc2749507593f662295f2f37b4ea51a6
df7b3e7ec2269218f81a92cfbee08be708965636
Commit:
df7b3e7ec2269218f81a92cfbee08be708965636
Tree:
43907f03e86580bbf0d6aa11225a2b710bdf4b77
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Sat Sep 25 19:31:55 2010 UTC
Message:
* nxdomain stuff should work now tested on OpenBSD
blob - 06ef52d7157aa5f3662e948fa681257c3c1579c7
blob + 4a7cebf061fdf96d3390ee3d9030016803db94e7
--- recurse.c
+++ recurse.c
@@ -48,10 +48,12 @@ 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_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);
extern void reply_a(struct sreply *, DB *);
extern void reply_aaaa(struct sreply *, DB *);
extern void reply_ns(struct sreply *, DB *);
+extern void reply_nxdomain(struct 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 *);
@@ -69,7 +71,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.19 2010/09/25 16:07:07 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.20 2010/09/25 19:31:55 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -306,6 +308,16 @@ recurseloop(int sp, int *raw, DB *db)
type = lookup_zone(db, sr->question, &sd, &lzerrno, (char *)fakereplystring, wildcard);
if (type < 0) {
+ if (lzerrno == ERR_NOERROR &&
+ (sd.flags & DOMAIN_NEGATIVE_CACHE) ==
+ DOMAIN_NEGATIVE_CACHE) {
+
+ reply_raw_nxdomain(db, sr, &sd, raw);
+ free_question(sr->question);
+ free(sr);
+ continue;
+
+ }
if (netlookup(db, sr) < 0)
continue;
@@ -383,6 +395,7 @@ recurseloop(int sp, int *raw, DB *db)
negative_cache(db, sr1);
syslog(LOG_DEBUG, "added negative cache for domain \"%s\"", sr1->question->converted_name);
/* reply negatively */
+ reply_raw_nxdomain(db, sr1, &sd, raw);
goto remove;
}
@@ -1669,6 +1682,41 @@ reply_raw_noerror(DB *db, struct recurses *sr, struct
build_reply(&sreply, so, sr->query, sr->len, sr->question, NULL, 0, sd, NULL, 0xff, 0, 0, sr);
reply_noerror(&sreply);
+
+ return;
+}
+
+void
+reply_raw_nxdomain(DB *db, struct recurses *sr, struct domain *sd, int *raw)
+{
+ int so;
+ struct sreply sreply;
+
+ syslog(LOG_DEBUG, "reply_raw_nxdomain called");
+
+ switch (sr->af) {
+ case AF_INET:
+ so = raw[0];
+ break;
+ case AF_INET6:
+ so = raw[1];
+ break;
+ default:
+ syslog(LOG_ERR, "reply_raw_nxdomain(): unknown address family in struct recurses");
+ return;
+ }
+
+ switch (sr->proto) {
+ case IPPROTO_UDP:
+ break;
+ default:
+ syslog(LOG_ERR, "reply_raw_nxdomain(): 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_nxdomain(&sreply);
return;
}
blob - 0e5107fe6f24d3ed3b37c31098a15e40e5a4b1e6
blob + 01ba91f9c8b4ffc1ddc27e724850614a3b007553
--- reply.c
+++ reply.c
@@ -75,7 +75,7 @@ struct collects {
} *cn1, *cn2, *cnp;
-static const char rcsid[] = "$Id: reply.c,v 1.31 2010/09/25 16:07:07 pbug Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.32 2010/09/25 19:31:55 pbug Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -1541,30 +1541,41 @@ reply_nxdomain(struct sreply *sreply)
memset((char *)&odh->query, 0, sizeof(u_int16_t));
SET_DNS_REPLY(odh);
+#if 1
+ if (sreply->sr != NULL) {
+ SET_DNS_RECURSION_AVAIL(odh);
+ }
+#endif
SET_DNS_RCODE_NAMEERR(odh);
+
+
HTONS(odh->query);
- if (istcp) {
- char *tmpbuf;
- u_int16_t *plen;
+ if (sreply->sr != NULL) {
+ reply_raw2(so, reply, len, sreply->sr);
+ } else {
+ if (istcp) {
+ char *tmpbuf;
+ u_int16_t *plen;
- tmpbuf = malloc(len + 2);
- if (tmpbuf == NULL) {
- syslog(LOG_INFO, "malloc: %m");
- }
- plen = (u_int16_t *)tmpbuf;
- *plen = htons(len);
-
- memcpy(&tmpbuf[2], reply, len);
+ tmpbuf = malloc(len + 2);
+ if (tmpbuf == NULL) {
+ syslog(LOG_INFO, "malloc: %m");
+ }
+ plen = (u_int16_t *)tmpbuf;
+ *plen = htons(len);
+
+ memcpy(&tmpbuf[2], reply, len);
- if (send(so, tmpbuf, len + 2, 0) < 0) {
- syslog(LOG_INFO, "send: %m");
+ if (send(so, tmpbuf, len + 2, 0) < 0) {
+ syslog(LOG_INFO, "send: %m");
+ }
+ free(tmpbuf);
+ } else {
+ if (sendto(so, reply, len, 0, sa, salen) < 0) {
+ syslog(LOG_INFO, "sendto: %m");
+ }
}
- free(tmpbuf);
- } else {
- if (sendto(so, reply, len, 0, sa, salen) < 0) {
- syslog(LOG_INFO, "sendto: %m");
- }
}
return;
@@ -1578,7 +1589,11 @@ reply_nxdomain(struct sreply *sreply)
outlen += (q->hdr->namelen + 4);
SET_DNS_REPLY(odh);
- SET_DNS_AUTHORITATIVE(odh);
+ if (sreply->sr != NULL)
+ SET_DNS_RECURSION_AVAIL(odh);
+ else
+ SET_DNS_AUTHORITATIVE(odh);
+
SET_DNS_RCODE_NAMEERR(odh);
NTOHS(odh->query);
@@ -1595,7 +1610,10 @@ reply_nxdomain(struct sreply *sreply)
answer->name[1] = 0x0c;
answer->type = htons(DNS_TYPE_SOA);
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 */
@@ -1693,29 +1711,34 @@ reply_nxdomain(struct sreply *sreply)
outlen += sizeof(sd->soa->minttl);
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
+
+ if (sreply->sr != NULL) {
+ reply_raw2(so, reply, outlen, sreply->sr);
+ } else {
- if (istcp) {
- char *tmpbuf;
- u_int16_t *plen;
+ 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");
- }
- }
+ } /* sreply->sr.. */
return;
}
repomaster@centroid.eu