aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/librdns/compression.c52
-rw-r--r--contrib/librdns/packet.c2
-rw-r--r--contrib/librdns/packet.h4
3 files changed, 33 insertions, 25 deletions
diff --git a/contrib/librdns/compression.c b/contrib/librdns/compression.c
index 7ee7d3d45..895178eb1 100644
--- a/contrib/librdns/compression.c
+++ b/contrib/librdns/compression.c
@@ -37,6 +37,10 @@ rdns_can_compress (const char *pos, unsigned int len, khash_t(rdns_compression_h
struct rdns_compression_name check;
khiter_t k;
+ if (comp == NULL) {
+ return NULL;
+ }
+
check.suffix_len = len;
check.suffix = pos;
k = kh_get(rdns_compression_hash, comp, check);
@@ -72,18 +76,21 @@ rdns_add_compressed (const char *pos, const char *end,
struct rdns_compression_name new_name;
int r;
- assert (offset >= 0);
- new_name.suffix_len = end - pos;
- new_name.suffix = pos;
- new_name.offset = offset;
+ if (comp != NULL) {
+
+ assert (offset >= 0);
+ new_name.suffix_len = end - pos;
+ new_name.suffix = pos;
+ new_name.offset = offset;
- kh_put(rdns_compression_hash, comp, new_name, &r);
+ kh_put(rdns_compression_hash, comp, new_name, &r);
+ }
}
void
rdns_compression_free (khash_t(rdns_compression_hash) *comp)
{
- if (comp) {
+ if (comp != NULL) {
kh_destroy(rdns_compression_hash, comp);
}
}
@@ -102,24 +109,23 @@ rdns_write_name_compressed (struct rdns_request *req,
if (comp != NULL && *comp == NULL) {
*comp = kh_init(rdns_compression_hash);
}
- else if (comp == NULL) {
- return false;
- }
while (pos < end && remain > 0) {
- struct rdns_compression_name *test = rdns_can_compress (pos, end - pos, *comp);
- if (test != NULL) {
- /* Can compress name */
- if (remain < 2) {
- rdns_info ("no buffer remain for constructing query");
- return false;
+ if (comp) {
+ struct rdns_compression_name *test = rdns_can_compress(pos, end - pos, *comp);
+ if (test != NULL) {
+ /* Can compress name */
+ if (remain < 2) {
+ rdns_info ("no buffer remain for constructing query");
+ return false;
+ }
+
+ pointer = htons ((uint16_t) test->offset) | DNS_COMPRESSION_BITS;
+ memcpy(target, &pointer, sizeof(pointer));
+ req->pos += 2;
+
+ return true;
}
-
- pointer = htons ((uint16_t)test->offset) | DNS_COMPRESSION_BITS;
- memcpy (target, &pointer, sizeof (pointer));
- req->pos += 2;
-
- return true;
}
label_len = rdns_calculate_label_len (pos, end);
@@ -144,7 +150,9 @@ rdns_write_name_compressed (struct rdns_request *req,
label_len = remain - 1;
}
- rdns_add_compressed (pos, end, *comp, target - req->packet);
+ if (comp) {
+ rdns_add_compressed(pos, end, *comp, target - req->packet);
+ }
/* Write label as is */
*target++ = (uint8_t)label_len;
memcpy (target, pos, label_len);
diff --git a/contrib/librdns/packet.c b/contrib/librdns/packet.c
index 5c822ffef..59a919e9f 100644
--- a/contrib/librdns/packet.c
+++ b/contrib/librdns/packet.c
@@ -245,7 +245,7 @@ err:
bool
rdns_add_rr (struct rdns_request *req, const char *name, unsigned int len,
- enum dns_type type, struct rdns_compression_entry **comp)
+ enum dns_type type, struct kh_rdns_compression_hash_s **comp)
{
uint8_t *p8;
diff --git a/contrib/librdns/packet.h b/contrib/librdns/packet.h
index 6d22de4e0..44e16a50b 100644
--- a/contrib/librdns/packet.h
+++ b/contrib/librdns/packet.h
@@ -27,7 +27,7 @@
#include <stdint.h>
#include "dns_private.h"
-struct rdns_compression_entry;
+struct kh_rdns_compression_hash_s;
/**
* Allocate dns packet suitable to handle up to `namelen` name
@@ -50,7 +50,7 @@ void rdns_make_dns_header (struct rdns_request *req, unsigned int qcount);
* @param type type of resource record
*/
bool rdns_add_rr (struct rdns_request *req, const char *name, unsigned int len,
- enum dns_type type, struct rdns_compression_entry **comp);
+ enum dns_type type, struct kh_rdns_compression_hash_s **comp);
/**
* Add EDNS0 section