msgreply.c File Reference

This file contains a data structure to store a message and its reply. More...

#include "config.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"
#include "sldns/sbuffer.h"
#include "sldns/wire2str.h"
#include "util/module.h"
#include "util/fptr_wlist.h"

Macros

#define COMPARE_IT(x, y)
 tiny subroutine for msgreply_compare More...
 

Functions

static int parse_create_qinfo (sldns_buffer *pkt, struct msg_parse *msg, struct query_info *qinf, struct regional *region)
 allocate qinfo, return 0 on error
 
struct reply_infoconstruct_reply_info_base (struct regional *region, uint16_t flags, size_t qd, time_t ttl, time_t prettl, time_t expttl, size_t an, size_t ns, size_t ar, size_t total, enum sec_status sec, sldns_ede_code reason_bogus)
 constructor for replyinfo More...
 
static int parse_create_repinfo (struct msg_parse *msg, struct reply_info **rep, struct regional *region)
 allocate replyinfo, return 0 on error
 
int reply_info_alloc_rrset_keys (struct reply_info *rep, struct alloc_cache *alloc, struct regional *region)
 Allocate (special) rrset keys. More...
 
struct reply_infomake_new_reply_info (const struct reply_info *rep, struct regional *region, size_t an_numrrsets, size_t copy_rrsets)
 
static time_t soa_find_minttl (struct rr_parse *rr)
 find the minimumttl in the rdata of SOA record
 
static int rdata_copy (sldns_buffer *pkt, struct packed_rrset_data *data, uint8_t *to, struct rr_parse *rr, time_t *rr_ttl, uint16_t type, sldns_pkt_section section)
 do the rdata copy
 
static int parse_rr_copy (sldns_buffer *pkt, struct rrset_parse *pset, struct packed_rrset_data *data)
 copy over the data into packed rrset
 
