Commit e3435566 authored by Thomas Mangin's avatar Thomas Mangin Committed by Miek Gieben

plugin/hosts: fix for ipv4-in-ipv6 (#2506)

* fix for ipv4-in-ipv6

* update comment as requested
parent d571fbe0
...@@ -44,6 +44,12 @@ var hostsTestCases = []test.Case{ ...@@ -44,6 +44,12 @@ var hostsTestCases = []test.Case{
test.A("example.org. 3600 IN A 10.0.0.1"), test.A("example.org. 3600 IN A 10.0.0.1"),
}, },
}, },
{
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, Qname: "localhost.", Qtype: dns.TypeAAAA,
Answer: []dns.RR{ Answer: []dns.RR{
...@@ -56,6 +62,12 @@ var hostsTestCases = []test.Case{ ...@@ -56,6 +62,12 @@ var hostsTestCases = []test.Case{
test.PTR("1.0.0.10.in-addr.arpa. 3600 PTR example.org."), test.PTR("1.0.0.10.in-addr.arpa. 3600 PTR example.org."),
}, },
}, },
{
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, Qname: "1.0.0.127.in-addr.arpa.", Qtype: dns.TypePTR,
Answer: []dns.RR{ Answer: []dns.RR{
...@@ -76,4 +88,6 @@ var hostsTestCases = []test.Case{ ...@@ -76,4 +88,6 @@ var hostsTestCases = []test.Case{
const hostsExample = ` const hostsExample = `
127.0.0.1 localhost localhost.domain 127.0.0.1 localhost localhost.domain
::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
`
...@@ -185,8 +185,10 @@ func (h *Hostsfile) parse(r io.Reader, override *hostsMap) *hostsMap { ...@@ -185,8 +185,10 @@ func (h *Hostsfile) parse(r io.Reader, override *hostsMap) *hostsMap {
} }
// ipVersion returns what IP version was used textually // 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 { func ipVersion(s string) int {
for i := 0; i < len(s); i++ { for i := len(s) - 1; i >= 0; i-- {
switch s[i] { switch s[i] {
case '.': case '.':
return 4 return 4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment