#include "lib/layer/iterate.h"
#include "lib/cache.h"
#include "lib/module.h"
-#include "lib/rrset_stash.h"
+#include "lib/utils.h"
#define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(rplan), " rc ", fmt)
#define DEFAULT_MINTTL (5) /* Short-time "no data" retention to avoid bursts */
!knot_dname_is_equal(rr->owner, ns_name)) {
continue;
}
- stash_add(pkt, stash, rr, pool);
+ kr_rrmap_add(stash, rr, pool);
}
}
for (unsigned i = 0; i < authority->count; ++i) {
const knot_rrset_t *rr = knot_pkt_rr(authority, i);
if (rr->type == KNOT_RRTYPE_DS || rr->type == KNOT_RRTYPE_RRSIG) {
- stash_add(pkt, stash, rr, pool);
+ kr_rrmap_add(stash, rr, pool);
}
}
}
stash_glue(stash, pkt, knot_ns_name(&rr->rrs, 0), pool);
}
/* Stash record */
- stash_add(pkt, stash, rr, pool);
+ kr_rrmap_add(stash, rr, pool);
}
return kr_ok();
}
&& rr->type != KNOT_RRTYPE_RRSIG) {
continue;
}
- stash_add(pkt, stash, rr, pool);
+ kr_rrmap_add(stash, rr, pool);
/* Follow CNAME chain */
if (rr->type == KNOT_RRTYPE_CNAME) {
cname = knot_cname_name(&rr->rrs);
#include "lib/layer.h"
#include "lib/resolve.h"
#include "lib/rplan.h"
-#include "lib/rrset_stash.h"
+#include "lib/utils.h"
#include "lib/defines.h"
#include "lib/module.h"
if ((rr->type == KNOT_RRTYPE_NS) && (section_id == KNOT_AUTHORITY)) {
continue;
}
- ret = stash_add(answer, &stash, rr, pool);
+ ret = kr_rrmap_add(&stash, rr, pool);
if (ret != 0) {
goto fail;
}
lib/nsrep.c \
lib/module.c \
lib/resolve.c \
- lib/rrset_stash.c \
lib/zonecut.c \
lib/rplan.c \
lib/cache.c
lib/nsrep.h \
lib/module.h \
lib/resolve.h \
- lib/rrset_stash.h \
lib/zonecut.h \
lib/rplan.h \
lib/cache.h
+++ /dev/null
-/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <libknot/descriptor.h>
-#include <libknot/dname.h>
-#include <libknot/rrtype/rrsig.h>
-#include <stdio.h>
-
-#include "lib/defines.h"
-#include "lib/rrset_stash.h"
-
-int stash_add(const knot_pkt_t *pkt, map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
-{
- (void) pkt;
-
- /* Stash key = {[1] flags, [1-255] owner, [1-5] type, [1] \x00 } */
- char key[9 + KNOT_DNAME_MAXLEN];
- uint16_t rrtype = rr->type;
- KEY_FLAG_SET(key, KEY_FLAG_NO);
-
- /* Stash RRSIGs in a special cache, flag them and set type to its covering RR.
- * This way it the stash won't merge RRSIGs together. */
- if (rr->type == KNOT_RRTYPE_RRSIG) {
- rrtype = knot_rrsig_type_covered(&rr->rrs, 0);
- KEY_FLAG_SET(key, KEY_FLAG_RRSIG);
- }
-
- uint8_t *key_buf = (uint8_t *)key + 1;
- int ret = knot_dname_to_wire(key_buf, rr->owner, KNOT_DNAME_MAXLEN);
- if (ret <= 0) {
- return ret;
- }
- knot_dname_to_lower(key_buf);
- /* Must convert to string, as the key must not contain 0x00 */
- ret = snprintf((char *)key_buf + ret - 1, sizeof(key) - KNOT_DNAME_MAXLEN, "%hu", rrtype);
- if (ret <= 0 || ret >= KNOT_DNAME_MAXLEN) {
- return kr_error(EILSEQ);
- }
-
- /* Check if already exists */
- knot_rrset_t *stashed = map_get(stash, key);
- if (!stashed) {
- stashed = knot_rrset_copy(rr, pool);
- if (!stashed) {
- return kr_error(ENOMEM);
- }
- return map_set(stash, key, stashed);
- }
- /* Merge rdataset */
- return knot_rdataset_merge(&stashed->rrs, &rr->rrs, pool);
-}
+++ /dev/null
-/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include <libknot/internal/mempattern.h>
-#include <libknot/packet/pkt.h>
-#include <libknot/rrset.h>
-
-#include "lib/generic/map.h"
-
-/* Stash key flags */
-#define KEY_FLAG_NO 0x01
-#define KEY_FLAG_RRSIG 0x02
-#define KEY_FLAG_SET(key, flag) key[0] = (flag);
-#define KEY_COVERING_RRSIG(key) (key[0] & KEY_FLAG_RRSIG)
-
-/**
- * Merges RRSets with matching owner name and type together.
- * @note RRSIG RRSets are merged according the type covered fields.
- * @param pkt Packet which the rset belongs to.
- * @param stash Holds the merged RRSets.
- * @param rr RRSet to be added.
- * @param pool Memory pool.
- * @return 0 or an error
- */
-int stash_add(const knot_pkt_t *pkt, map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool);
#include <stdio.h>
#include <arpa/inet.h>
#include <sys/time.h>
+#include <libknot/descriptor.h>
+#include <libknot/dname.h>
+#include <libknot/rrtype/rrsig.h>
#include "ccan/isaac/isaac.h"
#include "lib/defines.h"
ret = ((uint8_t)(*a >> shift) - (uint8_t)(*b >> shift));
}
return ret;
-}
\ No newline at end of file
+}
+
+/* Set stashed RR flag */
+#define KEY_FLAG_SET(key, flag) key[0] = (flag);
+
+int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
+{
+ if (!stash || !rr) {
+ return kr_error(EINVAL);
+ }
+
+ /* Stash key = {[1] flags, [1-255] owner, [1-5] type, [1] \x00 } */
+ char key[9 + KNOT_DNAME_MAXLEN];
+ uint16_t rrtype = rr->type;
+ KEY_FLAG_SET(key, KEY_FLAG_NO);
+
+ /* Stash RRSIGs in a special cache, flag them and set type to its covering RR.
+ * This way it the stash won't merge RRSIGs together. */
+ if (rr->type == KNOT_RRTYPE_RRSIG) {
+ rrtype = knot_rrsig_type_covered(&rr->rrs, 0);
+ KEY_FLAG_SET(key, KEY_FLAG_RRSIG);
+ }
+
+ uint8_t *key_buf = (uint8_t *)key + 1;
+ int ret = knot_dname_to_wire(key_buf, rr->owner, KNOT_DNAME_MAXLEN);
+ if (ret <= 0) {
+ return ret;
+ }
+ knot_dname_to_lower(key_buf);
+ /* Must convert to string, as the key must not contain 0x00 */
+ ret = snprintf((char *)key_buf + ret - 1, sizeof(key) - KNOT_DNAME_MAXLEN, "%hu", rrtype);
+ if (ret <= 0 || ret >= KNOT_DNAME_MAXLEN) {
+ return kr_error(EILSEQ);
+ }
+
+ /* Check if already exists */
+ knot_rrset_t *stashed = map_get(stash, key);
+ if (!stashed) {
+ stashed = knot_rrset_copy(rr, pool);
+ if (!stashed) {
+ return kr_error(ENOMEM);
+ }
+ return map_set(stash, key, stashed);
+ }
+ /* Merge rdataset */
+ return knot_rdataset_merge(&stashed->rrs, &rr->rrs, pool);
+}
#include <sys/time.h>
#include <netinet/in.h>
#include <libknot/packet/pkt.h>
+#include "lib/generic/map.h"
/*
* General-purpose attributes.
* @warning 'dst' must be at least `sizeof(struct in6_addr)` long. */
int kr_straddr_subnet(void *dst, const char *addr);
/** Compare memory bitwise. */
-int kr_bitcmp(const char *a, const char *b, int bits);
\ No newline at end of file
+int kr_bitcmp(const char *a, const char *b, int bits);
+
+/** @internal RR map flags. */
+#define KEY_FLAG_NO 0x01
+#define KEY_FLAG_RRSIG 0x02
+#define KEY_COVERING_RRSIG(key) (key[0] & KEY_FLAG_RRSIG)
+
+/** @internal Merges RRSets with matching owner name and type together.
+ * @note RRSIG RRSets are merged according the type covered fields.
+ * @return 0 or an error
+ */
+int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool);
\ No newline at end of file