Commit Diff
Diff:
c77ce611686712e63160be345fccf8295ea5e05b
c5217a156b00c90d3e7abbdf7893460a757f56be
Commit:
c5217a156b00c90d3e7abbdf7893460a757f56be
Tree:
08d9ae5d11a7c1a93cbb039412bd946f522a15b5
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Fri Feb 15 15:11:34 2019 UTC
Message:
big commit replacing the database with 3G DB (3rd generation database). This has the benefit of using a lot less virtual size allowing for a lot of data. The dddctl query was tuned to be faster than dig in axfr. Please do not use this for a couple of days (best wait a week) for me to catch fallout. Tested on OpenBSD in lab.
blob - 3fc0b9715d4205c683c7bf0101737bf77016ad60
blob + b95076ce3131f586d39f4987eb616e2f5ec8808d
--- additional.c
+++ additional.c
@@ -27,24 +27,26 @@
*/
/*
- * $Id: additional.c,v 1.18 2018/10/19 08:24:48 pjp Exp $
+ * $Id: additional.c,v 1.19 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
#include "ddd-dns.h"
#include "ddd-db.h"
-int additional_a(char *, int, struct domain *, char *, int, int, int *);
-int additional_aaaa(char *, int, struct domain *, char *, int, int, int *);
-int additional_mx(char *, int, struct domain *, char *, int, int, int *);
+int additional_a(char *, int, struct rbtree *, char *, int, int, int *);
+int additional_aaaa(char *, int, struct rbtree *, char *, int, int, int *);
+int additional_mx(char *, int, struct rbtree *, char *, int, int, int *);
int additional_opt(struct question *, char *, int, int);
-int additional_ptr(char *, int, struct domain *, char *, int, int, int *);
-int additional_rrsig(char *, int, int, struct domain *, char *, int, int, int);
-int additional_nsec(char *, int, int, struct domain *, char *, int, int);
-int additional_nsec3(char *, int, int, struct domain *, char *, int, int);
+int additional_ptr(char *, int, struct rbtree *, char *, int, int, int *);
+int additional_rrsig(char *, int, int, struct rbtree *, char *, int, int, int);
+int additional_nsec(char *, int, int, struct rbtree *, char *, int, int);
+int additional_nsec3(char *, int, int, struct rbtree *, char *, int, int);
extern int compress_label(u_char *, int, int);
-extern void * find_substruct(struct domain *, u_int16_t);
+extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
+extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+extern int display_rr(struct rrset *rrset);
extern int dnssec;
@@ -54,9 +56,9 @@ extern int dnssec;
*/
int
-additional_a(char *name, int namelen, struct domain *sd, char *reply, int replylen, int offset, int *retcount)
+additional_a(char *name, int namelen, struct rbtree *rbt, char *reply, int replylen, int offset, int *retcount)
{
- int a_count;
+ int a_count = 0;
int tmplen;
int rroffset = offset;
@@ -69,21 +71,15 @@ additional_a(char *name, int namelen, struct domain *s
} __attribute__((packed));
struct answer *answer;
- struct domain_a *sda = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
*retcount = 0;
- if ((sda = (struct domain_a *)find_substruct(sd, INTERNAL_TYPE_A)) == NULL)
- return -1;
-
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) == NULL)
+ return 0;
- /*
- * We loop through our sd->a entries starting at the ptr offset
- * first in the first loop and at the beginning until the ptr
- * in the last loop. This will shift answers based on a_ptr.
- */
-
- for (a_count = sda->a_ptr; a_count < sda->a_count; a_count++) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
rroffset = offset;
if ((offset + namelen) > replylen)
goto out;
@@ -104,47 +100,18 @@ additional_a(char *name, int namelen, struct domain *s
answer->type = htons(DNS_TYPE_A);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_A]);
+ answer->ttl = htonl(((struct a *)rrp->rdata)->ttl);
answer->rdlength = htons(sizeof(in_addr_t));
- memcpy((char *)&answer->rdata, (char *)&sda->a[a_count], sizeof(in_addr_t));
+ memcpy((char *)&answer->rdata, (char *)&((struct a *)rrp->rdata)->a, sizeof(in_addr_t));
offset += sizeof(struct answer);
(*retcount)++;
+ a_count++;
}
- for (a_count = 0; a_count < sda->a_ptr; a_count++) {
- rroffset = offset;
- if ((offset + namelen) > replylen)
- goto out;
- memcpy(&reply[offset], name, namelen);
- offset += namelen;
- tmplen = compress_label((u_char*)reply, offset, namelen);
-
- if (tmplen != 0) {
- offset = tmplen;
- }
- if ((offset + sizeof(struct answer)) > replylen) {
- offset = rroffset;
- goto out;
- }
-
- answer = (struct answer *)&reply[offset];
-
- answer->type = htons(DNS_TYPE_A);
- answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_A]);
-
- answer->rdlength = htons(sizeof(in_addr_t));
-
- memcpy((char *)&answer->rdata, (char *)&sda->a[a_count], sizeof(in_addr_t));
- offset += sizeof(struct answer);
- (*retcount)++;
- }
-
-
out:
return (offset);
@@ -155,9 +122,9 @@ out:
*/
int
-additional_aaaa(char *name, int namelen, struct domain *sd, char *reply, int replylen, int offset, int *retcount)
+additional_aaaa(char *name, int namelen, struct rbtree *rbt, char *reply, int replylen, int offset, int *retcount)
{
- int aaaa_count;
+ int aaaa_count = 0;
int tmplen;
int rroffset = offset;
@@ -170,20 +137,15 @@ additional_aaaa(char *name, int namelen, struct domain
} __attribute__((packed));
struct answer *answer;
- struct domain_aaaa *sdaaaa = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
*retcount = 0;
- if ((sdaaaa = (struct domain_aaaa *)find_substruct(sd, INTERNAL_TYPE_AAAA)) == NULL)
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) == NULL)
+ return 0;
- /*
- * We loop through our sd->aaaa entries starting at the ptr offset
- * first in the first loop and at the beginning until the ptr
- * in the last loop. This will shift answers based on a_ptr.
- */
-
- for (aaaa_count = sdaaaa->aaaa_ptr; aaaa_count < sdaaaa->aaaa_count; aaaa_count++) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
rroffset = offset;
if ((offset + namelen) > replylen)
goto out;
@@ -205,49 +167,17 @@ additional_aaaa(char *name, int namelen, struct domain
answer->type = htons(DNS_TYPE_AAAA);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_AAAA]);
+ answer->ttl = htonl(((struct aaaa *)rrp->rdata)->ttl);
answer->rdlength = htons(sizeof(struct in6_addr));
- memcpy((char *)&answer->rdata, (char *)&sdaaaa->aaaa[aaaa_count], sizeof(struct in6_addr));
+ memcpy((char *)&answer->rdata, (char *)&((struct aaaa *)rrp->rdata)->aaaa, sizeof(struct in6_addr));
offset += sizeof(struct answer);
(*retcount)++;
+ aaaa_count++;
}
- for (aaaa_count = 0; aaaa_count < sdaaaa->aaaa_ptr; aaaa_count++) {
- rroffset = offset;
- if ((offset + namelen) > replylen)
- goto out;
-
-
- memcpy(&reply[offset], name, namelen);
- offset += namelen;
- tmplen = compress_label((u_char*)reply, offset, namelen);
-
- if (tmplen != 0) {
- offset = tmplen;
- }
- if ((offset + sizeof(struct answer)) > replylen) {
- offset = rroffset;
- goto out;
- }
-
- answer = (struct answer *)&reply[offset];
-
- answer->type = htons(DNS_TYPE_AAAA);
- answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_AAAA]);
-
- answer->rdlength = htons(sizeof(struct in6_addr));
-
-
- memcpy((char *)&answer->rdata, (char *)&sdaaaa->aaaa[aaaa_count], sizeof(struct in6_addr));
- offset += sizeof(struct answer);
- (*retcount)++;
- }
-
-
out:
return (offset);
@@ -259,9 +189,9 @@ out:
*/
int
-additional_mx(char *name, int namelen, struct domain *sd, char *reply, int replylen, int offset, int *retcount)
+additional_mx(char *name, int namelen, struct rbtree *rbt, char *reply, int replylen, int offset, int *retcount)
{
- int mx_count;
+ int mx_count = 0;
int tmplen;
int rroffset = offset;
@@ -274,24 +204,20 @@ additional_mx(char *name, int namelen, struct domain *
} __attribute__((packed));
struct answer *answer;
- struct domain_mx *sdmx = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
*retcount = 0;
- if ((sdmx = (struct domain_mx *)find_substruct(sd, INTERNAL_TYPE_MX)) == NULL)
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) == NULL)
+ return 0;
- /*
- * We loop through our sdmx->mx entries starting at the ptr offset
- * first in the first loop and at the beginning until the ptr
- * in the last loop. This will shift answers based on mx_ptr.
- */
- for (mx_count = sdmx->mx_ptr; mx_count < sdmx->mx_count; mx_count++) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
rroffset = offset;
if ((offset + namelen) > replylen)
- goto out;
+ return 0;
memcpy(&reply[offset], name, namelen);
offset += namelen;
@@ -303,89 +229,40 @@ additional_mx(char *name, int namelen, struct domain *
if ((offset + sizeof(struct answer)) > replylen) {
offset = rroffset;
- goto out;
+ return 0;
}
answer = (struct answer *)&reply[offset];
answer->type = htons(DNS_TYPE_MX);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_MX]);
- answer->mx_priority = htons(sdmx->mx[mx_count].preference);
+ answer->ttl = htonl(((struct smx *)rrp->rdata)->ttl);
+ answer->mx_priority = htons(((struct smx *)rrp->rdata)->preference);
offset += sizeof(struct answer);
- if ((offset + sdmx->mx[mx_count].exchangelen) > replylen) {
+ if ((offset + ((struct smx *)rrp->rdata)->exchangelen) > replylen) {
offset = rroffset;
- goto out;
+ return 0;
}
- memcpy((char *)&reply[offset], (char *)sdmx->mx[mx_count].exchange, sdmx->mx[mx_count].exchangelen);
+ memcpy((char *)&reply[offset], (char *)((struct smx *)rrp->rdata)->exchange, ((struct smx *)rrp->rdata)->exchangelen);
- offset += sdmx->mx[mx_count].exchangelen;
- tmplen = compress_label((u_char*)reply, offset, sdmx->mx[mx_count].exchangelen);
+ offset += ((struct smx *)rrp->rdata)->exchangelen;
+ tmplen = compress_label((u_char*)reply, offset, ((struct smx *)rrp->rdata)->exchangelen);
if (tmplen != 0) {
- answer->rdlength = htons((sdmx->mx[mx_count].exchangelen - (offset - tmplen)) + sizeof(u_int16_t));
+ answer->rdlength = htons((((struct smx *)rrp->rdata)->exchangelen - (offset - tmplen)) + sizeof(u_int16_t));
offset = tmplen;
} else
- answer->rdlength = htons(sdmx->mx[mx_count].exchangelen + sizeof(u_int16_t));
+ answer->rdlength = htons(((struct smx *)rrp->rdata)->exchangelen + sizeof(u_int16_t));
(*retcount)++;
+ mx_count++;
}
- for (mx_count = 0; mx_count < sdmx->mx_ptr; mx_count++) {
- rroffset = offset;
-
- if ((offset + namelen) > replylen)
- goto out;
-
-
- memcpy(&reply[offset], name, namelen);
- offset += namelen;
- tmplen = compress_label((u_char*)reply, offset, namelen);
-
- if (tmplen != 0) {
- offset = tmplen;
- }
-
- if ((offset + sizeof(struct answer)) > replylen) {
- offset = rroffset;
- goto out;
- }
-
- answer = (struct answer *)&reply[offset];
-
- answer->type = htons(DNS_TYPE_A);
- answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_A]);
-
- offset += sizeof(struct answer);
-
- if ((offset + sdmx->mx[mx_count].exchangelen) > replylen) {
- offset = rroffset;
- goto out;
- }
-
- memcpy((char *)&reply[offset], (char *)sdmx->mx[mx_count].exchange, sdmx->mx[mx_count].exchangelen);
-
- offset += sdmx->mx[mx_count].exchangelen;
- tmplen = compress_label((u_char *)reply, offset, sdmx->mx[mx_count].exchangelen);
-
- if (tmplen != 0) {
-
- answer->rdlength = htons((sdmx->mx[mx_count].exchangelen - (offset - tmplen)) + sizeof(u_int16_t));
- offset = tmplen;
- } else
- answer->rdlength = htons(sdmx->mx[mx_count].exchangelen + sizeof(u_int16_t));
-
- (*retcount)++;
- }
-
-
-out:
return (offset);
}
@@ -397,7 +274,7 @@ out:
int
-additional_ptr(char *name, int namelen, struct domain *sd, char *reply, int replylen, int offset, int *retcount)
+additional_ptr(char *name, int namelen, struct rbtree *rbt, char *reply, int replylen, int offset, int *retcount)
{
int tmplen;
int rroffset = offset;
@@ -410,12 +287,13 @@ additional_ptr(char *name, int namelen, struct domain
} __attribute__((packed));
struct answer *answer;
- struct domain_ptr *sdptr = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
*retcount = 0;
- if ((sdptr = (struct domain_ptr *)find_substruct(sd, INTERNAL_TYPE_PTR)) == NULL)
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) == NULL)
+ return 0;
if ((offset + namelen) > replylen)
goto out;
@@ -433,29 +311,33 @@ additional_ptr(char *name, int namelen, struct domain
goto out;
}
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return 0;
+
answer = (struct answer *)&reply[offset];
answer->type = htons(DNS_TYPE_PTR);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_PTR]);
+ answer->ttl = htonl(((struct ptr *)rrp->rdata)->ttl);
offset += sizeof(struct answer);
- if ((offset + sdptr->ptrlen) > replylen) {
+ if ((offset + ((struct ptr *)rrp->rdata)->ptrlen) > replylen) {
offset = rroffset;
goto out;
}
- memcpy((char *)&reply[offset], (char *)sdptr->ptr, sdptr->ptrlen);
+ memcpy((char *)&reply[offset], (char *)((struct ptr *)rrp->rdata)->ptr, ((struct ptr *)rrp->rdata)->ptrlen);
- offset += sdptr->ptrlen;
- tmplen = compress_label((u_char*)reply, offset, sdptr->ptrlen);
+ offset += ((struct ptr *)rrp->rdata)->ptrlen;
+ tmplen = compress_label((u_char*)reply, offset, ((struct ptr *)rrp->rdata)->ptrlen);
if (tmplen != 0) {
- answer->rdlength = htons(sdptr->ptrlen - (offset - tmplen));
+ answer->rdlength = htons(((struct ptr *)rrp->rdata)->ptrlen - (offset - tmplen));
offset = tmplen;
} else
- answer->rdlength = htons(sdptr->ptrlen);
+ answer->rdlength = htons(((struct ptr *)rrp->rdata)->ptrlen);
(*retcount)++;
@@ -503,11 +385,11 @@ out:
/*
* ADDITIONAL_RRSIG - tag on an additional RRSIG to the answer
- * type passed must be an INTERNAL_TYPE!
+ * type passed must be a DNS_TYPE!
*/
int
-additional_rrsig(char *name, int namelen, int inttype, struct domain *sd, char *reply, int replylen, int offset, int count)
+additional_rrsig(char *name, int namelen, int inttype, struct rbtree *rbt, char *reply, int replylen, int offset, int count)
{
struct answer {
u_int16_t type;
@@ -525,12 +407,11 @@ additional_rrsig(char *name, int namelen, int inttype,
struct answer *answer;
- struct domain_rrsig *sdrr;
- struct rrsig *rrsig;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int tmplen, rroffset;
- sdrr = (struct domain_rrsig *)find_substruct(sd, INTERNAL_TYPE_RRSIG);
- if (sdrr == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_RRSIG)) == NULL)
goto out;
rroffset = offset;
@@ -551,42 +432,40 @@ additional_rrsig(char *name, int namelen, int inttype,
return 0;
}
- if (inttype == INTERNAL_TYPE_DNSKEY) {
- rrsig = &sdrr->rrsig_dnskey[count];
- if (rrsig->algorithm == 0)
- return 0;
- } else {
- rrsig = &sdrr->rrsig[inttype];
- }
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ if (inttype != ((struct rrsig *)rrp->rdata)->type_covered)
+ continue;
- answer = (struct answer *)&reply[offset];
- answer->type = htons(DNS_TYPE_RRSIG);
- answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[inttype]);
- answer->type_covered = htons(rrsig->type_covered);
- answer->algorithm = rrsig->algorithm;
- answer->labels = rrsig->labels;
- answer->original_ttl = htonl(rrsig->original_ttl);
- answer->sig_expiration = htonl(rrsig->signature_expiration);
- answer->sig_inception = htonl(rrsig->signature_inception);
- answer->keytag = htons(rrsig->key_tag);
+ answer = (struct answer *)&reply[offset];
+ answer->type = htons(DNS_TYPE_RRSIG);
+ answer->class = htons(DNS_CLASS_IN);
+ answer->ttl = htonl(((struct rrsig *)rrp->rdata)->ttl);
+ answer->type_covered = htons(((struct rrsig *)rrp->rdata)->type_covered);
+ answer->algorithm = ((struct rrsig *)rrp->rdata)->algorithm;
+ answer->labels = ((struct rrsig *)rrp->rdata)->labels;
+ answer->original_ttl = htonl(((struct rrsig *)rrp->rdata)->original_ttl);
+ answer->sig_expiration = htonl(((struct rrsig *)rrp->rdata)->signature_expiration);
+ answer->sig_inception = htonl(((struct rrsig *)rrp->rdata)->signature_inception);
+ answer->keytag = htons(((struct rrsig *)rrp->rdata)->key_tag);
- offset += sizeof(struct answer);
- rroffset = offset;
+ offset += sizeof(struct answer);
+ rroffset = offset;
- if ((offset + rrsig->signame_len) > replylen)
- return 0;
+ if ((offset + ((struct rrsig *)rrp->rdata)->signame_len) > replylen)
+ return 0;
- memcpy(&reply[offset], rrsig->signers_name, rrsig->signame_len);
+ memcpy(&reply[offset], ((struct rrsig *)rrp->rdata)->signers_name, ((struct rrsig *)rrp->rdata)->signame_len);
- offset += rrsig->signame_len;
+ offset += ((struct rrsig *)rrp->rdata)->signame_len;
- if ((offset + rrsig->signature_len) > replylen)
- return 0;
+ if ((offset + ((struct rrsig *)rrp->rdata)->signature_len) > replylen)
+ return 0;
- memcpy(&reply[offset], rrsig->signature, rrsig->signature_len);
- offset += rrsig->signature_len;
+ memcpy(&reply[offset], ((struct rrsig *)rrp->rdata)->signature, ((struct rrsig *)rrp->rdata)->signature_len);
+ offset += ((struct rrsig *)rrp->rdata)->signature_len;
+ }
+
answer->rdlength = htons((offset - rroffset) + 18);
out:
return (offset);
@@ -595,11 +474,11 @@ out:
/*
* ADDITIONAL_NSEC - tag on an additional NSEC with RRSIG to the answer
- * type passed must be an INTERNAL_TYPE!
+ * type passed must be a DNS_TYPE!
*/
int
-additional_nsec(char *name, int namelen, int inttype, struct domain *sd, char *reply, int replylen, int offset)
+additional_nsec(char *name, int namelen, int inttype, struct rbtree *rbt, char *reply, int replylen, int offset)
{
struct answer {
u_int16_t type;
@@ -609,13 +488,17 @@ additional_nsec(char *name, int namelen, int inttype,
} __attribute__((packed));
struct answer *answer;
- struct domain_nsec *sdnsec;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int tmplen, rroffset;
- sdnsec = (struct domain_nsec *)find_substruct(sd, INTERNAL_TYPE_NSEC);
- if (sdnsec == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC)) == NULL)
goto out;
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ goto out;
+
rroffset = offset;
/* check if we go over our return length */
@@ -637,21 +520,22 @@ additional_nsec(char *name, int namelen, int inttype,
answer = (struct answer *)&reply[offset];
answer->type = htons(DNS_TYPE_NSEC);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[inttype]);
- answer->rdlength = htons(sdnsec->nsec.ndn_len +
- sdnsec->nsec.bitmap_len);
+ answer->ttl = htonl(((struct nsec *)rrp->rdata)->ttl);
+ answer->rdlength = htons(((struct nsec *)rrp->rdata)->ndn_len +
+ ((struct nsec *)rrp->rdata)->bitmap_len);
offset += sizeof(*answer);
- memcpy(&reply[offset], sdnsec->nsec.next_domain_name,
- sdnsec->nsec.ndn_len);
+ memcpy(&reply[offset], ((struct nsec *)rrp->rdata)->next_domain_name,
+ ((struct nsec *)rrp->rdata)->ndn_len);
- offset += sdnsec->nsec.ndn_len;
+ offset += ((struct nsec *)rrp->rdata)->ndn_len;
- memcpy(&reply[offset], sdnsec->nsec.bitmap, sdnsec->nsec.bitmap_len);
- offset += sdnsec->nsec.bitmap_len;
+ memcpy(&reply[offset], ((struct nsec *)rrp->rdata)->bitmap,
+ ((struct nsec *)rrp->rdata)->bitmap_len);
+ offset += ((struct nsec *)rrp->rdata)->bitmap_len;
- tmplen = additional_rrsig(name, namelen, INTERNAL_TYPE_NSEC, sd, reply, replylen, offset, 0);
+ tmplen = additional_rrsig(name, namelen, DNS_TYPE_NSEC, rbt, reply, replylen, offset, 0);
if (tmplen == 0) {
goto out;
@@ -666,11 +550,11 @@ out:
/*
* ADDITIONAL_NSEC3 - tag on an additional NSEC3 with RRSIG to the answer
- * type passed must be an INTERNAL_TYPE!
+ * type passed must be an DNS_TYPE!
*/
int
-additional_nsec3(char *name, int namelen, int inttype, struct domain *sd, char *reply, int replylen, int offset)
+additional_nsec3(char *name, int namelen, int inttype, struct rbtree *rbt, char *reply, int replylen, int offset)
{
struct answer {
u_int16_t type;
@@ -684,14 +568,19 @@ additional_nsec3(char *name, int namelen, int inttype,
} __attribute__((packed));
struct answer *answer;
- struct domain_nsec3 *sdnsec3;
+ struct rrset *rrset;
+ struct rr *rrp;
+
int tmplen, rroffset;
u_int8_t *somelen;
- sdnsec3 = (struct domain_nsec3 *)find_substruct(sd, INTERNAL_TYPE_NSEC3);
- if (sdnsec3 == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) == NULL)
goto out;
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ goto out;
+
rroffset = offset;
/* check if we go over our return length */
@@ -713,42 +602,44 @@ additional_nsec3(char *name, int namelen, int inttype,
answer = (struct answer *)&reply[offset];
answer->type = htons(DNS_TYPE_NSEC3);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[inttype]);
- answer->rdlength = htons(6 + sdnsec3->nsec3.saltlen +
- sdnsec3->nsec3.nextlen + sdnsec3->nsec3.bitmap_len);
- answer->algorithm = sdnsec3->nsec3.algorithm;
- answer->flags = sdnsec3->nsec3.flags;
- answer->iterations = htons(sdnsec3->nsec3.iterations);
- answer->saltlen = sdnsec3->nsec3.saltlen;
+ answer->ttl = htonl(((struct nsec3 *)rrp->rdata)->ttl);
+ answer->rdlength = htons(6 + ((struct nsec3 *)rrp->rdata)->saltlen +
+ ((struct nsec3 *)rrp->rdata)->nextlen +
+ ((struct nsec3 *)rrp->rdata)->bitmap_len);
+ answer->algorithm = ((struct nsec3 *)rrp->rdata)->algorithm;
+ answer->flags = ((struct nsec3 *)rrp->rdata)->flags;
+ answer->iterations = htons(((struct nsec3 *)rrp->rdata)->iterations);
+ answer->saltlen = ((struct nsec3 *)rrp->rdata)->saltlen;
offset += sizeof(*answer);
- if (sdnsec3->nsec3.saltlen) {
- memcpy(&reply[offset], &sdnsec3->nsec3.salt, sdnsec3->nsec3.saltlen);
- offset += sdnsec3->nsec3.saltlen;
+ if (((struct nsec3 *)rrp->rdata)->saltlen) {
+ memcpy(&reply[offset], &((struct nsec3 *)rrp->rdata)->salt,
+ ((struct nsec3 *)rrp->rdata)->saltlen);
+ offset += ((struct nsec3 *)rrp->rdata)->saltlen;
}
somelen = (u_int8_t *)&reply[offset];
- *somelen = sdnsec3->nsec3.nextlen;
+ *somelen = ((struct nsec3 *)rrp->rdata)->nextlen;
offset += 1;
- memcpy(&reply[offset], sdnsec3->nsec3.next, sdnsec3->nsec3.nextlen);
+ memcpy(&reply[offset], ((struct nsec3 *)rrp->rdata)->next,
+ ((struct nsec3 *)rrp->rdata)->nextlen);
- offset += sdnsec3->nsec3.nextlen;
+ offset += ((struct nsec3 *)rrp->rdata)->nextlen;
- memcpy(&reply[offset], sdnsec3->nsec3.bitmap, sdnsec3->nsec3.bitmap_len);
- offset += sdnsec3->nsec3.bitmap_len;
+ memcpy(&reply[offset], ((struct nsec3 *)rrp->rdata)->bitmap,
+ ((struct nsec3 *)rrp->rdata)->bitmap_len);
+ offset += ((struct nsec3 *)rrp->rdata)->bitmap_len;
-#if 1
- tmplen = additional_rrsig(name, namelen, INTERNAL_TYPE_NSEC3, sd, reply, replylen, offset, 0);
+ tmplen = additional_rrsig(name, namelen, DNS_TYPE_NSEC3, rbt, reply, replylen, offset, 0);
if (tmplen == 0) {
goto out;
}
offset = tmplen;
-#endif
out:
return (offset);
blob - a15c67f9699d57353b7a4c116db4663bbdc9ea0d
blob + 411beeca9e0d5dc6ccfd4841555039b4c948bc78
--- axfr.c
+++ axfr.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: axfr.c,v 1.19 2019/01/25 20:00:15 pjp Exp $
+ * $Id: axfr.c,v 1.20 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
@@ -38,8 +38,8 @@
void axfrloop(int *, int, char **, ddDB *, struct imsgbuf *ibuf);
void axfr_connection(int, char *, int, ddDB *, char *, int);
int build_header(ddDB *, char *, char *, struct question *, int);
-int build_soa(ddDB *, char *, int, struct domain *, struct question *);
-int checklabel(ddDB *, struct domain *, struct domain *, struct question *);
+int build_soa(ddDB *, char *, int, struct rbtree *, struct question *);
+int checklabel(ddDB *, struct rbtree *, struct rbtree *, struct question *);
int find_axfr(struct sockaddr_storage *, int);
void gather_notifydomains(ddDB *);
void init_axfr(void);
@@ -55,17 +55,21 @@ extern in_addr_t getmask(int);
extern int getmask6(int, struct sockaddr_in6 *);
extern void reply_fmterror(struct sreply *, ddDB *);
extern void reply_nxdomain(struct sreply *, ddDB *);
-extern struct domain * get_soa(ddDB *, struct question *);
-extern void * find_substruct(struct domain *, u_int16_t);
+extern struct rbtree * get_soa(ddDB *, struct question *);
extern int compress_label(u_char *, int, int);
extern u_int16_t create_anyreply(struct sreply *, char *, int, int, int);
extern struct question *build_fake_question(char *, int, u_int16_t);
extern struct question *build_question(char *, int, int);
extern int free_question(struct question *);
extern void dolog(int, char *, ...);
-extern void build_reply(struct sreply *, int, char *, int, struct question *, struct sockaddr *, socklen_t, struct domain *, struct domain *, u_int8_t, int, int, struct recurses *);
+extern void build_reply(struct sreply *, int, char *, int, struct question *, struct sockaddr *, socklen_t, struct rbtree *, struct rbtree *, u_int8_t, int, int, struct recurses *);
+extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
+extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+extern int display_rr(struct rrset *rrset);
+extern int rotate_rr(struct rrset *rrset);
+
int notify = 0; /* do not notify when set to 0 */
extern int debug, verbose;
@@ -732,9 +736,8 @@ axfr_connection(int so, char *address, int is_ipv6, dd
int len, dnslen;
int offset = 0;
- int ret;
int qlen;
- int outlen, i;
+ int outlen;
int rrcount;
int rs;
@@ -744,8 +747,9 @@ axfr_connection(int so, char *address, int is_ipv6, dd
struct dns_header *dh, *odh;
struct sreply sreply;
struct question *question, *fq;
- struct domain *soa = NULL, *sdomain = NULL, *nsdomain = NULL, *savesd = NULL;
- struct domain_ns *savesdns;
+ struct rbtree *rbt = NULL, *rbt2 = NULL, *saverbt = NULL, *soa = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
ddDBT key, data;
@@ -838,62 +842,36 @@ axfr_connection(int so, char *address, int is_ipv6, dd
q = question->hdr->name;
qlen = question->hdr->namelen;
- rs = get_record_size(db, q, qlen);
- if (rs < 0) {
- dolog(LOG_INFO, "internal error: %s\n", strerror(errno));
- goto drop;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = (char *)q;
- key.size = qlen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
-
- if (ret != 0) {
- sdomain = get_soa(db, question);
- if (sdomain == NULL) {
+ rbt = find_rrset(db, q, qlen);
+ if (rbt == NULL) {
+ rbt2 = get_soa(db, question);
+ if (rbt2 == NULL) {
dolog(LOG_INFO, "internal error: %s\n", strerror(errno));
goto drop;
}
- build_reply(&sreply, so, (p + 2), dnslen, question, NULL, 0, sdomain, NULL, 0xff, 1, 0, NULL);
+ build_reply(&sreply, so, (p + 2), dnslen, question, NULL, 0, rbt2, NULL, 0xff, 1, 0, NULL);
reply_nxdomain(&sreply, NULL);
dolog(LOG_INFO, "AXFR request for zone %s, no db entry, nxdomain -> drop\n", question->converted_name);
goto drop;
}
- if (data.size != rs) {
- dolog(LOG_INFO, "AXFR btree db is damaged, drop\n");
- goto drop;
- }
-
- if ((soa = calloc(1, rs)) == NULL) {
- dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
- goto drop;
- }
-
- memcpy((char *)soa, (char *)data.data, data.size);
-
/*
* check if we have an SOA record
*/
- if (! (soa->flags & DOMAIN_HAVE_SOA)) {
- sdomain = get_soa(db, question);
- if (sdomain == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) == NULL) {
+ rbt2 = get_soa(db, question);
+ if (rbt2 == NULL) {
dolog(LOG_INFO, "internal error: %s\n", strerror(errno));
goto drop;
}
- build_reply(&sreply, so, (p + 2), dnslen, question, NULL, 0, sdomain, NULL, 0xff, 1, 0, NULL);
+ build_reply(&sreply, so, (p + 2), dnslen, question, NULL, 0, rbt2, NULL, 0xff, 1, 0, NULL);
reply_nxdomain(&sreply, NULL);
dolog(LOG_INFO, "AXFR request for zone %s, which has no SOA for the zone, nxdomain -> drop\n", question->converted_name);
goto drop;
+ } else {
+ soa = rbt;
}
if (ntohs(question->hdr->qtype) == DNS_TYPE_SOA) {
@@ -927,88 +905,52 @@ axfr_connection(int so, char *address, int is_ipv6, dd
outlen = build_soa(db, (reply + 2), outlen, soa, question);
rrcount = 1;
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
rs = n->datalen;
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((rbt = calloc(1, sizeof(struct rbtree))) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
goto drop;
}
- if ((savesd = calloc(1, rs)) == NULL) {
+ if ((saverbt = calloc(1, sizeof(struct rbtree))) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
goto drop;
}
-
- memcpy((char*)sdomain,(char*)n->data, rs);
- memcpy((char*)savesd,(char*)n->data, rs);
- if (checklabel(db, sdomain, soa, question)) {
- fq = build_fake_question(sdomain->zone, sdomain->zonelen, 0);
- build_reply(&sreply, so, (p + 2), dnslen, fq, NULL, 0, sdomain, NULL, 0xff, 1, 0, NULL);
+ memcpy((char*)rbt, (char*)n->data, sizeof(struct rbtree));
+ memcpy((char*)saverbt,(char*)n->data, sizeof(struct rbtree));
+
+ if (checklabel(db, rbt, soa, question)) {
+ fq = build_fake_question(rbt->zone, rbt->zonelen, 0);
+ build_reply(&sreply, so, (p + 2), dnslen, fq, NULL, 0, rbt, NULL, 0xff, 1, 0, NULL);
outlen = create_anyreply(&sreply, (reply + 2), 65535, outlen, 0);
free_question(fq);
- if (savesd->flags & DOMAIN_HAVE_NS) {
- savesdns = (struct domain_ns *)find_substruct(savesd, INTERNAL_TYPE_NS);
- }
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp != NULL &&
+ ((struct ns *)rrp->rdata)->ns_type & NS_TYPE_DELEGATE) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ fq = build_fake_question(((struct ns *)rrp->rdata)->nsserver,
+ ((struct ns *)rrp->rdata)->nslen, 0);
+ rbt2 = find_rrset(db, fq->hdr->name, fq->hdr->namelen);
+ if (rbt2 == NULL) {
+ free_question(fq);
+ continue;
+ }
- if ((savesd->flags & DOMAIN_HAVE_NS) &&
- (savesdns->ns_type & NS_TYPE_DELEGATE)) {
-
- for (i = 0; i < savesdns->ns_count; i++) {
- fq = build_fake_question(savesdns->ns[i].nsserver,
- savesdns->ns[i].nslen, 0);
-
-
- rs = get_record_size(db, fq->hdr->name, fq->hdr->namelen);
- if (rs < 0) {
- dolog(LOG_INFO, "AXFR btree db is damaged (%d), drop\n", __LINE__);
+ build_reply(&sreply, so, (p + 2), dnslen, fq, NULL, 0, rbt2, NULL, 0xff, 1, 0, NULL);
+ outlen = create_anyreply(&sreply, (reply + 2), 65535, outlen, 0);
+ if (rbt2) {
+ free(rbt2);
+ rbt2 = NULL;
+ }
free_question(fq);
- goto drop;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = fq->hdr->name;
- key.size = fq->hdr->namelen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
- free_question(fq);
- continue;
- }
-
- if (data.size != rs) {
- dolog(LOG_INFO, "AXFR btree db is damaged (%d), drop\n", __LINE__);
- goto drop;
- }
-
- if ((nsdomain = calloc(1, rs)) == NULL) {
- dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
- free_question(fq);
- goto drop;
- }
- memcpy((char *)nsdomain, (char*)data.data, data.size);
-
- build_reply(&sreply, so, (p + 2), dnslen, fq, NULL, 0, nsdomain, NULL, 0xff, 1, 0, NULL);
- outlen = create_anyreply(&sreply, (reply + 2), 65535, outlen, 0);
- if (nsdomain) {
- free(nsdomain);
- nsdomain = NULL;
- }
- free_question(fq);
- } /* for (i.. */
- } /* if (sdomain.flags */
+ } /* TAILQ_FOREACH */
+ } /* if (rrp != NULL */
+ } /* if (find_rr */
+ } /* if checklabel */
- } /* if (checklabel */
-
/*
* if we accumulate 60000 bytes out of the maximum
* 65535 bytes then we fragment.
@@ -1035,13 +977,13 @@ axfr_connection(int so, char *address, int is_ipv6, dd
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
- if (sdomain) {
- free(sdomain);
- sdomain = NULL;
+ if (rbt) {
+ free(rbt);
+ rbt = NULL;
}
- if (savesd) {
- free(savesd);
- savesd = NULL;
+ if (rbt2) {
+ free(rbt2);
+ rbt2 = NULL;
}
} /* RB_FOREACH */
@@ -1073,19 +1015,19 @@ drop:
soa = NULL;
}
- if (sdomain) {
- free (sdomain);
- sdomain = NULL;
+ if (rbt) {
+ free (rbt);
+ rbt = NULL;
}
- if (nsdomain) {
- free (nsdomain);
- nsdomain = NULL;
+ if (rbt2) {
+ free (rbt2);
+ rbt2 = NULL;
}
- if (savesd) {
- free (savesd);
- savesd = NULL;
+ if (saverbt) {
+ free (saverbt);
+ saverbt = NULL;
}
close(so);
@@ -1149,7 +1091,7 @@ build_header(ddDB *db, char *reply, char *buf, struct
*/
int
-build_soa(ddDB *db, char *reply, int offset, struct domain *sd, struct question *q)
+build_soa(ddDB *db, char *reply, int offset, struct rbtree *rbt, struct question *q)
{
char *p;
char *label;
@@ -1169,24 +1111,31 @@ build_soa(ddDB *db, char *reply, int offset, struct do
} __attribute__((packed));
struct answer *answer;
- struct domain_soa *sdsoa = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
- sdsoa = (struct domain_soa *)find_substruct(sd, INTERNAL_TYPE_SOA);
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) == NULL) {
+ return 0;
+ }
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ return 0;
+ }
+
answer = (struct answer *)(&reply[offset]);
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = htons(DNS_TYPE_SOA);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA]);
+ answer->ttl = htonl(((struct soa *)rrp->rdata)->ttl);
offset += 12; /* up to rdata length */
p = (char *)&answer->rdata;
- label = sdsoa->soa.nsserver;
- labellen = sdsoa->soa.nsserver_len;
+ label = ((struct soa *)rrp->rdata)->nsserver;
+ labellen = ((struct soa *)rrp->rdata)->nsserver_len;
plabel = label;
@@ -1202,8 +1151,8 @@ build_soa(ddDB *db, char *reply, int offset, struct do
offset = tmplen;
}
- label = sdsoa->soa.responsible_person;
- labellen = sdsoa->soa.rp_len;
+ label = ((struct soa *)rrp->rdata)->responsible_person;
+ labellen = ((struct soa *)rrp->rdata)->rp_len;
plabel = label;
if (offset + labellen <= 65535)
@@ -1221,42 +1170,41 @@ build_soa(ddDB *db, char *reply, int offset, struct do
/* XXX */
- if ((offset + sizeof(sdsoa->soa.serial)) >= 65535 ) {
+ if ((offset + sizeof(u_int32_t)) >= 65535 ) {
/* XXX server error reply? */
return (offset);
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.serial);
- offset += sizeof(sdsoa->soa.serial); /* XXX */
+ *soa_val = htonl(((struct soa *)rrp->rdata)->serial);
+ offset += sizeof(u_int32_t);
- /* XXX */
- if ((offset + sizeof(sdsoa->soa.refresh)) >= 65535 ) {
+ if ((offset + sizeof(u_int32_t)) >= 65535 ) {
return (offset);
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.refresh);
- offset += sizeof(sdsoa->soa.refresh); /* XXX */
+ *soa_val = htonl(((struct soa *)rrp->rdata)->refresh);
+ offset += sizeof(u_int32_t);
- if ((offset + sizeof(sdsoa->soa.retry)) >= 65535 ) {
+ if ((offset + sizeof(u_int32_t)) >= 65535 ) {
return (offset);
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.retry);
- offset += sizeof(sdsoa->soa.retry); /* XXX */
+ *soa_val = htonl(((struct soa *)rrp->rdata)->retry);
+ offset += sizeof(u_int32_t);
- if ((offset + sizeof(sdsoa->soa.expire)) >= 65535 ) {
+ if ((offset + sizeof(u_int32_t)) >= 65535 ) {
return (offset);
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.expire);
- offset += sizeof(sdsoa->soa.expire);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->expire);
+ offset += sizeof(u_int32_t);
- if ((offset + sizeof(sdsoa->soa.minttl)) > 65535 ) {
+ if ((offset + sizeof(u_int32_t)) > 65535 ) {
return (offset);
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.minttl);
- offset += sizeof(sdsoa->soa.minttl);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->minttl);
+ offset += sizeof(u_int32_t);
answer->rdlength = htons(&reply[offset] - &answer->rdata);
@@ -1264,68 +1212,39 @@ build_soa(ddDB *db, char *reply, int offset, struct do
}
int
-checklabel(ddDB *db, struct domain *sd, struct domain *soa, struct question *q)
+checklabel(ddDB *db, struct rbtree *rbt, struct rbtree *soa, struct question *q)
{
- struct domain *tmpsd;
+ struct rbtree *tmprbt;
+ struct rrset *rrset;
char *p;
- int plen, ret;
- int rs;
+ int plen;
- ddDBT key, data;
-
- if (memcmp(sd, soa, sizeof(struct domain)) == 0)
+ if (memcmp(rbt, soa, sizeof(struct rbtree)) == 0)
return 1;
- p = sd->zone;
- plen = sd->zonelen;
+ p = rbt->zone;
+ plen = rbt->zonelen;
do {
if (*p == '\0')
return (0);
- rs = get_record_size(db, p, plen);
- if (rs < 0) {
- return (0);
- }
-
- tmpsd = calloc(1, rs);
- if (tmpsd == NULL) {
- return (0);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = (char *)p;
- key.size = plen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret == DDDB_NOTFOUND) {
+ tmprbt = find_rrset(db, p, plen);
+ if (tmprbt == NULL) {
plen -= (*p + 1);
p = (p + (*p + 1));
- free(tmpsd);
+ free(tmprbt);
continue;
}
- if (data.size != rs) {
- dolog(LOG_INFO, "AXFR btree db is damaged (%d), drop\n", __LINE__);
- free(tmpsd);
- return (0);
- }
-
- memcpy(tmpsd, data.data, data.size);
-
/*
* the encountered label has an SOA before we got to the
* root, so we skip this record entirely...
*/
- if (tmpsd->flags & DOMAIN_HAVE_SOA) {
- free (tmpsd);
+ if ((rrset = find_rr(tmprbt, DNS_TYPE_SOA)) != NULL) {
+ free (tmprbt);
return (0);
}
@@ -1337,7 +1256,7 @@ checklabel(ddDB *db, struct domain *sd, struct domain
plen -= (*p + 1);
p = (p + (*p + 1));
- free(tmpsd);
+ free(tmprbt);
} while (memcmp(p, q->hdr->name, q->hdr->namelen) != 0);
@@ -1357,8 +1276,9 @@ gather_notifydomains(ddDB *db)
char buf[128];
struct node *n, *nx;
- struct domain *sd;
- struct domain_soa *sdsoa = NULL;
+ struct rbtree *rbt;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
SLIST_INIT(&notifyhead);
@@ -1375,10 +1295,10 @@ gather_notifydomains(ddDB *db)
memset(&data, 0, sizeof(data));
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
- sd = (struct domain *)n->data;
+ rbt = (struct rbtree *)n->data;
- if ((sd->flags & DOMAIN_HAVE_SOA) == DOMAIN_HAVE_SOA) {
- sdsoa = (struct domain_soa *)find_substruct(sd, INTERNAL_TYPE_SOA);
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
notn2 = malloc(sizeof(struct notifyentry));
if (notn2 == NULL) {
continue;
@@ -1396,21 +1316,21 @@ gather_notifydomains(ddDB *db)
continue;
}
- memcpy(notn2->domain, sd->zone, sd->zonelen);
- notn2->domainlen = sd->zonelen;
+ memcpy(notn2->domain, rbt->zone, rbt->zonelen);
+ notn2->domainlen = rbt->zonelen;
- soatime = (time_t)sdsoa->soa.serial;
- snprintf(buf, sizeof(buf), "%u", sdsoa->soa.serial);
+ soatime = (time_t)((struct soa *)rrp->rdata)->serial;
+ snprintf(buf, sizeof(buf), "%u", ((struct soa *)rrp->rdata)->serial);
if (strncmp(buf, timestring, strlen(timestring)) == 0) {
- dolog(LOG_INFO, "inserting zone \"%s\" for notification...\n", sd->zonename);
+ dolog(LOG_INFO, "inserting zone \"%s\" for notification...\n", rbt->humanname);
SLIST_INSERT_HEAD(&notifyhead, notn2, notify_entry);
} else if (difftime(now, soatime) < 1800 && difftime(now, soatime) > 0) {
- dolog(LOG_INFO, "2 inserting zone \"%s\" for notification...\n", sd->zonename);
+ dolog(LOG_INFO, "2 inserting zone \"%s\" for notification...\n", rbt->humanname);
SLIST_INSERT_HEAD(&notifyhead, notn2, notify_entry);
} else {
#if 0
- dolog(LOG_INFO, "SOA serial for zone \"%s\" did not make sense (%s), not notifying\n", sd->zonename, buf);
+ dolog(LOG_INFO, "SOA serial for zone \"%s\" did not make sense (%s), not notifying\n", rbt->humanname, buf);
#endif
free(notn2);
}
blob - 9810402d57aad98e98db4e1573d783708905f3cd
blob + 58099551490cdcfd91c1d88bc3c4d5b057bfede4
--- db.c
+++ db.c
@@ -27,14 +27,21 @@
*/
/*
- * $Id: db.c,v 1.5 2017/10/26 15:49:29 pjp Exp $
+ * $Id: db.c,v 1.6 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
#include "ddd-dns.h"
#include "ddd-db.h"
+struct rbtree * create_rr(ddDB *db, char *name, int len, int type, void *rdata);
+struct rbtree * find_rrset(ddDB *db, char *name, int len);
+struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+int add_rr(struct rbtree *rbt, char *name, int len, u_int16_t rrtype, void *rdata);
+int display_rr(struct rrset *rrset);
+int rotate_rr(struct rrset *rrset);
+extern char * convert_name(char *, int);
int
domaincmp(struct node *e1, struct node *e2)
@@ -80,11 +87,6 @@ dddbput(ddDB *db, ddDBT *key, ddDBT *data)
struct node find, *n, *res;
char *map;
- if (data->size > SIZENODE) {
- errno = E2BIG;
- return -1;
- }
-
strlcpy(find.domainname, key->data, sizeof(find.domainname));
find.len = key->size;
@@ -92,15 +94,13 @@ dddbput(ddDB *db, ddDBT *key, ddDBT *data)
if (res == NULL) {
/* does not exist, create it */
- map = (char *)mmap(NULL, SIZENODE, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
- if (map == MAP_FAILED) {
- errno = EINVAL;
+ map = calloc(1, data->size);
+ if (map == NULL) {
return -1;
}
n = calloc(sizeof(struct node), 1);
if (n == NULL) {
- errno = ENOMEM;
return -1;
}
memset(n, 0, sizeof(struct node));
@@ -112,8 +112,10 @@ dddbput(ddDB *db, ddDBT *key, ddDBT *data)
RB_INSERT(domaintree, &rbhead, n);
} else {
- res->datalen = data->size;
- memcpy(res->data, data->data, data->size);
+ if (res->datalen != data->size)
+ return -1;
+
+ memcpy(res->data, data->data, res->datalen);
}
return 0;
@@ -141,5 +143,188 @@ dddbget(ddDB *db, ddDBT *key, ddDBT *data)
int
dddbclose(ddDB *db)
{
+ return 0;
+}
+
+struct rbtree *
+create_rr(ddDB *db, char *name, int len, int type, void *rdata)
+{
+ struct rbtree *rbt = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *myrr = NULL;
+ ddDBT key, data;
+ int nc = 1;
+ char *humanname = NULL;
+
+
+ rbt = find_rrset(db, name, len);
+ if (rbt == NULL) {
+ rbt = (struct rbtree *) calloc(1, sizeof(struct rbtree));
+ if (! rbt) {
+ perror("calloc");
+ return NULL;
+ }
+
+ strlcpy(rbt->zone, name, sizeof(rbt->zone));
+ rbt->zonelen = len;
+ humanname = convert_name(name, len);
+ strlcpy(rbt->humanname, humanname, sizeof(rbt->humanname));
+ TAILQ_INIT(&rbt->rrset_head);
+ nc = 1;
+ }
+
+ rrset = find_rr(rbt, type);
+ if (rrset == NULL) {
+ rrset = (struct rrset *)calloc(1, sizeof(struct rrset));
+ if (! rrset){
+ perror("calloc");
+
+ if (nc)
+ free(rbt);
+ return NULL;
+ }
+
+ rrset->rrtype = type;
+ TAILQ_INIT(&rrset->rr_head);
+
+ TAILQ_INSERT_TAIL(&rbt->rrset_head, rrset, entries);
+ }
+
+
+ if (nc) {
+ /* save this new rbtree (it changed) */
+
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+
+ key.data = (char *)name;
+ key.size = len;
+
+ data.data = (void*)rbt;
+ data.size = sizeof(struct rbtree);
+
+ if (db->put(db, &key, &data) != 0) {
+ return NULL;
+ }
+ }
+
+ myrr = (struct rr *)calloc(1, sizeof(struct rr));
+ if (! myrr) {
+ perror("calloc");
+ return NULL;
+ }
+
+ myrr->ttl = 86400;
+ myrr->rdata = rdata;
+ myrr->changed = time(NULL);
+
+ TAILQ_INSERT_HEAD(&rrset->rr_head, myrr, entries);
+
+ return (rbt);
+}
+
+
+struct rbtree *
+find_rrset(ddDB *db, char *name, int len)
+{
+ static struct rbtree *rb;
+ ddDBT key, data;
+
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+
+ key.data = (char *)name;
+ key.size = len;
+
+ if (db->get(db, &key, &data) != 0) {
+ return (NULL);
+ }
+
+ if ((rb = calloc(1, sizeof(struct rbtree))) == NULL)
+ return NULL;
+
+ memcpy((char *)rb, (char *)data.data, sizeof(struct rbtree));
+
+ return (rb);
+}
+
+
+int
+add_rr(struct rbtree *rbt, char *name, int len, u_int16_t rrtype, void *rdata)
+{
+ struct rrset *rp0, *rp;
+ struct rr *rt;
+
+ TAILQ_FOREACH_SAFE(rp, &rbt->rrset_head, entries, rp0) {
+ if (rrtype == rp->rrtype)
+ break;
+ }
+
+ if (rp == NULL) {
+ /* the rrset doesn't exist, create it */
+ rp = (struct rrset *)calloc(1, sizeof(struct rrset));
+ if (! rp) {
+ perror("calloc");
+ return -1;
+ }
+
+ rp->rrtype = rrtype;
+ TAILQ_INIT(&rp->rr_head);
+
+ TAILQ_INSERT_TAIL(&rbt->rrset_head, rp, entries);
+ }
+
+ rt = calloc(1, sizeof(struct rr));
+ if (rt == NULL) {
+ perror("calloc");
+ return -1;
+ }
+
+ rt->ttl = 86400;
+ rt->changed = time(NULL);
+ rt->rdata = rdata;
+
+ TAILQ_INSERT_HEAD(&rp->rr_head, rt, entries);
+
+ return 0;
+}
+
+struct rrset *
+find_rr(struct rbtree *rbt, u_int16_t rrtype)
+{
+ struct rrset *rp, *rp0;
+
+ TAILQ_FOREACH_SAFE(rp, &rbt->rrset_head, entries, rp0) {
+ if (rrtype == rp->rrtype)
+ break;
+ }
+
+ return (rp);
+}
+
+int
+display_rr(struct rrset *rrset)
+{
+ struct rr *rrp, *rrp0;
+
+ TAILQ_FOREACH_SAFE(rrp, &rrset->rr_head, entries, rrp0) {
+ printf("%lld:%u:%s\n", rrp->changed, rrp->ttl, (char *)rrp->rdata);
+ }
+
+ return 0;
+}
+
+int
+rotate_rr(struct rrset *rrset)
+{
+ struct rr *rrp;
+
+ rrp = TAILQ_LAST(&rrset->rr_head, rrh);
+ if (rrp == NULL)
+ return -1;
+
+ TAILQ_REMOVE(&rrset->rr_head, rrp, entries);
+ TAILQ_INSERT_HEAD(&rrset->rr_head, rrp, entries);
+
return 0;
}
blob - 076711ffc658423ca7eb7855f0a9816b228fb5ea
blob + 9235cfdfd4f5b2c6189db5b8e58ba0b84197571a
--- ddd-db.h
+++ ddd-db.h
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ddd-db.h,v 1.12 2019/02/07 16:06:47 pjp Exp $
+ * $Id: ddd-db.h,v 1.13 2019/02/15 15:11:34 pjp Exp $
*/
#ifndef _DB_H
@@ -57,26 +57,6 @@
#define RECORD_COUNT 20
#define NEGATIVE_CACHE_TIME 600 /* DNS & Bind 3rd edition page 35 */
-#define INTERNAL_TYPE_SOA 0
-#define INTERNAL_TYPE_A 1
-#define INTERNAL_TYPE_AAAA 2
-#define INTERNAL_TYPE_MX 3
-#define INTERNAL_TYPE_NS 4
-#define INTERNAL_TYPE_CNAME 5
-#define INTERNAL_TYPE_PTR 6
-#define INTERNAL_TYPE_TXT 7
-#define INTERNAL_TYPE_SRV 8
-#define INTERNAL_TYPE_SSHFP 9
-#define INTERNAL_TYPE_NAPTR 10
-#define INTERNAL_TYPE_DNSKEY 11
-#define INTERNAL_TYPE_DS 12
-#define INTERNAL_TYPE_NSEC 13
-#define INTERNAL_TYPE_RRSIG 14
-#define INTERNAL_TYPE_NSEC3 15
-#define INTERNAL_TYPE_NSEC3PARAM 16
-#define INTERNAL_TYPE_TLSA 17
-#define INTERNAL_TYPE_MAX 18
-
/* db stuff */
struct dnskey {
@@ -87,9 +67,9 @@ struct dnskey {
u_int8_t algorithm; /* would be 5, RFC 3110 */
char public_key[4096];
u_int16_t publickey_len;
+ u_int32_t ttl;
} __attribute__((packed));
-
struct rrsig {
u_int16_t type_covered;
u_int8_t algorithm; /* usually 5, RFC3110 */
@@ -102,13 +82,25 @@ struct rrsig {
u_int8_t signame_len;
char signature[4096];
u_int16_t signature_len;
+ u_int32_t ttl;
+ int used; /* if this RRSIG is used at all */
} __attribute__((packed));
+#if 0
+struct rrsig {
+ struct internal_rrsig internal[3];
+#define RRSIG_RRSET 0
+#define RRSIG_DNSKEY 1
+#define RRSIG_DS 2
+} __attribute__((packed));
+#endif
+
struct nsec {
char next_domain_name[DNS_MAXNAME];
u_int8_t ndn_len; /* next domain name length */
char bitmap[8192];
u_int16_t bitmap_len;
+ u_int32_t ttl;
} __attribute__((packed));
struct nsec3 {
@@ -121,6 +113,7 @@ struct nsec3 {
u_int8_t nextlen; /* next domain name length */
char bitmap[8192];
u_int16_t bitmap_len;
+ u_int32_t ttl;
} __attribute__((packed));
struct nsec3param {
@@ -129,6 +122,7 @@ struct nsec3param {
u_int16_t iterations;
u_int8_t saltlen;
char salt[256];
+ u_int32_t ttl;
} __attribute__((packed));
struct ds {
@@ -137,6 +131,7 @@ struct ds {
u_int8_t digest_type;
char digest[4096];
u_int16_t digestlen;
+ u_int32_t ttl;
} __attribute__((packed));
@@ -150,17 +145,24 @@ struct soa {
u_int32_t retry;
u_int32_t expire;
u_int32_t minttl;
+ u_int32_t ttl;
} __attribute__((packed));
struct smx {
u_int16_t preference; /* MX preference */
char exchange[DNS_MAXNAME]; /* name of exchange server */
int exchangelen; /* length of exchange server name */
+ u_int32_t ttl;
} __attribute__((packed));
struct ns {
char nsserver[DNS_MAXNAME]; /* NS name */
int nslen; /* length of NS */
+ int ns_type; /* set if it's a delegation */
+#define NS_TYPE_DELEGATE 0x1
+#define NS_TYPE_HINT 0x2
+ u_int32_t ttl;
+
} __attribute__((packed));
struct srv {
@@ -169,6 +171,7 @@ struct srv {
u_int16_t port; /* 16 bit port */
char target[DNS_MAXNAME]; /* SRV target name */
int targetlen; /* SRV target name length */
+ u_int32_t ttl;
} __attribute__((packed));
struct sshfp {
@@ -176,6 +179,7 @@ struct sshfp {
u_int8_t fptype; /* SSHFP fingerprint type */
char fingerprint[DNS_MAXNAME]; /* fingerprint */
int fplen; /* fingerprint length */
+ u_int32_t ttl;
} __attribute__((packed));
struct tlsa {
@@ -184,6 +188,7 @@ struct tlsa {
u_int8_t matchtype; /* TLSA matching type */
char data[DNS_MAXNAME]; /* TLSA data */
int datalen; /* data length */
+ u_int32_t ttl;
} __attribute__((packed));
struct naptr {
@@ -197,176 +202,39 @@ struct naptr {
int regexplen; /* regexp len */
char replacement[DNS_MAXNAME]; /* replacement this is a domain */
int replacementlen;
+ u_int32_t ttl;
} __attribute__((packed));
-struct domain {
- u_int16_t type;
- u_int32_t len;
- char zone[DNS_MAXNAME]; /* name of zone in dns name format */
- int zonelen; /* length of zone, above */
- char zonename[DNS_MAXNAME + 1]; /* name of zone in human readable */
- u_int64_t flags; /* flags of zone */
-#define DOMAIN_HAVE_A 0x1
-#define DOMAIN_HAVE_SOA 0x2
-#define DOMAIN_HAVE_CNAME 0x4
-#define DOMAIN_HAVE_PTR 0x8
-#define DOMAIN_HAVE_MX 0x10
-#define DOMAIN_HAVE_AAAA 0x20
-#define DOMAIN_HAVE_NS 0x40
-#define DOMAIN_HAVE_TXT 0x80
-#define DOMAIN_HAVE_SRV 0x100
-#define DOMAIN_HAVE_SSHFP 0x200
-#define DOMAIN_HAVE_NAPTR 0x400
-#define DOMAIN_HAVE_DNSKEY 0x800
-#define DOMAIN_HAVE_DS 0x1000
-#define DOMAIN_HAVE_NSEC 0x2000
-#define DOMAIN_HAVE_RRSIG 0x4000
-#define DOMAIN_HAVE_NSEC3 0x8000
-#define DOMAIN_HAVE_NSEC3PARAM 0x10000
-#define DOMAIN_HAVE_TLSA 0x20000
- u_int32_t ttl[INTERNAL_TYPE_MAX]; /* time to lives */
- time_t created; /* time created, for dynamic zones */
+struct cname {
+ char cname[DNS_MAXNAME]; /* CNAME RR */
+ int cnamelen; /* len of CNAME */
+ u_int32_t ttl;
} __attribute__((packed));
-struct domain_generic {
- u_int16_t type;
- u_int32_t len;
+struct ptr {
+ char ptr[DNS_MAXNAME]; /* PTR RR */
+ int ptrlen; /* len of PTR */
+ u_int32_t ttl;
} __attribute__((packed));
-struct domain_soa {
- u_int16_t type;
- u_int32_t len;
- struct soa soa; /* start of authority */
+struct txt {
+ char txt[DNS_MAXNAME]; /* TXT string */
+ int txtlen; /* len of TXT */
+ u_int32_t ttl;
} __attribute__((packed));
-struct domain_rrsig {
- u_int16_t type;
- u_int32_t len;
- struct rrsig rrsig[INTERNAL_TYPE_MAX * 2]; /* rrsig RR */
- int rrsig_count; /* how many ZSK's */
- struct rrsig rrsig_dnskey[RECORD_COUNT];/* hack around dnskeys */
- int rrsig_dnskey_count; /* RRSIG count */
+struct a {
+ in_addr_t a; /* IP addresses */
+ u_int32_t ttl;
} __attribute__((packed));
-
-struct domain_a {
- u_int16_t type;
- u_int32_t len;
- in_addr_t a[RECORD_COUNT]; /* IP addresses */
- u_int8_t region[RECORD_COUNT]; /* region of IP address */
- int a_ptr; /* pointer to last used address */
- int a_count; /* IP address count (max 10) */
+struct aaaa {
+ struct in6_addr aaaa; /* IPv6 addresses */
+ u_int32_t ttl;
} __attribute__((packed));
-struct domain_aaaa {
- u_int16_t type;
- u_int32_t len;
- struct in6_addr aaaa[RECORD_COUNT]; /* IPv6 addresses */
- int aaaa_count; /* IPv6 address count (max 10) */
- int aaaa_ptr; /* pointer to last used IPv6 address */
-} __attribute__((packed));
-struct domain_mx {
- u_int16_t type;
- u_int32_t len;
- struct smx mx[RECORD_COUNT]; /* MX addresses */
- int mx_count; /* MX address count, max 10 */
- int mx_ptr; /* pointer to last used MX adddress */
-} __attribute__((packed));
-struct domain_ns {
- u_int16_t type;
- u_int32_t len;
- struct ns ns[RECORD_COUNT]; /* NS resource records (max 10) */
- int ns_count; /* count of NS records, (max 10) */
- int ns_ptr; /* pointer to last used NS address */
- int ns_type; /* set if it's a delegation */
-#define NS_TYPE_DELEGATE 0x1
-#define NS_TYPE_HINT 0x2
-} __attribute__((packed));
-
-struct domain_cname {
- u_int16_t type;
- u_int32_t len;
- char cname[DNS_MAXNAME]; /* CNAME RR */
- int cnamelen; /* len of CNAME */
-} __attribute__((packed));
-
-struct domain_ptr {
- u_int16_t type;
- u_int32_t len;
- char ptr[DNS_MAXNAME]; /* PTR RR */
- int ptrlen; /* len of PTR */
-} __attribute__((packed));
-
-struct domain_txt {
- u_int16_t type;
- u_int32_t len;
- char txt[DNS_MAXNAME]; /* TXT string */
- int txtlen; /* len of TXT */
-} __attribute__((packed));
-
-struct domain_srv {
- u_int16_t type;
- u_int32_t len;
- struct srv srv[RECORD_COUNT]; /* SRV resource record */
- int srv_count; /* count of SRV RR */
-} __attribute__((packed));
-
-struct domain_sshfp {
- u_int16_t type;
- u_int32_t len;
- struct sshfp sshfp[RECORD_COUNT]; /* SSHFP resource record */
- int sshfp_count; /* SSHFP RR count */
-} __attribute__((packed));
-
-struct domain_tlsa {
- u_int16_t type;
- u_int32_t len;
- struct tlsa tlsa[RECORD_COUNT]; /* TLSA resource record */
- int tlsa_count; /* TLSA RR count */
-} __attribute__((packed));
-
-struct domain_naptr {
- u_int16_t type;
- u_int32_t len;
- struct naptr naptr[RECORD_COUNT]; /* NAPTR RR, eek 20K! */
- int naptr_count;
-} __attribute__((packed));
-
-struct domain_dnskey {
- u_int16_t type;
- u_int32_t len;
- struct dnskey dnskey[RECORD_COUNT]; /* DNSKEY RR */
- int dnskey_count; /* count of DNSKEY */
-} __attribute__((packed));
-
-struct domain_nsec {
- u_int16_t type;
- u_int32_t len;
- struct nsec nsec; /* NSEC RR */
-} __attribute__((packed));
-
-struct domain_nsec3 {
- u_int16_t type;
- u_int32_t len;
- struct nsec3 nsec3; /* NSEC3 RR */
-} __attribute__((packed));
-
-struct domain_nsec3param {
- u_int16_t type;
- u_int32_t len;
- struct nsec3param nsec3param; /* NSEC3PARAM RR */
-} __attribute__((packed));
-
-struct domain_ds {
- u_int16_t type;
- u_int32_t len;
- struct ds ds[RECORD_COUNT]; /* DS RR */
- int ds_count; /* count of DS */
-} __attribute__((packed));
-
-
struct sreply {
int so; /* socket */
char *buf; /* question packet */
@@ -374,8 +242,8 @@ struct sreply {
struct question *q; /* struct question */
struct sockaddr *sa; /* struct sockaddr of question */
int salen; /* length of struct sockaddr */
- struct domain *sd1; /* first resolved domain */
- struct domain *sd2; /* CNAME to second resolved domain */
+ struct rbtree *rbt1; /* first resolved domain */
+ struct rbtree *rbt2; /* CNAME to second resolved domain */
u_int8_t region; /* region of question */
int istcp; /* when set it's tcp */
int wildcard; /* wildcarding boolean */
@@ -383,59 +251,7 @@ struct sreply {
char *replybuf; /* reply buffer */
};
-struct srecurseheader {
- int af; /* address family */
- int proto; /* protocol UDP/TCP */
- struct sockaddr_storage source; /* source + port */
- struct sockaddr_storage dest; /* dest + port */
- int len; /* length of question */
- char buf[512]; /* question buffer */
-};
-
-SLIST_HEAD(listhead2, recurses) recurseshead;
-
-struct recurses {
- char query[512]; /* the query we received */
- int len; /* length of query */
-
- int isfake; /* received or faked */
- int launched; /* is launched */
- int replied; /* we replied to this question */
- int packetcount; /* packet count of requests */
- int af; /* address family */
- int proto; /* protocol UDP/TCP */
- struct sockaddr_storage source; /* source + port */
- struct sockaddr_storage dest; /* dest + port */
-
- time_t received; /* received request time */
- time_t sent_last_query; /* the last time we did a lookup */
-
- char upperlower[32]; /* uppercase / lowercase bitmap */
- int so; /* the socket we did a lookup with */
- u_short port; /* port used on outgoing */
- u_int16_t id; /* last id used */
-
- /* the below get loaded from the database upon each lookup */
- in_addr_t a[RECORD_COUNT]; /* IPv4 addresses of nameservers */
- int a_count; /* IPv4 address count */
- int a_ptr; /* pointer to last used address */
- struct in6_addr aaaa[RECORD_COUNT]; /* IPv6 addresses of nameservers */
- int aaaa_count; /* IPv6 address count */
- int aaaa_ptr; /* pointer to last used IPv6 address */
-
- /* the below is our indicator which part of the lookup we're at */
-
- u_char *lookrecord; /* what zone lookup is it from */
- int indicator; /* indicator of ns lookup */
- int authoritative; /* last reply was authoritative, type */
- int hascallback; /* some request has callback don't remove */
-
- struct question *question; /* question struct */
- SLIST_ENTRY(recurses) recurses_entry;
- struct recurses *callback; /* callback */
-} *sr, *sr1, *sr2;
-
struct logging {
int active;
char *hostname;
@@ -475,20 +291,31 @@ typedef struct __dddb {
} ddDB;
-#define SIZENODE ( sizeof(struct domain) + sizeof(struct domain_soa) + \
- sizeof(struct domain_rrsig) + sizeof(struct domain_a) + \
- sizeof(struct domain_aaaa) + sizeof(struct domain_mx) + \
- sizeof(struct domain_ns) + sizeof(struct domain_cname) + \
- sizeof(struct domain_ptr) + sizeof(struct domain_txt) + \
- sizeof(struct domain_srv) + sizeof(struct domain_sshfp) + \
- sizeof(struct domain_tlsa) + sizeof(struct domain_naptr) + \
- sizeof(struct domain_dnskey) + sizeof(struct domain_nsec) + \
- sizeof(struct domain_nsec3) + \
- sizeof(struct domain_nsec3param) + sizeof(struct domain_ds) )
+struct rr {
+ void *rdata;
+ u_int32_t ttl;
+ time_t changed;
+ TAILQ_ENTRY(rr) entries;
+};
+struct rrset {
+ u_int16_t rrtype;
+ TAILQ_ENTRY(rrset) entries;
+ TAILQ_HEAD(rrh, rr) rr_head;
+};
+
+
+struct rbtree {
+ char zone[DNS_MAXNAME];
+ int zonelen;
+ char humanname[DNS_MAXNAME + 1];
+
+ TAILQ_HEAD(, rrset) rrset_head;
+};
+
struct node {
RB_ENTRY(node) rbentry; /* the node entry */
- char domainname[256]; /* domain name key name */
+ char domainname[DNS_MAXNAME + 1]; /* domain name key name */
int len; /* length of domain name */
char *data; /* data it points to */
size_t datalen; /* the length of the data */
blob - e02173885ed49a3119c0e6a1fa3125d561db51e9
blob + 371539c5c702e2c8b934dbaabc630ed9aa9ecedd
--- dddctl.c
+++ dddctl.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: dddctl.c,v 1.47 2019/02/09 07:50:06 pjp Exp $
+ * $Id: dddctl.c,v 1.48 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
@@ -94,22 +94,22 @@ char * alg_to_name(int);
int alg_to_rsa(int);
int construct_nsec3(ddDB *, char *, int, char *);
int calculate_rrsigs(ddDB *, char *, int);
-int sign_dnskey(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_a(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_mx(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_ns(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_srv(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_cname(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_soa(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_txt(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_aaaa(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_ptr(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_nsec3(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_nsec3param(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_naptr(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_sshfp(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_tlsa(ddDB *, char *, struct keysentry *, int, struct domain *);
-int sign_ds(ddDB *, char *, struct keysentry *, int, struct domain *);
+int sign_dnskey(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_a(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_mx(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_ns(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_srv(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_cname(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_soa(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_txt(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_aaaa(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_ptr(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_nsec3(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_nsec3param(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_naptr(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_sshfp(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_tlsa(ddDB *, char *, struct keysentry *, int, struct rbtree *);
+int sign_ds(ddDB *, char *, struct keysentry *, int, struct rbtree *);
int create_ds(ddDB *, char *, struct keysentry *);
u_int keytag(u_char *key, u_int keysize);
void pack(char *, char *, int);
@@ -122,8 +122,8 @@ int store_private_key(struct keysentry *, char *, int,
u_int64_t timethuman(time_t);
char * bitmap2human(char *, int);
char * bin2hex(char *, int);
-int print_sd(FILE *, struct domain *);
-int print_sd_bind(FILE *, struct domain *);
+int print_rbt(FILE *, struct rbtree *);
+int print_rbt_bind(FILE *, struct rbtree *);
int usage(int argc, char *argv[]);
int start(int argc, char *argv[]);
int restart(int argc, char *argv[]);
@@ -245,10 +245,9 @@ extern char * convert_name(char *name, int namelen);
extern int mybase64_encode(u_char const *, size_t, char *, size_t);
extern int mybase64_decode(char const *, u_char *, size_t);
-extern struct domain * lookup_zone(ddDB *, struct question *, int *, int *, char *);
+extern struct rbtree * lookup_zone(ddDB *, struct question *, int *, int *, char *);
extern struct question *build_fake_question(char *, int, u_int16_t);
extern char * dns_label(char *, int *);
-extern void * find_substruct(struct domain *, u_int16_t);
extern int label_count(char *);
extern char *get_dns_type(int, int);
extern char * hash_name(char *, int, struct nsec3param *);
@@ -259,6 +258,10 @@ extern struct question *build_question(char *
extern int free_question(struct question *);
struct rrtab *rrlookup(char *);
+extern struct rbtree * create_rr(ddDB *db, char *name, int len, int type, void *rdata);
+extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
+extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+extern int add_rr(struct rbtree *rbt, char *name, int len, u_int16_t rrtype, void *rdata);
extern int raxfr_a(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t);
extern int raxfr_tlsa(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t);
@@ -1001,7 +1004,7 @@ dump_db(ddDB *db, FILE *of, char *zonename)
struct node *n, *nx;
struct question *q;
- struct domain *sdomain;
+ struct rbtree *rbt;
char replystring[512];
char *dnsname;
@@ -1022,12 +1025,12 @@ dump_db(ddDB *db, FILE *of, char *zonename)
return -1;
}
- if ((sdomain = lookup_zone(db, q, &retval, &lzerrno, (char *)&replystring)) == NULL) {
+ if ((rbt = lookup_zone(db, q, &retval, &lzerrno, (char *)&replystring)) == NULL) {
return -1;
}
- if (print_sd(of, sdomain) < 0) {
- fprintf(stderr, "print_sd error\n");
+ if (print_rbt(of, rbt) < 0) {
+ fprintf(stderr, "print_rbt error\n");
return -1;
}
@@ -1037,24 +1040,24 @@ dump_db(ddDB *db, FILE *of, char *zonename)
j = 0;
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
rs = n->datalen;
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sdomain, (char *)n->data, n->datalen);
+ memcpy((char *)rbt, (char *)n->data, n->datalen);
- if (strcmp(sdomain->zonename, zonename) == 0) {
- free(sdomain);
+ if (strcmp(rbt->humanname, zonename) == 0) {
+ free(rbt);
continue;
}
- if (print_sd(of, sdomain) < 0) {
- fprintf(stderr, "print_sd error\n");
+ if (print_rbt(of, rbt) < 0) {
+ fprintf(stderr, "print_rbt error\n");
return -1;
}
- free(sdomain);
+ free(rbt);
j++;
}
@@ -1382,7 +1385,8 @@ calculate_rrsigs(ddDB *db, char *zonename, int expiry)
{
struct keysentry *zsk_key = NULL;
struct node *n, *nx;
- struct domain *sd;
+ struct rbtree *rbt;
+ struct rrset *rrset = NULL;
int j, rs;
time_t now, twoweeksago;
@@ -1417,96 +1421,112 @@ calculate_rrsigs(ddDB *db, char *zonename, int expiry)
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
rs = n->datalen;
- if ((sd = calloc(1, rs)) == NULL) {
+ if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sd, (char *)n->data, n->datalen);
+ memcpy((char *)rbt, (char *)n->data, n->datalen);
- if (sd->flags & DOMAIN_HAVE_DNSKEY)
- if (sign_dnskey(db, zonename, zsk_key, expiry, sd) < 0) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
+ if (sign_dnskey(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_dnskey error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_A)
- if (sign_a(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) != NULL) {
+ if (sign_a(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_a error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_MX)
- if (sign_mx(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) != NULL) {
+ if (sign_mx(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_mx error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_NS)
- if (sign_ns(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
+ if (sign_ns(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_ns error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_SOA)
- if (sign_soa(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
+ if (sign_soa(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_soa error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_TXT)
- if (sign_txt(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) != NULL) {
+ if (sign_txt(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_txt error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_AAAA)
- if (sign_aaaa(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) != NULL) {
+ if (sign_aaaa(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_aaaa error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_NSEC3)
- if (sign_nsec3(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
+ if (sign_nsec3(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_nsec3 error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_NSEC3PARAM)
- if (sign_nsec3param(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) != NULL) {
+ if (sign_nsec3param(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_nsec3param error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_CNAME)
- if (sign_cname(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_CNAME)) != NULL) {
+ if (sign_cname(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_cname error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_PTR)
- if (sign_ptr(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) != NULL) {
+ if (sign_ptr(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_ptr error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_NAPTR)
- if (sign_naptr(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) != NULL) {
+ if (sign_naptr(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_naptr error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_SRV)
- if (sign_srv(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) != NULL) {
+ if (sign_srv(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_srv error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_SSHFP)
- if (sign_sshfp(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) != NULL) {
+ if (sign_sshfp(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_sshfp error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_TLSA)
- if (sign_tlsa(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) != NULL) {
+ if (sign_tlsa(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_tlsa error\n");
return -1;
}
- if (sd->flags & DOMAIN_HAVE_DS)
- if (sign_ds(db, zonename, zsk_key, expiry, sd) < 0) {
+ }
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
+ if (sign_ds(db, zonename, zsk_key, expiry, rbt) < 0) {
fprintf(stderr, "sign_ds error\n");
return -1;
}
+ }
- free(sd);
+ free(rbt);
j++;
}
@@ -1519,9 +1539,10 @@ calculate_rrsigs(ddDB *db, char *zonename, int expiry)
*/
int
-sign_soa(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_soa(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_soa *sdsoa = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char tmp[4096];
char signature[4096];
@@ -1586,7 +1607,7 @@ sign_soa(ddDB *db, char *zonename, struct keysentry *z
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -1596,11 +1617,15 @@ sign_soa(ddDB *db, char *zonename, struct keysentry *z
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_SOA) {
- if ((sdsoa = (struct domain_soa *)find_substruct(sd, INTERNAL_TYPE_SOA)) == NULL) {
- dolog(LOG_INFO, "no SOA records but have flags!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
+ dolog(LOG_INFO, "no SOA records but have rrset entry!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no SOA records\n");
+ return -1;
}
p = key;
@@ -1611,7 +1636,7 @@ sign_soa(ddDB *db, char *zonename, struct keysentry *z
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_SOA]));
+ pack32(p, htonl(((struct soa *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -1633,30 +1658,30 @@ sign_soa(ddDB *db, char *zonename, struct keysentry *z
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- pack(p, sd->zone, sd->zonelen);
- p += sd->zonelen;
+ pack(p, rbt->zone, rbt->zonelen);
+ p += rbt->zonelen;
pack16(p, htons(DNS_TYPE_SOA));
p += 2;
pack16(p, htons(DNS_CLASS_IN));
p += 2;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_SOA]));
+ pack32(p, htonl(((struct soa *)rrp->rdata)->ttl));
p += 4;
- pack16(p, htons(sdsoa->soa.nsserver_len + sdsoa->soa.rp_len + 4 + 4 + 4 + 4 + 4));
+ pack16(p, htons(((struct soa *)rrp->rdata)->nsserver_len + ((struct soa *)rrp->rdata)->rp_len + 4 + 4 + 4 + 4 + 4));
p += 2;
- pack(p, sdsoa->soa.nsserver, sdsoa->soa.nsserver_len);
- p += sdsoa->soa.nsserver_len;
- pack(p, sdsoa->soa.responsible_person, sdsoa->soa.rp_len);
- p += sdsoa->soa.rp_len;
- pack32(p, htonl(sdsoa->soa.serial));
- p += 4;
- pack32(p, htonl(sdsoa->soa.refresh));
- p += 4;
- pack32(p, htonl(sdsoa->soa.retry));
- p += 4;
- pack32(p, htonl(sdsoa->soa.expire));
- p += 4;
- pack32(p, htonl(sdsoa->soa.minttl));
- p += 4;
+ pack(p, ((struct soa *)rrp->rdata)->nsserver, ((struct soa *)rrp->rdata)->nsserver_len);
+ p += ((struct soa *)rrp->rdata)->nsserver_len;
+ pack(p, ((struct soa *)rrp->rdata)->responsible_person, ((struct soa *)rrp->rdata)->rp_len);
+ p += ((struct soa *)rrp->rdata)->rp_len;
+ pack32(p, htonl(((struct soa *)rrp->rdata)->serial));
+ p += sizeof(u_int32_t);
+ pack32(p, htonl(((struct soa *)rrp->rdata)->refresh));
+ p += sizeof(u_int32_t);
+ pack32(p, htonl(((struct soa *)rrp->rdata)->retry));
+ p += sizeof(u_int32_t);
+ pack32(p, htonl(((struct soa *)rrp->rdata)->expire));
+ p += sizeof(u_int32_t);
+ pack32(p, htonl(((struct soa *)rrp->rdata)->minttl));
+ p += sizeof(u_int32_t);
keylen = (p - key);
@@ -1710,7 +1735,7 @@ sign_soa(ddDB *db, char *zonename, struct keysentry *z
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_SOA], "SOA", algorithm, labels, sd->ttl[INTERNAL_TYPE_SOA], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct soa *)rrp->rdata)->ttl, "SOA", algorithm, labels, ((struct soa *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -1723,9 +1748,10 @@ sign_soa(ddDB *db, char *zonename, struct keysentry *z
*/
int
-sign_txt(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_txt(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_txt *sdtxt = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char tmp[4096];
char signature[4096];
@@ -1790,7 +1816,7 @@ sign_txt(ddDB *db, char *zonename, struct keysentry *z
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -1800,11 +1826,15 @@ sign_txt(ddDB *db, char *zonename, struct keysentry *z
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_TXT) {
- if ((sdtxt = (struct domain_txt *)find_substruct(sd, INTERNAL_TYPE_TXT)) == NULL) {
- dolog(LOG_INFO, "no TXT records but have flags!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
+ dolog(LOG_INFO, "no TXT records but have rrset entry!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no TXT records\n");
+ return -1;
}
p = key;
@@ -1815,8 +1845,8 @@ sign_txt(ddDB *db, char *zonename, struct keysentry *z
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_TXT]));
- p += 4;
+ pack32(p, htonl(((struct txt *)rrp->rdata)->ttl));
+ p += sizeof(u_int32_t);
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
strptime(timebuf, "%Y%m%d%H%M%S", &tm);
@@ -1837,20 +1867,20 @@ sign_txt(ddDB *db, char *zonename, struct keysentry *z
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- pack(p, sd->zone, sd->zonelen);
- p += sd->zonelen;
+ pack(p, rbt->zone, rbt->zonelen);
+ p += rbt->zonelen;
pack16(p, htons(DNS_TYPE_TXT));
p += 2;
pack16(p, htons(DNS_CLASS_IN));
p += 2;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_TXT]));
+ pack32(p, htonl(((struct txt *)rrp->rdata)->ttl));
p += 4;
- pack16(p, htons(sdtxt->txtlen + 1));
+ pack16(p, htons(((struct txt *)rrp->rdata)->txtlen + 1));
p += 2;
- pack8(p, sdtxt->txtlen);
+ pack8(p, ((struct txt *)rrp->rdata)->txtlen);
p++;
- pack(p, sdtxt->txt, sdtxt->txtlen);
- p += sdtxt->txtlen;
+ pack(p, ((struct txt *)rrp->rdata)->txt, ((struct txt *)rrp->rdata)->txtlen);
+ p += ((struct txt *)rrp->rdata)->txtlen;
keylen = (p - key);
@@ -1903,7 +1933,7 @@ sign_txt(ddDB *db, char *zonename, struct keysentry *z
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_TXT], "TXT", algorithm, labels, sd->ttl[INTERNAL_TYPE_TXT], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct txt *)rrp->rdata)->ttl, "TXT", algorithm, labels, ((struct txt *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -1914,11 +1944,12 @@ sign_txt(ddDB *db, char *zonename, struct keysentry *z
/*
* create a RRSIG for an AAAA record
*/
-
int
-sign_aaaa(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_aaaa(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_aaaa *sdaaaa = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -1938,7 +1969,7 @@ sign_aaaa(ddDB *db, char *zonename, struct keysentry *
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -1997,7 +2028,7 @@ sign_aaaa(ddDB *db, char *zonename, struct keysentry *
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -2007,11 +2038,15 @@ sign_aaaa(ddDB *db, char *zonename, struct keysentry *
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_AAAA) {
- if ((sdaaaa = (struct domain_aaaa *)find_substruct(sd, INTERNAL_TYPE_AAAA)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no AAAA records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no AAAA records\n");
+ return -1;
}
p = key;
@@ -2022,7 +2057,7 @@ sign_aaaa(ddDB *db, char *zonename, struct keysentry *
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_AAAA]));
+ pack32(p, htonl(((struct aaaa *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -2043,19 +2078,20 @@ sign_aaaa(ddDB *db, char *zonename, struct keysentry *
/* no signature here */
- for (i = 0; i < sdaaaa->aaaa_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_AAAA));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_AAAA]));
+ /* the below uses rrp! because we can't have an rrsig differ */
+ pack32(q, htonl(((struct aaaa *)rrp->rdata)->ttl));
q += 4;
pack16(q, htons(sizeof(struct in6_addr)));
q += 2;
- pack(q, (char *)&sdaaaa->aaaa[i], sizeof(struct in6_addr));
+ pack(q, (char *)&((struct aaaa *)rrp2->rdata)->aaaa, sizeof(struct in6_addr));
q += sizeof(struct in6_addr);
c1 = malloc(sizeof(struct canonical));
@@ -2153,7 +2189,7 @@ sign_aaaa(ddDB *db, char *zonename, struct keysentry *
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_AAAA], "AAAA", algorithm, labels, sd->ttl[INTERNAL_TYPE_AAAA], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct aaaa *)rrp->rdata)->ttl, "AAAA", algorithm, labels, ((struct aaaa *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -2166,9 +2202,10 @@ sign_aaaa(ddDB *db, char *zonename, struct keysentry *
*/
int
-sign_nsec3(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_nsec3(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_nsec3 *sdnsec3 = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char tmp[4096];
char signature[4096];
@@ -2233,7 +2270,7 @@ sign_nsec3(ddDB *db, char *zonename, struct keysentry
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -2243,11 +2280,15 @@ sign_nsec3(ddDB *db, char *zonename, struct keysentry
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_NSEC3) {
- if ((sdnsec3 = (struct domain_nsec3 *)find_substruct(sd, INTERNAL_TYPE_NSEC3)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no NSEC3 records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no NSEC3 records\n");
+ return -1;
}
p = key;
@@ -2258,7 +2299,7 @@ sign_nsec3(ddDB *db, char *zonename, struct keysentry
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_NSEC3]));
+ pack32(p, htonl(((struct nsec3 *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -2280,38 +2321,38 @@ sign_nsec3(ddDB *db, char *zonename, struct keysentry
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- pack(p, sd->zone, sd->zonelen);
- p += sd->zonelen;
+ pack(p, rbt->zone, rbt->zonelen);
+ p += rbt->zonelen;
pack16(p, htons(DNS_TYPE_NSEC3));
p += 2;
pack16(p, htons(DNS_CLASS_IN));
p += 2;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_NSEC3]));
+ pack32(p, htonl(((struct nsec3 *)rrp->rdata)->ttl));
p += 4;
- pack16(p, htons(1 + 1 + 2 + 1 + sdnsec3->nsec3.saltlen + 1 + sdnsec3->nsec3.nextlen + sdnsec3->nsec3.bitmap_len));
+ pack16(p, htons(1 + 1 + 2 + 1 + ((struct nsec3 *)rrp->rdata)->saltlen + 1 + ((struct nsec3 *)rrp->rdata)->nextlen + ((struct nsec3 *)rrp->rdata)->bitmap_len));
p += 2;
- pack8(p, sdnsec3->nsec3.algorithm);
+ pack8(p, ((struct nsec3 *)rrp->rdata)->algorithm);
p++;
- pack8(p, sdnsec3->nsec3.flags);
+ pack8(p, ((struct nsec3 *)rrp->rdata)->flags);
p++;
- pack16(p, htons(sdnsec3->nsec3.iterations));
+ pack16(p, htons(((struct nsec3 *)rrp->rdata)->iterations));
p += 2;
- pack8(p, sdnsec3->nsec3.saltlen);
+ pack8(p, ((struct nsec3 *)rrp->rdata)->saltlen);
p++;
- if (sdnsec3->nsec3.saltlen) {
- pack(p, sdnsec3->nsec3.salt, sdnsec3->nsec3.saltlen);
- p += sdnsec3->nsec3.saltlen;
+ if (((struct nsec3 *)rrp->rdata)->saltlen) {
+ pack(p, ((struct nsec3 *)rrp->rdata)->salt, ((struct nsec3 *)rrp->rdata)->saltlen);
+ p += ((struct nsec3 *)rrp->rdata)->saltlen;
}
- pack8(p, sdnsec3->nsec3.nextlen);
+ pack8(p, ((struct nsec3 *)rrp->rdata)->nextlen);
p++;
- pack(p, sdnsec3->nsec3.next, sdnsec3->nsec3.nextlen);
- p += sdnsec3->nsec3.nextlen;
- pack(p, sdnsec3->nsec3.bitmap, sdnsec3->nsec3.bitmap_len);
- p += sdnsec3->nsec3.bitmap_len;
+ pack(p, ((struct nsec3 *)rrp->rdata)->next, ((struct nsec3 *)rrp->rdata)->nextlen);
+ p += ((struct nsec3 *)rrp->rdata)->nextlen;
+ pack(p, ((struct nsec3 *)rrp->rdata)->bitmap, ((struct nsec3 *)rrp->rdata)->bitmap_len);
+ p += ((struct nsec3 *)rrp->rdata)->bitmap_len;
keylen = (p - key);
@@ -2364,7 +2405,7 @@ sign_nsec3(ddDB *db, char *zonename, struct keysentry
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_NSEC3], "NSEC3", algorithm, labels, sd->ttl[INTERNAL_TYPE_NSEC3], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct nsec3 *)rrp->rdata)->ttl, "NSEC3", algorithm, labels, ((struct nsec3 *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -2378,9 +2419,10 @@ sign_nsec3(ddDB *db, char *zonename, struct keysentry
*/
int
-sign_nsec3param(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_nsec3param(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_nsec3param *sdnsec3 = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char tmp[4096];
char signature[4096];
@@ -2445,7 +2487,7 @@ sign_nsec3param(ddDB *db, char *zonename, struct keyse
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -2455,11 +2497,15 @@ sign_nsec3param(ddDB *db, char *zonename, struct keyse
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_NSEC3PARAM) {
- if ((sdnsec3 = (struct domain_nsec3param *)find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no NSEC3PARAM records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no NSEC3PARAM records\n");
+ return -1;
}
p = key;
@@ -2470,7 +2516,7 @@ sign_nsec3param(ddDB *db, char *zonename, struct keyse
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_NSEC3PARAM]));
+ pack32(p, htonl(((struct nsec3param *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -2492,29 +2538,29 @@ sign_nsec3param(ddDB *db, char *zonename, struct keyse
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- pack(p, sd->zone, sd->zonelen);
- p += sd->zonelen;
+ pack(p, rbt->zone, rbt->zonelen);
+ p += rbt->zonelen;
pack16(p, htons(DNS_TYPE_NSEC3PARAM));
p += 2;
pack16(p, htons(DNS_CLASS_IN));
p += 2;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_NSEC3PARAM]));
+ pack32(p, htonl(((struct nsec3param *)rrp->rdata)->ttl));
p += 4;
- pack16(p, htons(1 + 1 + 2 + 1 + sdnsec3->nsec3param.saltlen));
+ pack16(p, htons(1 + 1 + 2 + 1 + ((struct nsec3param *)rrp->rdata)->saltlen));
p += 2;
- pack8(p, sdnsec3->nsec3param.algorithm);
+ pack8(p, ((struct nsec3param *)rrp->rdata)->algorithm);
p++;
- pack8(p, sdnsec3->nsec3param.flags);
+ pack8(p, ((struct nsec3param *)rrp->rdata)->flags);
p++;
- pack16(p, htons(sdnsec3->nsec3param.iterations));
+ pack16(p, htons(((struct nsec3param *)rrp->rdata)->iterations));
p += 2;
- pack8(p, sdnsec3->nsec3param.saltlen);
+ pack8(p, ((struct nsec3param *)rrp->rdata)->saltlen);
p++;
- if (sdnsec3->nsec3param.saltlen) {
- pack(p, sdnsec3->nsec3param.salt, sdnsec3->nsec3param.saltlen);
- p += sdnsec3->nsec3param.saltlen;
+ if (((struct nsec3param *)rrp->rdata)->saltlen) {
+ pack(p, ((struct nsec3param *)rrp->rdata)->salt, ((struct nsec3param *)rrp->rdata)->saltlen);
+ p += ((struct nsec3param *)rrp->rdata)->saltlen;
}
keylen = (p - key);
@@ -2568,7 +2614,7 @@ sign_nsec3param(ddDB *db, char *zonename, struct keyse
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", 0, "NSEC3PARAM", algorithm, labels, 0, expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", 0, "NSEC3PARAM", algorithm, labels, 0, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -2581,9 +2627,10 @@ sign_nsec3param(ddDB *db, char *zonename, struct keyse
*/
int
-sign_cname(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_cname(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_cname *sdc = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char tmp[4096];
char signature[4096];
@@ -2648,7 +2695,7 @@ sign_cname(ddDB *db, char *zonename, struct keysentry
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -2658,11 +2705,16 @@ sign_cname(ddDB *db, char *zonename, struct keysentry
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_CNAME) {
- if ((sdc = (struct domain_cname *)find_substruct(sd, INTERNAL_TYPE_CNAME)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_CNAME)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no CNAME records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no CNAME records\n");
+ return -1;
+
}
p = key;
@@ -2673,7 +2725,7 @@ sign_cname(ddDB *db, char *zonename, struct keysentry
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_CNAME]));
+ pack32(p, htonl(((struct cname *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -2695,18 +2747,18 @@ sign_cname(ddDB *db, char *zonename, struct keysentry
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- pack(p, sd->zone, sd->zonelen);
- p += sd->zonelen;
+ pack(p, rbt->zone, rbt->zonelen);
+ p += rbt->zonelen;
pack16(p, htons(DNS_TYPE_CNAME));
p += 2;
pack16(p, htons(DNS_CLASS_IN));
p += 2;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_CNAME]));
+ pack32(p, htonl(((struct cname *)rrp->rdata)->ttl));
p += 4;
- pack16(p, htons(sdc->cnamelen));
+ pack16(p, htons(((struct cname *)rrp->rdata)->cnamelen));
p += 2;
- pack(p, sdc->cname, sdc->cnamelen);
- p += sdc->cnamelen;
+ pack(p, ((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen);
+ p += ((struct cname *)rrp->rdata)->cnamelen;
keylen = (p - key);
@@ -2759,7 +2811,7 @@ sign_cname(ddDB *db, char *zonename, struct keysentry
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_CNAME], "CNAME", algorithm, labels, sd->ttl[INTERNAL_TYPE_CNAME], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct cname *)rrp->rdata)->ttl, "CNAME", algorithm, labels, ((struct cname *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -2772,9 +2824,10 @@ sign_cname(ddDB *db, char *zonename, struct keysentry
*/
int
-sign_ptr(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_ptr(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_ptr *sdptr = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char tmp[4096];
char signature[4096];
@@ -2839,7 +2892,7 @@ sign_ptr(ddDB *db, char *zonename, struct keysentry *z
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -2849,12 +2902,17 @@ sign_ptr(ddDB *db, char *zonename, struct keysentry *z
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_PTR) {
- if ((sdptr = (struct domain_ptr *)find_substruct(sd, INTERNAL_TYPE_PTR)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no PTR records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no PTR records\n");
+ return -1;
}
+
p = key;
@@ -2864,7 +2922,7 @@ sign_ptr(ddDB *db, char *zonename, struct keysentry *z
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_PTR]));
+ pack32(p, htonl(((struct ptr *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -2886,18 +2944,18 @@ sign_ptr(ddDB *db, char *zonename, struct keysentry *z
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- pack(p, sd->zone, sd->zonelen);
- p += sd->zonelen;
+ pack(p, rbt->zone, rbt->zonelen);
+ p += rbt->zonelen;
pack16(p, htons(DNS_TYPE_PTR));
p += 2;
pack16(p, htons(DNS_CLASS_IN));
p += 2;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_PTR]));
+ pack32(p, htonl(((struct ptr *)rrp->rdata)->ttl));
p += 4;
- pack16(p, htons(sdptr->ptrlen));
+ pack16(p, htons(((struct ptr *)rrp->rdata)->ptrlen));
p += 2;
- pack(p, sdptr->ptr, sdptr->ptrlen);
- p += sdptr->ptrlen;
+ pack(p, ((struct ptr *)rrp->rdata)->ptr, ((struct ptr *)rrp->rdata)->ptrlen);
+ p += ((struct ptr *)rrp->rdata)->ptrlen;
keylen = (p - key);
@@ -2950,7 +3008,7 @@ sign_ptr(ddDB *db, char *zonename, struct keysentry *z
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_PTR], "PTR", algorithm, labels, sd->ttl[INTERNAL_TYPE_PTR], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct ptr *)rrp->rdata)->ttl, "PTR", algorithm, labels, ((struct ptr *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -2963,9 +3021,11 @@ sign_ptr(ddDB *db, char *zonename, struct keysentry *z
*/
int
-sign_naptr(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_naptr(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_naptr *sdnaptr = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -2985,7 +3045,7 @@ sign_naptr(ddDB *db, char *zonename, struct keysentry
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -3044,7 +3104,7 @@ sign_naptr(ddDB *db, char *zonename, struct keysentry
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -3054,11 +3114,15 @@ sign_naptr(ddDB *db, char *zonename, struct keysentry
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_NAPTR) {
- if ((sdnaptr = (struct domain_naptr *)find_substruct(sd, INTERNAL_TYPE_NAPTR)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no NAPTR records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no NAPTR records\n");
+ return -1;
}
p = key;
@@ -3069,7 +3133,7 @@ sign_naptr(ddDB *db, char *zonename, struct keysentry
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_NAPTR]));
+ pack32(p, htonl(((struct naptr *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -3091,40 +3155,40 @@ sign_naptr(ddDB *db, char *zonename, struct keysentry
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sdnaptr->naptr_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_NAPTR));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_NAPTR]));
+ pack32(q, htonl(((struct naptr *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(2 + 2 + 1 + sdnaptr->naptr[i].flagslen + 1 + sdnaptr->naptr[i].serviceslen + 1 + sdnaptr->naptr[i].regexplen + sdnaptr->naptr[i].replacementlen));
+ pack16(q, htons(2 + 2 + 1 + ((struct naptr *)rrp2->rdata)->flagslen + 1 + ((struct naptr *)rrp2->rdata)->serviceslen + 1 + ((struct naptr *)rrp2->rdata)->regexplen + ((struct naptr *)rrp2->rdata)->replacementlen));
q += 2;
- pack16(q, htons(sdnaptr->naptr[i].order));
+ pack16(q, htons(((struct naptr *)rrp2->rdata)->order));
q += 2;
- pack16(q, htons(sdnaptr->naptr[i].preference));
+ pack16(q, htons(((struct naptr *)rrp2->rdata)->preference));
q += 2;
- pack8(q, sdnaptr->naptr[i].flagslen);
+ pack8(q, ((struct naptr *)rrp2->rdata)->flagslen);
q++;
- pack(q, sdnaptr->naptr[i].flags, sdnaptr->naptr[i].flagslen);
- q += sdnaptr->naptr[i].flagslen;
+ pack(q, ((struct naptr *)rrp2->rdata)->flags, ((struct naptr *)rrp2->rdata)->flagslen);
+ q += ((struct naptr *)rrp2->rdata)->flagslen;
- pack8(q, sdnaptr->naptr[i].serviceslen);
+ pack8(q, ((struct naptr *)rrp2->rdata)->serviceslen);
q++;
- pack(q, sdnaptr->naptr[i].services, sdnaptr->naptr[i].serviceslen);
- q += sdnaptr->naptr[i].serviceslen;
+ pack(q, ((struct naptr *)rrp2->rdata)->services, ((struct naptr *)rrp2->rdata)->serviceslen);
+ q += ((struct naptr *)rrp2->rdata)->serviceslen;
- pack8(q, sdnaptr->naptr[i].regexplen);
+ pack8(q, ((struct naptr *)rrp2->rdata)->regexplen);
q++;
- pack(q, sdnaptr->naptr[i].regexp, sdnaptr->naptr[i].regexplen);
- q += sdnaptr->naptr[i].regexplen;
+ pack(q, ((struct naptr *)rrp2->rdata)->regexp, ((struct naptr *)rrp2->rdata)->regexplen);
+ q += ((struct naptr *)rrp2->rdata)->regexplen;
- pack(q, sdnaptr->naptr[i].replacement, sdnaptr->naptr[i].replacementlen);
- q += sdnaptr->naptr[i].replacementlen;
+ pack(q, ((struct naptr *)rrp2->rdata)->replacement, ((struct naptr *)rrp2->rdata)->replacementlen);
+ q += ((struct naptr *)rrp2->rdata)->replacementlen;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -3221,7 +3285,7 @@ sign_naptr(ddDB *db, char *zonename, struct keysentry
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_NAPTR], "NAPTR", algorithm, labels, sd->ttl[INTERNAL_TYPE_NAPTR], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct naptr *)rrp->rdata)->ttl, "NAPTR", algorithm, labels, ((struct naptr *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -3234,9 +3298,11 @@ sign_naptr(ddDB *db, char *zonename, struct keysentry
*/
int
-sign_srv(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_srv(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_srv *sdsrv = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -3256,7 +3322,7 @@ sign_srv(ddDB *db, char *zonename, struct keysentry *z
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -3315,7 +3381,7 @@ sign_srv(ddDB *db, char *zonename, struct keysentry *z
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -3325,11 +3391,15 @@ sign_srv(ddDB *db, char *zonename, struct keysentry *z
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_SRV) {
- if ((sdsrv = (struct domain_srv *)find_substruct(sd, INTERNAL_TYPE_SRV)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no SRV records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no SRV records\n");
+ return -1;
}
p = key;
@@ -3340,7 +3410,7 @@ sign_srv(ddDB *db, char *zonename, struct keysentry *z
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_SRV]));
+ pack32(p, htonl(((struct srv *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -3362,26 +3432,26 @@ sign_srv(ddDB *db, char *zonename, struct keysentry *z
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sdsrv->srv_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_SRV));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_SRV]));
+ pack32(q, htonl(((struct srv *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(2 + 2 + 2 + sdsrv->srv[i].targetlen));
+ pack16(q, htons(2 + 2 + 2 + ((struct srv *)rrp2->rdata)->targetlen));
q += 2;
- pack16(q, htons(sdsrv->srv[i].priority));
+ pack16(q, htons(((struct srv *)rrp2->rdata)->priority));
q += 2;
- pack16(q, htons(sdsrv->srv[i].weight));
+ pack16(q, htons(((struct srv *)rrp2->rdata)->weight));
q += 2;
- pack16(q, htons(sdsrv->srv[i].port));
+ pack16(q, htons(((struct srv *)rrp2->rdata)->port));
q += 2;
- pack(q, sdsrv->srv[i].target, sdsrv->srv[i].targetlen);
- q += sdsrv->srv[i].targetlen;
+ pack(q, ((struct srv *)rrp2->rdata)->target, ((struct srv *)rrp2->rdata)->targetlen);
+ q += ((struct srv *)rrp2->rdata)->targetlen;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -3479,7 +3549,7 @@ sign_srv(ddDB *db, char *zonename, struct keysentry *z
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_SRV], "SRV", algorithm, labels, sd->ttl[INTERNAL_TYPE_SRV], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct srv *)rrp->rdata)->ttl, "SRV", algorithm, labels, ((struct srv *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -3493,9 +3563,11 @@ sign_srv(ddDB *db, char *zonename, struct keysentry *z
*/
int
-sign_sshfp(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_sshfp(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_sshfp *sdsshfp = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -3515,7 +3587,7 @@ sign_sshfp(ddDB *db, char *zonename, struct keysentry
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -3574,7 +3646,7 @@ sign_sshfp(ddDB *db, char *zonename, struct keysentry
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -3584,11 +3656,15 @@ sign_sshfp(ddDB *db, char *zonename, struct keysentry
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_SSHFP) {
- if ((sdsshfp = (struct domain_sshfp *)find_substruct(sd, INTERNAL_TYPE_SSHFP)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no SSHFP records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no SSHFP records\n");
+ return -1;
}
p = key;
@@ -3599,7 +3675,7 @@ sign_sshfp(ddDB *db, char *zonename, struct keysentry
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_SSHFP]));
+ pack32(p, htonl(((struct sshfp *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -3621,24 +3697,24 @@ sign_sshfp(ddDB *db, char *zonename, struct keysentry
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sdsshfp->sshfp_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_SSHFP));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_SSHFP]));
+ pack32(q, htonl(((struct sshfp *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(1 + 1 + sdsshfp->sshfp[i].fplen));
+ pack16(q, htons(1 + 1 + ((struct sshfp *)rrp2->rdata)->fplen));
q += 2;
- pack8(q, sdsshfp->sshfp[i].algorithm);
+ pack8(q, ((struct sshfp *)rrp2->rdata)->algorithm);
q++;
- pack8(q, sdsshfp->sshfp[i].fptype);
+ pack8(q, ((struct sshfp *)rrp2->rdata)->fptype);
q++;
- pack(q, sdsshfp->sshfp[i].fingerprint, sdsshfp->sshfp[i].fplen);
- q += sdsshfp->sshfp[i].fplen;
+ pack(q, ((struct sshfp *)rrp2->rdata)->fingerprint, ((struct sshfp *)rrp2->rdata)->fplen);
+ q += ((struct sshfp *)rrp2->rdata)->fplen;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -3736,7 +3812,7 @@ sign_sshfp(ddDB *db, char *zonename, struct keysentry
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_SSHFP], "SSHFP", algorithm, labels, sd->ttl[INTERNAL_TYPE_SSHFP], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct sshfp *)rrp->rdata)->ttl, "SSHFP", algorithm, labels, ((struct sshfp *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -3749,9 +3825,11 @@ sign_sshfp(ddDB *db, char *zonename, struct keysentry
*/
int
-sign_tlsa(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_tlsa(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_tlsa *sdtlsa = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -3771,7 +3849,7 @@ sign_tlsa(ddDB *db, char *zonename, struct keysentry *
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -3830,7 +3908,7 @@ sign_tlsa(ddDB *db, char *zonename, struct keysentry *
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -3840,11 +3918,16 @@ sign_tlsa(ddDB *db, char *zonename, struct keysentry *
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_TLSA) {
- if ((sdtlsa = (struct domain_tlsa *)find_substruct(sd, INTERNAL_TYPE_TLSA)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no TLSA records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no TLSA records\n");
+ return -1;
+
}
p = key;
@@ -3855,7 +3938,7 @@ sign_tlsa(ddDB *db, char *zonename, struct keysentry *
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_TLSA]));
+ pack32(p, htonl(((struct tlsa *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -3877,26 +3960,27 @@ sign_tlsa(ddDB *db, char *zonename, struct keysentry *
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sdtlsa->tlsa_count; i++) {
+
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_TLSA));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_TLSA]));
+ pack32(q, htonl(((struct tlsa *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(1 + 1 + 1 + sdtlsa->tlsa[i].datalen));
+ pack16(q, htons(1 + 1 + 1 + ((struct tlsa *)rrp2->rdata)->datalen));
q += 2;
- pack8(q, sdtlsa->tlsa[i].usage);
+ pack8(q, ((struct tlsa *)rrp2->rdata)->usage);
q++;
- pack8(q, sdtlsa->tlsa[i].selector);
+ pack8(q, ((struct tlsa *)rrp2->rdata)->selector);
q++;
- pack8(q, sdtlsa->tlsa[i].matchtype);
+ pack8(q, ((struct tlsa *)rrp2->rdata)->matchtype);
q++;
- pack(q, sdtlsa->tlsa[i].data, sdtlsa->tlsa[i].datalen);
- q += sdtlsa->tlsa[i].datalen;
+ pack(q, ((struct tlsa *)rrp2->rdata)->data, ((struct tlsa *)rrp2->rdata)->datalen);
+ q += ((struct tlsa *)rrp2->rdata)->datalen;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -3993,7 +4077,7 @@ sign_tlsa(ddDB *db, char *zonename, struct keysentry *
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_TLSA], "TLSA", algorithm, labels, sd->ttl[INTERNAL_TYPE_TLSA], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct tlsa *)rrp->rdata)->ttl, "TLSA", algorithm, labels, ((struct tlsa *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -4006,9 +4090,11 @@ sign_tlsa(ddDB *db, char *zonename, struct keysentry *
*/
int
-sign_ds(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_ds(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_ds *sdds = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -4028,7 +4114,7 @@ sign_ds(ddDB *db, char *zonename, struct keysentry *z
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -4087,7 +4173,7 @@ sign_ds(ddDB *db, char *zonename, struct keysentry *z
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -4097,11 +4183,15 @@ sign_ds(ddDB *db, char *zonename, struct keysentry *z
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_DS) {
- if ((sdds = (struct domain_ds *)find_substruct(sd, INTERNAL_TYPE_DS)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no DS records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no DS records\n");
+ return -1;
}
p = key;
@@ -4112,7 +4202,7 @@ sign_ds(ddDB *db, char *zonename, struct keysentry *z
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_DS]));
+ pack32(p, htonl(((struct ds *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -4134,26 +4224,26 @@ sign_ds(ddDB *db, char *zonename, struct keysentry *z
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sdds->ds_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_DS));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_DS]));
+ pack32(q, htonl(((struct ds *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(2 + 1 + 1 + sdds->ds[i].digestlen));
+ pack16(q, htons(2 + 1 + 1 + ((struct ds *)rrp2->rdata)->digestlen));
q += 2;
- pack16(q, htons(sdds->ds[i].key_tag));
+ pack16(q, htons(((struct ds *)rrp2->rdata)->key_tag));
q += 2;
- pack8(q, sdds->ds[i].algorithm);
+ pack8(q, ((struct ds *)rrp2->rdata)->algorithm);
q++;
- pack8(q, sdds->ds[i].digest_type);
+ pack8(q, ((struct ds *)rrp2->rdata)->digest_type);
q++;
- pack(q, sdds->ds[i].digest, sdds->ds[i].digestlen);
- q += sdds->ds[i].digestlen;
+ pack(q, ((struct ds *)rrp2->rdata)->digest, ((struct ds *)rrp2->rdata)->digestlen);
+ q += ((struct ds *)rrp2->rdata)->digestlen;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -4249,7 +4339,7 @@ sign_ds(ddDB *db, char *zonename, struct keysentry *z
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_DS], "DS", algorithm, labels, sd->ttl[INTERNAL_TYPE_DS], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct ds *)rrp->rdata)->ttl, "DS", algorithm, labels, ((struct ds *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -4261,11 +4351,12 @@ sign_ds(ddDB *db, char *zonename, struct keysentry *z
/*
* create a RRSIG for an NS record
*/
-
int
-sign_ns(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_ns(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_ns *sdns = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -4285,7 +4376,7 @@ sign_ns(ddDB *db, char *zonename, struct keysentry *zs
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -4344,7 +4435,7 @@ sign_ns(ddDB *db, char *zonename, struct keysentry *zs
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -4354,11 +4445,16 @@ sign_ns(ddDB *db, char *zonename, struct keysentry *zs
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_NS) {
- if ((sdns = (struct domain_ns *)find_substruct(sd, INTERNAL_TYPE_NS)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no NS records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no NS records\n");
+ return -1;
+
}
p = key;
@@ -4369,7 +4465,7 @@ sign_ns(ddDB *db, char *zonename, struct keysentry *zs
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_NS]));
+ pack32(p, htonl(((struct ns *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -4391,20 +4487,20 @@ sign_ns(ddDB *db, char *zonename, struct keysentry *zs
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sdns->ns_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_NS));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_NS]));
+ pack32(q, htonl(((struct ns *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(sdns->ns[i].nslen));
+ pack16(q, htons(((struct ns *)rrp2->rdata)->nslen));
q += 2;
- memcpy(q, sdns->ns[i].nsserver, sdns->ns[i].nslen);
- q += sdns->ns[i].nslen;
+ memcpy(q, ((struct ns *)rrp2->rdata)->nsserver, ((struct ns *)rrp2->rdata)->nslen);
+ q += ((struct ns *)rrp2->rdata)->nslen;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -4500,7 +4596,7 @@ sign_ns(ddDB *db, char *zonename, struct keysentry *zs
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_NS], "NS", algorithm, labels, sd->ttl[INTERNAL_TYPE_NS], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct ns *)rrp->rdata)->ttl, "NS", algorithm, labels, ((struct ns *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -4513,9 +4609,11 @@ sign_ns(ddDB *db, char *zonename, struct keysentry *zs
*/
int
-sign_mx(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_mx(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_mx *sdmx = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -4535,7 +4633,7 @@ sign_mx(ddDB *db, char *zonename, struct keysentry *zs
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -4594,7 +4692,7 @@ sign_mx(ddDB *db, char *zonename, struct keysentry *zs
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -4604,11 +4702,15 @@ sign_mx(ddDB *db, char *zonename, struct keysentry *zs
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_MX) {
- if ((sdmx = (struct domain_mx *)find_substruct(sd, INTERNAL_TYPE_MX)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no MX records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no MX records\n");
+ return -1;
}
p = key;
@@ -4619,7 +4721,7 @@ sign_mx(ddDB *db, char *zonename, struct keysentry *zs
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_MX]));
+ pack32(p, htonl(((struct smx *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -4641,22 +4743,22 @@ sign_mx(ddDB *db, char *zonename, struct keysentry *zs
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sdmx->mx_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_MX));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_MX]));
+ pack32(q, htonl(((struct smx *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(2 + sdmx->mx[i].exchangelen));
+ pack16(q, htons(2 + ((struct smx *)rrp2->rdata)->exchangelen));
q += 2;
- pack16(q, htons(sdmx->mx[i].preference));
+ pack16(q, htons(((struct smx *)rrp2->rdata)->preference));
q += 2;
- memcpy(q, sdmx->mx[i].exchange, sdmx->mx[i].exchangelen);
- q += sdmx->mx[i].exchangelen;
+ memcpy(q, ((struct smx *)rrp2->rdata)->exchange, ((struct smx *)rrp2->rdata)->exchangelen);
+ q += ((struct smx *)rrp2->rdata)->exchangelen;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -4752,7 +4854,7 @@ sign_mx(ddDB *db, char *zonename, struct keysentry *zs
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_MX], "MX", algorithm, labels, sd->ttl[INTERNAL_TYPE_MX], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct smx *)rrp->rdata)->ttl, "MX", algorithm, labels, ((struct smx *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -4766,9 +4868,11 @@ sign_mx(ddDB *db, char *zonename, struct keysentry *zs
*/
int
-sign_a(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_a(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_a *sda = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -4788,7 +4892,7 @@ sign_a(ddDB *db, char *zonename, struct keysentry *zsk
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -4847,7 +4951,7 @@ sign_a(ddDB *db, char *zonename, struct keysentry *zsk
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -4857,11 +4961,15 @@ sign_a(ddDB *db, char *zonename, struct keysentry *zsk
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_A) {
- if ((sda = (struct domain_a *)find_substruct(sd, INTERNAL_TYPE_A)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no A records but have flags!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no A records\n");
+ return -1;
}
p = key;
@@ -4872,7 +4980,7 @@ sign_a(ddDB *db, char *zonename, struct keysentry *zsk
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_A]));
+ pack32(p, htonl(((struct a *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -4894,19 +5002,19 @@ sign_a(ddDB *db, char *zonename, struct keysentry *zsk
/* no signature here */
/* XXX this should probably be done on a canonical sorted records */
- for (i = 0; i < sda->a_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
- pack(q, sd->zone, sd->zonelen);
- q += sd->zonelen;
+ pack(q, rbt->zone, rbt->zonelen);
+ q += rbt->zonelen;
pack16(q, htons(DNS_TYPE_A));
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_A]));
+ pack32(q, htonl(((struct a *)rrp->rdata)->ttl));
q += 4;
pack16(q, htons(sizeof(in_addr_t)));
q += 2;
- pack32(q, sda->a[i]);
+ pack32(q, ((struct a *)rrp2->rdata)->a);
q += 4;
c1 = malloc(sizeof(struct canonical));
@@ -5003,7 +5111,7 @@ sign_a(ddDB *db, char *zonename, struct keysentry *zsk
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", sd->ttl[INTERNAL_TYPE_A], "A", algorithm, labels, sd->ttl[INTERNAL_TYPE_A], expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ((struct a *)rrp->rdata)->ttl, "A", algorithm, labels, ((struct a *)rrp->rdata)->ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -5016,8 +5124,9 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
{
FILE *f;
- struct domain *sd;
- struct domain_dnskey *sddk = NULL;
+ struct rbtree *rbt = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
struct stat sb;
char *mytmp;
@@ -5066,8 +5175,8 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
return -1;
}
- if ((sd = lookup_zone(db, qp, &retval, &lzerrno, (char *)&replystring)) == NULL) {
- dolog(LOG_INFO, "sd == NULL\n");
+ if ((rbt = lookup_zone(db, qp, &retval, &lzerrno, (char *)&replystring)) == NULL) {
+ dolog(LOG_INFO, "rbt == NULL\n");
return -1;
}
@@ -5105,7 +5214,7 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -5115,20 +5224,21 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_DNSKEY) {
- if ((sddk = (struct domain_dnskey *)find_substruct(sd, INTERNAL_TYPE_DNSKEY)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in apex!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
+ dolog(LOG_INFO, "no ds!\n");
return -1;
}
- }
+ }
keylen = (p - key);
/* work out the digest */
p = key;
- pack(p, sd->zone, sd->zonelen);
- p += sd->zonelen;
+ pack(p, rbt->zone, rbt->zonelen);
+ p += rbt->zonelen;
pack16(p, htons(flags));
p += 2;
pack8(p, protocol);
@@ -5156,7 +5266,7 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
*p = toupper(*p);
}
- snprintf(buf, sizeof(buf), "dsset-%s", convert_name(sd->zone, sd->zonelen));
+ snprintf(buf, sizeof(buf), "dsset-%s", convert_name(rbt->zone, rbt->zonelen));
errno = 0;
if (lstat(buf, &sb) < 0 && errno != ENOENT) {
@@ -5179,7 +5289,7 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
return -1;
}
- fprintf(f, "%s\t\tIN DS %u %d 1 %s\n", convert_name(sd->zone, sd->zonelen), keyid, algorithm, mytmp);
+ fprintf(f, "%s\t\tIN DS %u %d 1 %s\n", convert_name(rbt->zone, rbt->zonelen), keyid, algorithm, mytmp);
SHA256_Init(&sha256);
@@ -5197,7 +5307,7 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
*p = toupper(*p);
}
- fprintf(f, "%s\t\tIN DS %u %d 2 %s\n", convert_name(sd->zone, sd->zonelen), keyid, algorithm, mytmp);
+ fprintf(f, "%s\t\tIN DS %u %d 2 %s\n", convert_name(rbt->zone, rbt->zonelen), keyid, algorithm, mytmp);
fclose(f);
@@ -5209,9 +5319,11 @@ create_ds(ddDB *db, char *zonename, struct keysentry *
*/
int
-sign_dnskey(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct domain *sd)
+sign_dnskey(ddDB *db, char *zonename, struct keysentry *zsk_key, int expiry, struct rbtree *rbt)
{
- struct domain_dnskey *sddk = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
char tmp[4096];
char signature[4096];
@@ -5231,7 +5343,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
uint8_t protocol;
uint8_t algorithm;
- int labellen, i;
+ int labellen;
int keyid;
int len;
int keylen, siglen;
@@ -5293,7 +5405,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -5303,12 +5415,16 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_DNSKEY) {
- if ((sddk = (struct domain_dnskey *)find_substruct(sd, INTERNAL_TYPE_DNSKEY)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no dnskeys in apex!\n");
return -1;
}
- }
+ } else {
+ dolog(LOG_INFO, "no dnskeys\n");
+ return -1;
+ }
p = key;
@@ -5318,7 +5434,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_DNSKEY]));
+ pack32(p, htonl(((struct dnskey *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -5339,7 +5455,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
/* no signature here */
- for (i = 0; i < sddk->dnskey_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
pack(q, dnsname, labellen);
q += labellen;
@@ -5347,18 +5463,18 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_DNSKEY]));
+ pack32(q, htonl(((struct dnskey *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(2 + 1 + 1 + sddk->dnskey[i].publickey_len));
+ pack16(q, htons(2 + 1 + 1 + ((struct dnskey *)rrp2->rdata)->publickey_len));
q += 2;
- pack16(q, htons(sddk->dnskey[i].flags));
+ pack16(q, htons(((struct dnskey *)rrp2->rdata)->flags));
q += 2;
- pack8(q, sddk->dnskey[i].protocol);
+ pack8(q, ((struct dnskey *)rrp2->rdata)->protocol);
q++;
- pack8(q, sddk->dnskey[i].algorithm);
+ pack8(q, ((struct dnskey *)rrp2->rdata)->algorithm);
q++;
- pack(q, sddk->dnskey[i].public_key, sddk->dnskey[i].publickey_len);
- q += sddk->dnskey[i].publickey_len;
+ pack(q, ((struct dnskey *)rrp2->rdata)->public_key, ((struct dnskey *)rrp2->rdata)->publickey_len);
+ q += ((struct dnskey *)rrp2->rdata)->publickey_len;
c1 = malloc(sizeof(struct canonical));
@@ -5456,7 +5572,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", ttl, "DNSKEY", algorithm, labels, ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ttl, "DNSKEY", algorithm, labels, ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -5486,7 +5602,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
return -1;
}
- labels = label_count(sd->zone);
+ labels = label_count(rbt->zone);
if (labels < 0) {
dolog(LOG_INFO, "label_count");
return -1;
@@ -5496,12 +5612,17 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
if (dnsname == NULL)
return -1;
- if (sd->flags & DOMAIN_HAVE_DNSKEY) {
- if ((sddk = (struct domain_dnskey *)find_substruct(sd, INTERNAL_TYPE_DNSKEY)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
dolog(LOG_INFO, "no dnskeys in apex!\n");
return -1;
}
+ } else {
+ dolog(LOG_INFO, "no dnskeys\n");
+ return -1;
}
+
p = key;
@@ -5511,7 +5632,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
p++;
pack8(p, labels);
p++;
- pack32(p, htonl(sd->ttl[INTERNAL_TYPE_DNSKEY]));
+ pack32(p, htonl(((struct dnskey *)rrp->rdata)->ttl));
p += 4;
snprintf(timebuf, sizeof(timebuf), "%lld", expiredon);
@@ -5532,7 +5653,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
/* no signature here */
- for (i = 0; i < sddk->dnskey_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
q = tmpkey;
pack(q, dnsname, labellen);
q += labellen;
@@ -5540,18 +5661,18 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
q += 2;
pack16(q, htons(DNS_CLASS_IN));
q += 2;
- pack32(q, htonl(sd->ttl[INTERNAL_TYPE_DNSKEY]));
+ pack32(q, htonl(((struct dnskey *)rrp->rdata)->ttl));
q += 4;
- pack16(q, htons(2 + 1 + 1 + sddk->dnskey[i].publickey_len));
+ pack16(q, htons(2 + 1 + 1 + ((struct dnskey *)rrp2->rdata)->publickey_len));
q += 2;
- pack16(q, htons(sddk->dnskey[i].flags));
+ pack16(q, htons(((struct dnskey *)rrp2->rdata)->flags));
q += 2;
- pack8(q, sddk->dnskey[i].protocol);
+ pack8(q, ((struct dnskey *)rrp2->rdata)->protocol);
q++;
- pack8(q, sddk->dnskey[i].algorithm);
+ pack8(q, ((struct dnskey *)rrp2->rdata)->algorithm);
q++;
- pack(q, sddk->dnskey[i].public_key, sddk->dnskey[i].publickey_len);
- q += sddk->dnskey[i].publickey_len;
+ pack(q, ((struct dnskey *)rrp2->rdata)->public_key, ((struct dnskey *)rrp2->rdata)->publickey_len);
+ q += ((struct dnskey *)rrp2->rdata)->publickey_len;
c1 = malloc(sizeof(struct canonical));
if (c1 == NULL) {
@@ -5648,7 +5769,7 @@ sign_dnskey(ddDB *db, char *zonename, struct keysentry
len = mybase64_encode(signature, siglen, tmp, sizeof(tmp));
tmp[len] = '\0';
- if (fill_rrsig(sd->zonename, "RRSIG", ttl, "DNSKEY", algorithm, labels, ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
+ if (fill_rrsig(rbt->humanname, "RRSIG", ttl, "DNSKEY", algorithm, labels, ttl, expiredon, signedon, keyid, zonename, tmp) < 0) {
dolog(LOG_INFO, "fill_rrsig\n");
return -1;
}
@@ -5909,12 +6030,14 @@ construct_nsec3(ddDB *db, char *zone, int iterations,
{
struct node *n, *nx;
- struct domain *sd;
struct question *q;
-
struct nsec3param n3p;
- struct domain_nsec3param *sdn3p;
-
+
+ struct rbtree *rbt = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
+
char replystring[512];
char buf[4096];
char bitmap[4096];
@@ -5955,82 +6078,95 @@ construct_nsec3(ddDB *db, char *zone, int iterations,
return -1;
}
- if ((sd = lookup_zone(db, q, &retval, &lzerrno, (char *)&replystring)) == NULL) {
+ if ((rbt = lookup_zone(db, q, &retval, &lzerrno, (char *)&replystring)) == NULL) {
return -1;
}
/* get the rootzone's len */
- rootlen = sd->zonelen;
+ rootlen = rbt->zonelen;
+ rrset = find_rr(rbt, DNS_TYPE_SOA);
+ if (rrset == NULL)
+ return -1;
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
/* RFC 5155 page 3 */
- ttl = sd->ttl[INTERNAL_TYPE_SOA];
+ ttl = ((struct soa *)rrp->rdata)->ttl;
- if ((sdn3p = find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
- return -1;
- }
+
+ rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM);
+ if (rrset == NULL)
+ return -1;
+ rrp2 = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp2 == NULL)
+ return -1;
n3p.algorithm = 1; /* still in conformance with above */
n3p.flags = 0;
- n3p.iterations = sdn3p->nsec3param.iterations;
- n3p.saltlen = sdn3p->nsec3param.saltlen;
- memcpy(&n3p.salt, sdn3p->nsec3param.salt, n3p.saltlen);
+ n3p.iterations = ((struct nsec3param *)rrp2->rdata)->iterations;
+ n3p.saltlen = ((struct nsec3param *)rrp2->rdata)->saltlen;
+ memcpy(&n3p.salt, ((struct nsec3param *)rrp2->rdata)->salt,
+ ((struct nsec3param *)rrp2->rdata)->saltlen);
j = 0;
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
rs = n->datalen;
- if ((sd = calloc(1, rs)) == NULL) {
+ if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sd, (char *)n->data, n->datalen);
+ memcpy((char *)rbt, (char *)n->data, n->datalen);
- hashname = hash_name(sd->zone, sd->zonelen, &n3p);
+ hashname = hash_name(rbt->zone, rbt->zonelen, &n3p);
if (hashname == NULL) {
dolog(LOG_INFO, "hash_name return NULL");
return -1;
}
+
bitmap[0] = '\0';
- if (sd->flags & DOMAIN_HAVE_A)
+ if (find_rr(rbt, DNS_TYPE_A) != NULL)
strlcat(bitmap, "A ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_NS)
+ if (find_rr(rbt, DNS_TYPE_NS) != NULL)
strlcat(bitmap, "NS ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_CNAME)
+ if (find_rr(rbt, DNS_TYPE_CNAME) != NULL)
strlcat(bitmap, "CNAME ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_SOA)
+ if (find_rr(rbt, DNS_TYPE_SOA) != NULL)
strlcat(bitmap, "SOA ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_PTR)
+ if (find_rr(rbt, DNS_TYPE_PTR) != NULL)
strlcat(bitmap, "PTR ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_MX)
+ if (find_rr(rbt, DNS_TYPE_MX) != NULL)
strlcat(bitmap, "MX ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_TXT)
+ if (find_rr(rbt, DNS_TYPE_TXT) != NULL)
strlcat(bitmap, "TXT ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_AAAA)
+ if (find_rr(rbt, DNS_TYPE_AAAA) != NULL)
strlcat(bitmap, "AAAA ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_SRV)
+ if (find_rr(rbt, DNS_TYPE_SRV) != NULL)
strlcat(bitmap, "SRV ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_NAPTR)
+ if (find_rr(rbt, DNS_TYPE_NAPTR) != NULL)
strlcat(bitmap, "NAPTR ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_DS)
+ if (find_rr(rbt, DNS_TYPE_DS) != NULL)
strlcat(bitmap, "DS ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_SSHFP)
+ if (find_rr(rbt, DNS_TYPE_SSHFP) != NULL)
strlcat(bitmap, "SSHFP ", sizeof(bitmap));
/* they all have RRSIG */
strlcat(bitmap, "RRSIG ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_DNSKEY)
+ if (find_rr(rbt, DNS_TYPE_DNSKEY) != NULL)
strlcat(bitmap, "DNSKEY ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_NSEC3)
+ if (find_rr(rbt, DNS_TYPE_NSEC3) != NULL)
strlcat(bitmap, "NSEC3 ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_NSEC3PARAM)
+ if (find_rr(rbt, DNS_TYPE_NSEC3PARAM) != NULL)
strlcat(bitmap, "NSEC3PARAM ", sizeof(bitmap));
- if (sd->flags & DOMAIN_HAVE_TLSA)
+ if (find_rr(rbt, DNS_TYPE_TLSA) != NULL)
strlcat(bitmap, "TLSA ", sizeof(bitmap));
#if 0
@@ -6064,22 +6200,22 @@ construct_nsec3(ddDB *db, char *zone, int iterations,
TAILQ_INSERT_TAIL(&head, n1, entries);
}
- free(sd);
+ free(rbt);
} /* RB_FOREACH_SAFE */
/* check ENT's which we'll create */
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
rs = n->datalen;
- if ((sd = calloc(1, rs)) == NULL) {
+ if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sd, (char *)n->data, n->datalen);
+ memcpy((char *)rbt, (char *)n->data, n->datalen);
- len = sd->zonelen;
- for (p = sd->zone; *p && len > rootlen; p++, len--) {
+ len = rbt->zonelen;
+ for (p = rbt->zone; *p && len > rootlen; p++, len--) {
if (check_ent(p, len))
break;
@@ -6126,7 +6262,7 @@ construct_nsec3(ddDB *db, char *zone, int iterations,
} /* if len > rootlen */
- free(sd);
+ free(rbt);
} /* RB_FOREACH_SAFE */
@@ -6251,574 +6387,277 @@ bitmap2human(char *bitmap, int len)
}
int
-print_sd(FILE *of, struct domain *sdomain)
+print_rbt(FILE *of, struct rbtree *rbt)
{
int i, x, len;
- struct domain_soa *sdsoa;
- struct domain_ns *sdns;
- struct domain_mx *sdmx;
- struct domain_a *sda;
- struct domain_aaaa *sdaaaa;
- struct domain_cname *sdcname;
- struct domain_ptr *sdptr;
- struct domain_txt *sdtxt;
- struct domain_naptr *sdnaptr;
- struct domain_srv *sdsrv;
- struct domain_rrsig *sdrr;
- struct domain_dnskey *sddk;
- struct domain_ds *sdds;
- struct domain_nsec3 *sdn3;
- struct domain_nsec3param *sdn3param;
- struct domain_sshfp *sdsshfp;
- struct domain_tlsa *sdtlsa;
- struct rrsig *rss;
-
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
+
char buf[4096];
- if (sdomain->flags & DOMAIN_HAVE_SOA) {
- if ((sdsoa = (struct domain_soa *)find_substruct(sdomain, INTERNAL_TYPE_SOA)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no soa in zone!\n");
return -1;
}
fprintf(of, " %s,soa,%d,%s,%s,%u,%d,%d,%d,%d\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_SOA],
- convert_name(sdsoa->soa.nsserver, sdsoa->soa.nsserver_len),
- convert_name(sdsoa->soa.responsible_person, sdsoa->soa.rp_len),
- sdsoa->soa.serial, sdsoa->soa.refresh, sdsoa->soa.retry,
- sdsoa->soa.expire, sdsoa->soa.minttl);
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct soa *)rrp->rdata)->ttl,
+ convert_name(((struct soa *)rrp->rdata)->nsserver, ((struct soa *)rrp->rdata)->nsserver_len),
+ convert_name(((struct soa *)rrp->rdata)->responsible_person, ((struct soa *)rrp->rdata)->rp_len),
+ ((struct soa *)rrp->rdata)->serial,
+ ((struct soa *)rrp->rdata)->refresh,
+ ((struct soa *)rrp->rdata)->retry,
+ ((struct soa *)rrp->rdata)->expire,
+ ((struct soa *)rrp->rdata)->minttl);
}
- if (sdomain->flags & DOMAIN_HAVE_NS) {
- if ((sdns = (struct domain_ns *)find_substruct(sdomain, INTERNAL_TYPE_NS)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no ns in zone!\n");
return -1;
}
- for (i = 0; i < sdns->ns_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, " %s,ns,%d,%s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_NS],
- convert_name(sdns->ns[i].nsserver, sdns->ns[i].nslen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct ns *)rrp->rdata)->ttl,
+ convert_name(((struct ns *)rrp2->rdata)->nsserver, ((struct ns *)rrp2->rdata)->nslen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_MX) {
- if ((sdmx = (struct domain_mx *)find_substruct(sdomain, INTERNAL_TYPE_MX)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no mx in zone!\n");
return -1;
}
- for (i = 0; i < sdmx->mx_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, " %s,mx,%d,%d,%s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_MX],
- sdmx->mx[i].preference,
- convert_name(sdmx->mx[i].exchange, sdmx->mx[i].exchangelen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct smx *)rrp->rdata)->ttl,
+ ((struct smx *)rrp2->rdata)->preference,
+ convert_name(((struct smx *)rrp2->rdata)->exchange, ((struct smx *)rrp2->rdata)->exchangelen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_DS) {
- if ((sdds = (struct domain_ds *)find_substruct(sdomain, INTERNAL_TYPE_DS)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no ds in zone!\n");
return -1;
}
- for (i = 0; i < sdds->ds_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, " %s,ds,%d,%d,%d,%d,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_DS],
- sdds->ds[i].key_tag,
- sdds->ds[i].algorithm,
- sdds->ds[i].digest_type,
- bin2hex(sdds->ds[i].digest, sdds->ds[i].digestlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct ds *)rrp->rdata)->ttl,
+ ((struct ds *)rrp2->rdata)->key_tag,
+ ((struct ds *)rrp2->rdata)->algorithm,
+ ((struct ds *)rrp2->rdata)->digest_type,
+ bin2hex(((struct ds *)rrp2->rdata)->digest, ((struct ds *)rrp2->rdata)->digestlen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_CNAME) {
- if ((sdcname = (struct domain_cname *)find_substruct(sdomain, INTERNAL_TYPE_CNAME)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_CNAME)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no cname in zone!\n");
return -1;
}
fprintf(of, " %s,cname,%d,%s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_CNAME],
- convert_name(sdcname->cname, sdcname->cnamelen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct ds *)rrp->rdata)->ttl,
+ convert_name(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen));
}
- if (sdomain->flags & DOMAIN_HAVE_NAPTR) {
- if ((sdnaptr = (struct domain_naptr *)find_substruct(sdomain, INTERNAL_TYPE_NAPTR)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
- for (i = 0; i < sdnaptr->naptr_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, " %s,naptr,%d,%d,%d,\"",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_NAPTR],
- sdnaptr->naptr[i].order,
- sdnaptr->naptr[i].preference);
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct naptr *)rrp->rdata)->ttl,
+ ((struct naptr *)rrp2->rdata)->order,
+ ((struct naptr *)rrp2->rdata)->preference);
- for (x = 0; x < sdnaptr->naptr[i].flagslen; x++) {
- fprintf(of, "%c", sdnaptr->naptr[i].flags[x]);
+ for (x = 0; x < ((struct naptr *)rrp2->rdata)->flagslen; x++) {
+ fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->flags[x]);
}
fprintf(of, "\",\"");
- for (x = 0; x < sdnaptr->naptr[i].serviceslen; x++) {
- fprintf(of, "%c", sdnaptr->naptr[i].services[x]);
+ for (x = 0; x < ((struct naptr *)rrp2->rdata)->serviceslen; x++) {
+ fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->services[x]);
}
fprintf(of, "\",\"");
- for (x = 0; x < sdnaptr->naptr[i].regexplen; x++) {
- fprintf(of, "%c", sdnaptr->naptr[i].regexp[x]);
+ for (x = 0; x < ((struct naptr *)rrp2->rdata)->regexplen; x++) {
+ fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->regexp[x]);
}
- fprintf(of, "\",%s\n", (sdnaptr->naptr[i].replacement[0] == '\0') ? "." : convert_name(sdnaptr->naptr[i].replacement, sdnaptr->naptr[i].replacementlen));
+ fprintf(of, "\",%s\n", (((struct naptr *)rrp2->rdata)->replacement[0] == '\0') ? "." : convert_name(((struct naptr *)rrp2->rdata)->replacement, ((struct naptr *)rrp2->rdata)->replacementlen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_TXT) {
- if ((sdtxt = (struct domain_txt *)find_substruct(sdomain, INTERNAL_TYPE_TXT)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no txt in zone!\n");
return -1;
}
fprintf(of, " %s,txt,%d,\"",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_TXT]);
- for (i = 0; i < sdtxt->txtlen; i++) {
- fprintf(of, "%c", sdtxt->txt[i]);
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct txt *)rrp->rdata)->ttl);
+
+ for (i = 0; i < ((struct txt *)rrp->rdata)->txtlen; i++) {
+ fprintf(of, "%c", ((struct txt *)rrp->rdata)->txt[i]);
}
fprintf(of, "\"\n");
}
- if (sdomain->flags & DOMAIN_HAVE_PTR) {
- if ((sdptr = (struct domain_ptr *)find_substruct(sdomain, INTERNAL_TYPE_PTR)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
fprintf(of, " %s,ptr,%d,%s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_PTR],
- convert_name(sdptr->ptr, sdptr->ptrlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct ptr *)rrp->rdata)->ttl,
+ convert_name(((struct ptr *)rrp->rdata)->ptr, ((struct ptr *)rrp->rdata)->ptrlen));
}
- if (sdomain->flags & DOMAIN_HAVE_SRV) {
- if ((sdsrv = (struct domain_srv *)find_substruct(sdomain, INTERNAL_TYPE_SRV)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
- for (i = 0; i < sdsrv->srv_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, " %s,srv,%d,%d,%d,%d,%s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_SRV],
- sdsrv->srv[i].priority,
- sdsrv->srv[i].weight,
- sdsrv->srv[i].port,
- convert_name(sdsrv->srv[i].target,sdsrv->srv[i].targetlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct srv *)rrp->rdata)->ttl,
+ ((struct srv *)rrp2->rdata)->priority,
+ ((struct srv *)rrp2->rdata)->weight,
+ ((struct srv *)rrp2->rdata)->port,
+ convert_name(((struct srv *)rrp2->rdata)->target,((struct srv *)rrp2->rdata)->targetlen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_TLSA) {
- if ((sdtlsa = (struct domain_tlsa *)find_substruct(sdomain, INTERNAL_TYPE_TLSA)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
- for (i = 0; i < sdtlsa->tlsa_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, " %s,tlsa,%d,%d,%d,%d,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_TLSA],
- sdtlsa->tlsa[i].usage,
- sdtlsa->tlsa[i].selector,
- sdtlsa->tlsa[i].matchtype,
- bin2hex(sdtlsa->tlsa[i].data, sdtlsa->tlsa[i].datalen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct tlsa *)rrp->rdata)->ttl,
+ ((struct tlsa *)rrp2->rdata)->usage,
+ ((struct tlsa *)rrp2->rdata)->selector,
+ ((struct tlsa *)rrp2->rdata)->matchtype,
+ bin2hex(((struct tlsa *)rrp2->rdata)->data, ((struct tlsa *)rrp2->rdata)->datalen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_SSHFP) {
- if ((sdsshfp = (struct domain_sshfp *)find_substruct(sdomain, INTERNAL_TYPE_SSHFP)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
- for (i = 0; i < sdsshfp->sshfp_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, " %s,sshfp,%d,%d,%d,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_SSHFP],
- sdsshfp->sshfp[i].algorithm,
- sdsshfp->sshfp[i].fptype,
- bin2hex(sdsshfp->sshfp[i].fingerprint, sdsshfp->sshfp[i].fplen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct sshfp *)rrp->rdata)->ttl,
+ ((struct sshfp *)rrp2->rdata)->algorithm,
+ ((struct sshfp *)rrp2->rdata)->fptype,
+ bin2hex(((struct sshfp *)rrp2->rdata)->fingerprint, ((struct sshfp *)rrp2->rdata)->fplen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_A) {
- if ((sda = (struct domain_a *)find_substruct(sdomain, INTERNAL_TYPE_A)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
- for (i = 0; i < sda->a_count; i++) {
- inet_ntop(AF_INET, &sda->a[i], buf, sizeof(buf));
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+ inet_ntop(AF_INET, &((struct a *)rrp2->rdata)->a, buf, sizeof(buf));
fprintf(of, " %s,a,%d,%s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_A],
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct a *)rrp->rdata)->ttl,
buf);
}
}
- if (sdomain->flags & DOMAIN_HAVE_AAAA) {
- if ((sdaaaa = (struct domain_aaaa *)find_substruct(sdomain, INTERNAL_TYPE_AAAA)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
- for (i = 0; i < sdaaaa->aaaa_count; i++) {
- inet_ntop(AF_INET6, &sdaaaa->aaaa[i], buf, sizeof(buf));
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+ inet_ntop(AF_INET6, &((struct aaaa *)rrp2->rdata)->aaaa, buf, sizeof(buf));
fprintf(of, " %s,aaaa,%d,%s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_AAAA],
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct aaaa *)rrp->rdata)->ttl,
buf);
}
}
- if (sdomain->flags & DOMAIN_HAVE_DNSKEY) {
-#if DEBUG
- printf(" has dnskey\n");
-#endif
- if ((sddk = (struct domain_dnskey *)find_substruct(sdomain, INTERNAL_TYPE_DNSKEY)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
- for (i = 0; i < sddk->dnskey_count; i++) {
- len = mybase64_encode(sddk->dnskey[i].public_key, sddk->dnskey[i].publickey_len, buf, sizeof(buf));
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+ len = mybase64_encode(((struct dnskey *)rrp2->rdata)->public_key, ((struct dnskey *)rrp2->rdata)->publickey_len, buf, sizeof(buf));
buf[len] = '\0';
fprintf(of, " %s,dnskey,%d,%d,%d,%d,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_DNSKEY],
- sddk->dnskey[i].flags,
- sddk->dnskey[i].protocol,
- sddk->dnskey[i].algorithm,
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct dnskey *)rrp->rdata)->ttl,
+ ((struct dnskey *)rrp2->rdata)->flags,
+ ((struct dnskey *)rrp2->rdata)->protocol,
+ ((struct dnskey *)rrp2->rdata)->algorithm,
buf);
}
}
- if (sdomain->flags & DOMAIN_HAVE_NSEC3PARAM) {
-#if DEBUG
- printf("has nsec3param\n");
-#endif
- if ((sdn3param = (struct domain_nsec3param *)find_substruct(sdomain, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
- dolog(LOG_INFO, "no nsec3param in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
-
+
fprintf(of, " %s,nsec3param,0,%d,%d,%d,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdn3param->nsec3param.algorithm,
- sdn3param->nsec3param.flags,
- sdn3param->nsec3param.iterations,
- (sdn3param->nsec3param.saltlen == 0) ? "-" : bin2hex(sdn3param->nsec3param.salt, sdn3param->nsec3param.saltlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct nsec3param *)rrp->rdata)->algorithm,
+ ((struct nsec3param *)rrp->rdata)->flags,
+ ((struct nsec3param *)rrp->rdata)->iterations,
+ (((struct nsec3param *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3param *)rrp->rdata)->salt, ((struct nsec3param *)rrp->rdata)->saltlen));
}
- if (sdomain->flags & DOMAIN_HAVE_NSEC3) {
-#if DEBUG
- printf("has nsec3\n");
-#endif
- if ((sdn3 = (struct domain_nsec3 *)find_substruct(sdomain, INTERNAL_TYPE_NSEC3)) == NULL) {
- dolog(LOG_INFO, "no nsec3 in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
fprintf(of, " %s,nsec3,%d,%d,%d,%d,\"%s\",\"%s\",\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_NSEC3],
- sdn3->nsec3.algorithm,
- sdn3->nsec3.flags,
- sdn3->nsec3.iterations,
- (sdn3->nsec3.saltlen == 0) ? "-" : bin2hex(sdn3->nsec3.salt, sdn3->nsec3.saltlen),
- base32hex_encode(sdn3->nsec3.next, sdn3->nsec3.nextlen),
- bitmap2human(sdn3->nsec3.bitmap, sdn3->nsec3.bitmap_len));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct nsec3 *)rrp->rdata)->ttl,
+ ((struct nsec3 *)rrp->rdata)->algorithm,
+ ((struct nsec3 *)rrp->rdata)->flags,
+ ((struct nsec3 *)rrp->rdata)->iterations,
+ (((struct nsec3 *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3 *)rrp->rdata)->salt, ((struct nsec3 *)rrp->rdata)->saltlen),
+ base32hex_encode(((struct nsec3 *)rrp->rdata)->next, ((struct nsec3 *)rrp->rdata)->nextlen),
+ bitmap2human(((struct nsec3 *)rrp->rdata)->bitmap, ((struct nsec3 *)rrp->rdata)->bitmap_len));
}
- if (sdomain->flags & DOMAIN_HAVE_RRSIG) {
-#if DEBUG
- printf(" has rrsig\n");
-#endif
-
- if ((sdrr = (struct domain_rrsig *)find_substruct(sdomain, INTERNAL_TYPE_RRSIG)) == NULL) {
- dolog(LOG_INFO, "no rrsigs in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_RRSIG)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no naptr in zone!\n");
return -1;
}
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+#if 0
+ if (((struct rrsig *)rrp2->rdata)->type_covered != DNS_TYPE_DNSKEY)
+ continue;
+#endif
- if ((sdomain->flags & DOMAIN_HAVE_DNSKEY) && sdrr->rrsig_dnskey_count > 0) {
- for (i = 0; i < sdrr->rrsig_dnskey_count; i++) {
- rss = (struct rrsig *)&sdrr->rrsig_dnskey[i];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_DNSKEY],
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
- }
- if (sdomain->flags & DOMAIN_HAVE_SOA) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_SOA];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
+ len = mybase64_encode(((struct rrsig *)rrp2->rdata)->signature, ((struct rrsig *)rrp2->rdata)->signature_len, buf, sizeof(buf));
buf[len] = '\0';
fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct rrsig *)rrp2->rdata)->ttl,
+
+ get_dns_type(((struct rrsig *)rrp2->rdata)->type_covered, 0),
+ ((struct rrsig *)rrp2->rdata)->algorithm,
+ ((struct rrsig *)rrp2->rdata)->labels,
+ ((struct rrsig *)rrp2->rdata)->original_ttl,
+ timethuman(((struct rrsig *)rrp2->rdata)->signature_expiration),
+ timethuman(((struct rrsig *)rrp2->rdata)->signature_inception),
+ ((struct rrsig *)rrp2->rdata)->key_tag,
+ convert_name(((struct rrsig *)rrp2->rdata)->signers_name, ((struct rrsig *)rrp2->rdata)->signame_len),
buf);
}
-
- if (sdomain->flags & DOMAIN_HAVE_DS) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_DS];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
-
- if (sdomain->flags & DOMAIN_HAVE_TLSA) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_TLSA];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_SSHFP) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_SSHFP];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_SRV) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_SRV];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_NAPTR) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NAPTR];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_TXT) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_TXT];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_AAAA) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_AAAA];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_NSEC3) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NSEC3];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone,sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_NSEC3PARAM) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NSEC3PARAM];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,0,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- 0, /* original ttl */
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_CNAME) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_CNAME];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_PTR) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_PTR];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
-
- if (sdomain->flags & DOMAIN_HAVE_NS) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NS];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_MX) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_MX];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_A) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_A];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, " %s,rrsig,%d,%s,%d,%d,%d,%llu,%llu,%d,%s,\"%s\"\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
}
return 0;
@@ -7052,6 +6891,7 @@ connect_server(char *nameserver, int port, u_int32_t f
{
struct sockaddr_in sin;
int so;
+ int window = 32768;
if (format & TCP_FORMAT)
so = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -7063,6 +6903,14 @@ connect_server(char *nameserver, int port, u_int32_t f
return -1;
}
+ /* biggen the window */
+
+ while (setsockopt(so, SOL_SOCKET, SO_RCVBUF, &window, sizeof(window)) != -1)
+ window <<= 1;
+
+ printf("receive window set to %d bytes\n", window >> 1);
+
+
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
@@ -7073,6 +6921,7 @@ connect_server(char *nameserver, int port, u_int32_t f
return -1;
}
+
return (so);
}
@@ -7157,7 +7006,7 @@ lookup_axfr(FILE *f, int so, char *zonename, struct so
for (;;) {
- len = recv(so, reply, 2, MSG_PEEK | MSG_WAITALL);
+ len = recv(so, reply, 0xffff, MSG_PEEK | MSG_WAITALL);
if (len <= 0)
break;
@@ -7967,8 +7816,9 @@ dump_db_bind(ddDB *db, FILE *of, char *zonename)
struct node *n, *nx;
struct question *q;
- struct domain *sdomain;
+ struct rbtree *rbt = NULL;
+
char replystring[512];
char *dnsname;
int labellen;
@@ -7985,12 +7835,12 @@ dump_db_bind(ddDB *db, FILE *of, char *zonename)
return -1;
}
- if ((sdomain = lookup_zone(db, q, &retval, &lzerrno, (char *)&replystring)) == NULL) {
+ if ((rbt = lookup_zone(db, q, &retval, &lzerrno, (char *)&replystring)) == NULL) {
return -1;
}
- if (print_sd_bind(of, sdomain) < 0) {
- fprintf(stderr, "print_sd_bind error\n");
+ if (print_rbt_bind(of, rbt) < 0) {
+ fprintf(stderr, "print_rbt_bind error\n");
return -1;
}
@@ -8000,24 +7850,24 @@ dump_db_bind(ddDB *db, FILE *of, char *zonename)
j = 0;
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
rs = n->datalen;
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sdomain, (char *)n->data, n->datalen);
+ memcpy((char *)rbt, (char *)n->data, n->datalen);
- if (strcmp(convert_name(sdomain->zone, sdomain->zonelen), zonename) == 0) {
- free(sdomain);
+ if (strcmp(convert_name(rbt->zone, rbt->zonelen), zonename) == 0) {
+ free(rbt);
continue;
}
- if (print_sd_bind(of, sdomain) < 0) {
- fprintf(stderr, "print_sd_bind error\n");
+ if (print_rbt_bind(of, rbt) < 0) {
+ fprintf(stderr, "print_rbt_bind error\n");
return -1;
}
- free(sdomain);
+ free(rbt);
j++;
}
@@ -8033,579 +7883,277 @@ dump_db_bind(ddDB *db, FILE *of, char *zonename)
*/
int
-print_sd_bind(FILE *of, struct domain *sdomain)
+print_rbt_bind(FILE *of, struct rbtree *rbt)
{
int i, x, len;
- struct domain_soa *sdsoa;
- struct domain_ns *sdns;
- struct domain_mx *sdmx;
- struct domain_a *sda;
- struct domain_aaaa *sdaaaa;
- struct domain_cname *sdcname;
- struct domain_ptr *sdptr;
- struct domain_txt *sdtxt;
- struct domain_naptr *sdnaptr;
- struct domain_srv *sdsrv;
- struct domain_rrsig *sdrr;
- struct domain_dnskey *sddk;
- struct domain_ds *sdds;
- struct domain_nsec3 *sdn3;
- struct domain_nsec3param *sdn3param;
- struct domain_sshfp *sdsshfp;
- struct domain_tlsa *sdtlsa;
- struct rrsig *rss;
-
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
+ struct rr *rrp2 = NULL;
+
char buf[4096];
- if (sdomain->flags & DOMAIN_HAVE_SOA) {
- if ((sdsoa = (struct domain_soa *)find_substruct(sdomain, INTERNAL_TYPE_SOA)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no soa in zone!\n");
return -1;
}
fprintf(of, "%s %d IN SOA %s %s (\n\t\t\t\t%u\t; Serial\n\t\t\t\t%d\t; Refresh\n\t\t\t\t%d\t; Retry\n\t\t\t\t%d\t; Expire\n\t\t\t\t%d )\t; Minimum TTL\n\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_SOA],
- convert_name(sdsoa->soa.nsserver, sdsoa->soa.nsserver_len),
- convert_name(sdsoa->soa.responsible_person, sdsoa->soa.rp_len),
- sdsoa->soa.serial, sdsoa->soa.refresh, sdsoa->soa.retry,
- sdsoa->soa.expire, sdsoa->soa.minttl);
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct soa *)rrp->rdata)->ttl,
+ convert_name(((struct soa *)rrp->rdata)->nsserver, ((struct soa *)rrp->rdata)->nsserver_len),
+ convert_name(((struct soa *)rrp->rdata)->responsible_person, ((struct soa *)rrp->rdata)->rp_len),
+ ((struct soa *)rrp->rdata)->serial,
+ ((struct soa *)rrp->rdata)->refresh,
+ ((struct soa *)rrp->rdata)->retry,
+ ((struct soa *)rrp->rdata)->expire,
+ ((struct soa *)rrp->rdata)->minttl);
}
- if (sdomain->flags & DOMAIN_HAVE_NS) {
- if ((sdns = (struct domain_ns *)find_substruct(sdomain, INTERNAL_TYPE_NS)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no soa in zone!\n");
return -1;
}
- for (i = 0; i < sdns->ns_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, "%s %d IN NS %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_NS],
- convert_name(sdns->ns[i].nsserver, sdns->ns[i].nslen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct ns *)rrp2->rdata)->ttl,
+ convert_name(((struct ns *)rrp2->rdata)->nsserver, ((struct ns *)rrp2->rdata)->nslen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_MX) {
- if ((sdmx = (struct domain_mx *)find_substruct(sdomain, INTERNAL_TYPE_MX)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no mx in zone!\n");
return -1;
}
- for (i = 0; i < sdmx->mx_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, "%s %d IN MX %d %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_MX],
- sdmx->mx[i].preference,
- convert_name(sdmx->mx[i].exchange, sdmx->mx[i].exchangelen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct smx *)rrp2->rdata)->ttl,
+ ((struct smx *)rrp2->rdata)->preference,
+ convert_name(((struct smx *)rrp2->rdata)->exchange, ((struct smx *)rrp2->rdata)->exchangelen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_DS) {
- if ((sdds = (struct domain_ds *)find_substruct(sdomain, INTERNAL_TYPE_DS)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no ds in zone!\n");
return -1;
}
- for (i = 0; i < sdds->ds_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, "%s %d IN DS %d %d %d (%s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_DS],
- sdds->ds[i].key_tag,
- sdds->ds[i].algorithm,
- sdds->ds[i].digest_type,
- bin2hex(sdds->ds[i].digest, sdds->ds[i].digestlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct ds *)rrp2->rdata)->ttl,
+ ((struct ds *)rrp2->rdata)->key_tag,
+ ((struct ds *)rrp2->rdata)->algorithm,
+ ((struct ds *)rrp2->rdata)->digest_type,
+ bin2hex(((struct ds *)rrp2->rdata)->digest, ((struct ds *)rrp2->rdata)->digestlen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_CNAME) {
- if ((sdcname = (struct domain_cname *)find_substruct(sdomain, INTERNAL_TYPE_CNAME)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_CNAME)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no soa in zone!\n");
return -1;
}
fprintf(of, "%s %d IN CNAME %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_CNAME],
- convert_name(sdcname->cname, sdcname->cnamelen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct cname *)rrp->rdata)->ttl,
+ convert_name(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen));
}
- if (sdomain->flags & DOMAIN_HAVE_NAPTR) {
- if ((sdnaptr = (struct domain_naptr *)find_substruct(sdomain, INTERNAL_TYPE_NAPTR)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no ds in zone!\n");
return -1;
}
- for (i = 0; i < sdnaptr->naptr_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, "%s %d IN NAPTR %d\t%d\t\"",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_NAPTR],
- sdnaptr->naptr[i].order,
- sdnaptr->naptr[i].preference);
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct naptr *)rrp2->rdata)->ttl,
+ ((struct naptr *)rrp2->rdata)->order,
+ ((struct naptr *)rrp2->rdata)->preference);
- for (x = 0; x < sdnaptr->naptr[i].flagslen; x++) {
- fprintf(of, "%c", sdnaptr->naptr[i].flags[x]);
+ for (x = 0; x < ((struct naptr *)rrp2->rdata)->flagslen; x++) {
+ fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->flags[x]);
}
fprintf(of, "\"\t\"");
- for (x = 0; x < sdnaptr->naptr[i].serviceslen; x++) {
- fprintf(of, "%c", sdnaptr->naptr[i].services[x]);
+ for (x = 0; x < ((struct naptr *)rrp2->rdata)->serviceslen; x++) {
+ fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->services[x]);
}
fprintf(of, "\"\t\"");
- for (x = 0; x < sdnaptr->naptr[i].regexplen; x++) {
- fprintf(of, "%c", sdnaptr->naptr[i].regexp[x]);
+ for (x = 0; x < ((struct naptr *)rrp2->rdata)->regexplen; x++) {
+ fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->regexp[x]);
}
- fprintf(of, "\"\t%s\n", (sdnaptr->naptr[i].replacement[0] == '\0') ? "." : convert_name(sdnaptr->naptr[i].replacement, sdnaptr->naptr[i].replacementlen));
+ fprintf(of, "\"\t%s\n", (((struct naptr *)rrp2->rdata)->replacement[0] == '\0') ? "." : convert_name(((struct naptr *)rrp2->rdata)->replacement, ((struct naptr *)rrp2->rdata)->replacementlen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_TXT) {
- if ((sdtxt = (struct domain_txt *)find_substruct(sdomain, INTERNAL_TYPE_TXT)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no ds in zone!\n");
return -1;
}
fprintf(of, "%s %d IN TXT \"",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_TXT]);
- for (i = 0; i < sdtxt->txtlen; i++) {
- fprintf(of, "%c", sdtxt->txt[i]);
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct txt *)rrp->rdata)->ttl);
+
+ for (i = 0; i < ((struct txt *)rrp->rdata)->txtlen; i++) {
+ fprintf(of, "%c", ((struct txt *)rrp->rdata)->txt[i]);
}
fprintf(of, "\"\n");
}
- if (sdomain->flags & DOMAIN_HAVE_PTR) {
- if ((sdptr = (struct domain_ptr *)find_substruct(sdomain, INTERNAL_TYPE_PTR)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no ds in zone!\n");
return -1;
}
fprintf(of, "%s %d IN PTR %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_PTR],
- convert_name(sdptr->ptr, sdptr->ptrlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct ptr *)rrp->rdata)->ttl,
+ convert_name(((struct ptr *)rrp->rdata)->ptr, ((struct ptr *)rrp->rdata)->ptrlen));
}
- if (sdomain->flags & DOMAIN_HAVE_SRV) {
- if ((sdsrv = (struct domain_srv *)find_substruct(sdomain, INTERNAL_TYPE_SRV)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no srv in zone!\n");
return -1;
}
- for (i = 0; i < sdsrv->srv_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, "%s %d IN SRV %d %d %d %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_SRV],
- sdsrv->srv[i].priority,
- sdsrv->srv[i].weight,
- sdsrv->srv[i].port,
- convert_name(sdsrv->srv[i].target,sdsrv->srv[i].targetlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct srv *)rrp2->rdata)->ttl,
+ ((struct srv *)rrp2->rdata)->priority,
+ ((struct srv *)rrp2->rdata)->weight,
+ ((struct srv *)rrp2->rdata)->port,
+ convert_name(((struct srv *)rrp2->rdata)->target,((struct srv *)rrp2->rdata)->targetlen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_TLSA) {
- if ((sdtlsa = (struct domain_tlsa *)find_substruct(sdomain, INTERNAL_TYPE_TLSA)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no tlsa in zone!\n");
return -1;
}
- for (i = 0; i < sdtlsa->tlsa_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, "%s %d IN TLSA %d %d %d (%s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_TLSA],
- sdtlsa->tlsa[i].usage,
- sdtlsa->tlsa[i].selector,
- sdtlsa->tlsa[i].matchtype,
- bin2hex(sdtlsa->tlsa[i].data, sdtlsa->tlsa[i].datalen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct tlsa *)rrp2->rdata)->ttl,
+ ((struct tlsa *)rrp2->rdata)->usage,
+ ((struct tlsa *)rrp2->rdata)->selector,
+ ((struct tlsa *)rrp2->rdata)->matchtype,
+ bin2hex(((struct tlsa *)rrp2->rdata)->data, ((struct tlsa *)rrp2->rdata)->datalen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_SSHFP) {
- if ((sdsshfp = (struct domain_sshfp *)find_substruct(sdomain, INTERNAL_TYPE_SSHFP)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no sshfp in zone!\n");
return -1;
}
- for (i = 0; i < sdsshfp->sshfp_count; i++) {
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
fprintf(of, "%s %d IN SSHFP %d %d (%s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_SSHFP],
- sdsshfp->sshfp[i].algorithm,
- sdsshfp->sshfp[i].fptype,
- bin2hex(sdsshfp->sshfp[i].fingerprint, sdsshfp->sshfp[i].fplen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct sshfp *)rrp2->rdata)->ttl,
+ ((struct sshfp *)rrp2->rdata)->algorithm,
+ ((struct sshfp *)rrp2->rdata)->fptype,
+ bin2hex(((struct sshfp *)rrp2->rdata)->fingerprint, ((struct sshfp *)rrp2->rdata)->fplen));
}
}
- if (sdomain->flags & DOMAIN_HAVE_A) {
- if ((sda = (struct domain_a *)find_substruct(sdomain, INTERNAL_TYPE_A)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no a RR in zone!\n");
return -1;
}
- for (i = 0; i < sda->a_count; i++) {
- inet_ntop(AF_INET, &sda->a[i], buf, sizeof(buf));
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+ inet_ntop(AF_INET, &((struct a *)rrp2->rdata)->a, buf, sizeof(buf));
fprintf(of, "%s %d IN A %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_A],
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct a *)rrp2->rdata)->ttl,
buf);
}
}
- if (sdomain->flags & DOMAIN_HAVE_AAAA) {
- if ((sdaaaa = (struct domain_aaaa *)find_substruct(sdomain, INTERNAL_TYPE_AAAA)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no a RR in zone!\n");
return -1;
}
- for (i = 0; i < sdaaaa->aaaa_count; i++) {
- inet_ntop(AF_INET6, &sdaaaa->aaaa[i], buf, sizeof(buf));
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+ inet_ntop(AF_INET6, &((struct aaaa *)rrp2->rdata)->aaaa , buf, sizeof(buf));
fprintf(of, "%s %d IN AAAA %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_AAAA],
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct aaaa *)rrp2->rdata)->ttl,
buf);
}
}
- if (sdomain->flags & DOMAIN_HAVE_DNSKEY) {
-#if DEBUG
- printf(" has dnskey\n");
-#endif
- if ((sddk = (struct domain_dnskey *)find_substruct(sdomain, INTERNAL_TYPE_DNSKEY)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no a RR in zone!\n");
return -1;
}
- for (i = 0; i < sddk->dnskey_count; i++) {
- len = mybase64_encode(sddk->dnskey[i].public_key, sddk->dnskey[i].publickey_len, buf, sizeof(buf));
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+ len = mybase64_encode(((struct dnskey *)rrp2->rdata)->public_key, ((struct dnskey *)rrp2->rdata)->publickey_len, buf, sizeof(buf));
buf[len] = '\0';
fprintf(of, "%s %d IN DNSKEY %d %d %d (%s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_DNSKEY],
- sddk->dnskey[i].flags,
- sddk->dnskey[i].protocol,
- sddk->dnskey[i].algorithm,
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct dnskey *)rrp2->rdata)->ttl,
+ ((struct dnskey *)rrp2->rdata)->flags,
+ ((struct dnskey *)rrp2->rdata)->protocol,
+ ((struct dnskey *)rrp2->rdata)->algorithm,
buf);
}
}
- if (sdomain->flags & DOMAIN_HAVE_NSEC3PARAM) {
-#if DEBUG
- printf("has nsec3param\n");
-#endif
- if ((sdn3param = (struct domain_nsec3param *)find_substruct(sdomain, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
- dolog(LOG_INFO, "no nsec3param in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no NSEC3PARAM RR in zone!\n");
return -1;
}
fprintf(of, "%s 0 IN NSEC3PARAM %d %d %d (%s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdn3param->nsec3param.algorithm,
- sdn3param->nsec3param.flags,
- sdn3param->nsec3param.iterations,
- (sdn3param->nsec3param.saltlen == 0) ? "-" : bin2hex(sdn3param->nsec3param.salt, sdn3param->nsec3param.saltlen));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct nsec3param *)rrp->rdata)->algorithm,
+ ((struct nsec3param *)rrp->rdata)->flags,
+ ((struct nsec3param *)rrp->rdata)->iterations,
+ (((struct nsec3param *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3param *)rrp->rdata)->salt, ((struct nsec3param *)rrp->rdata)->saltlen));
}
- if (sdomain->flags & DOMAIN_HAVE_NSEC3) {
-#if DEBUG
- printf("has nsec3\n");
-#endif
- if ((sdn3 = (struct domain_nsec3 *)find_substruct(sdomain, INTERNAL_TYPE_NSEC3)) == NULL) {
- dolog(LOG_INFO, "no nsec3 in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no NSEC3PARAM RR in zone!\n");
return -1;
}
fprintf(of, "%s %d IN NSEC3 %d %d %d %s %s %s\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_NSEC3],
- sdn3->nsec3.algorithm,
- sdn3->nsec3.flags,
- sdn3->nsec3.iterations,
- (sdn3->nsec3.saltlen == 0) ? "-" : bin2hex(sdn3->nsec3.salt, sdn3->nsec3.saltlen),
- base32hex_encode(sdn3->nsec3.next, sdn3->nsec3.nextlen),
- bitmap2human(sdn3->nsec3.bitmap, sdn3->nsec3.bitmap_len));
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct nsec3 *)rrp->rdata)->ttl,
+ ((struct nsec3 *)rrp->rdata)->algorithm,
+ ((struct nsec3 *)rrp->rdata)->flags,
+ ((struct nsec3 *)rrp->rdata)->iterations,
+ (((struct nsec3 *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3 *)rrp->rdata)->salt, ((struct nsec3 *)rrp->rdata)->saltlen),
+ base32hex_encode(((struct nsec3 *)rrp->rdata)->next, ((struct nsec3 *)rrp->rdata)->nextlen),
+ bitmap2human(((struct nsec3 *)rrp->rdata)->bitmap, ((struct nsec3 *)rrp->rdata)->bitmap_len));
}
- if (sdomain->flags & DOMAIN_HAVE_RRSIG) {
-#if DEBUG
- printf(" has rrsig\n");
-#endif
-
- if ((sdrr = (struct domain_rrsig *)find_substruct(sdomain, INTERNAL_TYPE_RRSIG)) == NULL) {
- dolog(LOG_INFO, "no rrsigs in zone!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_RRSIG)) != NULL) {
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ dolog(LOG_INFO, "no a RR in zone!\n");
return -1;
}
-
- if ((sdomain->flags & DOMAIN_HAVE_DNSKEY) && sdrr->rrsig_dnskey_count > 0) {
- for (i = 0; i < sdrr->rrsig_dnskey_count; i++) {
- rss = (struct rrsig *)&sdrr->rrsig_dnskey[i];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- sdomain->ttl[INTERNAL_TYPE_DNSKEY],
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
- }
- if (sdomain->flags & DOMAIN_HAVE_SOA) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_SOA];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
+ TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
+ len = mybase64_encode(((struct rrsig *)rrp2->rdata)->signature, ((struct rrsig *)rrp2->rdata)->signature_len, buf, sizeof(buf));
buf[len] = '\0';
fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
+ convert_name(rbt->zone, rbt->zonelen),
+ ((struct rrsig *)rrp2->rdata)->ttl,
+ get_dns_type(((struct rrsig *)rrp2->rdata)->type_covered, 0),
+ ((struct rrsig *)rrp2->rdata)->algorithm,
+ ((struct rrsig *)rrp2->rdata)->labels,
+ ((struct rrsig *)rrp2->rdata)->original_ttl,
+ timethuman(((struct rrsig *)rrp2->rdata)->signature_expiration),
+ timethuman(((struct rrsig *)rrp2->rdata)->signature_inception),
+ ((struct rrsig *)rrp2->rdata)->key_tag,
+ convert_name(((struct rrsig *)rrp2->rdata)->signers_name, ((struct rrsig *)rrp2->rdata)->signame_len),
buf);
}
-
- if (sdomain->flags & DOMAIN_HAVE_DS) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_DS];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
-
- if (sdomain->flags & DOMAIN_HAVE_TLSA) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_TLSA];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_SSHFP) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_SSHFP];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_SRV) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_SRV];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN rrsig (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_NAPTR) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NAPTR];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_TXT) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_TXT];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_AAAA) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_AAAA];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_NSEC3) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NSEC3];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone,sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
- if (sdomain->flags & DOMAIN_HAVE_NSEC3PARAM) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NSEC3PARAM];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s 0 IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- 0, /* original ttl */
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_CNAME) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_CNAME];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_PTR) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_PTR];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
-
-
- if (sdomain->flags & DOMAIN_HAVE_NS) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_NS];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_MX) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_MX];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
-
- if (sdomain->flags & DOMAIN_HAVE_A) {
- rss = (struct rrsig *)&sdrr->rrsig[INTERNAL_TYPE_A];
- len = mybase64_encode(rss->signature, rss->signature_len, buf, sizeof(buf));
- buf[len] = '\0';
-
- fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
- convert_name(sdomain->zone, sdomain->zonelen),
- rss->original_ttl,
- get_dns_type(rss->type_covered, 0),
- rss->algorithm, rss->labels,
- rss->original_ttl,
- timethuman(rss->signature_expiration),
- timethuman(rss->signature_inception),
- rss->key_tag,
- convert_name(rss->signers_name, rss->signame_len),
- buf);
- }
}
return 0;
}
+
int
bindfile(int argc, char *argv[])
{
@@ -8855,161 +8403,105 @@ BN_GENCB_free(BN_GENCB *cb)
int
count_db(ddDB *db)
{
- struct domain *sdomain;
+ struct rbtree *rbt;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
struct node *n, *nx;
int count = 0;
int rs;
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
rs = n->datalen;
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sdomain, (char *)n->data, n->datalen);
+ memcpy((char *)rbt, (char *)n->data, n->datalen);
- if (sdomain->flags & DOMAIN_HAVE_DNSKEY) {
- struct domain_dnskey *sdr = NULL;
- if ((sdr = (struct domain_dnskey *)find_substruct(sdomain, INTERNAL_TYPE_DNSKEY)) == NULL) {
- dolog(LOG_INFO, "no dnskeys in zone!\n");
- return -1;
+
+ if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
}
- if (sdomain->flags & DOMAIN_HAVE_A) {
- struct domain_a *sdr = NULL;
- if ((sdr = (struct domain_a *)find_substruct(sdomain, INTERNAL_TYPE_A)) == NULL) {
- dolog(LOG_INFO, "no as in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count += sdr->a_count;
}
- if (sdomain->flags & DOMAIN_HAVE_MX) {
- struct domain_mx *sdr = NULL;
- if ((sdr = (struct domain_mx *)find_substruct(sdomain, INTERNAL_TYPE_MX)) == NULL) {
- dolog(LOG_INFO, "no mxs in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count += sdr->mx_count;
}
- if (sdomain->flags & DOMAIN_HAVE_NS) {
- struct domain_ns *sdr = NULL;
- if ((sdr = (struct domain_ns *)find_substruct(sdomain, INTERNAL_TYPE_NS)) == NULL) {
- dolog(LOG_INFO, "no nss in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count += sdr->ns_count;
}
- if (sdomain->flags & DOMAIN_HAVE_SOA) {
- struct domain_soa *sdr = NULL;
- if ((sdr = (struct domain_soa *)find_substruct(sdomain, INTERNAL_TYPE_SOA)) == NULL) {
- dolog(LOG_INFO, "no soas in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count++;
}
- if (sdomain->flags & DOMAIN_HAVE_TXT) {
- struct domain_txt *sdr = NULL;
- if ((sdr = (struct domain_txt *)find_substruct(sdomain, INTERNAL_TYPE_TXT)) == NULL) {
- dolog(LOG_INFO, "no txts in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count++;
}
- if (sdomain->flags & DOMAIN_HAVE_AAAA) {
- struct domain_aaaa *sdr = NULL;
- if ((sdr = (struct domain_aaaa *)find_substruct(sdomain, INTERNAL_TYPE_AAAA)) == NULL) {
- dolog(LOG_INFO, "no aaaas in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count += sdr->aaaa_count;
}
- if (sdomain->flags & DOMAIN_HAVE_NSEC3) {
- struct domain_nsec3 *sdr = NULL;
- if ((sdr = (struct domain_nsec3 *)find_substruct(sdomain, INTERNAL_TYPE_NSEC3)) == NULL) {
- dolog(LOG_INFO, "no nsec3s in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count++;
}
- if (sdomain->flags & DOMAIN_HAVE_NSEC3PARAM) {
- struct domain_nsec3param *sdr = NULL;
- if ((sdr = (struct domain_nsec3param *)find_substruct(sdomain, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
- dolog(LOG_INFO, "no nsec3params in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
- count++;
}
- if (sdomain->flags & DOMAIN_HAVE_CNAME) {
- struct domain_cname *sdr = NULL;
- if ((sdr = (struct domain_cname *)find_substruct(sdomain, INTERNAL_TYPE_CNAME)) == NULL) {
- dolog(LOG_INFO, "no cnames in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_CNAME)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
- count++;
}
- if (sdomain->flags & DOMAIN_HAVE_PTR) {
- struct domain_ptr *sdr = NULL;
- if ((sdr = (struct domain_ptr *)find_substruct(sdomain, INTERNAL_TYPE_PTR)) == NULL) {
- dolog(LOG_INFO, "no ptrs in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count++;
}
- if (sdomain->flags & DOMAIN_HAVE_NAPTR) {
- struct domain_naptr *sdr = NULL;
- if ((sdr = (struct domain_naptr *)find_substruct(sdomain, INTERNAL_TYPE_NAPTR)) == NULL) {
- dolog(LOG_INFO, "no naptrs in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count += sdr->naptr_count;
}
- if (sdomain->flags & DOMAIN_HAVE_SRV) {
- struct domain_srv *sdr = NULL;
- if ((sdr = (struct domain_srv *)find_substruct(sdomain, INTERNAL_TYPE_SRV)) == NULL) {
- dolog(LOG_INFO, "no srvs in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
- count += sdr->srv_count;
}
- if (sdomain->flags & DOMAIN_HAVE_SSHFP) {
- struct domain_sshfp *sdr = NULL;
- if ((sdr = (struct domain_sshfp *)find_substruct(sdomain, INTERNAL_TYPE_SSHFP)) == NULL) {
- dolog(LOG_INFO, "no sshfps in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
- count += sdr->sshfp_count;
}
- if (sdomain->flags & DOMAIN_HAVE_TLSA) {
- struct domain_tlsa *sdr = NULL;
- if ((sdr = (struct domain_tlsa *)find_substruct(sdomain, INTERNAL_TYPE_TLSA)) == NULL) {
- dolog(LOG_INFO, "no tlsas in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count += sdr->tlsa_count;
}
- if (sdomain->flags & DOMAIN_HAVE_DS) {
- struct domain_ds *sdr = NULL;
- if ((sdr = (struct domain_ds *)find_substruct(sdomain, INTERNAL_TYPE_DS)) == NULL) {
- dolog(LOG_INFO, "no ds in zone!\n");
- return -1;
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ count++;
}
-
- count += sdr->ds_count;
}
-
- free(sdomain);
+ free(rbt);
}
printf("Records = %d , ", count);
blob - 021ef0f1c5c03e12fe4d19723c71c085f8b063e5
blob + 5a800ea5f42246a605589b634deaed96bf55f86c
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: delphinusdnsd.c,v 1.49 2019/02/07 11:16:03 pjp Exp $
+ * $Id: delphinusdnsd.c,v 1.50 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
@@ -42,25 +42,21 @@ extern void axfrloop(int *, int, char **, ddDB *, str
extern struct question *build_fake_question(char *, int, u_int16_t);
extern int check_ent(char *, int);
extern int check_rrlimit(int, u_int16_t *, int, char *);
-extern u_int16_t check_qtype(struct domain *, u_int16_t, int, int *);
extern void collects_init(void);
extern void dolog(int, char *, ...);
extern int find_axfr(struct sockaddr_storage *, int);
extern int find_filter(struct sockaddr_storage *, int);
-extern int find_recurse(struct sockaddr_storage *, int);
extern u_int8_t find_region(struct sockaddr_storage *, int);
extern int find_whitelist(struct sockaddr_storage *, int);
extern char * get_dns_type(int, int);
extern void init_dnssec(void);
-extern void init_recurse(void);
extern void init_region(void);
extern int init_entlist(ddDB *);
extern void init_filter(void);
extern void init_notifyslave(void);
extern void init_whitelist(void);
-extern struct domain * lookup_zone(ddDB *, struct question *, int *, int *, char *);
+extern struct rbtree * lookup_zone(ddDB *, struct question *, int *, int *, char *);
extern int memcasecmp(u_char *, u_char *, int);
-extern void recurseloop(int sp, int *, ddDB *);
extern void receivelog(char *, int);
extern int reply_a(struct sreply *, ddDB *);
extern int reply_aaaa(struct sreply *, ddDB *);
@@ -94,19 +90,22 @@ extern char *rrlimit_setup(int);
extern char *dns_label(char *, int *);
extern void slave_shutdown(void);
extern int get_record_size(ddDB *, char *, int);
-extern void * find_substruct(struct domain *, u_int16_t);
extern struct question *build_question(char *, int, int);
extern int free_question(struct question *);
+extern struct rbtree * create_rr(ddDB *db, char *name, int len, int type, void *rdata);
+extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
+extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+extern int add_rr(struct rbtree *rbt, char *name, int len, u_int16_t rrtype, void *rdata);
+extern int display_rr(struct rrset *rrset);
+
struct question *convert_question(struct parsequestion *);
-void build_reply(struct sreply *, int, char *, int, struct question *, struct sockaddr *, socklen_t, struct domain *, struct domain *, u_int8_t, int, int, struct recurses *, char *);
+void build_reply(struct sreply *, int, char *, int, struct question *, struct sockaddr *, socklen_t, struct rbtree *, struct rbtree *, u_int8_t, int, int, void *, char *);
int compress_label(u_char *, u_int16_t, int);
-struct domain * get_soa(ddDB *, struct question *);
-int lookup_type(int);
+struct rbtree * get_soa(ddDB *, struct question *);
void mainloop(struct cfg *, struct imsgbuf **);
void master_reload(int);
void master_shutdown(int);
-void recurseheader(struct srecurseheader *, int, struct sockaddr_storage *, struct sockaddr_storage *, int);
void setup_master(ddDB *, char **, char *, struct imsgbuf *ibuf);
void setup_unixsocket(char *, struct imsgbuf *);
void slave_signal(int);
@@ -1284,67 +1283,38 @@ out:
* GET_SOA - get authoritative soa for a particular domain
*/
-struct domain *
+struct rbtree *
get_soa(ddDB *db, struct question *question)
{
- struct domain *sd = NULL;
+ struct rbtree *rbt = NULL;
int plen;
- int ret = 0;
- int rs;
-
- ddDBT key, data;
-
char *p;
p = question->hdr->name;
plen = question->hdr->namelen;
do {
+ struct rrset *rrset;
- rs = get_record_size(db, p, plen);
- if (rs < 0) {
- return NULL;
- }
-
- if ((sd = calloc(1, rs)) == NULL) {
- return NULL;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = (char *)p;
- key.size = plen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
+ rbt = find_rrset(db, p, plen);
+ if (rbt == NULL) {
plen -= (*p + 1);
p = (p + (*p + 1));
- free (sd);
+ free (rbt);
continue;
}
- if (data.size != rs) {
- dolog(LOG_INFO, "btree db is damaged, drop\n");
- free(sd);
- return (NULL);
- }
-
- memcpy((char *)sd, (char *)data.data, data.size);
-
- if ((sd->flags & DOMAIN_HAVE_SOA) == DOMAIN_HAVE_SOA) {
+ rrset = find_rr(rbt, DNS_TYPE_SOA);
+ if (rrset != NULL) {
/* we'll take this one */
- return (sd);
+ return (rbt);
} else {
plen -= (*p + 1);
p = (p + (*p + 1));
}
- free(sd);
+ free(rbt);
} while (*p);
return (NULL);
@@ -1406,8 +1376,9 @@ mainloop(struct cfg *cfg, struct imsgbuf **ibuf)
struct question *question = NULL, *fakequestion = NULL;
struct parsequestion pq;
- struct domain *sd0 = NULL, *sd1 = NULL;
- struct domain_cname *csd;
+ struct rbtree *rbt0 = NULL, *rbt1 = NULL;
+ struct rrset *csd;
+ struct rr *rr_csd;
struct sreply sreply;
struct reply_logic *rl = NULL;
@@ -1797,7 +1768,7 @@ axfrentry:
fakequestion = NULL;
- sd0 = lookup_zone(cfg->db, question, &type0, &lzerrno, (char *)&replystring);
+ rbt0 = lookup_zone(cfg->db, question, &type0, &lzerrno, (char *)&replystring);
if (type0 < 0) {
switch (lzerrno) {
default:
@@ -1817,7 +1788,7 @@ axfrentry:
}
snprintf(replystring, DNS_MAXNAME, "REFUSED");
- build_reply(&sreply, so, buf, len, question, from, fromlen, sd0, NULL, aregion, istcp, 0, NULL, replybuf);
+ build_reply(&sreply, so, buf, len, question, from, fromlen, rbt0, NULL, aregion, istcp, 0, NULL, replybuf);
slen = reply_refused(&sreply, NULL);
goto udpout;
break;
@@ -1828,7 +1799,7 @@ axfrentry:
goto udpnoerror;
} else {
snprintf(replystring, DNS_MAXNAME, "NODATA");
- build_reply(&sreply, so, buf, len, question, from, fromlen, sd0, NULL, aregion, istcp, 0, NULL, replybuf);
+ build_reply(&sreply, so, buf, len, question, from, fromlen, rbt0, NULL, aregion, istcp, 0, NULL, replybuf);
slen = reply_nodata(&sreply, NULL);
goto udpout;
break;
@@ -1849,16 +1820,16 @@ udpnoerror:
* lookup an authoritative soa
*/
- if (sd0) {
- free (sd0);
- sd0 = NULL;
+ if (rbt0) {
+ free (rbt0);
+ rbt0 = NULL;
}
- sd0 = get_soa(cfg->db, question);
- if (sd0 != NULL) {
+ rbt0 = get_soa(cfg->db, question);
+ if (rbt0 != NULL) {
build_reply(&sreply, so, buf, len, question, from, \
- fromlen, sd0, NULL, aregion, istcp, 0,
+ fromlen, rbt0, NULL, aregion, istcp, 0,
NULL, replybuf);
slen = reply_noerror(&sreply, cfg->db);
@@ -1875,7 +1846,7 @@ udpnxdomain:
goto udpnoerror;
} else {
snprintf(replystring, DNS_MAXNAME, "NODATA");
- build_reply(&sreply, so, buf, len, question, from, fromlen, sd0, NULL, aregion, istcp, 0, NULL, replybuf);
+ build_reply(&sreply, so, buf, len, question, from, fromlen, rbt0, NULL, aregion, istcp, 0, NULL, replybuf);
slen = reply_nodata(&sreply, NULL);
goto udpout;
}
@@ -1891,23 +1862,30 @@ udpnxdomain:
* lookup an authoritative soa
*/
- if (sd0 != NULL) {
+ if (rbt0 != NULL) {
build_reply(&sreply, so, buf, len, question, from, \
- fromlen, sd0, NULL, aregion, istcp, \
+ fromlen, rbt0, NULL, aregion, istcp, \
0, NULL, replybuf);
slen = reply_nxdomain(&sreply, cfg->db);
}
goto udpout;
case DNS_TYPE_CNAME:
- csd = (struct domain_cname *)find_substruct(sd0, INTERNAL_TYPE_CNAME);
- fakequestion = build_fake_question(csd->cname, csd->cnamelen, question->hdr->qtype);
+ csd = find_rr(rbt0, DNS_TYPE_SOA);
+ if (csd == NULL)
+ break;
+
+ rr_csd = TAILQ_FIRST(&csd->rr_head);
+ if (rr_csd == NULL)
+ break;
+
+ fakequestion = build_fake_question(((struct cname *)rr_csd)->cname, ((struct cname *)rr_csd)->cnamelen, question->hdr->qtype);
if (fakequestion == NULL) {
dolog(LOG_INFO, "fakequestion failed\n");
break;
}
- sd1 = lookup_zone(cfg->db, fakequestion, &type1, &lzerrno, (char *)&fakereplystring);
+ rbt1 = lookup_zone(cfg->db, fakequestion, &type1, &lzerrno, (char *)&fakereplystring);
/* break CNAMES pointing to CNAMES */
if (type1 == DNS_TYPE_CNAME)
type1 = 0;
@@ -1943,12 +1921,12 @@ udpnxdomain:
switch (rl->buildtype) {
case BUILD_CNAME:
build_reply(&sreply, so, buf, len, question,
- from, fromlen, sd0, ((type1 > 0) ? sd1 :
+ from, fromlen, rbt0, ((type1 > 0) ? rbt1 :
NULL), aregion, istcp, 0, NULL, replybuf);
break;
case BUILD_OTHER:
build_reply(&sreply, so, buf, len, question,
- from, fromlen, sd0, NULL, aregion, istcp,
+ from, fromlen, rbt0, NULL, aregion, istcp,
0, NULL, replybuf);
break;
}
@@ -1972,7 +1950,7 @@ udpnxdomain:
if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, buf, len, question, from, \
- fromlen, sd0, NULL, aregion, istcp, 0, \
+ fromlen, rbt0, NULL, aregion, istcp, 0, \
NULL, replybuf);
slen = reply_ns(&sreply, cfg->db);
@@ -2004,13 +1982,13 @@ udpnxdomain:
free_question(question);
- if (sd0) {
- free (sd0);
- sd0 = NULL;
+ if (rbt0) {
+ free (rbt0);
+ rbt0 = NULL;
}
- if (sd1) {
- free (sd1);
- sd1 = NULL;
+ if (rbt1) {
+ free (rbt1);
+ rbt1 = NULL;
}
} /* END ISSET */
@@ -2028,14 +2006,14 @@ udpnxdomain:
drop:
- if (sd0) {
- free(sd0);
- sd0 = NULL;
+ if (rbt0) {
+ free(rbt0);
+ rbt0 = NULL;
}
- if (sd1) {
- free(sd1);
- sd1 = NULL;
+ if (rbt1) {
+ free(rbt1);
+ rbt1 = NULL;
}
continue;
@@ -2051,7 +2029,7 @@ udpnxdomain:
*/
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 deprecated0, struct recurses *sr, char *replybuf)
+build_reply(struct sreply *reply, int so, char *buf, int len, struct question *q, struct sockaddr *sa, socklen_t slen, struct rbtree *rbt1, struct rbtree *rbt2, u_int8_t region, int istcp, int deprecated0, void *sr, char *replybuf)
{
reply->so = so;
reply->buf = buf;
@@ -2059,68 +2037,18 @@ build_reply(struct sreply *reply, int so, char *buf, i
reply->q = q;
reply->sa = sa;
reply->salen = slen;
- reply->sd1 = sd1;
- reply->sd2 = sd2;
+ reply->rbt1 = rbt1;
+ reply->rbt2 = rbt2;
reply->region = region;
reply->istcp = istcp;
reply->wildcard = 0;
- reply->sr = sr;
+ reply->sr = NULL;
reply->replybuf = replybuf;
return;
}
-void
-recurseheader(struct srecurseheader *rh, int proto, struct sockaddr_storage *src, struct sockaddr_storage *dst, int family)
-{
- struct sockaddr_in *sin, *sin0;
- struct sockaddr_in6 *sin6, *sin60;
-
- rh->af = family;
- rh->proto = proto;
-
- if (family == AF_INET) {
- sin = (struct sockaddr_in *)&rh->dest;
- sin0 = (struct sockaddr_in *)dst;
- sin->sin_family = sin0->sin_family;
- sin->sin_port = sin0->sin_port;
- memcpy((char *)&sin->sin_addr.s_addr,
- (char *)&sin0->sin_addr.s_addr,
- sizeof(sin->sin_addr.s_addr));
- sin = (struct sockaddr_in *)&rh->source;
- sin0 = (struct sockaddr_in *)src;
- sin->sin_family = sin0->sin_family;
- sin->sin_port = sin0->sin_port;
- memcpy((char *)&sin->sin_addr.s_addr,
- (char *)&sin0->sin_addr.s_addr,
- sizeof(sin->sin_addr.s_addr));
- } else if (family == AF_INET6) {
- sin6 = (struct sockaddr_in6 *)&rh->dest;
- sin60 = (struct sockaddr_in6 *)dst;
-
- sin6->sin6_family = sin60->sin6_family;
- sin6->sin6_port = sin60->sin6_port;
-
- memcpy((char *)&sin6->sin6_addr,
- (char *)&sin60->sin6_addr,
- sizeof(sin6->sin6_addr));
-
- sin6 = (struct sockaddr_in6 *)&rh->source;
- sin60 = (struct sockaddr_in6 *)src;
-
- sin6->sin6_family = sin60->sin6_family;
- sin6->sin6_port = sin60->sin6_port;
-
- memcpy((char *)&sin6->sin6_addr,
- (char *)&sin60->sin6_addr,
- sizeof(sin6->sin6_addr));
- }
-
-
- return;
-}
-
/*
* The master process, waits to be killed, if any other processes are killed
* and they indicate shutdown through the shared memory segment it will kill
@@ -2137,7 +2065,6 @@ setup_master(ddDB *db, char **av, char *socketpath, st
fd_set rset;
struct timeval tv;
- struct domain *idata;
struct imsg imsg;
#if __OpenBSD__
@@ -2155,14 +2082,6 @@ setup_master(ddDB *db, char **av, char *socketpath, st
}
#endif
- idata = (struct domain *)calloc(1, SIZENODE);
- if (idata == NULL) {
- dolog(LOG_ERR, "couldn't malloc memory for idata\n");
- pid = getpgrp();
- killpg(pid, SIGTERM);
- exit(1);
- }
-
setproctitle("master");
pid = getpid();
@@ -2298,36 +2217,6 @@ master_reload(int sig)
}
-int
-lookup_type(int internal_type)
-{
- int array[INTERNAL_TYPE_MAX];
-
- array[INTERNAL_TYPE_A] = DOMAIN_HAVE_A;
- array[INTERNAL_TYPE_AAAA] = DOMAIN_HAVE_AAAA;
- array[INTERNAL_TYPE_CNAME] = DOMAIN_HAVE_CNAME;
- array[INTERNAL_TYPE_NS] = DOMAIN_HAVE_NS;
- array[INTERNAL_TYPE_DNSKEY] =DOMAIN_HAVE_DNSKEY;
- array[INTERNAL_TYPE_DS] = DOMAIN_HAVE_DS;
- array[INTERNAL_TYPE_MX] = DOMAIN_HAVE_MX;
- array[INTERNAL_TYPE_NAPTR] = DOMAIN_HAVE_NAPTR;
- array[INTERNAL_TYPE_NSEC] = DOMAIN_HAVE_NSEC;
- array[INTERNAL_TYPE_NSEC3] = DOMAIN_HAVE_NSEC3;
- array[INTERNAL_TYPE_NSEC3PARAM] = DOMAIN_HAVE_NSEC3PARAM;
- array[INTERNAL_TYPE_PTR] = DOMAIN_HAVE_PTR;
- array[INTERNAL_TYPE_RRSIG] = -1;
- array[INTERNAL_TYPE_SOA] = DOMAIN_HAVE_SOA;
- array[INTERNAL_TYPE_SRV] = DOMAIN_HAVE_SRV;
- array[INTERNAL_TYPE_SSHFP] = DOMAIN_HAVE_SSHFP;
- array[INTERNAL_TYPE_TLSA] = DOMAIN_HAVE_TLSA;
- array[INTERNAL_TYPE_TXT] = DOMAIN_HAVE_TXT;
-
- if (internal_type < 0 || internal_type > INTERNAL_TYPE_MAX)
- return -1;
-
- return(array[internal_type]);
-}
-
/*
* TCPLOOP - does the polling of tcp descriptors and if ready receives the
* requests, builds the question and calls for replies, loops
@@ -2376,8 +2265,9 @@ tcploop(struct cfg *cfg, struct imsgbuf **ibuf)
struct sockaddr_in6 *sin6;
struct question *question = NULL, *fakequestion = NULL;
- struct domain *sd0 = NULL, *sd1 = NULL;
- struct domain_cname *csd;
+ struct rbtree *rbt0 = NULL, *rbt1 = NULL;
+ struct rrset *csd;
+ struct rr *rr_csd;
struct sreply sreply;
struct reply_logic *rl = NULL;
@@ -2706,7 +2596,7 @@ tcploop(struct cfg *cfg, struct imsgbuf **ibuf)
break;
}
- sd0 = lookup_zone(cfg->db, question, &type0, &lzerrno, (char *)&replystring);
+ rbt0 = lookup_zone(cfg->db, question, &type0, &lzerrno, (char *)&replystring);
if (type0 < 0) {
switch (lzerrno) {
@@ -2727,7 +2617,7 @@ tcploop(struct cfg *cfg, struct imsgbuf **ibuf)
goto tcpout;
}
snprintf(replystring, DNS_MAXNAME, "REFUSED");
- build_reply(&sreply, so, pbuf, len, question, from, fromlen, sd0, NULL, aregion, istcp, 0, NULL, replybuf);
+ build_reply(&sreply, so, pbuf, len, question, from, fromlen, rbt0, NULL, aregion, istcp, 0, NULL, replybuf);
slen = reply_refused(&sreply, NULL);
goto tcpout;
break;
@@ -2738,7 +2628,7 @@ tcploop(struct cfg *cfg, struct imsgbuf **ibuf)
goto tcpnoerror;
} else {
snprintf(replystring, DNS_MAXNAME, "NODATA");
- build_reply(&sreply, so, pbuf, len, question, from, fromlen, sd0, NULL, aregion, istcp, 0, NULL, replybuf);
+ build_reply(&sreply, so, pbuf, len, question, from, fromlen, rbt0, NULL, aregion, istcp, 0, NULL, replybuf);
slen = reply_nodata(&sreply, NULL);
goto tcpout;
break;
@@ -2758,17 +2648,17 @@ tcpnoerror:
* lookup an authoritative soa
*/
- if (sd0) {
- free(sd0);
- sd0 = NULL;
+ if (rbt0) {
+ free(rbt0);
+ rbt0 = NULL;
}
- sd0 = get_soa(cfg->db, question);
- if (sd0 != NULL) {
+ rbt0 = get_soa(cfg->db, question);
+ if (rbt0 != NULL) {
build_reply( &sreply, so, pbuf, len,
question, from, fromlen,
- sd0, NULL, aregion, istcp,
+ rbt0, NULL, aregion, istcp,
0, NULL, replybuf);
slen = reply_noerror(&sreply, cfg->db);
@@ -2786,7 +2676,7 @@ tcpnoerror:
goto tcpnoerror;
} else {
snprintf(replystring, DNS_MAXNAME, "NODATA");
- build_reply(&sreply, so, pbuf, len, question, from, fromlen, sd0, NULL, aregion, istcp, 0, NULL, replybuf);
+ build_reply(&sreply, so, pbuf, len, question, from, fromlen, rbt0, NULL, aregion, istcp, 0, NULL, replybuf);
slen = reply_nodata(&sreply, NULL);
goto tcpout;
}
@@ -2803,10 +2693,10 @@ tcpnxdomain:
/*
* lookup an authoritative soa
*/
- if (sd0 != NULL) {
+ if (rbt0 != NULL) {
build_reply( &sreply, so, pbuf, len, question,
- from, fromlen, sd0, NULL,
+ from, fromlen, rbt0, NULL,
aregion, istcp, 0, NULL,
replybuf);
@@ -2814,14 +2704,21 @@ tcpnxdomain:
}
goto tcpout;
case DNS_TYPE_CNAME:
- csd = (struct domain_cname *)find_substruct(sd0, INTERNAL_TYPE_CNAME);
- fakequestion = build_fake_question(csd->cname, csd->cnamelen, question->hdr->qtype);
+ csd = find_rr(rbt0, DNS_TYPE_SOA);
+ if (csd == NULL)
+ break;
+
+ rr_csd = TAILQ_FIRST(&csd->rr_head);
+ if (rr_csd == NULL)
+ break;
+
+ fakequestion = build_fake_question(((struct cname *)rr_csd)->cname, ((struct cname *)rr_csd)->cnamelen, question->hdr->qtype);
if (fakequestion == NULL) {
dolog(LOG_INFO, "fakequestion failed\n");
break;
}
- sd1 = lookup_zone(cfg->db, fakequestion, &type1, &lzerrno, (char *)&fakereplystring);
+ rbt1 = lookup_zone(cfg->db, fakequestion, &type1, &lzerrno, (char *)&fakereplystring);
/* break CNAMES pointing to CNAMES */
if (type1 == DNS_TYPE_CNAME)
type1 = 0;
@@ -2871,12 +2768,12 @@ tcpnxdomain:
switch (rl->buildtype) {
case BUILD_CNAME:
build_reply(&sreply, so, pbuf, len, question,
- from, fromlen, sd0, ((type1 > 0) ? sd1 :
+ from, fromlen, rbt0, ((type1 > 0) ? rbt1 :
NULL), aregion, istcp, 0, NULL, replybuf);
break;
case BUILD_OTHER:
build_reply(&sreply, so, pbuf, len, question,
- from, fromlen, sd0, NULL, aregion, istcp,
+ from, fromlen, rbt0, NULL, aregion, istcp,
0, NULL, replybuf);
break;
}
@@ -2900,7 +2797,7 @@ tcpnxdomain:
if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, pbuf, len, question, from, \
- fromlen, sd0, NULL, aregion, istcp,
+ fromlen, rbt0, NULL, aregion, istcp,
0, NULL, replybuf);
slen = reply_ns(&sreply, cfg->db);
@@ -2927,13 +2824,13 @@ tcpnxdomain:
free_question(question);
- if (sd0) {
- free(sd0);
- sd0 = NULL;
+ if (rbt0) {
+ free(rbt0);
+ rbt0 = NULL;
}
- if (sd1) {
- free (sd1);
- sd1 = NULL;
+ if (rbt1) {
+ free (rbt1);
+ rbt1 = NULL;
}
close(so);
@@ -2941,14 +2838,14 @@ tcpnxdomain:
} /* for (i = 0;;)... */
drop:
- if (sd0) {
- free(sd0);
- sd0 = NULL;
+ if (rbt0) {
+ free(rbt0);
+ rbt0 = NULL;
}
- if (sd1) {
- free(sd1);
- sd1 = NULL;
+ if (rbt1) {
+ free(rbt1);
+ rbt1 = NULL;
}
close(so);
blob - ffb220f19cfb506385c2163a10b3415f2ccd715e
blob + ca516ef35a3a4672f183cd218673bf5b52ff10e6
--- dnssec.c
+++ dnssec.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: dnssec.c,v 1.20 2019/02/05 09:48:31 pjp Exp $
+ * $Id: dnssec.c,v 1.21 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
@@ -44,15 +44,15 @@ int insert_nsec3(char *zonename, char *domainname, cha
char * find_next_closer_nsec3(char *zonename, int zonelen, char *hashname);
char * find_match_nsec3(char *zonename, int zonelen, char *hashname);
char * find_match_nsec3_ent(char *zonename, int zonelen, char *hashname);
-struct domain * find_nsec(char *name, int namelen, struct domain *sd, ddDB *db);
-struct domain * find_nsec3_match_qname(char *name, int namelen, struct domain *sd, ddDB *db);
-struct domain * find_nsec3_match_closest(char *name, int namelen, struct domain *sd, ddDB *db);
-struct domain * find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, ddDB *db);
+struct rbtree * find_nsec(char *name, int namelen, struct rbtree *rbt, ddDB *db);
+struct rbtree * find_nsec3_match_qname(char *name, int namelen, struct rbtree *, ddDB *db);
+struct rbtree * find_nsec3_match_closest(char *name, int namelen, struct rbtree *, ddDB *db);
+struct rbtree * find_nsec3_wildcard_closest(char *name, int namelen, struct rbtree *, ddDB *db);
char * convert_name(char *name, int namelen);
int nsec_comp(const void *a, const void *b);
int nsec3_comp(const void *a, const void *b);
int count_dots(char *name);
-struct domain * find_closest_encloser(ddDB *db, char *name, int namelen);
+struct rbtree * find_closest_encloser(ddDB *db, char *name, int namelen);
char * find_next_closer_name(char *, int, char *, int, int *);
char * hash_name(char *name, int len, struct nsec3param *n3p);
char * base32hex_encode(u_char *input, int len);
@@ -62,13 +62,17 @@ void mysetbit(u_char *, int);
extern int get_record_size(ddDB *, char *, int);
extern char * dns_label(char *, int *);
extern void dolog(int, char *, ...);
-extern int checklabel(ddDB *, struct domain *, struct domain *, struct question *);
+extern int checklabel(ddDB *, struct rbtree *, struct rbtree *, struct question *);
extern struct question *build_fake_question(char *, int, u_int16_t);
extern int free_question(struct question *);
-extern void * find_substruct(struct domain *, u_int16_t);
extern int check_ent(char *, int);
extern int memcasecmp(u_char *, u_char *, int);
+extern struct rbtree * create_rr(ddDB *db, char *name, int len, int type, void *rdata);
+extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
+extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+extern int add_rr(struct rbtree *rbt, char *name, int len, u_int16_t rrtype, void *rdata);
+
SLIST_HEAD(listhead, dnssecentry) dnssechead;
static struct nsec3entry {
@@ -83,7 +87,7 @@ static struct dnssecentry {
char zone[DNS_MAXNAME];
int zonelen;
SLIST_ENTRY(dnssecentry) dnssec_entry;
- TAILQ_HEAD(a, nsec3entry) nsec3head;
+ TAILQ_HEAD(aa, nsec3entry) nsec3head;
} *dn, *dnp;
@@ -199,7 +203,7 @@ find_next_closer_nsec3(char *zonename, int zonelen, ch
if (n3 == NULL) {
/* returning NULL is not recommended here */
- ns3p = TAILQ_LAST(&dnp->nsec3head, a);
+ ns3p = TAILQ_LAST(&dnp->nsec3head, aa);
return (ns3p->domainname);
}
@@ -207,10 +211,10 @@ find_next_closer_nsec3(char *zonename, int zonelen, ch
dolog(LOG_INFO, "resolved at %s\n", n3->domainname);
#endif
- if ((ns3p = TAILQ_PREV(n3, a, nsec3_entries)) != NULL) {
+ if ((ns3p = TAILQ_PREV(n3, aa, nsec3_entries)) != NULL) {
return (ns3p->domainname);
} else {
- ns3p = TAILQ_LAST(&dnp->nsec3head, a);
+ ns3p = TAILQ_LAST(&dnp->nsec3head, aa);
return (ns3p->domainname);
}
@@ -241,9 +245,9 @@ find_match_nsec3_ent(char *zonename, int zonelen, char
TAILQ_FOREACH(n3, &dnp->nsec3head, nsec3_entries) {
if (strncasecmp(hashname, n3->domainname, hashlen) < 0) {
if (count == 0)
- n3 = TAILQ_LAST(&dnp->nsec3head, a);
+ n3 = TAILQ_LAST(&dnp->nsec3head, aa);
else
- n3 = TAILQ_PREV(n3, a, nsec3_entries);
+ n3 = TAILQ_PREV(n3, aa, nsec3_entries);
break;
}
count++;
@@ -298,10 +302,9 @@ find_match_nsec3(char *zonename, int zonelen, char *ha
/* FIND_NSEC */
/* finds the right nsec domainname in a zone */
-struct domain *
-find_nsec(char *name, int namelen, struct domain *sd, ddDB *db)
+struct rbtree *
+find_nsec(char *name, int namelen, struct rbtree *rbt, ddDB *db)
{
- ddDBT key, data;
char *table, *tmp;
char *nsecname;
struct domainnames {
@@ -309,25 +312,30 @@ find_nsec(char *name, int namelen, struct domain *sd,
char next[DNS_MAXNAME + 1];
} *dn;
- struct domain *sd0;
- struct domain_nsec *sdnsec;
+ struct rbtree *rbt0;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char *humanname;
- char *backname;
char tmpname[DNS_MAXNAME];
int tmplen;
+ char *backname;
int backnamelen;
- int rs, ret;
int i, names = 100;
int j;
humanname = convert_name(name, namelen);
- if ((sdnsec = find_substruct(sd, INTERNAL_TYPE_NSEC)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC)) == NULL) {
free (humanname);
return (NULL);
}
-
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
+ free(humanname);
+ return (NULL);
+ }
+
table = calloc(names, sizeof(struct domainnames));
if (table == NULL) {
free (humanname);
@@ -335,55 +343,34 @@ find_nsec(char *name, int namelen, struct domain *sd,
}
dn = (struct domainnames *)table;
- strlcpy(dn->name, sd->zonename, DNS_MAXNAME + 1);
- nsecname = convert_name(sdnsec->nsec.next_domain_name, sdnsec->nsec.ndn_len);
+ strlcpy(dn->name, rbt->humanname, DNS_MAXNAME + 1);
+ nsecname = convert_name(((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
strlcpy(dn->next, nsecname, DNS_MAXNAME + 1);
- rs = get_record_size(db, sdnsec->nsec.next_domain_name, sdnsec->nsec.ndn_len);
- if (rs < 0) {
+ rbt0 = find_rrset(db, ((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
+ if (rbt0 == NULL) {
free (nsecname);
free (humanname);
free (table);
return (NULL);
}
- if ((sd0 = calloc(1, rs)) == NULL) {
+ if ((rrset = find_rr(rbt0, DNS_TYPE_NSEC)) == NULL) {
free (nsecname);
free (humanname);
free (table);
+ free (rbt0);
return (NULL);
}
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = sdnsec->nsec.next_domain_name;
- key.size = sdnsec->nsec.ndn_len;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
- free (nsecname);
- free (humanname);
- free (table);
- free (sd0);
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL) {
+ free(humanname);
return (NULL);
}
- memcpy(sd0, data.data, data.size);
-
- if ((sdnsec = find_substruct(sd0, INTERNAL_TYPE_NSEC)) == NULL) {
- free (nsecname);
- free (humanname);
- free (table);
- free (sd0);
- return (NULL);
- }
-
i = 1;
- while (strcasecmp(nsecname, sd->zonename) != 0) {
+ while (strcasecmp(nsecname, rbt->humanname) != 0) {
/* grow our table */
if (i == names - 1) {
names += 100;
@@ -393,7 +380,7 @@ find_nsec(char *name, int namelen, struct domain *sd,
free (nsecname);
free (humanname);
free (table);
- free (sd0);
+ free (rbt0);
return (NULL);
}
table = tmp;
@@ -402,52 +389,30 @@ find_nsec(char *name, int namelen, struct domain *sd,
dn = ((struct domainnames *)table) + i;
free (nsecname);
- strlcpy(dn->name, sd0->zonename, DNS_MAXNAME + 1);
- nsecname = convert_name(sdnsec->nsec.next_domain_name, sdnsec->nsec.ndn_len);
+ strlcpy(dn->name, rbt0->humanname, DNS_MAXNAME + 1);
+ nsecname = convert_name(((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
strlcpy(dn->next, nsecname, DNS_MAXNAME + 1);
- rs = get_record_size(db, sdnsec->nsec.next_domain_name, sdnsec->nsec.ndn_len);
- if (rs < 0) {
- free (table);
- return (NULL);
- }
+ memcpy(tmpname, ((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
+ tmplen = ((struct nsec *)rrp->rdata)->ndn_len;
- memcpy(tmpname, sdnsec->nsec.next_domain_name, sdnsec->nsec.ndn_len);
- tmplen = sdnsec->nsec.ndn_len;
+ free (rbt0);
- free (sd0);
- if ((sd0 = calloc(1, rs)) == NULL) {
+ rbt0 = find_rrset(db, tmpname, tmplen);
+ if (rbt0 == NULL) {
free (humanname);
free (table);
+ free (rbt0);
return (NULL);
}
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = tmpname;
- key.size = tmplen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
+ if ((rrset = find_rr(rbt0, DNS_TYPE_NSEC)) == NULL) {
free (humanname);
free (table);
- free (sd0);
+ free (rbt0);
return (NULL);
}
- memcpy(sd0, data.data, data.size);
-
- if ((sdnsec = find_substruct(sd0, INTERNAL_TYPE_NSEC)) == NULL) {
- free (humanname);
- free (table);
- free (sd0);
- return (NULL);
- }
-
i++;
}
@@ -480,43 +445,21 @@ find_nsec(char *name, int namelen, struct domain *sd,
/* free what we don't need */
free (humanname);
- free (sd0);
+ free (rbt0);
backname = dns_label(dn->name, &backnamelen);
free (table);
- rs = get_record_size(db, backname, backnamelen);
- if (rs < 0) {
- free (backname);
- return (NULL);
- }
- if ((sd0 = calloc(1, rs)) == NULL) {
+ rbt0 = find_rrset(db, backname, backnamelen);
+ if (rbt0 == NULL) {
free (backname);
+ free (rbt0);
return (NULL);
}
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = backname;
- key.size = backnamelen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
- free (backname);
- free (sd0);
- return (NULL);
- }
-
-
- memcpy(sd0, data.data, data.size);
free (backname);
-
- return (sd0);
+ return (rbt0);
}
char *
@@ -676,17 +619,14 @@ find_next_closer_name(char *qname, int qlen, char *clo
* FIND_CLOSEST_ENCLOSER - find the closest encloser record
*/
-struct domain *
+struct rbtree *
find_closest_encloser(ddDB *db, char *name, int namelen)
{
- struct domain *sd = NULL;
+ struct rbtree *rbt = NULL;
+ struct rrset *rrset = NULL;
int plen;
- int ret = 0;
- int rs;
- ddDBT key, data;
-
char *p;
p = name;
@@ -698,51 +638,25 @@ find_closest_encloser(ddDB *db, char *name, int namele
do {
- rs = get_record_size(db, p, plen);
- if (rs < 0) {
- return NULL;
- }
-
- sd = calloc(rs, 1);
- if (sd == NULL)
- return NULL;
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = (char *)p;
- key.size = plen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
+ rbt = find_rrset(db, p, plen);
+ if (rbt == NULL) {
plen -= (*p + 1);
p = (p + (*p + 1));
- free (sd);
continue;
}
- if (data.size != rs) {
- dolog(LOG_INFO, "btree db is damaged, drop\n");
- free (sd);
- return (NULL);
- }
-
- memcpy((char *)sd, (char *)data.data, data.size);
- if (sd->flags & DOMAIN_HAVE_NSEC3) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
plen -= (*p + 1);
p = (p + (*p + 1));
- free (sd);
+ free (rbt);
continue;
}
- return (sd);
+ return (rbt);
} while (*p);
- if (sd)
- free (sd);
+ if (rbt)
+ free (rbt);
return NULL;
}
@@ -938,45 +852,46 @@ base32hex_encode(u_char *input, int len)
*
*/
-struct domain *
-find_nsec3_match_closest(char *name, int namelen, struct domain *sd, ddDB *db)
+struct rbtree *
+find_nsec3_match_closest(char *name, int namelen, struct rbtree *rbt, ddDB *db)
{
- ddDBT key, data;
-
char *hashname;
char *backname;
char *dname;
int backnamelen;
- int rs, ret;
- struct domain *sd0;
- struct domain_nsec3param *n3p;
+ struct rbtree *rbt0;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
- if ((n3p = find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
return NULL;
}
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ return NULL;
+ }
/* first off find the next closer record */
- sd0 = find_closest_encloser(db, name, namelen);
- if (sd0 == NULL) {
+ rbt0 = find_closest_encloser(db, name, namelen);
+ if (rbt0 == NULL) {
return NULL;
}
#if DEBUG
- dolog(LOG_INFO, "next closer = %s\n", sd0->zonename);
+ dolog(LOG_INFO, "next closer = %s\n", rbt0->humanname);
#endif
- hashname = hash_name(sd0->zone, sd0->zonelen, &n3p->nsec3param);
+ hashname = hash_name(rbt0->zone, rbt0->zonelen, (struct nsec3param *)rrp->rdata);
if (hashname == NULL) {
dolog(LOG_INFO, "unable to get hashname\n");
- free (sd0);
+ free (rbt0);
return NULL;
}
- free (sd0);
+ free (rbt0);
#if DEBUG
dolog(LOG_INFO, "hashname = %s\n", hashname);
#endif
- dname = find_match_nsec3(sd->zone, sd->zonelen, hashname);
+ dname = find_match_nsec3(rbt->zone, rbt->zonelen, hashname);
if (dname == NULL) {
return NULL;
@@ -989,82 +904,60 @@ find_nsec3_match_closest(char *name, int namelen, stru
#endif
backname = dns_label(dname, &backnamelen);
- rs = get_record_size(db, backname, backnamelen);
- if (rs < 0) {
+ rbt0 = find_rrset(db, backname, backnamelen);
+ if (rbt0 == NULL) {
free (backname);
return (NULL);
}
-
- if ((sd0 = calloc(1, rs)) == NULL) {
- free (backname);
- return (NULL);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = backname;
- key.size = backnamelen;
-
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
- free (backname);
- free (sd0);
- return (NULL);
- }
-
-
- memcpy(sd0, data.data, data.size);
free (backname);
#ifdef DEBUG
- dolog(LOG_INFO, "returning %s\n", sd0->zonename);
+ dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
#endif
- return (sd0);
+ return (rbt0);
}
/*
* FIND_NSEC3_WILDCARD_CLOSEST - finds the right nsec3 domainname in a zone
*
*/
-struct domain *
-find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, ddDB *db)
+struct rbtree *
+find_nsec3_wildcard_closest(char *name, int namelen, struct rbtree *rbt, ddDB *db)
{
- ddDBT key, data;
-
char *hashname;
char *backname;
char *dname;
char wildcard[DNS_MAXNAME + 1];
int backnamelen;
- int rs, ret;
- struct domain *sd0;
- struct domain_nsec3param *n3p;
+ struct rbtree *rbt0 = NULL;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
- if ((n3p = find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
return NULL;
}
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ return NULL;
+ }
/* first off find the next closer record */
- sd0 = find_closest_encloser(db, name, namelen);
- if (sd0 == NULL) {
+ rbt0 = find_closest_encloser(db, name, namelen);
+ if (rbt0 == NULL) {
return NULL;
}
#if DEBUG
- dolog(LOG_INFO, "next closer = %s\n", sd0->zonename);
+ dolog(LOG_INFO, "next closer = %s\n", rbt0->humanname);
#endif
- snprintf(wildcard, sizeof(wildcard), "*.%s", sd0->zonename);
+ snprintf(wildcard, sizeof(wildcard), "*.%s", rbt0->humanname);
backname = dns_label(wildcard, &backnamelen);
- hashname = hash_name(backname, backnamelen, &n3p->nsec3param);
+ hashname = hash_name(backname, backnamelen, (struct nsec3param *)rrp->rdata);
if (hashname == NULL) {
dolog(LOG_INFO, "unable to get hashname\n");
- free (sd0);
+ free (rbt0);
return NULL;
}
@@ -1072,94 +965,73 @@ find_nsec3_wildcard_closest(char *name, int namelen, s
dolog(LOG_INFO, "hashname = %s\n", hashname);
#endif
- dname = find_next_closer_nsec3(sd->zone, sd->zonelen, hashname);
+ dname = find_next_closer_nsec3(rbt->zone, rbt->zonelen, hashname);
/* found it, get it via db after converting it */
/* free what we don't need */
- free (sd0);
+ free (rbt0);
#ifdef DEBUG
dolog(LOG_INFO, "converting %s\n", dname);
#endif
backname = dns_label(dname, &backnamelen);
- rs = get_record_size(db, backname, backnamelen);
- if (rs < 0) {
+ rbt0 = find_rrset(db, backname, backnamelen);
+ if (rbt0 == NULL) {
free (backname);
return (NULL);
}
-
- if ((sd0 = calloc(1, rs)) == NULL) {
- free (backname);
- return (NULL);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = backname;
- key.size = backnamelen;
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
- free (backname);
- free (sd0);
- return (NULL);
- }
-
-
- memcpy(sd0, data.data, data.size);
free (backname);
#ifdef DEBUG
- dolog(LOG_INFO, "returning %s\n", sd0->zonename);
+ dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
#endif
- return (sd0);
+ return (rbt0);
}
/*
* FIND_NSEC3_COVER_NEXT_CLOSER - finds the right nsec3 domainname in a zone
*
*/
-struct domain *
-find_nsec3_cover_next_closer(char *name, int namelen, struct domain *sd, ddDB *db)
+struct rbtree *
+find_nsec3_cover_next_closer(char *name, int namelen, struct rbtree *rbt, ddDB *db)
{
- ddDBT key, data;
-
char *hashname;
char *backname;
char *dname;
int backnamelen;
- int rs, ret;
- struct domain *sd0;
- struct domain_nsec3param *n3p;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
char *ncn;
int ncnlen;
+ struct rbtree *rbt0;
- if ((n3p = find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
return NULL;
}
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ return NULL;
+ }
/* first off find the next closer record */
- sd0 = find_closest_encloser(db, name, namelen);
- if (sd0 == NULL) {
+ rbt0 = find_closest_encloser(db, name, namelen);
+ if (rbt0 == NULL) {
return NULL;
}
- ncn = find_next_closer_name(name, namelen, sd0->zone, sd0->zonelen, &ncnlen);
+ ncn = find_next_closer_name(name, namelen, rbt0->zone, rbt0->zonelen, &ncnlen);
if (ncn == NULL) {
- free(sd0);
+ free(rbt0);
return NULL;
}
- hashname = hash_name(ncn, ncnlen, &n3p->nsec3param);
+ hashname = hash_name(ncn, ncnlen, (struct nsec3param *)rrp->rdata);
if (hashname == NULL) {
dolog(LOG_INFO, "unable to get hashname\n");
- free (sd0);
+ free (rbt0);
return NULL;
}
@@ -1168,9 +1040,9 @@ find_nsec3_cover_next_closer(char *name, int namelen,
#endif
/* free what we don't need */
- free (sd0);
+ free (rbt0);
- dname = find_next_closer_nsec3(sd->zone, sd->zonelen, hashname);
+ dname = find_next_closer_nsec3(rbt->zone, rbt->zonelen, hashname);
if (dname == NULL)
return NULL;
@@ -1181,42 +1053,20 @@ find_nsec3_cover_next_closer(char *name, int namelen,
backname = dns_label(dname, &backnamelen);
- rs = get_record_size(db, backname, backnamelen);
- if (rs < 0) {
+ if ((rbt0 = find_rrset(db, backname, backnamelen)) == NULL) {
free (backname);
+ free (rbt0);
return (NULL);
}
-
- if ((sd0 = calloc(1, rs)) == NULL) {
- free (backname);
- return (NULL);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = backname;
- key.size = backnamelen;
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
- free (backname);
- free (sd0);
- return (NULL);
- }
-
-
- memcpy(sd0, data.data, data.size);
free (backname);
#ifdef DEBUG
- dolog(LOG_INFO, "returning %s\n", sd0->zonename);
+ dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
#endif
- return (sd0);
+ return (rbt0);
}
/*
@@ -1224,24 +1074,25 @@ find_nsec3_cover_next_closer(char *name, int namelen,
*
*/
-struct domain *
-find_nsec3_match_qname(char *name, int namelen, struct domain *sd, ddDB *db)
+struct rbtree *
+find_nsec3_match_qname(char *name, int namelen, struct rbtree *rbt, ddDB *db)
{
- ddDBT key, data;
-
char *hashname;
char *backname;
char *dname;
int backnamelen;
- int rs, ret;
- struct domain *sd0;
- struct domain_nsec3param *n3p;
+ struct rbtree *rbt0;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
- if ((n3p = find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
return NULL;
}
+ if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
+ return NULL;
+ }
- hashname = hash_name(name, namelen, &n3p->nsec3param);
+ hashname = hash_name(name, namelen, (struct nsec3param *)rrp->rdata);
if (hashname == NULL) {
dolog(LOG_INFO, "unable to get hashname\n");
return NULL;
@@ -1252,9 +1103,9 @@ find_nsec3_match_qname(char *name, int namelen, struct
#endif
if (check_ent(name, namelen))
- dname = find_match_nsec3_ent(sd->zone, sd->zonelen, hashname);
+ dname = find_match_nsec3_ent(rbt->zone, rbt->zonelen, hashname);
else
- dname = find_match_nsec3(sd->zone, sd->zonelen, hashname);
+ dname = find_match_nsec3(rbt->zone, rbt->zonelen, hashname);
if (dname == NULL)
return NULL;
@@ -1267,40 +1118,19 @@ find_nsec3_match_qname(char *name, int namelen, struct
backname = dns_label(dname, &backnamelen);
- rs = get_record_size(db, backname, backnamelen);
- if (rs < 0) {
+ rbt0 = find_rrset(db, backname, backnamelen);
+ if (rbt0 == NULL) {
free (backname);
+ free (rbt0);
return (NULL);
}
-
- if ((sd0 = calloc(1, rs)) == NULL) {
- free (backname);
- return (NULL);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = backname;
- key.size = backnamelen;
- data.data = NULL;
- data.size = rs;
-
- ret = db->get(db, &key, &data);
- if (ret != 0) {
- free (backname);
- free (sd0);
- return (NULL);
- }
-
-
- memcpy(sd0, data.data, data.size);
free (backname);
#ifdef DEBUG
- dolog(LOG_INFO, "returning %s\n", sd0->zonename);
+ dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
#endif
- return (sd0);
+ return (rbt0);
}
blob - 2d597292d969bbfaa20058175f72fbdba1947c41
blob + 37c6ebcdf55e934453a54f46c3b8716fae0c01d5
--- ent.c
+++ ent.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 Peter J. Philipp
+ * Copyright (c) 2017-2019 Peter J. Philipp
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ent.c,v 1.7 2018/10/19 08:24:48 pjp Exp $
+ * $Id: ent.c,v 1.8 2019/02/15 15:11:34 pjp Exp $
*/
/*
@@ -53,7 +53,6 @@ SLIST_HEAD(listhead, ententry) enthead;
static struct ententry {
char *name;
int len;
- u_int64_t flags;
SLIST_ENTRY(ententry) ent_entry;
} *ent2, *entp;
@@ -72,28 +71,27 @@ int
init_entlist(ddDB *db)
{
struct node *n, *nx;
- struct domain *sd = NULL;
+ struct rbtree *rbt = NULL;
SLIST_INIT(&enthead);
RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
- sd = (struct domain *)n->data;
+ rbt = (struct rbtree *)n->data;
ent2 = malloc(sizeof(struct ententry));
if (ent2 == NULL) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
return -1;
}
- ent2->name = malloc(sd->zonelen);
+ ent2->name = malloc(rbt->zonelen);
if (ent2->name == NULL) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
return -1;
}
- memcpy(ent2->name, sd->zone, sd->zonelen);
- ent2->len = sd->zonelen;
- ent2->flags = sd->flags;
+ memcpy(ent2->name, rbt->zone, rbt->zonelen);
+ ent2->len = rbt->zonelen;
SLIST_INSERT_HEAD(&enthead, ent2, ent_entry);
}
blob - e7a48364676a61223cf5908a5714b4562be4edf9
blob + 7113c143024ae4340cc787d10a40ccbd850905f3
--- parse.y
+++ parse.y
@@ -21,7 +21,7 @@
*/
/*
- * $Id: parse.y,v 1.58 2019/02/09 09:05:18 pjp Exp $
+ * $Id: parse.y,v 1.59 2019/02/15 15:11:34 pjp Exp $
*/
%{
@@ -29,6 +29,8 @@
#include "ddd-dns.h"
#include "ddd-db.h"
+void yyerror(const char *);
+int yylex(void);
extern struct rrtab *rrlookup(char *);
extern int base32hex_decode(u_char *, u_char *);
@@ -45,11 +47,13 @@ extern int insert_whitelist(char *, char *);
extern void slave_shutdown(void);
extern int mybase64_encode(u_char const *, size_t, char *, size_t);
extern int mybase64_decode(char const *, u_char *, size_t);
-extern int get_record_size(ddDB *, char *, int);
-extern void * find_substruct(struct domain *, u_int16_t);
-void yyerror(const char *);
-int yylex(void);
+extern struct rbtree * create_rr(ddDB *db, char *name, int len, int type, void *rdata);
+extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
+extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+extern int add_rr(struct rbtree *rbt, char *name, int len, u_int16_t rrtype, void *rdata);
+extern int display_rr(struct rrset *rrset);
+
extern int whitelist;
extern int notify;
extern int errno;
@@ -172,7 +176,6 @@ int findeol(void);
int get_ip(char *, int);
char *get_prefixlen(char *, char *, int);
int get_quotedstring(char *, int);
-int get_record(struct domain *, char *, int);
int get_string(char *, int);
int hex2bin(char *, int, char *);
int lgetc(int);
@@ -181,7 +184,6 @@ int lungetc(int);
int parse_file(ddDB *, char *);
struct file *pushfile(const char *, int, int, int);
int popfile(void);
-int set_record(struct domain *, int, char *, int);
static int temp_inet_net_pton_ipv6(const char *, void *, size_t);
int yyparse(void);
static struct rzone * add_rzone(void);
@@ -1865,12 +1867,11 @@ int
fill_cname(char *name, char *type, int myttl, char *hostname)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_cname *ssd_cname;
+ struct rbtree *rbt;
+ struct cname *cname;
char *myname, *converted_name;
int len, converted_namelen;
- int i, rs;
+ int i;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -1881,49 +1882,12 @@ fill_cname(char *name, char *type, int myttl, char *ho
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((cname = calloc(1, sizeof(struct cname))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
-
- ssd = (struct domain *)sdomain;
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_CNAME] = myttl;
-
- ssd_cname = (struct domain_cname *) find_substruct(ssd, INTERNAL_TYPE_CNAME);
- if (ssd_cname == NULL) {
- rs += sizeof(struct domain_cname);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL)
- return -1;
- sdomain = tp;
- ssd_cname = (sdomain + (rs - sizeof(struct domain_cname)));
- memset((char *)ssd_cname, 0, sizeof(struct domain_cname));
- ssd = (struct domain *)sdomain;
- ssd_cname->len = sizeof(struct domain_cname);
- ssd_cname->type = INTERNAL_TYPE_CNAME;
- }
-
- ssd_cname->type = DNS_TYPE_CNAME;
- ssd_cname->len = sizeof(struct domain_cname);
-
myname = dns_label(hostname, (int *)&len);
if (myname == NULL) {
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
@@ -1935,35 +1899,35 @@ fill_cname(char *name, char *type, int myttl, char *ho
return -1;
}
- ssd_cname->cnamelen = len;
- memcpy((char *)ssd_cname->cname, myname, len);
+ cname->cnamelen = len;
+ memcpy((char *)cname->cname, myname, len);
+ cname->ttl = myttl;
free(myname);
- ssd->flags |= DOMAIN_HAVE_CNAME;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_CNAME, cname);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
-
}
int
fill_ptr(char *name, char *type, int myttl, char *hostname)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_ptr *ssd_ptr;
+ struct ptr *ptr;
+ struct rbtree *rbt;
int len, converted_namelen;
char *myname, *converted_name;
- int i, rs;
+ int i;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -1974,46 +1938,6 @@ fill_ptr(char *name, char *type, int myttl, char *host
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_PTR] = myttl;
-
- ssd_ptr = (struct domain_ptr *) find_substruct(ssd, INTERNAL_TYPE_PTR);
- if (ssd_ptr == NULL) {
- rs += sizeof(struct domain_ptr);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL)
- return -1;
- sdomain = tp;
- ssd_ptr = (sdomain + (rs - sizeof(struct domain_ptr)));
- memset((char *)ssd_ptr, 0, sizeof(struct domain_ptr));
- ssd = (struct domain *)sdomain;
- ssd_ptr->len = sizeof(struct domain_ptr);
- ssd_ptr->type = INTERNAL_TYPE_PTR;
- }
-
myname = dns_label(hostname, (int *)&len);
if (myname == NULL) {
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
@@ -2025,20 +1949,27 @@ fill_ptr(char *name, char *type, int myttl, char *host
return -1;
}
- ssd_ptr->ptrlen = len;
- memcpy((char *)ssd_ptr->ptr, myname, len);
+ if ((ptr = calloc(1, sizeof(struct ptr))) == NULL) {
+ dolog(LOG_ERR, "calloc %s\n", strerror(errno));
+ return -1;
+ }
+ ptr->ptrlen = len;
+ memcpy((char *)ptr->ptr, myname, len);
+ ptr->ttl = myttl;
+
free(myname);
- ssd->flags |= DOMAIN_HAVE_PTR;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_PTR, ptr);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -2049,12 +1980,11 @@ int
fill_dnskey(char *name, char *type, u_int32_t myttl, u_int16_t flags, u_int8_t protocol, u_int8_t algorithm, char *pubkey)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_dnskey *ssd_dnskey;
+ struct dnskey *dnskey;
+ struct rbtree *rbt;
int converted_namelen;
char *converted_name;
- int i, ret, rs;
+ int i, ret;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2065,69 +1995,35 @@ fill_dnskey(char *name, char *type, u_int32_t myttl, u
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- return (-1);
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
+ if ((dnskey = calloc(1, sizeof(struct dnskey))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
+ return -1;
}
+ dnskey->flags = flags;
+ dnskey->protocol = protocol;
+ dnskey->algorithm = algorithm;
+ dnskey->ttl = myttl;
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_DNSKEY] = myttl;
-
- ssd_dnskey = (struct domain_dnskey *) find_substruct(ssd, INTERNAL_TYPE_DNSKEY);
- if (ssd_dnskey == NULL) {
- rs += sizeof(struct domain_dnskey);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL)
- return -1;
- sdomain = tp;
- ssd_dnskey = (sdomain + (rs - sizeof(struct domain_dnskey)));
- memset((char *)ssd_dnskey, 0, sizeof(struct domain_dnskey));
- ssd = (struct domain *)sdomain;
- ssd_dnskey->len = sizeof(struct domain_dnskey);
- ssd_dnskey->type = INTERNAL_TYPE_DNSKEY;
- }
-
- ssd_dnskey->dnskey[ssd_dnskey->dnskey_count].flags = flags;
- ssd_dnskey->dnskey[ssd_dnskey->dnskey_count].protocol = protocol;
- ssd_dnskey->dnskey[ssd_dnskey->dnskey_count].algorithm = algorithm;
-
/* feed our base64 key to the public key */
- ret = mybase64_decode(pubkey, ssd_dnskey->dnskey[ssd_dnskey->dnskey_count].public_key, sizeof(ssd_dnskey->dnskey[ssd_dnskey->dnskey_count].public_key));
-
+ ret = mybase64_decode(pubkey, dnskey->public_key, sizeof(dnskey->public_key));
if (ret < 0)
return (-1);
- ssd_dnskey->dnskey[ssd_dnskey->dnskey_count].publickey_len = ret;
+ dnskey->publickey_len = ret;
- ssd_dnskey->dnskey_count++;
-
- ssd->flags |= DOMAIN_HAVE_DNSKEY;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_DNSKEY, dnskey);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
+
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -2137,17 +2033,18 @@ int
fill_rrsig(char *name, char *type, u_int32_t myttl, char *typecovered, u_int8_t algorithm, u_int8_t labels, u_int32_t original_ttl, u_int64_t sig_expiration, u_int64_t sig_inception, u_int16_t keytag, char *signers_name, char *signature)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_rrsig *ssd_rrsig;
+ struct rbtree *rbt;
struct rrsig *rrsig;
int converted_namelen, signers_namelen;
char *converted_name, *signers_name2;
struct rrtab *rr;
- int i, ret, rs;
+ int i, ret;
char tmpbuf[32];
struct tm tmbuf;
time_t timebuf;
+#if 0
+ int rrtype = RRSIG_RRSET;
+#endif
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2158,27 +2055,6 @@ fill_rrsig(char *name, char *type, u_int32_t myttl, ch
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_RRSIG] = myttl;
-
if ((rr = rrlookup(typecovered)) == NULL) {
return (-1);
}
@@ -2190,47 +2066,17 @@ fill_rrsig(char *name, char *type, u_int32_t myttl, ch
break;
}
- ssd_rrsig = (struct domain_rrsig *) find_substruct(ssd, INTERNAL_TYPE_RRSIG);
- if (ssd_rrsig == NULL) {
- rs += sizeof(struct domain_rrsig);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL)
- return -1;
- sdomain = tp;
- ssd_rrsig = (sdomain + (rs - sizeof(struct domain_rrsig)));
- memset((char *)ssd_rrsig, 0, sizeof(struct domain_rrsig));
- ssd = (struct domain *)sdomain;
- ssd_rrsig->len = sizeof(struct domain_rrsig);
- ssd_rrsig->type = INTERNAL_TYPE_RRSIG;
- }
-
- if (rr->internal_type == INTERNAL_TYPE_DNSKEY) {
-#if DEBUG
- printf("filling hackaround type dnskey\n");
-#endif
- rrsig = &ssd_rrsig->rrsig_dnskey[ssd_rrsig->rrsig_dnskey_count++];
- } else {
-#if DEBUG
- printf("filling internal type %d\n", rr->internal_type);
-#endif
- rrsig = &ssd_rrsig->rrsig[rr->internal_type];
+ if ((rrsig = calloc(1, sizeof(struct rrsig))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
+ return -1;
}
-
+
rrsig->type_covered = rr->type;
rrsig->algorithm = algorithm;
rrsig->labels = labels;
+ rrsig->ttl = original_ttl;
-#if 0
- if (ssd->ttl[rr->internal_type] != original_ttl) {
- return (-1);
- }
-#endif
-
rrsig->original_ttl = original_ttl;
snprintf(tmpbuf, sizeof(tmpbuf), "%llu", sig_expiration);
if (strptime(tmpbuf, "%Y%m%d%H%M%S", &tmbuf) == NULL) {
@@ -2253,7 +2099,7 @@ fill_rrsig(char *name, char *type, u_int32_t myttl, ch
return (-1);
}
- memcpy(rrsig->signers_name, signers_name2, signers_namelen);
+ memcpy(&rrsig->signers_name, signers_name2, signers_namelen);
rrsig->signame_len = signers_namelen;
@@ -2264,19 +2110,21 @@ fill_rrsig(char *name, char *type, u_int32_t myttl, ch
return (-1);
rrsig->signature_len = ret;
-
- ssd->flags |= DOMAIN_HAVE_RRSIG;
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_RRSIG, rrsig);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
+
if (signers_name2)
- free (signers_name2);
+ free(signers_name2);
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -2286,12 +2134,11 @@ int
fill_ds(char *name, char *type, u_int32_t myttl, u_int16_t keytag, u_int8_t algorithm, u_int8_t digesttype, char *digest)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_ds *ssd_ds;
+ struct rbtree *rbt;
+ struct ds *ds;
int converted_namelen;
char *converted_name;
- int i, rs;
+ int i;
int ret;
for (i = 0; i < strlen(name); i++) {
@@ -2303,70 +2150,29 @@ fill_ds(char *name, char *type, u_int32_t myttl, u_int
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
+ if ((ds = calloc(1, sizeof(struct ds))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
+ return -1;
}
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_DS] = myttl;
-
- ssd_ds = (struct domain_ds *) find_substruct(ssd, INTERNAL_TYPE_DS);
- if (ssd_ds == NULL) {
- rs += sizeof(struct domain_ds);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL)
- return -1;
- sdomain = tp;
- ssd_ds = (sdomain + (rs - sizeof(struct domain_ds)));
- memset((char *)ssd_ds, 0, sizeof(struct domain_ds));
- ssd = (struct domain *)sdomain;
- ssd_ds->len = sizeof(struct domain_ds);
- ssd_ds->type = INTERNAL_TYPE_DS;
- }
-
- ssd_ds->ds[ssd_ds->ds_count].key_tag = keytag;
- ssd_ds->ds[ssd_ds->ds_count].algorithm = algorithm;
- ssd_ds->ds[ssd_ds->ds_count].digest_type = digesttype;
+ ds->key_tag = keytag;
+ ds->algorithm = algorithm;
+ ds->digest_type = digesttype;
-#if 0
- memcpy(ssd_ds->ds[ssd_ds->ds_count].digest, digest, strlen(digest));
- ssd_ds->ds[ssd_ds->ds_count].digestlen = strlen(digest);
-#endif
+ ret = hex2bin(digest, strlen(digest), ds->digest);
+ ds->digestlen = ret;
+ ds->ttl = myttl;
- ret = hex2bin(digest, strlen(digest), ssd_ds->ds[ssd_ds->ds_count].digest);
-
- ssd_ds->ds[ssd_ds->ds_count].digestlen = ret;
-
- ssd_ds->ds_count++;
-
- ssd->flags |= DOMAIN_HAVE_DS;
-
- if (set_record(sdomain, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_DS, ds);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
-
+ }
+
if (converted_name)
free (converted_name);
- free(sdomain);
+ free(rbt);
return (0);
@@ -2376,10 +2182,9 @@ int
fill_nsec3(char *name, char *type, u_int32_t myttl, u_int8_t algorithm, u_int8_t flags, u_int16_t iterations, char *salt, char *nextname, char *bitmap)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_nsec3 *ssd_nsec3;
- int i, rs;
+ struct nsec3 *nsec3;
+ struct rbtree *rbt;
+ int i;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2397,86 +2202,47 @@ fill_nsec3(char *name, char *type, u_int32_t myttl, u_
insert_nsec3(current_zone, name, converted_name, converted_namelen);
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- if (debug)
- dolog(LOG_INFO, "get_record_size failed\n");
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- if (debug)
- dolog(LOG_INFO, "calloc failed\n");
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_NSEC3] = myttl;
-
-
for (i = 0; i < strlen(nextname); i++) {
nextname[i] = tolower((int)nextname[i]);
}
- ssd_nsec3 = (struct domain_nsec3 *)find_substruct(ssd, INTERNAL_TYPE_NSEC3);
- if (ssd_nsec3 == NULL) {
- rs += sizeof(struct domain_nsec3);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- dolog(LOG_INFO, "reallocarray failed\n");
- free (sdomain);
- return -1;
- }
- sdomain = tp;
- ssd_nsec3 = (sdomain + (rs - sizeof(struct domain_nsec3)));
- memset((char *)ssd_nsec3, 0, sizeof(struct domain_nsec3));
- ssd = (struct domain *)sdomain;
- ssd_nsec3->len = sizeof(struct domain_nsec3);
- ssd_nsec3->type = INTERNAL_TYPE_NSEC3;
+
+ if ((nsec3 = calloc(1, sizeof(struct nsec3))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
+ return -1;
}
- ssd_nsec3->nsec3.algorithm = algorithm;
- ssd_nsec3->nsec3.flags = flags;
- ssd_nsec3->nsec3.iterations = iterations;
+ nsec3->algorithm = algorithm;
+ nsec3->flags = flags;
+ nsec3->iterations = iterations;
if (strcasecmp(salt, "-") == 0) {
- ssd_nsec3->nsec3.saltlen = 0;
+ nsec3->saltlen = 0;
} else {
- ssd_nsec3->nsec3.saltlen = (strlen(salt) / 2);
- hex2bin(salt, strlen(salt), ssd_nsec3->nsec3.salt);
+ nsec3->saltlen = (strlen(salt) / 2);
+ hex2bin(salt, strlen(salt), nsec3->salt);
}
- ssd_nsec3->nsec3.nextlen = base32hex_decode(nextname, (u_char*)&ssd_nsec3->nsec3.next);
- if (ssd_nsec3->nsec3.nextlen == 0) {
+ nsec3->nextlen = base32hex_decode(nextname, (u_char*)&nsec3->next);
+ if (nsec3->nextlen == 0) {
dolog(LOG_INFO, "base32_decode faulty");
return -1;
}
/* XXX create/manage bitmap */
- create_nsec_bitmap(bitmap, ssd_nsec3->nsec3.bitmap, (int *)&ssd_nsec3->nsec3.bitmap_len);
+ create_nsec_bitmap(bitmap, nsec3->bitmap, (int *)&nsec3->bitmap_len);
- ssd->flags |= DOMAIN_HAVE_NSEC3;
+ nsec3->ttl = myttl;
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC3, nsec3);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
}
@@ -2485,10 +2251,9 @@ int
fill_nsec3param(char *name, char *type, u_int32_t myttl, u_int8_t algorithm, u_int8_t flags, u_int16_t iterations, char *salt)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_nsec3param *ssd_nsec3param;
- int i, rs;
+ struct rbtree *rbt;
+ struct nsec3param *nsec3param;
+ int i;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2499,72 +2264,32 @@ fill_nsec3param(char *name, char *type, u_int32_t mytt
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- if (debug)
- dolog(LOG_INFO, "get_record_size failed\n");
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- if (debug)
- dolog(LOG_INFO, "calloc failed\n");
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
+ if ((nsec3param = calloc(1, sizeof(struct nsec3param))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
+ return -1;
}
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_NSEC3PARAM] = myttl;
-
- ssd_nsec3param = (struct domain_nsec3param *)find_substruct(ssd, INTERNAL_TYPE_NSEC3PARAM);
- if (ssd_nsec3param == NULL) {
- rs += sizeof(struct domain_nsec3param);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- dolog(LOG_INFO, "reallocarray failed\n");
- free (sdomain);
- return -1;
- }
- sdomain = tp;
- ssd_nsec3param = (sdomain + (rs - sizeof(struct domain_nsec3param)));
- memset((char *)ssd_nsec3param, 0, sizeof(struct domain_nsec3param));
- ssd = (struct domain *)sdomain;
- ssd_nsec3param->len = sizeof(struct domain_nsec3param);
- ssd_nsec3param->type = INTERNAL_TYPE_NSEC3PARAM;
- }
-
- ssd_nsec3param->nsec3param.algorithm = algorithm;
- ssd_nsec3param->nsec3param.flags = flags;
- ssd_nsec3param->nsec3param.iterations = iterations;
+ nsec3param->algorithm = algorithm;
+ nsec3param->flags = flags;
+ nsec3param->iterations = iterations;
if (strcasecmp(salt, "-") == 0) {
- ssd_nsec3param->nsec3param.saltlen = 0;
+ nsec3param->saltlen = 0;
} else {
- ssd_nsec3param->nsec3param.saltlen = (strlen(salt) / 2);
- hex2bin(salt, strlen(salt), ssd_nsec3param->nsec3param.salt);
+ nsec3param->saltlen = (strlen(salt) / 2);
+ hex2bin(salt, strlen(salt), nsec3param->salt);
}
+ nsec3param->ttl = myttl;
- ssd->flags |= DOMAIN_HAVE_NSEC3PARAM;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC3PARAM, nsec3param);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
}
@@ -2573,12 +2298,11 @@ int
fill_nsec(char *name, char *type, u_int32_t myttl, char *domainname, char *bitmap)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_nsec *ssd_nsec;
+ struct nsec *nsec;
+ struct rbtree *rbt;
int converted_namelen, converted_domainnamelen;
char *converted_name, *converted_domainname;
- int i, rs;
+ int i;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2589,33 +2313,6 @@ fill_nsec(char *name, char *type, u_int32_t myttl, cha
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- if (debug)
- dolog(LOG_INFO, "get_record_size failed\n");
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- if (debug)
- dolog(LOG_INFO, "calloc failed\n");
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_NSEC] = myttl;
-
-
for (i = 0; i < strlen(domainname); i++) {
domainname[i] = tolower((int)domainname[i]);
}
@@ -2627,43 +2324,27 @@ fill_nsec(char *name, char *type, u_int32_t myttl, cha
return -1;
}
- ssd_nsec = (struct domain_nsec *)find_substruct(ssd, INTERNAL_TYPE_NSEC);
- if (ssd_nsec == NULL) {
- rs += sizeof(struct domain_nsec);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- dolog(LOG_INFO, "reallocarray failed\n");
- free (sdomain);
- return -1;
- }
- sdomain = tp;
- ssd_nsec = (sdomain + (rs - sizeof(struct domain_nsec)));
- memset((char *)ssd_nsec, 0, sizeof(struct domain_nsec));
- ssd = (struct domain *)sdomain;
- ssd_nsec->len = sizeof(struct domain_nsec);
- ssd_nsec->type = INTERNAL_TYPE_NSEC;
+ if ((nsec = calloc(1, sizeof(struct nsec))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
+ return -1;
}
+ memcpy(nsec->next_domain_name, converted_domainname, converted_domainnamelen);
+ nsec->ndn_len = converted_domainnamelen;
- memcpy(ssd_nsec->nsec.next_domain_name, converted_domainname, converted_domainnamelen);
- ssd_nsec->nsec.ndn_len = converted_domainnamelen;
-
- /* XXX create/manage bitmap */
- create_nsec_bitmap(bitmap, ssd_nsec->nsec.bitmap, (int *)&ssd_nsec->nsec.bitmap_len);
+ create_nsec_bitmap(bitmap, nsec->bitmap, (int *)&nsec->bitmap_len);
+ nsec->ttl = myttl;
- ssd->flags |= DOMAIN_HAVE_NSEC;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC, nsec);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -2674,14 +2355,12 @@ int
fill_naptr(char *name, char *type, int myttl, int order, int preference, char *flags, char *services, char *regexp, char *replacement)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_naptr *ssd_naptr;
+ struct rbtree *rbt;
+ struct naptr *naptr;
int converted_namelen;
char *converted_name, *naptrname;
int flagslen, serviceslen, regexplen, replacementlen;
int i, naptr_namelen;
- int rs;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2701,73 +2380,37 @@ fill_naptr(char *name, char *type, int myttl, int orde
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((naptr = (struct naptr *)calloc(1, sizeof(struct naptr))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- ssd = (struct domain *)sdomain;
+ naptr->order = order;
+ naptr->preference = preference;
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
+ memcpy(&naptr->flags, flags, flagslen);
+ naptr->flagslen = flagslen;
+ memcpy(&naptr->services, services, serviceslen);
+ naptr->serviceslen = serviceslen;
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
+ memcpy(&naptr->regexp, regexp, regexplen);
+ naptr->regexplen = regexplen;
- ssd->ttl[INTERNAL_TYPE_NAPTR] = myttl;
-
- ssd_naptr = (struct domain_naptr *)find_substruct(ssd, INTERNAL_TYPE_NAPTR);
- if (ssd_naptr == NULL) {
- rs += sizeof(struct domain_naptr);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL)
- return -1;
-
- sdomain = tp;
- ssd_naptr = (sdomain + (rs - sizeof(struct domain_naptr)));
- memset((char *)ssd_naptr, 0, sizeof(struct domain_naptr));
- ssd = (struct domain *)sdomain;
- ssd_naptr->len = sizeof(struct domain_naptr);
- ssd_naptr->type = INTERNAL_TYPE_NAPTR;
- }
-
- ssd_naptr->naptr[ssd_naptr->naptr_count].order = order;
- ssd_naptr->naptr[ssd_naptr->naptr_count].preference = preference;
-
- memcpy(ssd_naptr->naptr[ssd_naptr->naptr_count].flags, flags, flagslen);
- ssd_naptr->naptr[ssd_naptr->naptr_count].flagslen = flagslen;
-
- memcpy(ssd_naptr->naptr[ssd_naptr->naptr_count].services, services, serviceslen);
- ssd_naptr->naptr[ssd_naptr->naptr_count].serviceslen = serviceslen;
-
- memcpy(ssd_naptr->naptr[ssd_naptr->naptr_count].regexp, regexp, regexplen);
- ssd_naptr->naptr[ssd_naptr->naptr_count].regexplen = regexplen;
-
naptrname = check_rr(replacement, type, DNS_TYPE_NAPTR, &naptr_namelen);
if (naptrname == NULL) {
return -1;
}
- memcpy(ssd_naptr->naptr[ssd_naptr->naptr_count].replacement, naptrname, naptr_namelen);
- ssd_naptr->naptr[ssd_naptr->naptr_count].replacementlen = naptr_namelen;
-
- ssd_naptr->naptr_count++;
+ memcpy(&naptr->replacement, naptrname, naptr_namelen);
+ naptr->replacementlen = naptr_namelen;
+ naptr->ttl = myttl;
- ssd->flags |= DOMAIN_HAVE_NAPTR;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NAPTR, naptr);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (naptrname)
free (naptrname);
@@ -2775,7 +2418,7 @@ fill_naptr(char *name, char *type, int myttl, int orde
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -2785,13 +2428,11 @@ int
fill_txt(char *name, char *type, int myttl, char *msg)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_txt *ssd_txt;
+ struct rbtree *rbt;
+ struct txt *txt;
int converted_namelen;
char *converted_name;
int len, i;
- int rs;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2807,61 +2448,25 @@ fill_txt(char *name, char *type, int myttl, char *msg)
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return -1;
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((txt = (struct txt *)calloc(1, sizeof(struct txt))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- ssd = (struct domain *)sdomain;
+ memcpy(&txt->txt, msg, len);
+ txt->txtlen = len;
+ txt->ttl = myttl;
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_TXT, txt);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
}
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_TXT] = myttl;
-
- ssd_txt = (struct domain_txt *) find_substruct(ssd, INTERNAL_TYPE_TXT);
- if (ssd_txt == NULL) {
- rs += sizeof(struct domain_txt);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free(sdomain);
- return -1;
- }
- sdomain = tp;
- ssd_txt = (sdomain + (rs - sizeof(struct domain_txt)));
- memset((char *)ssd_txt, 0, sizeof(struct domain_txt));
- ssd = (struct domain *)sdomain;
- ssd_txt->len = sizeof(struct domain_txt);
- ssd_txt->type = INTERNAL_TYPE_TXT;
- }
-
- memcpy(ssd_txt->txt, msg, len);
- ssd_txt->txtlen = len;
-
- ssd->flags |= DOMAIN_HAVE_TXT;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
- return -1;
-
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -2872,14 +2477,12 @@ int
fill_tlsa(char *name, char *type, int myttl, uint8_t usage, uint8_t selector, uint8_t matchtype, char *data)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_tlsa *ssd_tlsa;
+ struct rbtree *rbt;
+ struct tlsa *tlsa;
int converted_namelen;
char *converted_name;
char *p, *ep, save;
int len, i;
- int rs;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -2890,65 +2493,21 @@ fill_tlsa(char *name, char *type, int myttl, uint8_t u
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
+ if ((tlsa = (struct tlsa *)calloc(1, sizeof(struct tlsa))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
+ tlsa->usage = usage;
+ tlsa->selector = selector;
+ tlsa->matchtype = matchtype;
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd_tlsa = (struct domain_tlsa *)find_substruct(ssd, INTERNAL_TYPE_TLSA);
- if (ssd_tlsa == NULL) {
- rs += sizeof(struct domain_tlsa);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free (sdomain);
- return -1;
- }
-
- sdomain = tp;
- ssd_tlsa = (sdomain + (rs - sizeof(struct domain_tlsa)));
- memset((char *)ssd_tlsa, 0, sizeof(struct domain_tlsa));
- ssd = (struct domain *)sdomain;
- ssd_tlsa->len = sizeof(struct domain_tlsa);
- ssd_tlsa->type = INTERNAL_TYPE_TLSA;
-
- }
-
- if (ssd_tlsa->tlsa_count >= RECORD_COUNT) {
- dolog(LOG_INFO, "%s: too many TLSA records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
- return (-1);
- }
-
- ssd->ttl[INTERNAL_TYPE_TLSA] = myttl;
-
- ssd_tlsa->tlsa[ssd_tlsa->tlsa_count].usage = usage;
- ssd_tlsa->tlsa[ssd_tlsa->tlsa_count].selector = selector;
- ssd_tlsa->tlsa[ssd_tlsa->tlsa_count].matchtype = matchtype;
-
switch (matchtype) {
case 1:
- len = ssd_tlsa->tlsa[ssd_tlsa->tlsa_count].datalen = DNS_TLSA_SIZE_SHA256;
+ len = tlsa->datalen = DNS_TLSA_SIZE_SHA256;
break;
case 2:
- len = ssd_tlsa->tlsa[ssd_tlsa->tlsa_count].datalen = DNS_TLSA_SIZE_SHA512;
+ len = tlsa->datalen = DNS_TLSA_SIZE_SHA512;
break;
default:
dolog(LOG_ERR, "tlsa: unknown match type!\n");
@@ -2959,23 +2518,24 @@ fill_tlsa(char *name, char *type, int myttl, uint8_t u
for (i = 0; i < len; i++) {
save = p[2];
p[2] = '\0';
- ssd_tlsa->tlsa[ssd_tlsa->tlsa_count].data[i] = strtol(p, &ep, 16);
+ tlsa->data[i] = strtol(p, &ep, 16);
p[2] = save;
p += 2;
}
- ssd_tlsa->tlsa_count++;
+ tlsa->ttl = myttl;
- ssd->flags |= DOMAIN_HAVE_TLSA;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_TLSA, tlsa);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
-
+ }
+
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -2985,14 +2545,12 @@ int
fill_sshfp(char *name, char *type, int myttl, int alg, int fptype, char *fingerprint)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_sshfp *ssd_sshfp;
+ struct sshfp *sshfp;
+ struct rbtree *rbt;
int converted_namelen;
char *converted_name;
char *p, *ep, save;
int len, i;
- int rs;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -3003,64 +2561,20 @@ fill_sshfp(char *name, char *type, int myttl, int alg,
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
+ if ((sshfp = (struct sshfp *)calloc(1, sizeof(struct sshfp))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
+ sshfp->algorithm = alg;
+ sshfp->fptype = fptype;
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd_sshfp = (struct domain_sshfp *)find_substruct(ssd, INTERNAL_TYPE_SSHFP);
- if (ssd_sshfp == NULL) {
- rs += sizeof(struct domain_sshfp);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free (sdomain);
- return -1;
- }
-
- sdomain = tp;
- ssd_sshfp = (sdomain + (rs - sizeof(struct domain_sshfp)));
- memset((char *)ssd_sshfp, 0, sizeof(struct domain_sshfp));
- ssd = (struct domain *)sdomain;
- ssd_sshfp->len = sizeof(struct domain_sshfp);
- ssd_sshfp->type = INTERNAL_TYPE_SSHFP;
-
- }
-
- if (ssd_sshfp->sshfp_count >= RECORD_COUNT) {
- dolog(LOG_INFO, "%s: too many SSHFP records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
- return (-1);
- }
-
- ssd->ttl[INTERNAL_TYPE_SSHFP] = myttl;
-
- ssd_sshfp->sshfp[ssd_sshfp->sshfp_count].algorithm = alg;
- ssd_sshfp->sshfp[ssd_sshfp->sshfp_count].fptype = fptype;
-
switch (fptype) {
case 1:
- len = ssd_sshfp->sshfp[ssd_sshfp->sshfp_count].fplen = DNS_SSHFP_SIZE_SHA1;
+ len = sshfp->fplen = DNS_SSHFP_SIZE_SHA1;
break;
case 2:
- len = ssd_sshfp->sshfp[ssd_sshfp->sshfp_count].fplen = DNS_SSHFP_SIZE_SHA256;
+ len = sshfp->fplen = DNS_SSHFP_SIZE_SHA256;
break;
default:
dolog(LOG_ERR, "sshfp: unknown fingerprint type!\n");
@@ -3071,23 +2585,23 @@ fill_sshfp(char *name, char *type, int myttl, int alg,
for (i = 0; i < len; i++) {
save = p[2];
p[2] = '\0';
- ssd_sshfp->sshfp[ssd_sshfp->sshfp_count].fingerprint[i] = strtol(p, &ep, 16);
+ sshfp->fingerprint[i] = strtol(p, &ep, 16);
p[2] = save;
p += 2;
}
- ssd_sshfp->sshfp_count++;
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SSHFP, sshfp);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
+ return -1;
+ }
- ssd->flags |= DOMAIN_HAVE_SSHFP;
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
- return -1;
-
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -3097,14 +2611,12 @@ int
fill_srv(char *name, char *type, int myttl, int priority, int weight, int port, char *srvhost)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_srv *ssd_srv;
+ struct srv *srv;
+ struct rbtree *rbt;
int converted_namelen;
char *converted_name;
char *srvname;
int len, i;
- int rs;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -3115,84 +2627,42 @@ fill_srv(char *name, char *type, int myttl, int priori
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((srv = (struct srv *)calloc(1, sizeof(struct srv))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- ssd = (struct domain *)sdomain;
+ srv->ttl = myttl;
+ srv->priority = priority;
+ srv->weight = weight;
+ srv->port = port;
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd_srv = (struct domain_srv *)find_substruct(ssd, INTERNAL_TYPE_SRV);
- if (ssd_srv == NULL) {
- rs += sizeof(struct domain_srv);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free (sdomain);
- return -1;
- }
-
- sdomain = tp;
- ssd_srv = (sdomain + (rs - sizeof(struct domain_srv)));
- memset((char *)ssd_srv, 0, sizeof(struct domain_srv));
- ssd = (struct domain *)sdomain;
- ssd_srv->len = sizeof(struct domain_srv);
- ssd_srv->type = INTERNAL_TYPE_SRV;
- }
-
- if (ssd_srv->srv_count >= RECORD_COUNT) {
- dolog(LOG_INFO, "%s: too many SRV records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
- return (-1);
- }
-
- ssd->ttl[INTERNAL_TYPE_SRV] = myttl;
-
- ssd_srv->srv[ssd_srv->srv_count].priority = priority;
- ssd_srv->srv[ssd_srv->srv_count].weight = weight;
- ssd_srv->srv[ssd_srv->srv_count].port = port;
-
srvname = dns_label(srvhost, &len);
if (srvname == NULL) {
dolog(LOG_INFO, "illegal srv server, skipping line %d\n", file->lineno);
return (-1);
}
- ssd_srv->srv[ssd_srv->srv_count].targetlen = len;
- memcpy((char *)ssd_srv->srv[ssd_srv->srv_count].target, srvname, len);
+ srv->targetlen = len;
+ memcpy((char *)&srv->target, srvname, len);
/* bad hack workaround !!! */
if (strcmp(srvhost, ".") == 0 && len > 1)
- ssd_srv->srv[ssd_srv->srv_count].targetlen = 1;
+ srv->targetlen = 1;
free (srvname);
+ srv->ttl = myttl;
- ssd_srv->srv_count++;
-
- ssd->flags |= DOMAIN_HAVE_SRV;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SRV, srv);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -3202,14 +2672,12 @@ int
fill_mx(char *name, char *type, int myttl, int priority, char *mxhost)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_mx *ssd_mx;
+ struct smx *mx;
+ struct rbtree *rbt;
int converted_namelen;
char *converted_name;
char *mxname;
int len, i;
- int rs;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -3220,79 +2688,34 @@ fill_mx(char *name, char *type, int myttl, int priorit
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
+ if ((mx = (struct smx *)calloc(1, sizeof(struct smx))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
+ mx->preference = priority;
+ mx->ttl = myttl;
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd_mx = (struct domain_mx *)find_substruct(ssd, INTERNAL_TYPE_MX);
-
- if (ssd_mx == NULL) {
-
- rs += sizeof(struct domain_mx);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free (sdomain);
- return -1;
- }
-
- sdomain = tp;
- ssd_mx = (sdomain + (rs - sizeof(struct domain_mx)));
- memset((char *)ssd_mx, 0, sizeof(struct domain_mx));
- ssd = (struct domain *)sdomain;
- ssd_mx->len = sizeof(struct domain_mx);
- ssd_mx->type = INTERNAL_TYPE_MX;
-
- }
-
- if (ssd_mx->mx_count >= RECORD_COUNT) {
- dolog(LOG_INFO, "%s: too many MX records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
- return (-1);
- }
-
- ssd->ttl[INTERNAL_TYPE_MX] = myttl;
- ssd_mx->mx[ssd_mx->mx_count].preference = priority;
-
mxname = dns_label(mxhost, &len);
if (mxname == NULL) {
dolog(LOG_INFO, "illegal mx server, skipping line %d\n", file->lineno);
return (-1);
}
- ssd_mx->mx[ssd_mx->mx_count].exchangelen = len;
- memcpy((char *)ssd_mx->mx[ssd_mx->mx_count].exchange, mxname, len);
+ mx->exchangelen = len;
+ memcpy((char *)&mx->exchange, mxname, len);
free (mxname);
- ssd_mx->mx_count++;
-
- ssd->flags |= DOMAIN_HAVE_MX;
-
- if (set_record(sdomain, rs, converted_name, converted_namelen) < 0)
- return -1;
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_MX, mx);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
+ return -1;
+ }
+
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -3302,13 +2725,12 @@ int
fill_a(char *name, char *type, int myttl, char *a)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_a *ssd_a;
+ struct a *sa;
+ struct rbtree *rbt;
int converted_namelen;
char *converted_name;
in_addr_t *ia;
- int i, rs;
+ int i;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -3319,74 +2741,28 @@ fill_a(char *name, char *type, int myttl, char *a)
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
+ if ((sa = (struct a *)calloc(1, sizeof(struct a))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd_a = (struct domain_a *)find_substruct(ssd, INTERNAL_TYPE_A);
- if (ssd_a == NULL) {
- rs += sizeof(struct domain_a);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free (sdomain);
- return -1;
- }
- sdomain = tp;
-
- ssd_a = (sdomain + (rs - sizeof(struct domain_a)));
- memset((char *)ssd_a, 0, sizeof(struct domain_a));
- ssd = (struct domain *)sdomain;
- ssd_a->len = sizeof(struct domain_a);
- ssd_a->type = INTERNAL_TYPE_A;
-
- }
-
- if (ssd_a->a_count >= RECORD_COUNT) {
- dolog(LOG_INFO, "%s: too many A records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
- return (-1);
- }
-
- ssd->ttl[INTERNAL_TYPE_A] = myttl;
- ia = (in_addr_t *)&ssd_a->a[ssd_a->a_count];
-
+ ia = (in_addr_t *)&sa->a;
if ((*ia = inet_addr(a)) == INADDR_ANY) {
dolog(LOG_INFO, "could not parse A record on line %d\n", file->lineno);
return (-1);
}
+ sa->ttl = myttl;
- ssd_a->region[ssd_a->a_count] = 0xff;
-
- ssd_a->a_count++;
- ssd_a->a_ptr = 0;
-
- ssd->flags |= DOMAIN_HAVE_A;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_A, sa);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -3397,13 +2773,12 @@ int
fill_aaaa(char *name, char *type, int myttl, char *aaaa)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain_aaaa *ssd_aaaa;
- struct domain *ssd;
+ struct aaaa *saaaa;
+ struct rbtree *rbt;
int converted_namelen;
char *converted_name;
struct in6_addr *ia6;
- int i, rs;
+ int i;
for (i = 0; i < strlen(name); i++) {
@@ -3415,75 +2790,29 @@ fill_aaaa(char *name, char *type, int myttl, char *aaa
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return (-1);
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
+ if ((saaaa = (struct aaaa *)calloc(1, sizeof(struct aaaa))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd_aaaa = (struct domain_aaaa *)find_substruct(ssd, INTERNAL_TYPE_AAAA);
- if (ssd_aaaa == NULL) {
-
- rs += sizeof(struct domain_aaaa);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free (sdomain);
- return -1;
- }
-
- sdomain = tp;
-
- ssd_aaaa = (sdomain + (rs - sizeof(struct domain_aaaa)));
- memset((char *)ssd_aaaa, 0, sizeof(struct domain_aaaa));
- ssd = (struct domain *)sdomain;
- ssd_aaaa->len = sizeof(struct domain_aaaa);
- ssd_aaaa->type = INTERNAL_TYPE_AAAA;
-
- }
-
- if (ssd_aaaa->aaaa_count >= RECORD_COUNT) {
- dolog(LOG_INFO, "%s: too many AAAA records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
- return (-1);
- }
-
- ssd->ttl[INTERNAL_TYPE_AAAA] = myttl;
-
- ia6 = (struct in6_addr *)&ssd_aaaa->aaaa[ssd_aaaa->aaaa_count];
+ ia6 = (struct in6_addr *)&saaaa->aaaa;
if (inet_pton(AF_INET6, (char *)aaaa, (char *)ia6) != 1) {
dolog(LOG_INFO, "AAAA \"%s\" unparseable line %d\n", aaaa, file->lineno);
return -1;
}
- ssd_aaaa->aaaa_count++;
- ssd_aaaa->aaaa_ptr = 0;
+ saaaa->ttl = myttl;
- ssd->flags |= DOMAIN_HAVE_AAAA;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_AAAA, saaaa);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -3494,13 +2823,12 @@ int
fill_ns(char *name, char *type, int myttl, char *nameserver)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_ns *ssd_ns;
+ struct ns *ns;
+ struct rbtree *rbt;
int len, converted_namelen;
char *myname, *converted_name;
char *n;
- int nstype, i, rs;
+ int nstype, i;
for (i = 0; i < strlen(name); i++) {
@@ -3522,25 +2850,6 @@ fill_ns(char *name, char *type, int myttl, char *names
return -1;
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
- return -1;
- }
-
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
/*
* check if this is not the apex of a zone, if it was we're almost
* guaranteed to have come across a SOA already and it's not flagged
@@ -3548,38 +2857,22 @@ fill_ns(char *name, char *type, int myttl, char *names
* internal
*/
- if (!(ssd->flags & DOMAIN_HAVE_SOA))
- nstype = NS_TYPE_DELEGATE;
+ if ((rbt = find_rrset(db, converted_name, converted_namelen)) != NULL) {
+ struct rrset *rrset;
+ rrset = find_rr(rbt, DNS_TYPE_SOA);
+ if (rrset == NULL)
+ nstype = NS_TYPE_DELEGATE;
- ssd_ns = (struct domain_ns *) find_substruct(ssd, INTERNAL_TYPE_NS);
- if (ssd_ns == NULL) {
- rs += sizeof(struct domain_ns);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- free (sdomain);
- return -1;
- }
- sdomain = tp;
- ssd_ns = (sdomain + (rs - sizeof(struct domain_ns)));
- memset((char *)ssd_ns, 0, sizeof(struct domain_ns));
- ssd = (struct domain *)sdomain;
- ssd_ns->len = sizeof(struct domain_ns);
- ssd_ns->type = INTERNAL_TYPE_NS;
- }
- if (debug)
- dolog(LOG_INFO, "after substruct\n");
-
- if (ssd_ns->ns_count >= RECORD_COUNT) {
- dolog(LOG_INFO, "%s: too many NS records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
- return (-1);
- }
+ free(rbt);
+ } else
+ return -1;
- ssd->ttl[INTERNAL_TYPE_NS] = myttl;
+ if ((ns = (struct ns *)calloc(1, sizeof(struct ns))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
+ return -1;
+ }
+
myname = dns_label(nameserver, (int *)&len);
if (myname == NULL) {
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
@@ -3591,25 +2884,25 @@ fill_ns(char *name, char *type, int myttl, char *names
return -1;
}
- n = (char *)ssd_ns->ns[ssd_ns->ns_count].nsserver;
- ssd_ns->ns[ssd_ns->ns_count].nslen = len;
- memcpy((char *)n, myname, ssd_ns->ns[ssd_ns->ns_count].nslen);
+ n = (char *)ns->nsserver;
+ ns->nslen = len;
+ memcpy((char *)n, myname, ns->nslen);
free(myname);
- ssd_ns->ns_count++;
- ssd_ns->ns_ptr = 0;
- ssd_ns->ns_type = nstype;
+ ns->ns_type = nstype;
+ ns->ttl = myttl;
- ssd->flags |= DOMAIN_HAVE_NS;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NS, ns);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
@@ -3619,12 +2912,11 @@ int
fill_soa(char *name, char *type, int myttl, char *auth, char *contact, int serial, int refresh, int retry, int expire, int ttl)
{
ddDB *db = mydb;
- void *sdomain, *tp;
- struct domain *ssd;
- struct domain_soa *ssd_soa;
+ struct rbtree *rbt;
+ struct soa *soa;
int len, converted_namelen;
char *myname, *converted_name;
- int i, rs;
+ int i;
for (i = 0; i < strlen(name); i++) {
name[i] = tolower((int)name[i]);
@@ -3641,27 +2933,11 @@ fill_soa(char *name, char *type, int myttl, char *auth
current_zone = strdup(name);
}
- rs = get_record_size(db, converted_name, converted_namelen);
- if (rs < 0) {
+ if ((soa = (struct soa *)calloc(1, sizeof(struct soa))) == NULL) {
+ dolog(LOG_ERR, "calloc: %s\n", strerror(errno));
return -1;
}
- if ((sdomain = calloc(1, rs)) == NULL) {
- return -1;
- }
-
- ssd = (struct domain *)sdomain;
-
- if (get_record(ssd, converted_name, converted_namelen) < 0) {
- return (-1);
- }
-
- strlcpy((char *)ssd->zonename, (char *)name, DNS_MAXNAME + 1);
- memcpy(ssd->zone, converted_name, converted_namelen);
- ssd->zonelen = converted_namelen;
-
- ssd->ttl[INTERNAL_TYPE_SOA] = myttl;
-
myname = dns_label(auth, (int *)&len);
if (myname == NULL) {
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
@@ -3673,32 +2949,8 @@ fill_soa(char *name, char *type, int myttl, char *auth
return -1;
}
- ssd_soa = (struct domain_soa *)find_substruct(ssd, INTERNAL_TYPE_SOA);
- if (ssd_soa == NULL) {
- rs += sizeof(struct domain_soa);
-#ifdef __OpenBSD__
- tp = reallocarray(sdomain, 1, rs);
-#else
- tp = realloc(sdomain, rs);
-#endif
- if (tp == NULL) {
- if (debug)
- dolog(LOG_DEBUG, "reallocarray failed %s\n", strerror(errno));
-
- free (sdomain);
- return -1;
- }
-
- sdomain = tp;
- ssd_soa = (sdomain + (rs - sizeof(struct domain_soa)));
- memset((char *)ssd_soa, 0, sizeof(struct domain_soa));
- ssd = (struct domain *)sdomain;
- ssd_soa->len = sizeof(struct domain_soa);
- ssd_soa->type = INTERNAL_TYPE_SOA;
- }
-
- ssd_soa->soa.nsserver_len = len;
- memcpy((char *)&ssd_soa->soa.nsserver[0], myname, len);
+ soa->nsserver_len = len;
+ memcpy((char *)&soa->nsserver, myname, len);
free(myname);
@@ -3713,85 +2965,33 @@ fill_soa(char *name, char *type, int myttl, char *auth
return -1;
}
- ssd_soa->soa.rp_len = len;
- memcpy((char *)&ssd_soa->soa.responsible_person[0], myname, len);
+ soa->rp_len = len;
+ memcpy((char *)&soa->responsible_person, myname, len);
free (myname);
- ssd_soa->soa.serial = serial;
- ssd_soa->soa.refresh = refresh;
- ssd_soa->soa.retry = retry;
- ssd_soa->soa.expire = expire;
- ssd_soa->soa.minttl = ttl;
+ soa->serial = serial;
+ soa->refresh = refresh;
+ soa->retry = retry;
+ soa->expire = expire;
+ soa->minttl = ttl;
+ soa->ttl = myttl;
- ssd->flags |= DOMAIN_HAVE_SOA;
-
- if (set_record(ssd, rs, converted_name, converted_namelen) < 0)
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SOA, soa);
+ if (rbt == NULL) {
+ dolog(LOG_ERR, "create_rr failed\n");
return -1;
+ }
if (converted_name)
free (converted_name);
- free (sdomain);
+ free (rbt);
return (0);
}
-int
-get_record(struct domain *sdomain, char *converted_name, int converted_namelen)
-{
- ddDB *db = mydb; /* XXX */
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = (char *)converted_name;
- key.size = converted_namelen;
-
- data.data = NULL;
- data.size = 0;
-
- if (db->get(db, &key, &data) == 0) {
-
- memcpy((char *)sdomain, (char *)data.data, data.size);
- } else {
- if (debug)
- dolog(LOG_INFO, "db->get: %s\n", strerror(errno));
-
- memset((char *)sdomain, 0, sizeof(struct domain));
- }
-
- return 0;
-}
-
-
-int
-set_record(struct domain *sdomain, int rs, char *converted_name, int converted_namelen)
-{
- ddDB *db = mydb; /* XXX */
- int ret;
-
- /* everythign in parse.y should get this flag! */
- sdomain->len = rs;
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = (char *)converted_name;
- key.size = converted_namelen;
-
- data.data = (void*)sdomain;
- data.size = rs;
-
- if ((ret = db->put(db, &key, &data)) != 0) {
- dolog(LOG_ERR, "db->put: %s / Out of Memory\n", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
struct file *
pushfile(const char *name, int secret, int descend, int rzone)
{
blob - 84a4aa3bed313ca21f942793766dada9dd4b5b6b
blob + 5fe18281f4472338c391b77abd9869b0ccb40a70
--- raxfr.c
+++ raxfr.c
@@ -26,7 +26,7 @@
*
*/
/*
- * $Id: raxfr.c,v 1.9 2019/02/11 17:38:55 pjp Exp $
+ * $Id: raxfr.c,v 1.10 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
@@ -215,6 +215,8 @@ raxfr_peek(FILE *f, u_char *p, u_char *estart, u_char
}
}
}
+
+ fflush(f);
free(humanname);
blob - 208d1a5eed8ed2ef1ac4c808539bacba75f1020c
blob + 349b0a9d916c680538fd3344340a6bac80dc3594
--- regress/dddctl/sign/Makefile
+++ regress/dddctl/sign/Makefile
@@ -15,7 +15,7 @@ ldns-verify-zone:
@test -f /usr/local/bin/ldns-verify-zone
jdnssec-verifyzone:
- @test -f /home/pjp/Delphinusdns/tools/jdnssec-tools-0.13/bin/jdnssec-verifyzone
+ #@test -f /home/pjp/Delphinusdns/tools/jdnssec-tools-0.13/bin/jdnssec-verifyzone
depend: named-checkzone ldns-verify-zone jdnssec-verifyzone
@@ -33,7 +33,7 @@ test-sign: depend
@echo "--> checking against ldns-verify-zone"
/usr/local/bin/ldns-verify-zone ${i}.bind
@echo "--> checking against jdnssec-verifyzone"
- /home/pjp/Delphinusdns/tools/jdnssec-tools-0.13/bin/jdnssec-verifyzone ${i}.bind
+ #/home/pjp/Delphinusdns/tools/jdnssec-tools-0.13/bin/jdnssec-verifyzone ${i}.bind
.endfor
@echo "--> If you reach here everything verified"
@echo "--> OK."
blob - 3b256296b50ea119dd2b801ef61c878d9ea2443a
blob + 1a74a2d8f492b56d6bb1f59ebb12960258c757ca
--- regress/delphinusdnsd/zinclude/config1
+++ regress/delphinusdnsd/zinclude/config1
@@ -1,4 +1,4 @@
-version "8";
+version "9";
options "cool stuff" {
versionstring "DELPHINUSDNSD - http://delphinusdns.centroid.eu";
interface "lo0";
blob - d5fa38fdd3f719c9b380e5f16d43bac617658740
blob + ff5c2fc5f7d9bb763947604f4d6a9ec4386f635e
--- regress/delphinusdnsd/zinclude/config2
+++ regress/delphinusdnsd/zinclude/config2
@@ -1,4 +1,4 @@
-version "8";
+version "9";
options "cool stuff" {
versionstring "DELPHINUSDNSD - http://delphinusdns.centroid.eu";
interface "lo0";
blob - 848d42b50359faa95ddcbc2d500bd50696fc7592
blob + 2411ebceea6c3fc11ec36022e2ef0da467bb938c
--- regress/delphinusdnsd/zinclude/config3
+++ regress/delphinusdnsd/zinclude/config3
@@ -1,4 +1,4 @@
-version "8";
+version "9";
options "cool stuff" {
versionstring "DELPHINUSDNSD - http://delphinusdns.centroid.eu";
interface "lo0";
blob - 06041b329dab6c3616d8ed4535c8dfcd194dcc86
blob + 05f2a948f8d925069536a3d927059c9513783afa
--- regress/delphinusdnsd/zinclude/config4
+++ regress/delphinusdnsd/zinclude/config4
@@ -1,4 +1,4 @@
-version "8";
+version "9";
options "cool stuff" {
versionstring "DELPHINUSDNSD - http://delphinusdns.centroid.eu";
interface "lo0";
blob - 59b019c43285ad692a06f9c566ddc0748429912b
blob + 6b2f1786502797d5aabd6d584201785c202f784b
--- reply.c
+++ reply.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: reply.c,v 1.64 2019/01/25 20:00:15 pjp Exp $
+ * $Id: reply.c,v 1.65 2019/02/15 15:11:34 pjp Exp $
*/
#include "ddd-include.h"
@@ -37,27 +37,32 @@
/* prototypes */
-extern int checklabel(ddDB *, struct domain *, struct domain *, struct question *);
-extern int additional_nsec3(char *, int, int, struct domain *, char *, int, int);
-extern int additional_a(char *, int, struct domain *, char *, int, int, int *);
-extern int additional_aaaa(char *, int, struct domain *, char *, int, int, int *);
-extern int additional_mx(char *, int, struct domain *, char *, int, int, int *);
-extern int additional_ptr(char *, int, struct domain *, char *, int, int, int *);
+extern int checklabel(ddDB *, struct rbtree *, struct rbtree *, struct question *);
+extern int additional_nsec3(char *, int, int, struct rbtree *, char *, int, int);
+extern int additional_a(char *, int, struct rbtree *, char *, int, int, int *);
+extern int additional_aaaa(char *, int, struct rbtree *, char *, int, int, int *);
+extern int additional_mx(char *, int, struct rbtree *, char *, int, int, int *);
+extern int additional_ptr(char *, int, struct rbtree *, char *, int, int, int *);
extern int additional_opt(struct question *, char *, int, int);
-extern int additional_rrsig(char *, int, int, struct domain *, char *, int, int, int);
-extern int additional_nsec(char *, int, int, struct domain *, char *, int, int);
+extern int additional_rrsig(char *, int, int, struct rbtree *, char *, int, int, int);
+extern int additional_nsec(char *, int, int, struct rbtree *, char *, int, int);
extern struct question *build_fake_question(char *, int, u_int16_t);
extern int compress_label(u_char *, int, int);
extern void dolog(int, char *, ...);
extern int free_question(struct question *);
-extern struct domain * lookup_zone(ddDB *, struct question *, int *, int *, char *);
+extern struct rbtree * lookup_zone(ddDB *, struct question *, int *, int *, char *);
extern void slave_shutdown(void);
-extern void * find_substruct(struct domain *, u_int16_t);
extern int get_record_size(ddDB *, char *, int);
extern char * dns_label(char *, int *);
extern int lookup_type(int internal_type);
-struct domain *Lookup_zone(ddDB *, char *, u_int16_t, u_int16_t, int);
+extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
+extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
+extern int display_rr(struct rrset *rrset);
+extern int rotate_rr(struct rrset *rrset);
+
+
+struct rbtree *Lookup_zone(ddDB *, char *, u_int16_t, u_int16_t, int);
u_int16_t create_anyreply(struct sreply *, char *, int, int, int);
int reply_a(struct sreply *, ddDB *);
int reply_nsec3(struct sreply *, ddDB *);
@@ -86,33 +91,21 @@ int reply_cname(struct sreply *, ddDB *);
int reply_any(struct sreply *, ddDB *);
int reply_refused(struct sreply *, ddDB *);
int reply_fmterror(struct sreply *, ddDB *);
-void update_db(ddDB *, struct domain *);
-struct domain * find_nsec(char *name, int namelen, struct domain *sd, ddDB *db);
+struct rbtree * find_nsec(char *name, int namelen, struct rbtree *, ddDB *db);
int nsec_comp(const void *a, const void *b);
char * convert_name(char *name, int namelen);
int count_dots(char *name);
char * base32hex_encode(u_char *input, int len);
-struct domain * find_nsec3_cover_next_closer(char *name, int namelen, struct domain *sd, ddDB *db);
-struct domain * find_nsec3_match_closest(char *name, int namelen, struct domain *sd, ddDB *db);
-struct domain * find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, ddDB *db);
-struct domain * find_nsec3_match_qname(char *name, int namelen, struct domain *sd, ddDB *db);
+struct rbtree * find_nsec3_cover_next_closer(char *name, int namelen, struct rbtree *, ddDB *db);
+struct rbtree * find_nsec3_match_closest(char *name, int namelen, struct rbtree *, ddDB *db);
+struct rbtree * find_nsec3_wildcard_closest(char *name, int namelen, struct rbtree *, ddDB *db);
+struct rbtree * find_nsec3_match_qname(char *name, int namelen, struct rbtree *, ddDB *db);
extern int debug, verbose, dnssec;
extern char *versionstring;
extern uint8_t vslen;
-#define RRSIG_ALIAS(mytype) do { \
- odh->answer = htons(a_count++); \
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, mytype, sd, reply, replysize, outlen, 0); \
- if (tmplen == 0) { \
- NTOHS(odh->query); \
- SET_DNS_TRUNCATION(odh); \
- HTONS(odh->query); \
- goto out; \
- } \
- outlen = tmplen; \
- } while (0);
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -126,7 +119,6 @@ reply_a(struct sreply *sreply, ddDB *db)
struct dns_header *odh;
u_int16_t outlen = 0;
int a_count;
- int mod, pos;
struct answer {
char name[2];
@@ -145,15 +137,17 @@ reply_a(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_a *sda = NULL;
+
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sda = find_substruct(sd, INTERNAL_TYPE_A)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) == NULL)
return -1;
if (istcp) {
@@ -178,10 +172,7 @@ reply_a(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -190,7 +181,7 @@ reply_a(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sda->a_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -199,10 +190,8 @@ reply_a(struct sreply *sreply, ddDB *db)
q->hdr->namelen + 4);
a_count = 0;
- pos = sda->a_ptr;
- mod = sda->a_count;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
/*
* answer->name is a pointer to the request (0xc00c)
*/
@@ -211,21 +200,19 @@ reply_a(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c; /* 2 bytes */
answer->type = q->hdr->qtype; /* 4 bytes */
answer->class = q->hdr->qclass; /* 6 bytes */
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_A] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_A]); /* 10 bytes */
+ answer->ttl = htonl(((struct a *)rrp->rdata)->ttl); /* 10 b */
answer->rdlength = htons(sizeof(in_addr_t)); /* 12 bytes */
- memcpy((char *)&answer->rdata, (char *)&sda->a[pos++ % mod],
+ memcpy((char *)&answer->rdata,
+ (char *)&((struct a *)rrp->rdata)->a,
sizeof(in_addr_t)); /* 16 bytes */
a_count++;
outlen += 16;
/* can we afford to write another header? if no truncate */
- if (sda->a_count > 1 && outlen + 16 > replysize) {
+ if (outlen + 16 > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -239,14 +226,16 @@ reply_a(struct sreply *sreply, ddDB *db)
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (a_count < RECORD_COUNT && --sda->a_count);
+ }
+ odh->answer = htons(a_count);
+
/* Add RRSIG reply_a */
if (dnssec && q->dnssecok) {
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_A, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_A, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -297,13 +286,11 @@ out:
}
/*
- * update a_ptr setting
+ * update order XXX
*/
- sda->a_ptr = (sda->a_ptr + 1) % mod;
- sda->a_count = mod;
- update_db(db, sd);
-
+ rotate_rr(rrset);
+
return (retlen);
}
@@ -340,15 +327,18 @@ reply_nsec3param(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_nsec3param *sdnsec3param = NULL;
+
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
+ int saltlen;
- if ((sdnsec3param = find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL)
return -1;
if (istcp) {
@@ -373,10 +363,7 @@ reply_nsec3param(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -389,14 +376,19 @@ reply_nsec3param(struct sreply *sreply, ddDB *db)
odh->nsrr = 0;
odh->additional = 0;
+
/* skip dns header, question name, qtype and qclass */
answer = (struct answer *)(&reply[0] + sizeof(struct dns_header) +
q->hdr->namelen + 4);
a_count = 0;
- if ((outlen + sizeof(struct answer) +
- sdnsec3param->nsec3param.saltlen ) > replysize) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp != NULL)
+ return -1;
+
+ saltlen = ((struct nsec3param *)rrp->rdata)->saltlen;
+ if ((outlen + sizeof(struct answer) + saltlen ) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -407,6 +399,8 @@ reply_nsec3param(struct sreply *sreply, ddDB *db)
goto out;
}
+
+
/*
* answer->name is a pointer to the request (0xc00c)
*/
@@ -415,22 +409,22 @@ reply_nsec3param(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c; /* 2 bytes */
answer->type = q->hdr->qtype; /* 4 bytes */
answer->class = q->hdr->qclass; /* 6 bytes */
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC3] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC3]); /* 10 bytes */
+ answer->ttl = htonl(((struct nsec3param *)rrp->rdata)->ttl);
- answer->rdlength = htons(sdnsec3param->nsec3param.saltlen + 5); /* 5 = rest */
+ answer->rdlength = htons(((struct nsec3param *)rrp->rdata)->saltlen + 5); /* 5 = rest */
- answer->algorithm = sdnsec3param->nsec3param.algorithm;
- answer->flags = sdnsec3param->nsec3param.flags;
- answer->iterations = htons(sdnsec3param->nsec3param.iterations);
- answer->saltlen = sdnsec3param->nsec3param.saltlen;
+ answer->algorithm = ((struct nsec3param *)rrp->rdata)->algorithm;
+ answer->flags = ((struct nsec3param *)rrp->rdata)->flags;
+ answer->iterations = htons(((struct nsec3param *)rrp->rdata)->iterations);
+ answer->saltlen = saltlen;
outlen += sizeof(struct answer);
- if (sdnsec3param->nsec3param.saltlen) {
- memcpy(&reply[outlen], &sdnsec3param->nsec3param.salt, sdnsec3param->nsec3param.saltlen);
- outlen += sdnsec3param->nsec3param.saltlen;
+ if (saltlen) {
+ memcpy(&reply[outlen],
+ &((struct nsec3param*)rrp->rdata)->salt,
+ saltlen);
+
+ outlen += saltlen;
}
a_count++;
@@ -444,7 +438,7 @@ reply_nsec3param(struct sreply *sreply, ddDB *db)
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_NSEC3PARAM, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_NSEC3PARAM, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -530,16 +524,18 @@ reply_nsec3(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_nsec3 *sdnsec3 = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
u_int8_t *somelen;
+ int bitmaplen, saltlen, nextlen;
- if ((sdnsec3 = find_substruct(sd, INTERNAL_TYPE_NSEC3)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) == NULL)
return -1;
if (istcp) {
@@ -551,9 +547,8 @@ reply_nsec3(struct sreply *sreply, ddDB *db)
/* RFC 5155 section 7.2.8 */
- /* we are the sole RR here, or perhaps we are accompanied by an rrsig */
- if ((sd->flags == DOMAIN_HAVE_NSEC) ||
- (sd->flags == (DOMAIN_HAVE_NSEC3 | DOMAIN_HAVE_RRSIG))) {
+ /* perhaps we are accompanied by an rrsig */
+ if (find_rr(rbt, DNS_TYPE_NSEC3) && find_rr(rbt, DNS_TYPE_RRSIG)) {
return (reply_nxdomain(sreply, db));
}
odh = (struct dns_header *)&reply[0];
@@ -571,10 +566,7 @@ reply_nsec3(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -593,9 +585,16 @@ reply_nsec3(struct sreply *sreply, ddDB *db)
a_count = 0;
- if ((outlen + sizeof(struct answer) + sdnsec3->nsec3.nextlen +
- sdnsec3->nsec3.saltlen + 1 +
- sdnsec3->nsec3.bitmap_len) > replysize) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
+ saltlen = ((struct nsec3 *)rrp->rdata)->saltlen;
+ bitmaplen = ((struct nsec3 *)rrp->rdata)->bitmap_len;
+ nextlen = ((struct nsec3 *)rrp->rdata)->nextlen;
+
+ if ((outlen + sizeof(struct answer) +
+ nextlen + saltlen + 1 + bitmaplen) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -614,35 +613,35 @@ reply_nsec3(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c; /* 2 bytes */
answer->type = q->hdr->qtype; /* 4 bytes */
answer->class = q->hdr->qclass; /* 6 bytes */
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC3] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC3]); /* 10 bytes */
+ answer->ttl = htonl(((struct nsec3 *)rrp->rdata)->ttl); /* 10 b */
+
+ answer->rdlength = htons(nextlen + bitmaplen + saltlen + 6); /* 6 = rest */
- answer->rdlength = htons(sdnsec3->nsec3.nextlen + sdnsec3->nsec3.bitmap_len + sdnsec3->nsec3.saltlen + 6); /* 6 = rest */
-
- answer->algorithm = sdnsec3->nsec3.algorithm;
- answer->flags = sdnsec3->nsec3.flags;
- answer->iterations = htons(sdnsec3->nsec3.iterations);
- answer->saltlen = sdnsec3->nsec3.saltlen;
+ answer->algorithm = ((struct nsec3 *)rrp->rdata)->algorithm;
+ answer->flags = ((struct nsec3 *)rrp->rdata)->flags;
+ answer->iterations = htons(((struct nsec3 *)rrp->rdata)->iterations);
+ answer->saltlen = saltlen;
outlen += sizeof(struct answer);
- if (sdnsec3->nsec3.saltlen) {
- memcpy(&reply[outlen], &sdnsec3->nsec3.salt, sdnsec3->nsec3.saltlen);
- outlen += sdnsec3->nsec3.saltlen;
+ if (saltlen) {
+ memcpy(&reply[outlen],
+ (char *)&((struct nsec3 *)rrp->rdata)->salt,
+ saltlen);
+
+ outlen += saltlen;
}
somelen = (u_int8_t *)&reply[outlen];
- *somelen = sdnsec3->nsec3.nextlen;
+ *somelen = nextlen;
outlen += 1;
- memcpy(&reply[outlen], sdnsec3->nsec3.next, sdnsec3->nsec3.nextlen);
+ memcpy(&reply[outlen], ((struct nsec3 *)rrp->rdata)->next, nextlen);
- outlen += sdnsec3->nsec3.nextlen;
+ outlen += nextlen;
- memcpy(&reply[outlen], sdnsec3->nsec3.bitmap, sdnsec3->nsec3.bitmap_len);
- outlen += sdnsec3->nsec3.bitmap_len;
+ memcpy(&reply[outlen], ((struct nsec3 *)rrp->rdata)->bitmap, bitmaplen);
+ outlen += bitmaplen;
a_count++;
@@ -655,7 +654,7 @@ reply_nsec3(struct sreply *sreply, ddDB *db)
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_NSEC3, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_NSEC3, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -736,15 +735,17 @@ reply_nsec(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_nsec *sdnsec = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
+ int ndnlen, bitmaplen;
- if ((sdnsec = find_substruct(sd, INTERNAL_TYPE_NSEC)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) == NULL)
return -1;
if (istcp) {
@@ -769,10 +770,7 @@ reply_nsec(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -791,8 +789,14 @@ reply_nsec(struct sreply *sreply, ddDB *db)
a_count = 0;
- if ((outlen + sizeof(struct answer) + sdnsec->nsec.ndn_len +
- sdnsec->nsec.bitmap_len) > replysize) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
+ ndnlen = ((struct nsec *)rrp->rdata)->ndn_len;
+ bitmaplen = ((struct nsec *)rrp->rdata)->bitmap_len;
+
+ if ((outlen + sizeof(struct answer) + ndnlen + bitmaplen) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -811,22 +815,19 @@ reply_nsec(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c; /* 2 bytes */
answer->type = q->hdr->qtype; /* 4 bytes */
answer->class = q->hdr->qclass; /* 6 bytes */
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC]); /* 10 bytes */
+ answer->ttl = htonl(((struct nsec *)rrp->rdata)->ttl); /* 10 b */
- answer->rdlength = htons(sdnsec->nsec.ndn_len + sdnsec->nsec.bitmap_len);
+ answer->rdlength = htons(ndnlen + bitmaplen);
outlen += sizeof(struct answer);
- memcpy(&reply[outlen], sdnsec->nsec.next_domain_name,
- sdnsec->nsec.ndn_len);
+ memcpy(&reply[outlen], ((struct nsec *)rrp->rdata)->next_domain_name,
+ ndnlen);
- outlen += sdnsec->nsec.ndn_len;
+ outlen += ndnlen;
- memcpy(&reply[outlen], sdnsec->nsec.bitmap, sdnsec->nsec.bitmap_len);
- outlen += sdnsec->nsec.bitmap_len;
+ memcpy(&reply[outlen], ((struct nsec *)rrp->rdata)->bitmap, bitmaplen);
+ outlen += bitmaplen;
a_count++;
@@ -839,7 +840,7 @@ reply_nsec(struct sreply *sreply, ddDB *db)
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_NSEC, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_NSEC, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -925,16 +926,16 @@ reply_ds(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_ds *sdds = NULL;
- struct domain_rrsig *sdrrsig = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdds = find_substruct(sd, INTERNAL_TYPE_DS)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) == NULL)
return -1;
if (istcp) {
@@ -959,10 +960,7 @@ reply_ds(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -980,9 +978,9 @@ reply_ds(struct sreply *sreply, ddDB *db)
a_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if ((outlen + sizeof(struct answer) +
- sdds->ds[a_count].digestlen) > replysize) {
+ ((struct ds *)rrp->rdata)->digestlen) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -1001,28 +999,25 @@ reply_ds(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c; /* 2 bytes */
answer->type = q->hdr->qtype; /* 4 bytes */
answer->class = q->hdr->qclass; /* 6 bytes */
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_DS] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_DS]); /* 10 bytes */
+ answer->ttl = htonl(((struct ds *)rrp->rdata)->ttl); /* 10 */
- answer->rdlength = htons(sdds->ds[a_count].digestlen + 4); /* 12 bytes */
+ answer->rdlength = htons(((struct ds *)rrp->rdata)->digestlen + 4); /* 12 bytes */
- answer->key_tag = htons(sdds->ds[a_count].key_tag);
- answer->algorithm = sdds->ds[a_count].algorithm;
- answer->digest_type = sdds->ds[a_count].digest_type;
+ answer->key_tag = htons(((struct ds *)rrp->rdata)->key_tag);
+ answer->algorithm = ((struct ds *)rrp->rdata)->algorithm;
+ answer->digest_type = ((struct ds *)rrp->rdata)->digest_type;
outlen += sizeof(struct answer);
- memcpy(&reply[outlen], sdds->ds[a_count].digest,
- sdds->ds[a_count].digestlen);
+ memcpy(&reply[outlen], ((struct ds *)rrp->rdata)->digest,
+ ((struct ds *)rrp->rdata)->digestlen);
- outlen += sdds->ds[a_count].digestlen;
+ outlen += ((struct ds *)rrp->rdata)->digestlen;
a_count++;
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (a_count < RECORD_COUNT && --sdds->ds_count);
+ }
odh->answer = htons(a_count);
@@ -1031,10 +1026,7 @@ reply_ds(struct sreply *sreply, ddDB *db)
int tmplen = 0;
int origlen = outlen;
- if ((sdrrsig = find_substruct(sd, INTERNAL_TYPE_RRSIG)) == NULL)
- goto out;
-
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_DS, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_DS, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -1083,6 +1075,8 @@ out:
}
}
+ rotate_rr(rrset);
+
return (retlen);
}
@@ -1118,17 +1112,17 @@ reply_dnskey(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_dnskey *sdkey = NULL;
- struct domain_rrsig *sdrrsig = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rrset *rrset2 = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
- int i;
u_int16_t rollback;
- if ((sdkey = find_substruct(sd, INTERNAL_TYPE_DNSKEY)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_A)) == NULL)
return -1;
if (istcp) {
@@ -1153,10 +1147,7 @@ reply_dnskey(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -1165,7 +1156,7 @@ reply_dnskey(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sdkey->dnskey_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -1175,9 +1166,9 @@ reply_dnskey(struct sreply *sreply, ddDB *db)
a_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if ((outlen + sizeof(struct answer) +
- sdkey->dnskey[a_count].publickey_len) > replysize) {
+ ((struct dnskey *)rrp->rdata)->publickey_len) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -1196,41 +1187,40 @@ reply_dnskey(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c; /* 2 bytes */
answer->type = q->hdr->qtype; /* 4 bytes */
answer->class = q->hdr->qclass; /* 6 bytes */
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_DNSKEY] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_DNSKEY]); /* 10 bytes */
+ answer->ttl = htonl(((struct dnskey *)rrp->rdata)->ttl);
- answer->rdlength = htons(sdkey->dnskey[a_count].publickey_len + 4); /* 12 bytes */
+ answer->rdlength = htons(((struct dnskey *)rrp->rdata)->publickey_len + 4); /* 12 bytes */
- answer->flags = htons(sdkey->dnskey[a_count].flags);
- answer->protocol = sdkey->dnskey[a_count].protocol;
- answer->algorithm = sdkey->dnskey[a_count].algorithm;
+ answer->flags = htons(((struct dnskey *)rrp->rdata)->flags);
+ answer->protocol = ((struct dnskey *)rrp->rdata)->protocol;
+ answer->algorithm = ((struct dnskey *)rrp->rdata)->algorithm;
outlen += sizeof(struct answer);
- memcpy(&reply[outlen], sdkey->dnskey[a_count].public_key,
- sdkey->dnskey[a_count].publickey_len);
+ memcpy(&reply[outlen], ((struct dnskey*)rrp->rdata)->public_key,
+ ((struct dnskey *)rrp->rdata)->publickey_len);
- outlen += sdkey->dnskey[a_count].publickey_len;
+ outlen += ((struct dnskey *)rrp->rdata)->publickey_len;
a_count++;
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (a_count < RECORD_COUNT && --sdkey->dnskey_count);
+ }
+ odh->answer = htons(a_count);
+
/* Add RRSIG reply_dnskey */
if (dnssec && q->dnssecok) {
int tmplen = 0;
int origlen = outlen;
- if ((sdrrsig = find_substruct(sd, INTERNAL_TYPE_RRSIG)) == NULL)
+ if ((rrset2 = find_rr(rbt, DNS_TYPE_RRSIG)) == NULL)
goto out;
- for (i = 0; i < sdrrsig->rrsig_dnskey_count; i++) {
+ TAILQ_FOREACH(rrp, &rrset2->rr_head, entries) {
origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_DNSKEY, sd, reply, replysize, outlen, i);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_DNSKEY, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -1246,7 +1236,7 @@ reply_dnskey(struct sreply *sreply, ddDB *db)
outlen = tmplen;
if (outlen > origlen)
- odh->answer = htons(a_count + 1 + i);
+ odh->answer = htons(a_count + 1);
}
}
@@ -1313,17 +1303,19 @@ reply_rrsig(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_rrsig *sdrr = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+#if 0
+ struct rr *rrp = NULL;
+#endif
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
int tmplen = 0;
- int i;
u_int16_t rollback;
- if ((sdrr = find_substruct(sd, INTERNAL_TYPE_RRSIG)) == NULL)
+ if ((find_rr(rbt, DNS_TYPE_RRSIG)) == NULL)
return -1;
if (istcp) {
@@ -1348,10 +1340,7 @@ reply_rrsig(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -1365,43 +1354,10 @@ reply_rrsig(struct sreply *sreply, ddDB *db)
a_count = 0;
- if (sd->flags & DOMAIN_HAVE_A) {
- RRSIG_ALIAS(INTERNAL_TYPE_A);
- }
- if (sd->flags & DOMAIN_HAVE_SOA) {
- RRSIG_ALIAS(INTERNAL_TYPE_SOA);
- }
- if (sd->flags & DOMAIN_HAVE_CNAME) {
- RRSIG_ALIAS(INTERNAL_TYPE_CNAME);
- }
- if (sd->flags & DOMAIN_HAVE_PTR) {
- RRSIG_ALIAS(INTERNAL_TYPE_PTR);
- }
- if (sd->flags & DOMAIN_HAVE_MX) {
- RRSIG_ALIAS(INTERNAL_TYPE_MX);
- }
- if (sd->flags & DOMAIN_HAVE_AAAA) {
- RRSIG_ALIAS(INTERNAL_TYPE_AAAA);
- }
- if (sd->flags & DOMAIN_HAVE_NS) {
- RRSIG_ALIAS(INTERNAL_TYPE_NS);
- }
- if (sd->flags & DOMAIN_HAVE_TXT) {
- RRSIG_ALIAS(INTERNAL_TYPE_TXT);
- }
- if (sd->flags & DOMAIN_HAVE_SRV) {
- RRSIG_ALIAS(INTERNAL_TYPE_SRV);
- }
- if (sd->flags & DOMAIN_HAVE_SSHFP) {
- RRSIG_ALIAS(INTERNAL_TYPE_SSHFP);
- }
- if (sd->flags & DOMAIN_HAVE_NAPTR) {
- RRSIG_ALIAS(INTERNAL_TYPE_NAPTR);
- }
- if (sd->flags & DOMAIN_HAVE_DNSKEY) {
- for (i = 0; i < sdrr->rrsig_dnskey_count; i++) {
+ TAILQ_FOREACH(rrset, &rbt->rrset_head, entries) {
+ if (rrset->rrtype == DNS_TYPE_DNSKEY) {
odh->answer = htons(a_count++);
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_DNSKEY, sd, reply, replysize, outlen, i);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_DNSKEY, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
@@ -1414,14 +1370,18 @@ reply_rrsig(struct sreply *sreply, ddDB *db)
}
outlen = tmplen;
+ } else {
+ odh->answer = htons(a_count++);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, rrset->rrtype, rbt, reply, replysize, outlen, 0);
+ if (tmplen == 0) {
+ NTOHS(odh->query);
+ SET_DNS_TRUNCATION(odh);
+ HTONS(odh->query);
+ goto out;
+ }
+ outlen = tmplen;
}
}
- if (sd->flags & DOMAIN_HAVE_DS) {
- RRSIG_ALIAS(INTERNAL_TYPE_DS);
- }
- if (sd->flags & DOMAIN_HAVE_NSEC) {
- RRSIG_ALIAS(INTERNAL_TYPE_NSEC);
- }
odh->answer = htons(a_count);
@@ -1472,7 +1432,6 @@ reply_aaaa(struct sreply *sreply, ddDB *db)
struct dns_header *odh;
u_int16_t outlen = 0;
int aaaa_count;
- int mod, pos;
struct answer {
char name[2];
@@ -1491,14 +1450,15 @@ reply_aaaa(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_aaaa *sdaaaa = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rr *rrp = NULL;
+ struct rrset *rrset = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdaaaa = find_substruct(sd, INTERNAL_TYPE_AAAA)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) == NULL)
return -1;
if (istcp) {
@@ -1524,10 +1484,7 @@ reply_aaaa(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -1536,7 +1493,7 @@ reply_aaaa(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sdaaaa->aaaa_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -1546,48 +1503,33 @@ reply_aaaa(struct sreply *sreply, ddDB *db)
aaaa_count = 0;
- pos = sdaaaa->aaaa_ptr;
- mod = sdaaaa->aaaa_count;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_AAAA] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_AAAA]); /* 10 bytes */
+ answer->ttl = htonl(((struct aaaa *)rrp->rdata)->ttl);
answer->rdlength = htons(sizeof(struct in6_addr));
- memcpy((char *)&answer->rdata, (char *)&sdaaaa->aaaa[pos++ % mod], sizeof(struct in6_addr));
+ memcpy((char *)&answer->rdata, (char *)&((struct aaaa *)rrp->rdata)->aaaa, sizeof(struct in6_addr));
outlen += 28;
- /* can we afford to write another header? if no truncate */
- if (sdaaaa->aaaa_count > 1 && outlen + 28 > replysize) {
- NTOHS(odh->query);
- SET_DNS_TRUNCATION(odh);
- HTONS(odh->query);
- odh->answer = 0;
- odh->nsrr = 0;
- odh->additional = 0;
- outlen = rollback;
- goto out;
- }
-
aaaa_count++;
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (aaaa_count < RECORD_COUNT && --sdaaaa->aaaa_count);
+ };
+ odh->answer = htons(aaaa_count);
+
/* RRSIG reply_aaaa */
if (dnssec && q->dnssecok) {
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_AAAA, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_AAAA, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -1637,9 +1579,7 @@ out:
}
}
- sdaaaa->aaaa_ptr = (sdaaaa->aaaa_ptr + 1) % mod;
- sdaaaa->aaaa_count = mod;
- update_db(db, sd);
+ rotate_rr(rrset);
return (retlen);
}
@@ -1679,17 +1619,16 @@ reply_mx(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_mx *sdmx = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdmx = find_substruct(sd, INTERNAL_TYPE_MX)) == NULL) {
- dolog(LOG_INFO, "no such record MX!\n");
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) == NULL)
return -1;
- }
if (istcp) {
@@ -1714,11 +1653,7 @@ reply_mx(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
-
- if (sreply->sr == NULL) {
- SET_DNS_AUTHORITATIVE(odh);
- } else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -1727,7 +1662,7 @@ reply_mx(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sdmx->mx_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -1736,28 +1671,26 @@ reply_mx(struct sreply *sreply, ddDB *db)
q->hdr->namelen + 4);
mx_count = 0;
- do {
+
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_MX] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_MX]);
+ answer->ttl = htonl(((struct smx *)rrp->rdata)->ttl);
- answer->rdlength = htons(sizeof(u_int16_t) + sdmx->mx[mx_count].exchangelen);
+ answer->rdlength = htons(sizeof(u_int16_t) + ((struct smx *)rrp->rdata)->exchangelen);
- answer->mx_priority = htons(sdmx->mx[mx_count].preference);
- memcpy((char *)&answer->exchange, (char *)sdmx->mx[mx_count].exchange, sdmx->mx[mx_count].exchangelen);
+ answer->mx_priority = htons(((struct smx *)rrp->rdata)->preference);
+ memcpy((char *)&answer->exchange, (char *)((struct smx *)rrp->rdata)->exchange, ((struct smx *)rrp->rdata)->exchangelen);
- name = sdmx->mx[mx_count].exchange;
- namelen = sdmx->mx[mx_count].exchangelen;
+ name = ((struct smx *)rrp->rdata)->exchange;
+ namelen = ((struct smx *)rrp->rdata)->exchangelen;
- outlen += (12 + 2 + sdmx->mx[mx_count].exchangelen);
+ outlen += (12 + 2 + ((struct smx *)rrp->rdata)->exchangelen);
/* can we afford to write another header? if no truncate */
- if (sdmx->mx_count > 1 && (outlen + 12 + 2 + sdmx->mx[mx_count].exchangelen) > replysize) {
+ if ((outlen + 12 + 2 + ((struct smx *)rrp->rdata)->exchangelen) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -1770,14 +1703,17 @@ reply_mx(struct sreply *sreply, ddDB *db)
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (++mx_count < RECORD_COUNT && --sdmx->mx_count);
+ mx_count++;
+ }
+ odh->answer = htonl(mx_count);
+
/* RRSIG reply_mx*/
if (dnssec && q->dnssecok) {
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_MX, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_MX, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -1843,7 +1779,6 @@ reply_ns(struct sreply *sreply, ddDB *db)
struct dns_header *odh;
int tmplen = 0;
int ns_count;
- int mod, pos;
u_int16_t *plen;
char *name;
u_int16_t outlen = 0;
@@ -1866,14 +1801,16 @@ reply_ns(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_ns *sdns = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
+ int ns_type;
- if ((sdns = find_substruct(sd, INTERNAL_TYPE_NS)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) == NULL)
return -1;
if (istcp) {
@@ -1899,19 +1836,8 @@ reply_ns(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
+ SET_DNS_AUTHORITATIVE(odh);
- if (sreply->sr == NULL) {
- switch (sdns->ns_type) {
- case 0:
- SET_DNS_AUTHORITATIVE(odh);
- break;
- default:
- SET_DNS_RECURSION(odh);
- break;
- }
- } else
- SET_DNS_RECURSION_AVAIL(odh);
-
if (q->rd) {
SET_DNS_RECURSION(odh);
}
@@ -1919,16 +1845,8 @@ reply_ns(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- switch (sdns->ns_type) {
- case NS_TYPE_DELEGATE:
- odh->answer = 0;
- odh->nsrr = htons(sdns->ns_count);
- break;
- default:
- odh->answer = htons(sdns->ns_count);
- odh->nsrr = 0;
- break;
- }
+ odh->answer = 0;
+ odh->nsrr = 0;
odh->additional = 0;
/* skip dns header, question name, qtype and qclass */
@@ -1936,21 +1854,17 @@ reply_ns(struct sreply *sreply, ddDB *db)
q->hdr->namelen + 4);
ns_count = 0;
- mod = sdns->ns_count;
- pos = sdns->ns_ptr;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = htons(DNS_TYPE_NS);
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NS] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NS]);
+ answer->ttl = htonl(((struct ns *)rrp->rdata)->ttl);
- name = sdns->ns[pos % mod].nsserver;
- namelen = sdns->ns[pos % mod].nslen;
+ name = ((struct ns *)rrp->rdata)->nsserver;
+ namelen = ((struct ns *)rrp->rdata)->nslen;
+ ns_type = ((struct ns *)rrp->rdata)->ns_type;
answer->rdlength = htons(namelen);
@@ -1967,29 +1881,28 @@ reply_ns(struct sreply *sreply, ddDB *db)
answer->rdlength = htons(&reply[outlen] - &answer->ns);
- /* can we afford to write another header? if no truncate */
- if (sdns->ns_count > 1 && (outlen + 12 + sdns->ns[pos % mod].nslen) > replysize) {
- NTOHS(odh->query);
- SET_DNS_TRUNCATION(odh);
- HTONS(odh->query);
- odh->answer = 0;
- odh->nsrr = 0;
- odh->additional = 0;
- outlen = rollback;
- goto out;
- }
-
- pos++;
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (++ns_count < RECORD_COUNT && --sdns->ns_count);
+ ns_count++;
+ }
+ switch (ns_type) {
+ case NS_TYPE_DELEGATE:
+ odh->answer = 0;
+ odh->nsrr = htons(ns_count);
+ break;
+ default:
+ odh->answer = htons(ns_count);
+ odh->nsrr = 0;
+ break;
+ }
+
/* add RRSIG reply_ns */
if (dnssec && q->dnssecok) {
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_NS, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_NS, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2042,11 +1955,8 @@ out:
}
}
- sdns->ns_ptr = (sdns->ns_ptr + 1) % mod;
- sdns->ns_count = mod;
+ rotate_rr(rrset);
- update_db(db, sd);
-
return (retlen);
}
@@ -2087,15 +1997,16 @@ reply_cname(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain *sd1 = sreply->sd2;
- struct domain_cname *sdcname = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rbtree *rbt1 = sreply->rbt2;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdcname = find_substruct(sd, INTERNAL_TYPE_CNAME)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_CNAME)) == NULL)
return -1;
if (istcp) {
@@ -2122,11 +2033,8 @@ reply_cname(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
-
+ SET_DNS_AUTHORITATIVE(odh);
+
if (q->rd) {
SET_DNS_RECURSION(odh);
}
@@ -2137,6 +2045,10 @@ reply_cname(struct sreply *sreply, ddDB *db)
odh->answer = htons(1);
odh->nsrr = 0;
odh->additional = 0;
+
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
answer = (struct answer *)(&reply[0] + sizeof(struct dns_header) +
q->hdr->namelen + 4);
@@ -2145,17 +2057,14 @@ reply_cname(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c;
answer->type = htons(DNS_TYPE_CNAME);
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_CNAME] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_CNAME]);
+ answer->ttl = htonl(((struct cname *)rrp->rdata)->ttl);
outlen += 12; /* up to rdata length */
p = (char *)&answer->rdata;
- label = &sdcname->cname[0];
- labellen = sdcname->cnamelen;
+ label = (char *)&((struct cname *)rrp->rdata)->cname;
+ labellen = ((struct cname *)rrp->rdata)->cnamelen;
plabel = label;
@@ -2181,7 +2090,7 @@ reply_cname(struct sreply *sreply, ddDB *db)
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
if (dnssec && q->dnssecok) {
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_CNAME, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_CNAME, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2201,8 +2110,8 @@ reply_cname(struct sreply *sreply, ddDB *db)
HTONS(odh->answer);
}
- if (ntohs(q->hdr->qtype) == DNS_TYPE_A && sd1 != NULL) {
- tmplen = additional_a(sdcname->cname, sdcname->cnamelen, sd1, reply, replysize, outlen, &addcount);
+ if (ntohs(q->hdr->qtype) == DNS_TYPE_A && rbt1 != NULL) {
+ tmplen = additional_a(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, rbt1, reply, replysize, outlen, &addcount);
if (tmplen > 0)
outlen = tmplen;
@@ -2212,7 +2121,7 @@ reply_cname(struct sreply *sreply, ddDB *db)
HTONS(odh->answer);
if (dnssec && q->dnssecok) {
- tmplen = additional_rrsig(sdcname->cname, sdcname->cnamelen, INTERNAL_TYPE_A, sd1, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, DNS_TYPE_A, rbt1, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2231,8 +2140,8 @@ reply_cname(struct sreply *sreply, ddDB *db)
odh->answer++;
HTONS(odh->answer);
}
- } else if (ntohs(q->hdr->qtype) == DNS_TYPE_AAAA && sd1 != NULL) {
- tmplen = additional_aaaa(sdcname->cname, sdcname->cnamelen, sd1, reply, replysize, outlen, &addcount);
+ } else if (ntohs(q->hdr->qtype) == DNS_TYPE_AAAA && rbt1 != NULL) {
+ tmplen = additional_aaaa(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, rbt1, reply, replysize, outlen, &addcount);
if (tmplen > 0)
outlen = tmplen;
@@ -2242,7 +2151,7 @@ reply_cname(struct sreply *sreply, ddDB *db)
HTONS(odh->answer);
if (dnssec && q->dnssecok) {
- tmplen = additional_rrsig(sdcname->cname, sdcname->cnamelen, INTERNAL_TYPE_AAAA, sd1, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, DNS_TYPE_AAAA, rbt1, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2261,8 +2170,8 @@ reply_cname(struct sreply *sreply, ddDB *db)
odh->answer++;
HTONS(odh->answer);
}
- } else if (ntohs(q->hdr->qtype) == DNS_TYPE_MX && sd1 != NULL) {
- tmplen = additional_mx(sdcname->cname, sdcname->cnamelen, sd1, reply, replysize, outlen, &addcount);
+ } else if (ntohs(q->hdr->qtype) == DNS_TYPE_MX && rbt1 != NULL) {
+ tmplen = additional_mx(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, rbt1, reply, replysize, outlen, &addcount);
if (tmplen > 0)
outlen = tmplen;
@@ -2272,7 +2181,7 @@ reply_cname(struct sreply *sreply, ddDB *db)
HTONS(odh->answer);
if (dnssec && q->dnssecok) {
- tmplen = additional_rrsig(sdcname->cname, sdcname->cnamelen, INTERNAL_TYPE_MX, sd1, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, DNS_TYPE_MX, rbt1, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2291,8 +2200,8 @@ reply_cname(struct sreply *sreply, ddDB *db)
odh->answer++;
HTONS(odh->answer);
}
- } else if (ntohs(q->hdr->qtype) == DNS_TYPE_PTR && sd1 != NULL) {
- tmplen = additional_ptr(sdcname->cname, sdcname->cnamelen, sd1, reply, replysize, outlen, &addcount);
+ } else if (ntohs(q->hdr->qtype) == DNS_TYPE_PTR && rbt1 != NULL) {
+ tmplen = additional_ptr(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, rbt1, reply, replysize, outlen, &addcount);
if (tmplen > 0)
outlen = tmplen;
@@ -2302,7 +2211,7 @@ reply_cname(struct sreply *sreply, ddDB *db)
HTONS(odh->answer);
if (dnssec && q->dnssecok) {
- tmplen = additional_rrsig(sdcname->cname, sdcname->cnamelen, INTERNAL_TYPE_PTR, sd1, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen, DNS_TYPE_PTR, rbt1, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2391,14 +2300,15 @@ reply_ptr(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_ptr *sdptr = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdptr = find_substruct(sd, INTERNAL_TYPE_PTR)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) == NULL)
return -1;
if (istcp) {
@@ -2416,6 +2326,10 @@ reply_ptr(struct sreply *sreply, ddDB *db)
return (retlen);
}
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
/* copy question to reply */
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
/* blank query */
@@ -2425,15 +2339,13 @@ reply_ptr(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
}
+
HTONS(odh->query);
odh->question = htons(1);
@@ -2448,17 +2360,14 @@ reply_ptr(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_PTR] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_PTR]);
+ answer->ttl = htonl(((struct ptr *)rrp->rdata)->ttl);
outlen += 12; /* up to rdata length */
p = (char *)&answer->rdata;
- label = &sdptr->ptr[0];
- labellen = sdptr->ptrlen;
+ label = ((struct ptr *)rrp->rdata)->ptr;
+ labellen = ((struct ptr *)rrp->rdata)->ptrlen;
plabel = label;
@@ -2484,7 +2393,7 @@ reply_ptr(struct sreply *sreply, ddDB *db)
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
if (dnssec && q->dnssecok) {
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_PTR, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_PTR, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2567,17 +2476,6 @@ reply_soa(struct sreply *sreply, ddDB *db)
char rdata;
} __attribute__((packed));
- struct soa {
- char *nsserver;
- char *responsible_person;
- u_int32_t serial;
- u_int32_t refresh;
- u_int32_t retry;
- u_int32_t expire;
- u_int32_t minttl;
- };
-
-
struct answer *answer;
int so = sreply->so;
@@ -2586,14 +2484,15 @@ reply_soa(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_soa *sdsoa = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdsoa = find_substruct(sd, INTERNAL_TYPE_SOA)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) == NULL)
return -1;
if (istcp) {
@@ -2621,10 +2520,7 @@ reply_soa(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -2637,6 +2533,10 @@ reply_soa(struct sreply *sreply, ddDB *db)
odh->nsrr = 0;
odh->additional = 0;
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
answer = (struct answer *)(&reply[0] + sizeof(struct dns_header) +
q->hdr->namelen + 4);
@@ -2644,18 +2544,15 @@ reply_soa(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA]);
+ answer->ttl = htonl(((struct soa *)rrp->rdata)->ttl);
outlen += 12; /* up to rdata length */
p = (char *)&answer->rdata;
- label = sdsoa->soa.nsserver;
- labellen = sdsoa->soa.nsserver_len;
+ label = ((struct soa *)rrp->rdata)->nsserver;
+ labellen = ((struct soa *)rrp->rdata)->nsserver_len;
plabel = label;
@@ -2678,8 +2575,8 @@ reply_soa(struct sreply *sreply, ddDB *db)
outlen = tmplen;
}
- label = sdsoa->soa.responsible_person;
- labellen = sdsoa->soa.rp_len;
+ label = ((struct soa *)rrp->rdata)->responsible_person;
+ labellen = ((struct soa *)rrp->rdata)->rp_len;
plabel = label;
for (i = outlen; i < replysize; i++) {
@@ -2702,43 +2599,40 @@ reply_soa(struct sreply *sreply, ddDB *db)
}
- /* XXX */
- if ((outlen + sizeof(sdsoa->soa.serial)) > replysize) {
- /* XXX server error reply? */
+ if (outlen + sizeof(u_int32_t) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.serial);
- outlen += sizeof(sdsoa->soa.serial); /* XXX */
+ *soa_val = htonl(((struct soa *)rrp->rdata)->serial);
+ outlen += sizeof(u_int32_t);
- /* XXX */
- if ((outlen + sizeof(sdsoa->soa.refresh)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.refresh);
- outlen += sizeof(sdsoa->soa.refresh); /* XXX */
+ *soa_val = htonl(((struct soa *)rrp->rdata)->refresh);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.retry)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.retry);
- outlen += sizeof(sdsoa->soa.retry); /* XXX */
+ *soa_val = htonl(((struct soa *)rrp->rdata)->retry);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.expire)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.expire);
- outlen += sizeof(sdsoa->soa.expire);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->expire);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.minttl)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.minttl);
- outlen += sizeof(sdsoa->soa.minttl);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->minttl);
+ outlen += sizeof(u_int32_t);
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
@@ -2747,7 +2641,7 @@ reply_soa(struct sreply *sreply, ddDB *db)
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_SOA, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_SOA, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -2837,14 +2731,15 @@ reply_txt(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_txt *sdtxt = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdtxt = find_substruct(sd, INTERNAL_TYPE_TXT)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) == NULL)
return -1;
if (istcp) {
@@ -2863,6 +2758,10 @@ reply_txt(struct sreply *sreply, ddDB *db)
return (retlen);
}
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
/* copy question to reply */
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
/* blank query */
@@ -2872,10 +2771,7 @@ reply_txt(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -2895,27 +2791,24 @@ reply_txt(struct sreply *sreply, ddDB *db)
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_TXT] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_TXT]);
+ answer->ttl = htonl(((struct txt *)rrp->rdata)->ttl);
outlen += 12; /* up to rdata length */
p = (char *)&answer->rdata;
- *p = sdtxt->txtlen;
- memcpy((p + 1), sdtxt->txt, sdtxt->txtlen);
- outlen += (sdtxt->txtlen + 1);
+ *p = ((struct txt *)rrp->rdata)->txtlen;
+ memcpy((p + 1), ((struct txt *)rrp->rdata)->txt, ((struct txt *)rrp->rdata)->txtlen);
+ outlen += (((struct txt *)rrp->rdata)->txtlen + 1);
- answer->rdlength = htons(sdtxt->txtlen + 1);
+ answer->rdlength = htons(((struct txt *)rrp->rdata)->txtlen + 1);
/* Add RRSIG reply_txt */
if (dnssec && q->dnssecok) {
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_TXT, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_TXT, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -3034,10 +2927,7 @@ reply_version(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -3139,15 +3029,16 @@ reply_tlsa(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_tlsa *sdtlsa = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int typelen = 0;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdtlsa = find_substruct(sd, INTERNAL_TYPE_TLSA)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) == NULL)
return -1;
if (istcp) {
@@ -3173,11 +3064,7 @@ reply_tlsa(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
-
- if (sreply->sr == NULL) {
- SET_DNS_AUTHORITATIVE(odh);
- } else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -3186,7 +3073,7 @@ reply_tlsa(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sdtlsa->tlsa_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -3195,17 +3082,14 @@ reply_tlsa(struct sreply *sreply, ddDB *db)
q->hdr->namelen + 4);
tlsa_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_TLSA] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_TLSA]);
+ answer->ttl = htonl(((struct tlsa *)rrp->rdata)->ttl);
- switch (sdtlsa->tlsa[tlsa_count].matchtype) {
+ switch (((struct tlsa *)rrp->rdata)->matchtype) {
case 1:
typelen = DNS_TLSA_SIZE_SHA256;
break;
@@ -3218,35 +3102,26 @@ reply_tlsa(struct sreply *sreply, ddDB *db)
}
answer->rdlength = htons((3 * sizeof(u_int8_t)) + typelen);
- answer->usage = sdtlsa->tlsa[tlsa_count].usage;
- answer->selector = sdtlsa->tlsa[tlsa_count].selector;
- answer->matchtype = sdtlsa->tlsa[tlsa_count].matchtype;
+ answer->usage = ((struct tlsa *)rrp->rdata)->usage;
+ answer->selector = ((struct tlsa *)rrp->rdata)->selector;
+ answer->matchtype = ((struct tlsa *)rrp->rdata)->matchtype;
- memcpy((char *)&answer->target, (char *)sdtlsa->tlsa[tlsa_count].data, sdtlsa->tlsa[tlsa_count].datalen);
+ memcpy((char *)&answer->target, (char *)((struct tlsa *)rrp->rdata)->data, ((struct tlsa *)rrp->rdata)->datalen);
- /* can we afford to write another header? if no truncate */
- if (sdtlsa->tlsa_count > 1 && (outlen + 12 + 3 + sdtlsa->tlsa[tlsa_count].datalen) > replysize) {
- NTOHS(odh->query);
- SET_DNS_TRUNCATION(odh);
- HTONS(odh->query);
- odh->answer = 0;
- odh->nsrr = 0;
- odh->additional = 0;
- outlen = rollback;
- goto out;
- }
-
/* set new offset for answer */
- outlen += (12 + 3 + sdtlsa->tlsa[tlsa_count].datalen);
+ outlen += (12 + 3 + ((struct tlsa *)rrp->rdata)->datalen);
answer = (struct answer *)&reply[outlen];
- } while (++tlsa_count < RECORD_COUNT && --sdtlsa->tlsa_count);
+ tlsa_count++;
+ }
+ odh->answer = htons(tlsa_count);
+
/* RRSIG reply_tlsa */
if (dnssec && q->dnssecok) {
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_TLSA, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_TLSA, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -3335,15 +3210,16 @@ reply_sshfp(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_sshfp *sdsshfp = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int typelen = 0;
int replysize = 512;
int retlen = -1;
u_int16_t rollback;
- if ((sdsshfp = find_substruct(sd, INTERNAL_TYPE_SSHFP)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) == NULL)
return -1;
if (istcp) {
@@ -3369,11 +3245,7 @@ reply_sshfp(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
-
- if (sreply->sr == NULL) {
- SET_DNS_AUTHORITATIVE(odh);
- } else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -3382,7 +3254,7 @@ reply_sshfp(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sdsshfp->sshfp_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -3391,17 +3263,14 @@ reply_sshfp(struct sreply *sreply, ddDB *db)
q->hdr->namelen + 4);
sshfp_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SSHFP] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SSHFP]);
+ answer->ttl = htonl(((struct sshfp *)rrp->rdata)->ttl);
- switch (sdsshfp->sshfp[sshfp_count].fptype) {
+ switch (((struct sshfp *)rrp->rdata)->fptype) {
case 1:
typelen = DNS_SSHFP_SIZE_SHA1;
break;
@@ -3414,34 +3283,25 @@ reply_sshfp(struct sreply *sreply, ddDB *db)
}
answer->rdlength = htons((2 * sizeof(u_int8_t)) + typelen);
- answer->sshfp_alg = sdsshfp->sshfp[sshfp_count].algorithm;
- answer->sshfp_type = sdsshfp->sshfp[sshfp_count].fptype;
+ answer->sshfp_alg = ((struct sshfp *)rrp->rdata)->algorithm;
+ answer->sshfp_type = ((struct sshfp *)rrp->rdata)->fptype;
- memcpy((char *)&answer->target, (char *)sdsshfp->sshfp[sshfp_count].fingerprint, sdsshfp->sshfp[sshfp_count].fplen);
+ memcpy((char *)&answer->target, (char *)((struct sshfp *)rrp->rdata)->fingerprint, ((struct sshfp *)rrp->rdata)->fplen);
- /* can we afford to write another header? if no truncate */
- if (sdsshfp->sshfp_count > 1 && (outlen + 12 + 2 + sdsshfp->sshfp[sshfp_count].fplen) > replysize) {
- NTOHS(odh->query);
- SET_DNS_TRUNCATION(odh);
- HTONS(odh->query);
- odh->answer = 0;
- odh->nsrr = 0;
- odh->additional = 0;
- outlen = rollback;
- goto out;
- }
-
/* set new offset for answer */
- outlen += (12 + 2 + sdsshfp->sshfp[sshfp_count].fplen);
+ outlen += (12 + 2 + ((struct sshfp *)rrp->rdata)->fplen);
answer = (struct answer *)&reply[outlen];
- } while (++sshfp_count < RECORD_COUNT && --sdsshfp->sshfp_count);
+ sshfp_count++;
+ }
+ odh->answer = htons(sshfp_count);
+
/* RRSIG reply_sshfp */
if (dnssec && q->dnssecok) {
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_SSHFP, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_SSHFP, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -3532,8 +3392,9 @@ reply_naptr(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_naptr *sdnaptr = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int tmplen, savelen;
@@ -3541,7 +3402,7 @@ reply_naptr(struct sreply *sreply, ddDB *db)
int retlen = -1;
u_int16_t rollback;
- if ((sdnaptr = find_substruct(sd, INTERNAL_TYPE_NAPTR)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) == NULL)
return -1;
if (istcp) {
@@ -3566,11 +3427,7 @@ reply_naptr(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
-
- if (sreply->sr == NULL) {
- SET_DNS_AUTHORITATIVE(odh);
- } else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -3579,7 +3436,7 @@ reply_naptr(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sdnaptr->naptr_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -3588,47 +3445,45 @@ reply_naptr(struct sreply *sreply, ddDB *db)
q->hdr->namelen + 4);
naptr_count = 0;
- do {
+
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
savelen = outlen;
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NAPTR] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NAPTR]);
+ answer->ttl = htonl(((struct naptr *)rrp->rdata)->ttl);
- answer->naptr_order = htons(sdnaptr->naptr[naptr_count].order);
- answer->naptr_preference = htons(sdnaptr->naptr[naptr_count].preference);
+ answer->naptr_order = htons(((struct naptr *)rrp->rdata)->order);
+ answer->naptr_preference = htons(((struct naptr *)rrp->rdata)->preference);
p = (char *)&answer->rest;
- *p = sdnaptr->naptr[naptr_count].flagslen;
- memcpy((p + 1), sdnaptr->naptr[naptr_count].flags, sdnaptr->naptr[naptr_count].flagslen);
- p += (sdnaptr->naptr[naptr_count].flagslen + 1);
- outlen += (1 + sdnaptr->naptr[naptr_count].flagslen);
+ *p = ((struct naptr *)rrp->rdata)->flagslen;
+ memcpy((p + 1), ((struct naptr *)rrp->rdata)->flags, ((struct naptr *)rrp->rdata)->flagslen);
+ p += (((struct naptr *)rrp->rdata)->flagslen + 1);
+ outlen += (1 + ((struct naptr *)rrp->rdata)->flagslen);
/* services */
- *p = sdnaptr->naptr[naptr_count].serviceslen;
- memcpy((p + 1), sdnaptr->naptr[naptr_count].services, sdnaptr->naptr[naptr_count].serviceslen);
- p += (sdnaptr->naptr[naptr_count].serviceslen + 1);
- outlen += (1 + sdnaptr->naptr[naptr_count].serviceslen);
+ *p = ((struct naptr *)rrp->rdata)->serviceslen;
+ memcpy((p + 1), ((struct naptr *)rrp->rdata)->services, ((struct naptr *)rrp->rdata)->serviceslen);
+ p += (((struct naptr *)rrp->rdata)->serviceslen + 1);
+ outlen += (1 + ((struct naptr *)rrp->rdata)->serviceslen);
/* regexp */
- *p = sdnaptr->naptr[naptr_count].regexplen;
- memcpy((p + 1), sdnaptr->naptr[naptr_count].regexp, sdnaptr->naptr[naptr_count].regexplen);
- p += (sdnaptr->naptr[naptr_count].regexplen + 1);
- outlen += (1 + sdnaptr->naptr[naptr_count].regexplen);
+ *p = ((struct naptr *)rrp->rdata)->regexplen;
+ memcpy((p + 1), ((struct naptr *)rrp->rdata)->regexp, ((struct naptr *)rrp->rdata)->regexplen);
+ p += (((struct naptr *)rrp->rdata)->regexplen + 1);
+ outlen += (1 + ((struct naptr *)rrp->rdata)->regexplen);
/* replacement */
- memcpy((char *)p, (char *)sdnaptr->naptr[naptr_count].replacement, sdnaptr->naptr[naptr_count].replacementlen);
+ memcpy((char *)p, (char *)((struct naptr *)rrp->rdata)->replacement, ((struct naptr *)rrp->rdata)->replacementlen);
- name = sdnaptr->naptr[naptr_count].replacement;
- namelen = sdnaptr->naptr[naptr_count].replacementlen;
+ name = ((struct naptr *)rrp->rdata)->replacement;
+ namelen = ((struct naptr *)rrp->rdata)->replacementlen;
- outlen += (12 + 4 + sdnaptr->naptr[naptr_count].replacementlen);
+ outlen += (12 + 4 + ((struct naptr *)rrp->rdata)->replacementlen);
/* compress the label if possible */
if ((tmplen = compress_label((u_char*)reply, outlen, namelen)) > 0) {
@@ -3638,7 +3493,7 @@ reply_naptr(struct sreply *sreply, ddDB *db)
answer->rdlength = htons(outlen - (savelen + 12));
/* can we afford to write another header? if no truncate */
- if (sdnaptr->naptr_count > naptr_count && (outlen + 12 + 4 + sdnaptr->naptr[naptr_count + 1].replacementlen + sdnaptr->naptr[naptr_count + 1].flagslen + 1 + sdnaptr->naptr[naptr_count + 1].serviceslen + 1 + sdnaptr->naptr[naptr_count + 1].regexplen + 1) > replysize) {
+ if ((outlen + 12 + 4 + ((struct naptr *)rrp->rdata)->replacementlen + ((struct naptr *)rrp->rdata)->flagslen + 1 + ((struct naptr *)rrp->rdata)->serviceslen + 1 + ((struct naptr *)rrp->rdata)->regexplen + 1) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -3651,14 +3506,17 @@ reply_naptr(struct sreply *sreply, ddDB *db)
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (++naptr_count < RECORD_COUNT && --sdnaptr->naptr_count);
+ naptr_count++;
+ }
+ odh->answer = htons(naptr_count);
+
/* RRSIG reply_naptr*/
if (dnssec && q->dnssecok) {
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_NAPTR, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_NAPTR, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -3750,15 +3608,16 @@ reply_srv(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain_srv *sdsrv = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
int tmplen;
u_int16_t rollback;
- if ((sdsrv = find_substruct(sd, INTERNAL_TYPE_SRV)) == NULL)
+ if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) == NULL)
return -1;
if (istcp) {
@@ -3783,11 +3642,7 @@ reply_srv(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
-
- if (sreply->sr == NULL) {
- SET_DNS_AUTHORITATIVE(odh);
- } else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -3796,7 +3651,7 @@ reply_srv(struct sreply *sreply, ddDB *db)
HTONS(odh->query);
odh->question = htons(1);
- odh->answer = htons(sdsrv->srv_count);
+ odh->answer = htons(0);
odh->nsrr = 0;
odh->additional = 0;
@@ -3805,31 +3660,28 @@ reply_srv(struct sreply *sreply, ddDB *db)
q->hdr->namelen + 4);
srv_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
answer->name[0] = 0xc0;
answer->name[1] = 0x0c;
answer->type = q->hdr->qtype;
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SRV] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SRV]);
+ answer->ttl = htonl(((struct srv *)rrp->rdata)->ttl);
- answer->rdlength = htons((3 * sizeof(u_int16_t)) + sdsrv->srv[srv_count].targetlen);
+ answer->rdlength = htons((3 * sizeof(u_int16_t)) + ((struct srv *)rrp->rdata)->targetlen);
- answer->srv_priority = htons(sdsrv->srv[srv_count].priority);
- answer->srv_weight = htons(sdsrv->srv[srv_count].weight);
- answer->srv_port = htons(sdsrv->srv[srv_count].port);
+ answer->srv_priority = htons(((struct srv *)rrp->rdata)->priority);
+ answer->srv_weight = htons(((struct srv *)rrp->rdata)->weight);
+ answer->srv_port = htons(((struct srv *)rrp->rdata)->port);
- memcpy((char *)&answer->target, (char *)sdsrv->srv[srv_count].target, sdsrv->srv[srv_count].targetlen);
+ memcpy((char *)&answer->target, (char *)((struct srv *)rrp->rdata)->target, ((struct srv *)rrp->rdata)->targetlen);
- name = sdsrv->srv[srv_count].target;
- namelen = sdsrv->srv[srv_count].targetlen;
+ name = ((struct srv *)rrp->rdata)->target;
+ namelen = ((struct srv *)rrp->rdata)->targetlen;
- outlen += (12 + 6 + sdsrv->srv[srv_count].targetlen);
+ outlen += (12 + 6 + ((struct srv *)rrp->rdata)->targetlen);
/* can we afford to write another header? if no truncate */
- if (sdsrv->srv_count > 1 && (outlen + 12 + 6 + sdsrv->srv[srv_count].targetlen) > replysize) {
+ if ((outlen + 12 + 6 + ((struct srv *)rrp->rdata)->targetlen) > replysize) {
NTOHS(odh->query);
SET_DNS_TRUNCATION(odh);
HTONS(odh->query);
@@ -3842,12 +3694,15 @@ reply_srv(struct sreply *sreply, ddDB *db)
/* set new offset for answer */
answer = (struct answer *)&reply[outlen];
- } while (++srv_count < RECORD_COUNT && --sdsrv->srv_count);
+ srv_count++;
+ }
+ odh->answer = htons(srv_count);
+
if (dnssec && q->dnssecok) {
int origlen = outlen;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_SRV, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, DNS_TYPE_SRV, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -3999,17 +3854,6 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
char rdata;
} __attribute__((packed));
- struct soa {
- char *nsserver;
- char *responsible_person;
- u_int32_t serial;
- u_int32_t refresh;
- u_int32_t retry;
- u_int32_t expire;
- u_int32_t minttl;
- };
-
-
struct answer *answer;
int so = sreply->so;
@@ -4018,9 +3862,10 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain *sd0 = NULL;
- struct domain_soa *sdsoa = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rbtree *rbt0 = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
@@ -4052,15 +3897,12 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
* no SOA, use the old code
*/
- if ((sd->flags & DOMAIN_HAVE_SOA) != DOMAIN_HAVE_SOA) {
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) == NULL) {
memcpy(reply, buf, len);
memset((char *)&odh->query, 0, sizeof(u_int16_t));
SET_DNS_REPLY(odh);
- if (sreply->sr != NULL) {
- SET_DNS_RECURSION_AVAIL(odh);
- }
SET_DNS_RCODE_NAMEERR(odh);
if (q->rd) {
@@ -4094,7 +3936,8 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
return (retlen);
}
- if ((sdsoa = find_substruct(sd, INTERNAL_TYPE_SOA)) == NULL)
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
return -1;
/* copy question to reply */
@@ -4106,10 +3949,7 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr != NULL)
- SET_DNS_RECURSION_AVAIL(odh);
- else
- SET_DNS_AUTHORITATIVE(odh);
+ SET_DNS_AUTHORITATIVE(odh);
SET_DNS_RCODE_NAMEERR(odh);
@@ -4124,25 +3964,22 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
odh->nsrr = htons(1);
odh->additional = 0;
- memcpy(&reply[outlen], sd->zone, sd->zonelen);
- outlen += sd->zonelen;
+ memcpy(&reply[outlen], rbt->zone, rbt->zonelen);
+ outlen += rbt->zonelen;
answer = (struct answer *)(&reply[0] + sizeof(struct dns_header) +
- q->hdr->namelen + 4 + sd->zonelen);
+ q->hdr->namelen + 4 + rbt->zonelen);
answer->type = htons(DNS_TYPE_SOA);
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA]);
+ answer->ttl = htonl(((struct soa *)rrp->rdata)->ttl);
outlen += 10; /* sizeof(struct answer) up to rdata length */
p = (char *)&answer->rdata;
- label = &sdsoa->soa.nsserver[0];
- labellen = sdsoa->soa.nsserver_len;
+ label = ((struct soa *)rrp->rdata)->nsserver;
+ labellen = ((struct soa *)rrp->rdata)->nsserver_len;
plabel = label;
@@ -4165,8 +4002,8 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
outlen = tmplen;
}
- label = sdsoa->soa.responsible_person;
- labellen = sdsoa->soa.rp_len;
+ label = ((struct soa *)rrp->rdata)->responsible_person;
+ labellen = ((struct soa *)rrp->rdata)->rp_len;
plabel = label;
for (i = outlen; i < replysize; i++) {
@@ -4190,41 +4027,41 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
/* XXX */
- if ((outlen + sizeof(sdsoa->soa.serial)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
/* XXX server error reply? */
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.serial);
- outlen += sizeof(sdsoa->soa.serial);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->serial);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.refresh)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.refresh);
- outlen += sizeof(sdsoa->soa.refresh);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->refresh);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.retry)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.retry);
- outlen += sizeof(sdsoa->soa.retry);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->retry);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.expire)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.expire);
- outlen += sizeof(sdsoa->soa.expire);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->expire);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.minttl)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.minttl);
- outlen += sizeof(sdsoa->soa.minttl);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->minttl);
+ outlen += sizeof(u_int32_t);
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
@@ -4233,7 +4070,7 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(sd->zone, sd->zonelen, INTERNAL_TYPE_SOA, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(rbt->zone, rbt->zonelen, DNS_TYPE_SOA, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -4252,16 +4089,16 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
odh->nsrr = htons(2);
origlen = outlen;
- if (sd->flags & DOMAIN_HAVE_NSEC3PARAM) {
- sd0 = find_nsec3_cover_next_closer(q->hdr->name, q->hdr->namelen, sd, db);
- if (sd0 == NULL)
+ if (find_rr(rbt, DNS_TYPE_NSEC3PARAM)) {
+ rbt0 = find_nsec3_cover_next_closer(q->hdr->name, q->hdr->namelen, rbt, db);
+ if (rbt0 == NULL)
goto out;
- memcpy(&uniq[rruniq].name, sd0->zone, sd0->zonelen);
- uniq[rruniq++].len = sd0->zonelen;
+ memcpy(&uniq[rruniq].name, rbt0->zone, rbt0->zonelen);
+ uniq[rruniq++].len = rbt0->zonelen;
- tmplen = additional_nsec3(sd0->zone, sd0->zonelen, INTERNAL_TYPE_NSEC3, sd0, reply, replysize, outlen);
- free (sd0);
+ tmplen = additional_nsec3(rbt0->zone, rbt0->zonelen, DNS_TYPE_NSEC3, rbt0, reply, replysize, outlen);
+ free (rbt0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -4281,19 +4118,19 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
origlen = outlen;
- sd0 = find_nsec3_match_closest(q->hdr->name, q->hdr->namelen, sd, db);
- if (sd0 == NULL)
+ rbt0 = find_nsec3_match_closest(q->hdr->name, q->hdr->namelen, rbt, db);
+ if (rbt0 == NULL)
goto out;
- memcpy(&uniq[rruniq].name, sd0->zone, sd0->zonelen);
- uniq[rruniq++].len = sd0->zonelen;
+ memcpy(&uniq[rruniq].name, rbt0->zone, rbt0->zonelen);
+ uniq[rruniq++].len = rbt0->zonelen;
if (memcmp(uniq[0].name, uniq[1].name, uniq[1].len) != 0) {
- tmplen = additional_nsec3(sd0->zone, sd0->zonelen, INTERNAL_TYPE_NSEC3, sd0, reply, replysize, outlen);
+ tmplen = additional_nsec3(rbt0->zone, rbt0->zonelen, DNS_TYPE_NSEC3, rbt0, reply, replysize, outlen);
addrec = 1;
}
- free (sd0);
+ free (rbt0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -4317,19 +4154,19 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
addrec = 0;
origlen = outlen;
- sd0 = find_nsec3_wildcard_closest(q->hdr->name, q->hdr->namelen, sd, db);
- if (sd0 == NULL)
+ rbt0 = find_nsec3_wildcard_closest(q->hdr->name, q->hdr->namelen, rbt, db);
+ if (rbt0 == NULL)
goto out;
- memcpy(&uniq[rruniq].name, sd0->zone, sd0->zonelen);
- uniq[rruniq++].len = sd0->zonelen;
+ memcpy(&uniq[rruniq].name, rbt0->zone, rbt0->zonelen);
+ uniq[rruniq++].len = rbt0->zonelen;
if (memcmp(uniq[0].name, uniq[2].name, uniq[2].len) != 0&&
memcmp(uniq[1].name, uniq[2].name, uniq[2].len) != 0) {
- tmplen = additional_nsec3(sd0->zone, sd0->zonelen, INTERNAL_TYPE_NSEC3, sd0, reply, replysize, outlen);
+ tmplen = additional_nsec3(rbt0->zone, rbt0->zonelen, DNS_TYPE_NSEC3, rbt0, reply, replysize, outlen);
addrec = 1;
}
- free (sd0);
+ free (rbt0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -4351,7 +4188,7 @@ reply_nxdomain(struct sreply *sreply, ddDB *db)
}
addrec = 0;
- } /* if (sd->flags & DOMAIN_HAVE_NSEC3PARAM) .. */
+ } /* if (find_rr(... DNS_TYPE_NSEC3PARAM) */
}
out:
@@ -4553,17 +4390,6 @@ reply_noerror(struct sreply *sreply, ddDB *db)
char rdata;
} __attribute__((packed));
- struct soa {
- char *nsserver;
- char *responsible_person;
- u_int32_t serial;
- u_int32_t refresh;
- u_int32_t retry;
- u_int32_t expire;
- u_int32_t minttl;
- };
-
-
struct answer *answer;
int so = sreply->so;
@@ -4572,9 +4398,10 @@ reply_noerror(struct sreply *sreply, ddDB *db)
struct question *q = sreply->q;
struct sockaddr *sa = sreply->sa;
int salen = sreply->salen;
- struct domain *sd = sreply->sd1;
- struct domain *sd0 = NULL;
- struct domain_soa *sdsoa = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+ struct rbtree *rbt0 = NULL;
+ struct rr *rrp = NULL;
int istcp = sreply->istcp;
int replysize = 512;
int retlen = -1;
@@ -4602,12 +4429,12 @@ reply_noerror(struct sreply *sreply, ddDB *db)
}
+
/*
* no SOA, use the old code
*/
- if ((sd->flags & DOMAIN_HAVE_SOA) != DOMAIN_HAVE_SOA) {
-
+ if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) == NULL) {
memcpy(reply, buf, len);
memset((char *)&odh->query, 0, sizeof(u_int16_t));
@@ -4645,9 +4472,10 @@ reply_noerror(struct sreply *sreply, ddDB *db)
return (retlen);
}
- if ((sdsoa = find_substruct(sd, INTERNAL_TYPE_SOA)) == NULL)
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
return -1;
-
+
/* copy question to reply */
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
/* blank query */
@@ -4657,10 +4485,7 @@ reply_noerror(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr != NULL)
- SET_DNS_RECURSION_AVAIL(odh);
- else
- SET_DNS_AUTHORITATIVE(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -4673,26 +4498,23 @@ reply_noerror(struct sreply *sreply, ddDB *db)
odh->nsrr = htons(1);
odh->additional = 0;
- memcpy(&reply[outlen], sd->zone, sd->zonelen);
- outlen += sd->zonelen;
+ memcpy(&reply[outlen], rbt->zone, rbt->zonelen);
+ outlen += rbt->zonelen;
answer = (struct answer *)(&reply[0] + sizeof(struct dns_header) +
- q->hdr->namelen + 4 + sd->zonelen);
+ q->hdr->namelen + 4 + rbt->zonelen);
answer->type = htons(DNS_TYPE_SOA);
answer->class = q->hdr->qclass;
- if (sreply->sr != NULL)
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA] - (time(NULL) - sd->created));
- else
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA]);
+ answer->ttl = htonl(((struct soa *)rrp->rdata)->ttl);
outlen += 10; /* up to rdata length */
p = (char *)&answer->rdata;
- label = sdsoa->soa.nsserver;
- labellen = sdsoa->soa.nsserver_len;
+ label = ((struct soa *)rrp->rdata)->nsserver;
+ labellen = ((struct soa *)rrp->rdata)->nsserver_len;
plabel = label;
@@ -4715,8 +4537,8 @@ reply_noerror(struct sreply *sreply, ddDB *db)
outlen = tmplen;
}
- label = &sdsoa->soa.responsible_person[0];
- labellen = sdsoa->soa.rp_len;
+ label = ((struct soa *)rrp->rdata)->responsible_person;
+ labellen = ((struct soa *)rrp->rdata)->rp_len;
plabel = label;
for (i = outlen; i < replysize; i++) {
@@ -4738,43 +4560,43 @@ reply_noerror(struct sreply *sreply, ddDB *db)
outlen = tmplen;
}
-
+
/* XXX */
- if ((outlen + sizeof(sdsoa->soa.serial)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
/* XXX server error reply? */
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.serial);
- outlen += sizeof(sdsoa->soa.serial);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->serial);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.refresh)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.refresh);
- outlen += sizeof(sdsoa->soa.refresh);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->refresh);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.retry)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.retry);
- outlen += sizeof(sdsoa->soa.retry);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->retry);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.expire)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.expire);
- outlen += sizeof(sdsoa->soa.expire);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->expire);
+ outlen += sizeof(u_int32_t);
- if ((outlen + sizeof(sdsoa->soa.minttl)) > replysize) {
+ if ((outlen + sizeof(u_int32_t)) > replysize) {
return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
- *soa_val = htonl(sdsoa->soa.minttl);
- outlen += sizeof(sdsoa->soa.minttl);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->minttl);
+ outlen += sizeof(u_int32_t);
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
/* RRSIG reply_nxdomain */
@@ -4782,7 +4604,7 @@ reply_noerror(struct sreply *sreply, ddDB *db)
int tmplen = 0;
int origlen = outlen;
- tmplen = additional_rrsig(sd->zone, sd->zonelen, INTERNAL_TYPE_SOA, sd, reply, replysize, outlen, 0);
+ tmplen = additional_rrsig(rbt->zone, rbt->zonelen, DNS_TYPE_SOA, rbt, reply, replysize, outlen, 0);
if (tmplen == 0) {
NTOHS(odh->query);
@@ -4801,20 +4623,20 @@ reply_noerror(struct sreply *sreply, ddDB *db)
odh->nsrr = htons(2);
origlen = outlen;
- if (sd->flags & DOMAIN_HAVE_NSEC) {
- sd0 = Lookup_zone(db, q->hdr->name, q->hdr->namelen, htons(DNS_TYPE_NSEC), 0);
- tmplen = additional_nsec(q->hdr->name, q->hdr->namelen, INTERNAL_TYPE_NSEC, sd0, reply, replysize, outlen);
- free(sd0);
- } else if (sd->flags & DOMAIN_HAVE_NSEC3PARAM) {
- sd0 = find_nsec3_match_qname(q->hdr->name, q->hdr->namelen, sd, db);
- if (sd0 == NULL)
+ if (find_rr(rbt, DNS_TYPE_NSEC)) {
+ rbt0 = Lookup_zone(db, q->hdr->name, q->hdr->namelen, htons(DNS_TYPE_NSEC), 0);
+ tmplen = additional_nsec(q->hdr->name, q->hdr->namelen, DNS_TYPE_NSEC, rbt0, reply, replysize, outlen);
+ free(rbt0);
+ } else if (find_rr(rbt, DNS_TYPE_NSEC3PARAM)) {
+ rbt0 = find_nsec3_match_qname(q->hdr->name, q->hdr->namelen, rbt, db);
+ if (rbt0 == NULL)
goto out;
- memcpy(&uniq[rruniq].name, sd0->zone, sd0->zonelen);
- uniq[rruniq++].len = sd0->zonelen;
+ memcpy(&uniq[rruniq].name, rbt0->zone, rbt0->zonelen);
+ uniq[rruniq++].len = rbt0->zonelen;
- tmplen = additional_nsec3(sd0->zone, sd0->zonelen, INTERNAL_TYPE_NSEC3, sd0, reply, replysize, outlen);
- free (sd0);
+ tmplen = additional_nsec3(rbt0->zone, rbt0->zonelen, DNS_TYPE_NSEC3, rbt0, reply, replysize, outlen);
+ free (rbt0);
}
if (tmplen == 0) {
@@ -4870,44 +4692,14 @@ out:
return (retlen);
}
-void
-update_db(ddDB *db, struct domain *sd)
-{
- int ret;
- int i = 0;
- ddDBT key, data;
-
-
- do {
- if (++i == 32) {
- dolog(LOG_ERR, "could not update zone for 32 tries, giving up entire database, quit");
- slave_shutdown();
- exit(1);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- key.data = sd->zone;
- key.size = sd->zonelen;
-
- data.data = (char *)sd;
- data.size = sd->len;
-
- ret = db->put(db, &key, &data);
- } while (ret != 0);
-
- return;
-}
-
/*
* Lookup_zone: wrapper for lookup_zone() et al.
*/
-struct domain *
+struct rbtree *
Lookup_zone(ddDB *db, char *name, u_int16_t namelen, u_int16_t type, int wildcard)
{
- struct domain *sd;
+ struct rbtree *rbt;
struct question *fakequestion;
char fakereplystring[DNS_MAXNAME + 1];
int mytype;
@@ -4919,25 +4711,16 @@ Lookup_zone(ddDB *db, char *name, u_int16_t namelen, u
return (NULL);
}
-#if 0
- sd = calloc(sizeof(struct domain), 1);
- if (sd == NULL) {
- dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
- free_question(fakequestion);
- return (NULL);
- }
-#endif
+ rbt = lookup_zone(db, fakequestion, &mytype, &lzerrno, (char *)&fakereplystring);
- sd = lookup_zone(db, fakequestion, &mytype, &lzerrno, (char *)&fakereplystring);
-
- if (sd == NULL) {
+ if (rbt == NULL) {
free_question(fakequestion);
return (NULL);
}
free_question(fakequestion);
- return (sd);
+ return (rbt);
}
int
@@ -4983,10 +4766,7 @@ reply_any(struct sreply *sreply, ddDB *db)
rollback = outlen;
SET_DNS_REPLY(odh);
- if (sreply->sr == NULL)
- SET_DNS_AUTHORITATIVE(odh);
- else
- SET_DNS_RECURSION_AVAIL(odh);
+ SET_DNS_AUTHORITATIVE(odh);
if (q->rd) {
SET_DNS_RECURSION(odh);
@@ -5057,8 +4837,7 @@ create_anyreply(struct sreply *sreply, char *reply, in
int tlsa_count, typelen;
int ds_count, dnskey_count;
int naptr_count, rrsig_count;
- int internal_type;
- int tmplen, pos, mod;
+ int tmplen;
struct answer {
u_int16_t type; /* 0 */
u_int16_t class; /* 2 */
@@ -5067,25 +4846,10 @@ create_anyreply(struct sreply *sreply, char *reply, in
char rdata[0]; /* 10 */
} __packed;
struct answer *answer;
- struct domain *sd = sreply->sd1;
- struct domain_soa *sdsoa = NULL;
- struct domain_txt *sdtxt = NULL;
- struct domain_cname *sdcname = NULL;
- struct domain_a *sda = NULL;
- struct domain_aaaa *sdaaaa = NULL;
- struct domain_srv *sdsrv = NULL;
- struct domain_naptr *sdnaptr = NULL;
- struct domain_ptr *sdptr = NULL;
- struct domain_ns *sdns = NULL;
- struct domain_mx *sdmx = NULL;
- struct domain_sshfp *sdsshfp = NULL;
- struct domain_tlsa *sdtlsa = NULL;
- struct domain_nsec *sdnsec = NULL;
- struct domain_rrsig *sdrrsig = NULL;
- struct domain_ds *sdds = NULL;
- struct domain_dnskey *sddnskey = NULL;
- struct domain_nsec3param *sdnsec3param = NULL;
- struct domain_nsec3 *sdnsec3 = NULL;
+ struct rbtree *rbt = sreply->rbt1;
+ struct rrset *rrset = NULL;
+
+ struct rr *rrp = NULL;
struct question *q = sreply->q;
struct dns_header *odh = (struct dns_header *)reply;
int labellen;
@@ -5104,14 +4868,15 @@ create_anyreply(struct sreply *sreply, char *reply, in
char *name, *p;
int i;
- if ((sd->flags & DOMAIN_HAVE_SOA) && soa) {
- if ((sdsoa = (struct domain_soa *)find_substruct(sd, INTERNAL_TYPE_SOA)) == NULL)
- return 0;
-
+ if (soa && (rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
NTOHS(odh->answer);
odh->answer++;
HTONS(odh->answer);
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
if ((offset + q->hdr->namelen) > rlen) {
goto truncate;
}
@@ -5127,13 +4892,14 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_SOA);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SOA]);
+ answer->ttl = htonl(((struct soa *)rrp->rdata)->ttl);
offset += 10; /* up to rdata length */
- label = sdsoa->soa.nsserver;
- labellen = sdsoa->soa.nsserver_len;
+ label = ((struct soa *)rrp->rdata)->nsserver;
+ labellen = ((struct soa *)rrp->rdata)->nsserver_len;
+
plabel = label;
/* copy label to reply */
@@ -5155,8 +4921,8 @@ create_anyreply(struct sreply *sreply, char *reply, in
offset = tmplen;
}
- label = sdsoa->soa.responsible_person;
- labellen = sdsoa->soa.rp_len;
+ label = ((struct soa *)rrp->rdata)->responsible_person;
+ labellen = ((struct soa *)rrp->rdata)->rp_len;
plabel = label;
for (i = offset; i < rlen; i++) {
@@ -5178,93 +4944,70 @@ create_anyreply(struct sreply *sreply, char *reply, in
offset = tmplen;
}
- if ((offset + sizeof(sdsoa->soa.serial)) > rlen) {
+ if ((offset + sizeof(u_int32_t)) > rlen) {
goto truncate;
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.serial);
- offset += sizeof(sdsoa->soa.serial);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->serial);
+ offset += sizeof(u_int32_t);
- if ((offset + sizeof(sdsoa->soa.refresh)) > rlen) {
+ if ((offset + sizeof(u_int32_t)) > rlen) {
goto truncate;
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.refresh);
- offset += sizeof(sdsoa->soa.refresh);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->refresh);
+ offset += sizeof(u_int32_t);
- if ((offset + sizeof(sdsoa->soa.retry)) > rlen) {
+ if ((offset + sizeof(u_int32_t)) > rlen) {
goto truncate;
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.retry);
- offset += sizeof(sdsoa->soa.retry);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->retry);
+ offset += sizeof(u_int32_t);
- if ((offset + sizeof(sdsoa->soa.expire)) > rlen) {
+ if ((offset + sizeof(u_int32_t)) > rlen) {
goto truncate;
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.expire);
- offset += sizeof(sdsoa->soa.expire);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->expire);
+ offset += sizeof(u_int32_t);
- if ((offset + sizeof(sdsoa->soa.minttl)) > rlen) {
+ if ((offset + sizeof(u_int32_t)) > rlen) {
goto truncate;
}
soa_val = (u_int32_t *)&reply[offset];
- *soa_val = htonl(sdsoa->soa.minttl);
- offset += sizeof(sdsoa->soa.minttl);
+ *soa_val = htonl(((struct soa *)rrp->rdata)->minttl);
+ offset += sizeof(u_int32_t);
answer->rdlength = htons(&reply[offset] - answer->rdata);
}
- if (sd->flags & DOMAIN_HAVE_RRSIG) {
- if ((sdrrsig = (struct domain_rrsig *)find_substruct(sd, INTERNAL_TYPE_RRSIG)) == NULL)
- return 0;
-
+ if ((rrset = find_rr(rbt, DNS_TYPE_RRSIG)) != NULL) {
+
rrsig_count = 0;
- for (internal_type = 0; internal_type < INTERNAL_TYPE_MAX; internal_type++) {
- int checktype;
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ rrsig_count++;
+ if (((struct rrsig *)rrp->rdata)->type_covered == DNS_TYPE_DNSKEY) {
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen,
+ DNS_TYPE_DNSKEY, rbt, reply, rlen, offset, i);
+
+ if (tmplen == 0)
+ goto truncate;
- checktype = lookup_type(internal_type);
- if (checktype == -1)
- continue;
-
- if (sd->flags & checktype) {
- if (internal_type == INTERNAL_TYPE_DNSKEY) {
- for (i = 0; i < sdrrsig->rrsig_dnskey_count; i++) {
- rrsig_count++;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen,
- internal_type, sd, reply, rlen, offset, i);
-
- if (tmplen == 0)
- goto truncate;
-
- offset = tmplen;
- }
- } else if (internal_type == INTERNAL_TYPE_DS) {
- rrsig_count++;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen,
- internal_type, sd, reply, rlen, offset, 0);
-
- if (tmplen == 0)
- goto truncate;
-
- offset = tmplen;
- } else {
-
- rrsig_count++;
- tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen,
- internal_type, sd, reply, rlen, offset, 0);
+ offset = tmplen;
+ } else {
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen,
+ ((struct rrsig *)rrp->rdata)->type_covered, rbt, reply, rlen, offset, 0);
- if (tmplen == 0)
- goto truncate;
+ if (tmplen == 0)
+ goto truncate;
- offset = tmplen;
- }
+ offset = tmplen;
}
}
@@ -5273,12 +5016,9 @@ create_anyreply(struct sreply *sreply, char *reply, in
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_DNSKEY) {
- if ((sddnskey = (struct domain_dnskey *)find_substruct(sd, INTERNAL_TYPE_DNSKEY)) == NULL)
- return 0;
-
+ if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
dnskey_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if (offset + q->hdr->namelen > rlen)
goto truncate;
@@ -5293,7 +5033,7 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_DNSKEY);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_DNSKEY]);
+ answer->ttl = htonl(((struct dnskey *)rrp->rdata)->ttl);
answer->rdlength = htons(namelen);
@@ -5303,25 +5043,25 @@ create_anyreply(struct sreply *sreply, char *reply, in
goto truncate;
dnskey_flags = (u_int16_t *)&reply[offset];
- *dnskey_flags = htons(sddnskey->dnskey[dnskey_count].flags);
+ *dnskey_flags = htons(((struct dnskey *)rrp->rdata)->flags);
- offset += sizeof(*dnskey_flags);
+ offset += sizeof(u_int16_t);
dnskey_protocol = (u_int8_t *)&reply[offset];
- *dnskey_protocol = sddnskey->dnskey[dnskey_count].protocol;
+ *dnskey_protocol = ((struct dnskey *)rrp->rdata)->protocol;
- offset += sizeof(*dnskey_protocol);
+ offset++;
dnskey_alg = (u_int8_t *)&reply[offset];
- *dnskey_alg = sddnskey->dnskey[dnskey_count].algorithm;
+ *dnskey_alg = ((struct dnskey *)rrp->rdata)->algorithm;
- offset += sizeof(*dnskey_alg);
+ offset++;
memcpy(&reply[offset],
- sddnskey->dnskey[dnskey_count].public_key,
- sddnskey->dnskey[dnskey_count].publickey_len);
+ ((struct dnskey *)rrp->rdata)->public_key,
+ ((struct dnskey *)rrp->rdata)->publickey_len);
- offset += sddnskey->dnskey[dnskey_count].publickey_len;
+ offset += ((struct dnskey *)rrp->rdata)->publickey_len;
answer->rdlength = htons(&reply[offset] - answer->rdata);
@@ -5330,16 +5070,12 @@ create_anyreply(struct sreply *sreply, char *reply, in
NTOHS(odh->answer);
odh->answer += 1;
HTONS(odh->answer);
-
- } while (dnskey_count < RECORD_COUNT && --sddnskey->dnskey_count);
+ }
}
- if (sd->flags & DOMAIN_HAVE_DS) {
- if ((sdds = (struct domain_ds *)find_substruct(sd, INTERNAL_TYPE_DS)) == NULL)
- return 0;
-
+ if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
ds_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if (offset + q->hdr->namelen > rlen)
goto truncate;
@@ -5354,7 +5090,7 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_DS);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_DS]);
+ answer->ttl = htonl(((struct ds *)rrp->rdata)->ttl);
answer->rdlength = htons(namelen);
@@ -5364,24 +5100,23 @@ create_anyreply(struct sreply *sreply, char *reply, in
goto truncate;
ds_keytag = (u_int16_t *)&reply[offset];
- *ds_keytag = htons(sdds->ds[ds_count].key_tag);
+ *ds_keytag = htons(((struct ds *)rrp->rdata)->key_tag);
- offset += sizeof(*ds_keytag);
+ offset += sizeof(u_int16_t);
ds_alg = (u_int8_t *)&reply[offset];
- *ds_alg = sdds->ds[ds_count].algorithm;
+ *ds_alg = ((struct ds *)rrp->rdata)->algorithm;
- offset += sizeof(*ds_alg);
+ offset++;
ds_digesttype = (u_int8_t *)&reply[offset];
- *ds_digesttype = sdds->ds[ds_count].digest_type;
+ *ds_digesttype = ((struct ds *)rrp->rdata)->digest_type;
- offset += sizeof(*ds_digesttype);
+ offset++;
- memcpy(&reply[offset], sdds->ds[ds_count].digest,
- sdds->ds[ds_count].digestlen);
+ memcpy(&reply[offset], ((struct ds *)rrp->rdata)->digest,((struct ds *)rrp->rdata)->digestlen);
- offset += sdds->ds[ds_count].digestlen;
+ offset += ((struct ds *)rrp->rdata)->digestlen;
answer->rdlength = htons(&reply[offset] - answer->rdata);
@@ -5391,209 +5126,200 @@ create_anyreply(struct sreply *sreply, char *reply, in
odh->answer += 1;
HTONS(odh->answer);
- } while (ds_count < RECORD_COUNT && --sdds->ds_count);
-
-
+ }
}
- if (sd->flags & DOMAIN_HAVE_NSEC3) {
- if ((sdnsec3 = (struct domain_nsec3 *)find_substruct(sd, INTERNAL_TYPE_NSEC3)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
- do {
- if (offset + q->hdr->namelen > rlen)
- goto truncate;
+ if (offset + q->hdr->namelen > rlen)
+ goto truncate;
- memcpy(&reply[offset], q->hdr->name, q->hdr->namelen);
- offset += q->hdr->namelen;
+ memcpy(&reply[offset], q->hdr->name, q->hdr->namelen);
+ offset += q->hdr->namelen;
- if ((tmplen = compress_label((u_char*)reply, offset, q->hdr->namelen)) > 0) {
- offset = tmplen;
- }
+ if ((tmplen = compress_label((u_char*)reply, offset, q->hdr->namelen)) > 0) {
+ offset = tmplen;
+ }
- answer = (struct answer *)&reply[offset];
+ answer = (struct answer *)&reply[offset];
- answer->type = htons(DNS_TYPE_NSEC3);
- answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC3]);
+ answer->type = htons(DNS_TYPE_NSEC3);
+ answer->class = htons(DNS_CLASS_IN);
+ answer->ttl = htonl(((struct nsec3 *)rrp->rdata)->ttl);
- answer->rdlength = htons(namelen);
+ answer->rdlength = htons(namelen);
- offset += 10; /* struct answer */
+ offset += 10; /* struct answer */
- if (offset + sizeof(*nsec3_alg) + sizeof(*nsec3_flags)
- + sizeof(*nsec3_iterations)
- + sizeof(*nsec3_saltlen)
- + sdnsec3->nsec3.saltlen + sizeof(*nsec3_hashlen)
- + sdnsec3->nsec3.nextlen
- + sdnsec3->nsec3.bitmap_len > rlen)
- goto truncate;
+ if (offset + sizeof(*nsec3_alg) + sizeof(*nsec3_flags)
+ + sizeof(*nsec3_iterations)
+ + sizeof(*nsec3_saltlen)
+ + ((struct nsec3 *)rrp->rdata)->saltlen
+ + sizeof(*nsec3_hashlen)
+ + ((struct nsec3 *)rrp->rdata)->nextlen
+ + ((struct nsec3 *)rrp->rdata)->bitmap_len > rlen)
+ goto truncate;
- nsec3_alg = (u_int8_t *)&reply[offset];
- *nsec3_alg = sdnsec3->nsec3.algorithm;
+ nsec3_alg = (u_int8_t *)&reply[offset];
+ *nsec3_alg = ((struct nsec3 *)rrp->rdata)->algorithm;
- offset += sizeof(*nsec3_alg);
+ offset++;
- nsec3_flags = (u_int8_t *)&reply[offset];
- *nsec3_flags = sdnsec3->nsec3.flags;
+ nsec3_flags = (u_int8_t *)&reply[offset];
+ *nsec3_flags = ((struct nsec3 *)rrp->rdata)->flags;
- offset += sizeof(*nsec3_flags);
+ offset++;
- nsec3_iterations = (u_int16_t *)&reply[offset];
- *nsec3_iterations = htons(sdnsec3->nsec3.iterations);
- offset += sizeof(*nsec3_iterations);
+ nsec3_iterations = (u_int16_t *)&reply[offset];
+ *nsec3_iterations = htons(((struct nsec3 *)rrp->rdata)->iterations);
+ offset += sizeof(u_int16_t);
- nsec3_saltlen = (u_int8_t *)&reply[offset];
- *nsec3_saltlen = sdnsec3->nsec3.saltlen;
- offset += sizeof(*nsec3_saltlen);
+ nsec3_saltlen = (u_int8_t *)&reply[offset];
+ *nsec3_saltlen = ((struct nsec3 *)rrp->rdata)->saltlen;
+ offset++;
+
+ memcpy(&reply[offset], &((struct nsec3 *)rrp->rdata)->salt,
+ ((struct nsec3 *)rrp->rdata)->saltlen);
- memcpy(&reply[offset], &sdnsec3->nsec3.salt,
- sdnsec3->nsec3.saltlen);
-
- offset += sdnsec3->nsec3.saltlen;
+ offset += ((struct nsec3 *)rrp->rdata)->saltlen;
- nsec3_hashlen = (u_int8_t *)&reply[offset];
- *nsec3_hashlen = sdnsec3->nsec3.nextlen;
- offset += sizeof(*nsec3_hashlen);
+ nsec3_hashlen = (u_int8_t *)&reply[offset];
+ *nsec3_hashlen = ((struct nsec3 *)rrp->rdata)->nextlen;
+ offset++;
- memcpy(&reply[offset], &sdnsec3->nsec3.next,
- sdnsec3->nsec3.nextlen);
-
- offset += sdnsec3->nsec3.nextlen;
+ memcpy(&reply[offset], &((struct nsec3 *)rrp->rdata)->next,
+ ((struct nsec3 *)rrp->rdata)->nextlen);
+
+ offset += ((struct nsec3 *)rrp->rdata)->nextlen;
- memcpy(&reply[offset], &sdnsec3->nsec3.bitmap,
- sdnsec3->nsec3.bitmap_len);
+ memcpy(&reply[offset], &((struct nsec *)rrp->rdata)->bitmap,
+ ((struct nsec *)rrp->rdata)->bitmap_len);
- offset += sdnsec3->nsec3.bitmap_len;
+ offset += ((struct nsec *)rrp->rdata)->bitmap_len;
- answer->rdlength = htons(&reply[offset] - answer->rdata);
+ answer->rdlength = htons(&reply[offset] - answer->rdata);
- } while (0);
-
NTOHS(odh->answer);
odh->answer += 1;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_NSEC3PARAM) {
- if ((sdnsec3param = (struct domain_nsec3param *)find_substruct(sd, INTERNAL_TYPE_NSEC3PARAM)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
- do {
- if (offset + q->hdr->namelen > rlen)
- goto truncate;
+ if (offset + q->hdr->namelen > rlen)
+ goto truncate;
- memcpy(&reply[offset], q->hdr->name, q->hdr->namelen);
- offset += q->hdr->namelen;
+ memcpy(&reply[offset], q->hdr->name, q->hdr->namelen);
+ offset += q->hdr->namelen;
- if ((tmplen = compress_label((u_char*)reply, offset, q->hdr->namelen)) > 0) {
- offset = tmplen;
- }
+ if ((tmplen = compress_label((u_char*)reply, offset, q->hdr->namelen)) > 0) {
+ offset = tmplen;
+ }
- answer = (struct answer *)&reply[offset];
+ answer = (struct answer *)&reply[offset];
- answer->type = htons(DNS_TYPE_NSEC3PARAM);
- answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC3PARAM]);
+ answer->type = htons(DNS_TYPE_NSEC3PARAM);
+ answer->class = htons(DNS_CLASS_IN);
+ answer->ttl = htonl(((struct nsec3param *)rrp->rdata)->ttl);
- answer->rdlength = htons(namelen);
+ answer->rdlength = htons(namelen);
- offset += 10; /* struct answer */
+ offset += 10; /* struct answer */
- if (offset + sizeof(sdnsec3param->nsec3param.algorithm)
- + sizeof(sdnsec3param->nsec3param.flags)
- + sizeof(sdnsec3param->nsec3param.iterations)
- + sizeof(sdnsec3param->nsec3param.saltlen) > rlen)
- goto truncate;
+ if (offset + sizeof(((struct nsec3param *)rrp->rdata)->algorithm)
+ + sizeof(((struct nsec3param *)rrp->rdata)->flags)
+ + sizeof(((struct nsec3param *)rrp->rdata)->iterations)
+ + sizeof(((struct nsec3param *)rrp->rdata)->saltlen) > rlen)
+ goto truncate;
- nsec3param_alg = (u_int8_t *)&reply[offset];
- *nsec3param_alg = sdnsec3param->nsec3param.algorithm;
+ nsec3param_alg = (u_int8_t *)&reply[offset];
+ *nsec3param_alg = ((struct nsec3param *)rrp->rdata)->algorithm;
- offset += sizeof(*nsec3param_alg);
+ offset++;
- nsec3param_flags = (u_int8_t *)&reply[offset];
- *nsec3param_flags = sdnsec3param->nsec3param.flags;
+ nsec3param_flags = (u_int8_t *)&reply[offset];
+ *nsec3param_flags = ((struct nsec3param *)rrp->rdata)->flags;
- offset += sizeof(*nsec3param_flags);
+ offset++;
- nsec3param_iterations = (u_int16_t *)&reply[offset];
- *nsec3param_iterations = htons(sdnsec3param->nsec3param.iterations);
- offset += sizeof(*nsec3param_iterations);
+ nsec3param_iterations = (u_int16_t *)&reply[offset];
+ *nsec3param_iterations = htons(((struct nsec3param *)rrp->rdata)->iterations);
+ offset += sizeof(u_int16_t);
- nsec3param_saltlen = (u_int8_t *)&reply[offset];
- *nsec3param_saltlen = sdnsec3param->nsec3param.saltlen;
+ nsec3param_saltlen = (u_int8_t *)&reply[offset];
+ *nsec3param_saltlen = ((struct nsec3param *)rrp->rdata)->saltlen;
- offset += sizeof(*nsec3param_saltlen);
+ offset++;
+
+ memcpy(&reply[offset], &((struct nsec3param *)rrp->rdata)->salt,
+ ((struct nsec3param *)rrp->rdata)->saltlen);
- memcpy(&reply[offset], &sdnsec3param->nsec3param.salt,
- sdnsec3param->nsec3param.saltlen);
-
- offset += sdnsec3param->nsec3param.saltlen;
+ offset += ((struct nsec3param *)rrp->rdata)->saltlen;
- answer->rdlength = htons(&reply[offset] - answer->rdata);
+ answer->rdlength = htons(&reply[offset] - answer->rdata);
- } while (0);
NTOHS(odh->answer);
odh->answer += 1;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_NSEC) {
- if ((sdnsec = (struct domain_nsec *)find_substruct(sd, INTERNAL_TYPE_NSEC)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NSEC)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
- do {
- if (offset + q->hdr->namelen > rlen)
- goto truncate;
+ if (offset + q->hdr->namelen > rlen)
+ goto truncate;
- memcpy(&reply[offset], q->hdr->name, q->hdr->namelen);
- offset += q->hdr->namelen;
+ memcpy(&reply[offset], q->hdr->name, q->hdr->namelen);
+ offset += q->hdr->namelen;
- if ((tmplen = compress_label((u_char*)reply, offset, q->hdr->namelen)) > 0) {
- offset = tmplen;
- }
+ if ((tmplen = compress_label((u_char*)reply, offset, q->hdr->namelen)) > 0) {
+ offset = tmplen;
+ }
- answer = (struct answer *)&reply[offset];
+ answer = (struct answer *)&reply[offset];
- answer->type = htons(DNS_TYPE_NSEC);
- answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NSEC]);
+ answer->type = htons(DNS_TYPE_NSEC);
+ answer->class = htons(DNS_CLASS_IN);
+ answer->ttl = htonl(((struct nsec *)rrp->rdata)->ttl);
- answer->rdlength = htons(namelen);
+ answer->rdlength = htons(namelen);
- offset += 10; /* struct answer */
+ offset += 10; /* struct answer */
- if (offset + sdnsec->nsec.ndn_len > rlen)
- goto truncate;
+ if (offset + ((struct nsec *)rrp->rdata)->ndn_len > rlen)
+ goto truncate;
- memcpy((char *)&answer->rdata, (char *)sdnsec->nsec.next_domain_name, sdnsec->nsec.ndn_len);
+ memcpy((char *)&answer->rdata, (char *)((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
- offset += sdnsec->nsec.ndn_len;
+ offset += ((struct nsec *)rrp->rdata)->ndn_len;
- if (offset + sdnsec->nsec.bitmap_len > rlen)
- goto truncate;
-
- memcpy((char *)&reply[offset], sdnsec->nsec.bitmap, sdnsec->nsec.bitmap_len);
-
- offset += sdnsec->nsec.bitmap_len;
+ if (offset + ((struct nsec *)rrp->rdata)->bitmap_len > rlen)
+ goto truncate;
- answer->rdlength = htons(&reply[offset] - answer->rdata);
+ memcpy((char *)&reply[offset], ((struct nsec *)rrp->rdata)->bitmap, ((struct nsec *)rrp->rdata)->bitmap_len);
- } while (0);
+ offset += ((struct nsec *)rrp->rdata)->bitmap_len;
+
+ answer->rdlength = htons(&reply[offset] - answer->rdata);
+
NTOHS(odh->answer);
odh->answer += 1;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_NS) {
- if ((sdns = (struct domain_ns *)find_substruct(sd, INTERNAL_TYPE_NS)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
ns_count = 0;
- mod = sdns->ns_count;
- pos = sdns->ns_ptr;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if (offset + q->hdr->namelen > rlen)
goto truncate;
@@ -5608,14 +5334,14 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_NS);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NS]);
+ answer->ttl = htonl(((struct ns *)rrp->rdata)->ttl);
answer->rdlength = htons(namelen);
offset += 10; /* struct answer */
- name = sdns->ns[pos % mod].nsserver;
- namelen = sdns->ns[pos % mod].nslen;
+ name = ((struct ns *)rrp->rdata)->nsserver;
+ namelen = ((struct ns *)rrp->rdata)->nslen;
if (offset + namelen > rlen)
goto truncate;
@@ -5631,25 +5357,20 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->rdlength = htons(&reply[offset] - answer->rdata);
+ ns_count++;
+ }
- /* can we afford to write another header? if no truncate */
- if (sdns->ns_count > 1 && (offset + sdns->ns[pos % mod].nslen) > rlen) {
- goto truncate;
- }
-
- pos++;
-
- } while (++ns_count < RECORD_COUNT && --sdns->ns_count);
-
NTOHS(odh->answer);
odh->answer += ns_count;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_PTR) {
- if ((sdptr = (struct domain_ptr*)find_substruct(sd, INTERNAL_TYPE_PTR)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
+
NTOHS(odh->answer);
odh->answer++;
HTONS(odh->answer);
@@ -5669,12 +5390,12 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_PTR);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_PTR]);
+ answer->ttl = htonl(((struct ptr *)rrp->rdata)->ttl);
offset += 10; /* up to rdata length */
- label = sdptr->ptr;
- labellen = sdptr->ptrlen;
+ label = ((struct ptr *)rrp->rdata)->ptr;
+ labellen = ((struct ptr *)rrp->rdata)->ptrlen;
plabel = label;
@@ -5699,12 +5420,10 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->rdlength = htons(&reply[offset] - answer->rdata);
}
- if (sd->flags & DOMAIN_HAVE_MX) {
- if ((sdmx = (struct domain_mx*)find_substruct(sd, INTERNAL_TYPE_MX)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_MX)) != NULL) {
mx_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if ((offset + q->hdr->namelen) > rlen) {
goto truncate;
}
@@ -5724,43 +5443,39 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_MX);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_MX]);
- answer->rdlength = htons(sizeof(u_int16_t) + sdmx->mx[mx_count].exchangelen);
+ answer->ttl = htonl(((struct smx *)rrp->rdata)->ttl);
+ answer->rdlength = htons(sizeof(u_int16_t) + ((struct smx *)rrp->rdata)->exchangelen);
offset += 10; /* up to rdata length */
mx_priority = (u_int16_t *)&reply[offset];
- *mx_priority = htons(sdmx->mx[mx_count].preference);
+ *mx_priority = htons(((struct smx *)rrp->rdata)->preference);
- offset += 2;
+ offset += sizeof(u_int16_t);
- if (offset + sdmx->mx[mx_count].exchangelen > rlen)
+ if (offset + ((struct smx *)rrp->rdata)->exchangelen > rlen)
goto truncate;
- memcpy((char *)&reply[offset], (char *)sdmx->mx[mx_count].exchange, sdmx->mx[mx_count].exchangelen);
+ memcpy((char *)&reply[offset], (char *)((struct smx *)rrp->rdata)->exchange, ((struct smx *)rrp->rdata)->exchangelen);
- offset += sdmx->mx[mx_count].exchangelen;
+ offset += ((struct smx *)rrp->rdata)->exchangelen;
- if ((tmplen = compress_label((u_char*)reply, offset, sdmx->mx[mx_count].exchangelen)) > 0) {
+ if ((tmplen = compress_label((u_char*)reply, offset, ((struct smx *)rrp->rdata)->exchangelen)) > 0) {
offset = tmplen;
}
- /* can we afford to write another header? if no truncate */
- if (sdmx->mx_count > 1 && (offset + 12 + 2 + sdmx->mx[mx_count].exchangelen) > rlen) {
- goto truncate;
- }
-
answer->rdlength = htons(&reply[offset] - answer->rdata);
- } while (++mx_count < RECORD_COUNT && --sdmx->mx_count);
+ }
NTOHS(odh->answer);
odh->answer += mx_count;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_TXT) {
- if ((sdtxt = (struct domain_txt *)find_substruct(sd, INTERNAL_TYPE_TXT)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) != NULL) {
+ rrp = TAILQ_FIRST(&rrset->rr_head);
+ if (rrp == NULL)
+ return -1;
NTOHS(odh->answer);
odh->answer++;
@@ -5781,29 +5496,25 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_TXT);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_TXT]);
+ answer->ttl = htonl(((struct txt *)rrp->rdata)->ttl);
offset += 10; /* up to rdata length */
-
-
- if (offset + sdtxt->txtlen + 1 > rlen)
+ if (offset + ((struct txt *)rrp->rdata)->txtlen + 1 > rlen)
goto truncate;
p = (char *)&answer->rdata;
- *p = sdtxt->txtlen;
- memcpy((p + 1), sdtxt->txt, sdtxt->txtlen);
- offset += (sdtxt->txtlen + 1);
+ *p = ((struct txt *)rrp->rdata)->txtlen;
+ memcpy((p + 1), ((struct txt *)rrp->rdata)->txt, ((struct txt *)rrp->rdata)->txtlen);
+ offset += (((struct txt *)rrp->rdata)->txtlen + 1);
- answer->rdlength = htons(sdtxt->txtlen + 1);
+ answer->rdlength = htons(((struct txt *)rrp->rdata)->txtlen + 1);
}
- if (sd->flags & DOMAIN_HAVE_TLSA) {
- if ((sdtlsa = (struct domain_tlsa *)find_substruct(sd, INTERNAL_TYPE_TLSA)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) != NULL) {
tlsa_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if ((offset + q->hdr->namelen) > rlen) {
goto truncate;
}
@@ -5823,54 +5534,48 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_TLSA);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_TLSA]);
+ answer->ttl = htonl(((struct tlsa *)rrp->rdata)->ttl);
- typelen = sdtlsa->tlsa[tlsa_count].matchtype == 1 ? DNS_TLSA_SIZE_SHA256 : DNS_TLSA_SIZE_SHA512;
+ typelen = ((struct tlsa *)rrp->rdata)->matchtype == 1 ? DNS_TLSA_SIZE_SHA256 : DNS_TLSA_SIZE_SHA512;
answer->rdlength = htons((3 * sizeof(u_int8_t)) + typelen);
offset += 10; /* up to rdata length */
tlsa_usage = (u_int8_t *)&reply[offset];
- *tlsa_usage = sdtlsa->tlsa[tlsa_count].usage;
+ *tlsa_usage = ((struct tlsa *)rrp->rdata)->usage;
offset++;
tlsa_selector = (u_int8_t *)&reply[offset];
- *tlsa_selector = sdtlsa->tlsa[tlsa_count].selector;
+ *tlsa_selector = ((struct tlsa *)rrp->rdata)->selector;
offset++;
tlsa_matchtype = (u_int8_t *)&reply[offset];
- *tlsa_matchtype = sdtlsa->tlsa[tlsa_count].matchtype;
+ *tlsa_matchtype = ((struct tlsa *)rrp->rdata)->matchtype;
offset++;
- if (offset + sdtlsa->tlsa[tlsa_count].datalen > rlen)
+ if (offset + ((struct tlsa *)rrp->rdata)->datalen > rlen)
goto truncate;
- memcpy((char *)&reply[offset], (char *)sdtlsa->tlsa[tlsa_count].data, sdtlsa->tlsa[tlsa_count].datalen);
+ memcpy((char *)&reply[offset], (char *)((struct tlsa *)rrp->rdata)->data, ((struct tlsa *)rrp->rdata)->datalen);
- offset += sdtlsa->tlsa[tlsa_count].datalen;
+ offset += ((struct tlsa *)rrp->rdata)->datalen;
- /* can we afford to write another header? if no truncate */
- if (sdtlsa->tlsa_count > 1 && (offset + 12 + 3 + sdtlsa->tlsa[tlsa_count].datalen) > rlen) {
- goto truncate;
- }
-
answer->rdlength = htons(&reply[offset] - answer->rdata);
- } while (++tlsa_count < RECORD_COUNT && --sdtlsa->tlsa_count);
+ tlsa_count++;
+ }
NTOHS(odh->answer);
odh->answer += tlsa_count;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_SSHFP) {
- if ((sdsshfp = (struct domain_sshfp *)find_substruct(sd, INTERNAL_TYPE_SSHFP)) == NULL)
- return 0;
+ if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) != NULL) {
sshfp_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if ((offset + q->hdr->namelen) > rlen) {
goto truncate;
}
@@ -5890,47 +5595,40 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_SSHFP);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SSHFP]);
- answer->rdlength = htons((2 * sizeof(u_int8_t)) + sdsshfp->sshfp[sshfp_count].fplen);
+ answer->ttl = htonl(((struct sshfp *)rrp->rdata)->ttl);
+ answer->rdlength = htons((2 * sizeof(u_int8_t)) + ((struct sshfp *)rrp->rdata)->fplen);
offset += 10; /* up to rdata length */
sshfp_alg = (u_int8_t *)&reply[offset];
- *sshfp_alg = sdsshfp->sshfp[sshfp_count].algorithm;
+ *sshfp_alg = ((struct sshfp *)rrp->rdata)->algorithm;
offset++;
sshfp_fptype = (u_int8_t *)&reply[offset];
- *sshfp_fptype = sdsshfp->sshfp[sshfp_count].fptype;
+ *sshfp_fptype = ((struct sshfp *)rrp->rdata)->fptype;
offset++;
- if (offset + sdsshfp->sshfp[sshfp_count].fplen > rlen)
+ if (offset + ((struct sshfp *)rrp->rdata)->fplen > rlen)
goto truncate;
- memcpy((char *)&reply[offset], (char *)sdsshfp->sshfp[sshfp_count].fingerprint, sdsshfp->sshfp[sshfp_count].fplen);
+ memcpy((char *)&reply[offset], (char *)((struct sshfp *)rrp->rdata)->fingerprint, ((struct sshfp *)rrp->rdata)->fplen);
- offset += sdsshfp->sshfp[sshfp_count].fplen;
+ offset += ((struct sshfp *)rrp->rdata)->fplen;
- /* can we afford to write another header? if no truncate */
- if (sdsshfp->sshfp_count > 1 && (offset + 12 + 2 + sdsshfp->sshfp[sshfp_count].fplen) > rlen) {
- goto truncate;
- }
-
answer->rdlength = htons(&reply[offset] - answer->rdata);
- } while (++sshfp_count < RECORD_COUNT && --sdsshfp->sshfp_count);
+ sshfp_count++;
+ }
NTOHS(odh->answer);
odh->answer += sshfp_count;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_NAPTR) {
- if ((sdnaptr = (struct domain_naptr *)find_substruct(sd, INTERNAL_TYPE_NAPTR)) == NULL)
- return 0;
-
+ if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) != NULL) {
naptr_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if ((offset + q->hdr->namelen) > rlen) {
goto truncate;
}
@@ -5950,82 +5648,75 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_NAPTR);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_NAPTR]);
- answer->rdlength = htons((2 * sizeof(u_int16_t)) + sdnaptr->naptr[naptr_count].flagslen + 1 + sdnaptr->naptr[naptr_count].serviceslen + 1 + sdnaptr->naptr[naptr_count].regexplen + 1 + sdnaptr->naptr[naptr_count].replacementlen);
+ answer->ttl = htonl(((struct naptr *)rrp->rdata)->ttl);
+ answer->rdlength = htons((2 * sizeof(u_int16_t)) + ((struct naptr *)rrp->rdata)->flagslen + 1 + ((struct naptr *)rrp->rdata)->serviceslen + 1 + ((struct naptr *)rrp->rdata)->regexplen + 1 + ((struct naptr *)rrp->rdata)->replacementlen);
offset += 10; /* up to rdata length */
naptr_order = (u_int16_t *)&reply[offset];
- *naptr_order = htons(sdnaptr->naptr[naptr_count].order);
+ *naptr_order = htons(((struct naptr *)rrp->rdata)->order);
- offset += 2;
+ offset += sizeof(u_int16_t);
naptr_preference = (u_int16_t *)&reply[offset];
- *naptr_preference = htons(sdnaptr->naptr[naptr_count].preference);
+ *naptr_preference = htons(((struct naptr *)rrp->rdata)->preference);
- offset += 2;
+ offset += sizeof(u_int16_t);
/* flags */
- if (offset + sdnaptr->naptr[naptr_count].flagslen + 1> rlen)
+ if (offset + ((struct naptr *)rrp->rdata)->flagslen + 1> rlen)
goto truncate;
- reply[offset] = sdnaptr->naptr[naptr_count].flagslen;
+ reply[offset] = ((struct naptr *)rrp->rdata)->flagslen;
offset++;
- memcpy((char *)&reply[offset], (char *)sdnaptr->naptr[naptr_count].flags, sdnaptr->naptr[naptr_count].flagslen);
+ memcpy((char *)&reply[offset], (char *)((struct naptr *)rrp->rdata)->flags, ((struct naptr *)rrp->rdata)->flagslen);
- offset += sdnaptr->naptr[naptr_count].flagslen;
+ offset += ((struct naptr *)rrp->rdata)->flagslen;
/* services */
- if (offset + sdnaptr->naptr[naptr_count].serviceslen + 1> rlen)
+ if (offset + ((struct naptr *)rrp->rdata)->serviceslen + 1 > rlen)
goto truncate;
- reply[offset] = sdnaptr->naptr[naptr_count].serviceslen;
+ reply[offset] = ((struct naptr *)rrp->rdata)->serviceslen;
offset++;
- memcpy((char *)&reply[offset], (char *)sdnaptr->naptr[naptr_count].services, sdnaptr->naptr[naptr_count].serviceslen);
+ memcpy((char *)&reply[offset], (char *)((struct naptr *)rrp->rdata)->services, ((struct naptr *)rrp->rdata)->serviceslen);
- offset += sdnaptr->naptr[naptr_count].serviceslen;
+ offset += ((struct naptr *)rrp->rdata)->serviceslen;
/* regexp */
- if (offset + sdnaptr->naptr[naptr_count].regexplen + 1> rlen)
+ if (offset + ((struct naptr *)rrp->rdata)->regexplen + 1> rlen)
goto truncate;
- reply[offset] = sdnaptr->naptr[naptr_count].regexplen;
+ reply[offset] = ((struct naptr *)rrp->rdata)->regexplen;
offset++;
- memcpy((char *)&reply[offset], (char *)sdnaptr->naptr[naptr_count].regexp, sdnaptr->naptr[naptr_count].regexplen);
+ memcpy((char *)&reply[offset], (char *)((struct naptr *)rrp->rdata)->regexp, ((struct naptr *)rrp->rdata)->regexplen);
- offset += sdnaptr->naptr[naptr_count].regexplen;
+ offset += ((struct naptr *)rrp->rdata)->regexplen;
/* replacement */
- if (offset + sdnaptr->naptr[naptr_count].replacementlen > rlen)
+ if (offset + ((struct naptr *)rrp->rdata)->replacementlen > rlen)
goto truncate;
- memcpy((char *)&reply[offset], (char *)sdnaptr->naptr[naptr_count].replacement, sdnaptr->naptr[naptr_count].replacementlen);
+ memcpy((char *)&reply[offset], (char *)((struct naptr *)rrp->rdata)->replacement, ((struct naptr *)rrp->rdata)->replacementlen);
- offset += sdnaptr->naptr[naptr_count].replacementlen;
+ offset += ((struct naptr *)rrp->rdata)->replacementlen;
- if ((tmplen = compress_label((u_char*)reply, offset, sdnaptr->naptr[naptr_count].replacementlen)) > 0) {
+ if ((tmplen = compress_label((u_char*)reply, offset, ((struct naptr *)rrp->rdata)->replacementlen)) > 0) {
offset = tmplen;
}
- /* can we afford to write another header? if no truncate */
- if (sdnaptr->naptr_count > naptr_count && (offset + 12 + 4 + sdnaptr->naptr[naptr_count + 1].flagslen + 1) > rlen) {
- goto truncate;
- }
-
answer->rdlength = htons(&reply[offset] - answer->rdata);
- } while (++naptr_count < RECORD_COUNT && --sdnaptr->naptr_count);
+ naptr_count++;
+ }
NTOHS(odh->answer);
odh->answer += naptr_count;
HTONS(odh->answer);
}
- if (sd->flags & DOMAIN_HAVE_SRV) {
- if ((sdsrv = (struct domain_srv *)find_substruct(sd, INTERNAL_TYPE_SRV)) == NULL)
- return 0;
-
+ if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) != NULL) {
srv_count = 0;
- do {
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
if ((offset + q->hdr->namelen) > rlen) {
goto truncate;
}
@@ -6045,44 +5736,40 @@ create_anyreply(struct sreply *sreply, char *reply, in
answer->type = htons(DNS_TYPE_SRV);
answer->class = htons(DNS_CLASS_IN);
- answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_SRV]);
- answer->rdlength = htons((3 * sizeof(u_int16_t)) + sdsrv->srv[srv_count].targetlen);
+ answer->ttl = htonl(((struct srv *)rrp->rdata)->ttl);
+ answer->rdlength = htons((3 * sizeof(u_int16_t)) + ((struct srv *)rrp->rdata)->targetlen);
offset += 10; /* up to rdata length */
srv_priority = (u_int16_t *)&reply[offset];
- *srv_priority = htons(sdsrv->srv[srv_count].priority);
+ *srv_priority = htons(((struct srv *)rrp->rdata)->priority);
- offset += 2;
+ offset += sizeof(u_int16_t);
srv_weight = (u_int16_t *)&reply[offset];
- *srv_weight = htons(sdsrv->srv[srv_count].weight);
+ *srv_weight = htons(((struct srv *)rrp->rdata)->weight);
- offset += 2;
+ offset += sizeof(u_int16_t);
srv_port = (u_int16_t *)&reply[offset];
- *srv_port = htons(sdsrv->srv[srv_count].port);
+ *srv_port = htons(((struct srv *)rrp->rdata)->port);
- offset += 2;
+ offset += sizeof(u_int16_t);
- if (offset + sdsrv->srv[srv_count].targetlen > rlen)
+ if (offset + ((struct srv *)rrp->rdata)->targetlen > rlen)
goto truncate;
- memcpy((char *)&reply[offset], (char *)sdsrv->srv[srv_count].target, sdsrv->srv[srv_count].targetlen);
+ memcpy((char *)&reply[offset], (char *)((struct srv *)rrp->rdata)->target, ((struct srv *)rrp->rdata)->targetlen);
- offset += sdsrv->srv[srv_count].targetlen;
+ offset += ((struct srv *)rrp->rdata)->targetlen;
- if ((tmplen = compress_label((u_char*)reply, offset, sdsrv->srv[srv_count].targetlen)) > 0) {
+ if ((tmplen = compress_label((u_char*)reply, offset, ((struct srv *)rrp->rdata)->targetlen)) > 0) {
offset = tmplen;
}
- /* can we afford to write another header? if no truncate */
- if (sdsrv->srv_count > 1 && (offset + 12 + 6 + sdsrv->srv[srv_count].targetlen) > rlen) {
- goto truncate;
- }
-
answer->rdlength = htons(&reply[offset] - answer->rdata);
- } while (++srv_count < RECORD_COUNT && --sdsrv->srv_count);
+ srv_count++;
+ }
NTOHS(odh->answer);
odh->answer += srv_count;
@@ -6090,9 +5777,10 @@ create_anyrepl