dname.c File Reference

This file contains domain name handling functions. More...

#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.


Detailed Description

This file contains domain name handling functions.


Function Documentation

size_t query_dname_len ( ldns_buffer *  query  ) 

Determine length of dname in buffer, no compression ptrs allowed,.

Parameters:
query,: the ldns buffer, current position at start of dname. at end, position is at end of the dname.
Returns:
: 0 on parse failure, or length including ending 0 of 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.

Parameters:
dname,: where dname starts in memory.
len,: dname is not allowed to exceed this length (i.e. of allocation).
Returns:
length of dname if dname is ok, 0 on a parse error.

Referenced by canonicalize_rdata(), delegpt_rrset_add_ns(), dnskey_verify_rrset_sig(), get_cname_target(), nsec_get_next(), nsec_has_type(), rrsig_get_signer(), sanitize_nsec_is_overreach(), and wipeout().

void pkt_dname_tolower ( ldns_buffer *  pkt,
uint8_t *  dname 
)

lowercase pkt dname (follows compression pointers)

Parameters:
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.

Parameters:
pkt,: packet to read from (from current start position).
Returns:
: 0 on parse error. At exit the position is right after the (compressed) dname. Compression pointers are followed and checked for loops. The uncompressed wireformat length is returned.

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.

Parameters:
pkt,: packet, used to resolve compression pointers.
d1,: dname to compare
d2,: dname to compare
Returns:
: -1, 0, or +1 depending on comparison results. Sort order is first difference found. not the canonical ordering.

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).

Parameters:
dname,: dname to hash.
h,: initial hash value.
Returns:
: result hash value.

References log_assert.

Referenced by hash_lameness(), 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).

Parameters:
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.
Returns:
: result hash value. Result is the same as dname_query_hash, even if compression is used.

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.

Parameters:
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(), priv_lookup_name(), 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.

Parameters:
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(), parse_section(), and print_neg_cache().

int dname_count_labels ( uint8_t *  dname  ) 

int dname_count_size_labels ( uint8_t *  dname,
size_t *  size 
)

Count labels and dname length both, for uncompressed dname in memory.

Parameters:
dname,: pointer to uncompressed dname.
size,: length of dname, including root label.
Returns:
: count of labels, including root label, "com." has 2 labels.

Referenced by anchor_store_new_key(), compress_rdata(), delegpt_add_ns(), delegpt_set_name(), dname_test_count_size_labels(), forwards_delete_zone(), forwards_lookup(), hints_lookup_stub(), local_zones_add_RR(), lz_enter_rr_into_zone(), lz_enter_rr_str(), lz_setup_implicit(), make_stub_holes(), nsec3_prove_wildcard(), parse_arg_name(), parse_dname(), priv_lookup_name(), read_names(), val_find_best_signer(), wipeout(), and write_q().

static int memlowercmp ( uint8_t *  p1,
uint8_t *  p2,
uint8_t  len 
) [static]

Compare labels in memory, lowercase while comparing.

Parameters:
p1,: label 1
p2,: label 2
len,: number of bytes to compare.
Returns:
: 0, -1, +1 comparison result.

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.

Parameters:
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).
Returns:
: 0 for equal, -1 smaller, or +1 d1 larger than d2.

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(), init_parents(), local_zone_cmp(), local_zones_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_buffer_write ( ldns_buffer *  pkt,
uint8_t *  dname 
)

Copy over a valid dname to a packet.

Parameters:
pkt,: packet to copy to.
dname,: dname to copy.
Returns:
: 0 if not enough space in buffer.

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).

Parameters:
dname,: uncompressed wireformat.
str,: buffer of 255+1 length.

Referenced by anchors_assemble_rrsets(), delegpt_log(), do_dump_requestlist(), fill_canon(), get_mesh_status(), log_name_addr(), log_nametypeclass(), print_deleg_lookup(), print_neg_cache(), print_root_fwds(), 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.

Parameters:
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.
Returns:
true if d1 is a subdomain of d2, but not equal to d2.

References dname_lab_cmp().

Referenced by dname_strict_subdomain_c(), dname_test_strict_subdomain(), hints_lookup_stub(), is_terminal(), iter_msg_from_zone(), and set_kiddo_parents().

int dname_strict_subdomain_c ( uint8_t *  d1,
uint8_t *  d2 
)

Like dname_strict_subdomain but counts labels.

Parameters:
d1,: domain name, uncompressed wireformat
d2,: domain name, uncompressed wireformat
Returns:
true if d1 is a subdomain of d2, but not equal to d2.

References dname_count_labels(), and dname_strict_subdomain().

Referenced by handle_cname_response(), nsec_proves_nodata(), pkt_strict_sub(), processInit(), processQueryResponse(), response_type_from_server(), val_nsec_check_dlv(), and val_nsec_proves_name_error().

int dname_subdomain_c ( uint8_t *  d1,
uint8_t *  d2 
)

int dname_is_root ( uint8_t *  dname  ) 

Returns true if the uncompressed wireformat dname is the root ".".

Parameters:
dname,: the dname to check
Returns:
true if ".", false if not.

References LABEL_IS_PTR, and log_assert.

Referenced by calc_data_need(), calc_zone_need(), check_data(), check_zone_invariants(), del_empty_term(), dname_test_isroot(), forward_request(), key_cache_obtain(), prime_stub(), print_deleg_lookup(), and processInitRequest().

void dname_remove_label ( uint8_t **  dname,
size_t *  len 
)

void dname_remove_labels ( uint8_t **  dname,
size_t *  len,
int  n 
)

Snip off first N labels from a dname, returning the parent zone.

Parameters:
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.
Returns:
stripped off, or "." if input was ".".

References dname_remove_label().

Referenced by dlv_topdomain(), 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.

Parameters:
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.

Parameters:
dname,: valid uncompressed wireformat.
Returns:
true if wildcard, or false.

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.

Parameters:
p1,: label 1
len1,: length of label 1.
p2,: label 2
len2,: length of label 2.
Returns:
: 0, -1, +1 comparison result.

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.

Parameters:
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).
Returns:
: 0 for equal, -1 smaller, or +1 d1 larger than d2.

References log_assert, and memcanoncmp().

Referenced by dname_canonical_compare(), local_data_cmp(), 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.

Parameters:
d1,: first dname. pointer to uncompressed wireformat.
d2,: second dname. pointer to uncompressed wireformat.
Returns:
: 0 for equal, -1 smaller, or +1 d1 larger than d2.

References dname_canon_lab_cmp(), and dname_count_labels().

Referenced by dname_test_canoncmp(), nsec_proves_nodata(), val_nsec_check_dlv(), 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.

Parameters:
d1,: first dname. pointer to uncompressed wireformat.
d2,: second dname. pointer to uncompressed wireformat.
Returns:
pointer to shared topdomain. Ptr to a part of d1.

References dname_count_labels(), dname_lab_cmp(), and dname_remove_labels().

Referenced by dlv_topdomain(), dname_test_topdomain(), and nsec_closest_encloser().


Generated on Tue Oct 13 06:45:51 2009 for unbound by  doxygen 1.5.9