static int parse_create_rrset (sldns_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 (sldns_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. More...
 
static int parse_copy_decompress (sldns_buffer *pkt, struct msg_parse *msg, struct reply_info *rep, struct regional *region)
 Copy and decompress rrs. More...
 
int parse_create_msg (sldns_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. More...
 
int reply_info_parse (sldns_buffer *pkt, struct alloc_cache *alloc, struct query_info *qinf, struct reply_info **rep, struct regional *region, struct edns_data *edns)
 Parse query reply. More...
 
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. More...
 
void reply_info_set_ttls (struct reply_info *rep, time_t timenow)
 Set TTLs inside the replyinfo to absolute values. More...
 
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.). More...
 
int query_info_parse (struct query_info *m, sldns_buffer *query)
 Parse wire query into a queryinfo structure, return 0 on parse error. More...
 
int query_info_compare (void *m1, void *m2)
 Compare two queryinfo structures, on query and type, class. More...
 
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 *ATTR_UNUSED(arg))
 
void reply_info_delete (void *d, void *ATTR_UNUSED(arg))
 
hashvalue_type query_info_hash (struct query_info *q, uint16_t flags)
 calculate hash value of query_info, lowercases the qname, uses CD flag for AAAA qtype
 
struct msgreply_entryquery_info_entrysetup (struct query_info *q, struct reply_info *r, hashvalue_type h)
 Setup query info entry. More...
 
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_inforeply_info_copy (struct reply_info *rep, struct alloc_cache *alloc, struct regional *region)
 Copy reply_info and all rrsets in it and allocate. More...
 
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. More...
 
struct ub_packed_rrset_keyreply_find_answer_rrset (struct query_info *qinfo, struct reply_info *rep)
 Find answer rrset in reply, the one matching qinfo. More...
 
struct ub_packed_rrset_keyreply_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. More...
 
struct ub_packed_rrset_keyreply_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. More...
 
struct ub_packed_rrset_keyreply_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. More...
 
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. More...
 
void log_reply_info (enum verbosity_value v, struct query_info *qinf, struct sockaddr_storage *addr, socklen_t addrlen, struct timeval dur, int cached, struct sldns_buffer *rmsg, struct sockaddr_storage *daddr, enum comm_point_type tp)
 Print string with neat domain name, type, class, status code from, and size of a query response. More...
 
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. More...
 
int reply_check_cname_chain (struct query_info *qinfo, struct reply_info *rep)
 Check if cname chain in cached reply is still valid. More...
 
int reply_all_rrsets_secure (struct reply_info *rep)
 Check security status of all RRs in the message. More...
 
struct reply_infoparse_reply_in_temp_region (sldns_buffer *pkt, struct regional *region, struct query_info *qi)
 get msg reply struct (in temp region)
 
int edns_opt_list_append_ede (struct edns_option **list, struct regional *region, sldns_ede_code code, const char *txt)
 Append edns EDE option to edns options list. More...
 
int edns_opt_list_append_keepalive (struct edns_option **list, int msec, struct regional *region)
 Append edns keep alive option to edns options list. More...
 
int edns_opt_list_append (struct edns_option **list, uint16_t code, size_t len, uint8_t *data, struct regional *region)
 Append edns option to edns option list. More...
 
int edns_opt_list_remove (struct edns_option **list, uint16_t code)
 Remove any option found on the edns option list that matches the code. More...
 
static int inplace_cb_reply_call_generic (struct inplace_cb *callback_list, enum inplace_cb_list_type type, struct query_info *qinfo, struct module_qstate *qstate, struct reply_info *rep, int rcode, struct edns_data *edns, struct comm_reply *repinfo, struct regional *region, struct timeval *start_time)
 
int inplace_cb_reply_call (struct module_env *env, struct query_info *qinfo, struct module_qstate *qstate, struct reply_info *rep, int rcode, struct edns_data *edns, struct comm_reply *repinfo, struct regional *region, struct timeval *start_time)
 Call the registered functions in the inplace_cb_reply linked list. More...
 
int inplace_cb_reply_cache_call (struct module_env *env, struct query_info *qinfo, struct module_qstate *qstate, struct reply_info *rep, int rcode, struct edns_data *edns, struct comm_reply *repinfo, struct regional *region, struct timeval *start_time)
 Call the registered functions in the inplace_cb_reply_cache linked list. More...
 
int inplace_cb_reply_local_call (struct module_env *env, struct query_info *qinfo, struct module_qstate *qstate, struct reply_info *rep, int rcode, struct edns_data *edns, struct comm_reply *repinfo, struct regional *region, struct timeval *start_time)
 Call the registered functions in the inplace_cb_reply_local linked list. More...
 
int inplace_cb_reply_servfail_call (struct module_env *env, struct query_info *qinfo, struct module_qstate *qstate, struct reply_info *rep, int rcode, struct edns_data *edns, struct comm_reply *repinfo, struct regional *region, struct timeval *start_time)
 Call the registered functions in the inplace_cb_reply linked list. More...
 
int inplace_cb_query_call (struct module_env *env, struct query_info *qinfo, uint16_t flags, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *zone, size_t zonelen, struct module_qstate *qstate, struct regional *region)
 Call the registered functions in the inplace_cb_query linked list. More...
 
int inplace_cb_edns_back_parsed_call (struct module_env *env, struct module_qstate *qstate)
 Call the registered functions in the inplace_cb_edns_back_parsed linked list. More...
 
int inplace_cb_query_response_call (struct module_env *env, struct module_qstate *qstate, struct dns_msg *response)
 Call the registered functions in the inplace_cb_query_response linked list. More...
 
struct edns_optionedns_opt_copy_region (struct edns_option *list, struct regional *region)
 Copy edns option list allocated to the new region.
 
struct edns_optionedns_opt_copy_filter_region (struct edns_option *list, uint16_t *filter_list, size_t filter_list_len, struct regional *region)
 Copy a filtered edns option list allocated to the new region.
 
int edns_opt_compare (struct edns_option *p, struct edns_option *q)
 Compare an edns option. More...
 
int edns_opt_list_compare (struct edns_option *p, struct edns_option *q)
 Compare edns option lists, also the order and contents of edns-options.
 
void edns_opt_list_free (struct edns_option *list)
 Free edns option list allocated with malloc.
 
struct edns_optionedns_opt_copy_alloc (struct edns_option *list)
 Copy edns option list allocated with malloc.
 
struct edns_optionedns_opt_list_find (struct edns_option *list, uint16_t code)
 Find edns option in edns list. More...
 

Variables

time_t MAX_TTL = 3600 * 24 * 10
 MAX TTL default for messages and rrsets. More...
 
time_t MIN_TTL = 0
 MIN TTL default for messages and rrsets. More...
 
time_t MAX_NEG_TTL = 3600
 MAX Negative TTL, for SOA records in authority section. More...
 
time_t MIN_NEG_TTL = 0
 MIN Negative TTL, for SOA records in authority section. More...
 
int SERVE_EXPIRED = 0
 If we serve expired entries and prefetch them.
 
time_t SERVE_EXPIRED_TTL = 0
 Time to serve records after expiration.
 
time_t SERVE_EXPIRED_REPLY_TTL = 30
 TTL to use for expired records.
 
int SERVE_ORIGINAL_TTL = 0
 If we serve the original TTL or decrementing TTLs.
 

Detailed Description

This file contains a data structure to store a message and its reply.

Macro Definition Documentation

◆ COMPARE_IT

#define COMPARE_IT (   x,
 
)
Value:
if( (x) < (y) ) return -1; \
else if( (x) > (y) ) return +1; \
log_assert( (x) == (y) );

