]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- trustanchor tags are sorted. reusable routine to fetch taglist.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 16 Mar 2017 15:04:18 +0000 (15:04 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 16 Mar 2017 15:04:18 +0000 (15:04 +0000)
git-svn-id: file:///svn/unbound/trunk@4056 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/worker.c
doc/Changelog
validator/val_anchor.c
validator/val_anchor.h

index c2b7dc8e804c91d4faade369b750114f0bce5912..6f1f64647d365c46deb659a5abe1e5f3de0826c2 100644 (file)
@@ -785,8 +785,9 @@ static void
 chaos_trustanchor(sldns_buffer* pkt, struct edns_data* edns, struct worker* w)
 {
        int max_txt = 16;
-       int max_ids = 32;
+       int max_tags = 32;
        char* str_array[16];
+       uint16_t tags[32];
        int num = 0;
        struct trust_anchor* ta;
 
@@ -799,12 +800,15 @@ chaos_trustanchor(sldns_buffer* pkt, struct edns_data* edns, struct worker* w)
        /* fill the string with contents */
        lock_basic_lock(&w->env.anchors->lock);
        RBTREE_FOR(ta, struct trust_anchor*, w->env.anchors->tree) {
-               int numid = 0;
-               char* str = (char*)regional_alloc(w->scratchpad, 255);
+               int i, numtag;
+               char* str;
                size_t str_len = 255;
-               if(!str || num == max_txt) continue;
+               if(num == max_txt) continue;
+               str = (char*)regional_alloc(w->scratchpad, 255);
+               if(!str) continue;
                lock_basic_lock(&ta->lock);
-               if(ta->numDS == 0 && ta->numDNSKEY == 0) {
+               numtag = anchor_list_keytags(ta, tags, max_tags);
+               if(numtag == 0) {
                        /* empty, insecure point */
                        lock_basic_unlock(&ta->lock);
                        continue;
@@ -815,29 +819,10 @@ chaos_trustanchor(sldns_buffer* pkt, struct edns_data* edns, struct worker* w)
                /* spool name of anchor */
                (void)sldns_wire2str_dname_buf(ta->name, ta->namelen, str, str_len);
                str_len -= strlen(str); str += strlen(str);
-               /* spool DS */
-               if(ta->numDS != 0 && ta->ds_rrset) {
-                       struct packed_rrset_data* d=(struct packed_rrset_data*)
-                               ta->ds_rrset->entry.data;
-                       size_t i;
-                       for(i=0; i<d->count; i++) {
-                               uint16_t tag = ds_get_keytag(ta->ds_rrset, i);
-                               if(numid++ > max_ids) continue;
-                               snprintf(str, str_len, " %u", (unsigned)tag);
-                               str_len -= strlen(str); str += strlen(str);
-                       }
-               }
-               /* spool DNSKEY */
-               if(ta->numDNSKEY != 0 && ta->dnskey_rrset) {
-                       struct packed_rrset_data* d=(struct packed_rrset_data*)
-                               ta->dnskey_rrset->entry.data;
-                       size_t i;
-                       for(i=0; i<d->count; i++) {
-                               uint16_t tag = dnskey_calc_keytag(ta->dnskey_rrset, i);
-                               if(numid++ > max_ids) continue;
-                               snprintf(str, str_len, " %u", (unsigned)tag);
-                               str_len -= strlen(str); str += strlen(str);
-                       }
+               /* spool tags */
+               for(i=0; i<numtag; i++) {
+                       snprintf(str, str_len, " %u", (unsigned)tags[i]);
+                       str_len -= strlen(str); str += strlen(str);
                }
                lock_basic_unlock(&ta->lock);
        }
@@ -879,7 +864,7 @@ answer_chaos(struct worker* w, struct query_info* qinfo,
                                chaos_replystr(pkt, (char**)&"no hostname", 1, edns, w);
                        }
                }
-               else    chaos_replystr(pkt, &cfg->identity, 1, edns, w);
+               else    chaos_replystr(pkt, (char**)&cfg->identity, 1, edns, w);
                return 1;
        }
        if(query_dname_compare(qinfo->qname, 
index 54ac22d34468dc83bb1c0696f07e17f2d91faf83..7277d6e592ca7d21e98957609341760200eaeff0 100644 (file)
@@ -4,6 +4,7 @@
          of TXT RRs with a string like "example.com. 2345 1234" with
          the trust anchors and their keytags.
        - Fix that looped DNAMEs do not cause unbound to spend effort.
+       - trustanchor tags are sorted.  reusable routine to fetch taglist.
 
 13 March 2017: Wouter
        - testbound understands Deckard MATCH rcode question answer commands.
index 2a7e0beeb6c5decbf8a9393d1b6663291420de85..bd6a0da85bce659d484667ee0a4e10759543a244 100644 (file)
@@ -1273,3 +1273,37 @@ anchors_delete_insecure(struct val_anchors* anchors, uint16_t c,
        anchors_delfunc(&ta->node, NULL);
 }
 
+/** compare two keytags, return -1, 0 or 1 */
+static int
+keytag_compare(const void* x, const void* y)
+{
+       return *(uint16_t*)x - *(uint16_t*)y;
+}
+
+int
+anchor_list_keytags(struct trust_anchor* ta, uint16_t* list, int num)
+{
+       size_t i;
+       int ret = 0;
+       if(ta->numDS == 0 && ta->numDNSKEY == 0)
+               return 0; /* insecure point */
+       if(ta->numDS != 0 && ta->ds_rrset) {
+               struct packed_rrset_data* d=(struct packed_rrset_data*)
+                       ta->ds_rrset->entry.data;
+                       for(i=0; i<d->count; i++) {
+                               if(ret == num) continue;
+                               list[ret++] = ds_get_keytag(ta->ds_rrset, i);
+                       }
+       }
+       if(ta->numDNSKEY != 0 && ta->dnskey_rrset) {
+               struct packed_rrset_data* d=(struct packed_rrset_data*)
+                       ta->dnskey_rrset->entry.data;
+                       for(i=0; i<d->count; i++) {
+                               if(ret == num) continue;
+                               list[ret++] = dnskey_calc_keytag(
+                                       ta->dnskey_rrset, i);
+                       }
+       }
+       qsort(list, ret, sizeof(*list), keytag_compare);
+       return ret;
+}
index 226165514c5a55c86c61148a477539f784161e1f..76a7b54822734dd07d7d4c1872c565506d74bf8e 100644 (file)
@@ -216,4 +216,15 @@ int anchors_add_insecure(struct val_anchors* anchors, uint16_t c, uint8_t* nm);
 void anchors_delete_insecure(struct val_anchors* anchors, uint16_t c,
        uint8_t* nm);
 
+/**
+ * Get a list of keytags for the trust anchor.  Zero tags for insecure points.
+ * @param ta: trust anchor (locked by caller).
+ * @param list: array of uint16_t.
+ * @param num: length of array.
+ * @return number of keytags filled into array.  If total number of keytags is
+ * bigger than the array, it is truncated at num.  On errors, less keytags
+ * are filled in.  The array is sorted.
+ */
+int anchor_list_keytags(struct trust_anchor* ta, uint16_t* list, int num);
+
 #endif /* VALIDATOR_VAL_ANCHOR_H */