6d0937
From 7c80b06983505a0cb52d5e112777c9acbe2cb300 Mon Sep 17 00:00:00 2001
6d0937
From: Simon Kelley <simon@thekelleys.org.uk>
6d0937
Date: Fri, 22 Jan 2021 16:49:12 +0000
6d0937
Subject: [PATCH] Move fd into frec_src, fixes
6d0937
 15b60ddf935a531269bb8c68198de012a4967156
6d0937
6d0937
If identical queries from IPv4 and IPv6 sources are combined by the
6d0937
new code added in 15b60ddf935a531269bb8c68198de012a4967156 then replies
6d0937
can end up being sent via the wrong family of socket. The ->fd
6d0937
should be per query, not per-question.
6d0937
6d0937
In bind-interfaces mode, this could also result in replies being sent
6d0937
via the wrong socket even when IPv4/IPV6 issues are not in play.
6d0937
6d0937
(cherry picked from commit 04490bf622ac84891aad6f2dd2edf83725decdee)
6d0937
6d0937
Fix for 12af2b171de0d678d98583e2190789e544440e02
6d0937
6d0937
(cherry picked from commit 3f535da79e7a42104543ef5c7b5fa2bed819a78b)
6d0937
---
6d0937
 src/dnsmasq.h | 3 ++-
6d0937
 src/forward.c | 5 +++--
6d0937
 2 files changed, 5 insertions(+), 3 deletions(-)
6d0937
6d0937
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
6d0937
index 9f5b48b..77f59b9 100644
6d0937
--- a/src/dnsmasq.h
6d0937
+++ b/src/dnsmasq.h
6d0937
@@ -607,6 +607,7 @@ struct frec {
6d0937
     union mysockaddr source;
6d0937
     struct all_addr dest;
6d0937
     unsigned int iface, log_id;
6d0937
+    int fd;
6d0937
     unsigned short orig_id;
6d0937
     struct frec_src *next;
6d0937
   } frec_src;
6d0937
@@ -616,7 +617,7 @@ struct frec {
6d0937
   struct randfd *rfd6;
6d0937
 #endif
6d0937
   unsigned short new_id;
6d0937
-  int fd, forwardall, flags;
6d0937
+  int forwardall, flags;
6d0937
   time_t time;
6d0937
   unsigned char *hash[HASH_SIZE];
6d0937
 #ifdef HAVE_DNSSEC 
6d0937
diff --git a/src/forward.c b/src/forward.c
6d0937
index a0b1f1d..637f220 100644
6d0937
--- a/src/forward.c
6d0937
+++ b/src/forward.c
6d0937
@@ -366,6 +366,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
6d0937
 	      new->dest = *dst_addr;
6d0937
 	      new->log_id = daemon->log_id;
6d0937
 	      new->iface = dst_iface;
6d0937
+	      new->fd = udpfd;
6d0937
 	    }
6d0937
 	  
6d0937
 	  return 1;
6d0937
@@ -390,8 +391,8 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
6d0937
 	  forward->frec_src.dest = *dst_addr;
6d0937
 	  forward->frec_src.iface = dst_iface;
6d0937
 	  forward->frec_src.next = NULL;
6d0937
+	  forward->frec_src.fd = udpfd;
6d0937
 	  forward->new_id = get_id();
6d0937
-	  forward->fd = udpfd;
6d0937
 	  memcpy(forward->hash, hash, HASH_SIZE);
6d0937
 	  forward->forwardall = 0;
6d0937
 	  forward->flags = fwd_flags;
6d0937
@@ -1169,7 +1170,7 @@ void reply_query(int fd, int family, time_t now)
6d0937
 	    {
6d0937
 	      header->id = htons(src->orig_id);
6d0937
 	      
6d0937
-	      send_from(forward->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn, 
6d0937
+	      send_from(src->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn, 
6d0937
 			&src->source, &src->dest, src->iface);
6d0937
 
6d0937
 	      if (option_bool(OPT_EXTRALOG) && src != &forward->frec_src)
6d0937
-- 
6d0937
2.26.2
6d0937