dnsmasq: backport fixes
[librecmc/librecmc.git] / package / network / services / dnsmasq / patches / 0116-Move-fd-into-frec_src-fixes-15b60ddf935a531269bb8c68.patch
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
6
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.
11
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.
14
15 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
16 ---
17  src/dnsmasq.h | 3 ++-
18  src/forward.c | 4 ++--
19  2 files changed, 4 insertions(+), 3 deletions(-)
20
21 --- a/src/dnsmasq.h
22 +++ b/src/dnsmasq.h
23 @@ -653,6 +653,7 @@ struct frec {
24      union mysockaddr source;
25      union all_addr dest;
26      unsigned int iface, log_id;
27 +    int fd;
28      unsigned short orig_id;
29      struct frec_src *next;
30    } frec_src;
31 @@ -660,7 +661,7 @@ struct frec {
32    struct randfd *rfd4;
33    struct randfd *rfd6;
34    unsigned short new_id;
35 -  int fd, forwardall, flags;
36 +  int forwardall, flags;
37    time_t time;
38    unsigned char *hash[HASH_SIZE];
39  #ifdef HAVE_DNSSEC 
40 --- a/src/forward.c
41 +++ b/src/forward.c
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);
54  #endif
55               
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);
59  
60               if (option_bool(OPT_EXTRALOG) && src != &forward->frec_src)