This file contains a data structure to store a message and its reply. More...
#include "config.h"#include <ldns/ldns.h>#include "util/data/msgreply.h"#include "util/storage/lookup3.h"#include "util/log.h"#include "util/alloc.h"#include "util/netevent.h"#include "util/net_help.h"#include "util/data/dname.h"#include "util/regional.h"#include "util/data/msgparse.h"#include "util/data/msgencode.h"Defines | |
| #define | COMPARE_IT(x, y) |
| tiny subroutine for msgreply_compare | |
Functions | |
| static int | parse_create_qinfo (ldns_buffer *pkt, struct msg_parse *msg, struct query_info *qinf, struct regional *region) |
| allocate qinfo, return 0 on error | |
| static struct reply_info * | construct_reply_info_base (struct regional *region, uint16_t flags, size_t qd, uint32_t ttl, uint32_t prettl, size_t an, size_t ns, size_t ar, size_t total, enum sec_status sec) |
| constructor for replyinfo | |
| static int | parse_create_repinfo (struct msg_parse *msg, struct reply_info **rep, struct regional *region) |
| allocate replyinfo, return 0 on error | |
| static int | repinfo_alloc_rrset_keys (struct reply_info *rep, struct alloc_cache *alloc, struct regional *region) |
| allocate (special) rrset keys, return 0 on error | |
| static int | rdata_copy (ldns_buffer *pkt, struct packed_rrset_data *data, uint8_t *to, struct rr_parse *rr, uint32_t *rr_ttl, uint16_t type) |
| do the rdata copy | |
| static int | parse_rr_copy (ldns_buffer *pkt, struct rrset_parse *pset, struct packed_rrset_data *data) |
| copy over the data into packed rrset | |
| static int | parse_create_rrset (ldns_buffer *pkt, struct rrset_parse *pset, struct packed_rrset_data **data, struct regional *region) |
| create rrset return 0 on failure | |
| static enum rrset_trust | get_rrset_trust (struct msg_parse *msg, struct rrset_parse *rrset) |
| get trust value for rrset | |
| int | parse_copy_decompress_rrset (ldns_buffer *pkt, struct msg_parse *msg, struct rrset_parse *pset, struct regional *region, struct ub_packed_rrset_key *pk) |
| Copy a parsed rrset into given key, decompressing and allocating rdata. | |
| static int | parse_copy_decompress (ldns_buffer *pkt, struct msg_parse *msg, struct reply_info *rep, struct regional *region) |
| Copy and decompress rrs. | |
| int | parse_create_msg (ldns_buffer *pkt, struct msg_parse *msg, struct alloc_cache *alloc, struct query_info *qinf, struct reply_info **rep, struct regional *region) |
| Allocate and decompress parsed message and rrsets. | |
| int | reply_info_parse (ldns_buffer *pkt, struct alloc_cache *alloc, struct query_info *qinf, struct reply_info **rep, struct regional *region, struct edns_data *edns) |
| Parse query reply. | |
| static int | reply_info_sortref_cmp (const void *a, const void *b) |
| helper compare function to sort in lock order | |
| void | reply_info_sortref (struct reply_info *rep) |
| Sorts the ref array. | |
| void | reply_info_set_ttls (struct reply_info *rep, uint32_t timenow) |
| Set TTLs inside the replyinfo to absolute values. | |
| void | reply_info_parsedelete (struct reply_info *rep, struct alloc_cache *alloc) |
| Delete reply_info and packed_rrsets (while they are not yet added to the hashtables.). | |
| int | query_info_parse (struct query_info *m, ldns_buffer *query) |
| Parse wire query into a queryinfo structure, return 0 on parse error. | |
| int | query_info_compare (void *m1, void *m2) |
| Compare two queryinfo structures, on query and type, class. | |
| void | query_info_clear (struct query_info *m) |
| clear out query info structure | |
| size_t | msgreply_sizefunc (void *k, void *d) |
| calculate size of struct query_info + reply_info | |
| void | query_entry_delete (void *k, void *arg) |
| delete msgreply_entry key structure | |
| void | reply_info_delete (void *d, void *arg) |
| delete reply_info data structure | |
| hashvalue_t | query_info_hash (struct query_info *q) |
| calculate hash value of query_info, lowercases the qname | |
| struct msgreply_entry * | query_info_entrysetup (struct query_info *q, struct reply_info *r, hashvalue_t h) |
| Setup query info entry. | |
| static int | repinfo_copy_rrsets (struct reply_info *dest, struct reply_info *from, struct regional *region) |
| copy rrsets from replyinfo to dest replyinfo | |
| struct reply_info * | reply_info_copy (struct reply_info *rep, struct alloc_cache *alloc, struct regional *region) |
| Copy reply_info and all rrsets in it and allocate. | |
| uint8_t * | reply_find_final_cname_target (struct query_info *qinfo, struct reply_info *rep) |
| Find final cname target in reply, the one matching qinfo. | |
| struct ub_packed_rrset_key * | reply_find_answer_rrset (struct query_info *qinfo, struct reply_info *rep) |
| Find answer rrset in reply, the one matching qinfo. | |
| struct ub_packed_rrset_key * | reply_find_rrset_section_an (struct reply_info *rep, uint8_t *name, size_t namelen, uint16_t type, uint16_t dclass) |
| Find rrset in reply, inside the answer section. | |
| struct ub_packed_rrset_key * | reply_find_rrset_section_ns (struct reply_info *rep, uint8_t *name, size_t namelen, uint16_t type, uint16_t dclass) |
| Find rrset in reply, inside the authority section. | |
| struct ub_packed_rrset_key * | reply_find_rrset (struct reply_info *rep, uint8_t *name, size_t namelen, uint16_t type, uint16_t dclass) |
| Find rrset in reply, inside any section. | |
| void | log_dns_msg (const char *str, struct query_info *qinfo, struct reply_info *rep) |
| Debug send the query info and reply info to the log in readable form. | |
| void | log_query_info (enum verbosity_value v, const char *str, struct query_info *qinf) |
| Print string with neat domain name, type, class from query info. | |
| int | reply_check_cname_chain (struct reply_info *rep) |
| Check if cname chain in cached reply is still valid. | |
| int | reply_all_rrsets_secure (struct reply_info *rep) |
| Check security status of all RRs in the message. | |
Variables | |
| uint32_t | MAX_TTL = 3600 * 24 * 10 |
| MAX TTL default for messages and rrsets. | |
| uint32_t | MIN_TTL = 0 |
| MIN TTL default for messages and rrsets. | |
This file contains a data structure to store a message and its reply.
| #define COMPARE_IT | ( | x, | |
| y | |||
| ) |
if( (x) < (y) ) return -1; \ else if( (x) > (y) ) return +1; \ log_assert( (x) == (y) );
tiny subroutine for msgreply_compare
Referenced by query_info_compare().
| int parse_copy_decompress_rrset | ( | ldns_buffer * | pkt, |
| struct msg_parse * | msg, | ||
| struct rrset_parse * | pset, | ||
| struct regional * | region, | ||
| struct ub_packed_rrset_key * | pk | ||
| ) |
Copy a parsed rrset into given key, decompressing and allocating rdata.
| pkt,: | packet for decompression |
| msg,: | the parser message (for flags for trust). |
| pset,: | the parsed rrset to copy. |
| region,: | if NULL - malloc, else data is allocated in this region. |
| pk,: | a freshly obtained rrsetkey structure. No dname is set yet, will be set on return. Note that TTL will still be relative on return. |
copy & decompress dname
copy over type and class
read data part.
References ub_packed_rrset_key::rk, packed_rrset_key::flags, rrset_parse::flags, packed_rrset_key::dname_len, rrset_parse::dname_len, packed_rrset_key::dname, regional_alloc(), dname_pkt_copy(), rrset_parse::dname, packed_rrset_key::type, rrset_parse::type, packed_rrset_key::rrset_class, rrset_parse::rrset_class, parse_create_rrset(), ub_packed_rrset_key::entry, lruhash_entry::data, lruhash_entry::key, lruhash_entry::hash, rrset_parse::hash, packed_rrset_data::trust, and get_rrset_trust().
Referenced by store_rrset(), and parse_copy_decompress().
| static int parse_copy_decompress | ( | ldns_buffer * | pkt, |
| struct msg_parse * | msg, | ||
| struct reply_info * | rep, | ||
| struct regional * | region | ||
| ) | [static] |
Copy and decompress rrs.
| pkt,: | the packet for compression pointer resolution. |
| msg,: | the parsed message |
| rep,: | reply info to put rrs into. |
| region,: | if not NULL, used for allocation. |
References msg_parse::rrset_first, log_assert, reply_info::ttl, MAX_TTL, reply_info::security, sec_status_unchecked, reply_info::rrset_count, NORR_TTL, parse_copy_decompress_rrset(), reply_info::rrsets, ub_packed_rrset_key::entry, lruhash_entry::data, packed_rrset_data::ttl, rrset_parse::rrset_all_next, reply_info::prefetch_ttl, and PREFETCH_TTL_CALC.
Referenced by parse_create_msg().
| int parse_create_msg | ( | ldns_buffer * | pkt, |
| struct msg_parse * | msg, | ||
| struct alloc_cache * | alloc, | ||
| struct query_info * | qinf, | ||
| struct reply_info ** | rep, | ||
| struct regional * | region | ||
| ) |
Allocate and decompress parsed message and rrsets.
| pkt,: | for name decompression. |
| msg,: | parsed message in scratch region. |
| alloc,: | alloc cache for special rrset key structures. Not used if region!=NULL, it can be NULL in that case. |
| qinf,: | where to store query info. qinf itself is allocated by the caller. |
| rep,: | reply info is allocated and returned. |
| region,: | if this parameter is NULL then malloc and the alloc is used. otherwise, everything is allocated in this region. In a region, no special rrset key structures are needed (not shared), and no rrset_ref array in the reply is built up. |
References log_assert, parse_create_qinfo(), parse_create_repinfo(), repinfo_alloc_rrset_keys(), and parse_copy_decompress().
Referenced by dns_alloc_msg(), parse_reply(), createResponse(), and reply_info_parse().
| int reply_info_parse | ( | ldns_buffer * | pkt, |
| struct alloc_cache * | alloc, | ||
| struct query_info * | qinf, | ||
| struct reply_info ** | rep, | ||
| struct regional * | region, | ||
| struct edns_data * | edns | ||
| ) |
Parse query reply.
Fills in preallocated query_info structure (with ptr into buffer). Allocates reply_info and packed_rrsets. These are not yet added to any caches or anything, this is only parsing. Returns formerror on qdcount > 1.
| pkt,: | the packet buffer. Must be positioned after the query section. |
| alloc,: | creates packed rrset key structures. |
| rep,: | allocated reply_info is returned (only on no error). |
| qinf,: | query_info is returned (only on no error). |
| region,: | where to store temporary data (for parsing). |
| edns,: | where to store edns information, does not need to be inited. |
References query_info::qname, regional_alloc(), parse_packet(), parse_extract_edns(), parse_create_msg(), query_info_clear(), and reply_info_parsedelete().
Referenced by perftestpkt(), testpkt(), and entry_to_repinfo().
| void reply_info_sortref | ( | struct reply_info * | rep | ) |
Sorts the ref array.
| rep,: | reply info. rrsets must be filled in. |
References reply_info::ref, reply_info::rrset_count, and reply_info_sortref_cmp().
Referenced by dns_cache_store_msg().
| void reply_info_set_ttls | ( | struct reply_info * | rep, |
| uint32_t | timenow | ||
| ) |
Set TTLs inside the replyinfo to absolute values.
| rep,: | reply info. rrsets must be filled in. Also refs must be filled in. |
| timenow,: | the current time. |
References reply_info::ttl, reply_info::prefetch_ttl, reply_info::rrset_count, reply_info::ref, rrset_ref::key, ub_packed_rrset_key::entry, lruhash_entry::data, packed_rrset_data::ttl, packed_rrset_data::count, packed_rrset_data::rrsig_count, and packed_rrset_data::rr_ttl.
Referenced by dns_cache_store_msg().
| void reply_info_parsedelete | ( | struct reply_info * | rep, |
| struct alloc_cache * | alloc | ||
| ) |
Delete reply_info and packed_rrsets (while they are not yet added to the hashtables.).
Returns rrsets to the alloc cache.
| rep,: | reply_info to delete. |
| alloc,: | where to return rrset structures to. |
References reply_info::rrset_count, ub_packed_rrset_parsedelete(), and reply_info::rrsets.
Referenced by dns_cache_store(), perftestpkt(), testpkt(), extract_keys(), verifytest_entry(), dstest_entry(), nsec3_hash_test_entry(), reply_info_parse(), and reply_info_copy().
| int query_info_parse | ( | struct query_info * | m, |
| ldns_buffer * | query | ||
| ) |
Parse wire query into a queryinfo structure, return 0 on parse error.
initialises the (prealloced) queryinfo structure as well. This query structure contains a pointer back info the buffer! This pointer avoids memory allocation. allocqname does memory allocation.
| m,: | the prealloced queryinfo structure to put query into. must be unused, or _clear()ed. |
| query,: | the wireformat packet query. starts with ID. |
References query_info::qname, query_info::qname_len, query_dname_len(), query_info::qtype, and query_info::qclass.
Referenced by worker_handle_request().
| int query_info_compare | ( | void * | m1, |
| void * | m2 | ||
| ) |
Compare two queryinfo structures, on query and type, class.
It is _not_ sorted in canonical ordering.
| m1,: | struct query_info* , void* here to ease use as function pointer. |
| m2,: | struct query_info* , void* here to ease use as function pointer. |
References COMPARE_IT, query_info::qtype, query_dname_compare(), query_info::qname, log_assert, query_info::qname_len, and query_info::qclass.
Referenced by daemon_apply_cfg(), context_finalize(), mesh_state_compare(), and fptr_whitelist_hash_compfunc().
| struct msgreply_entry* query_info_entrysetup | ( | struct query_info * | q, |
| struct reply_info * | r, | ||
| hashvalue_t | h | ||
| ) | [read] |
Setup query info entry.
| q,: | query info to copy. Emptied as if clear is called. |
| r,: | reply to init data. |
| h,: | hash value. |
References msgreply_entry::key, msgreply_entry::entry, lruhash_entry::hash, lruhash_entry::key, lruhash_entry::data, lruhash_entry::lock, query_info::qname, and query_info::qname_len.
Referenced by dns_cache_store_msg().
| struct reply_info* reply_info_copy | ( | struct reply_info * | rep, |
| struct alloc_cache * | alloc, | ||
| struct regional * | region | ||
| ) | [read] |
Copy reply_info and all rrsets in it and allocate.
| rep,: | what to copy, probably inside region, no ref[] array in it. |
| alloc,: | how to allocate rrset keys. Not used if region!=NULL, it can be NULL in that case. |
| region,: | if this parameter is NULL then malloc and the alloc is used. otherwise, everything is allocated in this region. In a region, no special rrset key structures are needed (not shared), and no rrset_ref array in the reply is built up. |
References construct_reply_info_base(), reply_info::flags, reply_info::qdcount, reply_info::ttl, reply_info::prefetch_ttl, reply_info::an_numrrsets, reply_info::ns_numrrsets, reply_info::ar_numrrsets, reply_info::rrset_count, reply_info::security, repinfo_alloc_rrset_keys(), reply_info_parsedelete(), and repinfo_copy_rrsets().
Referenced by dns_copy_msg(), and dns_cache_store().
| uint8_t* reply_find_final_cname_target | ( | struct query_info * | qinfo, |
| struct reply_info * | rep | ||
| ) |
Find final cname target in reply, the one matching qinfo.
Follows CNAMEs.
| qinfo,: | what to start with. |
| rep,: | looks in answer section of this message. |
References query_info::qname, query_info::qname_len, reply_info::an_numrrsets, reply_info::rrsets, ub_packed_rrset_key::rk, packed_rrset_key::type, packed_rrset_key::rrset_class, query_info::qclass, packed_rrset_key::dname_len, query_dname_compare(), packed_rrset_key::dname, and get_cname_target().
Referenced by libworker_enter_result().
| struct ub_packed_rrset_key* reply_find_answer_rrset | ( | struct query_info * | qinfo, |
| struct reply_info * | rep | ||
| ) | [read] |
Find answer rrset in reply, the one matching qinfo.
Follows CNAMEs, so the result may have a different owner name.
| qinfo,: | what to look for. |
| rep,: | looks in answer section of this message. |
References query_info::qname, query_info::qname_len, reply_info::an_numrrsets, reply_info::rrsets, ub_packed_rrset_key::rk, packed_rrset_key::type, query_info::qtype, packed_rrset_key::rrset_class, query_info::qclass, packed_rrset_key::dname_len, query_dname_compare(), packed_rrset_key::dname, and get_cname_target().
Referenced by processTargetResponse(), libworker_enter_result(), ds_response_to_ke(), and process_dnskey_response().
| struct ub_packed_rrset_key* reply_find_rrset_section_an | ( | struct reply_info * | rep, |
| uint8_t * | name, | ||
| size_t | namelen, | ||
| uint16_t | type, | ||
| uint16_t | dclass | ||
| ) | [read] |
Find rrset in reply, inside the answer section.
Does not follow CNAMEs.
| rep,: | looks in answer section of this message. |
| name,: | what to look for. |
| namelen,: | length of name. |
| type,: | looks for (host order). |
| dclass,: | looks for (host order). |
References reply_info::an_numrrsets, reply_info::rrsets, ub_packed_rrset_key::rk, packed_rrset_key::type, packed_rrset_key::rrset_class, packed_rrset_key::dname_len, query_dname_compare(), and packed_rrset_key::dname.
Referenced by iter_msg_from_zone(), processQueryResponse(), ds_response_to_ke(), and process_prime_response().
| struct ub_packed_rrset_key* reply_find_rrset_section_ns | ( | struct reply_info * | rep, |
| uint8_t * | name, | ||
| size_t | namelen, | ||
| uint16_t | type, | ||
| uint16_t | dclass | ||
| ) | [read] |
Find rrset in reply, inside the authority section.
Does not follow CNAMEs.
| rep,: | looks in authority section of this message. |
| name,: | what to look for. |
| namelen,: | length of name. |
| type,: | looks for (host order). |
| dclass,: | looks for (host order). |
References reply_info::an_numrrsets, reply_info::ns_numrrsets, reply_info::rrsets, ub_packed_rrset_key::rk, packed_rrset_key::type, packed_rrset_key::rrset_class, packed_rrset_key::dname_len, query_dname_compare(), and packed_rrset_key::dname.
Referenced by iter_indicates_dnssec(), iter_msg_from_zone(), processQueryResponse(), and val_nsec_prove_nodata_dsreply().
| struct ub_packed_rrset_key* reply_find_rrset | ( | struct reply_info * | rep, |
| uint8_t * | name, | ||
| size_t | namelen, | ||
| uint16_t | type, | ||
| uint16_t | dclass | ||
| ) | [read] |
Find rrset in reply, inside any section.
Does not follow CNAMEs.
| rep,: | looks in answer,authority and additional section of this message. |
| name,: | what to look for. |
| namelen,: | length of name. |
| type,: | looks for (host order). |
| dclass,: | looks for (host order). |
References reply_info::rrset_count, reply_info::rrsets, ub_packed_rrset_key::rk, packed_rrset_key::type, packed_rrset_key::rrset_class, packed_rrset_key::dname_len, query_dname_compare(), and packed_rrset_key::dname.
Referenced by processQueryResponse().
| void log_dns_msg | ( | const char * | str, |
| struct query_info * | qinfo, | ||
| struct reply_info * | rep | ||
| ) |
Debug send the query info and reply info to the log in readable form.
| str,: | descriptive string printed with packet content. |
| qinfo,: | query section. |
| rep,: | rest of message. |
References regional_create(), reply_info_encode(), reply_info::flags, log_info(), and regional_destroy().
Referenced by processInitRequest(), processInitRequest3(), processQueryResponse(), process_response(), createResponse(), check_the_rrsigs(), val_classify_response(), validate_nodata_response(), validate_cname_noanswer_response(), and processInit().
| void log_query_info | ( | enum verbosity_value | v, |
| const char * | str, | ||
| struct query_info * | qinf | ||
| ) |
Print string with neat domain name, type, class from query info.
| v,: | at what verbosity level to print this. |
| str,: | string of message. |
| qinf,: | query info structure with name, type and class. |
References log_nametypeclass(), query_info::qname, query_info::qtype, and query_info::qclass.
Referenced by error_supers(), processInitRequest(), processInitRequest2(), processInitRequest3(), processQueryTargets(), prime_supers(), processTargetResponse(), processClassResponse(), processFinished(), process_response(), iter_operate(), pythonmod_inform_super(), mesh_continue(), mesh_log_list(), print_packet_rrsets(), probe_anchor(), generate_request(), processFindKey(), processValidate(), val_operate(), ds_response_to_ke(), process_dnskey_response(), and val_inform_super().
| int reply_check_cname_chain | ( | struct reply_info * | rep | ) |
Check if cname chain in cached reply is still valid.
| rep,: | reply to check. |
References reply_info::rrsets, ub_packed_rrset_key::rk, packed_rrset_key::dname, packed_rrset_key::dname_len, reply_info::an_numrrsets, packed_rrset_key::type, query_dname_compare(), and get_cname_target().
Referenced by answer_from_cache(), and tomsg().
| int reply_all_rrsets_secure | ( | struct reply_info * | rep | ) |
Check security status of all RRs in the message.
| rep,: | reply to check |
References reply_info::rrset_count, reply_info::rrsets, ub_packed_rrset_key::entry, lruhash_entry::data, and sec_status_secure.
Referenced by answer_from_cache(), and tomsg().
| uint32_t MAX_TTL = 3600 * 24 * 10 |
MAX TTL default for messages and rrsets.
Maximum TTL that is allowed.
Referenced by config_apply(), parse_rr_copy(), and parse_copy_decompress().
| uint32_t MIN_TTL = 0 |
MIN TTL default for messages and rrsets.
Minimum TTL that is allowed.
Referenced by config_apply(), and rdata_copy().