From a9d46d42cb2da24c6eb6c887b948fb0c71d4c094 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Sun, 13 Oct 2024 23:09:48 +0100 Subject: [PATCH] Tweak packet-reduction code going from TCP->UDP. --- src/forward.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/forward.c b/src/forward.c index 8f58311..e9a50a3 100644 --- a/src/forward.c +++ b/src/forward.c @@ -2143,11 +2143,18 @@ int tcp_from_udp(time_t now, int status, struct dns_header *header, ssize_t *ple if (n >= daemon->edns_pktsz) { - new_header->ancount = htons(0); + /* still too bug, strip optional sections and try again. */ new_header->nscount = htons(0); new_header->arcount = htons(0); - n = resize_packet(header, n, NULL, 0); - new_status = STAT_TRUNCATED; + n = resize_packet(new_header, n, NULL, 0); + if (n >= daemon->edns_pktsz) + { + /* truncating the packet will break the answers, so remove them too + and mark the reply as truncated. */ + new_header->ancount = htons(0); + n = resize_packet(new_header, n, NULL, 0); + new_status = STAT_TRUNCATED; + } } /* return the stripped or truncated reply. */