1 From 6d95099c56a926d672e0407d6017fef9714f40c4 Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Thu, 11 Aug 2016 23:38:54 +0100
4 Subject: [PATCH] Handle v4-mapped IPv6 addresses sanely for --synth-domain.
9 src/domain.c | 34 ++++++++++++++++++++++++----------
10 3 files changed, 32 insertions(+), 11 deletions(-)
12 diff --git a/CHANGELOG b/CHANGELOG
13 index 4f89799..2731cc4 100644
16 @@ -24,7 +24,12 @@ version 2.77
17 Bump zone serial on reloading /etc/hosts and friends
18 when providing authoritative DNS. Thanks to Harrald
19 Dunkel for spotting this.
22 + Handle v4-mapped IPv6 addresses sanely in --synth-domain.
23 + These have standard representation like ::ffff:1.2.3.4
24 + and are now converted to names like
25 + <prefix>--ffff-1-2-3-4.<domain>
29 Include 0.0.0.0/8 in DNS rebind checks. This range
30 diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
31 index 8910947..91fe672 100644
34 @@ -619,6 +619,8 @@ but IPv6 addresses may start with '::'
35 but DNS labels may not start with '-' so in this case if no prefix is
36 configured a zero is added in front of the label. ::1 becomes 0--1.
38 +V4 mapped IPv6 addresses, which have a representation like ::ffff:1.2.3.4 are handled specially, and become like 0--ffff-1-2-3-4
40 The address range can be of the form
41 <ip address>,<ip address> or <ip address>/<netmask>
43 diff --git a/src/domain.c b/src/domain.c
44 index 1dd5027..a007acd 100644
47 @@ -77,18 +77,31 @@ int is_name_synthetic(int flags, char *name, struct all_addr *addr)
51 - /* swap . or : for - */
52 - for (p = tail; *p; p++)
55 - if (prot == AF_INET)
57 + if (prot == AF_INET6 && strstr(tail, "--ffff-") == tail)
59 + /* special hack for v4-mapped. */
60 + memcpy(tail, "::ffff:", 7);
61 + for (p = tail + 7; *p; p++)
68 + /* swap . or : for - */
69 + for (p = tail; *p; p++)
72 + if (prot == AF_INET)
85 if (hostname_isequal(c->domain, p+1) && inet_pton(prot, tail, addr))
88 @@ -169,8 +182,9 @@ int is_rev_synth(int flag, struct all_addr *addr, char *name)
89 inet_ntop(AF_INET6, &addr->addr.addr6, name+1, ADDRSTRLEN);
92 + /* V4-mapped have periods.... */
93 for (p = name; *p; p++)
95 + if (*p == ':' || *p == '.')
98 strncat(name, ".", MAXDNAME);