Permalink
Browse files

Add /48 subnet targeting for IPv6 ip targeting

Also add IP targeting tests for IPv6, closes #55
  • Loading branch information...
abh committed Jun 15, 2014
1 parent fc3fd3d commit 24d9545aa5e8a83d99c4cd26e1d8c031090237e9
Showing with 16 additions and 0 deletions.
  1. +10 −0 targeting.go
  2. +6 −0 targeting_test.go
View
@@ -18,6 +18,12 @@ const (
TargetIP
)
var cidr48Mask net.IPMask
func init() {
cidr48Mask = net.CIDRMask(48, 128)
}
func (t TargetOptions) GetTargets(ip net.IP) ([]string, int) {
targets := make([]string, 0)
@@ -45,6 +51,10 @@ func (t TargetOptions) GetTargets(ip net.IP) ([]string, int) {
ip4[3] = 0
targets = append(targets, "["+ip4.String()+"]")
}
} else {
// v6 address, also target the /48 address
ip48 := ip.Mask(cidr48Mask)
targets = append(targets, "["+ip48.String()+"]")
}
}
View
@@ -62,4 +62,10 @@ func (s *TargetingSuite) TestGetTargets(c *C) {
tgt, _ = parseTargets("@ continent regiongroup country region asn ip")
targets, _ = tgt.GetTargets(ip)
c.Check(targets, DeepEquals, []string{"[207.171.1.1]", "[207.171.1.0]", "as7012", "us-ca", "us-west", "us", "north-america", "@"})
ip = net.ParseIP("2607:f238:2:0::ff:4")
tgt, _ = parseTargets("ip")
targets, _ = tgt.GetTargets(ip)
c.Check(targets, DeepEquals, []string{"[2607:f238:2::ff:4]", "[2607:f238:2::]"})
}

0 comments on commit 24d9545

Please sign in to comment.