tiny subroutine for msgreply_compare

Function Documentation

◆ construct_reply_info_base()

struct reply_info* construct_reply_info_base ( struct regional region,
uint16_t  flags,
size_t  qd,
time_t  ttl,
time_t  prettl,
time_t  expttl,
size_t  an,
size_t  ns,
size_t  ar,
size_t  total,
enum sec_status  sec,
sldns_ede_code  reason_bogus 
)

◆ reply_info_alloc_rrset_keys()

int reply_info_alloc_rrset_keys ( struct reply_info rep,
struct alloc_cache alloc,
struct regional region 
)

Allocate (special) rrset keys.

Parameters
repreply info in which the rrset keys to be allocated, rrset[] array should have bee allocated with NULL pointers.
allochow to allocate rrset keys. Not used if region!=NULL, it can be NULL in that case.
regionif this parameter is NULL then the alloc is used. otherwise, rrset keys are allocated in this region. In a region, no special rrset key structures are needed (not shared). and no rrset_ref array in the reply needs to be built up.
Returns
1 on success, 0 on error

References alloc_special_obtain(), lruhash_entry::data, ub_packed_rrset_key::entry, lruhash_entry::key, regional_alloc(), reply_info::rrset_count, and reply_info::rrsets.

Referenced by parse_create_msg(), and reply_info_copy().

◆ parse_copy_decompress_rrset()

