Electroneum
msgparse.h File Reference
#include "util/storage/lruhash.h"
#include "sldns/pkthdr.h"
#include "sldns/rrdef.h"
Include dependency graph for msgparse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  msg_parse
 
struct  rrset_parse
 
struct  rr_parse
 
struct  edns_data
 
struct  edns_option
 

Macros

#define PARSE_TABLE_SIZE   32
 
#define NORR_TTL   5 /* seconds */
 
#define LABEL_IS_PTR(x)   ( ((x)&0xc0) == 0xc0 )
 
#define PTR_OFFSET(x, y)   ( ((x)&0x3f)<<8 | (y) )
 
#define PTR_CREATE(offset)   ((uint16_t)(0xc000 | (offset)))
 
#define EDNS_RCODE_BADVERS   16 /** bad EDNS version */
 
#define PTR_MAX_OFFSET   0x3fff
 

Functions

size_t get_rdf_size (sldns_rdf_type rdf)
 
int parse_packet (struct sldns_buffer *pkt, struct msg_parse *msg, struct regional *region)
 
int parse_extract_edns (struct msg_parse *msg, struct edns_data *edns, struct regional *region)
 
int parse_edns_from_pkt (struct sldns_buffer *pkt, struct edns_data *edns, struct regional *region)
 
hashvalue_type pkt_hash_rrset (struct sldns_buffer *pkt, uint8_t *dname, uint16_t type, uint16_t dclass, uint32_t rrset_flags)
 
struct rrset_parsemsgparse_hashtable_lookup (struct msg_parse *msg, struct sldns_buffer *pkt, hashvalue_type h, uint32_t rrset_flags, uint8_t *dname, size_t dnamelen, uint16_t type, uint16_t dclass)
 
void msgparse_bucket_remove (struct msg_parse *msg, struct rrset_parse *rrset)
 
void log_edns_opt_list (enum verbosity_value level, const char *info_str, struct edns_option *list)
 

Variables

time_t MAX_TTL
 
time_t MIN_TTL
 
time_t MAX_NEG_TTL
 

Detailed Description

Contains message parsing data structures. These point back into the packet buffer.

During parsing RRSIGS are put together with the rrsets they (claim to) sign. This process works as follows: o if RRSIG follows the data rrset, it is added to the rrset rrsig list. o if no matching data rrset is found, the RRSIG becomes a new rrset. o If the data rrset later follows the RRSIG o See if the RRSIG rrset contains multiple types, and needs to have the rrsig(s) for that data type split off. o Put the data rr as data type in the rrset and rrsig in list. o RRSIGs are allowed to move to a different section. The section of the data item is used for the final rrset. o multiple signatures over an RRset are possible.

For queries of qtype=RRSIG, some special handling is needed, to avoid splitting the RRSIG in the answer section. o duplicate, not split, RRSIGs from the answer section, if qtype=RRSIG. o check for doubles in the rrsig list when adding an RRSIG to data, so that a data rrset is signed by RRSIGs with different rdata. when qtype=RRSIG. This will move the RRSIG from the answer section to sign the data further in the packet (if possible). If then after that, more RRSIGs are found that sign the data as well, doubles are removed.

Definition in file msgparse.h.

Macro Definition Documentation

◆ EDNS_RCODE_BADVERS

#define EDNS_RCODE_BADVERS   16 /** bad EDNS version */

error codes, extended with EDNS, so > 15.

Definition at line 200 of file msgparse.h.

◆ LABEL_IS_PTR

#define LABEL_IS_PTR (   x)    ( ((x)&0xc0) == 0xc0 )

Check if label length is first octet of a compression pointer, pass u8.

Definition at line 192 of file msgparse.h.

◆ NORR_TTL

#define NORR_TTL   5 /* seconds */

Negative cache time (for entries without any RRs.)

Definition at line 83 of file msgparse.h.

◆ PARSE_TABLE_SIZE

#define PARSE_TABLE_SIZE   32

number of buckets in parse rrset hash table. Must be power of 2.

Definition at line 75 of file msgparse.h.

◆ PTR_CREATE

#define PTR_CREATE (   offset)    ((uint16_t)(0xc000 | (offset)))

create a compression pointer to the given offset.

Definition at line 197 of file msgparse.h.

◆ PTR_MAX_OFFSET

