Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Upgrade inet.af/netaddr for compatibility with Go 1.18 #6046

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ require (
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
inet.af/netaddr v0.0.0-20210707202901-70468d781e6c
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6
k8s.io/klog v1.0.0
)

Expand Down Expand Up @@ -256,8 +256,8 @@ require (
go.opentelemetry.io/otel/trace v1.4.1 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.1 // indirect
go4.org/intern v0.0.0-20210108033219-3eb7198706b2 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063 // indirect
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2024,11 +2024,10 @@ go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
go4.org/intern v0.0.0-20210108033219-3eb7198706b2 h1:VFTf+jjIgsldaz/Mr00VaCSswHJrI2hIjQygE/W4IMg=
go4.org/intern v0.0.0-20210108033219-3eb7198706b2/go.mod h1:vLqJ+12kCw61iCWsPto0EOHhBS+o4rO5VIucbc9g2Cc=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222175341-b30ae309168e/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063 h1:1tk03FUNpulq2cuWpXZWj649rwJpk0d20rxWiopKRmc=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 h1:UXLjNohABv4S58tHmeuIZDO6e3mHpW2Dx33gaNt03LE=
go4.org/intern v0.0.0-20211027215823-ae77deb06f29/go.mod h1:cS2ma+47FKrLPdXFpr7CuxiTW3eyJbWew4qx0qtQWDA=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37 h1:Tx9kY6yUkLge/pFG7IEMwDZy6CS2ajFc9TvQdPCW0uA=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180505025534-4ec37c66abab/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -2770,8 +2769,8 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
inet.af/netaddr v0.0.0-20210707202901-70468d781e6c h1:ZNUX2CiFwNbN1VFaD4MQFmC8o5Rxc7BQW1P1K8kMpbE=
inet.af/netaddr v0.0.0-20210707202901-70468d781e6c/go.mod h1:z0nx+Dh+7N7CC8V5ayHtHGpZpxLQZZxkIaaz6HN65Ls=
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6 h1:acCzuUSQ79tGsM/O50VRFySfMm19IoMKL+sZztZkCxw=
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6/go.mod h1:y3MGhcFMlh0KZPMuXXow8mpjxxAk3yoDNsp4cQz54i8=
k8s.io/api v0.21.0 h1:gu5iGF4V6tfVCQ/R+8Hc0h7H1JuEhzyEi9S4R5LM8+Y=
k8s.io/api v0.21.0/go.mod h1:+YbrhBBGgsxbF6o6Kj4KJPJnBmAKuXDeS3E18bgHNVU=
k8s.io/apimachinery v0.21.0 h1:3Fx+41if+IRavNcKOz09FwEXDBG6ORh6iMsTSelhkMA=
Expand Down
3 changes: 2 additions & 1 deletion vendor/go4.org/unsafe/assume-no-moving-gc/untested.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions vendor/inet.af/netaddr/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build gofuzz
// +build gofuzz

package netaddr
Expand Down Expand Up @@ -129,13 +130,18 @@ func checkBinaryMarshaller(x encoding.BinaryMarshaler) {
}
}