int parse_copy_decompress_rrset ( struct sldns_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.

Parameters
pktpacket for decompression
msgthe parser message (for flags for trust).
psetthe parsed rrset to copy.
regionif NULL - malloc, else data is allocated in this region.
pka freshly obtained rrsetkey structure. No dname is set yet, will be set on return. Note that TTL will still be relative on return.
Returns
false on alloc failure.

copy & decompress dname

copy over type and class

read data part.

References lruhash_entry::data, rrset_parse::dname, packed_rrset_key::dname, rrset_parse::dname_len, packed_rrset_key::dname_len, dname_pkt_copy(), ub_packed_rrset_key::entry, rrset_parse::flags, packed_rrset_key::flags, get_rrset_trust(), rrset_parse::hash, lruhash_entry::hash, lruhash_entry::key, parse_create_rrset(), regional_alloc(), ub_packed_rrset_key::rk, rrset_parse::rrset_class, packed_rrset_key::rrset_class, packed_rrset_data::trust, rrset_parse::type, and packed_rrset_key::type.

Referenced by parse_copy_decompress(), and store_rrset().

◆ parse_copy_decompress()

static int parse_copy_decompress ( sldns_buffer pkt,
struct msg_parse msg,
struct reply_info rep,
struct regional region 
)
static

Copy and decompress rrs.

Parameters
pktthe packet for compression pointer resolution.
msgthe parsed message
repreply info to put rrs into.
regionif not NULL, used for allocation.
Returns
0 on failure.

References lruhash_entry::data, ub_packed_rrset_key::entry, log_assert, MAX_TTL, NORR_TTL, parse_copy_decompress_rrset(), reply_info::prefetch_ttl, PREFETCH_TTL_CALC, rrset_parse::rrset_all_next, reply_info::rrset_count, msg_parse::rrset_first, reply_info::rrsets, sec_status_unchecked, reply_info::security, SERVE_EXPIRED_TTL, reply_info::serve_expired_ttl, reply_info::ttl, and packed_rrset_data::ttl.

Referenced by parse_create_msg().

◆ parse_create_msg()

int parse_create_msg ( struct sldns_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.

Parameters
pktfor name decompression.
msgparsed message in scratch region.
allocalloc cache for special rrset key structures. Not used if region!=NULL, it can be NULL in that case.
qinfwhere to store query info. qinf itself is allocated by the caller.
repreply info is allocated and returned.
regionif 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.
Returns
0 if allocation failed.

References log_assert, parse_copy_decompress(), parse_create_qinfo(), parse_create_repinfo(), reply_info_alloc_rrset_keys(), and reply_info_parsedelete().

Referenced by dns_alloc_msg(), and parse_reply_in_temp_region().

◆ reply_info_parse()

int reply_info_parse ( struct sldns_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.

Parameters
pktthe packet buffer. Must be positioned after the query section.
alloccreates packed rrset key structures.
repallocated reply_info is returned (only on no error).
qinfquery_info is returned (only on no error).
regionwhere to store temporary data (for parsing).
ednswhere to store edns information, does not need to be inited.
Returns
: zero is OK, or DNS error code in case of error o FORMERR for parse errors. o SERVFAIL for memory allocation errors.

References query_info::local_alias, query_info::qname, and regional_alloc().

Referenced by entry_to_repinfo(), perftestpkt(), and testpkt().

◆ reply_info_sortref()

void reply_info_sortref ( struct reply_info rep)

Sorts the ref array.

Parameters
repreply info. rrsets must be filled in.

References reply_info::ref, reply_info_sortref_cmp(), and reply_info::rrset_count.

Referenced by dns_cache_store_msg().

◆ reply_info_set_ttls()

void reply_info_set_ttls ( struct reply_info rep,
time_t  timenow 
)

Set TTLs inside the replyinfo to absolute values.

Parameters
repreply info. rrsets must be filled in. Also refs must be filled in.
timenowthe current time.

References packed_rrset_data::count, lruhash_entry::data, ub_packed_rrset_key::entry, rrset_ref::key, reply_info::prefetch_ttl, reply_info::ref, packed_rrset_data::rr_ttl, reply_info::rrset_count, packed_rrset_data::rrsig_count, reply_info::serve_expired_ttl, reply_info::ttl, packed_rrset_data::ttl, and packed_rrset_data::ttl_add.

Referenced by dns_cache_store_msg().

◆ reply_info_parsedelete()

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.

Parameters
repreply_info to delete.
allocwhere to return rrset structures to.

References reply_info::reason_bogus_str, reply_info::rrset_count, reply_info::rrsets, and ub_packed_rrset_parsedelete().

Referenced by dns_cache_store(), parse_create_msg(), reply_info_copy(), and verifytest_entry().

◆ query_info_parse()

int query_info_parse ( struct query_info m,
struct sldns_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.

Parameters
mthe prealloced queryinfo structure to put query into. must be unused, or _clear()ed.
querythe wireformat packet query. starts with ID.
Returns
: 0 on format error.

References sldns_buffer_begin(), and sldns_buffer_limit().

Referenced by auth_zone_parse_notify_serial().

◆ query_info_compare()

int query_info_compare ( void *  m1,
void *  m2 
)

Compare two queryinfo structures, on query and type, class.

It is not sorted in canonical ordering.

Parameters
m1struct query_info* , void* here to ease use as function pointer.
m2struct query_info* , void* here to ease use as function pointer.
Returns
: 0 = same, -1 m1 is smaller, +1 m1 is larger.

References COMPARE_IT, log_assert, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, and query_dname_compare().

Referenced by context_finalize(), daemon_apply_cfg(), fptr_whitelist_hash_compfunc(), and mesh_state_compare().

◆ query_info_entrysetup()

struct msgreply_entry* query_info_entrysetup ( struct query_info q,
struct reply_info r,
hashvalue_type  h 
)

Setup query info entry.

Parameters
qquery info to copy. Emptied as if clear is called.
rreply to init data.
hhash value.
Returns
: newly allocated message reply cache item.

References lruhash_entry::data, msgreply_entry::entry, lruhash_entry::hash, msgreply_entry::key, lruhash_entry::key, query_info::local_alias, lruhash_entry::lock, query_info::qclass, query_info::qname, query_info::qname_len, and query_info::qtype.

Referenced by dns_cache_store_msg().

◆ reply_info_copy()

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.

Parameters
repwhat to copy, probably inside region, no ref[] array in it.
allochow to allocate rrset keys. Not used if region!=NULL, it can be NULL in that case.
regionif 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.
Returns
new reply info or NULL on memory error.

References reply_info::an_numrrsets, reply_info::ar_numrrsets, construct_reply_info_base(), reply_info::flags, reply_info::ns_numrrsets, reply_info::prefetch_ttl, reply_info::qdcount, reply_info::reason_bogus, reply_info::reason_bogus_str, regional_alloc(), repinfo_copy_rrsets(), reply_info_alloc_rrset_keys(), reply_info_parsedelete(), reply_info::rrset_count, reply_info::security, reply_info::serve_expired_ttl, and reply_info::ttl.

Referenced by dns64_adjust_ptr(), dns_cache_store(), and dns_copy_msg().

◆ reply_find_final_cname_target()

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.

Parameters
qinfowhat to start with.
replooks in answer section of this message.
Returns
: pointer dname, or NULL if not found.

References reply_info::an_numrrsets, packed_rrset_key::dname, packed_rrset_key::dname_len, get_cname_target(), LDNS_RR_TYPE_CNAME, query_info::qclass, query_info::qname, query_info::qname_len, query_dname_compare(), ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, reply_info::rrsets, and packed_rrset_key::type.

◆ reply_find_answer_rrset()

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.

Follows CNAMEs, so the result may have a different owner name.

Parameters
qinfowhat to look for.
replooks in answer section of this message.
Returns
: pointer to rrset, or NULL if not found.

References reply_info::an_numrrsets, packed_rrset_key::dname, packed_rrset_key::dname_len, get_cname_target(), LDNS_RR_TYPE_CNAME, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, query_dname_compare(), ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, reply_info::rrsets, and packed_rrset_key::type.

Referenced by dns64_adjust_ptr().

◆ reply_find_rrset_section_an()

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.

Does not follow CNAMEs.

Parameters
replooks in answer section of this message.
namewhat to look for.
namelenlength of name.
typelooks for (host order).
dclasslooks for (host order).
Returns
: pointer to rrset, or NULL if not found.

References reply_info::an_numrrsets, packed_rrset_key::dname, packed_rrset_key::dname_len, query_dname_compare(), ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, reply_info::rrsets, and packed_rrset_key::type.

Referenced by iter_msg_from_zone().

◆ reply_find_rrset_section_ns()

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.

Does not follow CNAMEs.

Parameters
replooks in authority section of this message.
namewhat to look for.
namelenlength of name.
typelooks for (host order).
dclasslooks for (host order).
Returns
: pointer to rrset, or NULL if not found.

References reply_info::an_numrrsets, packed_rrset_key::dname, packed_rrset_key::dname_len, reply_info::ns_numrrsets, query_dname_compare(), ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, reply_info::rrsets, and packed_rrset_key::type.

Referenced by iter_indicates_dnssec(), and iter_msg_from_zone().

◆ reply_find_rrset()

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.

Does not follow CNAMEs.

Parameters
replooks in answer,authority and additional section of this message.
namewhat to look for.
namelenlength of name.
typelooks for (host order).
dclasslooks for (host order).
Returns
: pointer to rrset, or NULL if not found.

References packed_rrset_key::dname, packed_rrset_key::dname_len, query_dname_compare(), ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, reply_info::rrset_count, reply_info::rrsets, and packed_rrset_key::type.

◆ log_dns_msg()

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.

Parameters
strdescriptive string printed with packet content.
qinfoquery section.
represt of message.

Referenced by check_the_rrsigs(), mesh_serve_expired_callback(), and processInitRequest3().

◆ log_reply_info()

void log_reply_info ( enum verbosity_value  v,
struct query_info qinf,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
struct timeval  dur,
int  cached,
struct sldns_buffer rmsg,
struct sockaddr_storage *  daddr,
enum comm_point_type  tp 
)

Print string with neat domain name, type, class, status code from, and size of a query response.

Parameters
vat what verbosity level to print this.
qinfquery section.
addraddress of the client.
addrlenlength of the client address.
durhow long it took to complete the query.
cachedwhether or not the reply is coming from the cache, or an outside network.
rmsgsldns buffer packet.
daddrif not NULL, the destination address and port are logged.
tptype of the comm point for logging destination connection type.

References addr_to_str(), FLAGS_GET_RCODE, LDNS_MAX_DOMAINLEN, sldns_buffer_read_u16_at(), sldns_wire2str_rcode_buf(), and verbosity.

◆ log_query_info()

void log_query_info ( enum verbosity_value  v,
const char *  str,
struct query_info qinf 
)

◆ reply_check_cname_chain()

int reply_check_cname_chain ( struct query_info qinfo,
struct reply_info rep 
)

Check if cname chain in cached reply is still valid.

Parameters
qinfoquery info with query name.
repreply to check.
Returns
: true if valid, false if invalid.

References reply_info::an_numrrsets, packed_rrset_key::dname, get_cname_target(), LDNS_RR_TYPE_CNAME, LDNS_RR_TYPE_DNAME, query_info::qname, query_info::qname_len, query_dname_compare(), ub_packed_rrset_key::rk, reply_info::rrsets, and packed_rrset_key::type.

◆ reply_all_rrsets_secure()

int reply_all_rrsets_secure ( struct reply_info rep)

Check security status of all RRs in the message.

Parameters
repreply to check
Returns
: true if all RRs are secure. False if not. True if there are zero RRs.

References lruhash_entry::data, ub_packed_rrset_key::entry, reply_info::rrset_count, reply_info::rrsets, and sec_status_secure.

Referenced by mesh_serve_expired_lookup().

◆ edns_opt_list_append_ede()

int edns_opt_list_append_ede ( struct edns_option **  list,
struct regional region,
sldns_ede_code  code,
const char *  txt 
)

Append edns EDE option to edns options list.

Parameters
listthe edns option list to append the edns option to.
regionregion to allocate the new edns option.
codethe EDE code.
txtAdditional text for the option
Returns
false on failure.

References edns_option::next, edns_option::opt_code, and regional_alloc().

◆ edns_opt_list_append_keepalive()

int edns_opt_list_append_keepalive ( struct edns_option **  list,
int  msec,
struct regional region 
)

Append edns keep alive option to edns options list.

Parameters
listthe edns option list to append the edns option to.
msecthe duration in msecs for the keep alive.
regionregion to allocate the new edns option.
Returns
false on failure.

References edns_opt_list_append().

Referenced by parse_edns_options_from_query().

◆ edns_opt_list_append()

int edns_opt_list_append ( struct edns_option **  list,
uint16_t  code,
size_t  len,
uint8_t *  data,
struct regional region 
)

Append edns option to edns option list.

Parameters
listthe edns option list to append the edns option to.
codethe edns option's code.
lenthe edns option's length.
datathe edns option's data.
regionregion to allocate the new edns option.
Returns
false on failure.

References edns_option::next, edns_option::opt_code, edns_option::opt_data, edns_option::opt_len, regional_alloc(), and regional_alloc_init().

Referenced by edns_opt_list_append_keepalive(), and outnet_serviced_query().

◆ edns_opt_list_remove()

int edns_opt_list_remove ( struct edns_option **  list,
uint16_t  code 
)

Remove any option found on the edns option list that matches the code.

Parameters
listthe list of edns options.
codethe opt code to remove.
Returns
true when at least one edns option was removed, false otherwise.

References edns_option::next, and edns_option::opt_code.

Referenced by extended_error_encode().

◆ inplace_cb_reply_call()

int inplace_cb_reply_call ( struct module_env env,
struct query_info qinfo,
struct module_qstate qstate,
struct reply_info rep,
int  rcode,
struct edns_data edns,
struct comm_reply repinfo,
struct regional region,
struct timeval *  start_time 
)

Call the registered functions in the inplace_cb_reply linked list.

This function is going to get called while answering with a resolved query.

Parameters
envmodule environment.
qinfoquery info.
qstatemodule qstate.
repReply info. Could be NULL.
rcodereturn code.
ednsedns data of the reply.
repinfocomm_reply. Reply information for a communication point.
regionregion to store data.
start_timethe start time of recursion, when the packet arrived, or the current time for cache responses.
Returns
false on failure (a callback function returned an error).

◆ inplace_cb_reply_cache_call()

int inplace_cb_reply_cache_call ( struct module_env env,
struct query_info qinfo,
struct module_qstate qstate,
struct reply_info rep,
int  rcode,
struct edns_data edns,
struct comm_reply repinfo,
struct regional region,
struct timeval *  start_time 
)

Call the registered functions in the inplace_cb_reply_cache linked list.

This function is going to get called while answering from cache.

Parameters
envmodule environment.
qinfoquery info.
qstatemodule qstate. NULL when replying from cache.
repReply info.
rcodereturn code.
ednsedns data of the reply. Edns input can be found here.
repinfocomm_reply. Reply information for a communication point.
regionregion to store data.
start_timethe start time of recursion, when the packet arrived, or the current time for cache responses.
Returns
false on failure (a callback function returned an error).

◆ inplace_cb_reply_local_call()

int inplace_cb_reply_local_call ( struct module_env env,
struct query_info qinfo,
struct module_qstate qstate,
struct reply_info rep,
int  rcode,
struct edns_data edns,
struct comm_reply repinfo,
struct regional region,
struct timeval *  start_time 
)

Call the registered functions in the inplace_cb_reply_local linked list.

This function is going to get called while answering with local data.

Parameters
envmodule environment.
qinfoquery info.
qstatemodule qstate. NULL when replying from cache.
repReply info.
rcodereturn code.
ednsedns data of the reply. Edns input can be found here.
repinfocomm_reply. Reply information for a communication point.
regionregion to store data.
start_timethe start time of recursion, when the packet arrived, or the current time for cache responses.
Returns
false on failure (a callback function returned an error).

Referenced by auth_answer_encode(), auth_error_encode(), local_error_encode(), and rpz_local_encode().

◆ inplace_cb_reply_servfail_call()

int inplace_cb_reply_servfail_call ( struct module_env env,
struct query_info qinfo,
struct module_qstate qstate,
struct reply_info rep,
int  rcode,
struct edns_data edns,
struct comm_reply repinfo,
struct regional region,
struct timeval *  start_time 
)

Call the registered functions in the inplace_cb_reply linked list.

This function is going to get called while answering with a servfail.

Parameters
envmodule environment.
qinfoquery info.
qstatemodule qstate. Contains the edns option lists. Could be NULL.
repReply info. NULL when servfail.
rcodereturn code. LDNS_RCODE_SERVFAIL.
ednsedns data of the reply. Edns input can be found here if qstate is NULL.
repinfocomm_reply. Reply information for a communication point.
regionregion to store data.
start_timethe start time of recursion, when the packet arrived, or the current time for cache responses.
Returns
false on failure (a callback function returned an error).

References module_qstate::edns_opts_front_out.

Referenced by answer_norec_from_cache(), and mesh_new_client().

◆ inplace_cb_query_call()

int inplace_cb_query_call ( struct module_env env,
struct query_info qinfo,
uint16_t  flags,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t *  zone,
size_t  zonelen,
struct module_qstate qstate,
struct regional region 
)

Call the registered functions in the inplace_cb_query linked list.

This function is going to get called just before sending a query to a nameserver.

Parameters
envmodule environment.
qinfoquery info.
flagsflags of the query.
addrto which server to send the query.
addrlenlength of addr.
zonename of the zone of the delegation point. wireformat dname. This is the delegation point name for which the server is deemed authoritative.
zonelenlength of zone.
qstatemodule qstate.
regionregion to store data.
Returns
false on failure (a callback function returned an error).

References inplace_cb::cb.

Referenced by outnet_serviced_query().

◆ inplace_cb_edns_back_parsed_call()

int inplace_cb_edns_back_parsed_call ( struct module_env env,
struct module_qstate qstate 
)

Call the registered functions in the inplace_cb_edns_back_parsed linked list.

This function is going to get called after parsing the EDNS data on the reply from a nameserver.

Parameters
envmodule environment.
qstatemodule qstate.
Returns
false on failure (a callback function returned an error).

References inplace_cb::cb.

◆ inplace_cb_query_response_call()

int inplace_cb_query_response_call ( struct module_env env,
struct module_qstate qstate,
struct dns_msg response 
)

Call the registered functions in the inplace_cb_query_response linked list.

This function is going to get called after receiving a reply from a nameserver.

Parameters
envmodule environment.
qstatemodule qstate.
responsereceived response
Returns
false on failure (a callback function returned an error).

References inplace_cb::cb.

Referenced by processQueryResponse().

◆ edns_opt_compare()

int edns_opt_compare ( struct edns_option p,
struct edns_option q 
)

Compare an edns option.

(not entire list). Also compares contents.

References log_assert, edns_option::opt_code, edns_option::opt_data, and edns_option::opt_len.

Referenced by edns_opt_list_compare().

◆ edns_opt_list_find()

struct edns_option* edns_opt_list_find ( struct edns_option list,
uint16_t  code 
)

Find edns option in edns list.

Parameters
listlist of edns options (eg. edns.opt_list)
codeopt code to find.
Returns
NULL or the edns_option element.

References edns_option::next, and edns_option::opt_code.

Variable Documentation

◆ MAX_TTL

time_t MAX_TTL = 3600 * 24 * 10

MAX TTL default for messages and rrsets.

Maximum TTL that is allowed.

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

◆ MIN_TTL

time_t MIN_TTL = 0

MIN TTL default for messages and rrsets.

Minimum TTL that is allowed.

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

◆ MAX_NEG_TTL

time_t MAX_NEG_TTL = 3600

MAX Negative TTL, for SOA records in authority section.

Maximum Negative TTL that is allowed.

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

◆ MIN_NEG_TTL

time_t MIN_NEG_TTL = 0

MIN Negative TTL, for SOA records in authority section.

Minimum Negative TTL that is allowed.

Referenced by config_apply(), and config_set_option().