#define PTR_MAX_OFFSET   0x3fff

largest valid compression offset

Definition at line 202 of file msgparse.h.

◆ PTR_OFFSET

#define PTR_OFFSET (   x,
 
)    ( ((x)&0x3f)<<8 | (y) )

Calculate destination offset of a compression pointer. pass first and second octets of the compression pointer.

Definition at line 195 of file msgparse.h.

Function Documentation

◆ get_rdf_size()

size_t get_rdf_size ( sldns_rdf_type  rdf)

Obtain size in the packet of an rr type, that is before dname type. Do TYPE_DNAME, and type STR, yourself. Gives size for most regular types.

Parameters
rdfthe rdf type from the descriptor.
Returns
: size in octets. 0 on failure.

◆ log_edns_opt_list()

void log_edns_opt_list ( enum verbosity_value  level,
const char *  info_str,
struct edns_option list 
)

Log the edns options in the edns option list.

Parameters
levelthe verbosity level.
info_strthe informational string to be printed before the options.
listthe edns option list.

◆ msgparse_bucket_remove()

void msgparse_bucket_remove ( struct msg_parse msg,
struct rrset_parse rrset 
)

Remove rrset from hash table.

Parameters
msgwith hashtable.
rrsetwith hash value and id info.

◆ msgparse_hashtable_lookup()

struct rrset_parse* msgparse_hashtable_lookup ( struct msg_parse msg,
struct sldns_buffer pkt,
hashvalue_type  h,
uint32_t  rrset_flags,
uint8_t dname,
size_t  dnamelen,
uint16_t  type,
uint16_t  dclass 
)

Lookup in msg hashtable to find a rrset.

Parameters
msgwith the hashtable.
pktpacket for compressed names.
hhash value
rrset_flagsflags of rrset sought for.
dnamename of rrset sought for.
dnamelenlen of dname.
typerrset type, host order.
dclassrrset class, network order.
Returns
NULL or the rrset_parse if found.

◆ parse_edns_from_pkt()

int parse_edns_from_pkt ( struct sldns_buffer pkt,
struct edns_data edns,
struct regional region 
)

If EDNS data follows a query section, extract it and initialize edns struct.

Parameters
pktthe packet. position at start must be right after the query section. At end, right after EDNS data or no movement if failed.
ednsthe edns data allocated by the caller. Does not have to be initialised.
regionregion to alloc results in (edns option contents)
Returns
: 0 on success, or an RCODE on error. RCODE formerr if OPT is badly formatted and so on.

◆ parse_extract_edns()

int parse_extract_edns ( struct msg_parse msg,
struct edns_data edns,
struct regional region 
)

After parsing the packet, extract EDNS data from packet. If not present this is noted in the data structure. If a parse error happens, an error code is returned.

Quirks: o ignores OPT rdata. o ignores OPT owner name. o ignores extra OPT records, except the last one in the packet.

Parameters
msgparsed message structure. Modified on exit, if EDNS was present it is removed from the additional section.
ednsthe edns data is stored here. Does not have to be initialised.
regionregion to alloc results in (edns option contents)
Returns
: 0 on success. or an RCODE on an error. RCODE formerr if OPT in wrong section, and so on.

◆ parse_packet()

int parse_packet ( struct sldns_buffer pkt,
struct msg_parse msg,
struct regional region 
)

Parse the packet.

Parameters
pktpacket, position at call must be at start of packet. at end position is after packet.
msgwhere to store results.
regionhow to alloc results.
Returns
: 0 if OK, or rcode on error.

◆ pkt_hash_rrset()

hashvalue_type pkt_hash_rrset ( struct sldns_buffer pkt,
uint8_t dname,
uint16_t  type,
uint16_t  dclass,
uint32_t  rrset_flags 
)

Calculate hash value for rrset in packet.

Parameters
pktthe packet.
dnamepointer to uncompressed dname, or compressed dname in packet.
typerrset type in host order.
dclassrrset class in network order.
rrset_flagsrrset flags (same as packed_rrset flags).
Returns
hash value

Variable Documentation

◆ MAX_NEG_TTL

time_t MAX_NEG_TTL

Maximum Negative TTL that is allowed

◆ MAX_TTL

time_t MAX_TTL

Maximum TTL that is allowed.

◆ MIN_TTL

time_t MIN_TTL

Minimum TTL that is allowed.