From: Vladimír Čunát Date: Fri, 31 Mar 2017 15:46:56 +0000 (+0200) Subject: util: add kr_rrset_type_maysig(knot_rrset_t *) X-Git-Tag: v1.3.0~23^2~39^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff4b59a55824be475160bf13ee4d8ab8d615c6f5;p=thirdparty%2Fknot-resolver.git util: add kr_rrset_type_maysig(knot_rrset_t *) Also correct a tiny bug where iterator didn't skip RRSIGs that covered non-interesting types of the name we desired. --- diff --git a/lib/layer/iterate.c b/lib/layer/iterate.c index 539d6c3c4..4956e6c80 100644 --- a/lib/layer/iterate.c +++ b/lib/layer/iterate.c @@ -398,12 +398,10 @@ static int unroll_cname(knot_pkt_t *pkt, struct kr_request *req, bool referral, const knot_rrset_t *rr = knot_pkt_rr(an, i); /* Skip the RR if its owner+type doesn't interest us. */ - const bool type_OK = rr->type == query->stype - || rr->type == KNOT_RRTYPE_CNAME - || rr->type == KNOT_RRTYPE_DNAME /* TODO: actually handle it */ - || (rr->type == KNOT_RRTYPE_RRSIG - && knot_rrsig_type_covered(&rr->rrs, 0)) - ; + const uint16_t type = kr_rrset_type_maysig(rr); + const bool type_OK = rr->type == query->stype || type == query->stype + || type == KNOT_RRTYPE_CNAME || type == KNOT_RRTYPE_DNAME; + /* TODO: actually handle DNAMEs */ if (!type_OK || !knot_dname_is_equal(rr->owner, cname)) { continue; } diff --git a/lib/layer/rrcache.c b/lib/layer/rrcache.c index e7f3a0f85..263c517ca 100644 --- a/lib/layer/rrcache.c +++ b/lib/layer/rrcache.c @@ -313,9 +313,7 @@ static int stash_authority(struct kr_request *req, knot_pkt_t *pkt, map_t *stash /* Skip NSEC3 RRs and their signatures. We don't use them this way. * They would be stored under the hashed name, etc. */ - if (rr->type == KNOT_RRTYPE_NSEC3 - || (rr->type == KNOT_RRTYPE_RRSIG - && knot_rrsig_type_covered(&rr->rrs, 0) == KNOT_RRTYPE_NSEC3)) { + if (kr_rrset_type_maysig(rr) == KNOT_RRTYPE_NSEC3) { continue; } diff --git a/lib/utils.c b/lib/utils.c index 0db488bff..c528c6dd4 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -429,11 +429,10 @@ int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, knot_mm_t * /* Stash key = {[1] flags, [1-255] owner, [5] type, [1] \x00 } */ char key[KR_RRKEY_LEN]; uint8_t extra_flags = 0; - uint16_t rrtype = rr->type; + uint16_t rrtype = kr_rrset_type_maysig(rr); /* 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); extra_flags |= KEY_FLAG_RRSIG; } int ret = kr_rrkey(key, rr->owner, rrtype, rank); diff --git a/lib/utils.h b/lib/utils.h index da87e64c5..59b1e3cfb 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -21,7 +21,10 @@ #include #include #include +#include #include +#include +#include #include "lib/generic/map.h" #include "lib/generic/array.h" #include "lib/defines.h" @@ -240,3 +243,12 @@ char *kr_module_call(struct kr_context *ctx, const char *module, const char *pro memcpy(&x, swap_temp, sizeof(x)); \ } while(0) +/** Return the (covered) type of an nonempty RRset. */ +static inline uint16_t kr_rrset_type_maysig(const knot_rrset_t *rr) +{ + assert(rr && rr->rrs.rr_count && rr->rrs.data); + uint16_t type = rr->type; + if (type == KNOT_RRTYPE_RRSIG) + type = knot_rrsig_type_covered(&rr->rrs, 0); + return type; +}