along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include <libknot/descriptor.h>
-#include <libknot/rrtype/rdname.h>
-#include <libknot/packet/wire.h>
-#include <libknot/descriptor.h>
-
#include "lib/zonecut.h"
-#include "lib/rplan.h"
+
#include "contrib/cleanup.h"
#include "lib/defines.h"
+#include "lib/generic/pack.h"
#include "lib/layer.h"
#include "lib/resolve.h"
-#include "lib/generic/pack.h"
+#include "lib/rplan.h"
+
+#include <libknot/descriptor.h>
+#include <libknot/packet/wire.h>
+#include <libknot/rrtype/rdname.h>
#define VERBOSE_MSG(qry, fmt...) QRVERBOSE(qry, "zcut", fmt)
* LATER: we might be interested whether it's only glue. */
} addrset_info_t;
-/* Root hint descriptor. */
-struct hint_info {
- const knot_dname_t *name;
- size_t len;
- const uint8_t *addr;
-};
-
-#define U8(x) (const uint8_t *)(x)
static void update_cut_name(struct kr_zonecut *cut, const knot_dname_t *name)
{
return kr_error(EINVAL);
}
+ memset(cut, 0, sizeof(*cut));
cut->name = knot_dname_copy(name, pool);
cut->pool = pool;
- cut->key = NULL;
- cut->trust_anchor = NULL;
- cut->parent = NULL;
cut->nsset = trie_create(pool);
return cut->name && cut->nsset ? kr_ok() : kr_error(ENOMEM);
}
trie_apply(cut->nsset, free_addr_set_cb, cut->pool);
trie_clear(cut->nsset);
- update_cut_name(cut, U8(""));
+ const uint8_t *const dname_root = (const uint8_t *)/*sign-cast*/("");
+ update_cut_name(cut, dname_root);
/* Copy root hints from resolution context. */
return kr_zonecut_copy(cut, &ctx->root_hints);
}
const knot_dname_t *name, const struct kr_query *qry,
bool * restrict secured)
{
- //VERBOSE_MSG(qry, "_find_cached\n");
if (!ctx || !cut || !name) {
+ //assert(false);
return kr_error(EINVAL);
}
+ /* I'm not sure whether the caller always passes a clean state;
+ * mixing doesn't seem to make sense in any case, so let's clear it.
+ * We don't bother freeing the packs, as they're on mempool. */
+ trie_clear(cut->nsset);
/* Copy name as it may overlap with cut name that is to be replaced. */
knot_dname_t *qname = knot_dname_copy(name, cut->pool);
if (!qname) {
return kr_error(ENOMEM);
}
- /* Start at QNAME parent. */
+ /* Start at QNAME. */
+ int ret;
const knot_dname_t *label = qname;
while (true) {
/* Fetch NS first and see if it's insecure. */
uint8_t rank = 0;
const bool is_root = (label[0] == '\0');
- if (fetch_ns(ctx, cut, label, qry, &rank) == 0) {
+ ret = fetch_ns(ctx, cut, label, qry, &rank);
+ if (ret == 0) {
/* Flag as insecure if cached as this */
if (kr_rank_test(rank, KR_RANK_INSECURE)) {
*secured = false;
label, KNOT_RRTYPE_DNSKEY, cut->pool, qry);
}
update_cut_name(cut, label);
- mm_free(cut->pool, qname);
- kr_cache_sync(&ctx->cache);
WITH_VERBOSE(qry) {
auto_free char *label_str = kr_dname_text(label);
VERBOSE_MSG(qry,
"found cut: %s (rank 0%.2o return codes: DS %d, DNSKEY %d)\n",
label_str, rank, ret_ds, ret_dnskey);
}
- return kr_ok();
- }
+ ret = kr_ok();
+ break;
+ } /* else */
+
+ trie_clear(cut->nsset);
/* Subtract label from QNAME. */
if (!is_root) {
label = knot_wire_next_label(label, NULL);
} else {
+ ret = kr_error(ENOENT);
break;
}
}
+
kr_cache_sync(&ctx->cache);
mm_free(cut->pool, qname);
- return kr_error(ENOENT);
+ return ret;
}