├── .gitignore ├── vendor └── github.com │ ├── tv42 │ └── httpunix │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── httpunix_test.go │ │ └── httpunix.go │ ├── hashicorp │ ├── go-retryablehttp │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── Makefile │ │ └── README.md │ └── go-cleanhttp │ │ ├── go.mod │ │ ├── handlers.go │ │ ├── doc.go │ │ ├── README.md │ │ ├── handlers_test.go │ │ └── cleanhttp.go │ ├── google │ └── gopacket │ │ ├── layers │ │ ├── gen_linted.sh │ │ ├── .linted │ │ ├── stp.go │ │ ├── endpoints_test.go │ │ ├── base_test.go │ │ ├── fddi.go │ │ ├── etherip.go │ │ ├── udplite.go │ │ ├── dot1q_test.go │ │ ├── tcp_test.go │ │ ├── base.go │ │ ├── eapol.go │ │ ├── pppoe.go │ │ ├── ipsec.go │ │ ├── ppp.go │ │ ├── vrrp_test.go │ │ ├── pflog.go │ │ ├── dot1q.go │ │ ├── loopback.go │ │ ├── usb_test.go │ │ ├── linux_sll.go │ │ ├── gen.go │ │ ├── doc.go │ │ ├── eap.go │ │ ├── rudp.go │ │ ├── mpls.go │ │ ├── geneve.go │ │ ├── radiotap_test.go │ │ ├── udp.go │ │ ├── vxlan.go │ │ ├── tcpip.go │ │ └── icmp6_test.go │ │ ├── pcap │ │ ├── test_dns.pcap │ │ ├── test_ethernet.pcap │ │ ├── test_loopback.pcap │ │ ├── pcap_windows.go │ │ ├── pcapgo_test.go │ │ ├── pcap_unix.go │ │ └── pcap_tester.go │ │ ├── examples │ │ ├── bytediff │ │ │ └── bytediff.png │ │ ├── util │ │ │ └── util.go │ │ ├── pfdump │ │ │ └── main.go │ │ └── pcapdump │ │ │ └── main.go │ │ ├── .travis.gofmt.sh │ │ ├── .travis.govet.sh │ │ ├── afpacket │ │ ├── sockopt_linux_386.s │ │ ├── sockopt_linux_386.go │ │ ├── afpacket_test.go │ │ └── sockopt_linux.go │ │ ├── macs │ │ ├── benchmark_test.go │ │ ├── doc.go │ │ └── gen.go │ │ ├── routing │ │ ├── other.go │ │ └── common.go │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── .travis.golint.sh │ │ ├── .gitignore │ │ ├── AUTHORS │ │ ├── LICENSE │ │ ├── bytediff │ │ └── bytediff_test.go │ │ ├── packet_test.go │ │ ├── pcapgo │ │ └── write_test.go │ │ ├── writer_test.go │ │ ├── pfring │ │ └── doc.go │ │ ├── reassembly │ │ └── cap2test.go │ │ ├── tcpassembly │ │ └── tcpreader │ │ │ └── reader_test.go │ │ └── layerclass.go │ ├── golang │ └── snappy │ │ ├── testdata │ │ └── Mark.Twain-Tom.Sawyer.txt.rawsnappy │ │ ├── decode_amd64.go │ │ ├── .gitignore │ │ ├── AUTHORS │ │ ├── encode_amd64.go │ │ ├── cmd │ │ └── snappytool │ │ │ └── main.go │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ ├── misc │ │ └── main.cpp │ │ └── decode_other.go │ ├── circonus-labs │ ├── circonus-gometrics │ │ ├── .gitignore │ │ ├── metrics.go │ │ ├── tools.go │ │ ├── Gopkg.toml │ │ ├── Gopkg.lock │ │ ├── text.go │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── counter.go │ │ ├── checkmgr │ │ │ ├── cert_test.go │ │ │ └── cert.go │ │ ├── submit_test.go │ │ ├── text_test.go │ │ ├── histogram.go │ │ ├── api │ │ │ ├── check_bundle_metrics.go │ │ │ ├── check.go │ │ │ └── doc.go │ │ ├── util_test.go │ │ ├── util.go │ │ └── gauge.go │ └── circonusllhist │ │ ├── LICENSE │ │ └── circonusllhist_test.go │ └── pkg │ └── errors │ ├── .travis.yml │ ├── .gitignore │ ├── appveyor.yml │ ├── bench_test.go │ ├── LICENSE │ └── README.md ├── protocol_observer ├── routes.json └── queries.json ├── Gopkg.toml ├── go.mod ├── go.sum └── Gopkg.lock /.gitignore: -------------------------------------------------------------------------------- 1 | protocol_observer/protocol_observer 2 | -------------------------------------------------------------------------------- /vendor/github.com/tv42/httpunix/.gitignore: -------------------------------------------------------------------------------- 1 | *.test 2 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-retryablehttp/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | *.test 4 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hashicorp/go-cleanhttp 2 | -------------------------------------------------------------------------------- /protocol_observer/routes.json: -------------------------------------------------------------------------------- 1 | { 2 | "routes": [ 3 | { "path": "^/", "name": "root" } 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /protocol_observer/queries.json: -------------------------------------------------------------------------------- 1 | { 2 | "PreparedStatements": [ 3 | { "Query": ".", "Name": "" } 4 | ], 5 | "AdhocStatements": [ 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/gen_linted.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in *.go; do golint $i | grep -q . || echo $i; done > .linted 4 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcap/test_dns.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/circonus-labs/wirelatency/HEAD/vendor/github.com/google/gopacket/pcap/test_dns.pcap -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcap/test_ethernet.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/circonus-labs/wirelatency/HEAD/vendor/github.com/google/gopacket/pcap/test_ethernet.pcap -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcap/test_loopback.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/circonus-labs/wirelatency/HEAD/vendor/github.com/google/gopacket/pcap/test_loopback.pcap -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/examples/bytediff/bytediff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/circonus-labs/wirelatency/HEAD/vendor/github.com/google/gopacket/examples/bytediff/bytediff.png -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/testdata/Mark.Twain-Tom.Sawyer.txt.rawsnappy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/circonus-labs/wirelatency/HEAD/vendor/github.com/golang/snappy/testdata/Mark.Twain-Tom.Sawyer.txt.rawsnappy -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | env.sh 3 | NOTES.md 4 | 5 | # codecov.io 6 | .codecov 7 | coverage.txt 8 | coverage.xml 9 | coverage.html 10 | 11 | vendor/ 12 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-retryablehttp/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.8.1 7 | 8 | branches: 9 | only: 10 | - master 11 | 12 | script: make updatedeps test 13 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/pkg/errors 3 | go: 4 | - 1.4.3 5 | - 1.5.4 6 | - 1.6.2 7 | - 1.7.1 8 | - tip 9 | 10 | script: 11 | - go test -v ./... 12 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/.travis.gofmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd "$(dirname $0)" 4 | if [ -n "$(go fmt ./...)" ]; then 5 | echo "Go code is not formatted, run 'go fmt github.com/google/stenographer/...'" >&2 6 | exit 1 7 | fi 8 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-retryablehttp/Makefile: -------------------------------------------------------------------------------- 1 | default: test 2 | 3 | test: 4 | go vet ./... 5 | go test -race ./... 6 | 7 | updatedeps: 8 | go get -f -t -u ./... 9 | go get -f -u ./... 10 | 11 | .PHONY: default test updatedeps 12 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/.travis.govet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd "$(dirname $0)" 4 | DIRS=". layers pcap pcapgo pfring tcpassembly tcpassembly/tcpreader routing ip4defrag bytediff macs" 5 | set -e 6 | for subdir in $DIRS; do 7 | pushd $subdir 8 | go vet 9 | popd 10 | done 11 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/afpacket/sockopt_linux_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | TEXT ·socketcall(SB),4,$0-36 8 | JMP syscall·socketcall(SB) -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | [[constraint]] 2 | name = "github.com/circonus-labs/circonus-gometrics" 3 | version = "2.1.0" 4 | 5 | [[constraint]] 6 | branch = "master" 7 | name = "github.com/golang/snappy" 8 | 9 | [[constraint]] 10 | name = "github.com/google/gopacket" 11 | version = "1.1.14" 12 | 13 | [prune] 14 | go-tests = true 15 | unused-packages = true -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/decode_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Snappy-Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | // +build gc 7 | // +build !noasm 8 | 9 | package snappy 10 | 11 | // decode has the same semantics as in decode_other.go. 12 | // 13 | //go:noescape 14 | func decode(dst, src []byte) int 15 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/.gitignore: -------------------------------------------------------------------------------- 1 | cmd/snappytool/snappytool 2 | testdata/bench 3 | 4 | # These explicitly listed benchmark data files are for an obsolete version of 5 | # snappy_test.go. 6 | testdata/alice29.txt 7 | testdata/asyoulik.txt 8 | testdata/fireworks.jpeg 9 | testdata/geo.protodata 10 | testdata/html 11 | testdata/html_x_4 12 | testdata/kppkn.gtb 13 | testdata/lcet10.txt 14 | testdata/paper-100k.pdf 15 | testdata/plrabn12.txt 16 | testdata/urls.10K 17 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/macs/benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package macs 8 | 9 | import ( 10 | "testing" 11 | ) 12 | 13 | func BenchmarkCheckEthernetPrefix(b *testing.B) { 14 | key := [3]byte{5, 5, 5} 15 | for i := 0; i < b.N; i++ { 16 | _ = ValidMACPrefixMap[key] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/routing/other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build !linux 8 | 9 | // Package routing is currently only supported in Linux, but the build system requires a valid go file for all architectures. 10 | 11 | package routing 12 | 13 | func New() (Router, error) { 14 | panic("router only implemented in linux") 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | install: 3 | - go get github.com/google/gopacket 4 | - go get github.com/google/gopacket/layers 5 | - go get github.com/google/gopacket/tcpassembly 6 | - go get github.com/google/gopacket/reassembly 7 | script: 8 | - go test github.com/google/gopacket 9 | - go test github.com/google/gopacket/layers 10 | - go test github.com/google/gopacket/tcpassembly 11 | - go test github.com/google/gopacket/reassembly 12 | - ./.travis.gofmt.sh 13 | - ./.travis.govet.sh 14 | - ./.travis.golint.sh 15 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/macs/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // Package macs provides an in-memory mapping of all valid Ethernet MAC address 8 | // prefixes to their associated organization. 9 | // 10 | // The ValidMACPrefixMap map maps 3-byte prefixes to organization strings. It 11 | // can be updated using 'go run gen.go' in this directory. 12 | package macs 13 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/README.md: -------------------------------------------------------------------------------- 1 | # GoPacket 2 | 3 | This library provides packet decoding capabilities for Go. 4 | See [godoc](https://godoc.org/github.com/google/gopacket) for more details. 5 | 6 | [![Build Status](https://travis-ci.org/google/gopacket.svg?branch=master)](https://travis-ci.org/google/gopacket) 7 | [![GoDoc](https://godoc.org/github.com/google/gopacket?status.svg)](https://godoc.org/github.com/google/gopacket) 8 | 9 | Originally forked from the gopcap project written by Andreas 10 | Krennmair (http://github.com/akrennmair/gopcap). 11 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of Snappy-Go authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | # Please keep the list sorted. 10 | 11 | Damian Gryski 12 | Google Inc. 13 | Jan Mercl <0xjnml@gmail.com> 14 | Rodolfo Carvalho 15 | Sebastien Binet 16 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/circonus-labs/wirelatency 2 | 3 | require ( 4 | github.com/circonus-labs/circonus-gometrics v2.2.1+incompatible 5 | github.com/circonus-labs/circonusllhist v0.0.0-20180430145027-5eb751da55c6 // indirect 6 | github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db 7 | github.com/google/gopacket v1.1.14 8 | github.com/hashicorp/go-cleanhttp v0.5.0 // indirect 9 | github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6 // indirect 10 | github.com/pkg/errors v0.8.0 // indirect 11 | github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 // indirect 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/.linted: -------------------------------------------------------------------------------- 1 | arp.go 2 | base.go 3 | base_test.go 4 | cdp.go 5 | ctp.go 6 | decode_test.go 7 | dhcp_test.go 8 | dhcpv4.go 9 | dns.go 10 | dns_test.go 11 | doc.go 12 | dot11_test.go 13 | dot1q.go 14 | dot1q_test.go 15 | eapol.go 16 | etherip.go 17 | fddi.go 18 | gen.go 19 | gre.go 20 | gre_test.go 21 | iana_ports.go 22 | icmp6_test.go 23 | igmp_test.go 24 | ip4_test.go 25 | ipsec.go 26 | ipsec_test.go 27 | loopback.go 28 | mpls_test.go 29 | ntp_test.go 30 | ports.go 31 | ppp.go 32 | prism_test.go 33 | radiotap_test.go 34 | sflow_test.go 35 | tcp_test.go 36 | udp_test.go 37 | usb_test.go 38 | vrrp_test.go 39 | vxlan.go 40 | vxlan_test.go 41 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcap/pcap_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style license 5 | // that can be found in the LICENSE file in the root of the source 6 | // tree. 7 | 8 | package pcap 9 | 10 | import ( 11 | "runtime" 12 | ) 13 | 14 | func (p *Handle) openLive() error { 15 | // do nothing 16 | return nil 17 | } 18 | 19 | // waitForPacket waits for a packet or for the timeout to expire. 20 | func (p *Handle) waitForPacket() { 21 | // can't use select() so instead just switch goroutines 22 | runtime.Gosched() 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/.travis.golint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd "$(dirname $0)" 4 | 5 | go get github.com/golang/lint/golint 6 | DIRS=". tcpassembly tcpassembly/tcpreader ip4defrag reassembly macs pcapgo pcap afpacket pfring routing" 7 | # Add subdirectories here as we clean up golint on each. 8 | for subdir in $DIRS; do 9 | pushd $subdir 10 | if golint | 11 | grep -v CannotSetRFMon | # pcap exported error name 12 | grep -v DataLost | # tcpassembly/tcpreader exported error name 13 | grep .; then 14 | exit 1 15 | fi 16 | popd 17 | done 18 | 19 | pushd layers 20 | for file in $(cat .linted); do 21 | if golint $file | grep .; then 22 | exit 1 23 | fi 24 | done 25 | popd 26 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/metrics.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | // SetMetricTags sets the tags for the named metric and flags a check update is needed 8 | func (m *CirconusMetrics) SetMetricTags(name string, tags []string) bool { 9 | return m.check.AddMetricTags(name, tags, false) 10 | } 11 | 12 | // AddMetricTags appends tags to any existing tags for the named metric and flags a check update is needed 13 | func (m *CirconusMetrics) AddMetricTags(name string, tags []string) bool { 14 | return m.check.AddMetricTags(name, tags, true) 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | #* 24 | *~ 25 | 26 | # examples binaries 27 | examples/synscan/synscan 28 | examples/pfdump/pfdump 29 | examples/pcapdump/pcapdump 30 | examples/httpassembly/httpassembly 31 | examples/statsassembly/statsassembly 32 | examples/arpscan/arpscan 33 | examples/bidirectional/bidirectional 34 | examples/bytediff/bytediff 35 | examples/reassemblydump/reassemblydump 36 | layers/gen 37 | macs/gen 38 | pcap/pcap_tester 39 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: build-{build}.{branch} 2 | 3 | clone_folder: C:\gopath\src\github.com\pkg\errors 4 | shallow_clone: true # for startup speed 5 | 6 | environment: 7 | GOPATH: C:\gopath 8 | 9 | platform: 10 | - x64 11 | 12 | # http://www.appveyor.com/docs/installed-software 13 | install: 14 | # some helpful output for debugging builds 15 | - go version 16 | - go env 17 | # pre-installed MinGW at C:\MinGW is 32bit only 18 | # but MSYS2 at C:\msys64 has mingw64 19 | - set PATH=C:\msys64\mingw64\bin;%PATH% 20 | - gcc --version 21 | - g++ --version 22 | 23 | build_script: 24 | - go install -v ./... 25 | 26 | test_script: 27 | - set PATH=C:\gopath\bin;%PATH% 28 | - go test -v ./... 29 | 30 | #artifacts: 31 | # - path: '%GOPATH%\bin\*.exe' 32 | deploy: off 33 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/stp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "github.com/google/gopacket" 11 | ) 12 | 13 | // STP decode spanning tree protocol packets to transport BPDU (bridge protocol data unit) message. 14 | type STP struct { 15 | BaseLayer 16 | } 17 | 18 | // LayerType returns gopacket.LayerTypeSTP. 19 | func (s *STP) LayerType() gopacket.LayerType { return LayerTypeSTP } 20 | 21 | func decodeSTP(data []byte, p gopacket.PacketBuilder) error { 22 | stp := &STP{} 23 | stp.Contents = data[:] 24 | // TODO: parse the STP protocol into actual subfields. 25 | p.AddLayer(stp) 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/encode_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Snappy-Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | // +build gc 7 | // +build !noasm 8 | 9 | package snappy 10 | 11 | // emitLiteral has the same semantics as in encode_other.go. 12 | // 13 | //go:noescape 14 | func emitLiteral(dst, lit []byte) int 15 | 16 | // emitCopy has the same semantics as in encode_other.go. 17 | // 18 | //go:noescape 19 | func emitCopy(dst []byte, offset, length int) int 20 | 21 | // extendMatch has the same semantics as in encode_other.go. 22 | // 23 | //go:noescape 24 | func extendMatch(src []byte, i, j int) int 25 | 26 | // encodeBlock has the same semantics as in encode_other.go. 27 | // 28 | //go:noescape 29 | func encodeBlock(dst, src []byte) (d int) 30 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/cmd/snappytool/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "flag" 6 | "io/ioutil" 7 | "os" 8 | 9 | "github.com/golang/snappy" 10 | ) 11 | 12 | var ( 13 | decode = flag.Bool("d", false, "decode") 14 | encode = flag.Bool("e", false, "encode") 15 | ) 16 | 17 | func run() error { 18 | flag.Parse() 19 | if *decode == *encode { 20 | return errors.New("exactly one of -d or -e must be given") 21 | } 22 | 23 | in, err := ioutil.ReadAll(os.Stdin) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | out := []byte(nil) 29 | if *decode { 30 | out, err = snappy.Decode(nil, in) 31 | if err != nil { 32 | return err 33 | } 34 | } else { 35 | out = snappy.Encode(nil, in) 36 | } 37 | _, err = os.Stdout.Write(out) 38 | return err 39 | } 40 | 41 | func main() { 42 | if err := run(); err != nil { 43 | os.Stderr.WriteString(err.Error() + "\n") 44 | os.Exit(1) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/tools.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | import ( 8 | "net/http" 9 | "time" 10 | ) 11 | 12 | // TrackHTTPLatency wraps Handler functions registered with an http.ServerMux tracking latencies. 13 | // Metrics are of the for go`HTTP```latency and are tracked in a histogram in units 14 | // of seconds (as a float64) providing nanosecond ganularity. 15 | func (m *CirconusMetrics) TrackHTTPLatency(name string, handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { 16 | return func(rw http.ResponseWriter, req *http.Request) { 17 | start := time.Now().UnixNano() 18 | handler(rw, req) 19 | elapsed := time.Now().UnixNano() - start 20 | m.RecordValue("go`HTTP`"+req.Method+"`"+name+"`latency", float64(elapsed)/float64(time.Second)) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | 22 | 23 | [[constraint]] 24 | branch = "master" 25 | name = "github.com/circonus-labs/circonusllhist" 26 | 27 | [[constraint]] 28 | branch = "master" 29 | name = "github.com/hashicorp/go-retryablehttp" 30 | 31 | [[constraint]] 32 | name = "github.com/pkg/errors" 33 | version = "0.8.0" 34 | 35 | [[constraint]] 36 | branch = "master" 37 | name = "github.com/tv42/httpunix" 38 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/examples/util/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // Package util provides shared utilities for all gopacket examples. 8 | package util 9 | 10 | import ( 11 | "flag" 12 | "log" 13 | "os" 14 | "runtime/pprof" 15 | ) 16 | 17 | var cpuprofile = flag.String("cpuprofile", "", "Where to write CPU profile") 18 | 19 | // Run starts up stuff at the beginning of a main function, and returns a 20 | // function to defer until the function completes. It should be used like this: 21 | // 22 | // func main() { 23 | // defer util.Run()() 24 | // ... stuff ... 25 | // } 26 | func Run() func() { 27 | flag.Parse() 28 | if *cpuprofile != "" { 29 | f, err := os.Create(*cpuprofile) 30 | if err != nil { 31 | log.Fatalf("could not open cpu profile file %q", *cpuprofile) 32 | } 33 | pprof.StartCPUProfile(f) 34 | return func() { 35 | pprof.StopCPUProfile() 36 | f.Close() 37 | } 38 | } 39 | return func() {} 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/tv42/httpunix/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Tommi Virtanen. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/handlers.go: -------------------------------------------------------------------------------- 1 | package cleanhttp 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | "unicode" 7 | ) 8 | 9 | // HandlerInput provides input options to cleanhttp's handlers 10 | type HandlerInput struct { 11 | ErrStatus int 12 | } 13 | 14 | // PrintablePathCheckHandler is a middleware that ensures the request path 15 | // contains only printable runes. 16 | func PrintablePathCheckHandler(next http.Handler, input *HandlerInput) http.Handler { 17 | // Nil-check on input to make it optional 18 | if input == nil { 19 | input = &HandlerInput{ 20 | ErrStatus: http.StatusBadRequest, 21 | } 22 | } 23 | 24 | // Default to http.StatusBadRequest on error 25 | if input.ErrStatus == 0 { 26 | input.ErrStatus = http.StatusBadRequest 27 | } 28 | 29 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 30 | // Check URL path for non-printable characters 31 | idx := strings.IndexFunc(r.URL.Path, func(c rune) bool { 32 | return !unicode.IsPrint(c) 33 | }) 34 | 35 | if idx != -1 { 36 | w.WriteHeader(input.ErrStatus) 37 | return 38 | } 39 | 40 | next.ServeHTTP(w, r) 41 | return 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/endpoints_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017, Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "net" 11 | "testing" 12 | 13 | "github.com/google/gopacket" 14 | ) 15 | 16 | func TestNewIPEndpoint(t *testing.T) { 17 | cases := []struct { 18 | ip net.IP 19 | endpointType gopacket.EndpointType 20 | }{ 21 | {net.ParseIP("192.168.0.1").To4(), EndpointIPv4}, 22 | {net.ParseIP("192.168.0.1").To16(), EndpointIPv4}, 23 | {net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), EndpointIPv6}, 24 | } 25 | 26 | for _, c := range cases { 27 | endpoint := NewIPEndpoint(c.ip) 28 | if endpoint == gopacket.InvalidEndpoint { 29 | t.Errorf("Failed to create an IP endpoint for %s (%d-bytes)", 30 | c.ip, len(c.ip)) 31 | } 32 | if endpoint.EndpointType() != c.endpointType { 33 | t.Errorf("Wrong endpoint type created for %s (%d-bytes): expected %s, got %s", 34 | c.ip, len(c.ip), c.endpointType, endpoint.EndpointType()) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/base_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012, Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // This file contains some test helper functions. 8 | 9 | package layers 10 | 11 | import ( 12 | "github.com/google/gopacket" 13 | "testing" 14 | ) 15 | 16 | func min(a, b int) int { 17 | if a < b { 18 | return a 19 | } 20 | return b 21 | } 22 | 23 | func checkLayers(p gopacket.Packet, want []gopacket.LayerType, t *testing.T) { 24 | layers := p.Layers() 25 | t.Log("Checking packet layers, want", want) 26 | for _, l := range layers { 27 | t.Logf(" Got layer %v, %d bytes, payload of %d bytes", l.LayerType(), 28 | len(l.LayerContents()), len(l.LayerPayload())) 29 | } 30 | t.Log(p) 31 | if len(layers) != len(want) { 32 | t.Errorf(" Number of layers mismatch: got %d want %d", len(layers), 33 | len(want)) 34 | return 35 | } 36 | for i, l := range layers { 37 | if l.LayerType() != want[i] { 38 | t.Errorf(" Layer %d mismatch: got %v want %v", i, l.LayerType(), 39 | want[i]) 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/bench_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package errors 4 | 5 | import ( 6 | "fmt" 7 | "testing" 8 | 9 | stderrors "errors" 10 | ) 11 | 12 | func noErrors(at, depth int) error { 13 | if at >= depth { 14 | return stderrors.New("no error") 15 | } 16 | return noErrors(at+1, depth) 17 | } 18 | func yesErrors(at, depth int) error { 19 | if at >= depth { 20 | return New("ye error") 21 | } 22 | return yesErrors(at+1, depth) 23 | } 24 | 25 | func BenchmarkErrors(b *testing.B) { 26 | var toperr error 27 | type run struct { 28 | stack int 29 | std bool 30 | } 31 | runs := []run{ 32 | {10, false}, 33 | {10, true}, 34 | {100, false}, 35 | {100, true}, 36 | {1000, false}, 37 | {1000, true}, 38 | } 39 | for _, r := range runs { 40 | part := "pkg/errors" 41 | if r.std { 42 | part = "errors" 43 | } 44 | name := fmt.Sprintf("%s-stack-%d", part, r.stack) 45 | b.Run(name, func(b *testing.B) { 46 | var err error 47 | f := yesErrors 48 | if r.std { 49 | f = noErrors 50 | } 51 | b.ReportAllocs() 52 | for i := 0; i < b.N; i++ { 53 | err = f(0, r.stack) 54 | } 55 | b.StopTimer() 56 | toperr = err 57 | }) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/doc.go: -------------------------------------------------------------------------------- 1 | // Package cleanhttp offers convenience utilities for acquiring "clean" 2 | // http.Transport and http.Client structs. 3 | // 4 | // Values set on http.DefaultClient and http.DefaultTransport affect all 5 | // callers. This can have detrimental effects, esepcially in TLS contexts, 6 | // where client or root certificates set to talk to multiple endpoints can end 7 | // up displacing each other, leading to hard-to-debug issues. This package 8 | // provides non-shared http.Client and http.Transport structs to ensure that 9 | // the configuration will not be overwritten by other parts of the application 10 | // or dependencies. 11 | // 12 | // The DefaultClient and DefaultTransport functions disable idle connections 13 | // and keepalives. Without ensuring that idle connections are closed before 14 | // garbage collection, short-term clients/transports can leak file descriptors, 15 | // eventually leading to "too many open files" errors. If you will be 16 | // connecting to the same hosts repeatedly from the same client, you can use 17 | // DefaultPooledClient to receive a client that has connection pooling 18 | // semantics similar to http.DefaultClient. 19 | // 20 | package cleanhttp 21 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | branch = "master" 6 | name = "github.com/circonus-labs/circonusllhist" 7 | packages = ["."] 8 | revision = "5eb751da55c6d3091faf3861ec5062ae91fee9d0" 9 | 10 | [[projects]] 11 | branch = "master" 12 | name = "github.com/hashicorp/go-cleanhttp" 13 | packages = ["."] 14 | revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d" 15 | 16 | [[projects]] 17 | branch = "master" 18 | name = "github.com/hashicorp/go-retryablehttp" 19 | packages = ["."] 20 | revision = "e651d75abec6fbd4f2c09508f72ae7af8a8b7171" 21 | 22 | [[projects]] 23 | name = "github.com/pkg/errors" 24 | packages = ["."] 25 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d" 26 | version = "v0.8.0" 27 | 28 | [[projects]] 29 | branch = "master" 30 | name = "github.com/tv42/httpunix" 31 | packages = ["."] 32 | revision = "b75d8614f926c077e48d85f1f8f7885b758c6225" 33 | 34 | [solve-meta] 35 | analyzer-name = "dep" 36 | analyzer-version = 1 37 | inputs-digest = "6db34ba31cd011426f28b5db0dbe259c4dc3787fb2074b2c06cb382385a90242" 38 | solver-name = "gps-cdcl" 39 | solver-version = 1 40 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/text.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | // A Text metric is an arbitrary string 8 | // 9 | 10 | // SetText sets a text metric 11 | func (m *CirconusMetrics) SetText(metric string, val string) { 12 | m.SetTextValue(metric, val) 13 | } 14 | 15 | // SetTextValue sets a text metric 16 | func (m *CirconusMetrics) SetTextValue(metric string, val string) { 17 | m.tm.Lock() 18 | defer m.tm.Unlock() 19 | m.text[metric] = val 20 | } 21 | 22 | // RemoveText removes a text metric 23 | func (m *CirconusMetrics) RemoveText(metric string) { 24 | m.tm.Lock() 25 | defer m.tm.Unlock() 26 | delete(m.text, metric) 27 | } 28 | 29 | // SetTextFunc sets a text metric to a function [called at flush interval] 30 | func (m *CirconusMetrics) SetTextFunc(metric string, fn func() string) { 31 | m.tfm.Lock() 32 | defer m.tfm.Unlock() 33 | m.textFuncs[metric] = fn 34 | } 35 | 36 | // RemoveTextFunc a text metric function 37 | func (m *CirconusMetrics) RemoveTextFunc(metric string) { 38 | m.tfm.Lock() 39 | defer m.tfm.Unlock() 40 | delete(m.textFuncs, metric) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/afpacket/sockopt_linux_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build linux,386 8 | 9 | package afpacket 10 | 11 | import ( 12 | "unsafe" 13 | 14 | "golang.org/x/sys/unix" 15 | ) 16 | 17 | const ( 18 | sysSETSOCKOPT = 0xe 19 | sysGETSOCKOPT = 0xf 20 | ) 21 | 22 | func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, unix.Errno) 23 | 24 | // setsockopt provides access to the setsockopt syscall. 25 | func setsockopt(fd, level, name int, v unsafe.Pointer, l uintptr) error { 26 | _, errno := socketcall( 27 | sysSETSOCKOPT, 28 | uintptr(fd), 29 | uintptr(level), 30 | uintptr(name), 31 | uintptr(v), 32 | l, 33 | 0, 34 | ) 35 | if errno != 0 { 36 | return error(errno) 37 | } 38 | 39 | return nil 40 | } 41 | 42 | func getsockopt(fd, level, name int, v unsafe.Pointer, l uintptr) error { 43 | _, errno := socketcall( 44 | sysGETSOCKOPT, 45 | uintptr(fd), 46 | uintptr(level), 47 | uintptr(name), 48 | uintptr(v), 49 | l, 50 | 0, 51 | ) 52 | if errno != 0 { 53 | return error(errno) 54 | } 55 | 56 | return nil 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/fddi.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "github.com/google/gopacket" 11 | "net" 12 | ) 13 | 14 | // FDDI contains the header for FDDI frames. 15 | type FDDI struct { 16 | BaseLayer 17 | FrameControl FDDIFrameControl 18 | Priority uint8 19 | SrcMAC, DstMAC net.HardwareAddr 20 | } 21 | 22 | // LayerType returns LayerTypeFDDI. 23 | func (f *FDDI) LayerType() gopacket.LayerType { return LayerTypeFDDI } 24 | 25 | // LinkFlow returns a new flow of type EndpointMAC. 26 | func (f *FDDI) LinkFlow() gopacket.Flow { 27 | return gopacket.NewFlow(EndpointMAC, f.SrcMAC, f.DstMAC) 28 | } 29 | 30 | func decodeFDDI(data []byte, p gopacket.PacketBuilder) error { 31 | f := &FDDI{ 32 | FrameControl: FDDIFrameControl(data[0] & 0xF8), 33 | Priority: data[0] & 0x07, 34 | SrcMAC: net.HardwareAddr(data[1:7]), 35 | DstMAC: net.HardwareAddr(data[7:13]), 36 | BaseLayer: BaseLayer{data[:13], data[13:]}, 37 | } 38 | p.SetLinkLayer(f) 39 | p.AddLayer(f) 40 | return p.NextDecoder(f.FrameControl) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/afpacket/afpacket_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build linux 8 | 9 | package afpacket 10 | 11 | import ( 12 | "reflect" 13 | "testing" 14 | ) 15 | 16 | func TestParseOptions(t *testing.T) { 17 | wanted1 := defaultOpts 18 | wanted1.frameSize = 1 << 10 19 | wanted1.framesPerBlock = wanted1.blockSize / wanted1.frameSize 20 | for i, test := range []struct { 21 | opts []interface{} 22 | want options 23 | err bool 24 | }{ 25 | {opts: []interface{}{OptBlockSize(2)}, err: true}, 26 | {opts: []interface{}{OptFrameSize(333)}, err: true}, 27 | {opts: []interface{}{OptTPacketVersion(-3)}, err: true}, 28 | {opts: []interface{}{OptTPacketVersion(5)}, err: true}, 29 | {opts: []interface{}{OptFrameSize(1 << 10)}, want: wanted1}, 30 | } { 31 | got, err := parseOptions(test.opts...) 32 | t.Logf("got: %#v\nerr: %v", got, err) 33 | if test.err && err == nil || !test.err && err != nil { 34 | t.Errorf("%d error mismatch, want error? %v. error: %v", i, test.err, err) 35 | } 36 | if !test.err && !reflect.DeepEqual(test.want, got) { 37 | t.Errorf("%d opts mismatch, want\n%#v", i, test.want) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Dave Cheney 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # v2.2.1 2 | 3 | * fix: if submission url host is 'api.circonus.com' do not use private CA in TLSConfig 4 | 5 | # v2.2.0 6 | 7 | * fix: do not reset counter|gauge|text funcs after each snapshot (only on explicit call to Reset) 8 | * upd: dashboards - optional widget attributes - which are structs - should be pointers for correct omission in json sent to api 9 | * fix: dashboards - remove `omitempty` from required attributes 10 | * fix: graphs - remove `omitempty` from required attributes 11 | * fix: worksheets - correct attribute name, remove `omitempty` from required attributes 12 | * fix: handle case where a broker has no external host or ip set 13 | 14 | # v2.1.2 15 | 16 | * upd: breaking change in upstream repo 17 | * upd: upstream deps 18 | 19 | # v2.1.1 20 | 21 | * dep dependencies 22 | * fix two instances of shadowed variables 23 | * fix several documentation typos 24 | * simplify (gofmt -s) 25 | * remove an inefficient use of regexp.MatchString 26 | 27 | # v2.1.0 28 | 29 | * Add unix socket capability for SubmissionURL `http+unix://...` 30 | * Add `RecordCountForValue` function to histograms 31 | 32 | # v2.0.0 33 | 34 | * gauges as `interface{}` 35 | * change: `GeTestGauge(string) (string,error)` -> `GeTestGauge(string) (interface{},error)` 36 | * add: `AddGauge(string, interface{})` to add a delta value to an existing gauge 37 | * prom output candidate 38 | * Add `CHANGELOG.md` to repository 39 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/afpacket/sockopt_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build linux 8 | 9 | package afpacket 10 | 11 | import ( 12 | "unsafe" 13 | 14 | "golang.org/x/sys/unix" 15 | ) 16 | 17 | // setsockopt provides access to the setsockopt syscall. 18 | func setsockopt(fd, level, name int, val unsafe.Pointer, vallen uintptr) error { 19 | _, _, errno := unix.Syscall6( 20 | unix.SYS_SETSOCKOPT, 21 | uintptr(fd), 22 | uintptr(level), 23 | uintptr(name), 24 | uintptr(val), 25 | vallen, 26 | 0, 27 | ) 28 | if errno != 0 { 29 | return error(errno) 30 | } 31 | 32 | return nil 33 | } 34 | 35 | // getsockopt provides access to the getsockopt syscall. 36 | func getsockopt(fd, level, name int, val unsafe.Pointer, vallen uintptr) error { 37 | _, _, errno := unix.Syscall6( 38 | unix.SYS_GETSOCKOPT, 39 | uintptr(fd), 40 | uintptr(level), 41 | uintptr(name), 42 | uintptr(val), 43 | vallen, 44 | 0, 45 | ) 46 | if errno != 0 { 47 | return error(errno) 48 | } 49 | 50 | return nil 51 | } 52 | 53 | // htons converts a short (uint16) from host-to-network byte order. 54 | // Thanks to mikioh for this neat trick: 55 | // https://github.com/mikioh/-stdyng/blob/master/afpacket.go 56 | func htons(i uint16) uint16 { 57 | return (i<<8)&0xff00 | i>>8 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/etherip.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "github.com/google/gopacket" 12 | ) 13 | 14 | // EtherIP is the struct for storing RFC 3378 EtherIP packet headers. 15 | type EtherIP struct { 16 | BaseLayer 17 | Version uint8 18 | Reserved uint16 19 | } 20 | 21 | // LayerType returns gopacket.LayerTypeEtherIP. 22 | func (e *EtherIP) LayerType() gopacket.LayerType { return LayerTypeEtherIP } 23 | 24 | // DecodeFromBytes decodes the given bytes into this layer. 25 | func (e *EtherIP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 26 | e.Version = data[0] >> 4 27 | e.Reserved = binary.BigEndian.Uint16(data[:2]) & 0x0fff 28 | e.BaseLayer = BaseLayer{data[:2], data[2:]} 29 | return nil 30 | } 31 | 32 | // CanDecode returns the set of layer types that this DecodingLayer can decode. 33 | func (e *EtherIP) CanDecode() gopacket.LayerClass { 34 | return LayerTypeEtherIP 35 | } 36 | 37 | // NextLayerType returns the layer type contained by this DecodingLayer. 38 | func (e *EtherIP) NextLayerType() gopacket.LayerType { 39 | return LayerTypeEthernet 40 | } 41 | 42 | func decodeEtherIP(data []byte, p gopacket.PacketBuilder) error { 43 | e := &EtherIP{} 44 | return decodingLayerDecoder(e, data, p) 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/udplite.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style license 5 | // that can be found in the LICENSE file in the root of the source 6 | // tree. 7 | 8 | package layers 9 | 10 | import ( 11 | "encoding/binary" 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | // UDPLite is the layer for UDP-Lite headers (rfc 3828). 16 | type UDPLite struct { 17 | BaseLayer 18 | SrcPort, DstPort UDPLitePort 19 | ChecksumCoverage uint16 20 | Checksum uint16 21 | sPort, dPort []byte 22 | } 23 | 24 | // LayerType returns gopacket.LayerTypeUDPLite 25 | func (u *UDPLite) LayerType() gopacket.LayerType { return LayerTypeUDPLite } 26 | 27 | func decodeUDPLite(data []byte, p gopacket.PacketBuilder) error { 28 | udp := &UDPLite{ 29 | SrcPort: UDPLitePort(binary.BigEndian.Uint16(data[0:2])), 30 | sPort: data[0:2], 31 | DstPort: UDPLitePort(binary.BigEndian.Uint16(data[2:4])), 32 | dPort: data[2:4], 33 | ChecksumCoverage: binary.BigEndian.Uint16(data[4:6]), 34 | Checksum: binary.BigEndian.Uint16(data[6:8]), 35 | BaseLayer: BaseLayer{data[:8], data[8:]}, 36 | } 37 | p.AddLayer(udp) 38 | p.SetTransportLayer(udp) 39 | return p.NextDecoder(gopacket.LayerTypePayload) 40 | } 41 | 42 | func (u *UDPLite) TransportFlow() gopacket.Flow { 43 | return gopacket.NewFlow(EndpointUDPLitePort, u.sPort, u.dPort) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/README.md: -------------------------------------------------------------------------------- 1 | # cleanhttp 2 | 3 | Functions for accessing "clean" Go http.Client values 4 | 5 | ------------- 6 | 7 | The Go standard library contains a default `http.Client` called 8 | `http.DefaultClient`. It is a common idiom in Go code to start with 9 | `http.DefaultClient` and tweak it as necessary, and in fact, this is 10 | encouraged; from the `http` package documentation: 11 | 12 | > The Client's Transport typically has internal state (cached TCP connections), 13 | so Clients should be reused instead of created as needed. Clients are safe for 14 | concurrent use by multiple goroutines. 15 | 16 | Unfortunately, this is a shared value, and it is not uncommon for libraries to 17 | assume that they are free to modify it at will. With enough dependencies, it 18 | can be very easy to encounter strange problems and race conditions due to 19 | manipulation of this shared value across libraries and goroutines (clients are 20 | safe for concurrent use, but writing values to the client struct itself is not 21 | protected). 22 | 23 | Making things worse is the fact that a bare `http.Client` will use a default 24 | `http.Transport` called `http.DefaultTransport`, which is another global value 25 | that behaves the same way. So it is not simply enough to replace 26 | `http.DefaultClient` with `&http.Client{}`. 27 | 28 | This repository provides some simple functions to get a "clean" `http.Client` 29 | -- one that uses the same default values as the Go standard library, but 30 | returns a client that does not share any state with other clients. 31 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcap/pcapgo_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package pcap 8 | 9 | import ( 10 | "bytes" 11 | "github.com/google/gopacket" 12 | "github.com/google/gopacket/layers" 13 | "github.com/google/gopacket/pcapgo" 14 | "io/ioutil" 15 | "reflect" 16 | "testing" 17 | "time" 18 | ) 19 | 20 | func TestPCAPGoWrite(t *testing.T) { 21 | f, err := ioutil.TempFile("", "pcapgo") 22 | if err != nil { 23 | t.Fatal(err) 24 | } 25 | data := []byte{0xab, 0xcd, 0xef, 0x01, 0x02, 0x03, 0x04} 26 | ci := gopacket.CaptureInfo{ 27 | Timestamp: time.Unix(12345667, 1234567000), 28 | Length: 700, 29 | CaptureLength: len(data), 30 | } 31 | func() { 32 | defer f.Close() 33 | w := pcapgo.NewWriter(f) 34 | if err := w.WriteFileHeader(65536, layers.LinkTypeEthernet); err != nil { 35 | t.Fatal(err) 36 | } 37 | if err := w.WritePacket(ci, data); err != nil { 38 | t.Fatal(err) 39 | } 40 | }() 41 | h, err := OpenOffline(f.Name()) 42 | if err != nil { 43 | t.Fatal(err) 44 | } 45 | defer h.Close() 46 | gotData, gotCI, err := h.ReadPacketData() 47 | if err != nil { 48 | t.Fatal("could not read first packet:", err) 49 | } 50 | if !bytes.Equal(gotData, data) { 51 | t.Errorf("byte mismatch:\nwant: %v\n got: %v", data, gotData) 52 | } 53 | if !reflect.DeepEqual(ci, gotCI) { 54 | t.Errorf("CI mismatch:\nwant: %v\n got: %v", ci, gotCI) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This is the official list of people who can contribute 2 | # (and typically have contributed) code to the Snappy-Go repository. 3 | # The AUTHORS file lists the copyright holders; this file 4 | # lists people. For example, Google employees are listed here 5 | # but not in AUTHORS, because Google holds the copyright. 6 | # 7 | # The submission process automatically checks to make sure 8 | # that people submitting code are listed in this file (by email address). 9 | # 10 | # Names should be added to this file only after verifying that 11 | # the individual or the individual's organization has agreed to 12 | # the appropriate Contributor License Agreement, found here: 13 | # 14 | # http://code.google.com/legal/individual-cla-v1.0.html 15 | # http://code.google.com/legal/corporate-cla-v1.0.html 16 | # 17 | # The agreement for individuals can be filled out on the web. 18 | # 19 | # When adding J Random Contributor's name to this file, 20 | # either J's name or J's organization's name should be 21 | # added to the AUTHORS file, depending on whether the 22 | # individual or corporate CLA was used. 23 | 24 | # Names should be added to this file like so: 25 | # Name 26 | 27 | # Please keep the list sorted. 28 | 29 | Damian Gryski 30 | Jan Mercl <0xjnml@gmail.com> 31 | Kai Backman 32 | Marc-Antoine Ruel 33 | Nigel Tao 34 | Rob Pike 35 | Rodolfo Carvalho 36 | Russ Cox 37 | Sebastien Binet 38 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 The Snappy-Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/AUTHORS: -------------------------------------------------------------------------------- 1 | AUTHORS AND MAINTAINERS: 2 | 3 | MAIN DEVELOPERS: 4 | Graeme Connell 5 | 6 | AUTHORS: 7 | Nigel Tao 8 | Cole Mickens 9 | Ben Daglish 10 | Luis Martinez 11 | Remco Verhoef 12 | Hiroaki Kawai 13 | Lukas Lueg 14 | Laurent Hausermann 15 | Bill Green 16 | 17 | CONTRIBUTORS: 18 | Attila Oláh 19 | Vittus Mikiassen 20 | Matthias Radestock 21 | Matthew Sackman 22 | Loic Prylli 23 | Alexandre Fiori 24 | Adrian Tam 25 | Satoshi Matsumoto 26 | David Stainton 27 | Jesse Ward 28 | Kane Mathers 29 | 30 | ----------------------------------------------- 31 | FORKED FROM github.com/akrennmair/gopcap 32 | ALL THE FOLLOWING ARE FOR THAT PROJECT 33 | 34 | MAIN DEVELOPERS: 35 | Andreas Krennmair 36 | 37 | CONTRIBUTORS: 38 | Andrea Nall 39 | Daniel Arndt 40 | Dustin Sallings 41 | Graeme Connell 42 | Guillaume Savary 43 | Mark Smith 44 | Miek Gieben 45 | Mike Bell 46 | Trevor Strohman 47 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonusllhist/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Circonus, Inc. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the name Circonus, Inc. nor the names of its contributors 14 | may be used to endorse or promote products derived from this 15 | software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Circonus, Inc. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the name Circonus, Inc. nor the names 14 | of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written 16 | permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Google, Inc. All rights reserved. 2 | Copyright (c) 2009-2011 Andreas Krennmair. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Andreas Krennmair, Google, nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/bytediff/bytediff_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package bytediff 8 | 9 | import ( 10 | "reflect" 11 | "testing" 12 | ) 13 | 14 | func TestLCS(t *testing.T) { 15 | for i, test := range []struct { 16 | a, b []byte 17 | indexA, indexB, length int 18 | }{ 19 | {[]byte{1, 2, 3}, []byte{1, 2, 3}, 0, 0, 3}, 20 | {[]byte{0, 1, 2, 3}, []byte{1, 2, 3, 4}, 1, 0, 3}, 21 | {[]byte{0, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3}, []byte{1, 2, 3, 4}, 4, 0, 4}, 22 | {[]byte{1, 2, 2, 3, 4}, []byte{1, 2, 3, 4}, 2, 1, 3}, 23 | {[]byte{0, 1, 2, 3, 4}, []byte{1, 1, 2, 2, 3, 4}, 2, 3, 3}, 24 | } { 25 | ia, ib, l := longestCommonSubstring(test.a, test.b) 26 | if ia != test.indexA || ib != test.indexB || l != test.length { 27 | t.Errorf("%d: want (%d %d %d) got (%d %d %d)", i, test.indexA, test.indexB, test.length, ia, ib, l) 28 | } 29 | } 30 | } 31 | 32 | func TestDiff(t *testing.T) { 33 | for i, test := range []struct { 34 | a, b []byte 35 | d Differences 36 | }{ 37 | { 38 | []byte{0, 1, 2, 3, 4}, 39 | []byte{1, 1, 2, 2, 3, 4}, 40 | Differences{ 41 | Difference{true, []byte{0}, []byte{}}, 42 | Difference{false, []byte{1}, []byte{1}}, 43 | Difference{true, []byte{}, []byte{1, 2}}, 44 | Difference{false, []byte{2, 3, 4}, []byte{2, 3, 4}}, 45 | }, 46 | }, 47 | } { 48 | diffs := Diff(test.a, test.b) 49 | if !reflect.DeepEqual(diffs, test.d) { 50 | t.Errorf("%d want %v got %v", i, test.d, diffs) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/dot1q_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | package layers 7 | 8 | import ( 9 | "fmt" 10 | "reflect" 11 | "testing" 12 | 13 | "github.com/google/gopacket" 14 | ) 15 | 16 | // test harness to ensure the dot1q layer can be encoded/decoded properly 17 | // return error if decoded data not match. 18 | func testEncodeDecodeDot1Q(dot1Q *Dot1Q) error { 19 | buf := gopacket.NewSerializeBuffer() 20 | opts := gopacket.SerializeOptions{} 21 | expectedDot1Q := dot1Q 22 | 23 | err := dot1Q.SerializeTo(buf, opts) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | newDot1q := &Dot1Q{} 29 | err = newDot1q.DecodeFromBytes(buf.Bytes(), gopacket.NilDecodeFeedback) 30 | if err != nil { 31 | return err 32 | } 33 | newDot1q.BaseLayer = BaseLayer{} 34 | 35 | if !reflect.DeepEqual(expectedDot1Q, newDot1q) { 36 | return fmt.Errorf("Expect %v actual %v", expectedDot1Q, newDot1q) 37 | } 38 | return nil 39 | 40 | } 41 | 42 | // Test to ensure what has been encode can be decoded 43 | func TestEncodeDecodeDot1Q(t *testing.T) { 44 | dot1Qs := []*Dot1Q{ 45 | &Dot1Q{ 46 | Priority: uint8(3), 47 | VLANIdentifier: uint16(30), 48 | }, 49 | &Dot1Q{ 50 | Priority: uint8(0x07), 51 | DropEligible: true, 52 | VLANIdentifier: uint16(0xFFF), 53 | }, 54 | } 55 | 56 | for i, curTest := range dot1Qs { 57 | err := testEncodeDecodeDot1Q(curTest) 58 | if err != nil { 59 | t.Error("Error with item ", i, " with error message :", err) 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/routing/common.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package routing 8 | 9 | import ( 10 | "net" 11 | ) 12 | 13 | // Router implements simple IPv4/IPv6 routing based on the kernel's routing 14 | // table. This routing library has very few features and may actually route 15 | // incorrectly in some cases, but it should work the majority of the time. 16 | type Router interface { 17 | // Route returns where to route a packet based on the packet's source 18 | // and destination IP address. 19 | // 20 | // Callers may pass in nil for src, in which case the src is treated as 21 | // either 0.0.0.0 or ::, depending on whether dst is a v4 or v6 address. 22 | // 23 | // It returns the interface on which to send the packet, the gateway IP 24 | // to send the packet to (if necessary), the preferred src IP to use (if 25 | // available). If the preferred src address is not given in the routing 26 | // table, the first IP address of the interface is provided. 27 | // 28 | // If an error is encountered, iface, geteway, and 29 | // preferredSrc will be nil, and err will be set. 30 | Route(dst net.IP) (iface *net.Interface, gateway, preferredSrc net.IP, err error) 31 | 32 | // RouteWithSrc routes based on source information as well as destination 33 | // information. Either or both of input/src can be nil. If both are, this 34 | // should behave exactly like Route(dst) 35 | RouteWithSrc(input net.HardwareAddr, src, dst net.IP) (iface *net.Interface, gateway, preferredSrc net.IP, err error) 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/tcp_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016, Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | func TestTCPOptionKindString(t *testing.T) { 16 | testData := []struct { 17 | o *TCPOption 18 | s string 19 | }{ 20 | {&TCPOption{ 21 | OptionType: TCPOptionKindNop, 22 | OptionLength: 1, 23 | }, 24 | "TCPOption(NOP:)"}, 25 | {&TCPOption{ 26 | OptionType: TCPOptionKindMSS, 27 | OptionLength: 4, 28 | OptionData: []byte{0x12, 0x34}, 29 | }, 30 | "TCPOption(MSS:4660 0x1234)"}, 31 | {&TCPOption{ 32 | OptionType: TCPOptionKindTimestamps, 33 | OptionLength: 10, 34 | OptionData: []byte{0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}, 35 | }, 36 | "TCPOption(Timestamps:2/1 0x0000000200000001)"}} 37 | 38 | for _, tc := range testData { 39 | if s := tc.o.String(); s != tc.s { 40 | t.Errorf("expected %#v string to be %s, got %s", tc.o, tc.s, s) 41 | } 42 | } 43 | } 44 | 45 | func TestTCPSerializePadding(t *testing.T) { 46 | tcp := &TCP{} 47 | tcp.Options = append(tcp.Options, TCPOption{ 48 | OptionType: TCPOptionKindNop, 49 | OptionLength: 1, 50 | }) 51 | buf := gopacket.NewSerializeBuffer() 52 | opts := gopacket.SerializeOptions{FixLengths: true} 53 | err := gopacket.SerializeLayers(buf, opts, tcp) 54 | if err != nil { 55 | t.Fatal(err) 56 | } 57 | if len(buf.Bytes())%4 != 0 { 58 | t.Errorf("TCP data of len %d not padding to 32 bit boundary", len(buf.Bytes())) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/circonus-labs/circonus-gometrics v2.2.1+incompatible h1:1L31gruXa06igfDg0HNf0lw40TEgGesySg9nZ3rI5v4= 2 | github.com/circonus-labs/circonus-gometrics v2.2.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= 3 | github.com/circonus-labs/circonusllhist v0.0.0-20180430145027-5eb751da55c6 h1:Rm//1hbNxCErrYx7+QSOvITlZtNpt3rW1Ov8lxifdsg= 4 | github.com/circonus-labs/circonusllhist v0.0.0-20180430145027-5eb751da55c6/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= 5 | github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= 6 | github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 7 | github.com/google/gopacket v1.1.14 h1:1+TEhSu8Mh154ZBVjyd1Nt2Bb7cnyOeE3GQyb1WGLqI= 8 | github.com/google/gopacket v1.1.14/go.mod h1:UCLx9mCmAwsVbn6qQl1WIEt2SO7Nd2fD0th1TBAsqBw= 9 | github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig= 10 | github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 11 | github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6 h1:qCv4319q2q7XKn0MQbi8p37hsJ+9Xo8e6yojA73JVxk= 12 | github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6/go.mod h1:fXcdFsQoipQa7mwORhKad5jmDCeSy/RCGzWA08PO0lM= 13 | github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= 14 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 15 | github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 h1:G3dpKMzFDjgEh2q1Z7zUUtKa8ViPtH+ocF0bE0g00O8= 16 | github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= 17 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/base.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "github.com/google/gopacket" 11 | ) 12 | 13 | // BaseLayer is a convenience struct which implements the LayerData and 14 | // LayerPayload functions of the Layer interface. 15 | type BaseLayer struct { 16 | // Contents is the set of bytes that make up this layer. IE: for an 17 | // Ethernet packet, this would be the set of bytes making up the 18 | // Ethernet frame. 19 | Contents []byte 20 | // Payload is the set of bytes contained by (but not part of) this 21 | // Layer. Again, to take Ethernet as an example, this would be the 22 | // set of bytes encapsulated by the Ethernet protocol. 23 | Payload []byte 24 | } 25 | 26 | // LayerContents returns the bytes of the packet layer. 27 | func (b *BaseLayer) LayerContents() []byte { return b.Contents } 28 | 29 | // LayerPayload returns the bytes contained within the packet layer. 30 | func (b *BaseLayer) LayerPayload() []byte { return b.Payload } 31 | 32 | type layerDecodingLayer interface { 33 | gopacket.Layer 34 | DecodeFromBytes([]byte, gopacket.DecodeFeedback) error 35 | NextLayerType() gopacket.LayerType 36 | } 37 | 38 | func decodingLayerDecoder(d layerDecodingLayer, data []byte, p gopacket.PacketBuilder) error { 39 | err := d.DecodeFromBytes(data, p) 40 | if err != nil { 41 | return err 42 | } 43 | p.AddLayer(d) 44 | next := d.NextLayerType() 45 | if next == gopacket.LayerTypeZero { 46 | return nil 47 | } 48 | return p.NextDecoder(next) 49 | } 50 | 51 | // hacky way to zero out memory... there must be a better way? 52 | var lotsOfZeros [1024]byte 53 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/handlers_test.go: -------------------------------------------------------------------------------- 1 | package cleanhttp 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/http/httptest" 7 | "testing" 8 | ) 9 | 10 | func TestPrintablePathCheckHandler(t *testing.T) { 11 | getTestHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 12 | fmt.Fprintln(w, "Hello, client") 13 | }) 14 | 15 | cases := map[string]struct { 16 | path string 17 | expectCode int 18 | input *HandlerInput 19 | }{ 20 | "valid nil input": { 21 | path: "/valid", 22 | expectCode: http.StatusOK, 23 | input: nil, 24 | }, 25 | 26 | "valid empty error status": { 27 | path: "/valid", 28 | expectCode: http.StatusOK, 29 | input: &HandlerInput{}, 30 | }, 31 | 32 | "invalid newline": { 33 | path: "/invalid\n", 34 | expectCode: http.StatusBadRequest, 35 | }, 36 | 37 | "invalid carriage return": { 38 | path: "/invalid\r", 39 | expectCode: http.StatusBadRequest, 40 | }, 41 | 42 | "invalid null": { 43 | path: "/invalid\x00", 44 | expectCode: http.StatusBadRequest, 45 | }, 46 | 47 | "invalid alternate status": { 48 | path: "/invalid\n", 49 | expectCode: http.StatusInternalServerError, 50 | input: &HandlerInput{ 51 | ErrStatus: http.StatusInternalServerError, 52 | }, 53 | }, 54 | } 55 | 56 | for name, tc := range cases { 57 | t.Run(name, func(t *testing.T) { 58 | // Create test HTTP server 59 | ts := httptest.NewServer(PrintablePathCheckHandler(getTestHandler, tc.input)) 60 | defer ts.Close() 61 | 62 | res, err := http.Get(ts.URL + tc.path) 63 | if err != nil { 64 | t.Fatal(err) 65 | } 66 | 67 | if tc.expectCode != res.StatusCode { 68 | t.Fatalf("expected %d, got :%d", tc.expectCode, res.StatusCode) 69 | } 70 | }) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/eapol.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "github.com/google/gopacket" 12 | ) 13 | 14 | // EAPOL defines an EAP over LAN (802.1x) layer. 15 | type EAPOL struct { 16 | BaseLayer 17 | Version uint8 18 | Type EAPOLType 19 | Length uint16 20 | } 21 | 22 | // LayerType returns LayerTypeEAPOL. 23 | func (e *EAPOL) LayerType() gopacket.LayerType { return LayerTypeEAPOL } 24 | 25 | // DecodeFromBytes decodes the given bytes into this layer. 26 | func (e *EAPOL) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 27 | e.Version = data[0] 28 | e.Type = EAPOLType(data[1]) 29 | e.Length = binary.BigEndian.Uint16(data[2:4]) 30 | e.BaseLayer = BaseLayer{data[:4], data[4:]} 31 | return nil 32 | } 33 | 34 | // SerializeTo writes the serialized form of this layer into the 35 | // SerializationBuffer, implementing gopacket.SerializableLayer 36 | func (e *EAPOL) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 37 | bytes, _ := b.PrependBytes(4) 38 | bytes[0] = e.Version 39 | bytes[1] = byte(e.Type) 40 | binary.BigEndian.PutUint16(bytes[2:], e.Length) 41 | return nil 42 | } 43 | 44 | // CanDecode returns the set of layer types that this DecodingLayer can decode. 45 | func (e *EAPOL) CanDecode() gopacket.LayerClass { 46 | return LayerTypeEAPOL 47 | } 48 | 49 | // NextLayerType returns the layer type contained by this DecodingLayer. 50 | func (e *EAPOL) NextLayerType() gopacket.LayerType { 51 | return e.Type.LayerType() 52 | } 53 | 54 | func decodeEAPOL(data []byte, p gopacket.PacketBuilder) error { 55 | e := &EAPOL{} 56 | return decodingLayerDecoder(e, data, p) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/packet_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package gopacket 8 | 9 | import ( 10 | "io" 11 | "reflect" 12 | "testing" 13 | ) 14 | 15 | type embedded struct { 16 | A, B int 17 | } 18 | 19 | type embedding struct { 20 | embedded 21 | C, D int 22 | } 23 | 24 | func TestDumpEmbedded(t *testing.T) { 25 | e := embedding{embedded: embedded{A: 1, B: 2}, C: 3, D: 4} 26 | if got, want := layerString(reflect.ValueOf(e), false, false), "{A=1 B=2 C=3 D=4}"; got != want { 27 | t.Errorf("embedded dump mismatch:\n got: %v\n want: %v", got, want) 28 | } 29 | } 30 | 31 | type singlePacketSource [1][]byte 32 | 33 | func (s *singlePacketSource) ReadPacketData() ([]byte, CaptureInfo, error) { 34 | if (*s)[0] == nil { 35 | return nil, CaptureInfo{}, io.EOF 36 | } 37 | out := (*s)[0] 38 | (*s)[0] = nil 39 | return out, CaptureInfo{}, nil 40 | } 41 | 42 | func TestConcatPacketSources(t *testing.T) { 43 | sourceA := &singlePacketSource{[]byte{1}} 44 | sourceB := &singlePacketSource{[]byte{2}} 45 | sourceC := &singlePacketSource{[]byte{3}} 46 | concat := ConcatFinitePacketDataSources(sourceA, sourceB, sourceC) 47 | a, _, err := concat.ReadPacketData() 48 | if err != nil || len(a) != 1 || a[0] != 1 { 49 | t.Errorf("expected [1], got %v/%v", a, err) 50 | } 51 | b, _, err := concat.ReadPacketData() 52 | if err != nil || len(b) != 1 || b[0] != 2 { 53 | t.Errorf("expected [2], got %v/%v", b, err) 54 | } 55 | c, _, err := concat.ReadPacketData() 56 | if err != nil || len(c) != 1 || c[0] != 3 { 57 | t.Errorf("expected [3], got %v/%v", c, err) 58 | } 59 | if _, _, err := concat.ReadPacketData(); err != io.EOF { 60 | t.Errorf("expected io.EOF, got %v", err) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/circonus-labs/circonus-gometrics" 6 | packages = [ 7 | ".", 8 | "api", 9 | "api/config", 10 | "checkmgr" 11 | ] 12 | revision = "dd698dc110872f6e554abf74a7740fc363354086" 13 | version = "v2.2.1" 14 | 15 | [[projects]] 16 | branch = "master" 17 | name = "github.com/circonus-labs/circonusllhist" 18 | packages = ["."] 19 | revision = "5eb751da55c6d3091faf3861ec5062ae91fee9d0" 20 | 21 | [[projects]] 22 | branch = "master" 23 | name = "github.com/golang/snappy" 24 | packages = ["."] 25 | revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a" 26 | 27 | [[projects]] 28 | name = "github.com/google/gopacket" 29 | packages = [ 30 | ".", 31 | "layers", 32 | "pcap", 33 | "tcpassembly", 34 | "tcpassembly/tcpreader" 35 | ] 36 | revision = "11c65f1ca9081dfea43b4f9643f5c155583b73ba" 37 | version = "v1.1.14" 38 | 39 | [[projects]] 40 | name = "github.com/hashicorp/go-cleanhttp" 41 | packages = ["."] 42 | revision = "e8ab9daed8d1ddd2d3c4efba338fe2eeae2e4f18" 43 | version = "v0.5.0" 44 | 45 | [[projects]] 46 | branch = "master" 47 | name = "github.com/hashicorp/go-retryablehttp" 48 | packages = ["."] 49 | revision = "e651d75abec6fbd4f2c09508f72ae7af8a8b7171" 50 | 51 | [[projects]] 52 | name = "github.com/pkg/errors" 53 | packages = ["."] 54 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d" 55 | version = "v0.8.0" 56 | 57 | [[projects]] 58 | branch = "master" 59 | name = "github.com/tv42/httpunix" 60 | packages = ["."] 61 | revision = "b75d8614f926c077e48d85f1f8f7885b758c6225" 62 | 63 | [solve-meta] 64 | analyzer-name = "dep" 65 | analyzer-version = 1 66 | inputs-digest = "f203c239dcd3954fd4c93b3d7e0fb373ed2fcf48204608823f8a7d3e004ffe30" 67 | solver-name = "gps-cdcl" 68 | solver-version = 1 69 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/examples/pfdump/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // The pfdump binary implements a tcpdump-like command line tool with gopacket 8 | // using pfring as a backend data collection mechanism. 9 | package main 10 | 11 | import ( 12 | "flag" 13 | "fmt" 14 | "github.com/google/gopacket/dumpcommand" 15 | "github.com/google/gopacket/examples/util" 16 | "github.com/google/gopacket/pfring" 17 | "log" 18 | "os" 19 | "strings" 20 | ) 21 | 22 | var iface = flag.String("i", "eth0", "Interface to read packets from") 23 | var snaplen = flag.Int("s", 65536, "Snap length (number of bytes max to read per packet") 24 | var cluster = flag.Int("cluster", -1, "If >= 0, sets the pfring cluster to this value") 25 | var clustertype = flag.Int("clustertype", int(pfring.ClusterPerFlow), "Cluster type") 26 | 27 | func main() { 28 | defer util.Run()() 29 | var ring *pfring.Ring 30 | var err error 31 | if ring, err = pfring.NewRing(*iface, uint32(*snaplen), pfring.FlagPromisc); err != nil { 32 | log.Fatalln("pfring ring creation error:", err) 33 | } 34 | if len(flag.Args()) > 0 { 35 | bpffilter := strings.Join(flag.Args(), " ") 36 | fmt.Fprintf(os.Stderr, "Using BPF filter %q\n", bpffilter) 37 | if err = ring.SetBPFFilter(bpffilter); err != nil { 38 | log.Fatalln("BPF filter error:", err) 39 | } 40 | } 41 | if *cluster >= 0 { 42 | if err = ring.SetCluster(*cluster, pfring.ClusterType(*clustertype)); err != nil { 43 | log.Fatalln("pfring SetCluster error:", err) 44 | } 45 | } 46 | if err = ring.SetSocketMode(pfring.ReadOnly); err != nil { 47 | log.Fatalln("pfring SetSocketMode error:", err) 48 | } else if err = ring.Enable(); err != nil { 49 | log.Fatalln("pfring Enable error:", err) 50 | } 51 | dumpcommand.Run(ring) 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/pppoe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "github.com/google/gopacket" 12 | ) 13 | 14 | // PPPoE is the layer for PPPoE encapsulation headers. 15 | type PPPoE struct { 16 | BaseLayer 17 | Version uint8 18 | Type uint8 19 | Code PPPoECode 20 | SessionId uint16 21 | Length uint16 22 | } 23 | 24 | // LayerType returns gopacket.LayerTypePPPoE. 25 | func (p *PPPoE) LayerType() gopacket.LayerType { 26 | return LayerTypePPPoE 27 | } 28 | 29 | // decodePPPoE decodes the PPPoE header (see http://tools.ietf.org/html/rfc2516). 30 | func decodePPPoE(data []byte, p gopacket.PacketBuilder) error { 31 | pppoe := &PPPoE{ 32 | Version: data[0] >> 4, 33 | Type: data[0] & 0x0F, 34 | Code: PPPoECode(data[1]), 35 | SessionId: binary.BigEndian.Uint16(data[2:4]), 36 | Length: binary.BigEndian.Uint16(data[4:6]), 37 | } 38 | pppoe.BaseLayer = BaseLayer{data[:6], data[6 : 6+pppoe.Length]} 39 | p.AddLayer(pppoe) 40 | return p.NextDecoder(pppoe.Code) 41 | } 42 | 43 | // SerializeTo writes the serialized form of this layer into the 44 | // SerializationBuffer, implementing gopacket.SerializableLayer. 45 | // See the docs for gopacket.SerializableLayer for more info. 46 | func (p *PPPoE) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 47 | payload := b.Bytes() 48 | bytes, err := b.PrependBytes(6) 49 | if err != nil { 50 | return err 51 | } 52 | bytes[0] = (p.Version << 4) | p.Type 53 | bytes[1] = byte(p.Code) 54 | binary.BigEndian.PutUint16(bytes[2:], p.SessionId) 55 | if opts.FixLengths { 56 | p.Length = uint16(len(payload)) 57 | } 58 | binary.BigEndian.PutUint16(bytes[4:], p.Length) 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcap/pcap_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style license 5 | // that can be found in the LICENSE file in the root of the source 6 | // tree. 7 | // 8 | // +build !windows 9 | 10 | package pcap 11 | 12 | /* 13 | #include 14 | #include 15 | 16 | // pcap_wait returns when the next packet is available or the timeout expires. 17 | // Since it uses pcap_get_selectable_fd, it will not work in Windows. 18 | int pcap_wait(pcap_t *p, int usec) { 19 | fd_set fds; 20 | int fd; 21 | struct timeval tv; 22 | 23 | fd = pcap_get_selectable_fd(p); 24 | if(fd < 0) { 25 | return fd; 26 | } 27 | 28 | FD_ZERO(&fds); 29 | FD_SET(fd, &fds); 30 | 31 | tv.tv_sec = 0; 32 | tv.tv_usec = usec; 33 | 34 | if(usec != 0) { 35 | return select(fd+1, &fds, NULL, NULL, &tv); 36 | } 37 | 38 | // block indefinitely if no timeout provided 39 | return select(fd+1, &fds, NULL, NULL, NULL); 40 | } 41 | */ 42 | import "C" 43 | 44 | import ( 45 | "errors" 46 | "unsafe" 47 | ) 48 | 49 | func (p *Handle) openLive() error { 50 | buf := (*C.char)(C.calloc(errorBufferSize, 1)) 51 | defer C.free(unsafe.Pointer(buf)) 52 | 53 | // Change the device to non-blocking, we'll use pcap_wait to wait until the 54 | // handle is ready to read. 55 | if v := C.pcap_setnonblock(p.cptr, 1, buf); v == -1 { 56 | return errors.New(C.GoString(buf)) 57 | } 58 | 59 | return nil 60 | } 61 | 62 | // waitForPacket waits for a packet or for the timeout to expire. 63 | func (p *Handle) waitForPacket() { 64 | // need to wait less than the read timeout according to pcap documentation. 65 | // timeoutMillis rounds up to at least one millisecond so we can safely 66 | // subtract up to a millisecond. 67 | usec := timeoutMillis(p.timeout) * 1000 68 | usec -= 100 69 | 70 | C.pcap_wait(p.cptr, usec) 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/tv42/httpunix/httpunix_test.go: -------------------------------------------------------------------------------- 1 | package httpunix_test 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net" 7 | "net/http" 8 | "net/http/httputil" 9 | "time" 10 | 11 | "github.com/tv42/httpunix" 12 | ) 13 | 14 | func Example_clientStandalone() { 15 | // This example shows using a customized http.Client. 16 | u := &httpunix.Transport{ 17 | DialTimeout: 100 * time.Millisecond, 18 | RequestTimeout: 1 * time.Second, 19 | ResponseHeaderTimeout: 1 * time.Second, 20 | } 21 | u.RegisterLocation("myservice", "/path/to/socket") 22 | 23 | var client = http.Client{ 24 | Transport: u, 25 | } 26 | 27 | resp, err := client.Get("http+unix://myservice/urlpath/as/seen/by/server") 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | buf, err := httputil.DumpResponse(resp, true) 32 | if err != nil { 33 | log.Fatal(err) 34 | } 35 | fmt.Printf("%s", buf) 36 | resp.Body.Close() 37 | } 38 | 39 | func Example_clientIntegrated() { 40 | // This example shows handling all net/http requests for the 41 | // http+unix URL scheme. 42 | u := &httpunix.Transport{ 43 | DialTimeout: 100 * time.Millisecond, 44 | RequestTimeout: 1 * time.Second, 45 | ResponseHeaderTimeout: 1 * time.Second, 46 | } 47 | u.RegisterLocation("myservice", "/path/to/socket") 48 | 49 | // If you want to use http: with the same client: 50 | t := &http.Transport{} 51 | t.RegisterProtocol(httpunix.Scheme, u) 52 | var client = http.Client{ 53 | Transport: t, 54 | } 55 | 56 | resp, err := client.Get("http+unix://myservice/urlpath/as/seen/by/server") 57 | if err != nil { 58 | log.Fatal(err) 59 | } 60 | buf, err := httputil.DumpResponse(resp, true) 61 | if err != nil { 62 | log.Fatal(err) 63 | } 64 | fmt.Printf("%s", buf) 65 | resp.Body.Close() 66 | } 67 | 68 | func Example_server() { 69 | l, err := net.Listen("unix", "/path/to/socket") 70 | if err != nil { 71 | log.Fatal(err) 72 | } 73 | defer l.Close() 74 | 75 | if err := http.Serve(l, nil); err != nil { 76 | log.Fatal(err) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcapgo/write_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package pcapgo 8 | 9 | import ( 10 | "bytes" 11 | "github.com/google/gopacket" 12 | "testing" 13 | "time" 14 | ) 15 | 16 | func TestWriteHeader(t *testing.T) { 17 | var buf bytes.Buffer 18 | w := NewWriter(&buf) 19 | w.WriteFileHeader(0x1234, 0x56) 20 | want := []byte{ 21 | 0xd4, 0xc3, 0xb2, 0xa1, 0x02, 0x00, 0x04, 0x00, 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 23 | 0x34, 0x12, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 24 | } 25 | if got := buf.Bytes(); !bytes.Equal(got, want) { 26 | t.Errorf("buf mismatch:\nwant: %+v\ngot: %+v", want, got) 27 | } 28 | } 29 | 30 | func TestWritePacket(t *testing.T) { 31 | ci := gopacket.CaptureInfo{ 32 | Timestamp: time.Unix(0x01020304, 0xAA*1000), 33 | Length: 0xABCD, 34 | CaptureLength: 10, 35 | } 36 | data := []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0} 37 | var buf bytes.Buffer 38 | w := NewWriter(&buf) 39 | w.WritePacket(ci, data) 40 | want := []byte{ 41 | 0x04, 0x03, 0x02, 0x01, 0xAA, 0x00, 0x00, 0x00, 42 | 0x0A, 0x00, 0x00, 0x00, 0xCD, 0xAB, 0x00, 0x00, 43 | 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 44 | } 45 | if got := buf.Bytes(); !bytes.Equal(got, want) { 46 | t.Errorf("buf mismatch:\nwant: %+v\ngot: %+v", want, got) 47 | } 48 | } 49 | 50 | func TestCaptureInfoErrors(t *testing.T) { 51 | data := []byte{1, 2, 3, 4} 52 | ts := time.Unix(0, 0) 53 | for _, test := range []gopacket.CaptureInfo{ 54 | gopacket.CaptureInfo{ 55 | Timestamp: ts, 56 | Length: 5, 57 | CaptureLength: 5, 58 | }, 59 | gopacket.CaptureInfo{ 60 | Timestamp: ts, 61 | Length: 3, 62 | CaptureLength: 4, 63 | }, 64 | } { 65 | var buf bytes.Buffer 66 | w := NewWriter(&buf) 67 | if err := w.WritePacket(test, data); err == nil { 68 | t.Errorf("CaptureInfo %+v should have error", test) 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go: -------------------------------------------------------------------------------- 1 | package cleanhttp 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "runtime" 7 | "time" 8 | ) 9 | 10 | // DefaultTransport returns a new http.Transport with similar default values to 11 | // http.DefaultTransport, but with idle connections and keepalives disabled. 12 | func DefaultTransport() *http.Transport { 13 | transport := DefaultPooledTransport() 14 | transport.DisableKeepAlives = true 15 | transport.MaxIdleConnsPerHost = -1 16 | return transport 17 | } 18 | 19 | // DefaultPooledTransport returns a new http.Transport with similar default 20 | // values to http.DefaultTransport. Do not use this for transient transports as 21 | // it can leak file descriptors over time. Only use this for transports that 22 | // will be re-used for the same host(s). 23 | func DefaultPooledTransport() *http.Transport { 24 | transport := &http.Transport{ 25 | Proxy: http.ProxyFromEnvironment, 26 | DialContext: (&net.Dialer{ 27 | Timeout: 30 * time.Second, 28 | KeepAlive: 30 * time.Second, 29 | DualStack: true, 30 | }).DialContext, 31 | MaxIdleConns: 100, 32 | IdleConnTimeout: 90 * time.Second, 33 | TLSHandshakeTimeout: 10 * time.Second, 34 | ExpectContinueTimeout: 1 * time.Second, 35 | MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1, 36 | } 37 | return transport 38 | } 39 | 40 | // DefaultClient returns a new http.Client with similar default values to 41 | // http.Client, but with a non-shared Transport, idle connections disabled, and 42 | // keepalives disabled. 43 | func DefaultClient() *http.Client { 44 | return &http.Client{ 45 | Transport: DefaultTransport(), 46 | } 47 | } 48 | 49 | // DefaultPooledClient returns a new http.Client with similar default values to 50 | // http.Client, but with a shared Transport. Do not use this function for 51 | // transient clients as it can leak file descriptors over time. Only use this 52 | // for clients that will be re-used for the same host(s). 53 | func DefaultPooledClient() *http.Client { 54 | return &http.Client{ 55 | Transport: DefaultPooledTransport(), 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-retryablehttp/README.md: -------------------------------------------------------------------------------- 1 | go-retryablehttp 2 | ================ 3 | 4 | [![Build Status](http://img.shields.io/travis/hashicorp/go-retryablehttp.svg?style=flat-square)][travis] 5 | [![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] 6 | 7 | [travis]: http://travis-ci.org/hashicorp/go-retryablehttp 8 | [godocs]: http://godoc.org/github.com/hashicorp/go-retryablehttp 9 | 10 | The `retryablehttp` package provides a familiar HTTP client interface with 11 | automatic retries and exponential backoff. It is a thin wrapper over the 12 | standard `net/http` client library and exposes nearly the same public API. This 13 | makes `retryablehttp` very easy to drop into existing programs. 14 | 15 | `retryablehttp` performs automatic retries under certain conditions. Mainly, if 16 | an error is returned by the client (connection errors, etc.), or if a 500-range 17 | response code is received (except 501), then a retry is invoked after a wait 18 | period. Otherwise, the response is returned and left to the caller to 19 | interpret. 20 | 21 | The main difference from `net/http` is that requests which take a request body 22 | (POST/PUT et. al) can have the body provided in a number of ways (some more or 23 | less efficient) that allow "rewinding" the request body if the initial request 24 | fails so that the full request can be attempted again. See the 25 | [godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp) for more 26 | details. 27 | 28 | Example Use 29 | =========== 30 | 31 | Using this library should look almost identical to what you would do with 32 | `net/http`. The most simple example of a GET request is shown below: 33 | 34 | ```go 35 | resp, err := retryablehttp.Get("/foo") 36 | if err != nil { 37 | panic(err) 38 | } 39 | ``` 40 | 41 | The returned response object is an `*http.Response`, the same thing you would 42 | usually get from `net/http`. Had the request failed one or more times, the above 43 | call would block and retry with exponential backoff. 44 | 45 | For more usage and examples see the 46 | [godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp). 47 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/writer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package gopacket 8 | 9 | import ( 10 | "fmt" 11 | "testing" 12 | ) 13 | 14 | func TestExponentialSizeIncreasePrepend(t *testing.T) { 15 | var b serializeBuffer 16 | for i, test := range []struct { 17 | prepend, size int 18 | }{ 19 | {2, 2}, 20 | {2, 4}, 21 | {2, 8}, 22 | {2, 8}, 23 | {2, 16}, 24 | {2, 16}, 25 | {2, 16}, 26 | {2, 16}, 27 | {2, 32}, 28 | } { 29 | b.PrependBytes(test.prepend) 30 | if test.size != cap(b.data) { 31 | t.Error(i, "size want", test.size, "got", cap(b.data)) 32 | } 33 | } 34 | b.Clear() 35 | if b.start != 32 { 36 | t.Error(b.start) 37 | } 38 | } 39 | 40 | func TestExponentialSizeIncreaseAppend(t *testing.T) { 41 | var b serializeBuffer 42 | for i, test := range []struct { 43 | appnd, size int 44 | }{ 45 | {2, 2}, 46 | {2, 4}, 47 | {2, 8}, 48 | {2, 8}, 49 | {2, 16}, 50 | {2, 16}, 51 | {2, 16}, 52 | {2, 16}, 53 | {2, 32}, 54 | } { 55 | b.AppendBytes(test.appnd) 56 | if test.size != cap(b.data) { 57 | t.Error(i, "size want", test.size, "got", cap(b.data)) 58 | } 59 | } 60 | b.Clear() 61 | if b.start != 0 { 62 | t.Error(b.start) 63 | } 64 | } 65 | 66 | func ExampleSerializeBuffer() { 67 | b := NewSerializeBuffer() 68 | fmt.Println("1:", b.Bytes()) 69 | bytes, _ := b.PrependBytes(3) 70 | copy(bytes, []byte{1, 2, 3}) 71 | fmt.Println("2:", b.Bytes()) 72 | bytes, _ = b.AppendBytes(2) 73 | copy(bytes, []byte{4, 5}) 74 | fmt.Println("3:", b.Bytes()) 75 | bytes, _ = b.PrependBytes(1) 76 | copy(bytes, []byte{0}) 77 | fmt.Println("4:", b.Bytes()) 78 | bytes, _ = b.AppendBytes(3) 79 | copy(bytes, []byte{6, 7, 8}) 80 | fmt.Println("5:", b.Bytes()) 81 | b.Clear() 82 | fmt.Println("6:", b.Bytes()) 83 | bytes, _ = b.PrependBytes(2) 84 | copy(bytes, []byte{9, 9}) 85 | fmt.Println("7:", b.Bytes()) 86 | // Output: 87 | // 1: [] 88 | // 2: [1 2 3] 89 | // 3: [1 2 3 4 5] 90 | // 4: [0 1 2 3 4 5] 91 | // 5: [0 1 2 3 4 5 6 7 8] 92 | // 6: [] 93 | // 7: [9 9] 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/counter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | import "fmt" 8 | 9 | // A Counter is a monotonically increasing unsigned integer. 10 | // 11 | // Use a counter to derive rates (e.g., record total number of requests, derive 12 | // requests per second). 13 | 14 | // Increment counter by 1 15 | func (m *CirconusMetrics) Increment(metric string) { 16 | m.Add(metric, 1) 17 | } 18 | 19 | // IncrementByValue updates counter by supplied value 20 | func (m *CirconusMetrics) IncrementByValue(metric string, val uint64) { 21 | m.Add(metric, val) 22 | } 23 | 24 | // Set a counter to specific value 25 | func (m *CirconusMetrics) Set(metric string, val uint64) { 26 | m.cm.Lock() 27 | defer m.cm.Unlock() 28 | m.counters[metric] = val 29 | } 30 | 31 | // Add updates counter by supplied value 32 | func (m *CirconusMetrics) Add(metric string, val uint64) { 33 | m.cm.Lock() 34 | defer m.cm.Unlock() 35 | m.counters[metric] += val 36 | } 37 | 38 | // RemoveCounter removes the named counter 39 | func (m *CirconusMetrics) RemoveCounter(metric string) { 40 | m.cm.Lock() 41 | defer m.cm.Unlock() 42 | delete(m.counters, metric) 43 | } 44 | 45 | // GetCounterTest returns the current value for a counter. (note: it is a function specifically for "testing", disable automatic submission during testing.) 46 | func (m *CirconusMetrics) GetCounterTest(metric string) (uint64, error) { 47 | m.cm.Lock() 48 | defer m.cm.Unlock() 49 | 50 | if val, ok := m.counters[metric]; ok { 51 | return val, nil 52 | } 53 | 54 | return 0, fmt.Errorf("Counter metric '%s' not found", metric) 55 | 56 | } 57 | 58 | // SetCounterFunc set counter to a function [called at flush interval] 59 | func (m *CirconusMetrics) SetCounterFunc(metric string, fn func() uint64) { 60 | m.cfm.Lock() 61 | defer m.cfm.Unlock() 62 | m.counterFuncs[metric] = fn 63 | } 64 | 65 | // RemoveCounterFunc removes the named counter function 66 | func (m *CirconusMetrics) RemoveCounterFunc(metric string) { 67 | m.cfm.Lock() 68 | defer m.cfm.Unlock() 69 | delete(m.counterFuncs, metric) 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/misc/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This is a C version of the cmd/snappytool Go program. 3 | 4 | To build the snappytool binary: 5 | g++ main.cpp /usr/lib/libsnappy.a -o snappytool 6 | or, if you have built the C++ snappy library from source: 7 | g++ main.cpp /path/to/your/snappy/.libs/libsnappy.a -o snappytool 8 | after running "make" from your snappy checkout directory. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "snappy.h" 17 | 18 | #define N 1000000 19 | 20 | char dst[N]; 21 | char src[N]; 22 | 23 | int main(int argc, char** argv) { 24 | // Parse args. 25 | if (argc != 2) { 26 | fprintf(stderr, "exactly one of -d or -e must be given\n"); 27 | return 1; 28 | } 29 | bool decode = strcmp(argv[1], "-d") == 0; 30 | bool encode = strcmp(argv[1], "-e") == 0; 31 | if (decode == encode) { 32 | fprintf(stderr, "exactly one of -d or -e must be given\n"); 33 | return 1; 34 | } 35 | 36 | // Read all of stdin into src[:s]. 37 | size_t s = 0; 38 | while (1) { 39 | if (s == N) { 40 | fprintf(stderr, "input too large\n"); 41 | return 1; 42 | } 43 | ssize_t n = read(0, src+s, N-s); 44 | if (n == 0) { 45 | break; 46 | } 47 | if (n < 0) { 48 | fprintf(stderr, "read error: %s\n", strerror(errno)); 49 | // TODO: handle EAGAIN, EINTR? 50 | return 1; 51 | } 52 | s += n; 53 | } 54 | 55 | // Encode or decode src[:s] to dst[:d], and write to stdout. 56 | size_t d = 0; 57 | if (encode) { 58 | if (N < snappy::MaxCompressedLength(s)) { 59 | fprintf(stderr, "input too large after encoding\n"); 60 | return 1; 61 | } 62 | snappy::RawCompress(src, s, dst, &d); 63 | } else { 64 | if (!snappy::GetUncompressedLength(src, s, &d)) { 65 | fprintf(stderr, "could not get uncompressed length\n"); 66 | return 1; 67 | } 68 | if (N < d) { 69 | fprintf(stderr, "input too large after decoding\n"); 70 | return 1; 71 | } 72 | if (!snappy::RawUncompress(src, s, dst)) { 73 | fprintf(stderr, "input was not valid Snappy-compressed data\n"); 74 | return 1; 75 | } 76 | } 77 | write(1, dst, d); 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/checkmgr/cert_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package checkmgr 6 | 7 | import ( 8 | "encoding/json" 9 | "fmt" 10 | "net/http" 11 | "net/http/httptest" 12 | "testing" 13 | 14 | "github.com/circonus-labs/circonus-gometrics/api" 15 | ) 16 | 17 | var ( 18 | apiCert = CACert{ 19 | Contents: string(circonusCA), 20 | } 21 | ) 22 | 23 | func testCertServer() *httptest.Server { 24 | f := func(w http.ResponseWriter, r *http.Request) { 25 | switch r.URL.Path { 26 | case "/pki/ca.crt": 27 | ret, err := json.Marshal(apiCert) 28 | if err != nil { 29 | panic(err) 30 | } 31 | w.WriteHeader(200) 32 | w.Header().Set("Content-Type", "application/json") 33 | fmt.Fprintln(w, string(ret)) 34 | default: 35 | w.WriteHeader(500) 36 | fmt.Fprintln(w, "unsupported") 37 | } 38 | } 39 | 40 | return httptest.NewServer(http.HandlerFunc(f)) 41 | } 42 | 43 | func TestLoadCACert(t *testing.T) { 44 | t.Log("default cert, no fetch") 45 | 46 | cm := &CheckManager{ 47 | enabled: false, 48 | } 49 | 50 | cm.loadCACert() 51 | 52 | if cm.certPool == nil { 53 | t.Errorf("Expected cert pool to be initialized, still nil.") 54 | } 55 | 56 | subjs := cm.certPool.Subjects() 57 | if len(subjs) == 0 { 58 | t.Errorf("Expected > 0 certs in pool") 59 | } 60 | } 61 | 62 | func TestFetchCert(t *testing.T) { 63 | server := testCertServer() 64 | defer server.Close() 65 | 66 | cm := &CheckManager{ 67 | enabled: true, 68 | } 69 | ac := &api.Config{ 70 | TokenApp: "abcd", 71 | TokenKey: "1234", 72 | URL: server.URL, 73 | } 74 | apih, err := api.NewAPI(ac) 75 | if err != nil { 76 | t.Errorf("Expected no error, got '%v'", err) 77 | } 78 | cm.apih = apih 79 | 80 | _, err = cm.fetchCert() 81 | if err != nil { 82 | t.Fatalf("Expected no error, got %v", err) 83 | } 84 | 85 | t.Log("load cert w/fetch") 86 | 87 | cm.loadCACert() 88 | 89 | if cm.certPool == nil { 90 | t.Errorf("Expected cert pool to be initialized, still nil.") 91 | } 92 | 93 | subjs := cm.certPool.Subjects() 94 | if len(subjs) == 0 { 95 | t.Errorf("Expected > 0 certs in pool") 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/ipsec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "github.com/google/gopacket" 12 | ) 13 | 14 | // IPSecAH is the authentication header for IPv4/6 defined in 15 | // http://tools.ietf.org/html/rfc2402 16 | type IPSecAH struct { 17 | // While the auth header can be used for both IPv4 and v6, its format is that of 18 | // an IPv6 extension (NextHeader, PayloadLength, etc...), so we use ipv6ExtensionBase 19 | // to build it. 20 | ipv6ExtensionBase 21 | Reserved uint16 22 | SPI, Seq uint32 23 | AuthenticationData []byte 24 | } 25 | 26 | // LayerType returns LayerTypeIPSecAH. 27 | func (i *IPSecAH) LayerType() gopacket.LayerType { return LayerTypeIPSecAH } 28 | 29 | func decodeIPSecAH(data []byte, p gopacket.PacketBuilder) error { 30 | i := &IPSecAH{ 31 | ipv6ExtensionBase: ipv6ExtensionBase{ 32 | NextHeader: IPProtocol(data[0]), 33 | HeaderLength: data[1], 34 | }, 35 | Reserved: binary.BigEndian.Uint16(data[2:4]), 36 | SPI: binary.BigEndian.Uint32(data[4:8]), 37 | Seq: binary.BigEndian.Uint32(data[8:12]), 38 | } 39 | i.ActualLength = (int(i.HeaderLength) + 2) * 4 40 | i.AuthenticationData = data[12:i.ActualLength] 41 | i.Contents = data[:i.ActualLength] 42 | i.Payload = data[i.ActualLength:] 43 | p.AddLayer(i) 44 | return p.NextDecoder(i.NextHeader) 45 | } 46 | 47 | // IPSecESP is the encapsulating security payload defined in 48 | // http://tools.ietf.org/html/rfc2406 49 | type IPSecESP struct { 50 | BaseLayer 51 | SPI, Seq uint32 52 | // Encrypted contains the encrypted set of bytes sent in an ESP 53 | Encrypted []byte 54 | } 55 | 56 | // LayerType returns LayerTypeIPSecESP. 57 | func (i *IPSecESP) LayerType() gopacket.LayerType { return LayerTypeIPSecESP } 58 | 59 | func decodeIPSecESP(data []byte, p gopacket.PacketBuilder) error { 60 | i := &IPSecESP{ 61 | BaseLayer: BaseLayer{data, nil}, 62 | SPI: binary.BigEndian.Uint32(data[:4]), 63 | Seq: binary.BigEndian.Uint32(data[4:8]), 64 | Encrypted: data[8:], 65 | } 66 | p.AddLayer(i) 67 | return nil 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/submit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | import ( 8 | "encoding/json" 9 | "fmt" 10 | "net/http" 11 | "net/http/httptest" 12 | "testing" 13 | "time" 14 | 15 | "github.com/circonus-labs/circonus-gometrics/api" 16 | ) 17 | 18 | func fakeBroker() *httptest.Server { 19 | handler := func(w http.ResponseWriter, r *http.Request) { 20 | w.WriteHeader(200) 21 | w.Header().Set("Content-Type", "application/json") 22 | fmt.Fprintln(w, `{"stats":1}`) 23 | } 24 | 25 | return httptest.NewServer(http.HandlerFunc(handler)) 26 | } 27 | 28 | func TestSubmit(t *testing.T) { 29 | t.Log("Testing submit.submit") 30 | 31 | server := fakeBroker() 32 | defer server.Close() 33 | 34 | cfg := &Config{} 35 | cfg.CheckManager.Check.SubmissionURL = server.URL 36 | 37 | cm, err := NewCirconusMetrics(cfg) 38 | if err != nil { 39 | t.Errorf("Expected no error, got '%v'", err) 40 | } 41 | 42 | newMetrics := make(map[string]*api.CheckBundleMetric) 43 | output := Metrics{"foo": Metric{Type: "n", Value: 1}} 44 | // output["foo"] = map[string]interface{}{ 45 | // "_type": "n", 46 | // "_value": 1, 47 | // } 48 | cm.submit(output, newMetrics) 49 | } 50 | 51 | func TestTrapCall(t *testing.T) { 52 | t.Log("Testing submit.trapCall") 53 | 54 | server := fakeBroker() 55 | defer server.Close() 56 | 57 | cfg := &Config{} 58 | cfg.CheckManager.Check.SubmissionURL = server.URL 59 | 60 | cm, err := NewCirconusMetrics(cfg) 61 | if err != nil { 62 | t.Errorf("Expected no error, got '%v'", err) 63 | } 64 | 65 | for !cm.check.IsReady() { 66 | t.Log("\twaiting for cm to init") 67 | time.Sleep(1 * time.Second) 68 | } 69 | 70 | output := make(map[string]interface{}) 71 | output["foo"] = map[string]interface{}{ 72 | "_type": "n", 73 | "_value": 1, 74 | } 75 | 76 | str, err := json.Marshal(output) 77 | if err != nil { 78 | t.Errorf("Expected no error, got '%v'", err) 79 | } 80 | 81 | numStats, err := cm.trapCall(str) 82 | if err != nil { 83 | t.Errorf("Expected no error, got '%v'", err) 84 | } 85 | 86 | if numStats != 1 { 87 | t.Errorf("Expected 1, got %d", numStats) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pfring/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | /*Package pfring wraps the PF_RING C library for Go. 8 | 9 | PF_RING is a high-performance packet capture library written by ntop.org (see 10 | http://www.ntop.org/products/pf_ring/). This library allows you to utilize the 11 | PF_RING library with gopacket to read packet data and decode it. 12 | 13 | This package is meant to be used with its parent, 14 | http://github.com/google/gopacket, although it can also be used independently 15 | if you just want to get packet data from the wire. 16 | 17 | Simple Example 18 | 19 | This is probably the simplest code you can use to start getting packets through 20 | pfring: 21 | 22 | if ring, err := pfring.NewRing("eth0", 65536, pfring.FlagPromisc); err != nil { 23 | panic(err) 24 | } else if err := ring.SetBPFFilter("tcp and port 80"); err != nil { // optional 25 | panic(err) 26 | } else if err := ring.Enable(); err != nil { // Must do this!, or you get no packets! 27 | panic(err) 28 | } else { 29 | packetSource := gopacket.NewPacketSource(ring, layers.LinkTypeEthernet) 30 | for packet := range packetSource.Packets() { 31 | handlePacket(packet) // Do something with a packet here. 32 | } 33 | } 34 | 35 | Pfring Tweaks 36 | 37 | PF_RING has a ton of optimizations and tweaks to make sure you get just the 38 | packets you want. For example, if you're only using pfring to read packets, 39 | consider running: 40 | 41 | ring.SetSocketMode(pfring.ReadOnly) 42 | 43 | If you only care about packets received on your interface (not those transmitted 44 | by the interface), you can run: 45 | 46 | ring.SetDirection(pfring.ReceiveOnly) 47 | 48 | Pfring Clusters 49 | 50 | PF_RING has an idea of 'clusters', where multiple applications can all read from 51 | the same cluster, and PF_RING will multiplex packets over that cluster such that 52 | only one application receives each packet. We won't discuss this mechanism in 53 | too much more detail (see the ntop.org docs for more info), but here's how to 54 | utilize this with the pfring go library: 55 | 56 | ring.SetCluster(1, pfring.ClusterPerFlow5Tuple) 57 | */ 58 | package pfring 59 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/ppp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "errors" 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | // PPP is the layer for PPP encapsulation headers. 16 | type PPP struct { 17 | BaseLayer 18 | PPPType PPPType 19 | } 20 | 21 | // PPPEndpoint is a singleton endpoint for PPP. Since there is no actual 22 | // addressing for the two ends of a PPP connection, we use a singleton value 23 | // named 'point' for each endpoint. 24 | var PPPEndpoint = gopacket.NewEndpoint(EndpointPPP, nil) 25 | 26 | // PPPFlow is a singleton flow for PPP. Since there is no actual addressing for 27 | // the two ends of a PPP connection, we use a singleton value to represent the 28 | // flow for all PPP connections. 29 | var PPPFlow = gopacket.NewFlow(EndpointPPP, nil, nil) 30 | 31 | // LayerType returns LayerTypePPP 32 | func (p *PPP) LayerType() gopacket.LayerType { return LayerTypePPP } 33 | 34 | // LinkFlow returns PPPFlow. 35 | func (p *PPP) LinkFlow() gopacket.Flow { return PPPFlow } 36 | 37 | func decodePPP(data []byte, p gopacket.PacketBuilder) error { 38 | ppp := &PPP{} 39 | if data[0]&0x1 == 0 { 40 | if data[1]&0x1 == 0 { 41 | return errors.New("PPP has invalid type") 42 | } 43 | ppp.PPPType = PPPType(binary.BigEndian.Uint16(data[:2])) 44 | ppp.Contents = data[:2] 45 | ppp.Payload = data[2:] 46 | } else { 47 | ppp.PPPType = PPPType(data[0]) 48 | ppp.Contents = data[:1] 49 | ppp.Payload = data[1:] 50 | } 51 | p.AddLayer(ppp) 52 | p.SetLinkLayer(ppp) 53 | return p.NextDecoder(ppp.PPPType) 54 | } 55 | 56 | // SerializeTo writes the serialized form of this layer into the 57 | // SerializationBuffer, implementing gopacket.SerializableLayer. 58 | // See the docs for gopacket.SerializableLayer for more info. 59 | func (p *PPP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 60 | if p.PPPType&0x100 == 0 { 61 | bytes, err := b.PrependBytes(2) 62 | if err != nil { 63 | return err 64 | } 65 | binary.BigEndian.PutUint16(bytes, uint16(p.PPPType)) 66 | } else { 67 | bytes, err := b.PrependBytes(1) 68 | if err != nil { 69 | return err 70 | } 71 | bytes[0] = uint8(p.PPPType) 72 | } 73 | return nil 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/vrrp_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | package layers 7 | 8 | import ( 9 | "github.com/google/gopacket" 10 | "testing" 11 | ) 12 | 13 | // vrrpPacketPriority100 is the packet: 14 | // 06:12:21.813317 IP 192.168.0.30 > 224.0.0.18: VRRPv2, Advertisement, vrid 1, prio 100, authtype none, intvl 1s, length 20 15 | // 0x0000: 0100 5e00 0012 0000 5e00 0101 0800 45c0 ..^.....^.....E. 16 | // 0x0010: 0028 0000 0000 ff70 19cd c0a8 001e e000 .(.....p........ 17 | // 0x0020: 0012 2101 6401 0001 ba52 c0a8 0001 0000 ..!.d....R...... 18 | // 0x0030: 0000 0000 0000 0000 0000 0000 ............ 19 | var vrrpPacketPriority100 = []byte{ 20 | 0x01, 0x00, 0x5e, 0x00, 0x00, 0x12, 0x00, 0x00, 0x5e, 0x00, 0x01, 0x01, 0x08, 0x00, 0x45, 0xc0, 21 | 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0xff, 0x70, 0x19, 0xcd, 0xc0, 0xa8, 0x00, 0x1e, 0xe0, 0x00, 22 | 0x00, 0x12, 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 24 | } 25 | 26 | func TestVRRPPacketPacket0(t *testing.T) { 27 | p := gopacket.NewPacket(vrrpPacketPriority100, LinkTypeEthernet, gopacket.Default) 28 | if p.ErrorLayer() != nil { 29 | t.Error("Failed to decode packet", p.ErrorLayer().Error()) 30 | } 31 | checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeVRRP}, t) 32 | 33 | // Version=2 Type=VRRPv2 Advertisement VirtualRtrID=1 Priority=100 34 | vrrp := p.Layer(LayerTypeVRRP).(*VRRPv2) 35 | if vrrp.Version != 2 { 36 | t.Fatalf("Unable to decode VRRPv2 version. Received %d, expected %d", vrrp.Version, 2) 37 | } 38 | 39 | if vrrp.Type != 1 { 40 | t.Fatalf("Unable to decode VRRPv2 type. Received %d, expected %d", vrrp.Type, 1) 41 | } 42 | 43 | if vrrp.Priority != 100 { 44 | t.Fatalf("Unable to decode VRRPv2 priority. Received %d, expected %d", vrrp.Priority, 100) 45 | } 46 | 47 | if vrrp.Checksum != 47698 { 48 | t.Fatalf("Unable to decode VRRPv2 checksum. Received %d, expected %d", vrrp.Checksum, 47698) 49 | } 50 | } 51 | func BenchmarkDecodeVRRPPacket0(b *testing.B) { 52 | for i := 0; i < b.N; i++ { 53 | gopacket.NewPacket(vrrpPacketPriority100, LayerTypeEthernet, gopacket.NoCopy) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/README.md: -------------------------------------------------------------------------------- 1 | # errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) 2 | 3 | Package errors provides simple error handling primitives. 4 | 5 | `go get github.com/pkg/errors` 6 | 7 | The traditional error handling idiom in Go is roughly akin to 8 | ```go 9 | if err != nil { 10 | return err 11 | } 12 | ``` 13 | which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error. 14 | 15 | ## Adding context to an error 16 | 17 | The errors.Wrap function returns a new error that adds context to the original error. For example 18 | ```go 19 | _, err := ioutil.ReadAll(r) 20 | if err != nil { 21 | return errors.Wrap(err, "read failed") 22 | } 23 | ``` 24 | ## Retrieving the cause of an error 25 | 26 | Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`. 27 | ```go 28 | type causer interface { 29 | Cause() error 30 | } 31 | ``` 32 | `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example: 33 | ```go 34 | switch err := errors.Cause(err).(type) { 35 | case *MyError: 36 | // handle specifically 37 | default: 38 | // unknown error 39 | } 40 | ``` 41 | 42 | [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). 43 | 44 | ## Contributing 45 | 46 | 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. 47 | 48 | Before proposing a change, please discuss your change by raising an issue. 49 | 50 | ## Licence 51 | 52 | BSD-2-Clause 53 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/pflog.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "errors" 12 | 13 | "github.com/google/gopacket" 14 | ) 15 | 16 | type PFDirection uint8 17 | 18 | const ( 19 | PFDirectionInOut PFDirection = 0 20 | PFDirectionIn PFDirection = 1 21 | PFDirectionOut PFDirection = 2 22 | ) 23 | 24 | // PFLog provides the layer for 'pf' packet-filter logging, as described at 25 | // http://www.freebsd.org/cgi/man.cgi?query=pflog&sektion=4 26 | type PFLog struct { 27 | BaseLayer 28 | Length uint8 29 | Family ProtocolFamily 30 | Action, Reason uint8 31 | IFName, Ruleset []byte 32 | RuleNum, SubruleNum uint32 33 | UID uint32 34 | PID int32 35 | RuleUID uint32 36 | RulePID int32 37 | Direction PFDirection 38 | // The remainder is padding 39 | } 40 | 41 | func (pf *PFLog) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 42 | pf.Length = data[0] 43 | pf.Family = ProtocolFamily(data[1]) 44 | pf.Action = data[2] 45 | pf.Reason = data[3] 46 | pf.IFName = data[4:20] 47 | pf.Ruleset = data[20:36] 48 | pf.RuleNum = binary.BigEndian.Uint32(data[36:40]) 49 | pf.SubruleNum = binary.BigEndian.Uint32(data[40:44]) 50 | pf.UID = binary.BigEndian.Uint32(data[44:48]) 51 | pf.PID = int32(binary.BigEndian.Uint32(data[48:52])) 52 | pf.RuleUID = binary.BigEndian.Uint32(data[52:56]) 53 | pf.RulePID = int32(binary.BigEndian.Uint32(data[56:60])) 54 | pf.Direction = PFDirection(data[60]) 55 | if pf.Length%4 != 1 { 56 | return errors.New("PFLog header length should be 3 less than multiple of 4") 57 | } 58 | actualLength := int(pf.Length) + 3 59 | pf.Contents = data[:actualLength] 60 | pf.Payload = data[actualLength:] 61 | return nil 62 | } 63 | 64 | // LayerType returns layers.LayerTypePFLog 65 | func (pf *PFLog) LayerType() gopacket.LayerType { return LayerTypePFLog } 66 | 67 | func (pf *PFLog) CanDecode() gopacket.LayerClass { return LayerTypePFLog } 68 | 69 | func (pf *PFLog) NextLayerType() gopacket.LayerType { 70 | return pf.Family.LayerType() 71 | } 72 | 73 | func decodePFLog(data []byte, p gopacket.PacketBuilder) error { 74 | pf := &PFLog{} 75 | return decodingLayerDecoder(pf, data, p) 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/dot1q.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style license 5 | // that can be found in the LICENSE file in the root of the source 6 | // tree. 7 | 8 | package layers 9 | 10 | import ( 11 | "encoding/binary" 12 | "fmt" 13 | "github.com/google/gopacket" 14 | ) 15 | 16 | // Dot1Q is the packet layer for 802.1Q VLAN headers. 17 | type Dot1Q struct { 18 | BaseLayer 19 | Priority uint8 20 | DropEligible bool 21 | VLANIdentifier uint16 22 | Type EthernetType 23 | } 24 | 25 | // LayerType returns gopacket.LayerTypeDot1Q 26 | func (d *Dot1Q) LayerType() gopacket.LayerType { return LayerTypeDot1Q } 27 | 28 | // DecodeFromBytes decodes the given bytes into this layer. 29 | func (d *Dot1Q) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 30 | d.Priority = (data[0] & 0xE0) >> 5 31 | d.DropEligible = data[0]&0x10 != 0 32 | d.VLANIdentifier = binary.BigEndian.Uint16(data[:2]) & 0x0FFF 33 | d.Type = EthernetType(binary.BigEndian.Uint16(data[2:4])) 34 | d.BaseLayer = BaseLayer{Contents: data[:4], Payload: data[4:]} 35 | return nil 36 | } 37 | 38 | // CanDecode returns the set of layer types that this DecodingLayer can decode. 39 | func (d *Dot1Q) CanDecode() gopacket.LayerClass { 40 | return LayerTypeDot1Q 41 | } 42 | 43 | // NextLayerType returns the layer type contained by this DecodingLayer. 44 | func (d *Dot1Q) NextLayerType() gopacket.LayerType { 45 | return d.Type.LayerType() 46 | } 47 | 48 | func decodeDot1Q(data []byte, p gopacket.PacketBuilder) error { 49 | d := &Dot1Q{} 50 | return decodingLayerDecoder(d, data, p) 51 | } 52 | 53 | // SerializeTo writes the serialized form of this layer into the 54 | // SerializationBuffer, implementing gopacket.SerializableLayer. 55 | // See the docs for gopacket.SerializableLayer for more info. 56 | func (d *Dot1Q) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 57 | bytes, err := b.PrependBytes(4) 58 | if err != nil { 59 | return err 60 | } 61 | if d.VLANIdentifier > 0xFFF { 62 | return fmt.Errorf("vlan identifier %v is too high", d.VLANIdentifier) 63 | } 64 | firstBytes := uint16(d.Priority)<<13 | d.VLANIdentifier 65 | if d.DropEligible { 66 | firstBytes |= 0x1000 67 | } 68 | binary.BigEndian.PutUint16(bytes, firstBytes) 69 | binary.BigEndian.PutUint16(bytes[2:], uint16(d.Type)) 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/loopback.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "errors" 12 | "fmt" 13 | 14 | "github.com/google/gopacket" 15 | ) 16 | 17 | // Loopback contains the header for loopback encapsulation. This header is 18 | // used by both BSD and OpenBSD style loopback decoding (pcap's DLT_NULL 19 | // and DLT_LOOP, respectively). 20 | type Loopback struct { 21 | BaseLayer 22 | Family ProtocolFamily 23 | } 24 | 25 | // LayerType returns LayerTypeLoopback. 26 | func (l *Loopback) LayerType() gopacket.LayerType { return LayerTypeLoopback } 27 | 28 | // DecodeFromBytes decodes the given bytes into this layer. 29 | func (l *Loopback) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 30 | if len(data) < 4 { 31 | return errors.New("Loopback packet too small") 32 | } 33 | 34 | // The protocol could be either big-endian or little-endian, we're 35 | // not sure. But we're PRETTY sure that the value is less than 36 | // 256, so we can check the first two bytes. 37 | var prot uint32 38 | if data[0] == 0 && data[1] == 0 { 39 | prot = binary.BigEndian.Uint32(data[:4]) 40 | } else { 41 | prot = binary.LittleEndian.Uint32(data[:4]) 42 | } 43 | if prot > 0xFF { 44 | return fmt.Errorf("Invalid loopback protocol %q", data[:4]) 45 | } 46 | 47 | l.Family = ProtocolFamily(prot) 48 | l.BaseLayer = BaseLayer{data[:4], data[4:]} 49 | return nil 50 | } 51 | 52 | // CanDecode returns the set of layer types that this DecodingLayer can decode. 53 | func (l *Loopback) CanDecode() gopacket.LayerClass { 54 | return LayerTypeLoopback 55 | } 56 | 57 | // NextLayerType returns the layer type contained by this DecodingLayer. 58 | func (l *Loopback) NextLayerType() gopacket.LayerType { 59 | return l.Family.LayerType() 60 | } 61 | 62 | // SerializeTo writes the serialized form of this layer into the 63 | // SerializationBuffer, implementing gopacket.SerializableLayer. 64 | func (l *Loopback) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 65 | bytes, err := b.PrependBytes(4) 66 | if err != nil { 67 | return err 68 | } 69 | binary.LittleEndian.PutUint32(bytes, uint32(l.Family)) 70 | return nil 71 | } 72 | 73 | func decodeLoopback(data []byte, p gopacket.PacketBuilder) error { 74 | l := Loopback{} 75 | if err := l.DecodeFromBytes(data, gopacket.NilDecodeFeedback); err != nil { 76 | return err 77 | } 78 | p.AddLayer(&l) 79 | return p.NextDecoder(l.Family) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/examples/pcapdump/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // The pcapdump binary implements a tcpdump-like command line tool with gopacket 8 | // using pcap as a backend data collection mechanism. 9 | package main 10 | 11 | import ( 12 | "flag" 13 | "fmt" 14 | "github.com/google/gopacket/dumpcommand" 15 | "github.com/google/gopacket/examples/util" 16 | "github.com/google/gopacket/pcap" 17 | "log" 18 | "os" 19 | "strings" 20 | "time" 21 | ) 22 | 23 | var iface = flag.String("i", "eth0", "Interface to read packets from") 24 | var fname = flag.String("r", "", "Filename to read from, overrides -i") 25 | var snaplen = flag.Int("s", 65536, "Snap length (number of bytes max to read per packet") 26 | var tstype = flag.String("timestamp_type", "", "Type of timestamps to use") 27 | var promisc = flag.Bool("promisc", true, "Set promiscuous mode") 28 | 29 | func main() { 30 | defer util.Run()() 31 | var handle *pcap.Handle 32 | var err error 33 | if *fname != "" { 34 | if handle, err = pcap.OpenOffline(*fname); err != nil { 35 | log.Fatal("PCAP OpenOffline error:", err) 36 | } 37 | } else { 38 | // This is a little complicated because we want to allow all possible options 39 | // for creating the packet capture handle... instead of all this you can 40 | // just call pcap.OpenLive if you want a simple handle. 41 | inactive, err := pcap.NewInactiveHandle(*iface) 42 | if err != nil { 43 | log.Fatalf("could not create: %v", err) 44 | } 45 | defer inactive.CleanUp() 46 | if err = inactive.SetSnapLen(*snaplen); err != nil { 47 | log.Fatalf("could not set snap length: %v", err) 48 | } else if err = inactive.SetPromisc(*promisc); err != nil { 49 | log.Fatalf("could not set promisc mode: %v", err) 50 | } else if err = inactive.SetTimeout(time.Second); err != nil { 51 | log.Fatalf("could not set timeout: %v", err) 52 | } 53 | if *tstype != "" { 54 | if t, err := pcap.TimestampSourceFromString(*tstype); err != nil { 55 | log.Fatalf("Supported timestamp types: %v", inactive.SupportedTimestamps()) 56 | } else if err := inactive.SetTimestampSource(t); err != nil { 57 | log.Fatalf("Supported timestamp types: %v", inactive.SupportedTimestamps()) 58 | } 59 | } 60 | if handle, err = inactive.Activate(); err != nil { 61 | log.Fatal("PCAP Activate error:", err) 62 | } 63 | defer handle.Close() 64 | } 65 | if len(flag.Args()) > 0 { 66 | bpffilter := strings.Join(flag.Args(), " ") 67 | fmt.Fprintf(os.Stderr, "Using BPF filter %q\n", bpffilter) 68 | if err = handle.SetBPFFilter(bpffilter); err != nil { 69 | log.Fatal("BPF filter error:", err) 70 | } 71 | } 72 | dumpcommand.Run(handle) 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/text_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func TestSetText(t *testing.T) { 12 | t.Log("Testing gauge.SetText") 13 | 14 | cm := &CirconusMetrics{} 15 | cm.text = make(map[string]string) 16 | cm.SetText("foo", "bar") 17 | 18 | val, ok := cm.text["foo"] 19 | if !ok { 20 | t.Errorf("Expected to find foo") 21 | } 22 | 23 | if val != "bar" { 24 | t.Errorf("Expected 'bar', found '%s'", val) 25 | } 26 | } 27 | 28 | func TestSetTextValue(t *testing.T) { 29 | t.Log("Testing gauge.SetTextValue") 30 | 31 | cm := &CirconusMetrics{} 32 | cm.text = make(map[string]string) 33 | cm.SetTextValue("foo", "bar") 34 | 35 | val, ok := cm.text["foo"] 36 | if !ok { 37 | t.Errorf("Expected to find foo") 38 | } 39 | 40 | if val != "bar" { 41 | t.Errorf("Expected 'bar', found '%s'", val) 42 | } 43 | } 44 | 45 | func TestRemoveText(t *testing.T) { 46 | t.Log("Testing text.RemoveText") 47 | 48 | cm := &CirconusMetrics{} 49 | cm.text = make(map[string]string) 50 | cm.SetText("foo", "bar") 51 | 52 | val, ok := cm.text["foo"] 53 | if !ok { 54 | t.Errorf("Expected to find foo") 55 | } 56 | 57 | if val != "bar" { 58 | t.Errorf("Expected 'bar', found '%s'", val) 59 | } 60 | 61 | cm.RemoveText("foo") 62 | 63 | val, ok = cm.text["foo"] 64 | if ok { 65 | t.Errorf("Expected NOT to find foo") 66 | } 67 | 68 | if val != "" { 69 | t.Errorf("Expected '', found '%s'", val) 70 | } 71 | } 72 | 73 | func TestSetTextFunc(t *testing.T) { 74 | t.Log("Testing text.SetTextFunc") 75 | 76 | tf := func() string { 77 | return "bar" 78 | } 79 | cm := &CirconusMetrics{} 80 | cm.textFuncs = make(map[string]func() string) 81 | cm.SetTextFunc("foo", tf) 82 | 83 | val, ok := cm.textFuncs["foo"] 84 | if !ok { 85 | t.Errorf("Expected to find foo") 86 | } 87 | 88 | if val() != "bar" { 89 | t.Errorf("Expected 'bar', found '%s'", val()) 90 | } 91 | } 92 | 93 | func TestRemoveTextFunc(t *testing.T) { 94 | t.Log("Testing text.RemoveTextFunc") 95 | 96 | tf := func() string { 97 | return "bar" 98 | } 99 | cm := &CirconusMetrics{} 100 | cm.textFuncs = make(map[string]func() string) 101 | cm.SetTextFunc("foo", tf) 102 | 103 | val, ok := cm.textFuncs["foo"] 104 | if !ok { 105 | t.Errorf("Expected to find foo") 106 | } 107 | 108 | if val() != "bar" { 109 | t.Errorf("Expected 'bar', found '%s'", val()) 110 | } 111 | 112 | cm.RemoveTextFunc("foo") 113 | 114 | val, ok = cm.textFuncs["foo"] 115 | if ok { 116 | t.Errorf("Expected NOT to find foo") 117 | } 118 | 119 | if val != nil { 120 | t.Errorf("Expected nil, found %s", val()) 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /vendor/github.com/tv42/httpunix/httpunix.go: -------------------------------------------------------------------------------- 1 | // Package httpunix provides a HTTP transport (net/http.RoundTripper) 2 | // that uses Unix domain sockets instead of HTTP. 3 | // 4 | // This is useful for non-browser connections within the same host, as 5 | // it allows using the file system for credentials of both client 6 | // and server, and guaranteeing unique names. 7 | // 8 | // The URLs look like this: 9 | // 10 | // http+unix://LOCATION/PATH_ETC 11 | // 12 | // where LOCATION is translated to a file system path with 13 | // Transport.RegisterLocation, and PATH_ETC follow normal http: scheme 14 | // conventions. 15 | package httpunix 16 | 17 | import ( 18 | "bufio" 19 | "errors" 20 | "net" 21 | "net/http" 22 | "sync" 23 | "time" 24 | ) 25 | 26 | // Scheme is the URL scheme used for HTTP over UNIX domain sockets. 27 | const Scheme = "http+unix" 28 | 29 | // Transport is a http.RoundTripper that connects to Unix domain 30 | // sockets. 31 | type Transport struct { 32 | DialTimeout time.Duration 33 | RequestTimeout time.Duration 34 | ResponseHeaderTimeout time.Duration 35 | 36 | mu sync.Mutex 37 | // map a URL "hostname" to a UNIX domain socket path 38 | loc map[string]string 39 | } 40 | 41 | // RegisterLocation registers an URL location and maps it to the given 42 | // file system path. 43 | // 44 | // Calling RegisterLocation twice for the same location is a 45 | // programmer error, and causes a panic. 46 | func (t *Transport) RegisterLocation(loc string, path string) { 47 | t.mu.Lock() 48 | defer t.mu.Unlock() 49 | if t.loc == nil { 50 | t.loc = make(map[string]string) 51 | } 52 | if _, exists := t.loc[loc]; exists { 53 | panic("location " + loc + " already registered") 54 | } 55 | t.loc[loc] = path 56 | } 57 | 58 | var _ http.RoundTripper = (*Transport)(nil) 59 | 60 | // RoundTrip executes a single HTTP transaction. See 61 | // net/http.RoundTripper. 62 | func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { 63 | if req.URL == nil { 64 | return nil, errors.New("http+unix: nil Request.URL") 65 | } 66 | if req.URL.Scheme != Scheme { 67 | return nil, errors.New("unsupported protocol scheme: " + req.URL.Scheme) 68 | } 69 | if req.URL.Host == "" { 70 | return nil, errors.New("http+unix: no Host in request URL") 71 | } 72 | t.mu.Lock() 73 | path, ok := t.loc[req.URL.Host] 74 | t.mu.Unlock() 75 | if !ok { 76 | return nil, errors.New("unknown location: " + req.Host) 77 | } 78 | 79 | c, err := net.DialTimeout("unix", path, t.DialTimeout) 80 | if err != nil { 81 | return nil, err 82 | } 83 | r := bufio.NewReader(c) 84 | if t.RequestTimeout > 0 { 85 | c.SetWriteDeadline(time.Now().Add(t.RequestTimeout)) 86 | } 87 | if err := req.Write(c); err != nil { 88 | return nil, err 89 | } 90 | if t.ResponseHeaderTimeout > 0 { 91 | c.SetReadDeadline(time.Now().Add(t.ResponseHeaderTimeout)) 92 | } 93 | resp, err := http.ReadResponse(r, req) 94 | return resp, err 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/usb_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014, Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | _ "fmt" 11 | "github.com/google/gopacket" 12 | "reflect" 13 | "testing" 14 | ) 15 | 16 | // Generator python layers/test_creator.py --link_type USB --name USB dongle.pcap 17 | // http://wiki.wireshark.org/SampleCaptures#Sample_Captures 18 | 19 | // testPacketUSB0 is the packet: 20 | // 02:41:04.689546 INTERRUPT COMPLETE to 2:1:1 21 | // 0x0000: 0038 4a3b 0088 ffff 4301 8101 0200 2d00 .8J;....C.....-. 22 | // 0x0010: c0d3 5b50 0000 0000 8a85 0a00 0000 0000 ..[P............ 23 | // 0x0020: 0100 0000 0100 0000 0000 0000 0000 0000 ................ 24 | // 0x0030: 8000 0000 0000 0000 0002 0000 0000 0000 ................ 25 | // 0x0040: 04 . 26 | var testPacketUSB0 = []byte{ 27 | 0x00, 0x38, 0x4a, 0x3b, 0x00, 0x88, 0xff, 0xff, 0x43, 0x01, 0x81, 0x01, 0x02, 0x00, 0x2d, 0x00, 28 | 0xc0, 0xd3, 0x5b, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x85, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 29 | 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31 | 0x04, 32 | } 33 | 34 | func TestPacketUSB0(t *testing.T) { 35 | p := gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.Default) 36 | if p.ErrorLayer() != nil { 37 | t.Error("Failed to decode packet:", p.ErrorLayer().Error()) 38 | } 39 | checkLayers(p, []gopacket.LayerType{LayerTypeUSB, LayerTypeUSBInterrupt}, t) 40 | 41 | if got, ok := p.Layer(LayerTypeUSB).(*USB); ok { 42 | want := &USB{ 43 | BaseLayer: BaseLayer{ 44 | Contents: []uint8{0x0, 0x38, 0x4a, 0x3b, 0x0, 0x88, 0xff, 0xff, 0x43, 0x1, 0x81, 0x1, 0x2, 0x0, 0x2d, 0x0, 0xc0, 0xd3, 0x5b, 0x50, 0x0, 0x0, 0x0, 0x0, 0x8a, 0x85, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0}, 45 | Payload: []uint8{0x4}, 46 | }, 47 | ID: 0xffff88003b4a3800, 48 | EventType: USBEventTypeComplete, 49 | TransferType: USBTransportTypeInterrupt, 50 | Direction: 0x1, 51 | EndpointNumber: 0x1, 52 | DeviceAddress: 0x1, 53 | BusID: 0x2, 54 | TimestampSec: 1348195264, 55 | TimestampUsec: 689546, 56 | Setup: false, 57 | Data: true, 58 | Status: 0, 59 | UrbLength: 0x1, 60 | UrbDataLength: 0x1, 61 | } 62 | 63 | if !reflect.DeepEqual(got, want) { 64 | t.Errorf("USB packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) 65 | } 66 | } 67 | 68 | } 69 | func BenchmarkDecodePacketUSB0(b *testing.B) { 70 | for i := 0; i < b.N; i++ { 71 | gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.NoCopy) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/histogram.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | import ( 8 | "fmt" 9 | "sync" 10 | 11 | "github.com/circonus-labs/circonusllhist" 12 | ) 13 | 14 | // Histogram measures the distribution of a stream of values. 15 | type Histogram struct { 16 | name string 17 | hist *circonusllhist.Histogram 18 | rw sync.RWMutex 19 | } 20 | 21 | // Timing adds a value to a histogram 22 | func (m *CirconusMetrics) Timing(metric string, val float64) { 23 | m.SetHistogramValue(metric, val) 24 | } 25 | 26 | // RecordValue adds a value to a histogram 27 | func (m *CirconusMetrics) RecordValue(metric string, val float64) { 28 | m.SetHistogramValue(metric, val) 29 | } 30 | 31 | // RecordCountForValue adds count n for value to a histogram 32 | func (m *CirconusMetrics) RecordCountForValue(metric string, val float64, n int64) { 33 | hist := m.NewHistogram(metric) 34 | 35 | m.hm.Lock() 36 | hist.rw.Lock() 37 | hist.hist.RecordValues(val, n) 38 | hist.rw.Unlock() 39 | m.hm.Unlock() 40 | } 41 | 42 | // SetHistogramValue adds a value to a histogram 43 | func (m *CirconusMetrics) SetHistogramValue(metric string, val float64) { 44 | hist := m.NewHistogram(metric) 45 | 46 | m.hm.Lock() 47 | hist.rw.Lock() 48 | hist.hist.RecordValue(val) 49 | hist.rw.Unlock() 50 | m.hm.Unlock() 51 | } 52 | 53 | // GetHistogramTest returns the current value for a gauge. (note: it is a function specifically for "testing", disable automatic submission during testing.) 54 | func (m *CirconusMetrics) GetHistogramTest(metric string) ([]string, error) { 55 | m.hm.Lock() 56 | defer m.hm.Unlock() 57 | 58 | if hist, ok := m.histograms[metric]; ok { 59 | return hist.hist.DecStrings(), nil 60 | } 61 | 62 | return []string{""}, fmt.Errorf("Histogram metric '%s' not found", metric) 63 | } 64 | 65 | // RemoveHistogram removes a histogram 66 | func (m *CirconusMetrics) RemoveHistogram(metric string) { 67 | m.hm.Lock() 68 | delete(m.histograms, metric) 69 | m.hm.Unlock() 70 | } 71 | 72 | // NewHistogram returns a histogram instance. 73 | func (m *CirconusMetrics) NewHistogram(metric string) *Histogram { 74 | m.hm.Lock() 75 | defer m.hm.Unlock() 76 | 77 | if hist, ok := m.histograms[metric]; ok { 78 | return hist 79 | } 80 | 81 | hist := &Histogram{ 82 | name: metric, 83 | hist: circonusllhist.New(), 84 | } 85 | 86 | m.histograms[metric] = hist 87 | 88 | return hist 89 | } 90 | 91 | // Name returns the name from a histogram instance 92 | func (h *Histogram) Name() string { 93 | return h.name 94 | } 95 | 96 | // RecordValue records the given value to a histogram instance 97 | func (h *Histogram) RecordValue(v float64) { 98 | h.rw.Lock() 99 | h.hist.RecordValue(v) 100 | h.rw.Unlock() 101 | } 102 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/macs/gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build ignore 8 | 9 | // This binary pulls the list of known MAC 10 | // prefixes from IEEE and writes them out to a go file which is compiled 11 | // into gopacket. It should be run as follows: 12 | // 13 | // go run gen.go | gofmt > valid_mac_prefixes.go 14 | package main 15 | 16 | import ( 17 | "bufio" 18 | "bytes" 19 | "encoding/hex" 20 | "flag" 21 | "fmt" 22 | "io" 23 | "net/http" 24 | "os" 25 | "regexp" 26 | "sort" 27 | "time" 28 | ) 29 | 30 | const header = `// Copyright 2012 Google, Inc. All rights reserved. 31 | // 32 | // Use of this source code is governed by a BSD-style license 33 | // that can be found in the LICENSE file in the root of the source 34 | // tree. 35 | 36 | package macs 37 | 38 | // Created by gen.go, don't edit manually 39 | // Generated at %s 40 | // Fetched from %q 41 | 42 | // ValidMACPrefixMap maps a valid MAC address prefix to the name of the 43 | // organization that owns the rights to use it. We map it to a hidden 44 | // variable so it won't show up in godoc, since it's a very large map. 45 | var ValidMACPrefixMap = validMACPrefixMap 46 | var validMACPrefixMap = map[[3]byte]string{ 47 | ` 48 | 49 | var url = flag.String("url", "http://standards.ieee.org/develop/regauth/oui/oui.txt", "URL to fetch MACs from") 50 | 51 | type mac struct { 52 | prefix [3]byte 53 | company string 54 | } 55 | 56 | type macs []mac 57 | 58 | func (m macs) Len() int { return len(m) } 59 | func (m macs) Less(i, j int) bool { return bytes.Compare(m[i].prefix[:], m[j].prefix[:]) < 0 } 60 | func (m macs) Swap(i, j int) { m[i], m[j] = m[j], m[i] } 61 | 62 | func main() { 63 | fmt.Fprintf(os.Stderr, "Fetching MACs from %q\n", *url) 64 | resp, err := http.Get(*url) 65 | if err != nil { 66 | panic(err) 67 | } 68 | defer resp.Body.Close() 69 | buffered := bufio.NewReader(resp.Body) 70 | finder := regexp.MustCompile(`^\s*([0-9A-F]{6})\s+\(base 16\)\s+(.*)`) 71 | got := macs{} 72 | for { 73 | line, err := buffered.ReadString('\n') 74 | if err == io.EOF { 75 | break 76 | } else if err != nil { 77 | panic(err) 78 | } 79 | if matches := finder.FindStringSubmatch(line); matches != nil { 80 | var prefix [3]byte 81 | hex.Decode(prefix[:], []byte(matches[1])) 82 | company := matches[2] 83 | if company == "" { 84 | company = "PRIVATE" 85 | } 86 | fmt.Fprint(os.Stderr, "*") 87 | got = append(got, mac{prefix: prefix, company: company}) 88 | } 89 | } 90 | fmt.Fprintln(os.Stderr, "\nSorting macs") 91 | sort.Sort(got) 92 | fmt.Fprintln(os.Stderr, "Starting write to standard output") 93 | fmt.Printf(header, time.Now(), *url) 94 | for _, m := range got { 95 | fmt.Printf("\t[3]byte{%d, %d, %d}: %q,\n", m.prefix[0], m.prefix[1], m.prefix[2], m.company) 96 | } 97 | fmt.Println("}") 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/linux_sll.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "errors" 12 | "fmt" 13 | "net" 14 | 15 | "github.com/google/gopacket" 16 | ) 17 | 18 | type LinuxSLLPacketType uint16 19 | 20 | const ( 21 | LinuxSLLPacketTypeHost LinuxSLLPacketType = 0 // To us 22 | LinuxSLLPacketTypeBroadcast LinuxSLLPacketType = 1 // To all 23 | LinuxSLLPacketTypeMulticast LinuxSLLPacketType = 2 // To group 24 | LinuxSLLPacketTypeOtherhost LinuxSLLPacketType = 3 // To someone else 25 | LinuxSLLPacketTypeOutgoing LinuxSLLPacketType = 4 // Outgoing of any type 26 | // These ones are invisible by user level 27 | LinuxSLLPacketTypeLoopback LinuxSLLPacketType = 5 // MC/BRD frame looped back 28 | LinuxSLLPacketTypeFastroute LinuxSLLPacketType = 6 // Fastrouted frame 29 | ) 30 | 31 | func (l LinuxSLLPacketType) String() string { 32 | switch l { 33 | case LinuxSLLPacketTypeHost: 34 | return "host" 35 | case LinuxSLLPacketTypeBroadcast: 36 | return "broadcast" 37 | case LinuxSLLPacketTypeMulticast: 38 | return "multicast" 39 | case LinuxSLLPacketTypeOtherhost: 40 | return "otherhost" 41 | case LinuxSLLPacketTypeOutgoing: 42 | return "outgoing" 43 | case LinuxSLLPacketTypeLoopback: 44 | return "loopback" 45 | case LinuxSLLPacketTypeFastroute: 46 | return "fastroute" 47 | } 48 | return fmt.Sprintf("Unknown(%d)", int(l)) 49 | } 50 | 51 | type LinuxSLL struct { 52 | BaseLayer 53 | PacketType LinuxSLLPacketType 54 | AddrLen uint16 55 | Addr net.HardwareAddr 56 | EthernetType EthernetType 57 | } 58 | 59 | // LayerType returns LayerTypeLinuxSLL. 60 | func (sll *LinuxSLL) LayerType() gopacket.LayerType { return LayerTypeLinuxSLL } 61 | 62 | func (sll *LinuxSLL) CanDecode() gopacket.LayerClass { 63 | return LayerTypeLinuxSLL 64 | } 65 | 66 | func (sll *LinuxSLL) LinkFlow() gopacket.Flow { 67 | return gopacket.NewFlow(EndpointMAC, sll.Addr, nil) 68 | } 69 | 70 | func (sll *LinuxSLL) NextLayerType() gopacket.LayerType { 71 | return sll.EthernetType.LayerType() 72 | } 73 | 74 | func (sll *LinuxSLL) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 75 | if len(data) < 16 { 76 | return errors.New("Linux SLL packet too small") 77 | } 78 | sll.PacketType = LinuxSLLPacketType(binary.BigEndian.Uint16(data[0:2])) 79 | sll.AddrLen = binary.BigEndian.Uint16(data[4:6]) 80 | 81 | sll.Addr = net.HardwareAddr(data[6 : sll.AddrLen+6]) 82 | sll.EthernetType = EthernetType(binary.BigEndian.Uint16(data[14:16])) 83 | sll.BaseLayer = BaseLayer{data[:16], data[16:]} 84 | 85 | return nil 86 | } 87 | 88 | func decodeLinuxSLL(data []byte, p gopacket.PacketBuilder) error { 89 | sll := &LinuxSLL{} 90 | if err := sll.DecodeFromBytes(data, p); err != nil { 91 | return err 92 | } 93 | p.AddLayer(sll) 94 | p.SetLinkLayer(sll) 95 | return p.NextDecoder(sll.EthernetType) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build ignore 8 | 9 | // This binary pulls known ports from IANA, and uses them to populate 10 | // iana_ports.go's TCPPortNames and UDPPortNames maps. 11 | // 12 | // go run gen.go | gofmt > iana_ports.go 13 | package main 14 | 15 | import ( 16 | "bytes" 17 | "encoding/xml" 18 | "flag" 19 | "fmt" 20 | "io/ioutil" 21 | "net/http" 22 | "os" 23 | "strconv" 24 | "time" 25 | ) 26 | 27 | const fmtString = `// Copyright 2012 Google, Inc. All rights reserved. 28 | 29 | package layers 30 | 31 | // Created by gen.go, don't edit manually 32 | // Generated at %s 33 | // Fetched from %q 34 | 35 | // TCPPortNames contains the port names for all TCP ports. 36 | var TCPPortNames = tcpPortNames 37 | 38 | // UDPPortNames contains the port names for all UDP ports. 39 | var UDPPortNames = udpPortNames 40 | 41 | // SCTPPortNames contains the port names for all SCTP ports. 42 | var SCTPPortNames = sctpPortNames 43 | 44 | var tcpPortNames = map[TCPPort]string{ 45 | %s} 46 | var udpPortNames = map[UDPPort]string{ 47 | %s} 48 | var sctpPortNames = map[SCTPPort]string{ 49 | %s} 50 | ` 51 | 52 | var url = flag.String("url", "http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml", "URL to grab port numbers from") 53 | 54 | func main() { 55 | fmt.Fprintf(os.Stderr, "Fetching ports from %q\n", *url) 56 | resp, err := http.Get(*url) 57 | if err != nil { 58 | panic(err) 59 | } 60 | defer resp.Body.Close() 61 | body, err := ioutil.ReadAll(resp.Body) 62 | if err != nil { 63 | panic(err) 64 | } 65 | fmt.Fprintln(os.Stderr, "Parsing XML") 66 | var registry struct { 67 | Records []struct { 68 | Protocol string `xml:"protocol"` 69 | Number string `xml:"number"` 70 | Name string `xml:"name"` 71 | } `xml:"record"` 72 | } 73 | xml.Unmarshal(body, ®istry) 74 | var tcpPorts bytes.Buffer 75 | var udpPorts bytes.Buffer 76 | var sctpPorts bytes.Buffer 77 | done := map[string]map[int]bool{ 78 | "tcp": map[int]bool{}, 79 | "udp": map[int]bool{}, 80 | "sctp": map[int]bool{}, 81 | } 82 | for _, r := range registry.Records { 83 | port, err := strconv.Atoi(r.Number) 84 | if err != nil { 85 | continue 86 | } 87 | if r.Name == "" { 88 | continue 89 | } 90 | var b *bytes.Buffer 91 | switch r.Protocol { 92 | case "tcp": 93 | b = &tcpPorts 94 | case "udp": 95 | b = &udpPorts 96 | case "sctp": 97 | b = &sctpPorts 98 | default: 99 | continue 100 | } 101 | if done[r.Protocol][port] { 102 | continue 103 | } 104 | done[r.Protocol][port] = true 105 | fmt.Fprintf(b, "\t%d: %q,\n", port, r.Name) 106 | } 107 | fmt.Fprintln(os.Stderr, "Writing results to stdout") 108 | fmt.Printf(fmtString, time.Now(), *url, tcpPorts.String(), udpPorts.String(), sctpPorts.String()) 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonusllhist/circonusllhist_test.go: -------------------------------------------------------------------------------- 1 | package circonusllhist 2 | 3 | import ( 4 | "bytes" 5 | "math" 6 | "testing" 7 | ) 8 | 9 | func TestSerialize(t *testing.T) { 10 | h, err := NewFromStrings([]string{ 11 | "H[0.0e+00]=1", 12 | "H[1.0e+01]=1", 13 | "H[2.0e+02]=1", 14 | }, false) 15 | if err != nil { 16 | t.Error("could not read from strings for test") 17 | } 18 | 19 | buf := bytes.NewBuffer([]byte{}) 20 | if err := h.Serialize(buf); err != nil { 21 | t.Error(err) 22 | } 23 | 24 | h2, err := Deserialize(buf) 25 | if err != nil { 26 | t.Error(h2, err) 27 | } 28 | if !h.Equals(h2) { 29 | t.Log(h.DecStrings()) 30 | t.Log(h2.DecStrings()) 31 | t.Error("histograms do not match") 32 | } 33 | } 34 | 35 | func helpTestBin(t *testing.T, v float64, val, exp int8) { 36 | b := newBinFromFloat64(v) 37 | if b.val != val || b.exp != exp { 38 | t.Errorf("%v -> [%v,%v] expected, but got [%v,%v]", v, val, exp, b.val, b.exp) 39 | } 40 | } 41 | 42 | func fuzzy_equals(expected, actual float64) bool { 43 | delta := math.Abs(expected / 100000.0) 44 | if actual >= expected-delta && actual <= expected+delta { 45 | return true 46 | } 47 | return false 48 | } 49 | 50 | func TestBins(t *testing.T) { 51 | helpTestBin(t, 0.0, 0, 0) 52 | helpTestBin(t, 100, 10, 2) 53 | helpTestBin(t, 9.9999e-129, 0, 0) 54 | helpTestBin(t, 1e-128, 10, -128) 55 | helpTestBin(t, 1.00001e-128, 10, -128) 56 | helpTestBin(t, 1.09999e-128, 10, -128) 57 | helpTestBin(t, 1.1e-128, 11, -128) 58 | helpTestBin(t, 1e127, 10, 127) 59 | helpTestBin(t, 9.999e127, 99, 127) 60 | helpTestBin(t, 1e128, -1, 0) 61 | helpTestBin(t, -9.9999e-129, 0, 0) 62 | helpTestBin(t, -1e-128, -10, -128) 63 | helpTestBin(t, -1.00001e-128, -10, -128) 64 | helpTestBin(t, -1.09999e-128, -10, -128) 65 | helpTestBin(t, -1.1e-128, -11, -128) 66 | helpTestBin(t, -1e127, -10, 127) 67 | helpTestBin(t, -9.999e127, -99, 127) 68 | helpTestBin(t, -1e128, -1, 0) 69 | helpTestBin(t, 9.999e127, 99, 127) 70 | 71 | h := New() 72 | h.RecordIntScale(100, 1) 73 | if h.bvs[0].val != 10 || h.bvs[0].exp != 2 { 74 | t.Errorf("100 not added correctly") 75 | } 76 | } 77 | 78 | func helpTestVB(t *testing.T, v, b, w float64) { 79 | bin := newBinFromFloat64(v) 80 | out := bin.value() 81 | interval := bin.binWidth() 82 | if out < 0 { 83 | interval *= -1.0 84 | } 85 | if !fuzzy_equals(b, out) { 86 | t.Errorf("%v -> %v != %v\n", v, out, b) 87 | } 88 | if !fuzzy_equals(w, interval) { 89 | t.Errorf("%v -> [%v] != [%v]\n", v, interval, w) 90 | } 91 | } 92 | 93 | func TestBinSizes(t *testing.T) { 94 | helpTestVB(t, 43.3, 43.0, 1.0) 95 | helpTestVB(t, 99.9, 99.0, 1.0) 96 | helpTestVB(t, 10.0, 10.0, 1.0) 97 | helpTestVB(t, 1.0, 1.0, 0.1) 98 | helpTestVB(t, 0.0002, 0.0002, 0.00001) 99 | helpTestVB(t, 0.003, 0.003, 0.0001) 100 | helpTestVB(t, 0.3201, 0.32, 0.01) 101 | helpTestVB(t, 0.0035, 0.0035, 0.0001) 102 | helpTestVB(t, -1.0, -1.0, -0.1) 103 | helpTestVB(t, -0.00123, -0.0012, -0.0001) 104 | helpTestVB(t, -987324, -980000, -10000) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/api/check_bundle_metrics.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // CheckBundleMetrics API support - Fetch, Create*, Update, and Delete** 6 | // See: https://login.circonus.com/resources/api/calls/check_bundle_metrics 7 | // * : create metrics by adding to array with a status of 'active' 8 | // ** : delete (distable collection of) metrics by changing status from 'active' to 'available' 9 | 10 | package api 11 | 12 | import ( 13 | "encoding/json" 14 | "fmt" 15 | "regexp" 16 | 17 | "github.com/circonus-labs/circonus-gometrics/api/config" 18 | ) 19 | 20 | // CheckBundleMetrics defines metrics for a specific check bundle. See https://login.circonus.com/resources/api/calls/check_bundle_metrics for more information. 21 | type CheckBundleMetrics struct { 22 | CID string `json:"_cid,omitempty"` // string 23 | Metrics []CheckBundleMetric `json:"metrics"` // See check_bundle.go for CheckBundleMetric definition 24 | } 25 | 26 | // FetchCheckBundleMetrics retrieves metrics for the check bundle with passed cid. 27 | func (a *API) FetchCheckBundleMetrics(cid CIDType) (*CheckBundleMetrics, error) { 28 | if cid == nil || *cid == "" { 29 | return nil, fmt.Errorf("Invalid check bundle metrics CID [none]") 30 | } 31 | 32 | metricsCID := string(*cid) 33 | 34 | matched, err := regexp.MatchString(config.CheckBundleMetricsCIDRegex, metricsCID) 35 | if err != nil { 36 | return nil, err 37 | } 38 | if !matched { 39 | return nil, fmt.Errorf("Invalid check bundle metrics CID [%s]", metricsCID) 40 | } 41 | 42 | result, err := a.Get(metricsCID) 43 | if err != nil { 44 | return nil, err 45 | } 46 | 47 | if a.Debug { 48 | a.Log.Printf("[DEBUG] fetch check bundle metrics, received JSON: %s", string(result)) 49 | } 50 | 51 | metrics := &CheckBundleMetrics{} 52 | if err := json.Unmarshal(result, metrics); err != nil { 53 | return nil, err 54 | } 55 | 56 | return metrics, nil 57 | } 58 | 59 | // UpdateCheckBundleMetrics updates passed metrics. 60 | func (a *API) UpdateCheckBundleMetrics(cfg *CheckBundleMetrics) (*CheckBundleMetrics, error) { 61 | if cfg == nil { 62 | return nil, fmt.Errorf("Invalid check bundle metrics config [nil]") 63 | } 64 | 65 | metricsCID := string(cfg.CID) 66 | 67 | matched, err := regexp.MatchString(config.CheckBundleMetricsCIDRegex, metricsCID) 68 | if err != nil { 69 | return nil, err 70 | } 71 | if !matched { 72 | return nil, fmt.Errorf("Invalid check bundle metrics CID [%s]", metricsCID) 73 | } 74 | 75 | jsonCfg, err := json.Marshal(cfg) 76 | if err != nil { 77 | return nil, err 78 | } 79 | 80 | if a.Debug { 81 | a.Log.Printf("[DEBUG] update check bundle metrics, sending JSON: %s", string(jsonCfg)) 82 | } 83 | 84 | result, err := a.Put(metricsCID, jsonCfg) 85 | if err != nil { 86 | return nil, err 87 | } 88 | 89 | metrics := &CheckBundleMetrics{} 90 | if err := json.Unmarshal(result, metrics); err != nil { 91 | return nil, err 92 | } 93 | 94 | return metrics, nil 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | /* 8 | Package layers provides decoding layers for many common protocols. 9 | 10 | The layers package contains decode implementations for a number of different 11 | types of packet layers. Users of gopacket will almost always want to also use 12 | layers to actually decode packet data into useful pieces. To see the set of 13 | protocols that gopacket/layers is currently able to decode, 14 | look at the set of LayerTypes defined in the Variables sections. The 15 | layers package also defines endpoints for many of the common packet layers 16 | that have source/destination addresses associated with them, for example IPv4/6 17 | (IPs) and TCP/UDP (ports). 18 | Finally, layers contains a number of useful enumerations (IPProtocol, 19 | EthernetType, LinkType, PPPType, etc...). Many of these implement the 20 | gopacket.Decoder interface, so they can be passed into gopacket as decoders. 21 | 22 | Most common protocol layers are named using acronyms or other industry-common 23 | names (IPv4, TCP, PPP). Some of the less common ones have their names expanded 24 | (CiscoDiscoveryProtocol). 25 | For certain protocols, sub-parts of the protocol are split out into their own 26 | layers (SCTP, for example). This is done mostly in cases where portions of the 27 | protocol may fulfill the capabilities of interesting layers (SCTPData implements 28 | ApplicationLayer, while base SCTP implements TransportLayer), or possibly 29 | because splitting a protocol into a few layers makes decoding easier. 30 | 31 | This package is meant to be used with its parent, 32 | http://github.com/google/gopacket. 33 | 34 | Port Types 35 | 36 | Instead of using raw uint16 or uint8 values for ports, we use a different port 37 | type for every protocol, for example TCPPort and UDPPort. This allows us to 38 | override string behavior for each port, which we do by setting up port name 39 | maps (TCPPortNames, UDPPortNames, etc...). Well-known ports are annotated with 40 | their protocol names, and their String function displays these names: 41 | 42 | p := TCPPort(80) 43 | fmt.Printf("Number: %d String: %v", p, p) 44 | // Prints: "Number: 80 String: 80(http)" 45 | 46 | Modifying Decode Behavior 47 | 48 | layers links together decoding through its enumerations. For example, after 49 | decoding layer type Ethernet, it uses Ethernet.EthernetType as its next decoder. 50 | All enumerations that act as decoders, like EthernetType, can be modified by 51 | users depending on their preferences. For example, if you have a spiffy new 52 | IPv4 decoder that works way better than the one built into layers, you can do 53 | this: 54 | 55 | var mySpiffyIPv4Decoder gopacket.Decoder = ... 56 | layers.EthernetTypeMetadata[EthernetTypeIPv4].DecodeWith = mySpiffyIPv4Decoder 57 | 58 | This will make all future ethernet packets use your new decoder to decode IPv4 59 | packets, instead of the built-in decoder used by gopacket. 60 | */ 61 | package layers 62 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/eap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "fmt" 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | type EAPCode uint8 16 | type EAPType uint8 17 | 18 | const ( 19 | EAPCodeRequest EAPCode = 1 20 | EAPCodeResponse EAPCode = 2 21 | EAPCodeSuccess EAPCode = 3 22 | EAPCodeFailure EAPCode = 4 23 | 24 | // EAPTypeNone means that this EAP layer has no Type or TypeData. 25 | // Success and Failure EAPs will have this set. 26 | EAPTypeNone EAPType = 0 27 | 28 | EAPTypeIdentity EAPType = 1 29 | EAPTypeNotification EAPType = 2 30 | EAPTypeNACK EAPType = 3 31 | EAPTypeOTP EAPType = 4 32 | EAPTypeTokenCard EAPType = 5 33 | ) 34 | 35 | // EAP defines an Extensible Authentication Protocol (rfc 3748) layer. 36 | type EAP struct { 37 | BaseLayer 38 | Code EAPCode 39 | Id uint8 40 | Length uint16 41 | Type EAPType 42 | TypeData []byte 43 | } 44 | 45 | // LayerType returns LayerTypeEAP. 46 | func (e *EAP) LayerType() gopacket.LayerType { return LayerTypeEAP } 47 | 48 | // DecodeFromBytes decodes the given bytes into this layer. 49 | func (e *EAP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 50 | e.Code = EAPCode(data[0]) 51 | e.Id = data[1] 52 | e.Length = binary.BigEndian.Uint16(data[2:4]) 53 | switch { 54 | case e.Length > 4: 55 | e.Type = EAPType(data[4]) 56 | e.TypeData = data[5:] 57 | case e.Length == 4: 58 | e.Type = 0 59 | e.TypeData = nil 60 | default: 61 | return fmt.Errorf("invalid EAP length %d", e.Length) 62 | } 63 | e.BaseLayer.Contents = data[:e.Length] 64 | e.BaseLayer.Payload = data[e.Length:] // Should be 0 bytes 65 | return nil 66 | } 67 | 68 | // SerializeTo writes the serialized form of this layer into the 69 | // SerializationBuffer, implementing gopacket.SerializableLayer. 70 | // See the docs for gopacket.SerializableLayer for more info. 71 | func (e *EAP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 72 | if opts.FixLengths { 73 | e.Length = uint16(len(e.TypeData) + 1) 74 | } 75 | size := len(e.TypeData) + 4 76 | if size > 4 { 77 | size++ 78 | } 79 | bytes, err := b.PrependBytes(size) 80 | if err != nil { 81 | return err 82 | } 83 | bytes[0] = byte(e.Code) 84 | bytes[1] = e.Id 85 | binary.BigEndian.PutUint16(bytes[2:], e.Length) 86 | if size > 4 { 87 | bytes[4] = byte(e.Type) 88 | copy(bytes[5:], e.TypeData) 89 | } 90 | return nil 91 | } 92 | 93 | // CanDecode returns the set of layer types that this DecodingLayer can decode. 94 | func (e *EAP) CanDecode() gopacket.LayerClass { 95 | return LayerTypeEAP 96 | } 97 | 98 | // NextLayerType returns the layer type contained by this DecodingLayer. 99 | func (e *EAP) NextLayerType() gopacket.LayerType { 100 | return gopacket.LayerTypeZero 101 | } 102 | 103 | func decodeEAP(data []byte, p gopacket.PacketBuilder) error { 104 | e := &EAP{} 105 | return decodingLayerDecoder(e, data, p) 106 | } 107 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/rudp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "fmt" 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | type RUDP struct { 16 | BaseLayer 17 | SYN, ACK, EACK, RST, NUL bool 18 | Version uint8 19 | HeaderLength uint8 20 | SrcPort, DstPort RUDPPort 21 | DataLength uint16 22 | Seq, Ack, Checksum uint32 23 | VariableHeaderArea []byte 24 | // RUDPHeaderSyn contains SYN information for the RUDP packet, 25 | // if the SYN flag is set 26 | *RUDPHeaderSYN 27 | // RUDPHeaderEack contains EACK information for the RUDP packet, 28 | // if the EACK flag is set. 29 | *RUDPHeaderEACK 30 | } 31 | 32 | type RUDPHeaderSYN struct { 33 | MaxOutstandingSegments, MaxSegmentSize, OptionFlags uint16 34 | } 35 | 36 | type RUDPHeaderEACK struct { 37 | SeqsReceivedOK []uint32 38 | } 39 | 40 | // LayerType returns gopacket.LayerTypeRUDP. 41 | func (r *RUDP) LayerType() gopacket.LayerType { return LayerTypeRUDP } 42 | 43 | func decodeRUDP(data []byte, p gopacket.PacketBuilder) error { 44 | r := &RUDP{ 45 | SYN: data[0]&0x80 != 0, 46 | ACK: data[0]&0x40 != 0, 47 | EACK: data[0]&0x20 != 0, 48 | RST: data[0]&0x10 != 0, 49 | NUL: data[0]&0x08 != 0, 50 | Version: data[0] & 0x3, 51 | HeaderLength: data[1], 52 | SrcPort: RUDPPort(data[2]), 53 | DstPort: RUDPPort(data[3]), 54 | DataLength: binary.BigEndian.Uint16(data[4:6]), 55 | Seq: binary.BigEndian.Uint32(data[6:10]), 56 | Ack: binary.BigEndian.Uint32(data[10:14]), 57 | Checksum: binary.BigEndian.Uint32(data[14:18]), 58 | } 59 | if r.HeaderLength < 9 { 60 | return fmt.Errorf("RUDP packet with too-short header length %d", r.HeaderLength) 61 | } 62 | hlen := int(r.HeaderLength) * 2 63 | r.Contents = data[:hlen] 64 | r.Payload = data[hlen : hlen+int(r.DataLength)] 65 | r.VariableHeaderArea = data[18:hlen] 66 | headerData := r.VariableHeaderArea 67 | switch { 68 | case r.SYN: 69 | if len(headerData) != 6 { 70 | return fmt.Errorf("RUDP packet invalid SYN header length: %d", len(headerData)) 71 | } 72 | r.RUDPHeaderSYN = &RUDPHeaderSYN{ 73 | MaxOutstandingSegments: binary.BigEndian.Uint16(headerData[:2]), 74 | MaxSegmentSize: binary.BigEndian.Uint16(headerData[2:4]), 75 | OptionFlags: binary.BigEndian.Uint16(headerData[4:6]), 76 | } 77 | case r.EACK: 78 | if len(headerData)%4 != 0 { 79 | return fmt.Errorf("RUDP packet invalid EACK header length: %d", len(headerData)) 80 | } 81 | r.RUDPHeaderEACK = &RUDPHeaderEACK{make([]uint32, len(headerData)/4)} 82 | for i := 0; i < len(headerData); i += 4 { 83 | r.SeqsReceivedOK[i/4] = binary.BigEndian.Uint32(headerData[i : i+4]) 84 | } 85 | } 86 | p.AddLayer(r) 87 | p.SetTransportLayer(r) 88 | return p.NextDecoder(gopacket.LayerTypePayload) 89 | } 90 | 91 | func (r *RUDP) TransportFlow() gopacket.Flow { 92 | return gopacket.NewFlow(EndpointRUDPPort, []byte{byte(r.SrcPort)}, []byte{byte(r.DstPort)}) 93 | } 94 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/checkmgr/cert.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package checkmgr 6 | 7 | import ( 8 | "crypto/x509" 9 | "encoding/json" 10 | "errors" 11 | "fmt" 12 | ) 13 | 14 | // Default Circonus CA certificate 15 | var circonusCA = []byte(`-----BEGIN CERTIFICATE----- 16 | MIID4zCCA0ygAwIBAgIJAMelf8skwVWPMA0GCSqGSIb3DQEBBQUAMIGoMQswCQYD 17 | VQQGEwJVUzERMA8GA1UECBMITWFyeWxhbmQxETAPBgNVBAcTCENvbHVtYmlhMRcw 18 | FQYDVQQKEw5DaXJjb251cywgSW5jLjERMA8GA1UECxMIQ2lyY29udXMxJzAlBgNV 19 | BAMTHkNpcmNvbnVzIENlcnRpZmljYXRlIEF1dGhvcml0eTEeMBwGCSqGSIb3DQEJ 20 | ARYPY2FAY2lyY29udXMubmV0MB4XDTA5MTIyMzE5MTcwNloXDTE5MTIyMTE5MTcw 21 | NlowgagxCzAJBgNVBAYTAlVTMREwDwYDVQQIEwhNYXJ5bGFuZDERMA8GA1UEBxMI 22 | Q29sdW1iaWExFzAVBgNVBAoTDkNpcmNvbnVzLCBJbmMuMREwDwYDVQQLEwhDaXJj 23 | b251czEnMCUGA1UEAxMeQ2lyY29udXMgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MR4w 24 | HAYJKoZIhvcNAQkBFg9jYUBjaXJjb251cy5uZXQwgZ8wDQYJKoZIhvcNAQEBBQAD 25 | gY0AMIGJAoGBAKz2X0/0vJJ4ad1roehFyxUXHdkjJA9msEKwT2ojummdUB3kK5z6 26 | PDzDL9/c65eFYWqrQWVWZSLQK1D+v9xJThCe93v6QkSJa7GZkCq9dxClXVtBmZH3 27 | hNIZZKVC6JMA9dpRjBmlFgNuIdN7q5aJsv8VZHH+QrAyr9aQmhDJAmk1AgMBAAGj 28 | ggERMIIBDTAdBgNVHQ4EFgQUyNTsgZHSkhhDJ5i+6IFlPzKYxsUwgd0GA1UdIwSB 29 | 1TCB0oAUyNTsgZHSkhhDJ5i+6IFlPzKYxsWhga6kgaswgagxCzAJBgNVBAYTAlVT 30 | MREwDwYDVQQIEwhNYXJ5bGFuZDERMA8GA1UEBxMIQ29sdW1iaWExFzAVBgNVBAoT 31 | DkNpcmNvbnVzLCBJbmMuMREwDwYDVQQLEwhDaXJjb251czEnMCUGA1UEAxMeQ2ly 32 | Y29udXMgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MR4wHAYJKoZIhvcNAQkBFg9jYUBj 33 | aXJjb251cy5uZXSCCQDHpX/LJMFVjzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB 34 | BQUAA4GBAAHBtl15BwbSyq0dMEBpEdQYhHianU/rvOMe57digBmox7ZkPEbB/baE 35 | sYJysziA2raOtRxVRtcxuZSMij2RiJDsLxzIp1H60Xhr8lmf7qF6Y+sZl7V36KZb 36 | n2ezaOoRtsQl9dhqEMe8zgL76p9YZ5E69Al0mgiifTteyNjjMuIW 37 | -----END CERTIFICATE-----`) 38 | 39 | // CACert contains cert returned from Circonus API 40 | type CACert struct { 41 | Contents string `json:"contents"` 42 | } 43 | 44 | // loadCACert loads the CA cert for the broker designated by the submission url 45 | func (cm *CheckManager) loadCACert() error { 46 | if cm.certPool != nil { 47 | return nil 48 | } 49 | 50 | cm.certPool = x509.NewCertPool() 51 | 52 | var cert []byte 53 | var err error 54 | 55 | if cm.enabled { 56 | // only attempt to retrieve broker CA cert if 57 | // the check is being managed. 58 | cert, err = cm.fetchCert() 59 | if err != nil { 60 | return err 61 | } 62 | } 63 | 64 | if cert == nil { 65 | cert = circonusCA 66 | } 67 | 68 | cm.certPool.AppendCertsFromPEM(cert) 69 | 70 | return nil 71 | } 72 | 73 | // fetchCert fetches CA certificate using Circonus API 74 | func (cm *CheckManager) fetchCert() ([]byte, error) { 75 | if !cm.enabled { 76 | return nil, errors.New("check manager is not enabled") 77 | } 78 | 79 | response, err := cm.apih.Get("/pki/ca.crt") 80 | if err != nil { 81 | return nil, err 82 | } 83 | 84 | cadata := new(CACert) 85 | if err := json.Unmarshal(response, cadata); err != nil { 86 | return nil, err 87 | } 88 | 89 | if cadata.Contents == "" { 90 | return nil, fmt.Errorf("[ERROR] Unable to find ca cert %+v", cadata) 91 | } 92 | 93 | return []byte(cadata.Contents), nil 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/reassembly/cap2test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build ignore 8 | 9 | package main 10 | 11 | import ( 12 | "bytes" 13 | "flag" 14 | "fmt" 15 | "log" 16 | "os" 17 | "strings" 18 | 19 | "github.com/google/gopacket" 20 | "github.com/google/gopacket/layers" 21 | "github.com/google/gopacket/pcap" 22 | ) 23 | 24 | var input = flag.String("i", "", "Input filename") 25 | 26 | func main() { 27 | var handler *pcap.Handle 28 | var err error 29 | flag.Parse() 30 | if *input == "" { 31 | log.Fatalf("Please specify input filename") 32 | } 33 | if handler, err = pcap.OpenOffline(*input); err != nil { 34 | log.Fatalf("Failed to open: %s: %s", *input, err) 35 | } 36 | args := flag.Args() 37 | if len(args) > 0 { 38 | filter := strings.Join(args, " ") 39 | if err := handler.SetBPFFilter(filter); err != nil { 40 | log.Fatalf("Failed to set BPF filter \"%s\": %s", filter, err) 41 | } 42 | handler.Stats() 43 | } 44 | var decoder gopacket.Decoder 45 | var ok bool 46 | linkType := fmt.Sprintf("%s", handler.LinkType()) 47 | if decoder, ok = gopacket.DecodersByLayerName[linkType]; !ok { 48 | log.Fatalf("Failed to find decoder to pcap's linktype %s", linkType) 49 | } 50 | source := gopacket.NewPacketSource(handler, decoder) 51 | count := uint64(0) 52 | pktNonTcp := uint64(0) 53 | pktTcp := uint64(0) 54 | fmt.Println("test([]testSequence{") 55 | for packet := range source.Packets() { 56 | count++ 57 | tcp := packet.Layer(layers.LayerTypeTCP) 58 | if tcp == nil { 59 | pktNonTcp++ 60 | continue 61 | } else { 62 | pktTcp++ 63 | tcp := tcp.(*layers.TCP) 64 | //fmt.Printf("packet: %s\n", tcp) 65 | var b bytes.Buffer 66 | b.WriteString("{\n") 67 | // TCP 68 | b.WriteString("tcp: layers.TCP{\n") 69 | if tcp.SYN { 70 | b.WriteString(" SYN: true,\n") 71 | } 72 | if tcp.ACK { 73 | b.WriteString(" ACK: true,\n") 74 | } 75 | if tcp.RST { 76 | b.WriteString(" RST: true,\n") 77 | } 78 | if tcp.FIN { 79 | b.WriteString(" FIN: true,\n") 80 | } 81 | b.WriteString(fmt.Sprintf(" SrcPort: %d,\n", tcp.SrcPort)) 82 | b.WriteString(fmt.Sprintf(" DstPort: %d,\n", tcp.DstPort)) 83 | b.WriteString(fmt.Sprintf(" Seq: %d,\n", tcp.Seq)) 84 | b.WriteString(fmt.Sprintf(" Ack: %d,\n", tcp.Ack)) 85 | b.WriteString(" BaseLayer: layers.BaseLayer{Payload: []byte{") 86 | for _, p := range tcp.Payload { 87 | b.WriteString(fmt.Sprintf("%d,", p)) 88 | } 89 | b.WriteString("}},\n") 90 | b.WriteString("},\n") 91 | // CaptureInfo 92 | b.WriteString("ci: gopacket.CaptureInfo{\n") 93 | ts := packet.Metadata().CaptureInfo.Timestamp 94 | b.WriteString(fmt.Sprintf(" Timestamp: time.Unix(%d,%d),\n", ts.Unix(), ts.Nanosecond())) 95 | b.WriteString("},\n") 96 | // Struct 97 | b.WriteString("},\n") 98 | fmt.Print(b.String()) 99 | } 100 | 101 | } 102 | fmt.Println("})") 103 | 104 | fmt.Fprintf(os.Stderr, "Total: %d, TCP: %d, non-TCP: %d\n", count, pktTcp, pktNonTcp) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/pcap/pcap_tester.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | // +build ignore 8 | 9 | // This binary tests that PCAP packet capture is working correctly by issuing 10 | // HTTP requests, then making sure we actually capture data off the wire. 11 | package main 12 | 13 | import ( 14 | "errors" 15 | "flag" 16 | "fmt" 17 | "log" 18 | "net" 19 | "net/http" 20 | "os" 21 | "time" 22 | 23 | "github.com/google/gopacket/pcap" 24 | ) 25 | 26 | var mode = flag.String("mode", "basic", "One of: basic,filtered,timestamp") 27 | 28 | func generatePackets() { 29 | if resp, err := http.Get("http://code.google.com"); err != nil { 30 | log.Printf("Could not get HTTP: %v", err) 31 | } else { 32 | resp.Body.Close() 33 | } 34 | } 35 | 36 | func main() { 37 | flag.Parse() 38 | ifaces, err := net.Interfaces() 39 | if err != nil { 40 | log.Fatal(err) 41 | } 42 | for _, iface := range ifaces { 43 | log.Printf("Trying capture on %q", iface.Name) 44 | if err := tryCapture(iface); err != nil { 45 | log.Printf("Error capturing on %q: %v", iface.Name, err) 46 | } else { 47 | log.Printf("Successfully captured on %q", iface.Name) 48 | return 49 | } 50 | } 51 | os.Exit(1) 52 | } 53 | 54 | func tryCapture(iface net.Interface) error { 55 | if iface.Name[:2] == "lo" { 56 | return errors.New("skipping loopback") 57 | } 58 | var h *pcap.Handle 59 | var err error 60 | switch *mode { 61 | case "basic": 62 | h, err = pcap.OpenLive(iface.Name, 65536, false, time.Second*3) 63 | if err != nil { 64 | return fmt.Errorf("openlive: %v", err) 65 | } 66 | defer h.Close() 67 | case "filtered": 68 | h, err = pcap.OpenLive(iface.Name, 65536, false, time.Second*3) 69 | if err != nil { 70 | return fmt.Errorf("openlive: %v", err) 71 | } 72 | defer h.Close() 73 | if err := h.SetBPFFilter("port 80 or port 443"); err != nil { 74 | return fmt.Errorf("setbpf: %v", err) 75 | } 76 | case "timestamp": 77 | u, err := pcap.NewInactiveHandle(iface.Name) 78 | if err != nil { 79 | return err 80 | } 81 | defer u.CleanUp() 82 | if err = u.SetSnapLen(65536); err != nil { 83 | return err 84 | } else if err = u.SetPromisc(false); err != nil { 85 | return err 86 | } else if err = u.SetTimeout(time.Second * 3); err != nil { 87 | return err 88 | } 89 | sources := u.SupportedTimestamps() 90 | if len(sources) == 0 { 91 | return errors.New("no supported timestamp sources") 92 | } else if err := u.SetTimestampSource(sources[0]); err != nil { 93 | return fmt.Errorf("settimestampsource(%v): %v", sources[0], err) 94 | } else if h, err = u.Activate(); err != nil { 95 | return fmt.Errorf("could not activate: %v", err) 96 | } 97 | defer h.Close() 98 | default: 99 | panic("Invalid --mode: " + *mode) 100 | } 101 | go generatePackets() 102 | h.ReadPacketData() // Do one dummy read to clear any timeouts. 103 | data, ci, err := h.ReadPacketData() 104 | if err != nil { 105 | return fmt.Errorf("readpacketdata: %v", err) 106 | } 107 | log.Printf("Read packet, %v bytes, CI: %+v", len(data), ci) 108 | return nil 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/mpls.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "errors" 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | // MPLS is the MPLS packet header. 16 | type MPLS struct { 17 | BaseLayer 18 | Label uint32 19 | TrafficClass uint8 20 | StackBottom bool 21 | TTL uint8 22 | } 23 | 24 | // LayerType returns gopacket.LayerTypeMPLS. 25 | func (m *MPLS) LayerType() gopacket.LayerType { return LayerTypeMPLS } 26 | 27 | // ProtocolGuessingDecoder attempts to guess the protocol of the bytes it's 28 | // given, then decode the packet accordingly. Its algorithm for guessing is: 29 | // If the packet starts with byte 0x45-0x4F: IPv4 30 | // If the packet starts with byte 0x60-0x6F: IPv6 31 | // Otherwise: Error 32 | // See draft-hsmit-isis-aal5mux-00.txt for more detail on this approach. 33 | type ProtocolGuessingDecoder struct{} 34 | 35 | func (ProtocolGuessingDecoder) Decode(data []byte, p gopacket.PacketBuilder) error { 36 | switch data[0] { 37 | // 0x40 | header_len, where header_len is at least 5. 38 | case 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f: 39 | return decodeIPv4(data, p) 40 | // IPv6 can start with any byte whose first 4 bits are 0x6. 41 | case 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f: 42 | return decodeIPv6(data, p) 43 | } 44 | return errors.New("Unable to guess protocol of packet data") 45 | } 46 | 47 | // MPLSPayloadDecoder is the decoder used to data encapsulated by each MPLS 48 | // layer. MPLS contains no type information, so we have to explicitly decide 49 | // which decoder to use. This is initially set to ProtocolGuessingDecoder, our 50 | // simple attempt at guessing protocols based on the first few bytes of data 51 | // available to us. However, if you know that in your environment MPLS always 52 | // encapsulates a specific protocol, you may reset this. 53 | var MPLSPayloadDecoder gopacket.Decoder = ProtocolGuessingDecoder{} 54 | 55 | func decodeMPLS(data []byte, p gopacket.PacketBuilder) error { 56 | decoded := binary.BigEndian.Uint32(data[:4]) 57 | mpls := &MPLS{ 58 | Label: decoded >> 12, 59 | TrafficClass: uint8(decoded>>9) & 0x7, 60 | StackBottom: decoded&0x100 != 0, 61 | TTL: uint8(decoded), 62 | BaseLayer: BaseLayer{data[:4], data[4:]}, 63 | } 64 | p.AddLayer(mpls) 65 | if mpls.StackBottom { 66 | return p.NextDecoder(MPLSPayloadDecoder) 67 | } 68 | return p.NextDecoder(gopacket.DecodeFunc(decodeMPLS)) 69 | } 70 | 71 | // SerializeTo writes the serialized form of this layer into the 72 | // SerializationBuffer, implementing gopacket.SerializableLayer. 73 | // See the docs for gopacket.SerializableLayer for more info. 74 | func (m *MPLS) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 75 | bytes, err := b.PrependBytes(4) 76 | if err != nil { 77 | return err 78 | } 79 | encoded := m.Label << 12 80 | encoded |= uint32(m.TrafficClass) << 9 81 | encoded |= uint32(m.TTL) 82 | if m.StackBottom { 83 | encoded |= 0x100 84 | } 85 | binary.BigEndian.PutUint32(bytes, encoded) 86 | return nil 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/geneve.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | // Geneve is specifed here https://tools.ietf.org/html/draft-ietf-nvo3-geneve-03 16 | // Geneve Header: 17 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 18 | // |Ver| Opt Len |O|C| Rsvd. | Protocol Type | 19 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 20 | // | Virtual Network Identifier (VNI) | Reserved | 21 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 22 | // | Variable Length Options | 23 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 24 | type Geneve struct { 25 | BaseLayer 26 | Version uint8 // 2 bits 27 | OptionsLength uint8 // 6 bits 28 | OAMPacket bool // 1 bits 29 | CriticalOption bool // 1 bits 30 | Protocol EthernetType // 16 bits 31 | VNI uint32 // 24bits 32 | Options []*GeneveOption 33 | } 34 | 35 | // Geneve Tunnel Options 36 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 37 | // | Option Class | Type |R|R|R| Length | 38 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 39 | // | Variable Option Data | 40 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 41 | type GeneveOption struct { 42 | Class uint16 // 16 bits 43 | Type uint8 // 8 bits 44 | Flags uint8 // 3 bits 45 | Length uint8 // 5 bits 46 | Data []byte 47 | } 48 | 49 | // LayerType returns LayerTypeGeneve 50 | func (gn *Geneve) LayerType() gopacket.LayerType { return LayerTypeGeneve } 51 | 52 | func decodeGeneveOption(data []byte, gn *Geneve) (*GeneveOption, uint8) { 53 | opt := &GeneveOption{} 54 | 55 | opt.Class = binary.BigEndian.Uint16(data[0:1]) 56 | opt.Type = data[2] 57 | opt.Flags = data[3] >> 4 58 | opt.Length = data[3] & 0xf 59 | 60 | copy(opt.Data, data[4:opt.Length]) 61 | 62 | return opt, 4 + opt.Length 63 | } 64 | 65 | func (gn *Geneve) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 66 | gn.Version = data[0] >> 7 67 | gn.OptionsLength = data[0] & 0x3f 68 | 69 | gn.OAMPacket = data[1]&0x80 > 0 70 | gn.CriticalOption = data[1]&0x40 > 0 71 | gn.Protocol = EthernetType(binary.BigEndian.Uint16(data[2:4])) 72 | 73 | var buf [4]byte 74 | copy(buf[1:], data[4:7]) 75 | gn.VNI = binary.BigEndian.Uint32(buf[:]) 76 | 77 | offset, length := uint8(8), gn.OptionsLength 78 | for length > 0 { 79 | opt, len := decodeGeneveOption(data[offset:], gn) 80 | gn.Options = append(gn.Options, opt) 81 | 82 | length -= len 83 | offset += len 84 | } 85 | 86 | gn.BaseLayer = BaseLayer{data[:offset], data[offset:]} 87 | 88 | return nil 89 | } 90 | 91 | func (gn *Geneve) NextLayerType() gopacket.LayerType { 92 | return gn.Protocol.LayerType() 93 | } 94 | 95 | func decodeGeneve(data []byte, p gopacket.PacketBuilder) error { 96 | gn := &Geneve{} 97 | return decodingLayerDecoder(gn, data, p) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/util_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func TestReset(t *testing.T) { 12 | t.Log("Testing util.Reset") 13 | 14 | cm := &CirconusMetrics{} 15 | 16 | cm.counters = make(map[string]uint64) 17 | cm.counterFuncs = make(map[string]func() uint64) 18 | cm.Increment("foo") 19 | 20 | // cm.gauges = make(map[string]string) 21 | cm.gauges = make(map[string]interface{}) 22 | cm.gaugeFuncs = make(map[string]func() int64) 23 | cm.Gauge("foo", 1) 24 | 25 | cm.histograms = make(map[string]*Histogram) 26 | cm.Timing("foo", 1) 27 | 28 | cm.text = make(map[string]string) 29 | cm.textFuncs = make(map[string]func() string) 30 | cm.SetText("foo", "bar") 31 | 32 | if len(cm.counters) != 1 { 33 | t.Errorf("Expected 1, found %d", len(cm.counters)) 34 | } 35 | 36 | if len(cm.gauges) != 1 { 37 | t.Errorf("Expected 1, found %d", len(cm.gauges)) 38 | } 39 | 40 | if len(cm.histograms) != 1 { 41 | t.Errorf("Expected 1, found %d", len(cm.histograms)) 42 | } 43 | 44 | if len(cm.text) != 1 { 45 | t.Errorf("Expected 1, found %d", len(cm.text)) 46 | } 47 | 48 | cm.Reset() 49 | 50 | if len(cm.counters) != 0 { 51 | t.Errorf("Expected 0, found %d", len(cm.counters)) 52 | } 53 | 54 | if len(cm.gauges) != 0 { 55 | t.Errorf("Expected 0, found %d", len(cm.gauges)) 56 | } 57 | 58 | if len(cm.histograms) != 0 { 59 | t.Errorf("Expected 0, found %d", len(cm.histograms)) 60 | } 61 | 62 | if len(cm.text) != 0 { 63 | t.Errorf("Expected 0, found %d", len(cm.text)) 64 | } 65 | } 66 | 67 | func TestSnapshot(t *testing.T) { 68 | t.Log("Testing util.snapshot") 69 | 70 | cm := &CirconusMetrics{} 71 | 72 | cm.resetCounters = true 73 | cm.counters = make(map[string]uint64) 74 | cm.counterFuncs = make(map[string]func() uint64) 75 | cm.Increment("foo") 76 | 77 | cm.resetGauges = true 78 | // cm.gauges = make(map[string]string) 79 | cm.gauges = make(map[string]interface{}) 80 | cm.gaugeFuncs = make(map[string]func() int64) 81 | cm.Gauge("foo", 1) 82 | 83 | cm.resetHistograms = true 84 | cm.histograms = make(map[string]*Histogram) 85 | cm.Timing("foo", 1) 86 | 87 | cm.resetText = true 88 | cm.text = make(map[string]string) 89 | cm.textFuncs = make(map[string]func() string) 90 | cm.SetText("foo", "bar") 91 | 92 | if len(cm.counters) != 1 { 93 | t.Errorf("Expected 1, found %d", len(cm.counters)) 94 | } 95 | 96 | if len(cm.gauges) != 1 { 97 | t.Errorf("Expected 1, found %d", len(cm.gauges)) 98 | } 99 | 100 | if len(cm.histograms) != 1 { 101 | t.Errorf("Expected 1, found %d", len(cm.histograms)) 102 | } 103 | 104 | if len(cm.text) != 1 { 105 | t.Errorf("Expected 1, found %d", len(cm.text)) 106 | } 107 | 108 | counters, gauges, histograms, text := cm.snapshot() 109 | 110 | if len(counters) != 1 { 111 | t.Errorf("Expected 1, found %d", len(counters)) 112 | } 113 | 114 | if len(gauges) != 1 { 115 | t.Errorf("Expected 1, found %d", len(gauges)) 116 | } 117 | 118 | if len(histograms) != 1 { 119 | t.Errorf("Expected 1, found %d", len(histograms)) 120 | } 121 | 122 | if len(text) != 1 { 123 | t.Errorf("Expected 1, found %d", len(text)) 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/radiotap_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | package layers 7 | 8 | import ( 9 | "github.com/google/gopacket" 10 | "testing" 11 | ) 12 | 13 | // testPacketRadiotap0 is the packet: 14 | // 09:34:34.799438 1.0 Mb/s 2412 MHz 11b -58dB signal antenna 7 Acknowledgment RA:88:1f:a1:ae:9d:cb 15 | // 0x0000: 0000 1200 2e48 0000 1002 6c09 a000 c607 .....H....l..... 16 | // 0x0010: 0000 d400 0000 881f a1ae 9dcb c630 4b4b .............0KK 17 | var testPacketRadiotap0 = []byte{ 18 | 0x00, 0x00, 0x12, 0x00, 0x2e, 0x48, 0x00, 0x00, 0x10, 0x02, 0x6c, 0x09, 0xa0, 0x00, 0xc6, 0x07, 19 | 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x88, 0x1f, 0xa1, 0xae, 0x9d, 0xcb, 0xc6, 0x30, 0x4b, 0x4b, 20 | } 21 | 22 | func TestPacketRadiotap0(t *testing.T) { 23 | p := gopacket.NewPacket(testPacketRadiotap0, LayerTypeRadioTap, gopacket.Default) 24 | if p.ErrorLayer() != nil { 25 | t.Error("Failed to decode packet:", p.ErrorLayer().Error()) 26 | } 27 | checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t) 28 | rt := p.Layer(LayerTypeRadioTap).(*RadioTap) 29 | if rt.ChannelFrequency != 2412 || rt.DBMAntennaSignal != -58 || rt.Antenna != 7 { 30 | t.Error("Radiotap decode error") 31 | } 32 | if rt.Rate != 2 { // 500Kbps unit 33 | t.Error("Radiotap Rate decode error") 34 | } 35 | } 36 | func BenchmarkDecodePacketRadiotap0(b *testing.B) { 37 | for i := 0; i < b.N; i++ { 38 | gopacket.NewPacket(testPacketRadiotap0, LayerTypeRadioTap, gopacket.NoCopy) 39 | } 40 | } 41 | 42 | // testPacketRadiotap1 is the packet: 43 | // 05:24:21.380948 2412 MHz 11g -36dB signal antenna 5 65.0 Mb/s MCS 7 20 MHz lon GI 44 | // 0x0000: 0000 1500 2a48 0800 1000 6c09 8004 dc05 ....*H....l..... 45 | // 0x0010: 0000 0700 0748 112c 0000 3a9d aaf0 191c .....H.,..:..... 46 | // 0x0020: aba7 f213 9d00 3a9d aaf0 1970 b2ee a9f1 ......:....p.... 47 | // 0x0030: 16 . 48 | var testPacketRadiotap1 = []byte{ 49 | 0x00, 0x00, 0x15, 0x00, 0x2a, 0x48, 0x08, 0x00, 0x10, 0x00, 0x6c, 0x09, 0x80, 0x04, 0xdc, 0x05, 50 | 0x00, 0x00, 0x07, 0x00, 0x07, 0x48, 0x11, 0x2c, 0x00, 0x00, 0x3a, 0x9d, 0xaa, 0xf0, 0x19, 0x1c, 51 | 0xab, 0xa7, 0xf2, 0x13, 0x9d, 0x00, 0x3a, 0x9d, 0xaa, 0xf0, 0x19, 0x70, 0xb2, 0xee, 0xa9, 0xf1, 52 | 0x16, 53 | } 54 | 55 | func TestPacketRadiotap1(t *testing.T) { 56 | p := gopacket.NewPacket(testPacketRadiotap1, LayerTypeRadioTap, gopacket.Default) 57 | if p.ErrorLayer() != nil { 58 | t.Error("Failed to decode packet:", p.ErrorLayer().Error()) 59 | } 60 | checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t) 61 | rt := p.Layer(LayerTypeRadioTap).(*RadioTap) 62 | if rt.ChannelFrequency != 2412 || rt.DBMAntennaSignal != -36 || rt.Antenna != 5 { 63 | t.Error("Radiotap decode error") 64 | } 65 | if !rt.MCS.Known.MCSIndex() || rt.MCS.MCS != 7 { 66 | t.Error("Radiotap MCS error") 67 | } 68 | if !rt.MCS.Known.Bandwidth() || rt.MCS.Flags.Bandwidth() != 0 { 69 | t.Error("Radiotap bandwidth error") 70 | } 71 | if !rt.MCS.Known.GuardInterval() || rt.MCS.Flags.ShortGI() { 72 | t.Error("Radiotap GI error") 73 | } 74 | } 75 | func BenchmarkDecodePacketRadiotap1(b *testing.B) { 76 | for i := 0; i < b.N; i++ { 77 | gopacket.NewPacket(testPacketRadiotap1, LayerTypeRadioTap, gopacket.NoCopy) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/tcpassembly/tcpreader/reader_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package tcpreader 8 | 9 | import ( 10 | "bytes" 11 | "fmt" 12 | "github.com/google/gopacket" 13 | "github.com/google/gopacket/layers" 14 | "github.com/google/gopacket/tcpassembly" 15 | "io" 16 | "net" 17 | "testing" 18 | ) 19 | 20 | var netFlow gopacket.Flow 21 | 22 | func init() { 23 | netFlow, _ = gopacket.FlowFromEndpoints( 24 | layers.NewIPEndpoint(net.IP{1, 2, 3, 4}), 25 | layers.NewIPEndpoint(net.IP{5, 6, 7, 8})) 26 | } 27 | 28 | type readReturn struct { 29 | data []byte 30 | err error 31 | } 32 | type readSequence struct { 33 | in []layers.TCP 34 | want []readReturn 35 | } 36 | type testReaderFactory struct { 37 | lossErrors bool 38 | readSize int 39 | ReaderStream 40 | output chan []byte 41 | } 42 | 43 | func (t *testReaderFactory) New(a, b gopacket.Flow) tcpassembly.Stream { 44 | return &t.ReaderStream 45 | } 46 | 47 | func testReadSequence(t *testing.T, lossErrors bool, readSize int, seq readSequence) { 48 | f := &testReaderFactory{ReaderStream: NewReaderStream()} 49 | f.ReaderStream.LossErrors = lossErrors 50 | p := tcpassembly.NewStreamPool(f) 51 | a := tcpassembly.NewAssembler(p) 52 | buf := make([]byte, readSize) 53 | go func() { 54 | for i, test := range seq.in { 55 | fmt.Println("Assembling", i) 56 | a.Assemble(netFlow, &test) 57 | fmt.Println("Assembly done") 58 | } 59 | }() 60 | for i, test := range seq.want { 61 | fmt.Println("Waiting for read", i) 62 | n, err := f.Read(buf[:]) 63 | fmt.Println("Got read") 64 | if n != len(test.data) { 65 | t.Errorf("test %d want %d bytes, got %d bytes", i, len(test.data), n) 66 | } else if err != test.err { 67 | t.Errorf("test %d want err %v, got err %v", i, test.err, err) 68 | } else if !bytes.Equal(buf[:n], test.data) { 69 | t.Errorf("test %d\nwant: %v\n got: %v\n", i, test.data, buf[:n]) 70 | } 71 | } 72 | fmt.Println("All done reads") 73 | } 74 | 75 | func TestRead(t *testing.T) { 76 | testReadSequence(t, false, 10, readSequence{ 77 | in: []layers.TCP{ 78 | { 79 | SYN: true, 80 | SrcPort: 1, 81 | DstPort: 2, 82 | Seq: 1000, 83 | BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3}}, 84 | }, 85 | { 86 | FIN: true, 87 | SrcPort: 1, 88 | DstPort: 2, 89 | Seq: 1004, 90 | }, 91 | }, 92 | want: []readReturn{ 93 | {data: []byte{1, 2, 3}}, 94 | {err: io.EOF}, 95 | }, 96 | }) 97 | } 98 | 99 | func TestReadSmallChunks(t *testing.T) { 100 | testReadSequence(t, false, 2, readSequence{ 101 | in: []layers.TCP{ 102 | { 103 | SYN: true, 104 | SrcPort: 1, 105 | DstPort: 2, 106 | Seq: 1000, 107 | BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3}}, 108 | }, 109 | { 110 | FIN: true, 111 | SrcPort: 1, 112 | DstPort: 2, 113 | Seq: 1004, 114 | }, 115 | }, 116 | want: []readReturn{ 117 | {data: []byte{1, 2}}, 118 | {data: []byte{3}}, 119 | {err: io.EOF}, 120 | }, 121 | }) 122 | } 123 | 124 | func ExampleDiscardBytesToEOF() { 125 | b := bytes.NewBuffer([]byte{1, 2, 3, 4, 5}) 126 | fmt.Println(DiscardBytesToEOF(b)) 127 | // Output: 128 | // 5 129 | } 130 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | import ( 8 | "github.com/circonus-labs/circonusllhist" 9 | ) 10 | 11 | // Reset removes all existing counters and gauges. 12 | func (m *CirconusMetrics) Reset() { 13 | m.cm.Lock() 14 | defer m.cm.Unlock() 15 | 16 | m.cfm.Lock() 17 | defer m.cfm.Unlock() 18 | 19 | m.gm.Lock() 20 | defer m.gm.Unlock() 21 | 22 | m.gfm.Lock() 23 | defer m.gfm.Unlock() 24 | 25 | m.hm.Lock() 26 | defer m.hm.Unlock() 27 | 28 | m.tm.Lock() 29 | defer m.tm.Unlock() 30 | 31 | m.tfm.Lock() 32 | defer m.tfm.Unlock() 33 | 34 | m.counters = make(map[string]uint64) 35 | m.counterFuncs = make(map[string]func() uint64) 36 | m.gauges = make(map[string]interface{}) 37 | m.gaugeFuncs = make(map[string]func() int64) 38 | m.histograms = make(map[string]*Histogram) 39 | m.text = make(map[string]string) 40 | m.textFuncs = make(map[string]func() string) 41 | } 42 | 43 | // snapshot returns a copy of the values of all registered counters and gauges. 44 | func (m *CirconusMetrics) snapshot() (c map[string]uint64, g map[string]interface{}, h map[string]*circonusllhist.Histogram, t map[string]string) { 45 | c = m.snapCounters() 46 | g = m.snapGauges() 47 | h = m.snapHistograms() 48 | t = m.snapText() 49 | 50 | return 51 | } 52 | 53 | func (m *CirconusMetrics) snapCounters() map[string]uint64 { 54 | m.cm.Lock() 55 | defer m.cm.Unlock() 56 | m.cfm.Lock() 57 | defer m.cfm.Unlock() 58 | 59 | c := make(map[string]uint64, len(m.counters)+len(m.counterFuncs)) 60 | 61 | for n, v := range m.counters { 62 | c[n] = v 63 | } 64 | if m.resetCounters && len(c) > 0 { 65 | m.counters = make(map[string]uint64) 66 | } 67 | 68 | for n, f := range m.counterFuncs { 69 | c[n] = f() 70 | } 71 | 72 | return c 73 | } 74 | 75 | func (m *CirconusMetrics) snapGauges() map[string]interface{} { 76 | m.gm.Lock() 77 | defer m.gm.Unlock() 78 | m.gfm.Lock() 79 | defer m.gfm.Unlock() 80 | 81 | g := make(map[string]interface{}, len(m.gauges)+len(m.gaugeFuncs)) 82 | 83 | for n, v := range m.gauges { 84 | g[n] = v 85 | } 86 | if m.resetGauges && len(g) > 0 { 87 | m.gauges = make(map[string]interface{}) 88 | } 89 | 90 | for n, f := range m.gaugeFuncs { 91 | g[n] = f() 92 | } 93 | 94 | return g 95 | } 96 | 97 | func (m *CirconusMetrics) snapHistograms() map[string]*circonusllhist.Histogram { 98 | m.hm.Lock() 99 | defer m.hm.Unlock() 100 | 101 | h := make(map[string]*circonusllhist.Histogram, len(m.histograms)) 102 | 103 | for n, hist := range m.histograms { 104 | hist.rw.Lock() 105 | h[n] = hist.hist.CopyAndReset() 106 | hist.rw.Unlock() 107 | } 108 | if m.resetHistograms && len(h) > 0 { 109 | m.histograms = make(map[string]*Histogram) 110 | } 111 | 112 | return h 113 | } 114 | 115 | func (m *CirconusMetrics) snapText() map[string]string { 116 | m.tm.Lock() 117 | defer m.tm.Unlock() 118 | m.tfm.Lock() 119 | defer m.tfm.Unlock() 120 | 121 | t := make(map[string]string, len(m.text)+len(m.textFuncs)) 122 | 123 | for n, v := range m.text { 124 | t[n] = v 125 | } 126 | if m.resetText && len(t) > 0 { 127 | m.text = make(map[string]string) 128 | } 129 | 130 | for n, f := range m.textFuncs { 131 | t[n] = f() 132 | } 133 | 134 | return t 135 | } 136 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layerclass.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package gopacket 8 | 9 | // LayerClass is a set of LayerTypes, used for grabbing one of a number of 10 | // different types from a packet. 11 | type LayerClass interface { 12 | // Contains returns true if the given layer type should be considered part 13 | // of this layer class. 14 | Contains(LayerType) bool 15 | // LayerTypes returns the set of all layer types in this layer class. 16 | // Note that this may not be a fast operation on all LayerClass 17 | // implementations. 18 | LayerTypes() []LayerType 19 | } 20 | 21 | // Contains implements LayerClass. 22 | func (l LayerType) Contains(a LayerType) bool { 23 | return l == a 24 | } 25 | 26 | // LayerTypes implements LayerClass. 27 | func (l LayerType) LayerTypes() []LayerType { 28 | return []LayerType{l} 29 | } 30 | 31 | // LayerClassSlice implements a LayerClass with a slice. 32 | type LayerClassSlice []bool 33 | 34 | // Contains returns true if the given layer type should be considered part 35 | // of this layer class. 36 | func (s LayerClassSlice) Contains(t LayerType) bool { 37 | return int(t) < len(s) && s[t] 38 | } 39 | 40 | // LayerTypes returns all layer types in this LayerClassSlice. 41 | // Because of LayerClassSlice's implementation, this could be quite slow. 42 | func (s LayerClassSlice) LayerTypes() (all []LayerType) { 43 | for i := 0; i < len(s); i++ { 44 | if s[i] { 45 | all = append(all, LayerType(i)) 46 | } 47 | } 48 | return 49 | } 50 | 51 | // NewLayerClassSlice creates a new LayerClassSlice by creating a slice of 52 | // size max(types) and setting slice[t] to true for each type t. Note, if 53 | // you implement your own LayerType and give it a high value, this WILL create 54 | // a very large slice. 55 | func NewLayerClassSlice(types []LayerType) LayerClassSlice { 56 | var max LayerType 57 | for _, typ := range types { 58 | if typ > max { 59 | max = typ 60 | } 61 | } 62 | t := make([]bool, int(max+1)) 63 | for _, typ := range types { 64 | t[typ] = true 65 | } 66 | return t 67 | } 68 | 69 | // LayerClassMap implements a LayerClass with a map. 70 | type LayerClassMap map[LayerType]bool 71 | 72 | // Contains returns true if the given layer type should be considered part 73 | // of this layer class. 74 | func (m LayerClassMap) Contains(t LayerType) bool { 75 | return m[t] 76 | } 77 | 78 | // LayerTypes returns all layer types in this LayerClassMap. 79 | func (m LayerClassMap) LayerTypes() (all []LayerType) { 80 | for t := range m { 81 | all = append(all, t) 82 | } 83 | return 84 | } 85 | 86 | // NewLayerClassMap creates a LayerClassMap and sets map[t] to true for each 87 | // type in types. 88 | func NewLayerClassMap(types []LayerType) LayerClassMap { 89 | m := LayerClassMap{} 90 | for _, typ := range types { 91 | m[typ] = true 92 | } 93 | return m 94 | } 95 | 96 | // NewLayerClass creates a LayerClass, attempting to be smart about which type 97 | // it creates based on which types are passed in. 98 | func NewLayerClass(types []LayerType) LayerClass { 99 | for _, typ := range types { 100 | if typ > maxLayerType { 101 | // NewLayerClassSlice could create a very large object, so instead create 102 | // a map. 103 | return NewLayerClassMap(types) 104 | } 105 | } 106 | return NewLayerClassSlice(types) 107 | } 108 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/decode_other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Snappy-Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64 appengine !gc noasm 6 | 7 | package snappy 8 | 9 | // decode writes the decoding of src to dst. It assumes that the varint-encoded 10 | // length of the decompressed bytes has already been read, and that len(dst) 11 | // equals that length. 12 | // 13 | // It returns 0 on success or a decodeErrCodeXxx error code on failure. 14 | func decode(dst, src []byte) int { 15 | var d, s, offset, length int 16 | for s < len(src) { 17 | switch src[s] & 0x03 { 18 | case tagLiteral: 19 | x := uint32(src[s] >> 2) 20 | switch { 21 | case x < 60: 22 | s++ 23 | case x == 60: 24 | s += 2 25 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 26 | return decodeErrCodeCorrupt 27 | } 28 | x = uint32(src[s-1]) 29 | case x == 61: 30 | s += 3 31 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 32 | return decodeErrCodeCorrupt 33 | } 34 | x = uint32(src[s-2]) | uint32(src[s-1])<<8 35 | case x == 62: 36 | s += 4 37 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 38 | return decodeErrCodeCorrupt 39 | } 40 | x = uint32(src[s-3]) | uint32(src[s-2])<<8 | uint32(src[s-1])<<16 41 | case x == 63: 42 | s += 5 43 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 44 | return decodeErrCodeCorrupt 45 | } 46 | x = uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24 47 | } 48 | length = int(x) + 1 49 | if length <= 0 { 50 | return decodeErrCodeUnsupportedLiteralLength 51 | } 52 | if length > len(dst)-d || length > len(src)-s { 53 | return decodeErrCodeCorrupt 54 | } 55 | copy(dst[d:], src[s:s+length]) 56 | d += length 57 | s += length 58 | continue 59 | 60 | case tagCopy1: 61 | s += 2 62 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 63 | return decodeErrCodeCorrupt 64 | } 65 | length = 4 + int(src[s-2])>>2&0x7 66 | offset = int(uint32(src[s-2])&0xe0<<3 | uint32(src[s-1])) 67 | 68 | case tagCopy2: 69 | s += 3 70 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 71 | return decodeErrCodeCorrupt 72 | } 73 | length = 1 + int(src[s-3])>>2 74 | offset = int(uint32(src[s-2]) | uint32(src[s-1])<<8) 75 | 76 | case tagCopy4: 77 | s += 5 78 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 79 | return decodeErrCodeCorrupt 80 | } 81 | length = 1 + int(src[s-5])>>2 82 | offset = int(uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24) 83 | } 84 | 85 | if offset <= 0 || d < offset || length > len(dst)-d { 86 | return decodeErrCodeCorrupt 87 | } 88 | // Copy from an earlier sub-slice of dst to a later sub-slice. Unlike 89 | // the built-in copy function, this byte-by-byte copy always runs 90 | // forwards, even if the slices overlap. Conceptually, this is: 91 | // 92 | // d += forwardCopy(dst[d:d+length], dst[d-offset:]) 93 | for end := d + length; d != end; d++ { 94 | dst[d] = dst[d-offset] 95 | } 96 | } 97 | if d != len(dst) { 98 | return decodeErrCodeCorrupt 99 | } 100 | return 0 101 | } 102 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/api/check.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Check API support - Fetch and Search 6 | // See: https://login.circonus.com/resources/api/calls/check 7 | // Notes: checks do not directly support create, update, and delete - see check bundle. 8 | 9 | package api 10 | 11 | import ( 12 | "encoding/json" 13 | "fmt" 14 | "net/url" 15 | "regexp" 16 | 17 | "github.com/circonus-labs/circonus-gometrics/api/config" 18 | ) 19 | 20 | // CheckDetails contains [undocumented] check type specific information 21 | type CheckDetails map[config.Key]string 22 | 23 | // Check defines a check. See https://login.circonus.com/resources/api/calls/check for more information. 24 | type Check struct { 25 | Active bool `json:"_active"` // bool 26 | BrokerCID string `json:"_broker"` // string 27 | CheckBundleCID string `json:"_check_bundle"` // string 28 | CheckUUID string `json:"_check_uuid"` // string 29 | CID string `json:"_cid"` // string 30 | Details CheckDetails `json:"_details"` // NOTE contents of details are check type specific, map len >= 0 31 | } 32 | 33 | // FetchCheck retrieves check with passed cid. 34 | func (a *API) FetchCheck(cid CIDType) (*Check, error) { 35 | if cid == nil || *cid == "" { 36 | return nil, fmt.Errorf("Invalid check CID [none]") 37 | } 38 | 39 | checkCID := string(*cid) 40 | 41 | matched, err := regexp.MatchString(config.CheckCIDRegex, checkCID) 42 | if err != nil { 43 | return nil, err 44 | } 45 | if !matched { 46 | return nil, fmt.Errorf("Invalid check CID [%s]", checkCID) 47 | } 48 | 49 | result, err := a.Get(checkCID) 50 | if err != nil { 51 | return nil, err 52 | } 53 | 54 | if a.Debug { 55 | a.Log.Printf("[DEBUG] fetch check, received JSON: %s", string(result)) 56 | } 57 | 58 | check := new(Check) 59 | if err := json.Unmarshal(result, check); err != nil { 60 | return nil, err 61 | } 62 | 63 | return check, nil 64 | } 65 | 66 | // FetchChecks retrieves all checks available to the API Token. 67 | func (a *API) FetchChecks() (*[]Check, error) { 68 | result, err := a.Get(config.CheckPrefix) 69 | if err != nil { 70 | return nil, err 71 | } 72 | 73 | var checks []Check 74 | if err := json.Unmarshal(result, &checks); err != nil { 75 | return nil, err 76 | } 77 | 78 | return &checks, nil 79 | } 80 | 81 | // SearchChecks returns checks matching the specified search query 82 | // and/or filter. If nil is passed for both parameters all checks 83 | // will be returned. 84 | func (a *API) SearchChecks(searchCriteria *SearchQueryType, filterCriteria *SearchFilterType) (*[]Check, error) { 85 | q := url.Values{} 86 | 87 | if searchCriteria != nil && *searchCriteria != "" { 88 | q.Set("search", string(*searchCriteria)) 89 | } 90 | 91 | if filterCriteria != nil && len(*filterCriteria) > 0 { 92 | for filter, criteria := range *filterCriteria { 93 | for _, val := range criteria { 94 | q.Add(filter, val) 95 | } 96 | } 97 | } 98 | 99 | if q.Encode() == "" { 100 | return a.FetchChecks() 101 | } 102 | 103 | reqURL := url.URL{ 104 | Path: config.CheckPrefix, 105 | RawQuery: q.Encode(), 106 | } 107 | 108 | result, err := a.Get(reqURL.String()) 109 | if err != nil { 110 | return nil, err 111 | } 112 | 113 | var checks []Check 114 | if err := json.Unmarshal(result, &checks); err != nil { 115 | return nil, err 116 | } 117 | 118 | return &checks, nil 119 | } 120 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/gauge.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package circonusgometrics 6 | 7 | // A Gauge is an instantaneous measurement of a value. 8 | // 9 | // Use a gauge to track metrics which increase and decrease (e.g., amount of 10 | // free memory). 11 | 12 | import ( 13 | "fmt" 14 | ) 15 | 16 | // Gauge sets a gauge to a value 17 | func (m *CirconusMetrics) Gauge(metric string, val interface{}) { 18 | m.SetGauge(metric, val) 19 | } 20 | 21 | // SetGauge sets a gauge to a value 22 | func (m *CirconusMetrics) SetGauge(metric string, val interface{}) { 23 | m.gm.Lock() 24 | defer m.gm.Unlock() 25 | m.gauges[metric] = val 26 | } 27 | 28 | // AddGauge adds value to existing gauge 29 | func (m *CirconusMetrics) AddGauge(metric string, val interface{}) { 30 | m.gm.Lock() 31 | defer m.gm.Unlock() 32 | 33 | v, ok := m.gauges[metric] 34 | if !ok { 35 | m.gauges[metric] = val 36 | return 37 | } 38 | 39 | switch val.(type) { 40 | default: 41 | // ignore it, unsupported type 42 | case int: 43 | m.gauges[metric] = v.(int) + val.(int) 44 | case int8: 45 | m.gauges[metric] = v.(int8) + val.(int8) 46 | case int16: 47 | m.gauges[metric] = v.(int16) + val.(int16) 48 | case int32: 49 | m.gauges[metric] = v.(int32) + val.(int32) 50 | case int64: 51 | m.gauges[metric] = v.(int64) + val.(int64) 52 | case uint: 53 | m.gauges[metric] = v.(uint) + val.(uint) 54 | case uint8: 55 | m.gauges[metric] = v.(uint8) + val.(uint8) 56 | case uint16: 57 | m.gauges[metric] = v.(uint16) + val.(uint16) 58 | case uint32: 59 | m.gauges[metric] = v.(uint32) + val.(uint32) 60 | case uint64: 61 | m.gauges[metric] = v.(uint64) + val.(uint64) 62 | case float32: 63 | m.gauges[metric] = v.(float32) + val.(float32) 64 | case float64: 65 | m.gauges[metric] = v.(float64) + val.(float64) 66 | } 67 | } 68 | 69 | // RemoveGauge removes a gauge 70 | func (m *CirconusMetrics) RemoveGauge(metric string) { 71 | m.gm.Lock() 72 | defer m.gm.Unlock() 73 | delete(m.gauges, metric) 74 | } 75 | 76 | // GetGaugeTest returns the current value for a gauge. (note: it is a function specifically for "testing", disable automatic submission during testing.) 77 | func (m *CirconusMetrics) GetGaugeTest(metric string) (interface{}, error) { 78 | m.gm.Lock() 79 | defer m.gm.Unlock() 80 | 81 | if val, ok := m.gauges[metric]; ok { 82 | return val, nil 83 | } 84 | 85 | return nil, fmt.Errorf("Gauge metric '%s' not found", metric) 86 | } 87 | 88 | // SetGaugeFunc sets a gauge to a function [called at flush interval] 89 | func (m *CirconusMetrics) SetGaugeFunc(metric string, fn func() int64) { 90 | m.gfm.Lock() 91 | defer m.gfm.Unlock() 92 | m.gaugeFuncs[metric] = fn 93 | } 94 | 95 | // RemoveGaugeFunc removes a gauge function 96 | func (m *CirconusMetrics) RemoveGaugeFunc(metric string) { 97 | m.gfm.Lock() 98 | defer m.gfm.Unlock() 99 | delete(m.gaugeFuncs, metric) 100 | } 101 | 102 | // getGaugeType returns accurate resmon type for underlying type of gauge value 103 | func (m *CirconusMetrics) getGaugeType(v interface{}) string { 104 | mt := "n" 105 | switch v.(type) { 106 | case int: 107 | mt = "i" 108 | case int8: 109 | mt = "i" 110 | case int16: 111 | mt = "i" 112 | case int32: 113 | mt = "i" 114 | case uint: 115 | mt = "I" 116 | case uint8: 117 | mt = "I" 118 | case uint16: 119 | mt = "I" 120 | case uint32: 121 | mt = "I" 122 | case int64: 123 | mt = "l" 124 | case uint64: 125 | mt = "L" 126 | } 127 | 128 | return mt 129 | } 130 | -------------------------------------------------------------------------------- /vendor/github.com/circonus-labs/circonus-gometrics/api/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Circonus, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package api provides methods for interacting with the Circonus API. See the full Circonus API 7 | Documentation at https://login.circonus.com/resources/api for more information. 8 | 9 | Raw REST methods 10 | 11 | Get - retrieve existing item(s) 12 | Put - update an existing item 13 | Post - create a new item 14 | Delete - remove an existing item 15 | 16 | Endpoints (supported) 17 | 18 | Account https://login.circonus.com/resources/api/calls/account 19 | Acknowledgement https://login.circonus.com/resources/api/calls/acknowledgement 20 | Alert https://login.circonus.com/resources/api/calls/alert 21 | Annotation https://login.circonus.com/resources/api/calls/annotation 22 | Broker https://login.circonus.com/resources/api/calls/broker 23 | Check https://login.circonus.com/resources/api/calls/check 24 | Check Bundle https://login.circonus.com/resources/api/calls/check_bundle 25 | Check Bundle Metrics https://login.circonus.com/resources/api/calls/check_bundle_metrics 26 | Contact Group https://login.circonus.com/resources/api/calls/contact_group 27 | Dashboard https://login.circonus.com/resources/api/calls/dashboard 28 | Graph https://login.circonus.com/resources/api/calls/graph 29 | Maintenance [window] https://login.circonus.com/resources/api/calls/maintenance 30 | Metric https://login.circonus.com/resources/api/calls/metric 31 | Metric Cluster https://login.circonus.com/resources/api/calls/metric_cluster 32 | Outlier Report https://login.circonus.com/resources/api/calls/outlier_report 33 | Provision Broker https://login.circonus.com/resources/api/calls/provision_broker 34 | Rule Set https://login.circonus.com/resources/api/calls/rule_set 35 | Rule Set Group https://login.circonus.com/resources/api/calls/rule_set_group 36 | User https://login.circonus.com/resources/api/calls/user 37 | Worksheet https://login.circonus.com/resources/api/calls/worksheet 38 | 39 | Endpoints (not supported) 40 | 41 | Support may be added for these endpoints in the future. These endpoints may currently be used 42 | directly with the Raw REST methods above. 43 | 44 | CAQL https://login.circonus.com/resources/api/calls/caql 45 | Check Move https://login.circonus.com/resources/api/calls/check_move 46 | Data https://login.circonus.com/resources/api/calls/data 47 | Snapshot https://login.circonus.com/resources/api/calls/snapshot 48 | Tag https://login.circonus.com/resources/api/calls/tag 49 | Template https://login.circonus.com/resources/api/calls/template 50 | 51 | Verbs 52 | 53 | Fetch singular/plural item(s) - e.g. FetchAnnotation, FetchAnnotations 54 | Create create new item - e.g. CreateAnnotation 55 | Update update an item - e.g. UpdateAnnotation 56 | Delete remove an item - e.g. DeleteAnnotation, DeleteAnnotationByCID 57 | Search search for item(s) - e.g. SearchAnnotations 58 | New new item config - e.g. NewAnnotation (returns an empty item, 59 | any applicable defaults defined) 60 | 61 | Not all endpoints support all verbs. 62 | */ 63 | package api 64 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/udp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style license 5 | // that can be found in the LICENSE file in the root of the source 6 | // tree. 7 | 8 | package layers 9 | 10 | import ( 11 | "encoding/binary" 12 | "fmt" 13 | "github.com/google/gopacket" 14 | ) 15 | 16 | // UDP is the layer for UDP headers. 17 | type UDP struct { 18 | BaseLayer 19 | SrcPort, DstPort UDPPort 20 | Length uint16 21 | Checksum uint16 22 | sPort, dPort []byte 23 | tcpipchecksum 24 | } 25 | 26 | // LayerType returns gopacket.LayerTypeUDP 27 | func (u *UDP) LayerType() gopacket.LayerType { return LayerTypeUDP } 28 | 29 | func (udp *UDP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 30 | udp.SrcPort = UDPPort(binary.BigEndian.Uint16(data[0:2])) 31 | udp.sPort = data[0:2] 32 | udp.DstPort = UDPPort(binary.BigEndian.Uint16(data[2:4])) 33 | udp.dPort = data[2:4] 34 | udp.Length = binary.BigEndian.Uint16(data[4:6]) 35 | udp.Checksum = binary.BigEndian.Uint16(data[6:8]) 36 | udp.BaseLayer = BaseLayer{Contents: data[:8]} 37 | switch { 38 | case udp.Length >= 8: 39 | hlen := int(udp.Length) 40 | if hlen > len(data) { 41 | df.SetTruncated() 42 | hlen = len(data) 43 | } 44 | udp.Payload = data[8:hlen] 45 | case udp.Length == 0: // Jumbogram, use entire rest of data 46 | udp.Payload = data[8:] 47 | default: 48 | return fmt.Errorf("UDP packet too small: %d bytes", udp.Length) 49 | } 50 | return nil 51 | } 52 | 53 | // SerializeTo writes the serialized form of this layer into the 54 | // SerializationBuffer, implementing gopacket.SerializableLayer. 55 | // See the docs for gopacket.SerializableLayer for more info. 56 | func (u *UDP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 57 | var jumbo bool 58 | 59 | payload := b.Bytes() 60 | if _, ok := u.pseudoheader.(*IPv6); ok { 61 | if len(payload)+8 > 65535 { 62 | jumbo = true 63 | } 64 | } 65 | bytes, err := b.PrependBytes(8) 66 | if err != nil { 67 | return err 68 | } 69 | binary.BigEndian.PutUint16(bytes, uint16(u.SrcPort)) 70 | binary.BigEndian.PutUint16(bytes[2:], uint16(u.DstPort)) 71 | if opts.FixLengths { 72 | if jumbo { 73 | u.Length = 0 74 | } else { 75 | u.Length = uint16(len(payload)) + 8 76 | } 77 | } 78 | binary.BigEndian.PutUint16(bytes[4:], u.Length) 79 | if opts.ComputeChecksums { 80 | // zero out checksum bytes 81 | bytes[6] = 0 82 | bytes[7] = 0 83 | csum, err := u.computeChecksum(b.Bytes(), IPProtocolUDP) 84 | if err != nil { 85 | return err 86 | } 87 | u.Checksum = csum 88 | } 89 | binary.BigEndian.PutUint16(bytes[6:], u.Checksum) 90 | return nil 91 | } 92 | 93 | func (u *UDP) CanDecode() gopacket.LayerClass { 94 | return LayerTypeUDP 95 | } 96 | 97 | // NextLayerType use the destination port to select the 98 | // right next decoder. It tries first to decode via the 99 | // destination port, then the source port. 100 | func (u *UDP) NextLayerType() gopacket.LayerType { 101 | if lt := u.DstPort.LayerType(); lt != gopacket.LayerTypePayload { 102 | return lt 103 | } 104 | return u.SrcPort.LayerType() 105 | } 106 | 107 | func decodeUDP(data []byte, p gopacket.PacketBuilder) error { 108 | udp := &UDP{} 109 | err := udp.DecodeFromBytes(data, p) 110 | p.AddLayer(udp) 111 | p.SetTransportLayer(udp) 112 | if err != nil { 113 | return err 114 | } 115 | return p.NextDecoder(udp.NextLayerType()) 116 | } 117 | 118 | func (u *UDP) TransportFlow() gopacket.Flow { 119 | return gopacket.NewFlow(EndpointUDPPort, u.sPort, u.dPort) 120 | } 121 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/vxlan.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google, Inc. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the LICENSE file in the root of the source 5 | // tree. 6 | 7 | package layers 8 | 9 | import ( 10 | "encoding/binary" 11 | "fmt" 12 | "github.com/google/gopacket" 13 | ) 14 | 15 | // VXLAN is specifed in RFC 7348 https://tools.ietf.org/html/rfc7348 16 | // G, D, A, Group Policy ID from https://tools.ietf.org/html/draft-smith-vxlan-group-policy-00 17 | // 0 1 2 3 18 | // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 19 | // 0 8 16 24 32 20 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 21 | // |G|R|R|R|I|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID | 22 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 23 | // | 24 bit VXLAN Network Identifier | Reserved | 24 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 25 | 26 | // VXLAN is a VXLAN packet header 27 | type VXLAN struct { 28 | BaseLayer 29 | ValidIDFlag bool // 'I' bit per RFC 7348 30 | VNI uint32 // 'VXLAN Network Identifier' 24 bits per RFC 7348 31 | GBPExtension bool // 'G' bit per Group Policy https://tools.ietf.org/html/draft-smith-vxlan-group-policy-00 32 | GBPDontLearn bool // 'D' bit per Group Policy 33 | GBPApplied bool // 'A' bit per Group Policy 34 | GBPGroupPolicyID uint16 // 'Group Policy ID' 16 bits per Group Policy 35 | } 36 | 37 | // LayerType returns LayerTypeVXLAN 38 | func (vx *VXLAN) LayerType() gopacket.LayerType { return LayerTypeVXLAN } 39 | 40 | func decodeVXLAN(data []byte, p gopacket.PacketBuilder) error { 41 | vx := &VXLAN{} 42 | 43 | // VNI is a 24bit number, Uint32 requires 32 bits 44 | var buf [4]byte 45 | copy(buf[1:], data[4:7]) 46 | 47 | // RFC 7348 https://tools.ietf.org/html/rfc7348 48 | vx.ValidIDFlag = data[0]&0x08 > 0 // 'I' bit per RFC7348 49 | vx.VNI = binary.BigEndian.Uint32(buf[:]) // VXLAN Network Identifier per RFC7348 50 | 51 | // Group Based Policy https://tools.ietf.org/html/draft-smith-vxlan-group-policy-00 52 | vx.GBPExtension = data[0]&0x80 > 0 // 'G' bit per the group policy draft 53 | vx.GBPDontLearn = data[1]&0x40 > 0 // 'D' bit - the egress VTEP MUST NOT learn the source address of the encapsulated frame. 54 | vx.GBPApplied = data[1]&0x80 > 0 // 'A' bit - indicates that the group policy has already been applied to this packet. 55 | vx.GBPGroupPolicyID = binary.BigEndian.Uint16(data[2:4]) // Policy ID as per the group policy draft 56 | 57 | // Layer information 58 | const vxlanLength = 8 59 | vx.Contents = data[:vxlanLength] 60 | vx.Payload = data[vxlanLength:] 61 | 62 | p.AddLayer(vx) 63 | return p.NextDecoder(LinkTypeEthernet) 64 | } 65 | 66 | // SerializeTo writes the serialized form of this layer into the 67 | // SerializationBuffer, implementing gopacket.SerializableLayer. 68 | // See the docs for gopacket.SerializableLayer for more info. 69 | func (vx *VXLAN) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 70 | bytes, err := b.PrependBytes(8) 71 | if err != nil { 72 | return err 73 | } 74 | 75 | if vx.ValidIDFlag { 76 | bytes[0] |= 0x08 77 | } 78 | if vx.GBPExtension { 79 | bytes[0] |= 0x80 80 | } 81 | if vx.GBPDontLearn { 82 | bytes[1] |= 0x40 83 | } 84 | if vx.GBPApplied { 85 | bytes[1] |= 0x80 86 | } 87 | 88 | binary.BigEndian.PutUint16(bytes[2:4], vx.GBPGroupPolicyID) 89 | if vx.VNI >= 1<<24 { 90 | return fmt.Errorf("Virtual Network Identifier = %x exceeds max for 24-bit uint", vx.VNI) 91 | } 92 | binary.BigEndian.PutUint32(bytes[4:8], vx.VNI<<8) 93 | return nil 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/tcpip.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google, Inc. All rights reserved. 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style license 5 | // that can be found in the LICENSE file in the root of the source 6 | // tree. 7 | 8 | package layers 9 | 10 | import ( 11 | "errors" 12 | "fmt" 13 | 14 | "github.com/google/gopacket" 15 | ) 16 | 17 | // Checksum computation for TCP/UDP. 18 | type tcpipchecksum struct { 19 | pseudoheader tcpipPseudoHeader 20 | } 21 | 22 | type tcpipPseudoHeader interface { 23 | pseudoheaderChecksum() (uint32, error) 24 | } 25 | 26 | func (ip *IPv4) pseudoheaderChecksum() (csum uint32, err error) { 27 | if err := ip.AddressTo4(); err != nil { 28 | return 0, err 29 | } 30 | csum += (uint32(ip.SrcIP[0]) + uint32(ip.SrcIP[2])) << 8 31 | csum += uint32(ip.SrcIP[1]) + uint32(ip.SrcIP[3]) 32 | csum += (uint32(ip.DstIP[0]) + uint32(ip.DstIP[2])) << 8 33 | csum += uint32(ip.DstIP[1]) + uint32(ip.DstIP[3]) 34 | return csum, nil 35 | } 36 | 37 | func (ip *IPv6) pseudoheaderChecksum() (csum uint32, err error) { 38 | if err := ip.AddressTo16(); err != nil { 39 | return 0, err 40 | } 41 | for i := 0; i < 16; i += 2 { 42 | csum += uint32(ip.SrcIP[i]) << 8 43 | csum += uint32(ip.SrcIP[i+1]) 44 | csum += uint32(ip.DstIP[i]) << 8 45 | csum += uint32(ip.DstIP[i+1]) 46 | } 47 | return csum, nil 48 | } 49 | 50 | // Calculate the TCP/IP checksum defined in rfc1071. The passed-in csum is any 51 | // initial checksum data that's already been computed. 52 | func tcpipChecksum(data []byte, csum uint32) uint16 { 53 | // to handle odd lengths, we loop to length - 1, incrementing by 2, then 54 | // handle the last byte specifically by checking against the original 55 | // length. 56 | length := len(data) - 1 57 | for i := 0; i < length; i += 2 { 58 | // For our test packet, doing this manually is about 25% faster 59 | // (740 ns vs. 1000ns) than doing it by calling binary.BigEndian.Uint16. 60 | csum += uint32(data[i]) << 8 61 | csum += uint32(data[i+1]) 62 | } 63 | if len(data)%2 == 1 { 64 | csum += uint32(data[length]) << 8 65 | } 66 | for csum > 0xffff { 67 | csum = (csum >> 16) + (csum & 0xffff) 68 | } 69 | return ^uint16(csum) 70 | } 71 | 72 | // computeChecksum computes a TCP or UDP checksum. headerAndPayload is the 73 | // serialized TCP or UDP header plus its payload, with the checksum zero'd 74 | // out. headerProtocol is the IP protocol number of the upper-layer header. 75 | func (c *tcpipchecksum) computeChecksum(headerAndPayload []byte, headerProtocol IPProtocol) (uint16, error) { 76 | if c.pseudoheader == nil { 77 | return 0, errors.New("TCP/IP layer 4 checksum cannot be computed without network layer... call SetNetworkLayerForChecksum to set which layer to use") 78 | } 79 | length := uint32(len(headerAndPayload)) 80 | csum, err := c.pseudoheader.pseudoheaderChecksum() 81 | if err != nil { 82 | return 0, err 83 | } 84 | csum += uint32(headerProtocol) 85 | csum += length & 0xffff 86 | csum += length >> 16 87 | return tcpipChecksum(headerAndPayload, csum), nil 88 | } 89 | 90 | // SetNetworkLayerForChecksum tells this layer which network layer is wrapping it. 91 | // This is needed for computing the checksum when serializing, since TCP/IP transport 92 | // layer checksums depends on fields in the IPv4 or IPv6 layer that contains it. 93 | // The passed in layer must be an *IPv4 or *IPv6. 94 | func (i *tcpipchecksum) SetNetworkLayerForChecksum(l gopacket.NetworkLayer) error { 95 | switch v := l.(type) { 96 | case *IPv4: 97 | i.pseudoheader = v 98 | case *IPv6: 99 | i.pseudoheader = v 100 | default: 101 | return fmt.Errorf("cannot use layer type %v for tcp checksum network layer", l.LayerType()) 102 | } 103 | return nil 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/google/gopacket/layers/icmp6_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012, Google, Inc. All rights reserved. 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style license 5 | // that can be found in the LICENSE file in the root of the source 6 | // tree. 7 | 8 | package layers 9 | 10 | import ( 11 | "github.com/google/gopacket" 12 | "net" 13 | "reflect" 14 | "testing" 15 | ) 16 | 17 | // testPacketICMPv6 is the packet: 18 | // 10:48:30.088384 IP6 2620:0:1005:0:26be:5ff:fe27:b17 > fe80::21f:caff:feb3:7640: ICMP6, neighbor advertisement, tgt is 2620:0:1005:0:26be:5ff:fe27:b17, length 24 19 | // 0x0000: 001f cab3 7640 24be 0527 0b17 86dd 6000 ....v@$..'....`. 20 | // 0x0010: 0000 0018 3aff 2620 0000 1005 0000 26be ....:.&.......&. 21 | // 0x0020: 05ff fe27 0b17 fe80 0000 0000 0000 021f ...'............ 22 | // 0x0030: caff feb3 7640 8800 1ed6 4000 0000 2620 ....v@....@...&. 23 | // 0x0040: 0000 1005 0000 26be 05ff fe27 0b17 ......&....'.. 24 | var testPacketICMPv6 = []byte{ 25 | 0x00, 0x1f, 0xca, 0xb3, 0x76, 0x40, 0x24, 0xbe, 0x05, 0x27, 0x0b, 0x17, 0x86, 0xdd, 0x60, 0x00, 26 | 0x00, 0x00, 0x00, 0x18, 0x3a, 0xff, 0x26, 0x20, 0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x26, 0xbe, 27 | 0x05, 0xff, 0xfe, 0x27, 0x0b, 0x17, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1f, 28 | 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40, 0x88, 0x00, 0x1e, 0xd6, 0x40, 0x00, 0x00, 0x00, 0x26, 0x20, 29 | 0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x26, 0xbe, 0x05, 0xff, 0xfe, 0x27, 0x0b, 0x17, 30 | } 31 | 32 | func TestPacketICMPv6(t *testing.T) { 33 | p := gopacket.NewPacket(testPacketICMPv6, LinkTypeEthernet, gopacket.Default) 34 | if p.ErrorLayer() != nil { 35 | t.Error("Failed to decode packet:", p.ErrorLayer().Error()) 36 | } 37 | checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeICMPv6, gopacket.LayerTypePayload}, t) 38 | if got, ok := p.Layer(LayerTypeIPv6).(*IPv6); ok { 39 | want := &IPv6{ 40 | BaseLayer: BaseLayer{ 41 | Contents: []byte{0x60, 0x0, 0x0, 0x0, 0x0, 0x18, 42 | 0x3a, 0xff, 0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 43 | 0xff, 0xfe, 0x27, 0xb, 0x17, 0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 44 | 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40}, 45 | Payload: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0, 0x26, 0x20, 46 | 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 47 | 0x17}, 48 | }, 49 | Version: 6, 50 | TrafficClass: 0, 51 | FlowLabel: 0, 52 | Length: 24, 53 | NextHeader: IPProtocolICMPv6, 54 | HopLimit: 255, 55 | SrcIP: net.IP{0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17}, 56 | DstIP: net.IP{0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40}, 57 | } 58 | if !reflect.DeepEqual(got, want) { 59 | t.Errorf("IPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) 60 | } 61 | } else { 62 | t.Error("No IPv6 layer type found in packet") 63 | } 64 | if got, ok := p.Layer(LayerTypeICMPv6).(*ICMPv6); ok { 65 | want := &ICMPv6{ 66 | BaseLayer: BaseLayer{ 67 | Contents: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0}, 68 | Payload: []byte{0x26, 0x20, 0x0, 0x0, 0x10, 69 | 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17}, 70 | }, 71 | TypeCode: 0x8800, 72 | Checksum: 0x1ed6, 73 | TypeBytes: []byte{0x40, 0x0, 0x0, 0x0}, 74 | } 75 | if !reflect.DeepEqual(got, want) { 76 | t.Errorf("ICMPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) 77 | } 78 | if got.TypeCode.String() != "NeighborAdvertisement" { 79 | t.Errorf("ICMPv6 type code, got %q want 'NeighborAdvertisement'", got.TypeCode.String()) 80 | } 81 | } else { 82 | t.Error("No ICMPv6 layer type found in packet") 83 | } 84 | } 85 | --------------------------------------------------------------------------------