summaryrefslogtreecommitdiff
path: root/util/data
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2018-05-12 11:49:30 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2018-05-12 11:49:30 +0000
commitfbdb9ac866a647da0919b224f05cca039afc02fa (patch)
treea4ddb15b51a795c9f985e693a04d992a94f4f455 /util/data
parent31f8d531e1359c7acd82cff9ab798cdeac277adc (diff)
Diffstat (limited to 'util/data')
-rw-r--r--util/data/dname.c8
-rw-r--r--util/data/dname.h5
-rw-r--r--util/data/msgparse.c30
-rw-r--r--util/data/msgparse.h8
-rw-r--r--util/data/msgreply.c40
-rw-r--r--util/data/msgreply.h25
-rw-r--r--util/data/packed_rrset.c4
-rw-r--r--util/data/packed_rrset.h12
8 files changed, 94 insertions, 38 deletions
diff --git a/util/data/dname.c b/util/data/dname.c
index 8fc475f7f3f13..517af2843e2cd 100644
--- a/util/data/dname.c
+++ b/util/data/dname.c
@@ -270,8 +270,8 @@ dname_pkt_compare(sldns_buffer* pkt, uint8_t* d1, uint8_t* d2)
return 0;
}
-hashvalue_t
-dname_query_hash(uint8_t* dname, hashvalue_t h)
+hashvalue_type
+dname_query_hash(uint8_t* dname, hashvalue_type h)
{
uint8_t labuf[LDNS_MAX_LABELLEN+1];
uint8_t lablen;
@@ -294,8 +294,8 @@ dname_query_hash(uint8_t* dname, hashvalue_t h)
return h;
}
-hashvalue_t
-dname_pkt_hash(sldns_buffer* pkt, uint8_t* dname, hashvalue_t h)
+hashvalue_type
+dname_pkt_hash(sldns_buffer* pkt, uint8_t* dname, hashvalue_type h)
{
uint8_t labuf[LDNS_MAX_LABELLEN+1];
uint8_t lablen;
diff --git a/util/data/dname.h b/util/data/dname.h
index ae2fbadc1d854..53b341bf7ef72 100644
--- a/util/data/dname.h
+++ b/util/data/dname.h
@@ -127,7 +127,7 @@ int dname_pkt_compare(struct sldns_buffer* pkt, uint8_t* d1, uint8_t* d2);
* @param h: initial hash value.
* @return: result hash value.
*/
-hashvalue_t dname_query_hash(uint8_t* dname, hashvalue_t h);
+hashvalue_type dname_query_hash(uint8_t* dname, hashvalue_type h);
/**
* Hash dname, label by label, lowercasing, into hashvalue.
@@ -139,7 +139,8 @@ hashvalue_t dname_query_hash(uint8_t* dname, hashvalue_t h);
* @return: result hash value.
* Result is the same as dname_query_hash, even if compression is used.
*/
-hashvalue_t dname_pkt_hash(struct sldns_buffer* pkt, uint8_t* dname, hashvalue_t h);
+hashvalue_type dname_pkt_hash(struct sldns_buffer* pkt, uint8_t* dname,
+ hashvalue_type h);
/**
* Copy over a valid dname and decompress it.
diff --git a/util/data/msgparse.c b/util/data/msgparse.c
index 3774054f57000..5381500e1523f 100644
--- a/util/data/msgparse.c
+++ b/util/data/msgparse.c
@@ -71,7 +71,7 @@ smart_compare(sldns_buffer* pkt, uint8_t* dnow,
*/
static struct rrset_parse*
new_rrset(struct msg_parse* msg, uint8_t* dname, size_t dnamelen,
- uint16_t type, uint16_t dclass, hashvalue_t hash,
+ uint16_t type, uint16_t dclass, hashvalue_type hash,
uint32_t rrset_flags, sldns_pkt_section section,
struct regional* region)
{
@@ -159,13 +159,13 @@ pkt_rrset_flags(sldns_buffer* pkt, uint16_t type, sldns_pkt_section sec)
return f;
}
-hashvalue_t
+hashvalue_type
pkt_hash_rrset(sldns_buffer* pkt, uint8_t* dname, uint16_t type,
uint16_t dclass, uint32_t rrset_flags)
{
/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
/* this routine handles compressed names */
- hashvalue_t h = 0xab;
+ hashvalue_type h = 0xab;
h = dname_pkt_hash(pkt, dname, h);
h = hashlittle(&type, sizeof(type), h); /* host order */
h = hashlittle(&dclass, sizeof(dclass), h); /* netw order */
@@ -174,25 +174,25 @@ pkt_hash_rrset(sldns_buffer* pkt, uint8_t* dname, uint16_t type,
}
/** create partial dname hash for rrset hash */
-static hashvalue_t
+static hashvalue_type
pkt_hash_rrset_first(sldns_buffer* pkt, uint8_t* dname)
{
/* works together with pkt_hash_rrset_rest */
/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
/* this routine handles compressed names */
- hashvalue_t h = 0xab;
+ hashvalue_type h = 0xab;
h = dname_pkt_hash(pkt, dname, h);
return h;
}
/** create a rrset hash from a partial dname hash */
-static hashvalue_t
-pkt_hash_rrset_rest(hashvalue_t dname_h, uint16_t type, uint16_t dclass,
+static hashvalue_type
+pkt_hash_rrset_rest(hashvalue_type dname_h, uint16_t type, uint16_t dclass,
uint32_t rrset_flags)
{
/* works together with pkt_hash_rrset_first */
/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
- hashvalue_t h;
+ hashvalue_type h;
h = hashlittle(&type, sizeof(type), dname_h); /* host order */
h = hashlittle(&dclass, sizeof(dclass), h); /* netw order */
h = hashlittle(&rrset_flags, sizeof(uint32_t), h);
@@ -201,7 +201,7 @@ pkt_hash_rrset_rest(hashvalue_t dname_h, uint16_t type, uint16_t dclass,
/** compare rrset_parse with data */
static int
-rrset_parse_equals(struct rrset_parse* p, sldns_buffer* pkt, hashvalue_t h,
+rrset_parse_equals(struct rrset_parse* p, sldns_buffer* pkt, hashvalue_type h,
uint32_t rrset_flags, uint8_t* dname, size_t dnamelen,
uint16_t type, uint16_t dclass)
{
@@ -215,8 +215,8 @@ rrset_parse_equals(struct rrset_parse* p, sldns_buffer* pkt, hashvalue_t h,
struct rrset_parse*
msgparse_hashtable_lookup(struct msg_parse* msg, sldns_buffer* pkt,
- hashvalue_t h, uint32_t rrset_flags, uint8_t* dname, size_t dnamelen,
- uint16_t type, uint16_t dclass)
+ hashvalue_type h, uint32_t rrset_flags, uint8_t* dname,
+ size_t dnamelen, uint16_t type, uint16_t dclass)
{
struct rrset_parse* p = msg->hashtable[h & (PARSE_TABLE_SIZE-1)];
while(p) {
@@ -388,7 +388,7 @@ change_rrsig_rrset(struct rrset_parse* sigset, struct msg_parse* msg,
int hasother, sldns_pkt_section section, struct regional* region)
{
struct rrset_parse* dataset = sigset;
- hashvalue_t hash = pkt_hash_rrset(pkt, sigset->dname, datatype,
+ hashvalue_type hash = pkt_hash_rrset(pkt, sigset->dname, datatype,
sigset->rrset_class, rrset_flags);
log_assert( sigset->type == LDNS_RR_TYPE_RRSIG );
log_assert( datatype != LDNS_RR_TYPE_RRSIG );
@@ -455,14 +455,14 @@ change_rrsig_rrset(struct rrset_parse* sigset, struct msg_parse* msg,
*/
static int
find_rrset(struct msg_parse* msg, sldns_buffer* pkt, uint8_t* dname,
- size_t dnamelen, uint16_t type, uint16_t dclass, hashvalue_t* hash,
+ size_t dnamelen, uint16_t type, uint16_t dclass, hashvalue_type* hash,
uint32_t* rrset_flags,
uint8_t** prev_dname_first, uint8_t** prev_dname_last,
size_t* prev_dnamelen, uint16_t* prev_type,
uint16_t* prev_dclass, struct rrset_parse** rrset_prev,
sldns_pkt_section section, struct regional* region)
{
- hashvalue_t dname_h = pkt_hash_rrset_first(pkt, dname);
+ hashvalue_type dname_h = pkt_hash_rrset_first(pkt, dname);
uint16_t covtype;
if(*rrset_prev) {
/* check if equal to previous item */
@@ -824,7 +824,7 @@ parse_section(sldns_buffer* pkt, struct msg_parse* msg,
uint16_t type, prev_type = 0;
uint16_t dclass, prev_dclass = 0;
uint32_t rrset_flags = 0;
- hashvalue_t hash = 0;
+ hashvalue_type hash = 0;
struct rrset_parse* rrset = NULL;
int r;
diff --git a/util/data/msgparse.h b/util/data/msgparse.h
index 594517b2db114..e21f8504ea7d0 100644
--- a/util/data/msgparse.h
+++ b/util/data/msgparse.h
@@ -138,7 +138,7 @@ struct rrset_parse {
/** next in list of all rrsets */
struct rrset_parse* rrset_all_next;
/** hash value of rrset */
- hashvalue_t hash;
+ hashvalue_type hash;
/** which section was it found in: one of
* LDNS_SECTION_ANSWER, LDNS_SECTION_AUTHORITY, LDNS_SECTION_ADDITIONAL
*/
@@ -296,8 +296,8 @@ int parse_edns_from_pkt(struct sldns_buffer* pkt, struct edns_data* edns,
* @param rrset_flags: rrset flags (same as packed_rrset flags).
* @return hash value
*/
-hashvalue_t pkt_hash_rrset(struct sldns_buffer* pkt, uint8_t* dname, uint16_t type,
- uint16_t dclass, uint32_t rrset_flags);
+hashvalue_type pkt_hash_rrset(struct sldns_buffer* pkt, uint8_t* dname,
+ uint16_t type, uint16_t dclass, uint32_t rrset_flags);
/**
* Lookup in msg hashtable to find a rrset.
@@ -312,7 +312,7 @@ hashvalue_t pkt_hash_rrset(struct sldns_buffer* pkt, uint8_t* dname, uint16_t ty
* @return NULL or the rrset_parse if found.
*/
struct rrset_parse* msgparse_hashtable_lookup(struct msg_parse* msg,
- struct sldns_buffer* pkt, hashvalue_t h, uint32_t rrset_flags,
+ struct sldns_buffer* pkt, hashvalue_type h, uint32_t rrset_flags,
uint8_t* dname, size_t dnamelen, uint16_t type, uint16_t dclass);
/**
diff --git a/util/data/msgreply.c b/util/data/msgreply.c
index 2caee7789fde3..8869716b67939 100644
--- a/util/data/msgreply.c
+++ b/util/data/msgreply.c
@@ -608,10 +608,10 @@ reply_info_delete(void* d, void* ATTR_UNUSED(arg))
free(r);
}
-hashvalue_t
+hashvalue_type
query_info_hash(struct query_info *q, uint16_t flags)
{
- hashvalue_t h = 0xab;
+ hashvalue_type h = 0xab;
h = hashlittle(&q->qtype, sizeof(q->qtype), h);
if(q->qtype == LDNS_RR_TYPE_AAAA && (flags&BIT_CD))
h++;
@@ -622,7 +622,7 @@ query_info_hash(struct query_info *q, uint16_t flags)
struct msgreply_entry*
query_info_entrysetup(struct query_info* q, struct reply_info* r,
- hashvalue_t h)
+ hashvalue_type h)
{
struct msgreply_entry* e = (struct msgreply_entry*)malloc(
sizeof(struct msgreply_entry));
@@ -819,7 +819,39 @@ log_dns_msg(const char* str, struct query_info* qinfo, struct reply_info* rep)
regional_destroy(region);
}
-void
+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)
+{
+ char qname_buf[LDNS_MAX_DOMAINLEN+1];
+ char clientip_buf[128];
+ char rcode_buf[16];
+ char type_buf[16];
+ char class_buf[16];
+ size_t pktlen;
+ uint16_t rcode = FLAGS_GET_RCODE(sldns_buffer_read_u16_at(rmsg, 2));
+
+ if(verbosity < v)
+ return;
+
+ sldns_wire2str_rcode_buf((int)rcode, rcode_buf, sizeof(rcode_buf));
+ addr_to_str(addr, addrlen, clientip_buf, sizeof(clientip_buf));
+ if(rcode == LDNS_RCODE_FORMERR)
+ {
+ log_info("%s - - - %s - - - ", clientip_buf, rcode_buf);
+ } else {
+ dname_str(qinf->qname, qname_buf);
+ pktlen = sldns_buffer_limit(rmsg);
+ sldns_wire2str_type_buf(qinf->qtype, type_buf, sizeof(type_buf));
+ sldns_wire2str_class_buf(qinf->qclass, class_buf, sizeof(class_buf));
+ log_info("%s %s %s %s %s " ARG_LL "d.%6.6d %d %d",
+ clientip_buf, qname_buf, type_buf, class_buf,
+ rcode_buf, (long long)dur.tv_sec, (int)dur.tv_usec, cached, (int)pktlen);
+ }
+}
+
+void
log_query_info(enum verbosity_value v, const char* str,
struct query_info* qinf)
{
diff --git a/util/data/msgreply.h b/util/data/msgreply.h
index cc02161333778..485d49afa87da 100644
--- a/util/data/msgreply.h
+++ b/util/data/msgreply.h
@@ -105,7 +105,7 @@ struct rrset_ref {
/** the key with lock, and ptr to packed data. */
struct ub_packed_rrset_key* key;
/** id needed */
- rrset_id_t id;
+ rrset_id_type id;
};
/**
@@ -330,7 +330,7 @@ void reply_info_delete(void* d, void* arg);
/** calculate hash value of query_info, lowercases the qname,
* uses CD flag for AAAA qtype */
-hashvalue_t query_info_hash(struct query_info *q, uint16_t flags);
+hashvalue_type query_info_hash(struct query_info *q, uint16_t flags);
/**
* Setup query info entry
@@ -340,7 +340,7 @@ hashvalue_t query_info_hash(struct query_info *q, uint16_t flags);
* @return: newly allocated message reply cache item.
*/
struct msgreply_entry* query_info_entrysetup(struct query_info* q,
- struct reply_info* r, hashvalue_t h);
+ struct reply_info* r, hashvalue_type h);
/**
* Copy reply_info and all rrsets in it and allocate.
@@ -448,10 +448,27 @@ struct ub_packed_rrset_key* reply_find_rrset(struct reply_info* rep,
* @param qinfo: query section.
* @param rep: rest of message.
*/
-void log_dns_msg(const char* str, struct query_info* qinfo,
+void log_dns_msg(const char* str, struct query_info* qinfo,
struct reply_info* rep);
/**
+ * Print string with neat domain name, type, class,
+ * status code from, and size of a query response.
+ *
+ * @param v: at what verbosity level to print this.
+ * @param qinf: query section.
+ * @param addr: address of the client.
+ * @param addrlen: length of the client address.
+ * @param dur: how long it took to complete the query.
+ * @param cached: whether or not the reply is coming from
+ * the cache, or an outside network.
+ * @param rmsg: sldns buffer packet.
+ */
+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);
+
+/**
* Print string with neat domain name, type, class from query info.
* @param v: at what verbosity level to print this.
* @param str: string of message.
diff --git a/util/data/packed_rrset.c b/util/data/packed_rrset.c
index 66399085a65e6..9944087cbf51e 100644
--- a/util/data/packed_rrset.c
+++ b/util/data/packed_rrset.c
@@ -158,14 +158,14 @@ rrsetdata_equal(struct packed_rrset_data* d1, struct packed_rrset_data* d2)
return 1;
}
-hashvalue_t
+hashvalue_type
rrset_key_hash(struct packed_rrset_key* key)
{
/* type is hashed in host order */
uint16_t t = ntohs(key->type);
/* Note this MUST be identical to pkt_hash_rrset in msgparse.c */
/* this routine does not have a compressed name */
- hashvalue_t h = 0xab;
+ hashvalue_type h = 0xab;
h = dname_query_hash(key->dname, h);
h = hashlittle(&t, sizeof(t), h);
h = hashlittle(&key->rrset_class, sizeof(uint16_t), h);
diff --git a/util/data/packed_rrset.h b/util/data/packed_rrset.h
index 6039aef242ca5..a2f116afba430 100644
--- a/util/data/packed_rrset.h
+++ b/util/data/packed_rrset.h
@@ -47,7 +47,7 @@ struct regional;
/** type used to uniquely identify rrsets. Cannot be reused without
* clearing the cache. */
-typedef uint64_t rrset_id_t;
+typedef uint64_t rrset_id_type;
/** this rrset is NSEC and is at zone apex (at child side of zonecut) */
#define PACKED_RRSET_NSEC_AT_APEX 0x1
@@ -114,7 +114,7 @@ struct ub_packed_rrset_key {
* The other values in this struct may only be altered after changing
* the id (which needs a writelock on entry.lock).
*/
- rrset_id_t id;
+ rrset_id_type id;
/** key data: dname, type and class */
struct packed_rrset_key rk;
};
@@ -191,6 +191,12 @@ enum sec_status {
* RRset data.
*
* The data is packed, stored contiguously in memory.
+ *
+ * It is not always stored contiguously, in that case, an unpacked-packed
+ * rrset has the arrays separate. A bunch of routines work on that, but
+ * the packed rrset that is contiguous is for the rrset-cache and the
+ * cache-response routines in daemon/worker.c.
+ *
* memory layout:
* o base struct
* o rr_len size_t array
@@ -334,7 +340,7 @@ void rrset_data_delete(void* data, void* userdata);
* @param key: the rrset key with name, type, class, flags.
* @return hash value.
*/
-hashvalue_t rrset_key_hash(struct packed_rrset_key* key);
+hashvalue_type rrset_key_hash(struct packed_rrset_key* key);
/**
* Fixup pointers in fixed data packed_rrset_data blob.