diff options
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/kubernetes/reverse_test.go | 26 | ||||
-rw-r--r-- | plugin/kubernetes/setup_reverse_test.go | 1 | ||||
-rw-r--r-- | plugin/normalize.go | 9 |
3 files changed, 33 insertions, 3 deletions
diff --git a/plugin/kubernetes/reverse_test.go b/plugin/kubernetes/reverse_test.go index 881b99285..bfb9e4aa9 100644 --- a/plugin/kubernetes/reverse_test.go +++ b/plugin/kubernetes/reverse_test.go @@ -50,6 +50,8 @@ func (APIConnReverseTest) EpIndexReverse(ip string) []*api.Endpoints { switch ip { case "10.0.0.100": case "1234:abcd::1": + case "fd00:77:30::a": + case "fd00:77:30::2:9ba6": default: return nil } @@ -66,6 +68,14 @@ func (APIConnReverseTest) EpIndexReverse(ip string) []*api.Endpoints { IP: "1234:abcd::1", Hostname: "ep1b", }, + { + IP: "fd00:77:30::a", + Hostname: "ip6svc1ex", + }, + { + IP: "fd00:77:30::2:9ba6", + Hostname: "ip6svc1in", + }, }, Ports: []api.EndpointPort{ { @@ -103,7 +113,7 @@ func (APIConnReverseTest) GetNamespaceByName(name string) (*api.Namespace, error func TestReverse(t *testing.T) { - k := New([]string{"cluster.local.", "0.10.in-addr.arpa.", "168.192.in-addr.arpa.", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.c.b.a.4.3.2.1.ip6.arpa."}) + k := New([]string{"cluster.local.", "0.10.in-addr.arpa.", "168.192.in-addr.arpa.", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.c.b.a.4.3.2.1.ip6.arpa.", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa."}) k.APIConn = &APIConnReverseTest{} tests := []test.Case{ @@ -128,6 +138,20 @@ func TestReverse(t *testing.T) { test.PTR("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.c.b.a.4.3.2.1.ip6.arpa. 5 IN PTR ep1b.svc1.testns.svc.cluster.local."), }, }, + { // A PTR record query for an existing ipv6 endpoint should return a record + Qname: "a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa.", Qtype: dns.TypePTR, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.PTR("a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa. 5 IN PTR ip6svc1ex.svc1.testns.svc.cluster.local."), + }, + }, + { // A PTR record query for an existing ipv6 endpoint should return a record + Qname: "6.a.b.9.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa.", Qtype: dns.TypePTR, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.PTR("6.a.b.9.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa. 5 IN PTR ip6svc1in.svc1.testns.svc.cluster.local."), + }, + }, { Qname: "101.0.0.10.in-addr.arpa.", Qtype: dns.TypePTR, Rcode: dns.RcodeSuccess, diff --git a/plugin/kubernetes/setup_reverse_test.go b/plugin/kubernetes/setup_reverse_test.go index 626874e6d..3ba92a9ec 100644 --- a/plugin/kubernetes/setup_reverse_test.go +++ b/plugin/kubernetes/setup_reverse_test.go @@ -13,6 +13,7 @@ func TestKubernetesParseReverseZone(t *testing.T) { }{ {`kubernetes coredns.local 10.0.0.0/16`, []string{"coredns.local.", "0.10.in-addr.arpa."}}, {`kubernetes coredns.local 10.0.0.0/17`, []string{"coredns.local.", "0.10.in-addr.arpa."}}, + {`kubernetes coredns.local fd00:77:30::0/110`, []string{"coredns.local.", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa."}}, } for i, tc := range tests { diff --git a/plugin/normalize.go b/plugin/normalize.go index f8cbcf7a0..ef6f2eaa0 100644 --- a/plugin/normalize.go +++ b/plugin/normalize.go @@ -115,11 +115,16 @@ func SplitHostPort(s string) (host, port string, ipnet *net.IPNet, err error) { if err == nil { if rev, e := dns.ReverseAddr(ip.String()); e == nil { ones, bits = n.Mask.Size() + // get the size, in bits, of each portion of hostname defined in the reverse address. (8 for IPv4, 4 for IPv6) + sizeDigit := 8 + if len(n.IP) == net.IPv6len { + sizeDigit = 4 + } // Get the first lower octet boundary to see what encompassing zone we should be authoritative for. - mod := (bits - ones) % 8 + mod := (bits - ones) % sizeDigit nearest := (bits - ones) + mod offset, end := 0, false - for i := 0; i < nearest/8; i++ { + for i := 0; i < nearest/sizeDigit; i++ { offset, end = dns.NextLabel(rev, offset) if end { break |