Commit Diff
Diff:
3553d5f311ff8d924ddbff45b28310969a69917b
8bd942da4f99292a4fcdc1b14b5a5669101fdd7e
Commit:
8bd942da4f99292a4fcdc1b14b5a5669101fdd7e
Tree:
92f5f1c39a3043930a1d562a4973fcc17652951d
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Sun Sep 26 14:01:15 2010 UTC
Message:
* mx recurse support tested on OpenBSD
blob - f399b21c518248bcf75986dbd5b8064f4e3075a1
blob + f978eff5d07f95a8b71e3c23fcc4a0ac81c24134
--- recurse.c
+++ recurse.c
@@ -53,6 +53,7 @@ extern void build_reply(struct sreply *reply, int so,
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_nxdomain(struct sreply *);
extern void reply_ptr(struct sreply *);
extern int memcasecmp(u_char *, u_char *, int);
@@ -72,7 +73,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.22 2010/09/26 11:08:37 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.23 2010/09/26 14:01:15 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -818,6 +819,7 @@ recurse_parse(DB *db, struct recurses *sr, u_char *buf
u_int i, j, k;
u_int16_t *compressor;
u_int16_t c;
+ u_int16_t *preference;
int found = 0;
@@ -1221,6 +1223,7 @@ again:
p++;
break;
case DNS_TYPE_MX:
+ preference = (u_int16_t *)p;
p += sizeof(u_int16_t); /* mx_priority */
/* FALLTHROUGH */
case DNS_TYPE_NS:
@@ -1261,6 +1264,15 @@ again:
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_NS) {
update = 1;
for (j = 0; j < sdomain.ns_count; j++) {
@@ -1315,6 +1327,57 @@ again:
if (rrcount[pointer] == 0)
pointer++;
+ } else if (ntohs(a->type) == DNS_TYPE_MX) {
+ update = 1;
+ for (j = 0; j < sdomain.mx_count; j++) {
+ if (memcmp(sdomain.mx[j]->exchange, converted_name[i], cn_len[i]) == 0) {
+ update = 0;
+ }
+ }
+
+ if (j >= RECORD_COUNT) {
+ syslog(LOG_INFO, "db can't hold any more records\n");
+ update = 0;
+ }
+
+ if (update) {
+ sdomain.mx[j] = malloc(sizeof(struct smx));
+ if (sdomain.mx[j] == NULL) {
+ syslog(LOG_ERR, "malloc: %m");
+ return (-1);
+ }
+
+ memcpy(&sdomain.mx[j]->exchange, converted_name[i], cn_len[i]);
+ sdomain.mx[j]->exchangelen = cn_len[i];
+ sdomain.mx[j]->preference = ntohs(*preference);
+
+ sdomain.mx_count++;
+ sdomain.mx_ptr = 0;
+ sdomain.flags |= DOMAIN_HAVE_MX;
+ 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 0
+ syslog(LOG_DEBUG, "updateing zone %s with MX name %s ttl= %u\n", converted_name[i - 1], converted_name[i], sdomain.ttl);
+#endif
+ }
+ } /* if update */
+ if (pointer > 2) {
+ syslog(LOG_ERR, "there is more records than indicated in the header!!!");
+ return (-1);
+ }
+
+ rrcount[pointer]--;
+#if 0
+ if (pointer == 1) /* authoritative */
+ sr->authoritative = DNS_TYPE_MX;
+#endif
+ if (rrcount[pointer] == 0)
+ pointer++;
+
} /* if type ns */
p++; /* one more */
@@ -1658,6 +1721,9 @@ reply_raw(DB *db, struct recurses *sr, struct domain *
break;
case DNS_TYPE_PTR:
reply_ptr(&sreply);
+ break;
+ case DNS_TYPE_MX:
+ reply_mx(&sreply, db);
break;
default:
syslog(LOG_ERR, "other types have not been implemented yet");
blob - f75e329a8257142b6fca4b7e8f9e398562c84156
blob + 117dc14a6d668e8ab56011677affa873ccde7597
--- reply.c
+++ reply.c
@@ -75,7 +75,7 @@ struct collects {
} *cn1, *cn2, *cnp;
-static const char rcsid[] = "$Id: reply.c,v 1.33 2010/09/26 11:08:37 pbug Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.34 2010/09/26 14:01:16 pbug Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -428,7 +428,11 @@ reply_mx(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);
@@ -447,7 +451,10 @@ reply_mx(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);
answer->rdlength = htons(sizeof(u_int16_t) + sd->mx[mx_count]->exchangelen);
@@ -535,24 +542,28 @@ reply_mx(struct sreply *sreply, DB *db)
}
out:
- 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);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
- syslog(LOG_INFO, "send: %m");
- }
- free(tmpbuf);
+ if (sreply->sr != NULL) {
+ reply_raw2(so, reply, outlen, sreply->sr);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
- syslog(LOG_INFO, "sendto: %m");
+ 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);
+ 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