aboutsummaryrefslogtreecommitdiff
path: root/plugin/normalize.go
diff options
context:
space:
mode:
authorGravatar Francois Tur <ftur@infoblox.com> 2018-01-23 10:58:36 -0500
committerGravatar Miek Gieben <miek@miek.nl> 2018-01-23 15:58:36 +0000
commitf9c03c2ead6ae655006b3b8264b9870028884d8f (patch)
tree11c04997e8b01f6573b6d9aa5d707e149fdd516b /plugin/normalize.go
parent9575789c363d9fc72eb96f3263e94d2037142335 (diff)
downloadcoredns-f9c03c2ead6ae655006b3b8264b9870028884d8f.tar.gz
coredns-f9c03c2ead6ae655006b3b8264b9870028884d8f.tar.zst
coredns-f9c03c2ead6ae655006b3b8264b9870028884d8f.zip
fix computation of reverse zone based on Ipv6 CIDRs (#1415)
Diffstat (limited to 'plugin/normalize.go')
-rw-r--r--plugin/normalize.go9
1 files changed, 7 insertions, 2 deletions
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