type appendMarshaller interface {
// fuzzAppendMarshaler is identical to appendMarshaler, defined in netaddr_test.go.
// We have two because the two go-fuzz implementations differ
// in whether they include _test.go files when typechecking.
// We need this fuzz file to compile with and without netaddr_test.go,
// which means defining the interface twice.
type fuzzAppendMarshaler interface {
encoding.TextMarshaler
AppendTo([]byte) []byte
}

// checkTextMarshalMatchesAppendTo checks that x's MarshalText matches x's AppendTo.
func checkTextMarshalMatchesAppendTo(x appendMarshaller) {
func checkTextMarshalMatchesAppendTo(x fuzzAppendMarshaler) {
buf, err := x.MarshalText()
if err != nil {
panic(err)
Expand All @@ -154,16 +160,16 @@ func parseIPPort(s string) (interface{}, error) { return ParseIPPort(s) }
func parseIPPrefix(s string) (interface{}, error) { return ParseIPPrefix(s) }

func checkStringParseRoundTrip(x fmt.Stringer, parse func(string) (interface{}, error)) {
v, vok := x.(interface{ Valid() bool })
if vok && !v.Valid() {
v, vok := x.(interface{ IsValid() bool })
if vok && !v.IsValid() {
// Ignore invalid values.
return
}
// Zero values tend to print something like "invalid <TYPE>", so it's OK if they don't round trip.
// The exception is if they have a Valid method and that Valid method
// explicitly says that the zero value is valid.
z, zok := x.(interface{ IsZero() bool })
if zok && z.IsZero() && !(vok && v.Valid()) {
if zok && z.IsZero() && !(vok && v.IsValid()) {
return
}
s := x.String()
Expand All @@ -189,7 +195,7 @@ func checkEncoding(x interface{}) {
if bm, ok := x.(encoding.BinaryMarshaler); ok {
checkBinaryMarshaller(bm)
}
if am, ok := x.(appendMarshaller); ok {
if am, ok := x.(fuzzAppendMarshaler); ok {
checkTextMarshalMatchesAppendTo(am)
}
}
Expand Down
63 changes: 51 additions & 12 deletions vendor/inet.af/netaddr/ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package netaddr

import (
"errors"
"fmt"
"runtime"
"sort"
"strings"
)
Expand Down Expand Up @@ -64,7 +64,7 @@ func (s *IPSetBuilder) normalize() {
}

switch {
case !rout.Valid() || !rin.Valid():
case !rout.IsValid() || !rin.IsValid():
// mergeIPRanges should have prevented invalid ranges from
// sneaking in.
panic("invalid IPRanges during Ranges merge")
Expand Down Expand Up @@ -168,28 +168,41 @@ func (s *IPSetBuilder) Clone() *IPSetBuilder {
}
}

func (s *IPSetBuilder) addError(msg string, args ...interface{}) {
se := new(stacktraceErr)
// Skip three frames: runtime.Callers, addError, and the IPSetBuilder
// method that called addError (such as IPSetBuilder.Add).
// The resulting stack trace ends at the line in the user's
// code where they called into netaddr.
n := runtime.Callers(3, se.pcs[:])
se.at = se.pcs[:n]
se.err = fmt.Errorf(msg, args...)
s.errs = append(s.errs, se)
}

// Add adds ip to s.
func (s *IPSetBuilder) Add(ip IP) {
if ip.IsZero() {
s.addError("Add(IP{})")
return
}
s.AddRange(IPRangeFrom(ip, ip))
}

// AddPrefix adds all IPs in p to s.
func (s *IPSetBuilder) AddPrefix(p IPPrefix) {
if r := p.Range(); r.Valid() {
if r := p.Range(); r.IsValid() {
s.AddRange(r)
} else {
s.errs = append(s.errs, fmt.Errorf("AddPrefix of invalid prefix %q", p))
s.addError("AddPrefix(%v/%v)", p.IP(), p.Bits())
}
}

// AddRange adds r to s.
// If r is not Valid, AddRange does nothing.
func (s *IPSetBuilder) AddRange(r IPRange) {
if !r.Valid() {
s.errs = append(s.errs, fmt.Errorf("AddRange of invalid range %q", r))
if !r.IsValid() {
s.addError("AddRange(%v-%v)", r.From(), r.To())
return
}
// If there are any removals (s.out), then we need to compact the set
Expand All @@ -213,27 +226,27 @@ func (s *IPSetBuilder) AddSet(b *IPSet) {
// Remove removes ip from s.
func (s *IPSetBuilder) Remove(ip IP) {
if ip.IsZero() {
s.errs = append(s.errs, errors.New("ignored Remove of zero IP"))
s.addError("Remove(IP{})")
} else {
s.RemoveRange(IPRangeFrom(ip, ip))
}
}

// RemovePrefix removes all IPs in p from s.
func (s *IPSetBuilder) RemovePrefix(p IPPrefix) {
if r := p.Range(); r.Valid() {
if r := p.Range(); r.IsValid() {
s.RemoveRange(r)
} else {
s.errs = append(s.errs, fmt.Errorf("RemovePrefix of invalid prefix %q", p))
s.addError("RemovePrefix(%v/%v)", p.IP(), p.Bits())
}
}

// RemoveRange removes all IPs in r from s.
func (s *IPSetBuilder) RemoveRange(r IPRange) {
if r.Valid() {
if r.IsValid() {
s.out = append(s.out, r)
} else {
s.errs = append(s.errs, fmt.Errorf("RemoveRange of invalid range %q", r))
s.addError("RemoveRange(%v-%v)", r.From(), r.To())
}
}

Expand Down Expand Up @@ -454,5 +467,31 @@ func (e multiErr) Error() string {
for _, err := range e {
ret = append(ret, err.Error())
}
return strings.Join(ret, ", ")
return strings.Join(ret, "; ")
}

// A stacktraceErr combines an error with a stack trace.
type stacktraceErr struct {
pcs [16]uintptr // preallocated array of PCs
at []uintptr // stack trace whence the error
err error // underlying error
}

func (e *stacktraceErr) Error() string {
frames := runtime.CallersFrames(e.at)
buf := new(strings.Builder)
buf.WriteString(e.err.Error())
buf.WriteString(" @ ")
for {
frame, more := frames.Next()
if !more {
break
}
fmt.Fprintf(buf, "%s:%d ", frame.File, frame.Line)
}
return strings.TrimSpace(buf.String())
}

func (e *stacktraceErr) Unwrap() error {
return e.err
}
Loading