Commit Diff
Diff:
c3151551f44dba733f63b72cb23c3348abf32459
8c24ba133a6485514616fac9b030b1301fbee17c
Commit:
8c24ba133a6485514616fac9b030b1301fbee17c
Tree:
97107b3c830c33ccc0c48b75de8a63049be98f76
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Wed Jul 15 20:27:15 2020 UTC
Message:
add caching for 28 (or so) RR's, unfortunately limited testing...
blob - 27685aae297e26d22a9dc50894da389a24af338e
blob + b6ce1dc4ddcc24c6a733def7f708e405d80e152f
--- cache.c
+++ cache.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: cache.c,v 1.5 2020/07/13 22:02:26 pjp Exp $
+ * $Id: cache.c,v 1.6 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -118,6 +118,7 @@ int cache_tlsa(struct scache *);
int cache_srv(struct scache *);
int cache_naptr(struct scache *);
int cache_soa(struct scache *);
+int cache_generic(struct scache *);
/* The following alias helps with bounds checking all input, needed! */
@@ -304,6 +305,9 @@ cacheit(u_char *payload, u_char *estart, u_char *end,
break;
}
}
+ if (cr->rrtype == 0) {
+ cache_generic(scache);
+ }
pb += rdlen;
@@ -841,5 +845,32 @@ cache_naptr(struct scache *scache)
q = save;
}
+ return (q - scache->estart);
+}
+
+int
+cache_generic(struct scache *scache)
+{
+ u_char *p = scache->payload;
+ u_char *q = p;
+
+ switch (scache->rrtype) {
+ case 18: /* AFSDB */ case 42: /* APL */ case 257: /* CAA */
+ case 60: /* CDNSKEY */ case 59: /* CDS */ case 37: /* CERT */
+ case 62: /* CSYNC */ case 49: /* DHCID */ case 39: /* DNAME */
+ case 108: /* EUI48 */ case 109: /* EUI64 */ case 13: /* HINFO */
+ case 55: /* HIP */ case 45: /* IPSECKEY */ case 25: /* KEY */
+ case 36: /* KX */ case 29: /* LOC */ case 61: /* OPENPGPKEY */
+ case 17: /* RP */ case 24: /* SIG */ case 53: /* SMIMEA */
+ case 249: /* TKEY */ case 256: /* URI */
+ break;
+ default:
+ /* we don't cache unsupported types */
+ return -1;
+ }
+
+ transmit_rr(scache, (void*)scache->payload, scache->rdlen);
+
+ q += scache->rdlen;
return (q - scache->estart);
}
blob - 5a42309ba1b93b572c3a27e20fa6377ae61ab128
blob + 7fc55e2cfe7db8436da68cd6fb292d7dc0bd7e2f
--- db.c
+++ db.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: db.c,v 1.22 2020/07/13 22:02:26 pjp Exp $
+ * $Id: db.c,v 1.23 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -63,7 +63,7 @@
#include "ddd-dns.h"
#include "ddd-db.h"
-struct rbtree * create_rr(ddDB *db, char *name, int len, int type, void *rdata, uint32_t ttl);
+struct rbtree * create_rr(ddDB *, char *, int, int, void *, uint32_t, uint16_t);
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);
@@ -177,7 +177,7 @@ dddbclose(ddDB *db)
}
struct rbtree *
-create_rr(ddDB *db, char *name, int len, int type, void *rdata, uint32_t ttl)
+create_rr(ddDB *db, char *name, int len, int type, void *rdata, uint32_t ttl, uint16_t rdlen)
{
ddDBT key, data;
struct rbtree *rbt = NULL;
@@ -254,6 +254,7 @@ create_rr(ddDB *db, char *name, int len, int type, voi
break;
}
myrr->changed = time(NULL);
+ myrr->rdlen = rdlen;
rrset->ttl = ttl;
blob - 1e0d350e6cef2ecb323d98fd0173b40776f591f7
blob + f08368ee86a88accf2f66e2d74c6e551c52235b4
--- ddd-db.h
+++ ddd-db.h
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ddd-db.h,v 1.46 2020/07/14 14:46:23 pjp Exp $
+ * $Id: ddd-db.h,v 1.47 2020/07/15 20:27:15 pjp Exp $
*/
#ifndef _DB_H
@@ -302,6 +302,7 @@ typedef struct __dddb {
struct rr {
void *rdata;
+ uint16_t rdlen;
time_t changed;
TAILQ_ENTRY(rr) entries;
};
blob - 685abed4268fed991fdc57adfdbb0dedce6e32cf
blob + 6d0a4348ca7af9e994c50848bc4efcbd1611102c
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: delphinusdnsd.c,v 1.127 2020/07/15 07:39:38 pjp Exp $
+ * $Id: delphinusdnsd.c,v 1.128 2020/07/15 20:27:15 pjp Exp $
*/
@@ -165,7 +165,6 @@ extern void ddd_shutdown(void);
extern int get_record_size(ddDB *, char *, int);
extern struct question *build_question(char *, int, int, char *);
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 *, char *, int, u_int16_t, void *);
blob - 2e8753580ad4e71f631a48810396520697116751
blob + f33c601763a63a1679c501a88e8ebd6224e87529
--- dnssec.c
+++ dnssec.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: dnssec.c,v 1.27 2020/07/08 12:29:02 pjp Exp $
+ * $Id: dnssec.c,v 1.28 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -104,7 +104,6 @@ extern int free_question(struct question
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);
blob - 99d46eaca99683b3a5bae3c34bc68158e1387cb3
blob + b94a84d62f3c987c5aea8044b8be1296069a1ecd
--- forward.c
+++ forward.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: forward.c,v 1.26 2020/07/15 16:51:42 pjp Exp $
+ * $Id: forward.c,v 1.27 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -180,7 +180,8 @@ extern int reply_ds(struct sreply *, ddDB *);
extern int reply_nsec(struct sreply *, ddDB *);
extern int reply_nsec3(struct sreply *, ddDB *);
extern int reply_nsec3param(struct sreply *, ddDB *);
-extern struct rbtree * create_rr(ddDB *, char *, int, int, void *, uint32_t);
+extern int reply_generic(struct sreply *, ddDB *);
+extern struct rbtree * create_rr(ddDB *, char *, int, int, void *, uint32_t, uint16_t);
extern void flag_rr(struct rbtree *rbt);
extern struct rbtree * find_rrset(ddDB *, char *, int);
@@ -624,7 +625,7 @@ drop:
if ((rbt = create_rr(db, ri->rri_rr.name,
ri->rri_rr.namelen, ri->rri_rr.rrtype,
- (void *)rdata, ri->rri_rr.ttl)) == NULL) {
+ (void *)rdata, ri->rri_rr.ttl, ri->rri_rr.buflen)) == NULL) {
dolog(LOG_ERR, "cache insertion failed 2\n");
free(rdata);
pack32((char *)&ri->u.s.read, 1);
@@ -844,8 +845,38 @@ forwardthis(ddDB *db, struct cfg *cfg, int so, struct
}
if (rl->rrtype == 0) {
- dolog(LOG_INFO, "we did not have any right answer in our cache, skip to newqueue\n");
- goto newqueue;
+ /* https://en.wikipedia.org/wiki/List_of_DNS_record_types */
+ switch (ntohs(q->hdr->qtype)) {
+ /* FALLTHROUGH for all listed */
+ case 18: /* AFSDB */ case 42: /* APL */ case 257: /* CAA */
+ case 60: /* CDNSKEY */ case 59: /* CDS */ case 37: /* CERT */
+ case 62: /* CSYNC */ case 49: /* DHCID */ case 39: /* DNAME */
+ case 108: /* EUI48 */ case 109: /* EUI64 */ case 13: /* HINFO */
+ case 55: /* HIP */ case 45: /* IPSECKEY */ case 25: /* KEY */
+ case 36: /* KX */ case 29: /* LOC */ case 61: /* OPENPGPKEY */
+ case 17: /* RP */ case 24: /* SIG */ case 53: /* SMIMEA */
+ case 249: /* TKEY */ case 256: /* URI */
+#if DEBUG
+ dolog(LOG_INFO, "replying generic RR %d\n",
+ ntohs(q->hdr->qtype));
+#endif
+ if (reply_generic(&sreply, cfg->db) < 0) {
+ expire_rr(db, q->hdr->name, q->hdr->namelen,
+ ntohs(q->hdr->qtype), highexpire);
+ free_question(q);
+ goto newqueue;
+ }
+
+ break;
+ default:
+ dolog(LOG_INFO,
+ "no answer in our cache, skip to newqueue\n");
+ free_question(q);
+ goto newqueue;
+ break;
+ }
+
+ /* NOTREACHED */
}
free_question(q);
blob - a03f13891b7efdb502c3a2e6a21e0088b195a98a
blob + 4bc336da75fa4316d3740f4177be18ab15378d15
--- parse.y
+++ parse.y
@@ -21,7 +21,7 @@
*/
/*
- * $Id: parse.y,v 1.105 2020/07/15 15:09:24 pjp Exp $
+ * $Id: parse.y,v 1.106 2020/07/15 20:27:15 pjp Exp $
*/
%{
@@ -99,7 +99,7 @@ extern int insert_tsig_key(char *, int, char *, int);
extern void ddd_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 struct rbtree * create_rr(ddDB *, char *, int, int, void *, uint32_t);
+extern struct rbtree * create_rr(ddDB *, char *, int, int, void *, uint32_t, uint16_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);
@@ -2194,7 +2194,7 @@ fill_cname(ddDB *db, char *name, char *type, int myttl
free(myname);
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_CNAME, cname, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_CNAME, cname, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2246,7 +2246,7 @@ fill_ptr(ddDB *db, char *name, char *type, int myttl,
free(myname);
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_PTR, ptr, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_PTR, ptr, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2296,7 +2296,7 @@ fill_dnskey(ddDB *db, char *name, char *type, u_int32_
dnskey->publickey_len = ret;
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_DNSKEY, dnskey, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_DNSKEY, dnskey, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2392,7 +2392,7 @@ fill_rrsig(ddDB *db, char *name, char *type, u_int32_t
rrsig->signature_len = ret;
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_RRSIG, rrsig, original_ttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_RRSIG, rrsig, original_ttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2457,7 +2457,7 @@ fill_ds(ddDB *db, char *name, char *type, u_int32_t my
ret = hex2bin(digest, strlen(digest), ds->digest);
ds->digestlen = ret;
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_DS, ds, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_DS, ds, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2531,7 +2531,7 @@ fill_nsec3(ddDB *db, char *name, char *type, u_int32_t
printf(";nsec3->bitmap == \"%s\", nsec3->bitmap_len == %d\n", bitmap, nsec3->bitmap_len);
#endif
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC3, nsec3, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC3, nsec3, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2574,7 +2574,7 @@ fill_nsec3param(ddDB *db, char *name, char *type, u_in
nsec3param->saltlen = (strlen(salt) / 2);
hex2bin(salt, strlen(salt), nsec3param->salt);
}
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC3PARAM, nsec3param, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC3PARAM, nsec3param, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2626,7 +2626,7 @@ fill_nsec(ddDB *db, char *name, char *type, u_int32_t
create_nsec_bitmap(bitmap, nsec->bitmap, (int *)&nsec->bitmap_len);
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC, nsec, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NSEC, nsec, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2694,7 +2694,7 @@ fill_naptr(ddDB *db, char *name, char *type, int myttl
memcpy(&naptr->replacement, naptrname, naptr_namelen);
naptr->replacementlen = naptr_namelen;
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NAPTR, naptr, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NAPTR, naptr, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2766,7 +2766,7 @@ fill_txt(ddDB *db, char *name, char *type, int myttl,
memcpy(&txt->txt, tmp, len);
txt->txtlen = len;
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_TXT, txt, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_TXT, txt, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2833,7 +2833,7 @@ fill_tlsa(ddDB *db, char *name, char *type, int myttl,
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_TLSA, tlsa, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_TLSA, tlsa, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2890,7 +2890,7 @@ fill_sshfp(ddDB *db, char *name, char *type, int myttl
ret = hex2bin(fingerprint, strlen(fingerprint), sshfp->fingerprint);
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SSHFP, sshfp, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SSHFP, sshfp, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2948,7 +2948,7 @@ fill_srv(ddDB *db, char *name, char *type, int myttl,
free (srvname);
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SRV, srv, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SRV, srv, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -2998,7 +2998,7 @@ fill_mx(ddDB *db, char *name, char *type, int myttl, i
free (mxname);
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_MX, mx, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_MX, mx, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -3042,7 +3042,7 @@ fill_a(ddDB *db, char *name, char *type, int myttl, ch
return (-1);
}
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_A, sa, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_A, sa, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -3088,7 +3088,7 @@ fill_aaaa(ddDB *db, char *name, char *type, int myttl,
return -1;
}
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_AAAA, saaaa, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_AAAA, saaaa, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -3173,7 +3173,7 @@ fill_ns(ddDB *db, char *name, char *type, int myttl, c
ns->ns_type = nstype;
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NS, ns, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_NS, ns, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
@@ -3254,7 +3254,7 @@ fill_soa(ddDB *db, char *name, char *type, int myttl,
soa->expire = expire;
soa->minttl = ttl;
- rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SOA, soa, myttl);
+ rbt = create_rr(db, converted_name, converted_namelen, DNS_TYPE_SOA, soa, myttl, 0);
if (rbt == NULL) {
dolog(LOG_ERR, "create_rr failed\n");
return -1;
blob - 5271e5cf53291de72350f4bf7041a9c12fc42c37
blob + 58a475bcb5e890a55c1505feffe1f211af7f7e66
--- query.c
+++ query.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: query.c,v 1.6 2020/07/08 12:29:02 pjp Exp $
+ * $Id: query.c,v 1.7 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -135,7 +135,6 @@ extern int check_ent(char *, int);
extern struct question *build_question(char *, int, int, char *);
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);
blob - 7821cab82ece55983f13b9584ac1957b31bad180
blob + 8e412642e1b6a0b17127edea0af96900dac9314e
--- reply.c
+++ reply.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: reply.c,v 1.106 2020/07/08 17:33:28 pjp Exp $
+ * $Id: reply.c,v 1.107 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -112,6 +112,7 @@ extern int dn_contains(char *, int, char *, int);
u_int16_t create_anyreply(struct sreply *, char *, int, int, int);
+int reply_generic(struct sreply *, ddDB *);
int reply_a(struct sreply *, ddDB *);
int reply_nsec3(struct sreply *, ddDB *);
int reply_nsec3param(struct sreply *, ddDB *);
@@ -7067,4 +7068,212 @@ int
reply_nodata(struct sreply *sreply, ddDB *db)
{
return (reply_noerror(sreply, db));
+}
+
+/*
+ * REPLY_GENERIC() - replies a DNS question (*q) on socket (so)
+ *
+ */
+
+int
+reply_generic(struct sreply *sreply, ddDB *db)
+{
+ char *reply = sreply->replybuf;
+ struct dns_header *odh;
+ u_int16_t outlen = 0;
+ int gen_count;
+
+ struct answer {
+ char name[2];
+ u_int16_t type;
+ u_int16_t class;
+ u_int32_t ttl;
+ u_int16_t rdlength; /* 12 */
+ in_addr_t rdata; /* 16 */
+ } __attribute__((packed));
+
+ struct answer *answer;
+
+ int so = sreply->so;
+ char *buf = sreply->buf;
+ int len = sreply->len;
+ struct question *q = sreply->q;
+ struct sockaddr *sa = sreply->sa;
+ int salen = sreply->salen;
+
+ 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;
+ time_t now;
+
+ now = time(NULL);
+
+ if ((rrset = find_rr(rbt, ntohs(q->hdr->qtype))) == 0)
+ return -1;
+
+ if (istcp) {
+ replysize = 65535;
+ }
+
+ if (!istcp && q->edns0len > 512)
+ replysize = q->edns0len;
+
+ odh = (struct dns_header *)&reply[0];
+
+ outlen = sizeof(struct dns_header);
+
+ if (len > replysize) {
+ return (retlen);
+ }
+
+ memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
+ memset((char *)&odh->query, 0, sizeof(u_int16_t));
+
+ outlen += (q->hdr->namelen + 4);
+ rollback = outlen;
+
+ SET_DNS_REPLY(odh);
+
+ if (q->aa)
+ SET_DNS_AUTHORITATIVE(odh);
+
+ if (q->rd) {
+ SET_DNS_RECURSION(odh);
+
+ if (! q->aa)
+ SET_DNS_RECURSION_AVAIL(odh);
+ }
+
+ HTONS(odh->query);
+
+ odh->question = htons(1);
+ odh->answer = htons(0);
+ 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);
+
+ gen_count = 0;
+
+ TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
+ /* can we afford to write another header? if no truncate */
+ if ((outlen + 12 + rrp->rdlen) > replysize) {
+ NTOHS(odh->query);
+ SET_DNS_TRUNCATION(odh);
+ HTONS(odh->query);
+ odh->answer = 0;
+ odh->nsrr = 0;
+ odh->additional = 0;
+ outlen = rollback;
+ goto out;
+ }
+ /*
+ * answer->name is a pointer to the request (0xc00c)
+ */
+
+ answer->name[0] = 0xc0; /* 1 byte */
+ answer->name[1] = 0x0c; /* 2 bytes */
+ answer->type = q->hdr->qtype; /* 4 bytes */
+ answer->class = q->hdr->qclass; /* 6 bytes */
+
+ if (q->aa)
+ answer->ttl = htonl(rrset->ttl); /* 10 b */
+ else
+ answer->ttl = htonl(rrset->ttl - (MIN(rrset->ttl, difftime(now, rrset->created))));
+
+ answer->rdlength = htons(rrp->rdlen);
+
+ memcpy((char *)&answer->rdata, (char *)rrp->rdata,
+ rrp->rdlen);
+
+ gen_count++;
+ outlen += (12 + rrp->rdlen);
+
+ /* set new offset for answer */
+ answer = (struct answer *)&reply[outlen];
+ }
+
+ odh->answer = htons(gen_count);
+
+ /* Add RRSIG reply_a */
+ if (dnssec && q->dnssecok && (rbt->flags & RBT_DNSSEC)) {
+ int tmplen = 0;
+ int origlen = outlen;
+ int retcount;
+
+ tmplen = additional_rrsig(q->hdr->name, q->hdr->namelen, ntohs(q->hdr->qtype), rbt, reply, replysize, outlen, &retcount, q->aa);
+
+ if (tmplen == 0) {
+ /* we're forwarding and had no RRSIG return with -1 */
+ if (q->aa != 1)
+ return -1;
+
+ NTOHS(odh->query);
+ SET_DNS_TRUNCATION(odh);
+ HTONS(odh->query);
+ odh->answer = 0;
+ odh->nsrr = 0;
+ odh->additional = 0;
+ outlen = rollback;
+ goto out;
+ }
+
+ outlen = tmplen;
+
+ if (outlen > origlen)
+ odh->answer = htons(gen_count + retcount);
+
+ }
+
+out:
+ if (q->edns0len) {
+ /* tag on edns0 opt record */
+ odh->additional = htons(1);
+ outlen = additional_opt(q, reply, replysize, outlen);
+ }
+
+ if (q->tsig.tsigverified == 1) {
+ outlen = additional_tsig(q, reply, replysize, outlen, 0, 0, NULL);
+
+ NTOHS(odh->additional);
+ odh->additional++;
+ HTONS(odh->additional);
+ }
+
+ if (istcp) {
+ char *tmpbuf;
+
+ tmpbuf = malloc(outlen + 2);
+ if (tmpbuf == 0) {
+ dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
+ }
+ pack16(tmpbuf, htons(outlen));
+ memcpy(&tmpbuf[2], reply, outlen);
+
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
+ dolog(LOG_INFO, "send: %s\n", strerror(errno));
+ }
+ free(tmpbuf);
+ } else {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
+ dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
+ }
+ }
+
+#if 0
+ /*
+ * update order XXX
+ */
+
+ rotate_rr(rrset);
+#endif
+
+ return (retlen);
}
blob - dc6dc1b0f007100f3688b49076d3b0cfdf805963
blob + b47e870ebded2163d544412ac23a4963c8831127
--- sign.c
+++ sign.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: sign.c,v 1.6 2020/07/08 12:29:02 pjp Exp $
+ * $Id: sign.c,v 1.7 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -245,7 +245,6 @@ extern int check_ent(char *, int);
extern struct question *build_question(char *, int, int, char *);
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);
blob - 1bbff3ba479ce6cb6eead1aea13203657ed0bf70
blob + f69ea967d54e9bdbfc2a836e149c034f42edc205
--- util.c
+++ util.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: util.c,v 1.66 2020/07/08 12:29:02 pjp Exp $
+ * $Id: util.c,v 1.67 2020/07/15 20:27:15 pjp Exp $
*/
#include <sys/types.h>
@@ -128,7 +128,6 @@ extern int zonecount;
extern void dolog(int, 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);
repomaster@centroid.eu