#include "config.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. |
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 canonicalize_rdata(), delegpt_rrset_add_ns(), dnskey_verify_rrset_sig(), get_cname_target(), nsec_get_next(), nsec_has_type(), 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, and PTR_OFFSET.
Referenced by serviced_callbacks().
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, MAX_COMPRESS_PTRS, and PTR_OFFSET.
Referenced by analyze_dname(), calc_size(), dname_test_pkt_dname_len(), get_additional_name(), nsec_at_apex(), parse_edns_from_pkt(), parse_query_section(), parse_section(), 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 LABEL_IS_PTR, log_assert, and PTR_OFFSET.
Referenced by rrset_parse_equals(), scrub_message(), scrub_normalize(), scrub_sanitize(), and smart_compare().
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 key_entry_hash(), query_info_hash(), and rrset_key_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, log_assert, and PTR_OFFSET.
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, log_assert, log_err(), and PTR_OFFSET.
Referenced by parse_copy_decompress_rrset(), parse_create_qinfo(), pkt_strict_sub(), pkt_sub(), rdata_copy(), remove_rrset(), synth_cname(), and synth_cname_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(), 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 anchors_lookup(), dname_canonical_compare(), dname_get_shared_topdomain(), dname_strict_subdomain_c(), dname_subdomain_c(), dname_test_count_labels(), insert_query(), iter_msg_from_zone(), local_zones_answer(), next_closer(), nsec_closest_encloser(), packed_rrset_encode(), processFindKey(), 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(), compress_rdata(), delegpt_add_ns(), delegpt_set_name(), dname_test_count_size_labels(), forwards_lookup(), hints_lookup_stub(), lz_enter_rr_into_zone(), lz_enter_rr_str(), lz_setup_implicit(), nsec3_prove_wildcard(), parse_dname(), val_find_best_signer(), and write_q().
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 anchor_cmp(), anchors_lookup(), 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(), hints_lookup_stub(), init_parents(), local_zone_cmp(), local_zones_lookup(), lz_setup_implicit(), stub_cmp(), 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 delegpt_log(), fill_canon(), log_name_addr(), log_nametypeclass(), and serviced_perturb_qname().
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 dname_strict_subdomain_c(), dname_test_strict_subdomain(), hints_lookup_stub(), and iter_msg_from_zone().
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 handle_cname_response(), nsec_proves_nodata(), pkt_strict_sub(), processInit(), response_type_from_server(), and val_nsec_proves_name_error().
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 dname_test_subdomain(), dnskey_verify_rrset_sig(), filter_init(), generate_target_query(), iter_dp_is_useless(), nsec3_find_closest_encloser(), pkt_sub(), processFindKey(), response_type_from_server(), val_find_best_signer(), val_mark_insecure(), and val_nsec_proves_name_error().
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 dname_test_isroot(), key_cache_obtain(), and processInitRequest().
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 LABEL_IS_PTR, and log_assert.
Referenced by dname_remove_labels(), dname_test_removelabel(), filter_init(), filter_next(), insert_can_owner(), key_cache_obtain(), lz_find_create_node(), nsec3_find_closest_encloser(), nsec_proves_nodata(), processInit(), and processInitRequest().
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 dname_get_shared_topdomain(), lz_setup_implicit(), next_closer(), processFindKey(), 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(), dnskey_verify_rrset_sig(), 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_nsec_prove_nodata_dsreply().
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 dname_canonical_compare(), and local_data_cmp().
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(), 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(), and dname_remove_labels().
Referenced by dname_test_topdomain(), and nsec_closest_encloser().