]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
layer/validate: fix duplicate records in AUTHORITY section in case of WC expansion...
authorGrigorii Demidov <grigorii.demidov@nic.cz>
Mon, 27 Feb 2017 12:19:48 +0000 (13:19 +0100)
committerGrigorii Demidov <grigorii.demidov@nic.cz>
Mon, 27 Feb 2017 12:19:48 +0000 (13:19 +0100)
lib/layer/validate.c
lib/utils.c
lib/utils.h

index e4e99c9211c14cf059341a51986d1ea3ac656592..1b9dd5d3e0f7e8050ed97e8cd95114257d537a0d 100644 (file)
@@ -710,7 +710,7 @@ static int validate(kr_layer_t *ctx, knot_pkt_t *pkt)
        /* Check if wildcard expansion detected for final query.
         * If yes, copy authority. */
        if ((qry->parent == NULL) && (qry->flags & QUERY_DNSSEC_WEXPAND)) {
-               kr_ranked_rrarray_set_wire(&req->auth_selected, true, qry->uid);
+               kr_ranked_rrarray_set_wire(&req->auth_selected, true, qry->uid, true);
        }
 
        /* Check and update current delegation point security status. */
index 7d59e7f266e88b295a728c17506b387d27b3e4f3..af1b4dbd841035e7d147d2b0b836a006e1c8a440 100644 (file)
@@ -493,12 +493,33 @@ int kr_ranked_rrarray_add(ranked_rr_array_t *array, const knot_rrset_t *rr,
        return kr_ok();
 }
 
-int kr_ranked_rrarray_set_wire(ranked_rr_array_t *array, bool to_wire, uint32_t qry_uid)
+int kr_ranked_rrarray_set_wire(ranked_rr_array_t *array, bool to_wire,
+                              uint32_t qry_uid, bool check_dups)
 {
        for (size_t i = 0; i < array->len; ++i) {
                ranked_rr_array_entry_t *entry = array->at[i];
-               if (entry->qry_uid == qry_uid) {
-                       entry->to_wire = to_wire;
+               if (entry->qry_uid != qry_uid) {
+                       continue;
+               }
+               entry->to_wire = to_wire;
+               if (!check_dups) {
+                       continue;
+               }
+               knot_rrset_t *rr = entry->rr;
+               for (size_t j = 0; j < array->len; ++j) {
+                       ranked_rr_array_entry_t *stashed = array->at[j];
+                       if (stashed->qry_uid == qry_uid) {
+                               continue;
+                       }
+                       if (stashed->rr->rclass != rr->rclass ||
+                           stashed->rr->type != rr->type) {
+                               continue;
+                       }
+                       bool is_equal = knot_rrset_equal(rr, stashed->rr,
+                                                        KNOT_RRSET_COMPARE_WHOLE);
+                       if (is_equal && to_wire) {
+                               stashed->to_wire = false;
+                       }
                }
        }
        return kr_ok();
index 041edc017c84c684d41ee22437545349b9b49f85..e2224413e6b492fa415c6ac6341dee4be2120bdf 100644 (file)
@@ -193,7 +193,8 @@ int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, knot_mm_t *pool);
 int kr_ranked_rrarray_add(ranked_rr_array_t *array, const knot_rrset_t *rr,
                          uint8_t rank, bool to_wire, uint32_t qry_uid, knot_mm_t *pool);
 
-int kr_ranked_rrarray_set_wire(ranked_rr_array_t *array, bool to_wire, uint32_t qry_uid);
+int kr_ranked_rrarray_set_wire(ranked_rr_array_t *array, bool to_wire,
+                              uint32_t qry_uid, bool check_dups);
 
 void kr_rrset_print(const knot_rrset_t *rr, const char *prefix);
 void kr_pkt_print(knot_pkt_t *pkt);