unbound: util/data/msgparse.h File Reference

unbound 0.1

Data Structures | Macros | Functions | Variables
msgparse.h File Reference

Contains message parsing data structures. More...

`#include "util/storage/lruhash.h"`
`#include "sldns/pkthdr.h"`
`#include "sldns/rrdef.h"`

## Data Structures
struct | msg_parse
| Data stored in scratch pad memory during parsing. More...
struct | rrset_parse
| Data stored for an rrset during parsing. More...
struct | rr_parse
| Data stored for an RR during parsing. More...
struct | edns_data
| EDNS data storage rdata is parsed in a list (has accessor functions). More...
struct | edns_option
| EDNS option. More...

## Macros
#define | PARSE_TABLE_SIZE 32
| number of buckets in parse rrset hash table.
#define | NORR_TTL 5 /* seconds */
| Negative cache time (for entries without any RRs.)
#define | LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
| Check if label length is first octet of a compression pointer, pass u8.
#define | PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
| Calculate destination offset of a compression pointer.
#define | PTR_CREATE(offset) ((uint16_t)(0xc000 | (offset)))
| create a compression pointer to the given offset.
#define | EDNS_RCODE_BADVERS 16 /** bad EDNS version */
| error codes, extended with EDNS, so > 15.
#define | PTR_MAX_OFFSET 0x3fff
| largest valid compression offset

## Functions
size_t | get_rdf_size (sldns_rdf_type rdf)
| Obtain size in the packet of an rr type, that is before dname type.
int | parse_packet (struct sldns_buffer *pkt, struct msg_parse *msg, struct regional *region)
| Parse the packet.
int | parse_extract_edns_from_response_msg (struct msg_parse *msg, struct edns_data *edns, struct regional *region)
| After parsing the packet, extract EDNS data from packet.
int | skip_pkt_rrs (struct sldns_buffer *pkt, int num)
| Skip RRs from packet.
int | parse_edns_from_query_pkt (struct sldns_buffer *pkt, struct edns_data *edns, struct config_file *cfg, struct comm_point *c, struct regional *region)
| If EDNS data follows a query section, extract it and initialize edns struct.
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.
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.
void | msgparse_bucket_remove (struct msg_parse *msg, struct rrset_parse *rrset)
| Remove rrset from hash table.
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.

## Variables
time_t | MAX_TTL
| Maximum TTL that is allowed.
time_t | MIN_TTL
| Minimum TTL that is allowed.
time_t | MAX_NEG_TTL
| Maximum Negative TTL that is allowed.
int | SERVE_EXPIRED
| If we serve expired entries and prefetch them.
time_t | SERVE_EXPIRED_TTL
| Time to serve records after expiration.
time_t | SERVE_EXPIRED_REPLY_TTL
| TTL to use for expired records.
int | SERVE_ORIGINAL_TTL
| If we serve the original TTL or decrementing TTLs.

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

## Macro Definition Documentation

## ◆ PARSE_TABLE_SIZE

#define PARSE_TABLE_SIZE 32

number of buckets in parse rrset hash table.

Must be power of 2.

## ◆ PTR_OFFSET

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

Calculate destination offset of a compression pointer.

pass first and second octets of the compression pointer.

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

  rdf | the rdf type from the descriptor.

Returns
  : size in octets. 0 on failure.

References LDNS_RDF_TYPE_A, LDNS_RDF_TYPE_AAAA, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_CERT_ALG, LDNS_RDF_TYPE_CLASS, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT32, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TSIGTIME, LDNS_RDF_TYPE_TYPE, and log_assert.

Referenced by analyze_rdata(), calc_size(), canonical_compare_byfield(), compress_rdata(), decompress_rr_into_buffer(), and rdata_copy().

## ◆ parse_packet()

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

Parse the packet.

Parameters

  pkt | packet, position at call must be at start of packet. at end position is after packet.
  msg | where to store results.
  region | how to alloc results.

Returns
  : 0 if OK, or rcode on error.

References msg_parse::an_rrsets, msg_parse::ancount, msg_parse::ar_rrsets, msg_parse::arcount, msg_parse::flags, msg_parse::id, msg_parse::ns_rrsets, msg_parse::nscount, parse_query_section(), parse_section(), msg_parse::qdcount, msg_parse::rrset_count, sldns_buffer_read(), sldns_buffer_read_u16(), and sldns_buffer_remaining().

Referenced by createResponse(), parse_reply_in_temp_region(), process_response(), and reply_info_parse().

## ◆ parse_extract_edns_from_response_msg()

