Update vendor files

This commit is contained in:
Bryan Boreham committed 2020-08-04 10:11:27 +00:00
1 parent feb05c0904
commit 9439606c57
431 files changed
+20800 -124354

No files matched your search

-76
View File
@@ -1,76 +0,0 @@
// Copyright 2014 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build ignore
// This binary compares memory usage between btree and gollrb.
package main
import (
"flag"
"fmt"
"math/rand"
"runtime"
"time"
"github.com/google/btree"
"github.com/petar/GoLLRB/llrb"
)
var (
size = flag.Int("size", 1000000, "size of the tree to build")
degree = flag.Int("degree", 8, "degree of btree")
gollrb = flag.Bool("llrb", false, "use llrb instead of btree")
)
func main() {
flag.Parse()
vals := rand.Perm(*size)
var t, v interface{}
v = vals
var stats runtime.MemStats
for i := 0; i < 10; i++ {
runtime.GC()
}
fmt.Println("-------- BEFORE ----------")
runtime.ReadMemStats(&stats)
fmt.Printf("%+v\n", stats)
start := time.Now()
if *gollrb {
tr := llrb.New()
for _, v := range vals {
tr.ReplaceOrInsert(llrb.Int(v))
}
t = tr // keep it around
} else {
tr := btree.New(*degree)
for _, v := range vals {
tr.ReplaceOrInsert(btree.Int(v))
}
t = tr // keep it around
}
fmt.Printf("%v inserts in %v\n", *size, time.Since(start))
fmt.Println("-------- AFTER ----------")
runtime.ReadMemStats(&stats)
fmt.Printf("%+v\n", stats)
for i := 0; i < 10; i++ {
runtime.GC()
}
fmt.Println("-------- AFTER GC ----------")
runtime.ReadMemStats(&stats)
fmt.Printf("%+v\n", stats)
if t == v {
fmt.Println("to make sure vals and tree aren't GC'd")
}
}
Generated Vendored Executable → Regular
View File
File mode changed.
Generated Vendored Executable → Regular
View File
File mode changed.
Generated Vendored Executable → Regular
View File
File mode changed.
Generated Vendored Executable → Regular
View File
File mode changed.
-109
View File
@@ -1,109 +0,0 @@
// Copyright 2012 Google, Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
// +build ignore
// This binary pulls known ports from IANA, and uses them to populate
// iana_ports.go's TCPPortNames and UDPPortNames maps.
//
// go run gen.go | gofmt > iana_ports.go
package main
import (
"bytes"
"encoding/xml"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
"time"
)
const fmtString = `// Copyright 2012 Google, Inc. All rights reserved.
package layers
// Created by gen.go, don't edit manually
// Generated at %s
// Fetched from %q
// TCPPortNames contains the port names for all TCP ports.
var TCPPortNames = tcpPortNames
// UDPPortNames contains the port names for all UDP ports.
var UDPPortNames = udpPortNames
// SCTPPortNames contains the port names for all SCTP ports.
var SCTPPortNames = sctpPortNames
var tcpPortNames = map[TCPPort]string{
%s}
var udpPortNames = map[UDPPort]string{
%s}
var sctpPortNames = map[SCTPPort]string{
%s}
`
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")
func main() {
fmt.Fprintf(os.Stderr, "Fetching ports from %q\n", *url)
resp, err := http.Get(*url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Fprintln(os.Stderr, "Parsing XML")
var registry struct {
Records []struct {
Protocol string `xml:"protocol"`
Number string `xml:"number"`
Name string `xml:"name"`
} `xml:"record"`
}
xml.Unmarshal(body, &registry)
var tcpPorts bytes.Buffer
var udpPorts bytes.Buffer
var sctpPorts bytes.Buffer
done := map[string]map[int]bool{
"tcp": map[int]bool{},
"udp": map[int]bool{},
"sctp": map[int]bool{},
}
for _, r := range registry.Records {
port, err := strconv.Atoi(r.Number)
if err != nil {
continue
}
if r.Name == "" {
continue
}
var b *bytes.Buffer
switch r.Protocol {
case "tcp":
b = &tcpPorts
case "udp":
b = &udpPorts
case "sctp":
b = &sctpPorts
default:
continue
}
if done[r.Protocol][port] {
continue
}
done[r.Protocol][port] = true
fmt.Fprintf(b, "\t%d: %q,\n", port, r.Name)
}
fmt.Fprintln(os.Stderr, "Writing results to stdout")
fmt.Printf(fmtString, time.Now(), *url, tcpPorts.String(), udpPorts.String(), sctpPorts.String())
}
-104
View File
@@ -1,104 +0,0 @@
// Copyright 2012 Google, Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
// +build ignore
// This binary handles creating string constants and function templates for enums.
//
// go run gen.go | gofmt > enums_generated.go
package main
import (
"fmt"
"log"
"os"
"text/template"
"time"
)
const fmtString = `// Copyright 2012 Google, Inc. All rights reserved.
package layers
// Created by gen2.go, don't edit manually
// Generated at %s
import (
"fmt"
"github.com/google/gopacket"
)
`
var funcsTmpl = template.Must(template.New("foo").Parse(`
// Decoder calls {{.Name}}Metadata.DecodeWith's decoder.
func (a {{.Name}}) Decode(data []byte, p gopacket.PacketBuilder) error {
return {{.Name}}Metadata[a].DecodeWith.Decode(data, p)
}
// String returns {{.Name}}Metadata.Name.
func (a {{.Name}}) String() string {
return {{.Name}}Metadata[a].Name
}
// LayerType returns {{.Name}}Metadata.LayerType.
func (a {{.Name}}) LayerType() gopacket.LayerType {
return {{.Name}}Metadata[a].LayerType
}
type errorDecoderFor{{.Name}} int
func (a *errorDecoderFor{{.Name}}) Decode(data []byte, p gopacket.PacketBuilder) error {
return a
}
func (a *errorDecoderFor{{.Name}}) Error() string {
return fmt.Sprintf("Unable to decode {{.Name}} %d", int(*a))
}
var errorDecodersFor{{.Name}} [{{.Num}}]errorDecoderFor{{.Name}}
var {{.Name}}Metadata [{{.Num}}]EnumMetadata
func initUnknownTypesFor{{.Name}}() {
for i := 0; i < {{.Num}}; i++ {
errorDecodersFor{{.Name}}[i] = errorDecoderFor{{.Name}}(i)
{{.Name}}Metadata[i] = EnumMetadata{
DecodeWith: &errorDecodersFor{{.Name}}[i],
Name: "Unknown{{.Name}}",
}
}
}
`))
func main() {
fmt.Fprintf(os.Stderr, "Writing results to stdout\n")
fmt.Printf(fmtString, time.Now())
types := []struct {
Name string
Num int
}{
{"LinkType", 256},
{"EthernetType", 65536},
{"PPPType", 65536},
{"IPProtocol", 256},
{"SCTPChunkType", 256},
{"PPPoECode", 256},
{"FDDIFrameControl", 256},
{"EAPOLType", 256},
{"ProtocolFamily", 256},
{"Dot11Type", 256},
{"USBTransportType", 256},
}
fmt.Println("func init() {")
for _, t := range types {
fmt.Printf("initUnknownTypesFor%s()\n", t.Name)
}
fmt.Println("initActualTypeData()")
fmt.Println("}")
for _, t := range types {
if err := funcsTmpl.Execute(os.Stdout, t); err != nil {
log.Fatalf("Failed to execute template %s: %v", t.Name, err)
}
}
}
Generated Vendored Executable → Regular
View File
File mode changed.
-157
View File
@@ -1,157 +0,0 @@
// Copyright 2019 The GoPacket Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
// +build ignore
package main
// This file generates the godefs needed for the windows version.
// Rebuild is only necessary if additional libpcap functionality is implemented, or a new arch is implemented in golang.
// Call with go run generate_windows.go [-I includepath]
// Needs npcap sdk, go tool cgo, and gofmt to work. Location of npcap includes can be specified with -I
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
const header = `// Copyright 2019 The GoPacket Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
// This file contains necessary structs/constants generated from libpcap headers with cgo -godefs
// generated with: %s
// DO NOT MODIFY
`
const source = `
package pcap
//#include <pcap.h>
import "C"
import "syscall" // needed for RawSockaddr
const errorBufferSize = C.PCAP_ERRBUF_SIZE
const (
pcapErrorNotActivated = C.PCAP_ERROR_NOT_ACTIVATED
pcapErrorActivated = C.PCAP_ERROR_ACTIVATED
pcapWarningPromisc = C.PCAP_WARNING_PROMISC_NOTSUP
pcapErrorNoSuchDevice = C.PCAP_ERROR_NO_SUCH_DEVICE
pcapErrorDenied = C.PCAP_ERROR_PERM_DENIED
pcapErrorNotUp = C.PCAP_ERROR_IFACE_NOT_UP
pcapError = C.PCAP_ERROR
pcapWarning = C.PCAP_WARNING
pcapDIN = C.PCAP_D_IN
pcapDOUT = C.PCAP_D_OUT
pcapDINOUT = C.PCAP_D_INOUT
pcapNetmaskUnknown = C.PCAP_NETMASK_UNKNOWN
pcapTstampPrecisionMicro = C.PCAP_TSTAMP_PRECISION_MICRO
pcapTstampPrecisionNano = C.PCAP_TSTAMP_PRECISION_NANO
)
type timeval C.struct_timeval
type pcapPkthdr C.struct_pcap_pkthdr
type pcapTPtr uintptr
type pcapBpfInstruction C.struct_bpf_insn
type pcapBpfProgram C.struct_bpf_program
type pcapStats C.struct_pcap_stat
type pcapCint C.int
type pcapIf C.struct_pcap_if
// +godefs map struct_sockaddr syscall.RawSockaddr
type pcapAddr C.struct_pcap_addr
`
var includes = flag.String("I", "C:\\npcap-sdk-1.01\\Include", "Include path containing libpcap headers")
func main() {
flag.Parse()
infile, err := ioutil.TempFile(".", "defs.*.go")
if err != nil {
log.Fatal("Couldn't create temporary source file: ", err)
}
defer infile.Close()
defer os.Remove(infile.Name())
_, err = infile.WriteString(source)
if err != nil {
log.Fatalf("Couldn't write definitions to temporary file %s: %s", infile.Name(), err)
}
err = infile.Close()
if err != nil {
log.Fatalf("Couldn't close temporary source file %s: %s", infile.Name(), err)
}
archs := []string{"386", "amd64"}
for _, arch := range archs {
env := append(os.Environ(), "GOARCH="+arch)
cmd := exec.Command("go", "tool", "cgo", "-godefs", "--", "-I", *includes, infile.Name())
cmd.Env = env
cmd.Stderr = os.Stderr
var generated bytes.Buffer
cmd.Stdout = &generated
err := cmd.Run()
if err != nil {
log.Fatalf("Couldn't generated defs for %s: %s\n", arch, err)
}
cmd = exec.Command("gofmt")
cmd.Env = env
cmd.Stderr = os.Stderr
outName := fmt.Sprintf("defs_windows_%s.go", arch)
out, err := os.Create(outName)
if err != nil {
log.Fatalf("Couldn't open file %s: %s", outName, err)
}
cmd.Stdout = out
in, err := cmd.StdinPipe()
if err != nil {
log.Fatal("Couldn't create input pipe for gofmt: ", err)
}
err = cmd.Start()
if err != nil {
log.Fatal("Couldn't start gofmt: ", err)
}
_, err = fmt.Fprintf(in, header, strings.Join(append([]string{filepath.Base(os.Args[0])}, os.Args[1:]...), " "))
if err != nil {
log.Fatal("Couldn't write header to gofmt: ", err)
}
for {
line, err := generated.ReadBytes('\n')
if err != nil {
break
}
// remove godefs comments
if bytes.HasPrefix(line, []byte("//")) {
continue
}
_, err = in.Write(line)
if err != nil {
log.Fatal("Couldn't write line to gofmt: ", err)
}
}
in.Close()
err = cmd.Wait()
if err != nil {
log.Fatal("gofmt failed: ", err)
}
out.Close()
}
}
-108
View File
@@ -1,108 +0,0 @@
// Copyright 2012 Google, Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
// +build ignore
// This binary tests that PCAP packet capture is working correctly by issuing
// HTTP requests, then making sure we actually capture data off the wire.
package main
import (
"errors"
"flag"
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/google/gopacket/pcap"
)
var mode = flag.String("mode", "basic", "One of: basic,filtered,timestamp")
func generatePackets() {
if resp, err := http.Get("http://code.google.com"); err != nil {
log.Printf("Could not get HTTP: %v", err)
} else {
resp.Body.Close()
}
}
func main() {
flag.Parse()
ifaces, err := pcap.FindAllDevs()
if err != nil {
log.Fatal(err)
}
for _, iface := range ifaces {
log.Printf("Trying capture on %q", iface.Name)
if err := tryCapture(iface); err != nil {
log.Printf("Error capturing on %q: %v", iface.Name, err)
} else {
log.Printf("Successfully captured on %q", iface.Name)
return
}
}
os.Exit(1)
}
func tryCapture(iface pcap.Interface) error {
if iface.Name[:2] == "lo" {
return errors.New("skipping loopback")
}
var h *pcap.Handle
var err error
switch *mode {
case "basic":
h, err = pcap.OpenLive(iface.Name, 65536, false, time.Second*3)
if err != nil {
return fmt.Errorf("openlive: %v", err)
}
defer h.Close()
case "filtered":
h, err = pcap.OpenLive(iface.Name, 65536, false, time.Second*3)
if err != nil {
return fmt.Errorf("openlive: %v", err)
}
defer h.Close()
if err := h.SetBPFFilter("port 80 or port 443"); err != nil {
return fmt.Errorf("setbpf: %v", err)
}
case "timestamp":
u, err := pcap.NewInactiveHandle(iface.Name)
if err != nil {
return err
}
defer u.CleanUp()
if err = u.SetSnapLen(65536); err != nil {
return err
} else if err = u.SetPromisc(false); err != nil {
return err
} else if err = u.SetTimeout(time.Second * 3); err != nil {
return err
}
sources := u.SupportedTimestamps()
if len(sources) == 0 {
return errors.New("no supported timestamp sources")
} else if err := u.SetTimestampSource(sources[0]); err != nil {
return fmt.Errorf("settimestampsource(%v): %v", sources[0], err)
} else if h, err = u.Activate(); err != nil {
return fmt.Errorf("could not activate: %v", err)
}
defer h.Close()
default:
panic("Invalid --mode: " + *mode)
}
go generatePackets()
h.ReadPacketData() // Do one dummy read to clear any timeouts.
data, ci, err := h.ReadPacketData()
if err != nil {
return fmt.Errorf("readpacketdata: %v", err)
}
log.Printf("Read packet, %v bytes, CI: %+v", len(data), ci)
return nil
}