1 From 04490bf622ac84891aad6f2dd2edf83725decdee Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Fri, 22 Jan 2021 16:49:12 +0000
4 Subject: [PATCH 1/4] Move fd into frec_src, fixes
5 15b60ddf935a531269bb8c68198de012a4967156
7 If identical queries from IPv4 and IPv6 sources are combined by the
8 new code added in 15b60ddf935a531269bb8c68198de012a4967156 then replies
9 can end up being sent via the wrong family of socket. The ->fd
10 should be per query, not per-question.
12 In bind-interfaces mode, this could also result in replies being sent
13 via the wrong socket even when IPv4/IPV6 issues are not in play.
15 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
18 src/forward.c | 4 ++--
19 2 files changed, 4 insertions(+), 3 deletions(-)
23 @@ -653,6 +653,7 @@ struct frec {
24 union mysockaddr source;
26 unsigned int iface, log_id;
28 unsigned short orig_id;
29 struct frec_src *next;
31 @@ -660,7 +661,7 @@ struct frec {
34 unsigned short new_id;
35 - int fd, forwardall, flags;
36 + int forwardall, flags;
38 unsigned char *hash[HASH_SIZE];
42 @@ -394,8 +394,8 @@ static int forward_query(int udpfd, unio
43 forward->frec_src.dest = *dst_addr;
44 forward->frec_src.iface = dst_iface;
45 forward->frec_src.next = NULL;
46 + forward->frec_src.fd = udpfd;
47 forward->new_id = get_id();
48 - forward->fd = udpfd;
49 memcpy(forward->hash, hash, HASH_SIZE);
50 forward->forwardall = 0;
51 forward->flags = fwd_flags;
52 @@ -1284,7 +1284,7 @@ void reply_query(int fd, int family, tim
53 dump_packet(DUMP_REPLY, daemon->packet, (size_t)nn, NULL, &src->source);
56 - send_from(forward->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn,
57 + send_from(src->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn,
58 &src->source, &src->dest, src->iface);
60 if (option_bool(OPT_EXTRALOG) && src != &forward->frec_src)