dnsmasq: update to dnsmasq 2.77test1
[openwrt/openwrt.git] / package / network / services / dnsmasq / patches / 010-localise-queries-apply-to-interface-names.patch
1 From d42d4706bbcce3b5a40ad778a5a356a997db6b34 Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Thu, 2 Feb 2017 16:52:06 +0000
4 Subject: [PATCH] Make --localise-queries apply to names from
5 --interface-name.
6
7 ---
8 CHANGELOG | 7 +++++++
9 man/dnsmasq.8 | 9 +++++----
10 src/rfc1035.c | 21 ++++++++++++++++++++-
11 3 files changed, 32 insertions(+), 5 deletions(-)
12
13 --- a/CHANGELOG
14 +++ b/CHANGELOG
15 @@ -58,6 +58,13 @@ version 2.77
16 this is Nominum's. Thanks to Dave Täht for spotting the
17 bug and assisting in the fix.
18
19 + Fix the manpage which lied that only the primary address
20 + of an interface is used by --interface-name.
21 +
22 + Make --localise-queries apply to names from --interface-name.
23 + Thanks to Kevin Darbyshire-Bryant and Eric Luehrsen
24 + for pushing this.
25 +
26
27 version 2.76
28 Include 0.0.0.0/8 in DNS rebind checks. This range
29 --- a/man/dnsmasq.8
30 +++ b/man/dnsmasq.8
31 @@ -289,8 +289,8 @@ option requires non-standard networking
32 under Linux. On other platforms it falls-back to --bind-interfaces mode.
33 .TP
34 .B \-y, --localise-queries
35 -Return answers to DNS queries from /etc/hosts which depend on the interface over which the query was
36 -received. If a name in /etc/hosts has more than one address associated with
37 +Return answers to DNS queries from /etc/hosts and --interface-name which depend on the interface over which the query was
38 +received. If a name has more than one address associated with
39 it, and at least one of those addresses is on the same subnet as the
40 interface to which the query was sent, then return only the
41 address(es) on that subnet. This allows for a server to have multiple
42 @@ -604,7 +604,7 @@ given by the hex data, which may be of t
43 012345 or any mixture of these.
44 .TP
45 .B --interface-name=<name>,<interface>[/4|/6]
46 -Return a DNS record associating the name with the primary address on
47 +Return DNS records associating the name with the address(es) of
48 the given interface. This flag specifies an A or AAAA record for the given
49 name in the same way as an /etc/hosts line, except that the address is
50 not constant, but taken from the given interface. The interface may be
51 @@ -614,7 +614,8 @@ down, not configured or non-existent, an
52 matching PTR record is also created, mapping the interface address to
53 the name. More than one name may be associated with an interface
54 address by repeating the flag; in that case the first instance is used
55 -for the reverse address-to-name mapping.
56 +for the reverse address-to-name mapping. Note that a name used in
57 +--interface-name may not appear in /etc/hosts.
58 .TP
59 .B --synth-domain=<domain>,<address range>[,<prefix>]
60 Create artificial A/AAAA and PTR records for an address range. The
61 --- a/src/rfc1035.c
62 +++ b/src/rfc1035.c
63 @@ -1516,9 +1516,24 @@ size_t answer_request(struct dns_header
64 if (intr)
65 {
66 struct addrlist *addrlist;
67 - int gotit = 0;
68 + int gotit = 0, localise = 0;
69
70 enumerate_interfaces(0);
71 +
72 + /* See if a putative address is on the network from which we recieved
73 + the query, is so we'll filter other answers. */
74 + if (local_addr.s_addr != 0 && option_bool(OPT_LOCALISE) && type == T_A)
75 + for (intr = daemon->int_names; intr; intr = intr->next)
76 + if (hostname_isequal(name, intr->name))
77 + for (addrlist = intr->addr; addrlist; addrlist = addrlist->next)
78 +#ifdef HAVE_IPV6
79 + if (!(addrlist->flags & ADDRLIST_IPV6))
80 +#endif
81 + if (is_same_net(*((struct in_addr *)&addrlist->addr), local_addr, local_netmask))
82 + {
83 + localise = 1;
84 + break;
85 + }
86
87 for (intr = daemon->int_names; intr; intr = intr->next)
88 if (hostname_isequal(name, intr->name))
89 @@ -1528,6 +1543,10 @@ size_t answer_request(struct dns_header
90 if (((addrlist->flags & ADDRLIST_IPV6) ? T_AAAA : T_A) == type)
91 #endif
92 {
93 + if (localise &&
94 + !is_same_net(*((struct in_addr *)&addrlist->addr), local_addr, local_netmask))
95 + continue;
96 +
97 #ifdef HAVE_IPV6
98 if (addrlist->flags & ADDRLIST_REVONLY)
99 continue;