[Dnsmasq-discuss] [PATCH] Restore the query name before selecting a TCP upstream.
ooonea
ooonea at gmail.com
Mon Nov 16 14:38:37 UTC 2026
answer_request() uses namebuff to walk cached CNAMEs. If it cannot
answer the query, namebuff can still contain the last CNAME target.
Selecting an upstream with that name can send the original TCP query
to the wrong split-DNS server.
Extract the name again from the original query before selecting the
server, including when refreshing a stale answer.
Assisted-by: OpenAI Codex
---
Tested with two local upstreams after caching a CNAME via an AAAA reply:
TCP A queries and stale-answer refreshes use the original name's server.
src/forward.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/forward.c b/src/forward.c
index dae9a4f..c89eba1 100644
--- a/src/forward.c
+++ b/src/forward.c
@@ -2612,6 +2612,9 @@ void tcp_request(int confd, time_t now, struct iovec *bigbuff,
/* save state of "cd" flag in query */
checking_disabled = header->hb4 & HB4_CD;
+
+ /* answer_request() may have replaced the query name with a CNAME target. */
+ extract_request(header, size, daemon->namebuff, NULL, NULL);
if (lookup_domain(daemon->namebuff, gotname, &first, &last))
flags = is_local_answer(now, first, daemon->namebuff);
--
2.54.0
More information about the Dnsmasq-discuss
mailing list