Skip to content

Commit

Permalink
Merge pull request #1050 from highlyunavailable/master
Browse files Browse the repository at this point in the history
Add RFC 6598 private IP range
  • Loading branch information
ryanuber committed Jun 22, 2015
2 parents c8b3e48 + b48842c commit cc143fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion consul/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
/*
* Contains an entry for each private block:
* 10.0.0.0/8
* 100.64.0.0/10
* 172.16.0.0/12
* 192.168/16
*/
Expand All @@ -41,7 +42,8 @@ func (s *serverParts) String() string {

func init() {
// Add each private block
privateBlocks = make([]*net.IPNet, 3)
privateBlocks = make([]*net.IPNet, 4)

_, block, err := net.ParseCIDR("10.0.0.0/8")
if err != nil {
panic(fmt.Sprintf("Bad cidr. Got %v", err))
Expand All @@ -59,6 +61,12 @@ func init() {
panic(fmt.Sprintf("Bad cidr. Got %v", err))
}
privateBlocks[2] = block

_, block, err = net.ParseCIDR("100.64.0.0/10")
if err != nil {
panic(fmt.Sprintf("Bad cidr. Got %v", err))
}
privateBlocks[3] = block
}

// strContains checks if a list contains a string
Expand Down
3 changes: 3 additions & 0 deletions consul/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func TestIsPrivateIP(t *testing.T) {
if !isPrivateIP("10.1.2.3") {
t.Fatalf("bad")
}
if !isPrivateIP("100.115.110.19") {
t.Fatalf("bad")
}
if isPrivateIP("8.8.8.8") {
t.Fatalf("bad")
}
Expand Down

0 comments on commit cc143fa

Please sign in to comment.