Merge pull request #1050 from highlyunavailable/master

Add RFC 6598 private IP range
This commit is contained in:
Ryan Uber 2015-06-22 11:01:44 -07:00
commit 713661a035
2 changed files with 12 additions and 1 deletions

View File

@ -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
*/
@ -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))
@ -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

View File

@ -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")
}