Electroneum
dname.h File Reference
Include dependency graph for dname.h:

Go to the source code of this file.

Macros

#define MAX_COMPRESS_PTRS   256
 

Functions

size_t query_dname_len (struct sldns_buffer *query)
 
size_t dname_valid (uint8_t *dname, size_t len)
 
void query_dname_tolower (uint8_t *dname)
 
void pkt_dname_tolower (struct sldns_buffer *pkt, uint8_t *dname)
 
int query_dname_compare (uint8_t *d1, uint8_t *d2)
 
size_t pkt_dname_len (struct sldns_buffer *pkt)
 
int dname_pkt_compare (struct sldns_buffer *pkt, uint8_t *d1, uint8_t *d2)
 
hashvalue_type dname_query_hash (uint8_t *dname, hashvalue_type h)
 
hashvalue_type dname_pkt_hash (struct sldns_buffer *pkt, uint8_t *dname, hashvalue_type h)
 
void dname_pkt_copy (struct sldns_buffer *pkt, uint8_t *to, uint8_t *dname)
 
int dname_buffer_write (struct sldns_buffer *pkt, uint8_t *dname)
 
int dname_count_labels (uint8_t *dname)
 
int dname_count_size_labels (uint8_t *dname, size_t *size)
 
int dname_lab_cmp (uint8_t *d1, int labs1, uint8_t *d2, int labs2, int *mlabs)
 
int dname_lab_startswith (uint8_t *label, char *prefix, char **endptr)
 
int dname_strict_subdomain (uint8_t *d1, int labs1, uint8_t *d2, int labs2)
 
int dname_strict_subdomain_c (uint8_t *d1, uint8_t *d2)
 
int dname_subdomain_c (uint8_t *d1, uint8_t *d2)
 
void dname_print (FILE *out, struct sldns_buffer *pkt, uint8_t *dname)
 
void dname_str (uint8_t *dname, char *str)
 
int dname_is_root (uint8_t *dname)
 
void dname_remove_label (uint8_t **dname, size_t *len)
 
void dname_remove_labels (uint8_t **dname, size_t *len, int n)
 
int dname_signame_label_count (uint8_t *dname)
 
int dname_is_wild (uint8_t *dname)
 
int dname_canon_lab_cmp (uint8_t *d1, int labs1, uint8_t *d2, int labs2, int *mlabs)
 
int dname_canonical_compare (uint8_t *d1, uint8_t *d2)
 
uint8_tdname_get_shared_topdomain (uint8_t *d1, uint8_t *d2)
 

Detailed Description

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.

Definition in file dname.h.

Macro Definition Documentation

◆ MAX_COMPRESS_PTRS

#define MAX_COMPRESS_PTRS   256

max number of compression ptrs to follow

Definition at line 51 of file dname.h.

Function Documentation

◆ dname_buffer_write()

int dname_buffer_write ( struct sldns_buffer pkt,
uint8_t dname 
)

Copy over a valid dname to a packet.

Parameters
pktpacket to copy to.
dnamedname to copy.
Returns
: 0 if not enough space in buffer.

◆ 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
d1first dname. pointer to uncompressed wireformat.
labs1number of labels in first dname.
d2second dname. pointer to uncompressed wireformat.
labs2number of labels in second dname.
mlabsnumber of labels that matched exactly (the shared topdomain).
Returns
: 0 for equal, -1 smaller, or +1 d1 larger than d2.

◆ dname_canonical_compare()

int dname_canonical_compare ( uint8_t d1,
uint8_t d2 
)

Canonical dname compare. Takes care of counting labels. Per rfc 4034 canonical order.

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

◆ dname_count_labels()

int dname_count_labels ( uint8_t dname)

Count the number of labels in an uncompressed dname in memory.

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

◆ dname_count_size_labels()

int dname_count_size_labels ( uint8_t dname,
size_t *  size 
)

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

Parameters
dnamepointer to uncompressed dname.
sizelength of dname, including root label.
Returns
: count of labels, including root label, "com." has 2 labels.

◆ dname_get_shared_topdomain()

uint8_t* dname_get_shared_topdomain ( uint8_t d1,
uint8_t d2 
)

Get the shared topdomain between two names. Root "." or longer.

Parameters
d1first dname. pointer to uncompressed wireformat.
d2second dname. pointer to uncompressed wireformat.
Returns
pointer to shared topdomain. Ptr to a part of d1.

◆ dname_is_root()

int dname_is_root ( uint8_t dname)

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

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

◆ dname_is_wild()

int dname_is_wild ( uint8_t dname)

