1
0

0116-Move-fd-into-frec_src-fixes-15b60ddf935a531269bb8c68.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. If identical queries from IPv4 and IPv6 sources are combined by the
  7. new code added in 15b60ddf935a531269bb8c68198de012a4967156 then replies
  8. can end up being sent via the wrong family of socket. The ->fd
  9. should be per query, not per-question.
  10. In bind-interfaces mode, this could also result in replies being sent
  11. via the wrong socket even when IPv4/IPV6 issues are not in play.
  12. Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
  13. ---
  14. src/dnsmasq.h | 3 ++-
  15. src/forward.c | 4 ++--
  16. 2 files changed, 4 insertions(+), 3 deletions(-)
  17. --- a/src/dnsmasq.h
  18. +++ b/src/dnsmasq.h
  19. @@ -653,6 +653,7 @@ struct frec {
  20. union mysockaddr source;
  21. union all_addr dest;
  22. unsigned int iface, log_id;
  23. + int fd;
  24. unsigned short orig_id;
  25. struct frec_src *next;
  26. } frec_src;
  27. @@ -660,7 +661,7 @@ struct frec {
  28. struct randfd *rfd4;
  29. struct randfd *rfd6;
  30. unsigned short new_id;
  31. - int fd, forwardall, flags;
  32. + int forwardall, flags;
  33. time_t time;
  34. unsigned char *hash[HASH_SIZE];
  35. #ifdef HAVE_DNSSEC
  36. --- a/src/forward.c
  37. +++ b/src/forward.c
  38. @@ -394,8 +394,8 @@ static int forward_query(int udpfd, unio
  39. forward->frec_src.dest = *dst_addr;
  40. forward->frec_src.iface = dst_iface;
  41. forward->frec_src.next = NULL;
  42. + forward->frec_src.fd = udpfd;
  43. forward->new_id = get_id();
  44. - forward->fd = udpfd;
  45. memcpy(forward->hash, hash, HASH_SIZE);
  46. forward->forwardall = 0;
  47. forward->flags = fwd_flags;
  48. @@ -1284,7 +1284,7 @@ void reply_query(int fd, int family, tim
  49. dump_packet(DUMP_REPLY, daemon->packet, (size_t)nn, NULL, &src->source);
  50. #endif
  51. - send_from(forward->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn,
  52. + send_from(src->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn,
  53. &src->source, &src->dest, src->iface);
  54. if (option_bool(OPT_EXTRALOG) && src != &forward->frec_src)