]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
layer/pktcache: don't cache CNAME'ed negative answer when forwarding
authorGrigorii Demidov <grigorii.demidov@nic.cz>
Thu, 22 Jun 2017 09:21:01 +0000 (11:21 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 23 Jun 2017 08:50:13 +0000 (10:50 +0200)
it can contain records which have not been validated by validator

lib/layer/pktcache.c

index 0d1179dcf2ff95ddb264fa99f0d66d65f6d00a70..777e8e1e27f2a09c670265ff12d5b24d84db2214 100644 (file)
@@ -229,8 +229,16 @@ static int pktcache_stash(kr_layer_t *ctx, knot_pkt_t *pkt)
        /* Cache only NODATA/NXDOMAIN or metatype/RRSIG or wildcard expanded answers. */
        const uint16_t qtype = knot_pkt_qtype(pkt);
        const bool is_eligible = (knot_rrtype_is_metatype(qtype) || qtype == KNOT_RRTYPE_RRSIG);
-       const bool is_negative = kr_response_classify(pkt) & (PKT_NODATA|PKT_NXDOMAIN);
-       if (!(is_eligible || is_negative || (qry->flags & QUERY_DNSSEC_WEXPAND))) {
+       bool is_negative = kr_response_classify(pkt) & (PKT_NODATA|PKT_NXDOMAIN);
+       bool wcard_expansion = (qry->flags & QUERY_DNSSEC_WEXPAND);
+       if (is_negative && ((qry->flags & (QUERY_FORWARD | QUERY_CNAME)) ==
+           (QUERY_FORWARD | QUERY_CNAME))) {
+               /* Don't cache CNAME'ed NXDOMAIN answer in forwarding mode
+                  since it can contain records
+                  which have not been validated by validator */
+               return ctx->state;
+       }
+       if (!(is_eligible || is_negative || wcard_expansion)) {
                return ctx->state;
        }
        uint32_t ttl = packet_ttl(pkt, is_negative);