Return true if the label is a wildcard, *.example.com.

Parameters
dnamevalid uncompressed wireformat.
Returns
true if wildcard, or false.

◆ dname_lab_cmp()

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
d1first dname. pointer to uncompressed wireformat.
labs1number of labels in first dname.
d2second dname. pointer to uncompressed wireformat.
labs2number of labels in second dname.
mlabsnumber of labels that matched exactly (the shared topdomain).
Returns
: 0 for equal, -1 smaller, or +1 d1 larger than d2.

◆ dname_lab_startswith()

int dname_lab_startswith ( uint8_t label,
char *  prefix,
char **  endptr 
)

Check if labels starts with given prefix

Parameters
labeldname label
prefixthe string to match label with, null terminated.
endptrpointer 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.
Returns
: 1 if label starts with prefix, else 0

◆ dname_pkt_compare()

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.

Parameters
pktpacket, used to resolve compression pointers.
d1dname to compare
d2dname to compare
Returns
: -1, 0, or +1 depending on comparison results. Sort order is first difference found. not the canonical ordering.

◆ dname_pkt_copy()

void dname_pkt_copy ( struct sldns_buffer pkt,
uint8_t to,
uint8_t dname 
)

Copy over a valid dname and decompress it.

Parameters
pktpacket to resolve compression pointers.
tobuffer of size from pkt_len function to hold result.
dnamepointer into packet where dname starts.

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

Parameters
pktpacket, for resolving compression pointers.
dnamedname to hash, pointer to the pkt buffer. Must be valid format. No loops, etc.
hinitial hash value.
Returns
: result hash value. Result is the same as dname_query_hash, even if compression is used.

◆ dname_print()

void dname_print ( FILE *  out,
struct sldns_buffer pkt,
uint8_t dname 
)

Debug helper. Print wireformat dname to output.

Parameters
outlike stdout or a file.
pktif not NULL, the packet for resolving compression ptrs.
dnamepointer to (start of) dname.

◆ dname_query_hash()

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

Parameters
dnamedname to hash.
hinitial hash value.
Returns
: result hash value.

◆ dname_remove_label()

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

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

Parameters
dnamefrom what to strip off. uncompressed wireformat.
lenlength, adjusted to become less.
Returns
stripped off, or "." if input was ".".

◆ dname_remove_labels()

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
dnamefrom what to strip off. uncompressed wireformat.
lenlength, adjusted to become less.
nnumber of labels to strip off (from the left). if 0, nothing happens.
Returns
stripped off, or "." if input was ".".

◆ dname_signame_label_count()

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
dnamevalid uncompressed wireformat.
Returns
number of labels like in RRSIG; '*' and '.' are not counted.

◆ dname_str()

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
dnameuncompressed wireformat.
strbuffer of 255+1 length.

◆ dname_strict_subdomain()

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
d1domain name, uncompressed wireformat
labs1number of labels in d1, including root label.
d2domain name, uncompressed wireformat
labs2number of labels in d2, including root label.
Returns
true if d1 is a subdomain of d2, but not equal to d2.

◆ dname_strict_subdomain_c()

int dname_strict_subdomain_c ( uint8_t d1,
uint8_t d2 
)

Like dname_strict_subdomain but counts labels

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

◆ dname_subdomain_c()

int dname_subdomain_c ( uint8_t d1,
uint8_t d2 
)

Counts labels. Tests is d1 is a subdomain of d2.

Parameters
d1domain name, uncompressed wireformat
d2domain name, uncompressed wireformat
Returns
true if d1 is a subdomain of d2.

◆ dname_valid()

size_t dname_valid ( uint8_t dname,
size_t  len 
)

Determine if dname in memory is correct. no compression ptrs allowed.

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

◆ pkt_dname_len()

size_t pkt_dname_len ( struct sldns_buffer pkt)

Determine correct, compressed, dname present in packet. Checks for parse errors.

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

◆ pkt_dname_tolower()

void pkt_dname_tolower ( struct sldns_buffer pkt,
uint8_t dname 
)

lowercase pkt dname (follows compression pointers)

Parameters
pktthe packet, used to follow compression pointers. Position is unchanged.
dnamestart of dname in packet.

◆ query_dname_compare()

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.

Parameters
d1dname to compare
d2dname to compare
Returns
: -1, 0, or +1 depending on comparison results. Sort order is first difference found. not the canonical ordering.

◆ query_dname_len()

size_t query_dname_len ( struct sldns_buffer query)

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

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

◆ query_dname_tolower()

void query_dname_tolower ( uint8_t dname)

lowercase query dname