From 6f831978567b02399b5a4b3737be49a705227f8e Mon Sep 17 00:00:00 2001 From: wata_mac Date: Mon, 9 Sep 2019 14:04:56 -0700 Subject: [PATCH] go get github.com/apparentlymart/go-cidr@v1.0.1 This includes fixes in the handling of IPv6 prefixes that leave a host portion longer than the size of int on the target platform. --- go.mod | 2 +- go.sum | 4 +-- .../apparentlymart/go-cidr/cidr/cidr.go | 26 ++++++++++++------- .../apparentlymart/go-cidr/cidr/wrangling.go | 3 +-- vendor/modules.txt | 2 +- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 677c77cf9..70a01f448 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190329064014-6e358769c32a github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190103054945-8205d1f41e70 github.com/aliyun/aliyun-tablestore-go-sdk v4.1.2+incompatible - github.com/apparentlymart/go-cidr v1.0.0 + github.com/apparentlymart/go-cidr v1.0.1 github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect diff --git a/go.sum b/go.sum index cfe54cdc3..caa540d9d 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e h1:ptBAamGVd6CfRsUty github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0 h1:JaCC8jz0zdMLk2m+qCCVLLLM/PL93p84w4pK3aJWj60= github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0/go.mod h1:LzD22aAzDP8/dyiCKFp31He4m2GPjl0AFyzDtZzUu9M= -github.com/apparentlymart/go-cidr v1.0.0 h1:lGDvXx8Lv9QHjrAVP7jyzleG4F9+FkRhJcEsDFxeb8w= -github.com/apparentlymart/go-cidr v1.0.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= +github.com/apparentlymart/go-cidr v1.0.1 h1:NmIwLZ/KdsjIUlhf+/Np40atNXm/+lZ5txfTJ/SpF+U= +github.com/apparentlymart/go-cidr v1.0.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFUye+ZcSR6opIgz9Co7WcDx6ZcY+RjfFHoA0I= github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= diff --git a/vendor/github.com/apparentlymart/go-cidr/cidr/cidr.go b/vendor/github.com/apparentlymart/go-cidr/cidr/cidr.go index c292db0ce..ed749d4c5 100644 --- a/vendor/github.com/apparentlymart/go-cidr/cidr/cidr.go +++ b/vendor/github.com/apparentlymart/go-cidr/cidr/cidr.go @@ -44,7 +44,7 @@ func Subnet(base *net.IPNet, newBits int, num int) (*net.IPNet, error) { } return &net.IPNet{ - IP: insertNumIntoIP(ip, num, newPrefixLen), + IP: insertNumIntoIP(ip, big.NewInt(int64(num)), newPrefixLen), Mask: net.CIDRMask(newPrefixLen, addrLen), }, nil } @@ -56,19 +56,23 @@ func Subnet(base *net.IPNet, newBits int, num int) (*net.IPNet, error) { func Host(base *net.IPNet, num int) (net.IP, error) { ip := base.IP mask := base.Mask + bigNum := big.NewInt(int64(num)) parentLen, addrLen := mask.Size() hostLen := addrLen - parentLen - maxHostNum := uint64(1< maxHostNum { + if numUint64.Cmp(maxHostNum) == 1 { return nil, fmt.Errorf("prefix of %d does not accommodate a host numbered %d", parentLen, num) } var bitlength int @@ -77,7 +81,7 @@ func Host(base *net.IPNet, num int) (net.IP, error) { } else { bitlength = 128 } - return insertNumIntoIP(ip, num, bitlength), nil + return insertNumIntoIP(ip, bigNum, bitlength), nil } // AddressRange returns the first and last addresses in the given CIDR range. @@ -129,7 +133,11 @@ func VerifyNoOverlap(subnets []*net.IPNet, CIDRBlock *net.IPNet) error { if !CIDRBlock.Contains(firstLastIP[i][0]) || !CIDRBlock.Contains(firstLastIP[i][1]) { return fmt.Errorf("%s does not fully contain %s", CIDRBlock.String(), s.String()) } - for j := i + 1; j < len(subnets); j++ { + for j := 0; j < len(subnets); j++ { + if i == j { + continue + } + first := firstLastIP[j][0] last := firstLastIP[j][1] if s.Contains(first) || s.Contains(last) { diff --git a/vendor/github.com/apparentlymart/go-cidr/cidr/wrangling.go b/vendor/github.com/apparentlymart/go-cidr/cidr/wrangling.go index 861a5f623..e5e6a2cf9 100644 --- a/vendor/github.com/apparentlymart/go-cidr/cidr/wrangling.go +++ b/vendor/github.com/apparentlymart/go-cidr/cidr/wrangling.go @@ -29,9 +29,8 @@ func intToIP(ipInt *big.Int, bits int) net.IP { return net.IP(ret) } -func insertNumIntoIP(ip net.IP, num int, prefixLen int) net.IP { +func insertNumIntoIP(ip net.IP, bigNum *big.Int, prefixLen int) net.IP { ipInt, totalBits := ipToInt(ip) - bigNum := big.NewInt(int64(num)) bigNum.Lsh(bigNum, uint(totalBits-prefixLen)) ipInt.Or(ipInt, bigNum) return intToIP(ipInt, totalBits) diff --git a/vendor/modules.txt b/vendor/modules.txt index 8dac64c8e..a4e96e98c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -70,7 +70,7 @@ github.com/aliyun/aliyun-tablestore-go-sdk/tablestore/search github.com/antchfx/xpath # github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0 github.com/antchfx/xquery/xml -# github.com/apparentlymart/go-cidr v1.0.0 +# github.com/apparentlymart/go-cidr v1.0.1 github.com/apparentlymart/go-cidr/cidr # github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 github.com/apparentlymart/go-dump/dump