From 305b5db4ebcef190873bf475d50d1e12738cabc2 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 9 Sep 2024 13:09:47 +0200 Subject: [PATCH] dns_msg: add debug output --- sys/net/application_layer/dns/msg.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/net/application_layer/dns/msg.c b/sys/net/application_layer/dns/msg.c index 767c697d87..4cf5758594 100644 --- a/sys/net/application_layer/dns/msg.c +++ b/sys/net/application_layer/dns/msg.c @@ -26,6 +26,9 @@ #include "net/dns/msg.h" +#define ENABLE_DEBUG 0 +#include "debug.h" + static ssize_t _enc_domain_name(uint8_t *out, const char *domain_name) { /* @@ -76,10 +79,13 @@ static ssize_t _skip_hostname(const uint8_t *buf, size_t len, if (bufpos >= buflim) { /* out-of-bound */ + DEBUG("dns_msg: bufpos is out of bounds\n"); return -EBADMSG; } + /* handle DNS Message Compression */ - if (*bufpos >= 192) { + if (*bufpos & 0xc0) { + DEBUG("dns_msg: hostname is compressed\n"); if ((bufpos + 2) >= buflim) { return -EBADMSG; } @@ -90,6 +96,7 @@ static ssize_t _skip_hostname(const uint8_t *buf, size_t len, res += bufpos[res] + 1; if ((&bufpos[res]) >= buflim) { /* out-of-bound */ + DEBUG("dns_msg: hostname out-of-bounds\n"); return -EBADMSG; } } @@ -156,6 +163,7 @@ int dns_msg_parse_reply(const uint8_t *buf, size_t len, int family, bufpos += tmp; if ((bufpos + RR_TYPE_LENGTH + RR_CLASS_LENGTH + RR_TTL_LENGTH + sizeof(uint16_t)) >= buflim) { + DEBUG("dns_msg: record beyond buf limit"); return -EBADMSG; } uint16_t _type = ntohs(_get_short(bufpos)); @@ -173,6 +181,8 @@ int dns_msg_parse_reply(const uint8_t *buf, size_t len, int family, return -EBADMSG; } + DEBUG("dns_msg: type: %u, class: %u, len: %u\n", _type, class, addrlen); + /* skip unwanted answers */ if ((class != DNS_CLASS_IN) || ((_type == DNS_TYPE_A) && (family == AF_INET6)) ||