From 58fc55a9f03cc9fd514146111bfa673514d30c17 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Fri, 7 Feb 2025 19:56:33 +0000 Subject: [PATCH 1/3] Fix 0x20 problem. A retry to upstream DNS servers triggered by the following conditions 1) A query asking for the same data as a previous query which has not yet been answered. 2) The second query arrives more than two seconds after the first. 3) Either the source of the second query or the id field differs from the first. fails to set the case of the retry to the same pattern as the first attempt. However dnsmasq expects the reply from upstream to have the case pattern of the first attempt. If the answer to the retry arrives before the answer to the first query, dnsmasq will notice the case mismatch, log an error, and ignore the answer. The worst case scenario would be the first upstream query or reply is lost and there would follow a short period where all queries for that particular domain would fail. This is a 2.91 development issue, it doesn't apply to previous stable releases. Signed-off-by: DL6ER --- src/dnsmasq/forward.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/dnsmasq/forward.c b/src/dnsmasq/forward.c index 3d341db7e..5a0015f9a 100644 --- a/src/dnsmasq/forward.c +++ b/src/dnsmasq/forward.c @@ -205,9 +205,9 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr, FREC_HAS_PHEADER | FREC_DNSKEY_QUERY | FREC_DS_QUERY | FREC_NO_CACHE))) { struct frec_src *src; - struct dns_header *saved_header; unsigned int casediff = 0; unsigned int *bitvector = NULL; + unsigned short id; for (src = &forward->frec_src; src; src = src->next) if (src->orig_id == ntohs(header->id) && @@ -250,7 +250,7 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr, goto reply; } - /* Find a bitmap of case differences between the query send upstream and this one, + /* Find a bitmap of case differences between the query sent upstream and this one, so we can reply to each query with the correct case pattern. Since we need this to get back the exact case pattern of each query when doing query combining, we have to handle the (rare) case that there are case differences @@ -261,9 +261,19 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr, we only scramble the first 32 letters for security reasons. Note the two names are guaranteed to be the same length and differ only in the case - of letters. */ - if ((saved_header = blockdata_retrieve(forward->stash, forward->stash_len, NULL)) && - extract_request(saved_header, forward->stash_len, daemon->workspacename, NULL)) + of letters at this point. + + Get the original query into the packet buffer and extract the query name it contains + to calculate the difference in case scrambling. This is important because we + may fall through below and forward the query in the packet buffer again and we + want to use the same case scrambling as the first time. + + Retrieve the id from the new query before we overwrite it. */ + + id = ntohs(header->id); + + if (blockdata_retrieve(forward->stash, forward->stash_len, (void *)header) && + extract_request(header, forward->stash_len, daemon->workspacename, NULL)) { unsigned int i, gobig = 0; char *s1, *s2; @@ -302,7 +312,7 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr, daemon->free_frec_src = src->next; src->next = forward->frec_src.next; forward->frec_src.next = src; - src->orig_id = ntohs(header->id); + src->orig_id = id; src->source = *udpaddr; src->dest = *dst_addr; src->log_id = daemon->log_id; From e992a73c6fbcd78aa76120aa7c0baea10cdc22d4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 8 Feb 2025 06:54:44 +0100 Subject: [PATCH 2/3] Update dnsmasq version to 2.91rc3 Signed-off-by: DL6ER --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1042bb230..b3ef60b65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,6 @@ set(CMAKE_C_STANDARD 17) project(PIHOLE_FTL C) -set(DNSMASQ_VERSION pi-hole-v2.91rc2) +set(DNSMASQ_VERSION pi-hole-v2.91rc3) add_subdirectory(src) From 7f0a373712efdd047bd207aa8b93c067870b8d0c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 8 Feb 2025 10:27:59 +0100 Subject: [PATCH 3/3] Add missing newline to verbose version output Signed-off-by: DL6ER --- src/args.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.c b/src/args.c index 2b4ed0382..363da3949 100644 --- a/src/args.c +++ b/src/args.c @@ -811,7 +811,7 @@ void parse_args(int argc, char *argv[]) printf("Version: %s%s%s%s\n", green, bold, get_FTL_version(), normal); printf("Branch: %s\n", git_branch()); - printf("Commit: %s (%s)",git_hash(), git_date()); + printf("Commit: %s (%s)\n",git_hash(), git_date()); printf("Architecture: %s\n", ftl_arch()); printf("Compiler: %s\n", ftl_cc()); #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)