int parse_extract_edns_from_response_msg | ( | 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

  msg | parsed message structure. Modified on exit, if EDNS was present it is removed from the additional section.
  edns | the edns data is stored here. Does not have to be initialised.
  region | region 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.

References msg_parse::ar_rrsets, msg_parse::arcount, edns_data::bits, rrset_parse::dname, rrset_parse::dname_len, edns_opt_list_append(), edns_data::edns_present, edns_data::edns_version, edns_data::ext_rcode, LDNS_RR_TYPE_OPT, log_assert, log_err(), edns_data::opt_list_in, edns_data::opt_list_inplace_cb_out, edns_data::opt_list_out, edns_data::padding_block_size, rrset_parse::rr_count, rrset_parse::rr_first, rrset_parse::rr_last, rrset_parse::rrset_all_next, rrset_parse::rrset_class, msg_parse::rrset_count, msg_parse::rrset_first, msg_parse::rrset_last, rrset_parse::section, rr_parse::size, rr_parse::ttl_data, rrset_parse::type, and edns_data::udp_size.

Referenced by createResponse(), process_response(), and reply_info_parse().

## ◆ skip_pkt_rrs()

int skip_pkt_rrs | ( | sldns_buffer * | pkt,
|  | int | num
| ) |  |

Skip RRs from packet.

Parameters

  pkt | the packet. position at start must be right after the query section. At end, right after EDNS data or no movement if failed.
  num | Limit of the number of records we want to parse.

Returns
  : 0 on success, 1 on failure.

Skip RRs from packet.

References skip_pkt_rr().

Referenced by parse_edns_from_query_pkt().

## ◆ parse_edns_from_query_pkt()

int parse_edns_from_query_pkt | ( | struct sldns_buffer * | pkt,
|  | struct edns_data * | edns,
|  | struct config_file * | cfg,
|  | struct comm_point * | c,
|  | struct regional * | region
| ) |  |

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

Parameters

  pkt | the packet. position at start must be right after the query section. At end, right after EDNS data or no movement if failed.
  edns | the edns data allocated by the caller. Does not have to be initialised.
  cfg | the configuration (with nsid value etc.)
  c | commpoint to determine transport (if needed)
  region | region 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.

References edns_data::bits, edns_data::edns_present, edns_data::edns_version, edns_data::ext_rcode, LDNS_RR_TYPE_OPT, log_assert, edns_data::opt_list_in, edns_data::opt_list_inplace_cb_out, edns_data::opt_list_out, edns_data::padding_block_size, parse_edns_options_from_query(), pkt_dname_len(), skip_pkt_rrs(), sldns_buffer_begin(), sldns_buffer_current(), sldns_buffer_read_u16(), sldns_buffer_read_u8(), sldns_buffer_remaining(), and edns_data::udp_size.

Referenced by worker_handle_request().

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

  pkt | the packet.
  dname | pointer to uncompressed dname, or compressed dname in packet.
  type | rrset type in host order.
  dclass | rrset class in network order.
  rrset_flags | rrset flags (same as packed_rrset flags).

Returns
  hash value

References rrset_parse::dname, dname_pkt_hash(), and rrset_parse::type.

Referenced by change_rrsig_rrset(), mark_additional_rrset(), and synth_cname_rrset().

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

  msg | with the hashtable.
  pkt | packet for compressed names.
  h | hash value
  rrset_flags | flags of rrset sought for.
  dname | name of rrset sought for.
  dnamelen | len of dname.
  type | rrset type, host order.
  dclass | rrset class, network order.

Returns
  NULL or the rrset_parse if found.

References rrset_parse::dname, msg_parse::hashtable, PARSE_TABLE_SIZE, rrset_parse::rrset_bucket_next, rrset_parse_equals(), and rrset_parse::type.

Referenced by find_rrset(), and mark_additional_rrset().

## ◆ msgparse_bucket_remove()

void msgparse_bucket_remove | ( | struct msg_parse * | msg,
|  | struct rrset_parse * | rrset
| ) |  |

Remove rrset from hash table.

Parameters

  msg | with hashtable.
  rrset | with hash value and id info.

References rrset_parse::hash, msg_parse::hashtable, PARSE_TABLE_SIZE, and rrset_parse::rrset_bucket_next.

Referenced by change_rrsig_rrset(), and remove_rrset().

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

  level | the verbosity level.
  info_str | the informational string to be printed before the options.
  list | the edns option list.

References edns_option::next, edns_option::opt_code, edns_option::opt_data, edns_option::opt_len, sldns_wire2str_edns_option_print(), verbose(), and verbosity.

## Variable Documentation

## ◆ MAX_TTL

time_t MAX_TTL
| extern

Maximum TTL that is allowed.

Maximum TTL that is allowed.

Referenced by config_apply(), config_set_option(), parse_copy_decompress(), parse_rr_copy(), and rdata_copy().

## ◆ MIN_TTL

time_t MIN_TTL
| extern

Minimum TTL that is allowed.

Minimum TTL that is allowed.

Referenced by adjust_ttl(), config_apply(), config_set_option(), and rdata_copy().

## ◆ MAX_NEG_TTL

time_t MAX_NEG_TTL
| extern

Maximum Negative TTL that is allowed.

Maximum Negative TTL that is allowed.

Referenced by config_apply(), config_set_option(), msgparse_test(), and rdata_copy().