This file contains domain name handling functions. More...
#include "config.h"#include <ctype.h>#include "util/data/dname.h"#include "util/data/msgparse.h"#include "util/log.h"#include "util/storage/lookup3.h"Functions | |
| size_t | query_dname_len (ldns_buffer *query) |
| Determine length of dname in buffer, no compression ptrs allowed,. | |
| size_t | dname_valid (uint8_t *dname, size_t maxlen) |
| Determine if dname in memory is correct. | |
| int | query_dname_compare (register uint8_t *d1, register uint8_t *d2) |
| compare uncompressed, noncanonical, registers are hints for speed | |
| void | query_dname_tolower (uint8_t *dname) |
| lowercase query dname | |
| void | pkt_dname_tolower (ldns_buffer *pkt, uint8_t *dname) |
| lowercase pkt dname (follows compression pointers) | |
| size_t | pkt_dname_len (ldns_buffer *pkt) |
| Determine correct, compressed, dname present in packet. | |
| int | dname_pkt_compare (ldns_buffer *pkt, uint8_t *d1, uint8_t *d2) |
| Compare dnames in packet (compressed). | |
| hashvalue_t | dname_query_hash (uint8_t *dname, hashvalue_t h) |
| Hash dname, label by label, lowercasing, into hashvalue. | |
| hashvalue_t | dname_pkt_hash (ldns_buffer *pkt, uint8_t *dname, hashvalue_t h) |
| Hash dname, label by label, lowercasing, into hashvalue. | |
| void | dname_pkt_copy (ldns_buffer *pkt, uint8_t *to, uint8_t *dname) |
| Copy over a valid dname and decompress it. | |
| void | dname_print (FILE *out, ldns_buffer *pkt, uint8_t *dname) |
| Debug helper. | |
| int | dname_count_labels (uint8_t *dname) |
| Count the number of labels in an uncompressed dname in memory. | |
| int | dname_count_size_labels (uint8_t *dname, size_t *size) |
| Count labels and dname length both, for uncompressed dname in memory. | |
| static int | memlowercmp (uint8_t *p1, uint8_t *p2, uint8_t len) |
| Compare labels in memory, lowercase while comparing. | |
| int | dname_lab_cmp (uint8_t *d1, int labs1, uint8_t *d2, int labs2, int *mlabs) |
| Compare dnames, sorted not canonical, but by label. | |
| int | dname_buffer_write (ldns_buffer *pkt, uint8_t *dname) |
| Copy over a valid dname to a packet. | |
| void | dname_str (uint8_t *dname, char *str) |
| Debug helper. | |
| int | dname_strict_subdomain (uint8_t *d1, int labs1, uint8_t *d2, int labs2) |
| See if domain name d1 is a strict subdomain of d2. | |
| int | dname_strict_subdomain_c (uint8_t *d1, uint8_t *d2) |
| Like dname_strict_subdomain but counts labels. | |
| int | dname_subdomain_c (uint8_t *d1, uint8_t *d2) |
| Counts labels. | |
| int | dname_is_root (uint8_t *dname) |
| Returns true if the uncompressed wireformat dname is the root ".". | |
| void | dname_remove_label (uint8_t **dname, size_t *len) |
| Snip off first label from a dname, returning the parent zone. | |
| void | dname_remove_labels (uint8_t **dname, size_t *len, int n) |
| Snip off first N labels from a dname, returning the parent zone. | |
| int | dname_signame_label_count (uint8_t *dname) |
| Count labels for the RRSIG signature label field. | |
| int | dname_is_wild (uint8_t *dname) |
| Return true if the label is a wildcard, *.example.com. | |
| static int | memcanoncmp (uint8_t *p1, uint8_t len1, uint8_t *p2, uint8_t len2) |
| Compare labels in memory, lowercase while comparing. | |
| int | dname_canon_lab_cmp (uint8_t *d1, int labs1, uint8_t *d2, int labs2, int *mlabs) |
| Compare dnames, Canonical in rfc4034 sense, but by label. | |
| int | dname_canonical_compare (uint8_t *d1, uint8_t *d2) |
| Canonical dname compare. | |
| uint8_t * | dname_get_shared_topdomain (uint8_t *d1, uint8_t *d2) |
| Get the shared topdomain between two names. | |
This file contains domain name handling functions.
| size_t query_dname_len | ( | ldns_buffer * | query | ) |
Determine length of dname in buffer, no compression ptrs allowed,.
| query,: | the ldns buffer, current position at start of dname. at end, position is at end of the dname. |
Referenced by chaos_replystr(), dname_test_qdl(), and query_info_parse().
| size_t dname_valid | ( | uint8_t * | dname, |
| size_t | len | ||
| ) |
Determine if dname in memory is correct.
no compression ptrs allowed.
| dname,: | where dname starts in memory. |
| len,: | dname is not allowed to exceed this length (i.e. of allocation). |
Referenced by delegpt_rrset_add_ns(), sanitize_nsec_is_overreach(), dname_test_valid(), get_cname_target(), wipeout(), nsec_has_type(), nsec_get_next(), canonicalize_rdata(), dnskey_verify_rrset_sig(), and rrsig_get_signer().
| void pkt_dname_tolower | ( | ldns_buffer * | pkt, |
| uint8_t * | dname | ||
| ) |
lowercase pkt dname (follows compression pointers)
| pkt,: | the packet, used to follow compression pointers. Position is unchanged. |
| dname,: | start of dname in packet. |
References LABEL_IS_PTR, PTR_OFFSET, and MAX_COMPRESS_PTRS.
Referenced by serviced_callbacks(), and dname_test_pdtl().
| size_t pkt_dname_len | ( | ldns_buffer * | pkt | ) |
Determine correct, compressed, dname present in packet.
Checks for parse errors.
| pkt,: | packet to read from (from current start position). |
References LABEL_IS_PTR, PTR_OFFSET, and MAX_COMPRESS_PTRS.
Referenced by get_additional_name(), analyze_dname(), dname_test_pkt_dname_len(), nsec_at_apex(), parse_query_section(), calc_size(), parse_section(), parse_edns_from_pkt(), and rdata_copy().
| int dname_pkt_compare | ( | ldns_buffer * | pkt, |
| uint8_t * | d1, | ||
| uint8_t * | d2 | ||
| ) |
Compare dnames in packet (compressed).
Dnames must be valid. routine performs lowercasing, so the packet casing is preserved.
| pkt,: | packet, used to resolve compression pointers. |
| d1,: | dname to compare |
| d2,: | dname to compare |
References log_assert, LABEL_IS_PTR, and PTR_OFFSET.
Referenced by scrub_normalize(), scrub_sanitize(), scrub_message(), smart_compare(), and rrset_parse_equals().
| hashvalue_t dname_query_hash | ( | uint8_t * | dname, |
| hashvalue_t | h | ||
| ) |
Hash dname, label by label, lowercasing, into hashvalue.
Dname in query format (not compressed).
| dname,: | dname to hash. |
| h,: | initial hash value. |
References log_assert.
Referenced by hash_infra(), query_info_hash(), rrset_key_hash(), and key_entry_hash().
| hashvalue_t dname_pkt_hash | ( | ldns_buffer * | pkt, |
| uint8_t * | dname, | ||
| hashvalue_t | h | ||
| ) |
Hash dname, label by label, lowercasing, into hashvalue.
Dname in pkt format (compressed).
| pkt,: | packet, for resolving compression pointers. |
| dname,: | dname to hash, pointer to the pkt buffer. Must be valid format. No loops, etc. |
| h,: | initial hash value. |
References LABEL_IS_PTR, PTR_OFFSET, and log_assert.
Referenced by pkt_hash_rrset(), and pkt_hash_rrset_first().
| void dname_pkt_copy | ( | ldns_buffer * | pkt, |
| uint8_t * | to, | ||
| uint8_t * | dname | ||
| ) |
Copy over a valid dname and decompress it.
| pkt,: | packet to resolve compression pointers. |
| to,: | buffer of size from pkt_len function to hold result. |
| dname,: | pointer into packet where dname starts. |
References LABEL_IS_PTR, PTR_OFFSET, log_assert, and log_err().
Referenced by priv_lookup_name(), remove_rrset(), synth_cname(), synth_cname_rrset(), pkt_strict_sub(), pkt_sub(), sub_of_pkt(), parse_create_qinfo(), rdata_copy(), and parse_copy_decompress_rrset().
| void dname_print | ( | FILE * | out, |
| ldns_buffer * | pkt, | ||
| uint8_t * | dname | ||
| ) |
Debug helper.
Print wireformat dname to output.
| out,: | like stdout or a file. |
| pkt,: | if not NULL, the packet for resolving compression ptrs. |
| dname,: | pointer to (start of) dname. |
References LABEL_IS_PTR, and PTR_OFFSET.
Referenced by analyze_dname(), print_neg_cache(), and parse_section().
| int dname_count_labels | ( | uint8_t * | dname | ) |
Count the number of labels in an uncompressed dname in memory.
| dname,: | pointer to uncompressed dname. |
Referenced by iter_msg_from_zone(), local_zones_answer(), dname_test_count_labels(), dname_strict_subdomain_c(), dname_subdomain_c(), dname_canonical_compare(), dname_get_shared_topdomain(), packed_rrset_encode(), insert_query(), autr_tp_create(), find_add_tp(), set_next_probe(), anchors_lookup(), neg_find_zone(), neg_create_zone(), wipeout(), neg_insert_data(), val_neg_dlvlookup(), val_neg_getmsg(), nsec_closest_encloser(), val_nsec_proves_no_wc(), dlv_topdomain(), next_closer(), val_find_best_signer(), val_rrset_wildcard(), and processFindKey().
| int dname_count_size_labels | ( | uint8_t * | dname, |
| size_t * | size | ||
| ) |
Count labels and dname length both, for uncompressed dname in memory.
| dname,: | pointer to uncompressed dname. |
| size,: | length of dname, including root label. |
Referenced by parse_arg_name(), delegpt_set_name(), delegpt_add_ns(), make_stub_holes(), forwards_lookup(), forwards_delete_zone(), hints_lookup_stub(), read_names(), priv_lookup_name(), parse_dname(), lz_enter_rr_into_zone(), lz_enter_rr_str(), lz_setup_implicit(), local_zones_add_RR(), write_q(), dname_test_count_size_labels(), compress_rdata(), anchor_store_new_key(), wipeout(), nsec3_prove_wildcard(), and val_find_best_signer().
| static int memlowercmp | ( | uint8_t * | p1, |
| uint8_t * | p2, | ||
| uint8_t | len | ||
| ) | [static] |
Compare labels in memory, lowercase while comparing.
| p1,: | label 1 |
| p2,: | label 2 |
| len,: | number of bytes to compare. |
Referenced by memcanoncmp().
| int dname_lab_cmp | ( | uint8_t * | d1, |
| int | labs1, | ||
| uint8_t * | d2, | ||
| int | labs2, | ||
| int * | mlabs | ||
| ) |
Compare dnames, sorted not canonical, but by label.
Such that zone contents follows zone apex.
| d1,: | first dname. pointer to uncompressed wireformat. |
| labs1,: | number of labels in first dname. |
| d2,: | second dname. pointer to uncompressed wireformat. |
| labs2,: | number of labels in second dname. |
| mlabs,: | number of labels that matched exactly (the shared topdomain). |
References log_assert.
Referenced by fwd_cmp(), fwd_init_parents(), forwards_lookup(), local_zone_cmp(), init_parents(), lz_setup_implicit(), local_zones_lookup(), dname_test_dname_lab_cmp(), dname_strict_subdomain(), dname_subdomain_c(), dname_get_shared_topdomain(), compress_tree_search(), name_tree_compare(), name_tree_init_parents(), name_tree_lookup(), anchor_cmp(), anchors_init_parents_locked(), anchors_lookup(), neg_closest_zone_parent(), neg_closest_data_parent(), and val_find_best_signer().
| int dname_buffer_write | ( | ldns_buffer * | pkt, |
| uint8_t * | dname | ||
| ) |
Copy over a valid dname to a packet.
| pkt,: | packet to copy to. |
| dname,: | dname to copy. |
Referenced by compress_any_dname().
| void dname_str | ( | uint8_t * | dname, |
| char * | str | ||
| ) |
Debug helper.
Print dname to given string buffer (string buffer must be at least 255 chars + 1 for the 0, in printable form. This may lose information (? for nonprintable characters, or & if the name is too long, # for a bad label length).
| dname,: | uncompressed wireformat. |
| str,: | buffer of 255+1 length. |
Referenced by print_deleg_lookup(), ssl_print_name_dp(), get_mesh_status(), do_dump_requestlist(), dump_infra_host(), do_list_local_zones(), delegpt_log(), fill_canon(), serviced_perturb_qname(), outnet_serviced_query(), print_neg_cache(), errinf_to_str(), errinf_rrset(), errinf_dname(), log_nametypeclass(), log_name_addr(), autr_debug_print_tp(), and anchors_assemble_rrsets().
| int dname_strict_subdomain | ( | uint8_t * | d1, |
| int | labs1, | ||
| uint8_t * | d2, | ||
| int | labs2 | ||
| ) |
See if domain name d1 is a strict subdomain of d2.
That is a subdomain, but not equal.
| d1,: | domain name, uncompressed wireformat |
| labs1,: | number of labels in d1, including root label. |
| d2,: | domain name, uncompressed wireformat |
| labs2,: | number of labels in d2, including root label. |
References dname_lab_cmp().
Referenced by hints_lookup_stub(), iter_msg_from_zone(), set_kiddo_parents(), is_terminal(), dname_test_strict_subdomain(), and dname_strict_subdomain_c().
| int dname_strict_subdomain_c | ( | uint8_t * | d1, |
| uint8_t * | d2 | ||
| ) |
Like dname_strict_subdomain but counts labels.
| d1,: | domain name, uncompressed wireformat |
| d2,: | domain name, uncompressed wireformat |
References dname_strict_subdomain(), and dname_count_labels().
Referenced by response_type_from_server(), pkt_strict_sub(), handle_cname_response(), processQueryResponse(), nsec_proves_nodata(), val_nsec_proves_name_error(), val_nsec_proves_insecuredelegation(), val_nsec_check_dlv(), and processInit().
| int dname_subdomain_c | ( | uint8_t * | d1, |
| uint8_t * | d2 | ||
| ) |
Counts labels.
Tests is d1 is a subdomain of d2.
| d1,: | domain name, uncompressed wireformat |
| d2,: | domain name, uncompressed wireformat |
References dname_count_labels(), and dname_lab_cmp().
Referenced by zone_del_rrset(), zone_del_msg(), zone_del_kcache(), response_type_from_server(), pkt_sub(), sub_of_pkt(), sanitize_nsec_is_overreach(), iter_dp_is_useless(), iter_scrub_ds(), generate_parentside_target_query(), processQueryResponse(), dname_test_subdomain(), sum_subtree_inuse(), sum_zone_subtree_inuse(), wipeout(), val_neg_addreply(), val_neg_addreferral(), val_neg_getmsg(), val_nsec_proves_name_error(), val_nsec_proves_insecuredelegation(), filter_init(), nsec3_find_closest_encloser(), dnskey_verify_rrset_sig(), val_find_best_signer(), val_mark_insecure(), processInit(), processFindKey(), val_dlv_init(), processDLVLookup(), and process_dlv_response().
| int dname_is_root | ( | uint8_t * | dname | ) |
Returns true if the uncompressed wireformat dname is the root ".".
| dname,: | the dname to check |
References log_assert, and LABEL_IS_PTR.
Referenced by print_deleg_lookup(), forwards_next_root(), prime_stub(), forward_request(), processInitRequest(), dns_cache_lookup(), del_empty_term(), dname_test_isroot(), check_data(), check_zone_invariants(), name_tree_next_root(), key_cache_obtain(), calc_data_need(), calc_zone_need(), nsec_proves_nodata(), filter_init(), and nsec3_do_prove_nodata().
| void dname_remove_label | ( | uint8_t ** | dname, |
| size_t * | len | ||
| ) |
Snip off first label from a dname, returning the parent zone.
| dname,: | from what to strip off. uncompressed wireformat. |
| len,: | length, adjusted to become less. |
References log_assert, and LABEL_IS_PTR.
Referenced by print_deleg_lookup(), need_hole_insert(), prime_stub(), forward_request(), processInitRequest(), dns_cache_lookup(), lz_find_create_node(), del_empty_term(), dname_test_removelabel(), dname_remove_labels(), key_cache_obtain(), calc_data_need(), calc_zone_need(), neg_zone_chain(), neg_data_chain(), neg_find_nsec3_ce(), val_neg_getmsg(), nsec_proves_nodata(), val_nsec_check_dlv(), nsec3_get_nextowner_b32(), filter_next(), filter_init(), nsec3_find_closest_encloser(), insert_can_owner(), processInit(), val_dlv_init(), and processDLVLookup().
| void dname_remove_labels | ( | uint8_t ** | dname, |
| size_t * | len, | ||
| int | n | ||
| ) |
Snip off first N labels from a dname, returning the parent zone.
| dname,: | from what to strip off. uncompressed wireformat. |
| len,: | length, adjusted to become less. |
| n,: | number of labels to strip off (from the left). if 0, nothing happens. |
References dname_remove_label().
Referenced by lz_setup_implicit(), dname_get_shared_topdomain(), val_nsec_proves_no_wc(), dlv_topdomain(), next_closer(), val_rrset_wildcard(), and processFindKey().
| int dname_signame_label_count | ( | uint8_t * | dname | ) |
Count labels for the RRSIG signature label field.
Like a normal labelcount, but "*" wildcard and "." root are not counted.
| dname,: | valid uncompressed wireformat. |
Referenced by dname_test_sigcount(), insert_can_owner(), and dnskey_verify_rrset_sig().
| int dname_is_wild | ( | uint8_t * | dname | ) |
Return true if the label is a wildcard, *.example.com.
| dname,: | valid uncompressed wireformat. |
Referenced by dname_test_iswild(), val_nsec_prove_nodata_dsreply(), nsec_proves_nodata(), and val_rrset_wildcard().
| static int memcanoncmp | ( | uint8_t * | p1, |
| uint8_t | len1, | ||
| uint8_t * | p2, | ||
| uint8_t | len2 | ||
| ) | [static] |
Compare labels in memory, lowercase while comparing.
Returns canonical order for labels. If all is equal, the shortest is first.
| p1,: | label 1 |
| len1,: | length of label 1. |
| p2,: | label 2 |
| len2,: | length of label 2. |
References memlowercmp().
Referenced by dname_canon_lab_cmp().
| int dname_canon_lab_cmp | ( | uint8_t * | d1, |
| int | labs1, | ||
| uint8_t * | d2, | ||
| int | labs2, | ||
| int * | mlabs | ||
| ) |
Compare dnames, Canonical in rfc4034 sense, but by label.
Such that zone contents follows zone apex.
| d1,: | first dname. pointer to uncompressed wireformat. |
| labs1,: | number of labels in first dname. |
| d2,: | second dname. pointer to uncompressed wireformat. |
| labs2,: | number of labels in second dname. |
| mlabs,: | number of labels that matched exactly (the shared topdomain). |
References log_assert, and memcanoncmp().
Referenced by local_data_cmp(), dname_canonical_compare(), val_neg_data_compare(), val_neg_zone_compare(), and wipeout().
| int dname_canonical_compare | ( | uint8_t * | d1, |
| uint8_t * | d2 | ||
| ) |
Canonical dname compare.
Takes care of counting labels. Per rfc 4034 canonical order.
| d1,: | first dname. pointer to uncompressed wireformat. |
| d2,: | second dname. pointer to uncompressed wireformat. |
References dname_count_labels(), and dname_canon_lab_cmp().
Referenced by dname_test_canoncmp(), nsec_proves_nodata(), val_nsec_proves_name_error(), and val_nsec_check_dlv().
| uint8_t* dname_get_shared_topdomain | ( | uint8_t * | d1, |
| uint8_t * | d2 | ||
| ) |
Get the shared topdomain between two names.
Root "." or longer.
| d1,: | first dname. pointer to uncompressed wireformat. |
| d2,: | second dname. pointer to uncompressed wireformat. |
References dname_count_labels(), dname_lab_cmp(), and dname_remove_labels().
Referenced by dname_test_topdomain(), nsec_closest_encloser(), and dlv_topdomain().