This file contains functions to deal with domain names (dnames). More...
#include "util/storage/lruhash.h"
Macros | |
#define | MAX_COMPRESS_PTRS 256 |
max number of compression ptrs to follow | |
Functions | |
size_t | query_dname_len (struct sldns_buffer *query) |
Determine length of dname in buffer, no compression ptrs allowed,. More... | |
size_t | dname_valid (uint8_t *dname, size_t len) |
Determine if dname in memory is correct. More... | |
void | query_dname_tolower (uint8_t *dname) |
lowercase query dname | |
void | pkt_dname_tolower (struct sldns_buffer *pkt, uint8_t *dname) |
lowercase pkt dname (follows compression pointers) More... | |
int | query_dname_compare (uint8_t *d1, uint8_t *d2) |
Compare query dnames (uncompressed storage). More... | |
size_t | pkt_dname_len (struct sldns_buffer *pkt) |
Determine correct, compressed, dname present in packet. More... | |
int | dname_pkt_compare (struct sldns_buffer *pkt, uint8_t *d1, uint8_t *d2) |
Compare dnames in packet (compressed). More... | |
hashvalue_type | dname_query_hash (uint8_t *dname, hashvalue_type h) |
Hash dname, label by label, lowercasing, into hashvalue. More... | |
hashvalue_type | dname_pkt_hash (struct sldns_buffer *pkt, uint8_t *dname, hashvalue_type h) |
Hash dname, label by label, lowercasing, into hashvalue. More... | |
void | dname_pkt_copy (struct sldns_buffer *pkt, uint8_t *to, uint8_t *dname) |
Copy over a valid dname and decompress it. More... | |
int | dname_buffer_write (struct sldns_buffer *pkt, uint8_t *dname) |
Copy over a valid dname to a packet. More... | |
int | dname_count_labels (uint8_t *dname) |
Count the number of labels in an uncompressed dname in memory. More... | |
int | dname_count_size_labels (uint8_t *dname, size_t *size) |
Count labels and dname length both, for uncompressed dname in memory. More... | |
int | dname_lab_cmp (uint8_t *d1, int labs1, uint8_t *d2, int labs2, int *mlabs) |
Compare dnames, sorted not canonical, but by label. More... | |
int | dname_lab_startswith (uint8_t *label, char *prefix, char **endptr) |
Check if labels starts with given prefix. More... | |
int | dname_has_label (uint8_t *dname, size_t dnamelen, uint8_t *label) |
Check if dname contains label. More... | |
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. More... | |
int | dname_strict_subdomain_c (uint8_t *d1, uint8_t *d2) |
Like dname_strict_subdomain but counts labels. More... | |
int | dname_subdomain_c (uint8_t *d1, uint8_t *d2) |
Counts labels. More... | |
void | dname_print (FILE *out, struct sldns_buffer *pkt, uint8_t *dname) |
Debug helper. More... | |
void | dname_str (uint8_t *dname, char *str) |
Debug helper. More... | |
int | dname_is_root (uint8_t *dname) |
Returns true if the uncompressed wireformat dname is the root ".". More... | |
void | dname_remove_label (uint8_t **dname, size_t *len) |
Snip off first label from a dname, returning the parent zone. More... | |
void | dname_remove_labels (uint8_t **dname, size_t *len, int n) |
Snip off first N labels from a dname, returning the parent zone. More... | |
int | dname_signame_label_count (uint8_t *dname) |
Count labels for the RRSIG signature label field. More... | |
int | dname_is_wild (uint8_t *dname) |
Return true if the label is a wildcard, *.example.com. More... | |
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. More... | |
int | dname_canonical_compare (uint8_t *d1, uint8_t *d2) |
Canonical dname compare. More... | |
uint8_t * | dname_get_shared_topdomain (uint8_t *d1, uint8_t *d2) |
Get the shared topdomain between two names. More... | |
This file contains functions to deal with domain names (dnames).
Some of the functions deal with domain names as a wireformat buffer, with a length.
size_t query_dname_len | ( | struct sldns_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. |
References LDNS_MAX_DOMAINLEN, sldns_buffer_read_u8(), sldns_buffer_remaining(), and sldns_buffer_skip().
Referenced by dname_test_qdl().
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). |
References LDNS_MAX_DOMAINLEN.
Referenced by az_add_additionals_from(), az_insert_rr_decompress(), az_remove_rr_decompress(), canonical_compare(), canonicalize_rdata(), delegpt_rrset_add_ns(), dname_test_valid(), follow_cname_chain(), nsec_get_next(), nsec_has_type(), parse_get_cname_target(), rrset_has_signer(), and rrsig_get_signer().
void pkt_dname_tolower | ( | struct sldns_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, MAX_COMPRESS_PTRS, PTR_OFFSET, sldns_buffer_at(), sldns_buffer_end(), and sldns_buffer_limit().
Referenced by dname_test_pdtl().
int query_dname_compare | ( | uint8_t * | d1, |
uint8_t * | d2 | ||
) |
Compare query dnames (uncompressed storage).
The Dnames passed do not have to be lowercased, comparison routine does this.
This routine is special, in that the comparison that it does corresponds with the canonical comparison needed when comparing dnames inside rdata for RR types that need canonicalization. That means that the first byte that is smaller (possibly after lowercasing) makes an RR smaller, or the shortest name makes an RR smaller.
This routine does not compute the canonical order needed for NSEC processing.
Dnames have to be valid format.
d1 | dname to compare |
d2 | dname to compare |
size_t pkt_dname_len | ( | struct sldns_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, LDNS_MAX_DOMAINLEN, MAX_COMPRESS_PTRS, PTR_OFFSET, sldns_buffer_limit(), sldns_buffer_position(), sldns_buffer_read_u8(), sldns_buffer_remaining(), sldns_buffer_set_position(), and sldns_buffer_skip().
Referenced by analyze_dname(), calc_size(), decompress_rr_into_buffer(), dname_test_pkt_dname_len(), nsec_at_apex(), parse_get_cname_target(), and skip_pkt_rr().
int dname_pkt_compare | ( | struct sldns_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 LABEL_IS_PTR, LDNS_MAX_LABELLEN, log_assert, MAX_COMPRESS_PTRS, PTR_OFFSET, sldns_buffer_at(), and sldns_buffer_limit().
Referenced by rrset_parse_equals(), and smart_compare().
hashvalue_type dname_query_hash | ( | uint8_t * | dname, |
hashvalue_type | h | ||
) |
Hash dname, label by label, lowercasing, into hashvalue.
Dname in query format (not compressed).
dname | dname to hash. |
h | initial hash value. |
References hashlittle(), LDNS_MAX_LABELLEN, and log_assert.
Referenced by hash_infra(), infra_create_ratedata(), infra_find_ratedata(), key_entry_hash(), query_info_hash(), and rrset_key_hash().
hashvalue_type dname_pkt_hash | ( | struct sldns_buffer * | pkt, |
uint8_t * | dname, | ||
hashvalue_type | 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 hashlittle(), LABEL_IS_PTR, LDNS_MAX_LABELLEN, log_assert, MAX_COMPRESS_PTRS, PTR_OFFSET, sldns_buffer_at(), and sldns_buffer_limit().
Referenced by pkt_hash_rrset(), and pkt_hash_rrset_first().
void dname_pkt_copy | ( | struct sldns_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, LDNS_MAX_DOMAINLEN, LDNS_MAX_LABELLEN, log_assert, log_err(), MAX_COMPRESS_PTRS, PTR_OFFSET, sldns_buffer_at(), and sldns_buffer_limit().
Referenced by decompress_rr_into_buffer(), parse_copy_decompress_rrset(), parse_create_qinfo(), pkt_strict_sub(), pkt_sub(), priv_lookup_name(), shorten_rrset(), sub_of_pkt(), synth_cname(), and synth_cname_rrset().
int dname_buffer_write | ( | struct sldns_buffer * | pkt, |
uint8_t * | dname | ||
) |
Copy over a valid dname to a packet.
pkt | packet to copy to. |
dname | dname to copy. |
References sldns_buffer_remaining(), sldns_buffer_write(), and sldns_buffer_write_u8().
Referenced by compress_any_dname().
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 anchors_lookup(), auth_xfer_find(), auth_zone_create(), auth_zone_find(), auth_zone_find_less_equal(), autr_tp_create(), az_domain_create(), az_find_domain(), az_find_name(), az_nsec3_get_nextcloser(), caps_white_apply_cfg(), dname_canonical_compare(), dname_get_shared_topdomain(), dname_strict_subdomain_c(), dname_subdomain_c(), dname_test_count_labels(), dns64_always_synth_for_qname(), domain_limit_findcreate(), find_add_tp(), infra_find_ratelimit(), insert_query(), is_caps_whitelisted(), iter_dp_cangodown(), iter_msg_from_zone(), local_zones_answer(), lz_enter_override(), lz_enter_zone_tag(), neg_create_zone(), neg_find_nsec(), neg_find_zone(), neg_insert_data(), next_closer(), nsec_closest_encloser(), packed_rrset_encode(), rpz_data_delete_rr(), rpz_find_zone(), set_next_probe(), val_find_best_signer(), val_nsec_proves_no_wc(), and val_rrset_wildcard().
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 anchor_store_new_key(), anchors_add_insecure(), anchors_delete_insecure(), auth_zones_find_zone(), az_find_candidate_ce(), compress_rdata(), delegpt_add_ns(), delegpt_add_ns_mlc(), delegpt_create_mlc(), delegpt_set_name(), delegpt_set_name_mlc(), dname_test_count_size_labels(), forwards_find(), forwards_lookup(), fwd_add_stub_hole(), hints_delete_stub(), hints_find(), hints_lookup_stub(), local_zones_add_RR(), lz_enter_rr_into_zone(), lz_enter_rr_str(), lz_setup_implicit(), priv_lookup_name(), read_names(), rpz_find_zone(), and val_find_best_signer().
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 anchor_cmp(), anchors_init_parents_locked(), anchors_lookup(), auth_xfer_cmp(), auth_zone_cmp(), compress_tree_search(), dname_get_shared_topdomain(), dname_strict_subdomain(), dname_subdomain_c(), dname_test_dname_lab_cmp(), forwards_lookup(), fwd_cmp(), fwd_init_parents(), local_zone_cmp(), local_zones_tags_lookup(), lz_setup_implicit(), name_tree_compare(), name_tree_init_parents(), name_tree_lookup(), neg_closest_data_parent(), neg_closest_zone_parent(), and val_find_best_signer().
int dname_lab_startswith | ( | uint8_t * | label, |
char * | prefix, | ||
char ** | endptr | ||
) |
Check if labels starts with given prefix.
label | dname label |
prefix | the string to match label with, null terminated. |
endptr | pointer to location in label after prefix, only if return value is 1. NULL if nothing in the label after the prefix, i.e. prefix and label are the same. |
int dname_has_label | ( | uint8_t * | dname, |
size_t | dnamelen, | ||
uint8_t * | label | ||
) |
Check if dname contains label.
dname | dname |
dnamelen | length of dname |
label | label to be checked for presence in dname |
References memlowercmp().
Referenced by dname_test_has_label().
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 az_nsec3_get_nextcloser(), dname_strict_subdomain_c(), dname_test_strict_subdomain(), hints_lookup_stub(), is_terminal(), iter_msg_from_zone(), iter_stub_fwd_no_cache(), and set_kiddo_parents().
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_count_labels(), and dname_strict_subdomain().
Referenced by az_empty_nonterminal(), cname_under_previous_dname(), handle_cname_response(), nsec_proves_nodata(), pkt_strict_sub(), processQueryResponse(), val_find_signer(), val_nsec_proves_insecuredelegation(), and val_nsec_proves_name_error().
int dname_subdomain_c | ( | uint8_t * | d1, |
uint8_t * | d2 | ||
) |
Counts labels.
Tests if 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 auth_zone_delegpt(), az_find_wildcard(), dname_test_subdomain(), follow_cname_chain(), generate_parentside_target_query(), iter_dp_is_useless(), iter_ds_toolow(), iter_scrub_ds(), nsec3_find_closest_encloser(), nsec_proves_nodata(), pkt_sub(), processDSNSFind(), processQueryResponse(), rpz_insert_rr(), rpz_remove_rr(), sub_of_pkt(), sum_subtree_inuse(), sum_zone_subtree_inuse(), val_find_best_signer(), val_mark_insecure(), val_neg_addreferral(), val_nsec_proves_insecuredelegation(), val_nsec_proves_name_error(), zone_del_kcache(), zone_del_msg(), zone_del_rrset(), and zonemd_simple_domain().
void dname_print | ( | FILE * | out, |
struct sldns_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, LDNS_MAX_LABELLEN, MAX_COMPRESS_PTRS, PTR_OFFSET, sldns_buffer_at(), and sldns_buffer_limit().
Referenced by analyze_dname(), and print_neg_cache().
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 auth_xfer_probe_timer_callback(), auth_xfer_probe_udp_callback(), auth_zone_delegpt(), auth_zone_read_zonefile(), auth_zone_zonemd_fail(), autr_debug_print_tp(), autr_tp_create(), delegpt_log(), do_dump_requestlist(), do_list_auth_zones(), do_list_local_zones(), dump_infra_host(), errinf_rrset(), errinf_to_str_bogus(), errinf_to_str_servfail(), fill_canon(), forwards_insert_data(), get_mesh_status(), hints_insert(), infra_ratelimit_inc(), iter_stub_fwd_no_cache(), local_data_find_tag_action(), local_zones_answer(), log_rpz_apply(), print_neg_cache(), query_for_targets(), rate_list(), rpz_insert_rr(), serviced_perturb_qname(), val_init(), xfr_probe_lookup_host(), xfr_probe_send_or_end(), xfr_probe_send_probe(), xfr_process_chunk_list(), xfr_transfer_init_fetch(), xfr_transfer_lookup_host(), xfr_transfer_nexttarget_or_end(), xfr_write_after_update(), and zonemd_generate_test().
int dname_is_root | ( | uint8_t * | dname | ) |
Returns true if the uncompressed wireformat dname is the root ".".
dname | the dname to check |
References LABEL_IS_PTR, and log_assert.
Referenced by auth_zones_find_zone(), az_domain_go_up(), az_find_candidate_ce(), az_find_wildcard(), calc_zone_need(), check_data(), check_zone_invariants(), del_empty_term(), dname_test_isroot(), forward_request(), key_cache_obtain(), local_zones_tags_lookup(), name_tree_next_root(), and nsec_proves_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. return stripped off, or "." if input was ".". |
References LABEL_IS_PTR, and log_assert.
Referenced by auth_zones_answer(), auth_zones_find_zone(), az_domain_go_up(), az_find_candidate_ce(), az_find_wildcard(), az_generate_wildcard_answer(), az_nsec3_find_ce(), calc_zone_need(), del_empty_term(), dname_remove_labels(), dname_test_removelabel(), forward_request(), insert_can_owner(), key_cache_obtain(), local_zones_tags_lookup(), lz_find_create_node(), neg_data_chain(), neg_zone_chain(), nsec3_find_closest_encloser(), nsec3_get_nextowner_b32(), and nsec_proves_nodata().
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. return stripped off, or "." if input was ".". |
References dname_remove_label().
Referenced by az_nsec3_get_nextcloser(), dname_get_shared_topdomain(), lz_setup_implicit(), next_closer(), val_nsec_proves_no_wc(), and val_rrset_wildcard().
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(), and insert_can_owner().
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(), nsec_proves_nodata(), and val_rrset_wildcard().
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 auth_data_cmp(), dname_canonical_compare(), local_data_cmp(), val_neg_data_compare(), and val_neg_zone_compare().
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_canon_lab_cmp(), and dname_count_labels().
Referenced by dname_test_canoncmp(), nsec_proves_nodata(), rrset_canonical_sort_cmp(), and val_nsec_proves_name_error().
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(), dname_remove_labels(), and LDNS_MAX_DOMAINLEN.
Referenced by auth_zones_find_zone(), az_find_candidate_ce(), dname_test_topdomain(), nsec_closest_encloser(), and rpz_find_zone().