Update code to use pault.ag/go/sniff package (#5038)

* Update code to use pault.ag/go/sniff package

* Update go dependencies
This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-02-07 12:27:43 -03:00 committed by GitHub
parent 3e2bbbed3d
commit d0423c6d4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 213 additions and 59 deletions

9
go.mod
View file

@ -3,7 +3,7 @@ module k8s.io/ingress-nginx
go 1.13 go 1.13
require ( require (
github.com/armon/go-proxyproto v0.0.0-20190211145416-68259f75880e github.com/armon/go-proxyproto v0.0.0-20200108142055-f0b8253b1507
github.com/eapache/channels v1.1.0 github.com/eapache/channels v1.1.0
github.com/eapache/queue v1.1.0 // indirect github.com/eapache/queue v1.1.0 // indirect
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa // indirect github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa // indirect
@ -11,7 +11,7 @@ require (
github.com/imdario/mergo v0.3.7 github.com/imdario/mergo v0.3.7
github.com/json-iterator/go v1.1.9 github.com/json-iterator/go v1.1.9
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 github.com/mitchellh/go-ps v1.0.0
github.com/mitchellh/hashstructure v1.0.0 github.com/mitchellh/hashstructure v1.0.0
github.com/mitchellh/mapstructure v1.1.2 github.com/mitchellh/mapstructure v1.1.2
github.com/moul/pb v0.0.0-20180404114147-54bdd96e6a52 github.com/moul/pb v0.0.0-20180404114147-54bdd96e6a52
@ -20,8 +20,7 @@ require (
github.com/onsi/gomega v1.8.1 github.com/onsi/gomega v1.8.1
github.com/opencontainers/runc v1.0.0-rc9 github.com/opencontainers/runc v1.0.0-rc9
github.com/parnurzeal/gorequest v0.2.16 github.com/parnurzeal/gorequest v0.2.16
github.com/paultag/sniff v0.0.0-20200207005214-cf7e4d167732 github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.4.0 github.com/prometheus/client_golang v1.4.0
github.com/prometheus/client_model v0.2.0 github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.9.1 github.com/prometheus/common v0.9.1
@ -46,7 +45,7 @@ require (
k8s.io/klog v1.0.0 k8s.io/klog v1.0.0
k8s.io/kubernetes v1.17.2 k8s.io/kubernetes v1.17.2
moul.io/http2curl v1.0.0 // indirect moul.io/http2curl v1.0.0 // indirect
pault.ag/go/sniff v0.0.0-20200207005214-cf7e4d167732 // indirect pault.ag/go/sniff v0.0.0-20200207005214-cf7e4d167732
sigs.k8s.io/controller-runtime v0.4.0 sigs.k8s.io/controller-runtime v0.4.0
) )

11
go.sum
View file

@ -51,8 +51,8 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-proxyproto v0.0.0-20190211145416-68259f75880e h1:h0gP0hBU6DsA5IQduhLWGOEfIUKzJS5hhXQBSgHuF/g= github.com/armon/go-proxyproto v0.0.0-20200108142055-f0b8253b1507 h1:dmVRVC/MmuwC2edm/P6oWIP+9n+p9IgVgK0lq9mBQjU=
github.com/armon/go-proxyproto v0.0.0-20190211145416-68259f75880e/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU= github.com/armon/go-proxyproto v0.0.0-20200108142055-f0b8253b1507/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7/go.mod h1:LWMyo4iOLWXHGdBki7NIht1kHru/0wM179h+d3g8ATM= github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7/go.mod h1:LWMyo4iOLWXHGdBki7NIht1kHru/0wM179h+d3g8ATM=
@ -427,6 +427,8 @@ github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 h1:kw1v0NlnN+GZcU8Ma8CLF2Zzgjfx95gs3/GN3vYAPpo= github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 h1:kw1v0NlnN+GZcU8Ma8CLF2Zzgjfx95gs3/GN3vYAPpo=
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk= github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9dGS02Q3Y= github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9dGS02Q3Y=
github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ= github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
@ -494,10 +496,6 @@ github.com/opencontainers/runtime-spec v1.0.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/
github.com/opencontainers/selinux v1.3.1-0.20190929122143-5215b1806f52/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs= github.com/opencontainers/selinux v1.3.1-0.20190929122143-5215b1806f52/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs=
github.com/parnurzeal/gorequest v0.2.16 h1:T/5x+/4BT+nj+3eSknXmCTnEVGSzFzPGdpqmUVVZXHQ= github.com/parnurzeal/gorequest v0.2.16 h1:T/5x+/4BT+nj+3eSknXmCTnEVGSzFzPGdpqmUVVZXHQ=
github.com/parnurzeal/gorequest v0.2.16/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE= github.com/parnurzeal/gorequest v0.2.16/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE=
github.com/paultag/sniff v0.0.0-20170624152000-87325c3dddf4 h1:bOK8V55gl1AEWE9KiXSZ0fzARvVBehdmYZOTFcQ5kUo=
github.com/paultag/sniff v0.0.0-20170624152000-87325c3dddf4/go.mod h1:J3XXNGJINXLa4yIivdUT0Ad/srv2q0pSOWbbm6El2EY=
github.com/paultag/sniff v0.0.0-20200207005214-cf7e4d167732 h1:nkseUkzjazCNyGhkRwnJ1OiHSwMXazsJQx+Ci+oVLEM=
github.com/paultag/sniff v0.0.0-20200207005214-cf7e4d167732/go.mod h1:J3XXNGJINXLa4yIivdUT0Ad/srv2q0pSOWbbm6El2EY=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
@ -506,6 +504,7 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

View file

@ -23,7 +23,7 @@ import (
"k8s.io/klog" "k8s.io/klog"
"github.com/paultag/sniff/parser" "pault.ag/go/sniff/parser"
) )
// TCPServer describes a server that works in passthrough mode. // TCPServer describes a server that works in passthrough mode.

View file

@ -49,6 +49,7 @@ type Listener struct {
Listener net.Listener Listener net.Listener
ProxyHeaderTimeout time.Duration ProxyHeaderTimeout time.Duration
SourceCheck SourceChecker SourceCheck SourceChecker
UnknownOK bool // allow PROXY UNKNOWN
} }
// Conn is used to wrap and underlying connection which // Conn is used to wrap and underlying connection which
@ -62,6 +63,7 @@ type Conn struct {
useConnAddr bool useConnAddr bool
once sync.Once once sync.Once
proxyHeaderTimeout time.Duration proxyHeaderTimeout time.Duration
unknownOK bool
} }
// Accept waits for and returns the next connection to the listener. // Accept waits for and returns the next connection to the listener.
@ -83,6 +85,7 @@ func (p *Listener) Accept() (net.Conn, error) {
} }
newConn := NewConn(conn, p.ProxyHeaderTimeout) newConn := NewConn(conn, p.ProxyHeaderTimeout)
newConn.useConnAddr = useConnAddr newConn.useConnAddr = useConnAddr
newConn.unknownOK = p.UnknownOK
return newConn, nil return newConn, nil
} }
@ -119,6 +122,22 @@ func (p *Conn) Read(b []byte) (int, error) {
return p.bufReader.Read(b) return p.bufReader.Read(b)
} }
func (p *Conn) ReadFrom(r io.Reader) (int64, error) {
if rf, ok := p.conn.(io.ReaderFrom); ok {
return rf.ReadFrom(r)
}
return io.Copy(p.conn, r)
}
func (p *Conn) WriteTo(w io.Writer) (int64, error) {
var err error
p.once.Do(func() { err = p.checkPrefix() })
if err != nil {
return 0, err
}
return p.bufReader.WriteTo(w)
}
func (p *Conn) Write(b []byte) (int, error) { func (p *Conn) Write(b []byte) (int, error) {
return p.conn.Write(b) return p.conn.Write(b)
} }
@ -209,13 +228,20 @@ func (p *Conn) checkPrefix() error {
// Split on spaces, should be (PROXY <type> <src addr> <dst addr> <src port> <dst port>) // Split on spaces, should be (PROXY <type> <src addr> <dst addr> <src port> <dst port>)
parts := strings.Split(header, " ") parts := strings.Split(header, " ")
if len(parts) != 6 { if len(parts) < 2 {
p.conn.Close() p.conn.Close()
return fmt.Errorf("Invalid header line: %s", header) return fmt.Errorf("Invalid header line: %s", header)
} }
// Verify the type is known // Verify the type is known
switch parts[1] { switch parts[1] {
case "UNKNOWN":
if !p.unknownOK || len(parts) != 2 {
p.conn.Close()
return fmt.Errorf("Invalid UNKNOWN header line: %s", header)
}
p.useConnAddr = true
return nil
case "TCP4": case "TCP4":
case "TCP6": case "TCP6":
default: default:
@ -223,6 +249,11 @@ func (p *Conn) checkPrefix() error {
return fmt.Errorf("Unhandled address type: %s", parts[1]) return fmt.Errorf("Unhandled address type: %s", parts[1])
} }
if len(parts) != 6 {
p.conn.Close()
return fmt.Errorf("Invalid header line: %s", header)
}
// Parse out the source address // Parse out the source address
ip := net.ParseIP(parts[2]) ip := net.ParseIP(parts[2])
if ip == nil { if ip == nil {

View file

@ -1,4 +1,4 @@
# Process List Library for Go # Process List Library for Go [![GoDoc](https://godoc.org/github.com/mitchellh/go-ps?status.png)](https://godoc.org/github.com/mitchellh/go-ps)
go-ps is a library for Go that implements OS-specific APIs to list and go-ps is a library for Go that implements OS-specific APIs to list and
manipulate processes in a platform-safe way. The library can find and manipulate processes in a platform-safe way. The library can find and

3
vendor/github.com/mitchellh/go-ps/go.mod generated vendored Normal file
View file

@ -0,0 +1,3 @@
module github.com/mitchellh/go-ps
go 1.13

View file

@ -1,4 +1,4 @@
// +build freebsd,amd64 // +build freebsd
package ps package ps

View file

@ -56,7 +56,7 @@ func processes() ([]Process, error) {
results := make([]Process, 0, 50) results := make([]Process, 0, 50)
for { for {
fis, err := d.Readdir(10) names, err := d.Readdirnames(10)
if err == io.EOF { if err == io.EOF {
break break
} }
@ -64,14 +64,8 @@ func processes() ([]Process, error) {
return nil, err return nil, err
} }
for _, fi := range fis { for _, name := range names {
// We only care about directories, since all pids are dirs
if !fi.IsDir() {
continue
}
// We only care if the name starts with a numeric // We only care if the name starts with a numeric
name := fi.Name()
if name[0] < '0' || name[0] > '9' { if name[0] < '0' || name[0] > '9' {
continue continue
} }

View file

@ -1,15 +1,10 @@
language: go language: go
go_import_path: github.com/pkg/errors go_import_path: github.com/pkg/errors
go: go:
- 1.4.x
- 1.5.x
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x - 1.11.x
- 1.12.x
- 1.13.x
- tip - tip
script: script:
- go test -v ./... - make check

44
vendor/github.com/pkg/errors/Makefile generated vendored Normal file
View file

@ -0,0 +1,44 @@
PKGS := github.com/pkg/errors
SRCDIRS := $(shell go list -f '{{.Dir}}' $(PKGS))
GO := go
check: test vet gofmt misspell unconvert staticcheck ineffassign unparam
test:
$(GO) test $(PKGS)
vet: | test
$(GO) vet $(PKGS)
staticcheck:
$(GO) get honnef.co/go/tools/cmd/staticcheck
staticcheck -checks all $(PKGS)
misspell:
$(GO) get github.com/client9/misspell/cmd/misspell
misspell \
-locale GB \
-error \
*.md *.go
unconvert:
$(GO) get github.com/mdempsky/unconvert
unconvert -v $(PKGS)
ineffassign:
$(GO) get github.com/gordonklaus/ineffassign
find $(SRCDIRS) -name '*.go' | xargs ineffassign
pedantic: check errcheck
unparam:
$(GO) get mvdan.cc/unparam
unparam ./...
errcheck:
$(GO) get github.com/kisielk/errcheck
errcheck $(PKGS)
gofmt:
@echo Checking code is gofmted
@test -z "$(shell gofmt -s -l -d -e $(SRCDIRS) | tee /dev/stderr)"

View file

@ -41,11 +41,18 @@ default:
[Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).
## Roadmap
With the upcoming [Go2 error proposals](https://go.googlesource.com/proposal/+/master/design/go2draft.md) this package is moving into maintenance mode. The roadmap for a 1.0 release is as follows:
- 0.9. Remove pre Go 1.9 and Go 1.10 support, address outstanding pull requests (if possible)
- 1.0. Final release.
## Contributing ## Contributing
We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high. Because of the Go2 errors changes, this package is not accepting proposals for new functionality. With that said, we welcome pull requests, bug fixes and issue reports.
Before proposing a change, please discuss your change by raising an issue. Before sending a PR, please discuss your change by raising an issue.
## License ## License

View file

@ -82,7 +82,7 @@
// //
// if err, ok := err.(stackTracer); ok { // if err, ok := err.(stackTracer); ok {
// for _, f := range err.StackTrace() { // for _, f := range err.StackTrace() {
// fmt.Printf("%+s:%d", f) // fmt.Printf("%+s:%d\n", f, f)
// } // }
// } // }
// //
@ -159,6 +159,9 @@ type withStack struct {
func (w *withStack) Cause() error { return w.error } func (w *withStack) Cause() error { return w.error }
// Unwrap provides compatibility for Go 1.13 error chains.
func (w *withStack) Unwrap() error { return w.error }
func (w *withStack) Format(s fmt.State, verb rune) { func (w *withStack) Format(s fmt.State, verb rune) {
switch verb { switch verb {
case 'v': case 'v':
@ -241,6 +244,9 @@ type withMessage struct {
func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() } func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() }
func (w *withMessage) Cause() error { return w.cause } func (w *withMessage) Cause() error { return w.cause }
// Unwrap provides compatibility for Go 1.13 error chains.
func (w *withMessage) Unwrap() error { return w.cause }
func (w *withMessage) Format(s fmt.State, verb rune) { func (w *withMessage) Format(s fmt.State, verb rune) {
switch verb { switch verb {
case 'v': case 'v':

38
vendor/github.com/pkg/errors/go113.go generated vendored Normal file
View file

@ -0,0 +1,38 @@
// +build go1.13
package errors
import (
stderrors "errors"
)
// Is reports whether any error in err's chain matches target.
//
// The chain consists of err itself followed by the sequence of errors obtained by
// repeatedly calling Unwrap.
//
// An error is considered to match a target if it is equal to that target or if
// it implements a method Is(error) bool such that Is(target) returns true.
func Is(err, target error) bool { return stderrors.Is(err, target) }
// As finds the first error in err's chain that matches target, and if so, sets
// target to that error value and returns true.
//
// The chain consists of err itself followed by the sequence of errors obtained by
// repeatedly calling Unwrap.
//
// An error matches target if the error's concrete value is assignable to the value
// pointed to by target, or if the error has a method As(interface{}) bool such that
// As(target) returns true. In the latter case, the As method is responsible for
// setting target.
//
// As will panic if target is not a non-nil pointer to either a type that implements
// error, or to any interface type. As returns false if err is nil.
func As(err error, target interface{}) bool { return stderrors.As(err, target) }
// Unwrap returns the result of calling the Unwrap method on err, if err's
// type contains an Unwrap method returning error.
// Otherwise, Unwrap returns nil.
func Unwrap(err error) error {
return stderrors.Unwrap(err)
}

View file

@ -5,10 +5,13 @@ import (
"io" "io"
"path" "path"
"runtime" "runtime"
"strconv"
"strings" "strings"
) )
// Frame represents a program counter inside a stack frame. // Frame represents a program counter inside a stack frame.
// For historical reasons if Frame is interpreted as a uintptr
// its value represents the program counter + 1.
type Frame uintptr type Frame uintptr
// pc returns the program counter for this frame; // pc returns the program counter for this frame;
@ -37,6 +40,15 @@ func (f Frame) line() int {
return line return line
} }
// name returns the name of this function, if known.
func (f Frame) name() string {
fn := runtime.FuncForPC(f.pc())
if fn == nil {
return "unknown"
}
return fn.Name()
}
// Format formats the frame according to the fmt.Formatter interface. // Format formats the frame according to the fmt.Formatter interface.
// //
// %s source file // %s source file
@ -54,22 +66,16 @@ func (f Frame) Format(s fmt.State, verb rune) {
case 's': case 's':
switch { switch {
case s.Flag('+'): case s.Flag('+'):
pc := f.pc() io.WriteString(s, f.name())
fn := runtime.FuncForPC(pc) io.WriteString(s, "\n\t")
if fn == nil { io.WriteString(s, f.file())
io.WriteString(s, "unknown")
} else {
file, _ := fn.FileLine(pc)
fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file)
}
default: default:
io.WriteString(s, path.Base(f.file())) io.WriteString(s, path.Base(f.file()))
} }
case 'd': case 'd':
fmt.Fprintf(s, "%d", f.line()) io.WriteString(s, strconv.Itoa(f.line()))
case 'n': case 'n':
name := runtime.FuncForPC(f.pc()).Name() io.WriteString(s, funcname(f.name()))
io.WriteString(s, funcname(name))
case 'v': case 'v':
f.Format(s, 's') f.Format(s, 's')
io.WriteString(s, ":") io.WriteString(s, ":")
@ -77,6 +83,16 @@ func (f Frame) Format(s fmt.State, verb rune) {
} }
} }
// MarshalText formats a stacktrace Frame as a text string. The output is the
// same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.
func (f Frame) MarshalText() ([]byte, error) {
name := f.name()
if name == "unknown" {
return []byte(name), nil
}
return []byte(fmt.Sprintf("%s %s:%d", name, f.file(), f.line())), nil
}
// StackTrace is stack of Frames from innermost (newest) to outermost (oldest). // StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
type StackTrace []Frame type StackTrace []Frame
@ -94,18 +110,32 @@ func (st StackTrace) Format(s fmt.State, verb rune) {
switch { switch {
case s.Flag('+'): case s.Flag('+'):
for _, f := range st { for _, f := range st {
fmt.Fprintf(s, "\n%+v", f) io.WriteString(s, "\n")
f.Format(s, verb)
} }
case s.Flag('#'): case s.Flag('#'):
fmt.Fprintf(s, "%#v", []Frame(st)) fmt.Fprintf(s, "%#v", []Frame(st))
default: default:
fmt.Fprintf(s, "%v", []Frame(st)) st.formatSlice(s, verb)
} }
case 's': case 's':
fmt.Fprintf(s, "%s", []Frame(st)) st.formatSlice(s, verb)
} }
} }
// formatSlice will format this StackTrace into the given buffer as a slice of
// Frame, only valid when called with '%s' or '%v'.
func (st StackTrace) formatSlice(s fmt.State, verb rune) {
io.WriteString(s, "[")
for i, f := range st {
if i > 0 {
io.WriteString(s, " ")
}
f.Format(s, verb)
}
io.WriteString(s, "]")
}
// stack represents a stack of program counters. // stack represents a stack of program counters.
type stack []uintptr type stack []uintptr

10
vendor/modules.txt vendored
View file

@ -17,7 +17,7 @@ github.com/BurntSushi/toml
github.com/PuerkitoBio/purell github.com/PuerkitoBio/purell
# github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 # github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
github.com/PuerkitoBio/urlesc github.com/PuerkitoBio/urlesc
# github.com/armon/go-proxyproto v0.0.0-20190211145416-68259f75880e # github.com/armon/go-proxyproto v0.0.0-20200108142055-f0b8253b1507
github.com/armon/go-proxyproto github.com/armon/go-proxyproto
# github.com/beorn7/perks v1.0.1 # github.com/beorn7/perks v1.0.1
github.com/beorn7/perks/quantile github.com/beorn7/perks/quantile
@ -127,7 +127,7 @@ github.com/mailru/easyjson/jlexer
github.com/mailru/easyjson/jwriter github.com/mailru/easyjson/jwriter
# github.com/matttproud/golang_protobuf_extensions v1.0.1 # github.com/matttproud/golang_protobuf_extensions v1.0.1
github.com/matttproud/golang_protobuf_extensions/pbutil github.com/matttproud/golang_protobuf_extensions/pbutil
# github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 # github.com/mitchellh/go-ps v1.0.0
github.com/mitchellh/go-ps github.com/mitchellh/go-ps
# github.com/mitchellh/hashstructure v1.0.0 # github.com/mitchellh/hashstructure v1.0.0
github.com/mitchellh/hashstructure github.com/mitchellh/hashstructure
@ -191,11 +191,9 @@ github.com/opencontainers/runc/libcontainer/configs
github.com/opencontainers/runtime-spec/specs-go github.com/opencontainers/runtime-spec/specs-go
# github.com/parnurzeal/gorequest v0.2.16 # github.com/parnurzeal/gorequest v0.2.16
github.com/parnurzeal/gorequest github.com/parnurzeal/gorequest
# github.com/paultag/sniff v0.0.0-20170624152000-87325c3dddf4
github.com/paultag/sniff/parser
# github.com/peterbourgon/diskv v2.0.1+incompatible # github.com/peterbourgon/diskv v2.0.1+incompatible
github.com/peterbourgon/diskv github.com/peterbourgon/diskv
# github.com/pkg/errors v0.8.1 # github.com/pkg/errors v0.9.1
github.com/pkg/errors github.com/pkg/errors
# github.com/prometheus/client_golang v1.4.0 # github.com/prometheus/client_golang v1.4.0
github.com/prometheus/client_golang/prometheus github.com/prometheus/client_golang/prometheus
@ -803,6 +801,8 @@ k8s.io/utils/pointer
k8s.io/utils/trace k8s.io/utils/trace
# moul.io/http2curl v1.0.0 # moul.io/http2curl v1.0.0
moul.io/http2curl moul.io/http2curl
# pault.ag/go/sniff v0.0.0-20200207005214-cf7e4d167732
pault.ag/go/sniff/parser
# sigs.k8s.io/controller-runtime v0.4.0 # sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/controller-runtime/pkg/client/config sigs.k8s.io/controller-runtime/pkg/client/config
sigs.k8s.io/controller-runtime/pkg/envtest sigs.k8s.io/controller-runtime/pkg/envtest

View file

@ -44,6 +44,14 @@ func GetHostname(data []byte) (string, error) {
return string(sni), nil return string(sni), nil
} }
/* Return the length computed from the two octets starting at index */
func lengthFromData(data []byte, index int) int {
b1 := int(data[index])
b2 := int(data[index+1])
return (b1 << 8) + b2
}
/* Given a Server Name TLS Extension block, parse out and return the SNI /* Given a Server Name TLS Extension block, parse out and return the SNI
* (Server Name Indication) payload */ * (Server Name Indication) payload */
func GetSNIBlock(data []byte) ([]byte, error) { func GetSNIBlock(data []byte) ([]byte, error) {
@ -53,11 +61,11 @@ func GetSNIBlock(data []byte) ([]byte, error) {
if index >= len(data) { if index >= len(data) {
break break
} }
length := int((data[index] << 8) + data[index+1]) length := lengthFromData(data, index)
endIndex := index + 2 + length endIndex := index + 2 + length
if data[index+2] == 0x00 { /* SNI */ if data[index+2] == 0x00 { /* SNI */
sni := data[index+3:] sni := data[index+3:]
sniLength := int((sni[0] << 8) + sni[1]) sniLength := lengthFromData(sni, 0)
return sni[2 : sniLength+2], nil return sni[2 : sniLength+2], nil
} }
index = endIndex index = endIndex
@ -75,17 +83,17 @@ func GetSNBlock(data []byte) ([]byte, error) {
return []byte{}, fmt.Errorf("Not enough bytes to be an SN block") return []byte{}, fmt.Errorf("Not enough bytes to be an SN block")
} }
extensionLength := int((data[index] << 8) + data[index+1]) extensionLength := lengthFromData(data, index)
if extensionLength+2 > len(data) { if extensionLength+2 > len(data) {
return []byte{}, fmt.Errorf("Extension looks bonkers") return []byte{}, fmt.Errorf("Extension looks bonkers")
} }
data = data[2 : extensionLength+2] data = data[2 : extensionLength+2]
for { for {
if index+3 >= len(data) { if index+4 >= len(data) {
break break
} }
length := int((data[index+2] << 8) + data[index+3]) length := lengthFromData(data, index+2)
endIndex := index + 4 + length endIndex := index + 4 + length
if data[index] == 0x00 && data[index+1] == 0x00 { if data[index] == 0x00 && data[index+1] == 0x00 {
return data[index+4 : endIndex], nil return data[index+4 : endIndex], nil
@ -121,7 +129,7 @@ func GetExtensionBlock(data []byte) ([]byte, error) {
} }
/* Index is at Cipher List Length bits */ /* Index is at Cipher List Length bits */
if newIndex := (index + 2 + int((data[index]<<8)+data[index+1])); (newIndex + 1) < len(data) { if newIndex := (index + 2 + lengthFromData(data, index)); (newIndex + 1) < len(data) {
index = newIndex index = newIndex
} else { } else {
return []byte{}, fmt.Errorf("Not enough bytes for the Cipher List") return []byte{}, fmt.Errorf("Not enough bytes for the Cipher List")