diff options
author | 2019-01-28 16:36:34 +0000 | |
---|---|---|
committer | 2019-01-28 16:36:34 +0000 | |
commit | e3435566879c6a7ed564fc7108a12c0121ecd56c (patch) | |
tree | ceec2f8c0bb9c2bec55c5a0f77b79788dee74858 | |
parent | d571fbe04622096081a21935ce4c0bcda90361ce (diff) | |
download | coredns-e3435566879c6a7ed564fc7108a12c0121ecd56c.tar.gz coredns-e3435566879c6a7ed564fc7108a12c0121ecd56c.tar.zst coredns-e3435566879c6a7ed564fc7108a12c0121ecd56c.zip |
plugin/hosts: fix for ipv4-in-ipv6 (#2506)
* fix for ipv4-in-ipv6
* update comment as requested
-rw-r--r-- | plugin/hosts/hosts_test.go | 16 | ||||
-rw-r--r-- | plugin/hosts/hostsfile.go | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/plugin/hosts/hosts_test.go b/plugin/hosts/hosts_test.go index 6515f36b9..e412b7ae5 100644 --- a/plugin/hosts/hosts_test.go +++ b/plugin/hosts/hosts_test.go @@ -45,6 +45,12 @@ var hostsTestCases = []test.Case{ }, }, { + Qname: "example.com.", Qtype: dns.TypeA, + Answer: []dns.RR{ + test.A("example.com. 3600 IN A 10.0.0.2"), + }, + }, + { Qname: "localhost.", Qtype: dns.TypeAAAA, Answer: []dns.RR{ test.AAAA("localhost. 3600 IN AAAA ::1"), @@ -57,6 +63,12 @@ var hostsTestCases = []test.Case{ }, }, { + Qname: "2.0.0.10.in-addr.arpa.", Qtype: dns.TypePTR, + Answer: []dns.RR{ + test.PTR("2.0.0.10.in-addr.arpa. 3600 PTR example.com."), + }, + }, + { Qname: "1.0.0.127.in-addr.arpa.", Qtype: dns.TypePTR, Answer: []dns.RR{ test.PTR("1.0.0.127.in-addr.arpa. 3600 PTR localhost."), @@ -76,4 +88,6 @@ var hostsTestCases = []test.Case{ const hostsExample = ` 127.0.0.1 localhost localhost.domain ::1 localhost localhost.domain -10.0.0.1 example.org` +10.0.0.1 example.org +::FFFF:10.0.0.2 example.com +` diff --git a/plugin/hosts/hostsfile.go b/plugin/hosts/hostsfile.go index 8b2ffa0a6..1cce850c3 100644 --- a/plugin/hosts/hostsfile.go +++ b/plugin/hosts/hostsfile.go @@ -185,8 +185,10 @@ func (h *Hostsfile) parse(r io.Reader, override *hostsMap) *hostsMap { } // ipVersion returns what IP version was used textually +// For why the string is parsed end to start, +// see IPv4-Compatible IPv6 addresses - RFC 4291 section 2.5.5 func ipVersion(s string) int { - for i := 0; i < len(s); i++ { + for i := len(s) - 1; i >= 0; i-- { switch s[i] { case '.': return 4 |