summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/bpf
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-04-16 05:37:14 -0700
committerJoram Wilander <jwawilander@gmail.com>2018-04-16 08:37:14 -0400
commit6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch)
tree3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/golang.org/x/net/bpf
parentbf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff)
downloadchat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz
chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2
chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/golang.org/x/net/bpf')
-rw-r--r--vendor/golang.org/x/net/bpf/instructions.go32
-rw-r--r--vendor/golang.org/x/net/bpf/instructions_test.go525
-rw-r--r--vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf1
-rw-r--r--vendor/golang.org/x/net/bpf/testdata/all_instructions.txt79
-rw-r--r--vendor/golang.org/x/net/bpf/vm_aluop_test.go512
-rw-r--r--vendor/golang.org/x/net/bpf/vm_bpf_test.go192
-rw-r--r--vendor/golang.org/x/net/bpf/vm_extension_test.go49
-rw-r--r--vendor/golang.org/x/net/bpf/vm_jump_test.go380
-rw-r--r--vendor/golang.org/x/net/bpf/vm_load_test.go246
-rw-r--r--vendor/golang.org/x/net/bpf/vm_ret_test.go115
-rw-r--r--vendor/golang.org/x/net/bpf/vm_scratch_test.go247
-rw-r--r--vendor/golang.org/x/net/bpf/vm_test.go144
12 files changed, 16 insertions, 2506 deletions
diff --git a/vendor/golang.org/x/net/bpf/instructions.go b/vendor/golang.org/x/net/bpf/instructions.go
index 3b4fd0891..f9dc0e8ee 100644
--- a/vendor/golang.org/x/net/bpf/instructions.go
+++ b/vendor/golang.org/x/net/bpf/instructions.go
@@ -198,7 +198,7 @@ func (a LoadConstant) Assemble() (RawInstruction, error) {
return assembleLoad(a.Dst, 4, opAddrModeImmediate, a.Val)
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a LoadConstant) String() string {
switch a.Dst {
case RegA:
@@ -224,7 +224,7 @@ func (a LoadScratch) Assemble() (RawInstruction, error) {
return assembleLoad(a.Dst, 4, opAddrModeScratch, uint32(a.N))
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a LoadScratch) String() string {
switch a.Dst {
case RegA:
@@ -248,7 +248,7 @@ func (a LoadAbsolute) Assemble() (RawInstruction, error) {
return assembleLoad(RegA, a.Size, opAddrModeAbsolute, a.Off)
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a LoadAbsolute) String() string {
switch a.Size {
case 1: // byte
@@ -277,7 +277,7 @@ func (a LoadIndirect) Assemble() (RawInstruction, error) {
return assembleLoad(RegA, a.Size, opAddrModeIndirect, a.Off)
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a LoadIndirect) String() string {
switch a.Size {
case 1: // byte
@@ -306,7 +306,7 @@ func (a LoadMemShift) Assemble() (RawInstruction, error) {
return assembleLoad(RegX, 1, opAddrModeMemShift, a.Off)
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a LoadMemShift) String() string {
return fmt.Sprintf("ldx 4*([%d]&0xf)", a.Off)
}
@@ -325,7 +325,7 @@ func (a LoadExtension) Assemble() (RawInstruction, error) {
return assembleLoad(RegA, 4, opAddrModeAbsolute, uint32(extOffset+a.Num))
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a LoadExtension) String() string {
switch a.Num {
case ExtLen:
@@ -392,7 +392,7 @@ func (a StoreScratch) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a StoreScratch) String() string {
switch a.Src {
case RegA:
@@ -418,7 +418,7 @@ func (a ALUOpConstant) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a ALUOpConstant) String() string {
switch a.Op {
case ALUOpAdd:
@@ -458,7 +458,7 @@ func (a ALUOpX) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a ALUOpX) String() string {
switch a.Op {
case ALUOpAdd:
@@ -496,7 +496,7 @@ func (a NegateA) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a NegateA) String() string {
return fmt.Sprintf("neg")
}
@@ -514,7 +514,7 @@ func (a Jump) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a Jump) String() string {
return fmt.Sprintf("ja %d", a.Skip)
}
@@ -566,7 +566,7 @@ func (a JumpIf) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a JumpIf) String() string {
switch a.Cond {
// K == A
@@ -621,7 +621,7 @@ func (a RetA) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a RetA) String() string {
return fmt.Sprintf("ret a")
}
@@ -639,7 +639,7 @@ func (a RetConstant) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a RetConstant) String() string {
return fmt.Sprintf("ret #%d", a.Val)
}
@@ -654,7 +654,7 @@ func (a TXA) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a TXA) String() string {
return fmt.Sprintf("txa")
}
@@ -669,7 +669,7 @@ func (a TAX) Assemble() (RawInstruction, error) {
}, nil
}
-// String returns the the instruction in assembler notation.
+// String returns the instruction in assembler notation.
func (a TAX) String() string {
return fmt.Sprintf("tax")
}
diff --git a/vendor/golang.org/x/net/bpf/instructions_test.go b/vendor/golang.org/x/net/bpf/instructions_test.go
deleted file mode 100644
index dde474aba..000000000
--- a/vendor/golang.org/x/net/bpf/instructions_test.go
+++ /dev/null
@@ -1,525 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf
-
-import (
- "fmt"
- "io/ioutil"
- "reflect"
- "strconv"
- "strings"
- "testing"
-)
-
-// This is a direct translation of the program in
-// testdata/all_instructions.txt.
-var allInstructions = []Instruction{
- LoadConstant{Dst: RegA, Val: 42},
- LoadConstant{Dst: RegX, Val: 42},
-
- LoadScratch{Dst: RegA, N: 3},
- LoadScratch{Dst: RegX, N: 3},
-
- LoadAbsolute{Off: 42, Size: 1},
- LoadAbsolute{Off: 42, Size: 2},
- LoadAbsolute{Off: 42, Size: 4},
-
- LoadIndirect{Off: 42, Size: 1},
- LoadIndirect{Off: 42, Size: 2},
- LoadIndirect{Off: 42, Size: 4},
-
- LoadMemShift{Off: 42},
-
- LoadExtension{Num: ExtLen},
- LoadExtension{Num: ExtProto},
- LoadExtension{Num: ExtType},
- LoadExtension{Num: ExtRand},
-
- StoreScratch{Src: RegA, N: 3},
- StoreScratch{Src: RegX, N: 3},
-
- ALUOpConstant{Op: ALUOpAdd, Val: 42},
- ALUOpConstant{Op: ALUOpSub, Val: 42},
- ALUOpConstant{Op: ALUOpMul, Val: 42},
- ALUOpConstant{Op: ALUOpDiv, Val: 42},
- ALUOpConstant{Op: ALUOpOr, Val: 42},
- ALUOpConstant{Op: ALUOpAnd, Val: 42},
- ALUOpConstant{Op: ALUOpShiftLeft, Val: 42},
- ALUOpConstant{Op: ALUOpShiftRight, Val: 42},
- ALUOpConstant{Op: ALUOpMod, Val: 42},
- ALUOpConstant{Op: ALUOpXor, Val: 42},
-
- ALUOpX{Op: ALUOpAdd},
- ALUOpX{Op: ALUOpSub},
- ALUOpX{Op: ALUOpMul},
- ALUOpX{Op: ALUOpDiv},
- ALUOpX{Op: ALUOpOr},
- ALUOpX{Op: ALUOpAnd},
- ALUOpX{Op: ALUOpShiftLeft},
- ALUOpX{Op: ALUOpShiftRight},
- ALUOpX{Op: ALUOpMod},
- ALUOpX{Op: ALUOpXor},
-
- NegateA{},
-
- Jump{Skip: 10},
- JumpIf{Cond: JumpEqual, Val: 42, SkipTrue: 8, SkipFalse: 9},
- JumpIf{Cond: JumpNotEqual, Val: 42, SkipTrue: 8},
- JumpIf{Cond: JumpLessThan, Val: 42, SkipTrue: 7},
- JumpIf{Cond: JumpLessOrEqual, Val: 42, SkipTrue: 6},
- JumpIf{Cond: JumpGreaterThan, Val: 42, SkipTrue: 4, SkipFalse: 5},
- JumpIf{Cond: JumpGreaterOrEqual, Val: 42, SkipTrue: 3, SkipFalse: 4},
- JumpIf{Cond: JumpBitsSet, Val: 42, SkipTrue: 2, SkipFalse: 3},
-
- TAX{},
- TXA{},
-
- RetA{},
- RetConstant{Val: 42},
-}
-var allInstructionsExpected = "testdata/all_instructions.bpf"
-
-// Check that we produce the same output as the canonical bpf_asm
-// linux kernel tool.
-func TestInterop(t *testing.T) {
- out, err := Assemble(allInstructions)
- if err != nil {
- t.Fatalf("assembly of allInstructions program failed: %s", err)
- }
- t.Logf("Assembled program is %d instructions long", len(out))
-
- bs, err := ioutil.ReadFile(allInstructionsExpected)
- if err != nil {
- t.Fatalf("reading %s: %s", allInstructionsExpected, err)
- }
- // First statement is the number of statements, last statement is
- // empty. We just ignore both and rely on slice length.
- stmts := strings.Split(string(bs), ",")
- if len(stmts)-2 != len(out) {
- t.Fatalf("test program lengths don't match: %s has %d, Go implementation has %d", allInstructionsExpected, len(stmts)-2, len(allInstructions))
- }
-
- for i, stmt := range stmts[1 : len(stmts)-2] {
- nums := strings.Split(stmt, " ")
- if len(nums) != 4 {
- t.Fatalf("malformed instruction %d in %s: %s", i+1, allInstructionsExpected, stmt)
- }
-
- actual := out[i]
-
- op, err := strconv.ParseUint(nums[0], 10, 16)
- if err != nil {
- t.Fatalf("malformed opcode %s in instruction %d of %s", nums[0], i+1, allInstructionsExpected)
- }
- if actual.Op != uint16(op) {
- t.Errorf("opcode mismatch on instruction %d (%#v): got 0x%02x, want 0x%02x", i+1, allInstructions[i], actual.Op, op)
- }
-
- jt, err := strconv.ParseUint(nums[1], 10, 8)
- if err != nil {
- t.Fatalf("malformed jt offset %s in instruction %d of %s", nums[1], i+1, allInstructionsExpected)
- }
- if actual.Jt != uint8(jt) {
- t.Errorf("jt mismatch on instruction %d (%#v): got %d, want %d", i+1, allInstructions[i], actual.Jt, jt)
- }
-
- jf, err := strconv.ParseUint(nums[2], 10, 8)
- if err != nil {
- t.Fatalf("malformed jf offset %s in instruction %d of %s", nums[2], i+1, allInstructionsExpected)
- }
- if actual.Jf != uint8(jf) {
- t.Errorf("jf mismatch on instruction %d (%#v): got %d, want %d", i+1, allInstructions[i], actual.Jf, jf)
- }
-
- k, err := strconv.ParseUint(nums[3], 10, 32)
- if err != nil {
- t.Fatalf("malformed constant %s in instruction %d of %s", nums[3], i+1, allInstructionsExpected)
- }
- if actual.K != uint32(k) {
- t.Errorf("constant mismatch on instruction %d (%#v): got %d, want %d", i+1, allInstructions[i], actual.K, k)
- }
- }
-}
-
-// Check that assembly and disassembly match each other.
-func TestAsmDisasm(t *testing.T) {
- prog1, err := Assemble(allInstructions)
- if err != nil {
- t.Fatalf("assembly of allInstructions program failed: %s", err)
- }
- t.Logf("Assembled program is %d instructions long", len(prog1))
-
- got, allDecoded := Disassemble(prog1)
- if !allDecoded {
- t.Errorf("Disassemble(Assemble(allInstructions)) produced unrecognized instructions:")
- for i, inst := range got {
- if r, ok := inst.(RawInstruction); ok {
- t.Logf(" insn %d, %#v --> %#v", i+1, allInstructions[i], r)
- }
- }
- }
-
- if len(allInstructions) != len(got) {
- t.Fatalf("disassembly changed program size: %d insns before, %d insns after", len(allInstructions), len(got))
- }
- if !reflect.DeepEqual(allInstructions, got) {
- t.Errorf("program mutated by disassembly:")
- for i := range got {
- if !reflect.DeepEqual(allInstructions[i], got[i]) {
- t.Logf(" insn %d, s: %#v, p1: %#v, got: %#v", i+1, allInstructions[i], prog1[i], got[i])
- }
- }
- }
-}
-
-type InvalidInstruction struct{}
-
-func (a InvalidInstruction) Assemble() (RawInstruction, error) {
- return RawInstruction{}, fmt.Errorf("Invalid Instruction")
-}
-
-func (a InvalidInstruction) String() string {
- return fmt.Sprintf("unknown instruction: %#v", a)
-}
-
-func TestString(t *testing.T) {
- testCases := []struct {
- instruction Instruction
- assembler string
- }{
- {
- instruction: LoadConstant{Dst: RegA, Val: 42},
- assembler: "ld #42",
- },
- {
- instruction: LoadConstant{Dst: RegX, Val: 42},
- assembler: "ldx #42",
- },
- {
- instruction: LoadConstant{Dst: 0xffff, Val: 42},
- assembler: "unknown instruction: bpf.LoadConstant{Dst:0xffff, Val:0x2a}",
- },
- {
- instruction: LoadScratch{Dst: RegA, N: 3},
- assembler: "ld M[3]",
- },
- {
- instruction: LoadScratch{Dst: RegX, N: 3},
- assembler: "ldx M[3]",
- },
- {
- instruction: LoadScratch{Dst: 0xffff, N: 3},
- assembler: "unknown instruction: bpf.LoadScratch{Dst:0xffff, N:3}",
- },
- {
- instruction: LoadAbsolute{Off: 42, Size: 1},
- assembler: "ldb [42]",
- },
- {
- instruction: LoadAbsolute{Off: 42, Size: 2},
- assembler: "ldh [42]",
- },
- {
- instruction: LoadAbsolute{Off: 42, Size: 4},
- assembler: "ld [42]",
- },
- {
- instruction: LoadAbsolute{Off: 42, Size: -1},
- assembler: "unknown instruction: bpf.LoadAbsolute{Off:0x2a, Size:-1}",
- },
- {
- instruction: LoadIndirect{Off: 42, Size: 1},
- assembler: "ldb [x + 42]",
- },
- {
- instruction: LoadIndirect{Off: 42, Size: 2},
- assembler: "ldh [x + 42]",
- },
- {
- instruction: LoadIndirect{Off: 42, Size: 4},
- assembler: "ld [x + 42]",
- },
- {
- instruction: LoadIndirect{Off: 42, Size: -1},
- assembler: "unknown instruction: bpf.LoadIndirect{Off:0x2a, Size:-1}",
- },
- {
- instruction: LoadMemShift{Off: 42},
- assembler: "ldx 4*([42]&0xf)",
- },
- {
- instruction: LoadExtension{Num: ExtLen},
- assembler: "ld #len",
- },
- {
- instruction: LoadExtension{Num: ExtProto},
- assembler: "ld #proto",
- },
- {
- instruction: LoadExtension{Num: ExtType},
- assembler: "ld #type",
- },
- {
- instruction: LoadExtension{Num: ExtPayloadOffset},
- assembler: "ld #poff",
- },
- {
- instruction: LoadExtension{Num: ExtInterfaceIndex},
- assembler: "ld #ifidx",
- },
- {
- instruction: LoadExtension{Num: ExtNetlinkAttr},
- assembler: "ld #nla",
- },
- {
- instruction: LoadExtension{Num: ExtNetlinkAttrNested},
- assembler: "ld #nlan",
- },
- {
- instruction: LoadExtension{Num: ExtMark},
- assembler: "ld #mark",
- },
- {
- instruction: LoadExtension{Num: ExtQueue},
- assembler: "ld #queue",
- },
- {
- instruction: LoadExtension{Num: ExtLinkLayerType},
- assembler: "ld #hatype",
- },
- {
- instruction: LoadExtension{Num: ExtRXHash},
- assembler: "ld #rxhash",
- },
- {
- instruction: LoadExtension{Num: ExtCPUID},
- assembler: "ld #cpu",
- },
- {
- instruction: LoadExtension{Num: ExtVLANTag},
- assembler: "ld #vlan_tci",
- },
- {
- instruction: LoadExtension{Num: ExtVLANTagPresent},
- assembler: "ld #vlan_avail",
- },
- {
- instruction: LoadExtension{Num: ExtVLANProto},
- assembler: "ld #vlan_tpid",
- },
- {
- instruction: LoadExtension{Num: ExtRand},
- assembler: "ld #rand",
- },
- {
- instruction: LoadAbsolute{Off: 0xfffff038, Size: 4},
- assembler: "ld #rand",
- },
- {
- instruction: LoadExtension{Num: 0xfff},
- assembler: "unknown instruction: bpf.LoadExtension{Num:4095}",
- },
- {
- instruction: StoreScratch{Src: RegA, N: 3},
- assembler: "st M[3]",
- },
- {
- instruction: StoreScratch{Src: RegX, N: 3},
- assembler: "stx M[3]",
- },
- {
- instruction: StoreScratch{Src: 0xffff, N: 3},
- assembler: "unknown instruction: bpf.StoreScratch{Src:0xffff, N:3}",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpAdd, Val: 42},
- assembler: "add #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpSub, Val: 42},
- assembler: "sub #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpMul, Val: 42},
- assembler: "mul #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpDiv, Val: 42},
- assembler: "div #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpOr, Val: 42},
- assembler: "or #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpAnd, Val: 42},
- assembler: "and #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpShiftLeft, Val: 42},
- assembler: "lsh #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpShiftRight, Val: 42},
- assembler: "rsh #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpMod, Val: 42},
- assembler: "mod #42",
- },
- {
- instruction: ALUOpConstant{Op: ALUOpXor, Val: 42},
- assembler: "xor #42",
- },
- {
- instruction: ALUOpConstant{Op: 0xffff, Val: 42},
- assembler: "unknown instruction: bpf.ALUOpConstant{Op:0xffff, Val:0x2a}",
- },
- {
- instruction: ALUOpX{Op: ALUOpAdd},
- assembler: "add x",
- },
- {
- instruction: ALUOpX{Op: ALUOpSub},
- assembler: "sub x",
- },
- {
- instruction: ALUOpX{Op: ALUOpMul},
- assembler: "mul x",
- },
- {
- instruction: ALUOpX{Op: ALUOpDiv},
- assembler: "div x",
- },
- {
- instruction: ALUOpX{Op: ALUOpOr},
- assembler: "or x",
- },
- {
- instruction: ALUOpX{Op: ALUOpAnd},
- assembler: "and x",
- },
- {
- instruction: ALUOpX{Op: ALUOpShiftLeft},
- assembler: "lsh x",
- },
- {
- instruction: ALUOpX{Op: ALUOpShiftRight},
- assembler: "rsh x",
- },
- {
- instruction: ALUOpX{Op: ALUOpMod},
- assembler: "mod x",
- },
- {
- instruction: ALUOpX{Op: ALUOpXor},
- assembler: "xor x",
- },
- {
- instruction: ALUOpX{Op: 0xffff},
- assembler: "unknown instruction: bpf.ALUOpX{Op:0xffff}",
- },
- {
- instruction: NegateA{},
- assembler: "neg",
- },
- {
- instruction: Jump{Skip: 10},
- assembler: "ja 10",
- },
- {
- instruction: JumpIf{Cond: JumpEqual, Val: 42, SkipTrue: 8, SkipFalse: 9},
- assembler: "jeq #42,8,9",
- },
- {
- instruction: JumpIf{Cond: JumpEqual, Val: 42, SkipTrue: 8},
- assembler: "jeq #42,8",
- },
- {
- instruction: JumpIf{Cond: JumpEqual, Val: 42, SkipFalse: 8},
- assembler: "jneq #42,8",
- },
- {
- instruction: JumpIf{Cond: JumpNotEqual, Val: 42, SkipTrue: 8},
- assembler: "jneq #42,8",
- },
- {
- instruction: JumpIf{Cond: JumpLessThan, Val: 42, SkipTrue: 7},
- assembler: "jlt #42,7",
- },
- {
- instruction: JumpIf{Cond: JumpLessOrEqual, Val: 42, SkipTrue: 6},
- assembler: "jle #42,6",
- },
- {
- instruction: JumpIf{Cond: JumpGreaterThan, Val: 42, SkipTrue: 4, SkipFalse: 5},
- assembler: "jgt #42,4,5",
- },
- {
- instruction: JumpIf{Cond: JumpGreaterThan, Val: 42, SkipTrue: 4},
- assembler: "jgt #42,4",
- },
- {
- instruction: JumpIf{Cond: JumpGreaterOrEqual, Val: 42, SkipTrue: 3, SkipFalse: 4},
- assembler: "jge #42,3,4",
- },
- {
- instruction: JumpIf{Cond: JumpGreaterOrEqual, Val: 42, SkipTrue: 3},
- assembler: "jge #42,3",
- },
- {
- instruction: JumpIf{Cond: JumpBitsSet, Val: 42, SkipTrue: 2, SkipFalse: 3},
- assembler: "jset #42,2,3",
- },
- {
- instruction: JumpIf{Cond: JumpBitsSet, Val: 42, SkipTrue: 2},
- assembler: "jset #42,2",
- },
- {
- instruction: JumpIf{Cond: JumpBitsNotSet, Val: 42, SkipTrue: 2, SkipFalse: 3},
- assembler: "jset #42,3,2",
- },
- {
- instruction: JumpIf{Cond: JumpBitsNotSet, Val: 42, SkipTrue: 2},
- assembler: "jset #42,0,2",
- },
- {
- instruction: JumpIf{Cond: 0xffff, Val: 42, SkipTrue: 1, SkipFalse: 2},
- assembler: "unknown instruction: bpf.JumpIf{Cond:0xffff, Val:0x2a, SkipTrue:0x1, SkipFalse:0x2}",
- },
- {
- instruction: TAX{},
- assembler: "tax",
- },
- {
- instruction: TXA{},
- assembler: "txa",
- },
- {
- instruction: RetA{},
- assembler: "ret a",
- },
- {
- instruction: RetConstant{Val: 42},
- assembler: "ret #42",
- },
- // Invalid instruction
- {
- instruction: InvalidInstruction{},
- assembler: "unknown instruction: bpf.InvalidInstruction{}",
- },
- }
-
- for _, testCase := range testCases {
- if input, ok := testCase.instruction.(fmt.Stringer); ok {
- got := input.String()
- if got != testCase.assembler {
- t.Errorf("String did not return expected assembler notation, expected: %s, got: %s", testCase.assembler, got)
- }
- } else {
- t.Errorf("Instruction %#v is not a fmt.Stringer", testCase.instruction)
- }
- }
-}
diff --git a/vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf b/vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf
deleted file mode 100644
index f87144064..000000000
--- a/vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf
+++ /dev/null
@@ -1 +0,0 @@
-50,0 0 0 42,1 0 0 42,96 0 0 3,97 0 0 3,48 0 0 42,40 0 0 42,32 0 0 42,80 0 0 42,72 0 0 42,64 0 0 42,177 0 0 42,128 0 0 0,32 0 0 4294963200,32 0 0 4294963204,32 0 0 4294963256,2 0 0 3,3 0 0 3,4 0 0 42,20 0 0 42,36 0 0 42,52 0 0 42,68 0 0 42,84 0 0 42,100 0 0 42,116 0 0 42,148 0 0 42,164 0 0 42,12 0 0 0,28 0 0 0,44 0 0 0,60 0 0 0,76 0 0 0,92 0 0 0,108 0 0 0,124 0 0 0,156 0 0 0,172 0 0 0,132 0 0 0,5 0 0 10,21 8 9 42,21 0 8 42,53 0 7 42,37 0 6 42,37 4 5 42,53 3 4 42,69 2 3 42,7 0 0 0,135 0 0 0,22 0 0 0,6 0 0 0,
diff --git a/vendor/golang.org/x/net/bpf/testdata/all_instructions.txt b/vendor/golang.org/x/net/bpf/testdata/all_instructions.txt
deleted file mode 100644
index 304550155..000000000
--- a/vendor/golang.org/x/net/bpf/testdata/all_instructions.txt
+++ /dev/null
@@ -1,79 +0,0 @@
-# This filter is compiled to all_instructions.bpf by the `bpf_asm`
-# tool, which can be found in the linux kernel source tree under
-# tools/net.
-
-# Load immediate
-ld #42
-ldx #42
-
-# Load scratch
-ld M[3]
-ldx M[3]
-
-# Load absolute
-ldb [42]
-ldh [42]
-ld [42]
-
-# Load indirect
-ldb [x + 42]
-ldh [x + 42]
-ld [x + 42]
-
-# Load IPv4 header length
-ldx 4*([42]&0xf)
-
-# Run extension function
-ld #len
-ld #proto
-ld #type
-ld #rand
-
-# Store scratch
-st M[3]
-stx M[3]
-
-# A <op> constant
-add #42
-sub #42
-mul #42
-div #42
-or #42
-and #42
-lsh #42
-rsh #42
-mod #42
-xor #42
-
-# A <op> X
-add x
-sub x
-mul x
-div x
-or x
-and x
-lsh x
-rsh x
-mod x
-xor x
-
-# !A
-neg
-
-# Jumps
-ja end
-jeq #42,prev,end
-jne #42,end
-jlt #42,end
-jle #42,end
-jgt #42,prev,end
-jge #42,prev,end
-jset #42,prev,end
-
-# Register transfers
-tax
-txa
-
-# Returns
-prev: ret a
-end: ret #42
diff --git a/vendor/golang.org/x/net/bpf/vm_aluop_test.go b/vendor/golang.org/x/net/bpf/vm_aluop_test.go
deleted file mode 100644
index 16678244a..000000000
--- a/vendor/golang.org/x/net/bpf/vm_aluop_test.go
+++ /dev/null
@@ -1,512 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "testing"
-
- "golang.org/x/net/bpf"
-)
-
-func TestVMALUOpAdd(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpAdd,
- Val: 3,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 8, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 3, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpSub(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.TAX{},
- bpf.ALUOpX{
- Op: bpf.ALUOpSub,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 1, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpMul(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpMul,
- Val: 2,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 6, 2, 3, 4,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 4, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpDiv(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpDiv,
- Val: 2,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 20, 2, 3, 4,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 2, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpDivByZeroALUOpConstant(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.ALUOpConstant{
- Op: bpf.ALUOpDiv,
- Val: 0,
- },
- bpf.RetA{},
- })
- if errStr(err) != "cannot divide by zero using ALUOpConstant" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMALUOpDivByZeroALUOpX(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- // Load byte 0 into X
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.TAX{},
- // Load byte 1 into A
- bpf.LoadAbsolute{
- Off: 9,
- Size: 1,
- },
- // Attempt to perform 1/0
- bpf.ALUOpX{
- Op: bpf.ALUOpDiv,
- },
- // Return 4 bytes if program does not terminate
- bpf.LoadConstant{
- Val: 12,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 3, 4,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpOr(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 2,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpOr,
- Val: 0x01,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x10, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08,
- 0x09, 0xff,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 9, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpAnd(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 2,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpAnd,
- Val: 0x0019,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0xaa, 0x09,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpShiftLeft(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpShiftLeft,
- Val: 0x01,
- },
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 0x02,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x01, 0xaa,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpShiftRight(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpShiftRight,
- Val: 0x01,
- },
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 0x04,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x08, 0xff, 0xff,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpMod(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpMod,
- Val: 20,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 30, 0, 0,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 2, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpModByZeroALUOpConstant(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpMod,
- Val: 0,
- },
- bpf.RetA{},
- })
- if errStr(err) != "cannot divide by zero using ALUOpConstant" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMALUOpModByZeroALUOpX(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- // Load byte 0 into X
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.TAX{},
- // Load byte 1 into A
- bpf.LoadAbsolute{
- Off: 9,
- Size: 1,
- },
- // Attempt to perform 1%0
- bpf.ALUOpX{
- Op: bpf.ALUOpMod,
- },
- // Return 4 bytes if program does not terminate
- bpf.LoadConstant{
- Val: 12,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 3, 4,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpXor(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpXor,
- Val: 0x0a,
- },
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 0x01,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x0b, 0x00, 0x00, 0x00,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMALUOpUnknown(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.ALUOpConstant{
- Op: bpf.ALUOpAdd,
- Val: 1,
- },
- // Verify that an unknown operation is a no-op
- bpf.ALUOpConstant{
- Op: 100,
- },
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 0x02,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 1,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
diff --git a/vendor/golang.org/x/net/bpf/vm_bpf_test.go b/vendor/golang.org/x/net/bpf/vm_bpf_test.go
deleted file mode 100644
index 77fa8fe4a..000000000
--- a/vendor/golang.org/x/net/bpf/vm_bpf_test.go
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "net"
- "runtime"
- "testing"
- "time"
-
- "golang.org/x/net/bpf"
- "golang.org/x/net/ipv4"
-)
-
-// A virtualMachine is a BPF virtual machine which can process an
-// input packet against a BPF program and render a verdict.
-type virtualMachine interface {
- Run(in []byte) (int, error)
-}
-
-// canUseOSVM indicates if the OS BPF VM is available on this platform.
-func canUseOSVM() bool {
- // OS BPF VM can only be used on platforms where x/net/ipv4 supports
- // attaching a BPF program to a socket.
- switch runtime.GOOS {
- case "linux":
- return true
- }
-
- return false
-}
-
-// All BPF tests against both the Go VM and OS VM are assumed to
-// be used with a UDP socket. As a result, the entire contents
-// of a UDP datagram is sent through the BPF program, but only
-// the body after the UDP header will ever be returned in output.
-
-// testVM sets up a Go BPF VM, and if available, a native OS BPF VM
-// for integration testing.
-func testVM(t *testing.T, filter []bpf.Instruction) (virtualMachine, func(), error) {
- goVM, err := bpf.NewVM(filter)
- if err != nil {
- // Some tests expect an error, so this error must be returned
- // instead of fatally exiting the test
- return nil, nil, err
- }
-
- mvm := &multiVirtualMachine{
- goVM: goVM,
-
- t: t,
- }
-
- // If available, add the OS VM for tests which verify that both the Go
- // VM and OS VM have exactly the same output for the same input program
- // and packet.
- done := func() {}
- if canUseOSVM() {
- osVM, osVMDone := testOSVM(t, filter)
- done = func() { osVMDone() }
- mvm.osVM = osVM
- }
-
- return mvm, done, nil
-}
-
-// udpHeaderLen is the length of a UDP header.
-const udpHeaderLen = 8
-
-// A multiVirtualMachine is a virtualMachine which can call out to both the Go VM
-// and the native OS VM, if the OS VM is available.
-type multiVirtualMachine struct {
- goVM virtualMachine
- osVM virtualMachine
-
- t *testing.T
-}
-
-func (mvm *multiVirtualMachine) Run(in []byte) (int, error) {
- if len(in) < udpHeaderLen {
- mvm.t.Fatalf("input must be at least length of UDP header (%d), got: %d",
- udpHeaderLen, len(in))
- }
-
- // All tests have a UDP header as part of input, because the OS VM
- // packets always will. For the Go VM, this output is trimmed before
- // being sent back to tests.
- goOut, goErr := mvm.goVM.Run(in)
- if goOut >= udpHeaderLen {
- goOut -= udpHeaderLen
- }
-
- // If Go output is larger than the size of the packet, packet filtering
- // interop tests must trim the output bytes to the length of the packet.
- // The BPF VM should not do this on its own, as other uses of it do
- // not trim the output byte count.
- trim := len(in) - udpHeaderLen
- if goOut > trim {
- goOut = trim
- }
-
- // When the OS VM is not available, process using the Go VM alone
- if mvm.osVM == nil {
- return goOut, goErr
- }
-
- // The OS VM will apply its own UDP header, so remove the pseudo header
- // that the Go VM needs.
- osOut, err := mvm.osVM.Run(in[udpHeaderLen:])
- if err != nil {
- mvm.t.Fatalf("error while running OS VM: %v", err)
- }
-
- // Verify both VMs return same number of bytes
- var mismatch bool
- if goOut != osOut {
- mismatch = true
- mvm.t.Logf("output byte count does not match:\n- go: %v\n- os: %v", goOut, osOut)
- }
-
- if mismatch {
- mvm.t.Fatal("Go BPF and OS BPF packet outputs do not match")
- }
-
- return goOut, goErr
-}
-
-// An osVirtualMachine is a virtualMachine which uses the OS's BPF VM for
-// processing BPF programs.
-type osVirtualMachine struct {
- l net.PacketConn
- s net.Conn
-}
-
-// testOSVM creates a virtualMachine which uses the OS's BPF VM by injecting
-// packets into a UDP listener with a BPF program attached to it.
-func testOSVM(t *testing.T, filter []bpf.Instruction) (virtualMachine, func()) {
- l, err := net.ListenPacket("udp4", "127.0.0.1:0")
- if err != nil {
- t.Fatalf("failed to open OS VM UDP listener: %v", err)
- }
-
- prog, err := bpf.Assemble(filter)
- if err != nil {
- t.Fatalf("failed to compile BPF program: %v", err)
- }
-
- p := ipv4.NewPacketConn(l)
- if err = p.SetBPF(prog); err != nil {
- t.Fatalf("failed to attach BPF program to listener: %v", err)
- }
-
- s, err := net.Dial("udp4", l.LocalAddr().String())
- if err != nil {
- t.Fatalf("failed to dial connection to listener: %v", err)
- }
-
- done := func() {
- _ = s.Close()
- _ = l.Close()
- }
-
- return &osVirtualMachine{
- l: l,
- s: s,
- }, done
-}
-
-// Run sends the input bytes into the OS's BPF VM and returns its verdict.
-func (vm *osVirtualMachine) Run(in []byte) (int, error) {
- go func() {
- _, _ = vm.s.Write(in)
- }()
-
- vm.l.SetDeadline(time.Now().Add(50 * time.Millisecond))
-
- var b [512]byte
- n, _, err := vm.l.ReadFrom(b[:])
- if err != nil {
- // A timeout indicates that BPF filtered out the packet, and thus,
- // no input should be returned.
- if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
- return n, nil
- }
-
- return n, err
- }
-
- return n, nil
-}
diff --git a/vendor/golang.org/x/net/bpf/vm_extension_test.go b/vendor/golang.org/x/net/bpf/vm_extension_test.go
deleted file mode 100644
index 7a48c82f3..000000000
--- a/vendor/golang.org/x/net/bpf/vm_extension_test.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "testing"
-
- "golang.org/x/net/bpf"
-)
-
-func TestVMLoadExtensionNotImplemented(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.LoadExtension{
- Num: 100,
- },
- bpf.RetA{},
- })
- if errStr(err) != "extension 100 not implemented" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMLoadExtensionExtLen(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadExtension{
- Num: bpf.ExtLen,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 4, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
diff --git a/vendor/golang.org/x/net/bpf/vm_jump_test.go b/vendor/golang.org/x/net/bpf/vm_jump_test.go
deleted file mode 100644
index e0a3a988b..000000000
--- a/vendor/golang.org/x/net/bpf/vm_jump_test.go
+++ /dev/null
@@ -1,380 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "testing"
-
- "golang.org/x/net/bpf"
-)
-
-func TestVMJumpOne(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.Jump{
- Skip: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 1,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpOutOfProgram(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.Jump{
- Skip: 1,
- },
- bpf.RetA{},
- })
- if errStr(err) != "cannot jump 1 instructions; jumping past program bounds" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMJumpIfTrueOutOfProgram(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- SkipTrue: 2,
- },
- bpf.RetA{},
- })
- if errStr(err) != "cannot jump 2 instructions in true case; jumping past program bounds" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMJumpIfFalseOutOfProgram(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- SkipFalse: 3,
- },
- bpf.RetA{},
- })
- if errStr(err) != "cannot jump 3 instructions in false case; jumping past program bounds" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMJumpIfEqual(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 1,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 1,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpIfNotEqual(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.JumpIf{
- Cond: bpf.JumpNotEqual,
- Val: 1,
- SkipFalse: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 1,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpIfGreaterThan(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 4,
- },
- bpf.JumpIf{
- Cond: bpf.JumpGreaterThan,
- Val: 0x00010202,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 12,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 4, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpIfLessThan(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 4,
- },
- bpf.JumpIf{
- Cond: bpf.JumpLessThan,
- Val: 0xff010203,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 12,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 4, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpIfGreaterOrEqual(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 4,
- },
- bpf.JumpIf{
- Cond: bpf.JumpGreaterOrEqual,
- Val: 0x00010203,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 12,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 4, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpIfLessOrEqual(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 4,
- },
- bpf.JumpIf{
- Cond: bpf.JumpLessOrEqual,
- Val: 0xff010203,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 12,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 4, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpIfBitsSet(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 2,
- },
- bpf.JumpIf{
- Cond: bpf.JumpBitsSet,
- Val: 0x1122,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 10,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x01, 0x02,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 2, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMJumpIfBitsNotSet(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 2,
- },
- bpf.JumpIf{
- Cond: bpf.JumpBitsNotSet,
- Val: 0x1221,
- SkipTrue: 1,
- },
- bpf.RetConstant{
- Val: 0,
- },
- bpf.RetConstant{
- Val: 10,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x01, 0x02,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 2, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
diff --git a/vendor/golang.org/x/net/bpf/vm_load_test.go b/vendor/golang.org/x/net/bpf/vm_load_test.go
deleted file mode 100644
index 04578b66b..000000000
--- a/vendor/golang.org/x/net/bpf/vm_load_test.go
+++ /dev/null
@@ -1,246 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "net"
- "testing"
-
- "golang.org/x/net/bpf"
- "golang.org/x/net/ipv4"
-)
-
-func TestVMLoadAbsoluteOffsetOutOfBounds(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 100,
- Size: 2,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1, 2, 3,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMLoadAbsoluteOffsetPlusSizeOutOfBounds(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 2,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMLoadAbsoluteBadInstructionSize(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Size: 5,
- },
- bpf.RetA{},
- })
- if errStr(err) != "assembling instruction 1: invalid load byte length 0" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMLoadConstantOK(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadConstant{
- Dst: bpf.RegX,
- Val: 9,
- },
- bpf.TXA{},
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMLoadIndirectOutOfBounds(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadIndirect{
- Off: 100,
- Size: 1,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMLoadMemShiftOutOfBounds(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadMemShift{
- Off: 100,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-const (
- dhcp4Port = 53
-)
-
-func TestVMLoadMemShiftLoadIndirectNoResult(t *testing.T) {
- vm, in, done := testDHCPv4(t)
- defer done()
-
- // Append mostly empty UDP header with incorrect DHCPv4 port
- in = append(in, []byte{
- 0, 0,
- 0, dhcp4Port + 1,
- 0, 0,
- 0, 0,
- }...)
-
- out, err := vm.Run(in)
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 0, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMLoadMemShiftLoadIndirectOK(t *testing.T) {
- vm, in, done := testDHCPv4(t)
- defer done()
-
- // Append mostly empty UDP header with correct DHCPv4 port
- in = append(in, []byte{
- 0, 0,
- 0, dhcp4Port,
- 0, 0,
- 0, 0,
- }...)
-
- out, err := vm.Run(in)
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := len(in)-8, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func testDHCPv4(t *testing.T) (virtualMachine, []byte, func()) {
- // DHCPv4 test data courtesy of David Anderson:
- // https://github.com/google/netboot/blob/master/dhcp4/conn_linux.go#L59-L70
- vm, done, err := testVM(t, []bpf.Instruction{
- // Load IPv4 packet length
- bpf.LoadMemShift{Off: 8},
- // Get UDP dport
- bpf.LoadIndirect{Off: 8 + 2, Size: 2},
- // Correct dport?
- bpf.JumpIf{Cond: bpf.JumpEqual, Val: dhcp4Port, SkipFalse: 1},
- // Accept
- bpf.RetConstant{Val: 1500},
- // Ignore
- bpf.RetConstant{Val: 0},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
-
- // Minimal requirements to make a valid IPv4 header
- h := &ipv4.Header{
- Len: ipv4.HeaderLen,
- Src: net.IPv4(192, 168, 1, 1),
- Dst: net.IPv4(192, 168, 1, 2),
- }
- hb, err := h.Marshal()
- if err != nil {
- t.Fatalf("failed to marshal IPv4 header: %v", err)
- }
-
- hb = append([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- }, hb...)
-
- return vm, hb, done
-}
diff --git a/vendor/golang.org/x/net/bpf/vm_ret_test.go b/vendor/golang.org/x/net/bpf/vm_ret_test.go
deleted file mode 100644
index 2d86eae3e..000000000
--- a/vendor/golang.org/x/net/bpf/vm_ret_test.go
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "testing"
-
- "golang.org/x/net/bpf"
-)
-
-func TestVMRetA(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 9,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMRetALargerThanInput(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadAbsolute{
- Off: 8,
- Size: 2,
- },
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 255,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 2, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMRetConstant(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.RetConstant{
- Val: 9,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 1, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMRetConstantLargerThanInput(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.RetConstant{
- Val: 16,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 1,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 2, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
diff --git a/vendor/golang.org/x/net/bpf/vm_scratch_test.go b/vendor/golang.org/x/net/bpf/vm_scratch_test.go
deleted file mode 100644
index e600e3c28..000000000
--- a/vendor/golang.org/x/net/bpf/vm_scratch_test.go
+++ /dev/null
@@ -1,247 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "testing"
-
- "golang.org/x/net/bpf"
-)
-
-func TestVMStoreScratchInvalidScratchRegisterTooSmall(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.StoreScratch{
- Src: bpf.RegA,
- N: -1,
- },
- bpf.RetA{},
- })
- if errStr(err) != "assembling instruction 1: invalid scratch slot -1" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMStoreScratchInvalidScratchRegisterTooLarge(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.StoreScratch{
- Src: bpf.RegA,
- N: 16,
- },
- bpf.RetA{},
- })
- if errStr(err) != "assembling instruction 1: invalid scratch slot 16" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMStoreScratchUnknownSourceRegister(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.StoreScratch{
- Src: 100,
- N: 0,
- },
- bpf.RetA{},
- })
- if errStr(err) != "assembling instruction 1: invalid source register 100" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMLoadScratchInvalidScratchRegisterTooSmall(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.LoadScratch{
- Dst: bpf.RegX,
- N: -1,
- },
- bpf.RetA{},
- })
- if errStr(err) != "assembling instruction 1: invalid scratch slot -1" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMLoadScratchInvalidScratchRegisterTooLarge(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.LoadScratch{
- Dst: bpf.RegX,
- N: 16,
- },
- bpf.RetA{},
- })
- if errStr(err) != "assembling instruction 1: invalid scratch slot 16" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMLoadScratchUnknownDestinationRegister(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.LoadScratch{
- Dst: 100,
- N: 0,
- },
- bpf.RetA{},
- })
- if errStr(err) != "assembling instruction 1: invalid target register 100" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMStoreScratchLoadScratchOneValue(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- // Load byte 255
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- // Copy to X and store in scratch[0]
- bpf.TAX{},
- bpf.StoreScratch{
- Src: bpf.RegX,
- N: 0,
- },
- // Load byte 1
- bpf.LoadAbsolute{
- Off: 9,
- Size: 1,
- },
- // Overwrite 1 with 255 from scratch[0]
- bpf.LoadScratch{
- Dst: bpf.RegA,
- N: 0,
- },
- // Return 255
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 255, 1, 2,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 3, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
-
-func TestVMStoreScratchLoadScratchMultipleValues(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- // Load byte 10
- bpf.LoadAbsolute{
- Off: 8,
- Size: 1,
- },
- // Store in scratch[0]
- bpf.StoreScratch{
- Src: bpf.RegA,
- N: 0,
- },
- // Load byte 20
- bpf.LoadAbsolute{
- Off: 9,
- Size: 1,
- },
- // Store in scratch[1]
- bpf.StoreScratch{
- Src: bpf.RegA,
- N: 1,
- },
- // Load byte 30
- bpf.LoadAbsolute{
- Off: 10,
- Size: 1,
- },
- // Store in scratch[2]
- bpf.StoreScratch{
- Src: bpf.RegA,
- N: 2,
- },
- // Load byte 1
- bpf.LoadAbsolute{
- Off: 11,
- Size: 1,
- },
- // Store in scratch[3]
- bpf.StoreScratch{
- Src: bpf.RegA,
- N: 3,
- },
- // Load in byte 10 to X
- bpf.LoadScratch{
- Dst: bpf.RegX,
- N: 0,
- },
- // Copy X -> A
- bpf.TXA{},
- // Verify value is 10
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 10,
- SkipTrue: 1,
- },
- // Fail test if incorrect
- bpf.RetConstant{
- Val: 0,
- },
- // Load in byte 20 to A
- bpf.LoadScratch{
- Dst: bpf.RegA,
- N: 1,
- },
- // Verify value is 20
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 20,
- SkipTrue: 1,
- },
- // Fail test if incorrect
- bpf.RetConstant{
- Val: 0,
- },
- // Load in byte 30 to A
- bpf.LoadScratch{
- Dst: bpf.RegA,
- N: 2,
- },
- // Verify value is 30
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: 30,
- SkipTrue: 1,
- },
- // Fail test if incorrect
- bpf.RetConstant{
- Val: 0,
- },
- // Return first two bytes on success
- bpf.RetConstant{
- Val: 10,
- },
- })
- if err != nil {
- t.Fatalf("failed to load BPF program: %v", err)
- }
- defer done()
-
- out, err := vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 10, 20, 30, 1,
- })
- if err != nil {
- t.Fatalf("unexpected error while running program: %v", err)
- }
- if want, got := 2, out; want != got {
- t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
- want, got)
- }
-}
diff --git a/vendor/golang.org/x/net/bpf/vm_test.go b/vendor/golang.org/x/net/bpf/vm_test.go
deleted file mode 100644
index 6bd4dd5c3..000000000
--- a/vendor/golang.org/x/net/bpf/vm_test.go
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package bpf_test
-
-import (
- "fmt"
- "testing"
-
- "golang.org/x/net/bpf"
-)
-
-var _ bpf.Instruction = unknown{}
-
-type unknown struct{}
-
-func (unknown) Assemble() (bpf.RawInstruction, error) {
- return bpf.RawInstruction{}, nil
-}
-
-func TestVMUnknownInstruction(t *testing.T) {
- vm, done, err := testVM(t, []bpf.Instruction{
- bpf.LoadConstant{
- Dst: bpf.RegA,
- Val: 100,
- },
- // Should terminate the program with an error immediately
- unknown{},
- bpf.RetA{},
- })
- if err != nil {
- t.Fatalf("unexpected error: %v", err)
- }
- defer done()
-
- _, err = vm.Run([]byte{
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00,
- })
- if errStr(err) != "unknown Instruction at index 1: bpf_test.unknown" {
- t.Fatalf("unexpected error while running program: %v", err)
- }
-}
-
-func TestVMNoReturnInstruction(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{
- bpf.LoadConstant{
- Dst: bpf.RegA,
- Val: 1,
- },
- })
- if errStr(err) != "BPF program must end with RetA or RetConstant" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-func TestVMNoInputInstructions(t *testing.T) {
- _, _, err := testVM(t, []bpf.Instruction{})
- if errStr(err) != "one or more Instructions must be specified" {
- t.Fatalf("unexpected error: %v", err)
- }
-}
-
-// ExampleNewVM demonstrates usage of a VM, using an Ethernet frame
-// as input and checking its EtherType to determine if it should be accepted.
-func ExampleNewVM() {
- // Offset | Length | Comment
- // -------------------------
- // 00 | 06 | Ethernet destination MAC address
- // 06 | 06 | Ethernet source MAC address
- // 12 | 02 | Ethernet EtherType
- const (
- etOff = 12
- etLen = 2
-
- etARP = 0x0806
- )
-
- // Set up a VM to filter traffic based on if its EtherType
- // matches the ARP EtherType.
- vm, err := bpf.NewVM([]bpf.Instruction{
- // Load EtherType value from Ethernet header
- bpf.LoadAbsolute{
- Off: etOff,
- Size: etLen,
- },
- // If EtherType is equal to the ARP EtherType, jump to allow
- // packet to be accepted
- bpf.JumpIf{
- Cond: bpf.JumpEqual,
- Val: etARP,
- SkipTrue: 1,
- },
- // EtherType does not match the ARP EtherType
- bpf.RetConstant{
- Val: 0,
- },
- // EtherType matches the ARP EtherType, accept up to 1500
- // bytes of packet
- bpf.RetConstant{
- Val: 1500,
- },
- })
- if err != nil {
- panic(fmt.Sprintf("failed to load BPF program: %v", err))
- }
-
- // Create an Ethernet frame with the ARP EtherType for testing
- frame := []byte{
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
- 0x08, 0x06,
- // Payload omitted for brevity
- }
-
- // Run our VM's BPF program using the Ethernet frame as input
- out, err := vm.Run(frame)
- if err != nil {
- panic(fmt.Sprintf("failed to accept Ethernet frame: %v", err))
- }
-
- // BPF VM can return a byte count greater than the number of input
- // bytes, so trim the output to match the input byte length
- if out > len(frame) {
- out = len(frame)
- }
-
- fmt.Printf("out: %d bytes", out)
-
- // Output:
- // out: 14 bytes
-}
-
-// errStr returns the string representation of an error, or
-// "<nil>" if it is nil.
-func errStr(err error) string {
- if err == nil {
- return "<nil>"
- }
-
- return err.Error()
-}