From: Miek Gieben Date: Tue, 29 Nov 2005 14:23:40 +0000 (+0000) Subject: added helper function to deal with nsecs: ldns_nsec_type_check and ldns_dname_interval X-Git-Tag: release-1.1.0~595 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96f44ffd0d416a9cf30a020d7cd4be1c4bf33276;p=thirdparty%2Fldns.git added helper function to deal with nsecs: ldns_nsec_type_check and ldns_dname_interval --- diff --git a/drill/chasetrace.c b/drill/chasetrace.c index 0b311f60..cf88ad1c 100644 --- a/drill/chasetrace.c +++ b/drill/chasetrace.c @@ -118,19 +118,15 @@ do_trace(ldns_resolver *local_res, ldns_rdf *name, ldns_rr_type t, * no nameserver found!!! * try to resolve the names we do got */ - printf("nameserver %d\n", ldns_rr_list_rr_count(new_nss)); for(i = 0; i < ldns_rr_list_rr_count(new_nss); i++) { /* get the name of the nameserver */ pop = ldns_rr_rdf(ldns_rr_list_rr(new_nss, i), 0); - printf("pop %p\n", pop); if (!pop) { break; } ldns_rr_list_print(stdout, new_nss); - printf("pop -- "); ldns_rdf_print(stdout, pop); - printf("\n"); /* retrieve it's addresses */ ns_addr = ldns_rr_list_cat_clone(ns_addr, ldns_get_rr_list_addr_by_name(local_res, pop, c, 0)); diff --git a/drill/drill.c b/drill/drill.c index e34a4c72..f388d7bb 100644 --- a/drill/drill.c +++ b/drill/drill.c @@ -367,9 +367,10 @@ main(int argc, char *argv[]) type = LDNS_RR_TYPE_A; } - /* if we're asking for DNSSEC record, act as if -D with given */ + /* if we're asking for DNSSEC records, act as if -D with given */ if (type == LDNS_RR_TYPE_DNSKEY || - type == LDNS_RR_TYPE_RRSIG || + type == LDNS_RR_TYPE_RRSIG || + type == LDNS_RR_TYPE_DS || type == LDNS_RR_TYPE_NSEC) { qdnssec = true; } diff --git a/drill/securetrace.c b/drill/securetrace.c index a183045c..47e2c5c9 100644 --- a/drill/securetrace.c +++ b/drill/securetrace.c @@ -62,7 +62,6 @@ do_secure_trace2(ldns_resolver *res, ldns_rdf *name, ldns_rr_type t, for(i = 1; i < 10 && chopped_dname[i - 1]; i++) { chopped_dname[i] = ldns_dname_left_chop(chopped_dname[i - 1]); } - printf("%d i\n", i); chopped_dname[i] = NULL; dname_labels = i - 2; /* set this also before this last NULL */ diff --git a/higher.c b/higher.c index 9ee3ace6..2cc75694 100644 --- a/higher.c +++ b/higher.c @@ -402,3 +402,36 @@ ldns_update_send_simple_addr(const char *fqdn, const char *zone, ldns_pkt_free(u_pkt); return LDNS_STATUS_ERR; } + +bool +ldns_nsec_type_check(ldns_rr *nsec, ldns_rr_type t) +{ + /* does the nsec cover the t given? */ + /* copied from host2str.c line 465: ldns_rdf2buffer_str_nsec */ + uint8_t window_block_nr; + uint8_t bitmap_length; + uint16_t type; + uint16_t pos = 0; + uint16_t bit_pos; + ldns_rdf *nsec_type_list = ldns_rr_rdf(nsec, 1); + uint8_t *data = ldns_rdf_data(nsec_type_list); + + while(pos < ldns_rdf_size(nsec_type_list)) { + window_block_nr = data[pos]; + bitmap_length = data[pos+1]; + pos += 2; + + for (bit_pos = 0; bit_pos < (bitmap_length) * 8; bit_pos++) { + if (ldns_get_bit(&data[pos], bit_pos)) { + type = 256 * (uint16_t) window_block_nr + bit_pos; + + if ((ldns_rr_type)type == t) { + /* we have a winner */ + return true; + } + } + } + pos += (uint16_t) bitmap_length; + } + return false; +} diff --git a/host2str.c b/host2str.c index a0c6feba..dd91a6fb 100644 --- a/host2str.c +++ b/host2str.c @@ -455,6 +455,9 @@ ldns_rdf2buffer_str_wks(ldns_buffer *output, ldns_rdf *rdf) ldns_status ldns_rdf2buffer_str_nsec(ldns_buffer *output, ldns_rdf *rdf) { + /* Note: this code is duplicated in higher.c in + * ldns_nsec_type_check() function + */ uint8_t window_block_nr; uint8_t bitmap_length; uint16_t type; diff --git a/ldns/higher.h b/ldns/higher.h index 27bac08a..3dbfbbdd 100644 --- a/ldns/higher.h +++ b/ldns/higher.h @@ -87,6 +87,14 @@ uint16_t ldns_getaddrinfo(ldns_resolver *res, ldns_rdf *node, ldns_rr_class c, l */ ldns_rr_list *ldns_getaddrinfo_secure(); +/** + * Check if t is enumerated in the nsec type rdata + * \param[in] nsec the NSEC Record to look in + * \param[in] t the type to check for + * \return true when t is found, otherwise return false + */ +bool ldns_nsec_type_check(ldns_rr *nsec, ldns_rr_type t); + /* * Send a "simple" update for an A or an AAAA RR. * \param[in] fqdn the update RR owner