vendor: Mega update all dependencies
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
3
vendor/golang.org/x/net/bpf/constants.go
generated
vendored
3
vendor/golang.org/x/net/bpf/constants.go
generated
vendored
@@ -70,6 +70,9 @@ type Extension int
|
||||
|
||||
// Extension functions available in the Linux kernel.
|
||||
const (
|
||||
// extOffset is the negative maximum number of instructions used
|
||||
// to load instructions by overloading the K argument.
|
||||
extOffset = -0x1000
|
||||
// ExtLen returns the length of the packet.
|
||||
ExtLen Extension = 1
|
||||
// ExtProto returns the packet's L3 protocol type.
|
||||
|
||||
272
vendor/golang.org/x/net/bpf/instructions.go
generated
vendored
272
vendor/golang.org/x/net/bpf/instructions.go
generated
vendored
@@ -57,6 +57,9 @@ func (ri RawInstruction) Disassemble() Instruction {
|
||||
}
|
||||
return LoadScratch{Dst: reg, N: int(ri.K)}
|
||||
case opAddrModeAbsolute:
|
||||
if ri.K > extOffset+0xffffffff {
|
||||
return LoadExtension{Num: Extension(-extOffset + ri.K)}
|
||||
}
|
||||
return LoadAbsolute{Size: sz, Off: ri.K}
|
||||
case opAddrModeIndirect:
|
||||
return LoadIndirect{Size: sz, Off: ri.K}
|
||||
@@ -104,6 +107,14 @@ func (ri RawInstruction) Disassemble() Instruction {
|
||||
case opJumpAlways:
|
||||
return Jump{Skip: ri.K}
|
||||
case opJumpEqual:
|
||||
if ri.Jt == 0 {
|
||||
return JumpIf{
|
||||
Cond: JumpNotEqual,
|
||||
Val: ri.K,
|
||||
SkipTrue: ri.Jf,
|
||||
SkipFalse: 0,
|
||||
}
|
||||
}
|
||||
return JumpIf{
|
||||
Cond: JumpEqual,
|
||||
Val: ri.K,
|
||||
@@ -111,6 +122,14 @@ func (ri RawInstruction) Disassemble() Instruction {
|
||||
SkipFalse: ri.Jf,
|
||||
}
|
||||
case opJumpGT:
|
||||
if ri.Jt == 0 {
|
||||
return JumpIf{
|
||||
Cond: JumpLessOrEqual,
|
||||
Val: ri.K,
|
||||
SkipTrue: ri.Jf,
|
||||
SkipFalse: 0,
|
||||
}
|
||||
}
|
||||
return JumpIf{
|
||||
Cond: JumpGreaterThan,
|
||||
Val: ri.K,
|
||||
@@ -118,6 +137,14 @@ func (ri RawInstruction) Disassemble() Instruction {
|
||||
SkipFalse: ri.Jf,
|
||||
}
|
||||
case opJumpGE:
|
||||
if ri.Jt == 0 {
|
||||
return JumpIf{
|
||||
Cond: JumpLessThan,
|
||||
Val: ri.K,
|
||||
SkipTrue: ri.Jf,
|
||||
SkipFalse: 0,
|
||||
}
|
||||
}
|
||||
return JumpIf{
|
||||
Cond: JumpGreaterOrEqual,
|
||||
Val: ri.K,
|
||||
@@ -171,6 +198,18 @@ func (a LoadConstant) Assemble() (RawInstruction, error) {
|
||||
return assembleLoad(a.Dst, 4, opAddrModeImmediate, a.Val)
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a LoadConstant) String() string {
|
||||
switch a.Dst {
|
||||
case RegA:
|
||||
return fmt.Sprintf("ld #%d", a.Val)
|
||||
case RegX:
|
||||
return fmt.Sprintf("ldx #%d", a.Val)
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadScratch loads scratch[N] into register Dst.
|
||||
type LoadScratch struct {
|
||||
Dst Register
|
||||
@@ -185,6 +224,18 @@ func (a LoadScratch) Assemble() (RawInstruction, error) {
|
||||
return assembleLoad(a.Dst, 4, opAddrModeScratch, uint32(a.N))
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a LoadScratch) String() string {
|
||||
switch a.Dst {
|
||||
case RegA:
|
||||
return fmt.Sprintf("ld M[%d]", a.N)
|
||||
case RegX:
|
||||
return fmt.Sprintf("ldx M[%d]", a.N)
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadAbsolute loads packet[Off:Off+Size] as an integer value into
|
||||
// register A.
|
||||
type LoadAbsolute struct {
|
||||
@@ -197,6 +248,23 @@ func (a LoadAbsolute) Assemble() (RawInstruction, error) {
|
||||
return assembleLoad(RegA, a.Size, opAddrModeAbsolute, a.Off)
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a LoadAbsolute) String() string {
|
||||
switch a.Size {
|
||||
case 1: // byte
|
||||
return fmt.Sprintf("ldb [%d]", a.Off)
|
||||
case 2: // half word
|
||||
return fmt.Sprintf("ldh [%d]", a.Off)
|
||||
case 4: // word
|
||||
if a.Off > extOffset+0xffffffff {
|
||||
return LoadExtension{Num: Extension(a.Off + 0x1000)}.String()
|
||||
}
|
||||
return fmt.Sprintf("ld [%d]", a.Off)
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadIndirect loads packet[X+Off:X+Off+Size] as an integer value
|
||||
// into register A.
|
||||
type LoadIndirect struct {
|
||||
@@ -209,6 +277,20 @@ func (a LoadIndirect) Assemble() (RawInstruction, error) {
|
||||
return assembleLoad(RegA, a.Size, opAddrModeIndirect, a.Off)
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a LoadIndirect) String() string {
|
||||
switch a.Size {
|
||||
case 1: // byte
|
||||
return fmt.Sprintf("ldb [x + %d]", a.Off)
|
||||
case 2: // half word
|
||||
return fmt.Sprintf("ldh [x + %d]", a.Off)
|
||||
case 4: // word
|
||||
return fmt.Sprintf("ld [x + %d]", a.Off)
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadMemShift multiplies the first 4 bits of the byte at packet[Off]
|
||||
// by 4 and stores the result in register X.
|
||||
//
|
||||
@@ -224,6 +306,11 @@ func (a LoadMemShift) Assemble() (RawInstruction, error) {
|
||||
return assembleLoad(RegX, 1, opAddrModeMemShift, a.Off)
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a LoadMemShift) String() string {
|
||||
return fmt.Sprintf("ldx 4*([%d]&0xf)", a.Off)
|
||||
}
|
||||
|
||||
// LoadExtension invokes a linux-specific extension and stores the
|
||||
// result in register A.
|
||||
type LoadExtension struct {
|
||||
@@ -235,7 +322,47 @@ func (a LoadExtension) Assemble() (RawInstruction, error) {
|
||||
if a.Num == ExtLen {
|
||||
return assembleLoad(RegA, 4, opAddrModePacketLen, 0)
|
||||
}
|
||||
return assembleLoad(RegA, 4, opAddrModeAbsolute, uint32(-0x1000+a.Num))
|
||||
return assembleLoad(RegA, 4, opAddrModeAbsolute, uint32(extOffset+a.Num))
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a LoadExtension) String() string {
|
||||
switch a.Num {
|
||||
case ExtLen:
|
||||
return "ld #len"
|
||||
case ExtProto:
|
||||
return "ld #proto"
|
||||
case ExtType:
|
||||
return "ld #type"
|
||||
case ExtPayloadOffset:
|
||||
return "ld #poff"
|
||||
case ExtInterfaceIndex:
|
||||
return "ld #ifidx"
|
||||
case ExtNetlinkAttr:
|
||||
return "ld #nla"
|
||||
case ExtNetlinkAttrNested:
|
||||
return "ld #nlan"
|
||||
case ExtMark:
|
||||
return "ld #mark"
|
||||
case ExtQueue:
|
||||
return "ld #queue"
|
||||
case ExtLinkLayerType:
|
||||
return "ld #hatype"
|
||||
case ExtRXHash:
|
||||
return "ld #rxhash"
|
||||
case ExtCPUID:
|
||||
return "ld #cpu"
|
||||
case ExtVLANTag:
|
||||
return "ld #vlan_tci"
|
||||
case ExtVLANTagPresent:
|
||||
return "ld #vlan_avail"
|
||||
case ExtVLANProto:
|
||||
return "ld #vlan_tpid"
|
||||
case ExtRand:
|
||||
return "ld #rand"
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// StoreScratch stores register Src into scratch[N].
|
||||
@@ -265,6 +392,18 @@ func (a StoreScratch) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a StoreScratch) String() string {
|
||||
switch a.Src {
|
||||
case RegA:
|
||||
return fmt.Sprintf("st M[%d]", a.N)
|
||||
case RegX:
|
||||
return fmt.Sprintf("stx M[%d]", a.N)
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// ALUOpConstant executes A = A <Op> Val.
|
||||
type ALUOpConstant struct {
|
||||
Op ALUOp
|
||||
@@ -279,6 +418,34 @@ func (a ALUOpConstant) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a ALUOpConstant) String() string {
|
||||
switch a.Op {
|
||||
case ALUOpAdd:
|
||||
return fmt.Sprintf("add #%d", a.Val)
|
||||
case ALUOpSub:
|
||||
return fmt.Sprintf("sub #%d", a.Val)
|
||||
case ALUOpMul:
|
||||
return fmt.Sprintf("mul #%d", a.Val)
|
||||
case ALUOpDiv:
|
||||
return fmt.Sprintf("div #%d", a.Val)
|
||||
case ALUOpMod:
|
||||
return fmt.Sprintf("mod #%d", a.Val)
|
||||
case ALUOpAnd:
|
||||
return fmt.Sprintf("and #%d", a.Val)
|
||||
case ALUOpOr:
|
||||
return fmt.Sprintf("or #%d", a.Val)
|
||||
case ALUOpXor:
|
||||
return fmt.Sprintf("xor #%d", a.Val)
|
||||
case ALUOpShiftLeft:
|
||||
return fmt.Sprintf("lsh #%d", a.Val)
|
||||
case ALUOpShiftRight:
|
||||
return fmt.Sprintf("rsh #%d", a.Val)
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// ALUOpX executes A = A <Op> X
|
||||
type ALUOpX struct {
|
||||
Op ALUOp
|
||||
@@ -291,6 +458,34 @@ func (a ALUOpX) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a ALUOpX) String() string {
|
||||
switch a.Op {
|
||||
case ALUOpAdd:
|
||||
return "add x"
|
||||
case ALUOpSub:
|
||||
return "sub x"
|
||||
case ALUOpMul:
|
||||
return "mul x"
|
||||
case ALUOpDiv:
|
||||
return "div x"
|
||||
case ALUOpMod:
|
||||
return "mod x"
|
||||
case ALUOpAnd:
|
||||
return "and x"
|
||||
case ALUOpOr:
|
||||
return "or x"
|
||||
case ALUOpXor:
|
||||
return "xor x"
|
||||
case ALUOpShiftLeft:
|
||||
return "lsh x"
|
||||
case ALUOpShiftRight:
|
||||
return "rsh x"
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// NegateA executes A = -A.
|
||||
type NegateA struct{}
|
||||
|
||||
@@ -301,6 +496,11 @@ func (a NegateA) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a NegateA) String() string {
|
||||
return fmt.Sprintf("neg")
|
||||
}
|
||||
|
||||
// Jump skips the following Skip instructions in the program.
|
||||
type Jump struct {
|
||||
Skip uint32
|
||||
@@ -314,6 +514,11 @@ func (a Jump) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a Jump) String() string {
|
||||
return fmt.Sprintf("ja %d", a.Skip)
|
||||
}
|
||||
|
||||
// JumpIf skips the following Skip instructions in the program if A
|
||||
// <Cond> Val is true.
|
||||
type JumpIf struct {
|
||||
@@ -361,6 +566,51 @@ func (a JumpIf) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a JumpIf) String() string {
|
||||
switch a.Cond {
|
||||
// K == A
|
||||
case JumpEqual:
|
||||
return conditionalJump(a, "jeq", "jneq")
|
||||
// K != A
|
||||
case JumpNotEqual:
|
||||
return fmt.Sprintf("jneq #%d,%d", a.Val, a.SkipTrue)
|
||||
// K > A
|
||||
case JumpGreaterThan:
|
||||
return conditionalJump(a, "jgt", "jle")
|
||||
// K < A
|
||||
case JumpLessThan:
|
||||
return fmt.Sprintf("jlt #%d,%d", a.Val, a.SkipTrue)
|
||||
// K >= A
|
||||
case JumpGreaterOrEqual:
|
||||
return conditionalJump(a, "jge", "jlt")
|
||||
// K <= A
|
||||
case JumpLessOrEqual:
|
||||
return fmt.Sprintf("jle #%d,%d", a.Val, a.SkipTrue)
|
||||
// K & A != 0
|
||||
case JumpBitsSet:
|
||||
if a.SkipFalse > 0 {
|
||||
return fmt.Sprintf("jset #%d,%d,%d", a.Val, a.SkipTrue, a.SkipFalse)
|
||||
}
|
||||
return fmt.Sprintf("jset #%d,%d", a.Val, a.SkipTrue)
|
||||
// K & A == 0, there is no assembler instruction for JumpBitNotSet, use JumpBitSet and invert skips
|
||||
case JumpBitsNotSet:
|
||||
return JumpIf{Cond: JumpBitsSet, SkipTrue: a.SkipFalse, SkipFalse: a.SkipTrue, Val: a.Val}.String()
|
||||
default:
|
||||
return fmt.Sprintf("unknown instruction: %#v", a)
|
||||
}
|
||||
}
|
||||
|
||||
func conditionalJump(inst JumpIf, positiveJump, negativeJump string) string {
|
||||
if inst.SkipTrue > 0 {
|
||||
if inst.SkipFalse > 0 {
|
||||
return fmt.Sprintf("%s #%d,%d,%d", positiveJump, inst.Val, inst.SkipTrue, inst.SkipFalse)
|
||||
}
|
||||
return fmt.Sprintf("%s #%d,%d", positiveJump, inst.Val, inst.SkipTrue)
|
||||
}
|
||||
return fmt.Sprintf("%s #%d,%d", negativeJump, inst.Val, inst.SkipFalse)
|
||||
}
|
||||
|
||||
// RetA exits the BPF program, returning the value of register A.
|
||||
type RetA struct{}
|
||||
|
||||
@@ -371,6 +621,11 @@ func (a RetA) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a RetA) String() string {
|
||||
return fmt.Sprintf("ret a")
|
||||
}
|
||||
|
||||
// RetConstant exits the BPF program, returning a constant value.
|
||||
type RetConstant struct {
|
||||
Val uint32
|
||||
@@ -384,6 +639,11 @@ func (a RetConstant) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a RetConstant) String() string {
|
||||
return fmt.Sprintf("ret #%d", a.Val)
|
||||
}
|
||||
|
||||
// TXA copies the value of register X to register A.
|
||||
type TXA struct{}
|
||||
|
||||
@@ -394,6 +654,11 @@ func (a TXA) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a TXA) String() string {
|
||||
return fmt.Sprintf("txa")
|
||||
}
|
||||
|
||||
// TAX copies the value of register A to register X.
|
||||
type TAX struct{}
|
||||
|
||||
@@ -404,6 +669,11 @@ func (a TAX) Assemble() (RawInstruction, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String returns the the instruction in assembler notation.
|
||||
func (a TAX) String() string {
|
||||
return fmt.Sprintf("tax")
|
||||
}
|
||||
|
||||
func assembleLoad(dst Register, loadSize int, mode uint16, k uint32) (RawInstruction, error) {
|
||||
var (
|
||||
cls uint16
|
||||
|
||||
184
vendor/golang.org/x/net/bpf/instructions_test.go
generated
vendored
184
vendor/golang.org/x/net/bpf/instructions_test.go
generated
vendored
@@ -1,184 +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 (
|
||||
"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.
|
||||
//
|
||||
// Because we offer "fake" jump conditions that don't appear in the
|
||||
// machine code, disassembly won't be a 1:1 match with the original
|
||||
// source, although the behavior will be identical. However,
|
||||
// reassembling the disassembly should produce an identical program.
|
||||
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))
|
||||
|
||||
src, allDecoded := Disassemble(prog1)
|
||||
if !allDecoded {
|
||||
t.Errorf("Disassemble(Assemble(allInstructions)) produced unrecognized instructions:")
|
||||
for i, inst := range src {
|
||||
if r, ok := inst.(RawInstruction); ok {
|
||||
t.Logf(" insn %d, %#v --> %#v", i+1, allInstructions[i], r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prog2, err := Assemble(src)
|
||||
if err != nil {
|
||||
t.Fatalf("assembly of Disassemble(Assemble(allInstructions)) failed: %s", err)
|
||||
}
|
||||
|
||||
if len(prog2) != len(prog1) {
|
||||
t.Fatalf("disassembly changed program size: %d insns before, %d insns after", len(prog1), len(prog2))
|
||||
}
|
||||
if !reflect.DeepEqual(prog1, prog2) {
|
||||
t.Errorf("program mutated by disassembly:")
|
||||
for i := range prog2 {
|
||||
if !reflect.DeepEqual(prog1[i], prog2[i]) {
|
||||
t.Logf(" insn %d, s: %#v, p1: %#v, p2: %#v", i+1, allInstructions[i], prog1[i], prog2[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf
generated
vendored
1
vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf
generated
vendored
@@ -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,
|
||||
79
vendor/golang.org/x/net/bpf/testdata/all_instructions.txt
generated
vendored
79
vendor/golang.org/x/net/bpf/testdata/all_instructions.txt
generated
vendored
@@ -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
|
||||
512
vendor/golang.org/x/net/bpf/vm_aluop_test.go
generated
vendored
512
vendor/golang.org/x/net/bpf/vm_aluop_test.go
generated
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
192
vendor/golang.org/x/net/bpf/vm_bpf_test.go
generated
vendored
192
vendor/golang.org/x/net/bpf/vm_bpf_test.go
generated
vendored
@@ -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
|
||||
}
|
||||
49
vendor/golang.org/x/net/bpf/vm_extension_test.go
generated
vendored
49
vendor/golang.org/x/net/bpf/vm_extension_test.go
generated
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
380
vendor/golang.org/x/net/bpf/vm_jump_test.go
generated
vendored
380
vendor/golang.org/x/net/bpf/vm_jump_test.go
generated
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
246
vendor/golang.org/x/net/bpf/vm_load_test.go
generated
vendored
246
vendor/golang.org/x/net/bpf/vm_load_test.go
generated
vendored
@@ -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
|
||||
}
|
||||
115
vendor/golang.org/x/net/bpf/vm_ret_test.go
generated
vendored
115
vendor/golang.org/x/net/bpf/vm_ret_test.go
generated
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
247
vendor/golang.org/x/net/bpf/vm_scratch_test.go
generated
vendored
247
vendor/golang.org/x/net/bpf/vm_scratch_test.go
generated
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
144
vendor/golang.org/x/net/bpf/vm_test.go
generated
vendored
144
vendor/golang.org/x/net/bpf/vm_test.go
generated
vendored
@@ -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()
|
||||
}
|
||||
30
vendor/golang.org/x/net/context/context.go
generated
vendored
30
vendor/golang.org/x/net/context/context.go
generated
vendored
@@ -7,7 +7,7 @@
|
||||
// and between processes.
|
||||
//
|
||||
// Incoming requests to a server should create a Context, and outgoing calls to
|
||||
// servers should accept a Context. The chain of function calls between must
|
||||
// servers should accept a Context. The chain of function calls between must
|
||||
// propagate the Context, optionally replacing it with a modified copy created
|
||||
// using WithDeadline, WithTimeout, WithCancel, or WithValue.
|
||||
//
|
||||
@@ -16,14 +16,14 @@
|
||||
// propagation:
|
||||
//
|
||||
// Do not store Contexts inside a struct type; instead, pass a Context
|
||||
// explicitly to each function that needs it. The Context should be the first
|
||||
// explicitly to each function that needs it. The Context should be the first
|
||||
// parameter, typically named ctx:
|
||||
//
|
||||
// func DoSomething(ctx context.Context, arg Arg) error {
|
||||
// // ... use ctx ...
|
||||
// }
|
||||
//
|
||||
// Do not pass a nil Context, even if a function permits it. Pass context.TODO
|
||||
// Do not pass a nil Context, even if a function permits it. Pass context.TODO
|
||||
// if you are unsure about which Context to use.
|
||||
//
|
||||
// Use context Values only for request-scoped data that transits processes and
|
||||
@@ -44,13 +44,13 @@ import "time"
|
||||
// Context's methods may be called by multiple goroutines simultaneously.
|
||||
type Context interface {
|
||||
// Deadline returns the time when work done on behalf of this context
|
||||
// should be canceled. Deadline returns ok==false when no deadline is
|
||||
// set. Successive calls to Deadline return the same results.
|
||||
// should be canceled. Deadline returns ok==false when no deadline is
|
||||
// set. Successive calls to Deadline return the same results.
|
||||
Deadline() (deadline time.Time, ok bool)
|
||||
|
||||
// Done returns a channel that's closed when work done on behalf of this
|
||||
// context should be canceled. Done may return nil if this context can
|
||||
// never be canceled. Successive calls to Done return the same value.
|
||||
// context should be canceled. Done may return nil if this context can
|
||||
// never be canceled. Successive calls to Done return the same value.
|
||||
//
|
||||
// WithCancel arranges for Done to be closed when cancel is called;
|
||||
// WithDeadline arranges for Done to be closed when the deadline
|
||||
@@ -79,24 +79,24 @@ type Context interface {
|
||||
// a Done channel for cancelation.
|
||||
Done() <-chan struct{}
|
||||
|
||||
// Err returns a non-nil error value after Done is closed. Err returns
|
||||
// Err returns a non-nil error value after Done is closed. Err returns
|
||||
// Canceled if the context was canceled or DeadlineExceeded if the
|
||||
// context's deadline passed. No other values for Err are defined.
|
||||
// context's deadline passed. No other values for Err are defined.
|
||||
// After Done is closed, successive calls to Err return the same value.
|
||||
Err() error
|
||||
|
||||
// Value returns the value associated with this context for key, or nil
|
||||
// if no value is associated with key. Successive calls to Value with
|
||||
// if no value is associated with key. Successive calls to Value with
|
||||
// the same key returns the same result.
|
||||
//
|
||||
// Use context values only for request-scoped data that transits
|
||||
// processes and API boundaries, not for passing optional parameters to
|
||||
// functions.
|
||||
//
|
||||
// A key identifies a specific value in a Context. Functions that wish
|
||||
// A key identifies a specific value in a Context. Functions that wish
|
||||
// to store values in Context typically allocate a key in a global
|
||||
// variable then use that key as the argument to context.WithValue and
|
||||
// Context.Value. A key can be any type that supports equality;
|
||||
// Context.Value. A key can be any type that supports equality;
|
||||
// packages should define keys as an unexported type to avoid
|
||||
// collisions.
|
||||
//
|
||||
@@ -115,7 +115,7 @@ type Context interface {
|
||||
// // This prevents collisions with keys defined in other packages.
|
||||
// type key int
|
||||
//
|
||||
// // userKey is the key for user.User values in Contexts. It is
|
||||
// // userKey is the key for user.User values in Contexts. It is
|
||||
// // unexported; clients use user.NewContext and user.FromContext
|
||||
// // instead of using this key directly.
|
||||
// var userKey key = 0
|
||||
@@ -134,14 +134,14 @@ type Context interface {
|
||||
}
|
||||
|
||||
// Background returns a non-nil, empty Context. It is never canceled, has no
|
||||
// values, and has no deadline. It is typically used by the main function,
|
||||
// values, and has no deadline. It is typically used by the main function,
|
||||
// initialization, and tests, and as the top-level Context for incoming
|
||||
// requests.
|
||||
func Background() Context {
|
||||
return background
|
||||
}
|
||||
|
||||
// TODO returns a non-nil, empty Context. Code should use context.TODO when
|
||||
// TODO returns a non-nil, empty Context. Code should use context.TODO when
|
||||
// it's unclear which Context to use or it is not yet available (because the
|
||||
// surrounding function has not yet been extended to accept a Context
|
||||
// parameter). TODO is recognized by static analysis tools that determine
|
||||
|
||||
4
vendor/golang.org/x/net/context/go17.go
generated
vendored
4
vendor/golang.org/x/net/context/go17.go
generated
vendored
@@ -35,8 +35,8 @@ func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
|
||||
}
|
||||
|
||||
// WithDeadline returns a copy of the parent context with the deadline adjusted
|
||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
||||
// context's Done channel is closed when the deadline expires, when the returned
|
||||
// cancel function is called, or when the parent context's Done channel is
|
||||
// closed, whichever happens first.
|
||||
|
||||
18
vendor/golang.org/x/net/context/pre_go17.go
generated
vendored
18
vendor/golang.org/x/net/context/pre_go17.go
generated
vendored
@@ -13,7 +13,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// An emptyCtx is never canceled, has no values, and has no deadline. It is not
|
||||
// An emptyCtx is never canceled, has no values, and has no deadline. It is not
|
||||
// struct{}, since vars of this type must have distinct addresses.
|
||||
type emptyCtx int
|
||||
|
||||
@@ -104,7 +104,7 @@ func propagateCancel(parent Context, child canceler) {
|
||||
}
|
||||
|
||||
// parentCancelCtx follows a chain of parent references until it finds a
|
||||
// *cancelCtx. This function understands how each of the concrete types in this
|
||||
// *cancelCtx. This function understands how each of the concrete types in this
|
||||
// package represents its parent.
|
||||
func parentCancelCtx(parent Context) (*cancelCtx, bool) {
|
||||
for {
|
||||
@@ -134,14 +134,14 @@ func removeChild(parent Context, child canceler) {
|
||||
p.mu.Unlock()
|
||||
}
|
||||
|
||||
// A canceler is a context type that can be canceled directly. The
|
||||
// A canceler is a context type that can be canceled directly. The
|
||||
// implementations are *cancelCtx and *timerCtx.
|
||||
type canceler interface {
|
||||
cancel(removeFromParent bool, err error)
|
||||
Done() <-chan struct{}
|
||||
}
|
||||
|
||||
// A cancelCtx can be canceled. When canceled, it also cancels any children
|
||||
// A cancelCtx can be canceled. When canceled, it also cancels any children
|
||||
// that implement canceler.
|
||||
type cancelCtx struct {
|
||||
Context
|
||||
@@ -193,8 +193,8 @@ func (c *cancelCtx) cancel(removeFromParent bool, err error) {
|
||||
}
|
||||
|
||||
// WithDeadline returns a copy of the parent context with the deadline adjusted
|
||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
||||
// context's Done channel is closed when the deadline expires, when the returned
|
||||
// cancel function is called, or when the parent context's Done channel is
|
||||
// closed, whichever happens first.
|
||||
@@ -226,8 +226,8 @@ func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
|
||||
return c, func() { c.cancel(true, Canceled) }
|
||||
}
|
||||
|
||||
// A timerCtx carries a timer and a deadline. It embeds a cancelCtx to
|
||||
// implement Done and Err. It implements cancel by stopping its timer then
|
||||
// A timerCtx carries a timer and a deadline. It embeds a cancelCtx to
|
||||
// implement Done and Err. It implements cancel by stopping its timer then
|
||||
// delegating to cancelCtx.cancel.
|
||||
type timerCtx struct {
|
||||
*cancelCtx
|
||||
@@ -281,7 +281,7 @@ func WithValue(parent Context, key interface{}, val interface{}) Context {
|
||||
return &valueCtx{parent, key, val}
|
||||
}
|
||||
|
||||
// A valueCtx carries a key-value pair. It implements Value for that key and
|
||||
// A valueCtx carries a key-value pair. It implements Value for that key and
|
||||
// delegates all other calls to the embedded Context.
|
||||
type valueCtx struct {
|
||||
Context
|
||||
|
||||
2
vendor/golang.org/x/net/internal/iana/gen.go
generated
vendored
2
vendor/golang.org/x/net/internal/iana/gen.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Copyright 2013 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.
|
||||
|
||||
|
||||
4
vendor/golang.org/x/net/internal/netreflect/socket.go
generated
vendored
4
vendor/golang.org/x/net/internal/netreflect/socket.go
generated
vendored
@@ -2,8 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !go1.9
|
||||
|
||||
// Package netreflect implements run-time reflection for the
|
||||
// facilities of net package.
|
||||
//
|
||||
// This package works only for Go 1.8 or below.
|
||||
package netreflect
|
||||
|
||||
import (
|
||||
|
||||
37
vendor/golang.org/x/net/internal/netreflect/socket_19.go
generated
vendored
Normal file
37
vendor/golang.org/x/net/internal/netreflect/socket_19.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2017 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.
|
||||
|
||||
// +build go1.9
|
||||
|
||||
package netreflect
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidType = errors.New("invalid type")
|
||||
errOpNoSupport = errors.New("operation not supported")
|
||||
)
|
||||
|
||||
// SocketOf returns the socket descriptor of c.
|
||||
func SocketOf(c net.Conn) (uintptr, error) {
|
||||
switch c.(type) {
|
||||
case *net.TCPConn, *net.UDPConn, *net.IPConn, *net.UnixConn:
|
||||
return 0, errOpNoSupport
|
||||
default:
|
||||
return 0, errInvalidType
|
||||
}
|
||||
}
|
||||
|
||||
// PacketSocketOf returns the socket descriptor of c.
|
||||
func PacketSocketOf(c net.PacketConn) (uintptr, error) {
|
||||
switch c.(type) {
|
||||
case *net.UDPConn, *net.IPConn, *net.UnixConn:
|
||||
return 0, errOpNoSupport
|
||||
default:
|
||||
return 0, errInvalidType
|
||||
}
|
||||
}
|
||||
1
vendor/golang.org/x/net/internal/netreflect/socket_posix.go
generated
vendored
1
vendor/golang.org/x/net/internal/netreflect/socket_posix.go
generated
vendored
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !go1.9
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
|
||||
|
||||
package netreflect
|
||||
|
||||
1
vendor/golang.org/x/net/internal/netreflect/socket_stub.go
generated
vendored
1
vendor/golang.org/x/net/internal/netreflect/socket_stub.go
generated
vendored
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !go1.9
|
||||
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
|
||||
|
||||
package netreflect
|
||||
|
||||
31
vendor/golang.org/x/net/internal/nettest/error_posix.go
generated
vendored
31
vendor/golang.org/x/net/internal/nettest/error_posix.go
generated
vendored
@@ -1,31 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
|
||||
|
||||
package nettest
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func protocolNotSupported(err error) bool {
|
||||
switch err := err.(type) {
|
||||
case syscall.Errno:
|
||||
switch err {
|
||||
case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
|
||||
return true
|
||||
}
|
||||
case *os.SyscallError:
|
||||
switch err := err.Err.(type) {
|
||||
case syscall.Errno:
|
||||
switch err {
|
||||
case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
11
vendor/golang.org/x/net/internal/nettest/error_stub.go
generated
vendored
11
vendor/golang.org/x/net/internal/nettest/error_stub.go
generated
vendored
@@ -1,11 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
// +build nacl plan9
|
||||
|
||||
package nettest
|
||||
|
||||
func protocolNotSupported(err error) bool {
|
||||
return false
|
||||
}
|
||||
94
vendor/golang.org/x/net/internal/nettest/interface.go
generated
vendored
94
vendor/golang.org/x/net/internal/nettest/interface.go
generated
vendored
@@ -1,94 +0,0 @@
|
||||
// Copyright 2012 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 nettest
|
||||
|
||||
import "net"
|
||||
|
||||
// IsMulticastCapable reports whether ifi is an IP multicast-capable
|
||||
// network interface. Network must be "ip", "ip4" or "ip6".
|
||||
func IsMulticastCapable(network string, ifi *net.Interface) (net.IP, bool) {
|
||||
switch network {
|
||||
case "ip", "ip4", "ip6":
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
if ifi == nil || ifi.Flags&net.FlagUp == 0 || ifi.Flags&net.FlagMulticast == 0 {
|
||||
return nil, false
|
||||
}
|
||||
return hasRoutableIP(network, ifi)
|
||||
}
|
||||
|
||||
// RoutedInterface returns a network interface that can route IP
|
||||
// traffic and satisfies flags. It returns nil when an appropriate
|
||||
// network interface is not found. Network must be "ip", "ip4" or
|
||||
// "ip6".
|
||||
func RoutedInterface(network string, flags net.Flags) *net.Interface {
|
||||
switch network {
|
||||
case "ip", "ip4", "ip6":
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, ifi := range ift {
|
||||
if ifi.Flags&flags != flags {
|
||||
continue
|
||||
}
|
||||
if _, ok := hasRoutableIP(network, &ifi); !ok {
|
||||
continue
|
||||
}
|
||||
return &ifi
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func hasRoutableIP(network string, ifi *net.Interface) (net.IP, bool) {
|
||||
ifat, err := ifi.Addrs()
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
for _, ifa := range ifat {
|
||||
switch ifa := ifa.(type) {
|
||||
case *net.IPAddr:
|
||||
if ip := routableIP(network, ifa.IP); ip != nil {
|
||||
return ip, true
|
||||
}
|
||||
case *net.IPNet:
|
||||
if ip := routableIP(network, ifa.IP); ip != nil {
|
||||
return ip, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func routableIP(network string, ip net.IP) net.IP {
|
||||
if !ip.IsLoopback() && !ip.IsLinkLocalUnicast() && !ip.IsGlobalUnicast() {
|
||||
return nil
|
||||
}
|
||||
switch network {
|
||||
case "ip4":
|
||||
if ip := ip.To4(); ip != nil {
|
||||
return ip
|
||||
}
|
||||
case "ip6":
|
||||
if ip.IsLoopback() { // addressing scope of the loopback address depends on each implementation
|
||||
return nil
|
||||
}
|
||||
if ip := ip.To16(); ip != nil && ip.To4() == nil {
|
||||
return ip
|
||||
}
|
||||
default:
|
||||
if ip := ip.To4(); ip != nil {
|
||||
return ip
|
||||
}
|
||||
if ip := ip.To16(); ip != nil {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
11
vendor/golang.org/x/net/internal/nettest/rlimit.go
generated
vendored
11
vendor/golang.org/x/net/internal/nettest/rlimit.go
generated
vendored
@@ -1,11 +0,0 @@
|
||||
// Copyright 2015 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 nettest
|
||||
|
||||
const defaultMaxOpenFiles = 256
|
||||
|
||||
// MaxOpenFiles returns the maximum number of open files for the
|
||||
// caller's process.
|
||||
func MaxOpenFiles() int { return maxOpenFiles() }
|
||||
9
vendor/golang.org/x/net/internal/nettest/rlimit_stub.go
generated
vendored
9
vendor/golang.org/x/net/internal/nettest/rlimit_stub.go
generated
vendored
@@ -1,9 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
// +build nacl plan9
|
||||
|
||||
package nettest
|
||||
|
||||
func maxOpenFiles() int { return defaultMaxOpenFiles }
|
||||
17
vendor/golang.org/x/net/internal/nettest/rlimit_unix.go
generated
vendored
17
vendor/golang.org/x/net/internal/nettest/rlimit_unix.go
generated
vendored
@@ -1,17 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package nettest
|
||||
|
||||
import "syscall"
|
||||
|
||||
func maxOpenFiles() int {
|
||||
var rlim syscall.Rlimit
|
||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil {
|
||||
return defaultMaxOpenFiles
|
||||
}
|
||||
return int(rlim.Cur)
|
||||
}
|
||||
7
vendor/golang.org/x/net/internal/nettest/rlimit_windows.go
generated
vendored
7
vendor/golang.org/x/net/internal/nettest/rlimit_windows.go
generated
vendored
@@ -1,7 +0,0 @@
|
||||
// Copyright 2015 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 nettest
|
||||
|
||||
func maxOpenFiles() int { return 4 * defaultMaxOpenFiles /* actually it's 16581375 */ }
|
||||
36
vendor/golang.org/x/net/internal/nettest/stack.go
generated
vendored
36
vendor/golang.org/x/net/internal/nettest/stack.go
generated
vendored
@@ -1,36 +0,0 @@
|
||||
// Copyright 2014 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 nettest provides utilities for IP testing.
|
||||
package nettest // import "golang.org/x/net/internal/nettest"
|
||||
|
||||
import "net"
|
||||
|
||||
// SupportsIPv4 reports whether the platform supports IPv4 networking
|
||||
// functionality.
|
||||
func SupportsIPv4() bool {
|
||||
ln, err := net.Listen("tcp4", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ln.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
// SupportsIPv6 reports whether the platform supports IPv6 networking
|
||||
// functionality.
|
||||
func SupportsIPv6() bool {
|
||||
ln, err := net.Listen("tcp6", "[::1]:0")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ln.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
// ProtocolNotSupported reports whether err is a protocol not
|
||||
// supported error.
|
||||
func ProtocolNotSupported(err error) bool {
|
||||
return protocolNotSupported(err)
|
||||
}
|
||||
18
vendor/golang.org/x/net/internal/nettest/stack_stub.go
generated
vendored
18
vendor/golang.org/x/net/internal/nettest/stack_stub.go
generated
vendored
@@ -1,18 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
// +build nacl plan9
|
||||
|
||||
package nettest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// SupportsRawIPSocket reports whether the platform supports raw IP
|
||||
// sockets.
|
||||
func SupportsRawIPSocket() (string, bool) {
|
||||
return fmt.Sprintf("not supported on %s", runtime.GOOS), false
|
||||
}
|
||||
22
vendor/golang.org/x/net/internal/nettest/stack_unix.go
generated
vendored
22
vendor/golang.org/x/net/internal/nettest/stack_unix.go
generated
vendored
@@ -1,22 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package nettest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// SupportsRawIPSocket reports whether the platform supports raw IP
|
||||
// sockets.
|
||||
func SupportsRawIPSocket() (string, bool) {
|
||||
if os.Getuid() != 0 {
|
||||
return fmt.Sprintf("must be root on %s", runtime.GOOS), false
|
||||
}
|
||||
return "", true
|
||||
}
|
||||
32
vendor/golang.org/x/net/internal/nettest/stack_windows.go
generated
vendored
32
vendor/golang.org/x/net/internal/nettest/stack_windows.go
generated
vendored
@@ -1,32 +0,0 @@
|
||||
// Copyright 2015 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 nettest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// SupportsRawIPSocket reports whether the platform supports raw IP
|
||||
// sockets.
|
||||
func SupportsRawIPSocket() (string, bool) {
|
||||
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
|
||||
// Note: To use a socket of type SOCK_RAW requires administrative privileges.
|
||||
// Users running Winsock applications that use raw sockets must be a member of
|
||||
// the Administrators group on the local computer, otherwise raw socket calls
|
||||
// will fail with an error code of WSAEACCES. On Windows Vista and later, access
|
||||
// for raw sockets is enforced at socket creation. In earlier versions of Windows,
|
||||
// access for raw sockets is enforced during other socket operations.
|
||||
s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, 0)
|
||||
if err == syscall.WSAEACCES {
|
||||
return fmt.Sprintf("no access to raw socket allowed on %s", runtime.GOOS), false
|
||||
}
|
||||
if err != nil {
|
||||
return err.Error(), false
|
||||
}
|
||||
syscall.Closesocket(s)
|
||||
return "", true
|
||||
}
|
||||
525
vendor/golang.org/x/net/internal/timeseries/timeseries.go
generated
vendored
525
vendor/golang.org/x/net/internal/timeseries/timeseries.go
generated
vendored
@@ -1,525 +0,0 @@
|
||||
// Copyright 2015 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 timeseries implements a time series structure for stats collection.
|
||||
package timeseries // import "golang.org/x/net/internal/timeseries"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
timeSeriesNumBuckets = 64
|
||||
minuteHourSeriesNumBuckets = 60
|
||||
)
|
||||
|
||||
var timeSeriesResolutions = []time.Duration{
|
||||
1 * time.Second,
|
||||
10 * time.Second,
|
||||
1 * time.Minute,
|
||||
10 * time.Minute,
|
||||
1 * time.Hour,
|
||||
6 * time.Hour,
|
||||
24 * time.Hour, // 1 day
|
||||
7 * 24 * time.Hour, // 1 week
|
||||
4 * 7 * 24 * time.Hour, // 4 weeks
|
||||
16 * 7 * 24 * time.Hour, // 16 weeks
|
||||
}
|
||||
|
||||
var minuteHourSeriesResolutions = []time.Duration{
|
||||
1 * time.Second,
|
||||
1 * time.Minute,
|
||||
}
|
||||
|
||||
// An Observable is a kind of data that can be aggregated in a time series.
|
||||
type Observable interface {
|
||||
Multiply(ratio float64) // Multiplies the data in self by a given ratio
|
||||
Add(other Observable) // Adds the data from a different observation to self
|
||||
Clear() // Clears the observation so it can be reused.
|
||||
CopyFrom(other Observable) // Copies the contents of a given observation to self
|
||||
}
|
||||
|
||||
// Float attaches the methods of Observable to a float64.
|
||||
type Float float64
|
||||
|
||||
// NewFloat returns a Float.
|
||||
func NewFloat() Observable {
|
||||
f := Float(0)
|
||||
return &f
|
||||
}
|
||||
|
||||
// String returns the float as a string.
|
||||
func (f *Float) String() string { return fmt.Sprintf("%g", f.Value()) }
|
||||
|
||||
// Value returns the float's value.
|
||||
func (f *Float) Value() float64 { return float64(*f) }
|
||||
|
||||
func (f *Float) Multiply(ratio float64) { *f *= Float(ratio) }
|
||||
|
||||
func (f *Float) Add(other Observable) {
|
||||
o := other.(*Float)
|
||||
*f += *o
|
||||
}
|
||||
|
||||
func (f *Float) Clear() { *f = 0 }
|
||||
|
||||
func (f *Float) CopyFrom(other Observable) {
|
||||
o := other.(*Float)
|
||||
*f = *o
|
||||
}
|
||||
|
||||
// A Clock tells the current time.
|
||||
type Clock interface {
|
||||
Time() time.Time
|
||||
}
|
||||
|
||||
type defaultClock int
|
||||
|
||||
var defaultClockInstance defaultClock
|
||||
|
||||
func (defaultClock) Time() time.Time { return time.Now() }
|
||||
|
||||
// Information kept per level. Each level consists of a circular list of
|
||||
// observations. The start of the level may be derived from end and the
|
||||
// len(buckets) * sizeInMillis.
|
||||
type tsLevel struct {
|
||||
oldest int // index to oldest bucketed Observable
|
||||
newest int // index to newest bucketed Observable
|
||||
end time.Time // end timestamp for this level
|
||||
size time.Duration // duration of the bucketed Observable
|
||||
buckets []Observable // collections of observations
|
||||
provider func() Observable // used for creating new Observable
|
||||
}
|
||||
|
||||
func (l *tsLevel) Clear() {
|
||||
l.oldest = 0
|
||||
l.newest = len(l.buckets) - 1
|
||||
l.end = time.Time{}
|
||||
for i := range l.buckets {
|
||||
if l.buckets[i] != nil {
|
||||
l.buckets[i].Clear()
|
||||
l.buckets[i] = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *tsLevel) InitLevel(size time.Duration, numBuckets int, f func() Observable) {
|
||||
l.size = size
|
||||
l.provider = f
|
||||
l.buckets = make([]Observable, numBuckets)
|
||||
}
|
||||
|
||||
// Keeps a sequence of levels. Each level is responsible for storing data at
|
||||
// a given resolution. For example, the first level stores data at a one
|
||||
// minute resolution while the second level stores data at a one hour
|
||||
// resolution.
|
||||
|
||||
// Each level is represented by a sequence of buckets. Each bucket spans an
|
||||
// interval equal to the resolution of the level. New observations are added
|
||||
// to the last bucket.
|
||||
type timeSeries struct {
|
||||
provider func() Observable // make more Observable
|
||||
numBuckets int // number of buckets in each level
|
||||
levels []*tsLevel // levels of bucketed Observable
|
||||
lastAdd time.Time // time of last Observable tracked
|
||||
total Observable // convenient aggregation of all Observable
|
||||
clock Clock // Clock for getting current time
|
||||
pending Observable // observations not yet bucketed
|
||||
pendingTime time.Time // what time are we keeping in pending
|
||||
dirty bool // if there are pending observations
|
||||
}
|
||||
|
||||
// init initializes a level according to the supplied criteria.
|
||||
func (ts *timeSeries) init(resolutions []time.Duration, f func() Observable, numBuckets int, clock Clock) {
|
||||
ts.provider = f
|
||||
ts.numBuckets = numBuckets
|
||||
ts.clock = clock
|
||||
ts.levels = make([]*tsLevel, len(resolutions))
|
||||
|
||||
for i := range resolutions {
|
||||
if i > 0 && resolutions[i-1] >= resolutions[i] {
|
||||
log.Print("timeseries: resolutions must be monotonically increasing")
|
||||
break
|
||||
}
|
||||
newLevel := new(tsLevel)
|
||||
newLevel.InitLevel(resolutions[i], ts.numBuckets, ts.provider)
|
||||
ts.levels[i] = newLevel
|
||||
}
|
||||
|
||||
ts.Clear()
|
||||
}
|
||||
|
||||
// Clear removes all observations from the time series.
|
||||
func (ts *timeSeries) Clear() {
|
||||
ts.lastAdd = time.Time{}
|
||||
ts.total = ts.resetObservation(ts.total)
|
||||
ts.pending = ts.resetObservation(ts.pending)
|
||||
ts.pendingTime = time.Time{}
|
||||
ts.dirty = false
|
||||
|
||||
for i := range ts.levels {
|
||||
ts.levels[i].Clear()
|
||||
}
|
||||
}
|
||||
|
||||
// Add records an observation at the current time.
|
||||
func (ts *timeSeries) Add(observation Observable) {
|
||||
ts.AddWithTime(observation, ts.clock.Time())
|
||||
}
|
||||
|
||||
// AddWithTime records an observation at the specified time.
|
||||
func (ts *timeSeries) AddWithTime(observation Observable, t time.Time) {
|
||||
|
||||
smallBucketDuration := ts.levels[0].size
|
||||
|
||||
if t.After(ts.lastAdd) {
|
||||
ts.lastAdd = t
|
||||
}
|
||||
|
||||
if t.After(ts.pendingTime) {
|
||||
ts.advance(t)
|
||||
ts.mergePendingUpdates()
|
||||
ts.pendingTime = ts.levels[0].end
|
||||
ts.pending.CopyFrom(observation)
|
||||
ts.dirty = true
|
||||
} else if t.After(ts.pendingTime.Add(-1 * smallBucketDuration)) {
|
||||
// The observation is close enough to go into the pending bucket.
|
||||
// This compensates for clock skewing and small scheduling delays
|
||||
// by letting the update stay in the fast path.
|
||||
ts.pending.Add(observation)
|
||||
ts.dirty = true
|
||||
} else {
|
||||
ts.mergeValue(observation, t)
|
||||
}
|
||||
}
|
||||
|
||||
// mergeValue inserts the observation at the specified time in the past into all levels.
|
||||
func (ts *timeSeries) mergeValue(observation Observable, t time.Time) {
|
||||
for _, level := range ts.levels {
|
||||
index := (ts.numBuckets - 1) - int(level.end.Sub(t)/level.size)
|
||||
if 0 <= index && index < ts.numBuckets {
|
||||
bucketNumber := (level.oldest + index) % ts.numBuckets
|
||||
if level.buckets[bucketNumber] == nil {
|
||||
level.buckets[bucketNumber] = level.provider()
|
||||
}
|
||||
level.buckets[bucketNumber].Add(observation)
|
||||
}
|
||||
}
|
||||
ts.total.Add(observation)
|
||||
}
|
||||
|
||||
// mergePendingUpdates applies the pending updates into all levels.
|
||||
func (ts *timeSeries) mergePendingUpdates() {
|
||||
if ts.dirty {
|
||||
ts.mergeValue(ts.pending, ts.pendingTime)
|
||||
ts.pending = ts.resetObservation(ts.pending)
|
||||
ts.dirty = false
|
||||
}
|
||||
}
|
||||
|
||||
// advance cycles the buckets at each level until the latest bucket in
|
||||
// each level can hold the time specified.
|
||||
func (ts *timeSeries) advance(t time.Time) {
|
||||
if !t.After(ts.levels[0].end) {
|
||||
return
|
||||
}
|
||||
for i := 0; i < len(ts.levels); i++ {
|
||||
level := ts.levels[i]
|
||||
if !level.end.Before(t) {
|
||||
break
|
||||
}
|
||||
|
||||
// If the time is sufficiently far, just clear the level and advance
|
||||
// directly.
|
||||
if !t.Before(level.end.Add(level.size * time.Duration(ts.numBuckets))) {
|
||||
for _, b := range level.buckets {
|
||||
ts.resetObservation(b)
|
||||
}
|
||||
level.end = time.Unix(0, (t.UnixNano()/level.size.Nanoseconds())*level.size.Nanoseconds())
|
||||
}
|
||||
|
||||
for t.After(level.end) {
|
||||
level.end = level.end.Add(level.size)
|
||||
level.newest = level.oldest
|
||||
level.oldest = (level.oldest + 1) % ts.numBuckets
|
||||
ts.resetObservation(level.buckets[level.newest])
|
||||
}
|
||||
|
||||
t = level.end
|
||||
}
|
||||
}
|
||||
|
||||
// Latest returns the sum of the num latest buckets from the level.
|
||||
func (ts *timeSeries) Latest(level, num int) Observable {
|
||||
now := ts.clock.Time()
|
||||
if ts.levels[0].end.Before(now) {
|
||||
ts.advance(now)
|
||||
}
|
||||
|
||||
ts.mergePendingUpdates()
|
||||
|
||||
result := ts.provider()
|
||||
l := ts.levels[level]
|
||||
index := l.newest
|
||||
|
||||
for i := 0; i < num; i++ {
|
||||
if l.buckets[index] != nil {
|
||||
result.Add(l.buckets[index])
|
||||
}
|
||||
if index == 0 {
|
||||
index = ts.numBuckets
|
||||
}
|
||||
index--
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// LatestBuckets returns a copy of the num latest buckets from level.
|
||||
func (ts *timeSeries) LatestBuckets(level, num int) []Observable {
|
||||
if level < 0 || level > len(ts.levels) {
|
||||
log.Print("timeseries: bad level argument: ", level)
|
||||
return nil
|
||||
}
|
||||
if num < 0 || num >= ts.numBuckets {
|
||||
log.Print("timeseries: bad num argument: ", num)
|
||||
return nil
|
||||
}
|
||||
|
||||
results := make([]Observable, num)
|
||||
now := ts.clock.Time()
|
||||
if ts.levels[0].end.Before(now) {
|
||||
ts.advance(now)
|
||||
}
|
||||
|
||||
ts.mergePendingUpdates()
|
||||
|
||||
l := ts.levels[level]
|
||||
index := l.newest
|
||||
|
||||
for i := 0; i < num; i++ {
|
||||
result := ts.provider()
|
||||
results[i] = result
|
||||
if l.buckets[index] != nil {
|
||||
result.CopyFrom(l.buckets[index])
|
||||
}
|
||||
|
||||
if index == 0 {
|
||||
index = ts.numBuckets
|
||||
}
|
||||
index -= 1
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// ScaleBy updates observations by scaling by factor.
|
||||
func (ts *timeSeries) ScaleBy(factor float64) {
|
||||
for _, l := range ts.levels {
|
||||
for i := 0; i < ts.numBuckets; i++ {
|
||||
l.buckets[i].Multiply(factor)
|
||||
}
|
||||
}
|
||||
|
||||
ts.total.Multiply(factor)
|
||||
ts.pending.Multiply(factor)
|
||||
}
|
||||
|
||||
// Range returns the sum of observations added over the specified time range.
|
||||
// If start or finish times don't fall on bucket boundaries of the same
|
||||
// level, then return values are approximate answers.
|
||||
func (ts *timeSeries) Range(start, finish time.Time) Observable {
|
||||
return ts.ComputeRange(start, finish, 1)[0]
|
||||
}
|
||||
|
||||
// Recent returns the sum of observations from the last delta.
|
||||
func (ts *timeSeries) Recent(delta time.Duration) Observable {
|
||||
now := ts.clock.Time()
|
||||
return ts.Range(now.Add(-delta), now)
|
||||
}
|
||||
|
||||
// Total returns the total of all observations.
|
||||
func (ts *timeSeries) Total() Observable {
|
||||
ts.mergePendingUpdates()
|
||||
return ts.total
|
||||
}
|
||||
|
||||
// ComputeRange computes a specified number of values into a slice using
|
||||
// the observations recorded over the specified time period. The return
|
||||
// values are approximate if the start or finish times don't fall on the
|
||||
// bucket boundaries at the same level or if the number of buckets spanning
|
||||
// the range is not an integral multiple of num.
|
||||
func (ts *timeSeries) ComputeRange(start, finish time.Time, num int) []Observable {
|
||||
if start.After(finish) {
|
||||
log.Printf("timeseries: start > finish, %v>%v", start, finish)
|
||||
return nil
|
||||
}
|
||||
|
||||
if num < 0 {
|
||||
log.Printf("timeseries: num < 0, %v", num)
|
||||
return nil
|
||||
}
|
||||
|
||||
results := make([]Observable, num)
|
||||
|
||||
for _, l := range ts.levels {
|
||||
if !start.Before(l.end.Add(-l.size * time.Duration(ts.numBuckets))) {
|
||||
ts.extract(l, start, finish, num, results)
|
||||
return results
|
||||
}
|
||||
}
|
||||
|
||||
// Failed to find a level that covers the desired range. So just
|
||||
// extract from the last level, even if it doesn't cover the entire
|
||||
// desired range.
|
||||
ts.extract(ts.levels[len(ts.levels)-1], start, finish, num, results)
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// RecentList returns the specified number of values in slice over the most
|
||||
// recent time period of the specified range.
|
||||
func (ts *timeSeries) RecentList(delta time.Duration, num int) []Observable {
|
||||
if delta < 0 {
|
||||
return nil
|
||||
}
|
||||
now := ts.clock.Time()
|
||||
return ts.ComputeRange(now.Add(-delta), now, num)
|
||||
}
|
||||
|
||||
// extract returns a slice of specified number of observations from a given
|
||||
// level over a given range.
|
||||
func (ts *timeSeries) extract(l *tsLevel, start, finish time.Time, num int, results []Observable) {
|
||||
ts.mergePendingUpdates()
|
||||
|
||||
srcInterval := l.size
|
||||
dstInterval := finish.Sub(start) / time.Duration(num)
|
||||
dstStart := start
|
||||
srcStart := l.end.Add(-srcInterval * time.Duration(ts.numBuckets))
|
||||
|
||||
srcIndex := 0
|
||||
|
||||
// Where should scanning start?
|
||||
if dstStart.After(srcStart) {
|
||||
advance := dstStart.Sub(srcStart) / srcInterval
|
||||
srcIndex += int(advance)
|
||||
srcStart = srcStart.Add(advance * srcInterval)
|
||||
}
|
||||
|
||||
// The i'th value is computed as show below.
|
||||
// interval = (finish/start)/num
|
||||
// i'th value = sum of observation in range
|
||||
// [ start + i * interval,
|
||||
// start + (i + 1) * interval )
|
||||
for i := 0; i < num; i++ {
|
||||
results[i] = ts.resetObservation(results[i])
|
||||
dstEnd := dstStart.Add(dstInterval)
|
||||
for srcIndex < ts.numBuckets && srcStart.Before(dstEnd) {
|
||||
srcEnd := srcStart.Add(srcInterval)
|
||||
if srcEnd.After(ts.lastAdd) {
|
||||
srcEnd = ts.lastAdd
|
||||
}
|
||||
|
||||
if !srcEnd.Before(dstStart) {
|
||||
srcValue := l.buckets[(srcIndex+l.oldest)%ts.numBuckets]
|
||||
if !srcStart.Before(dstStart) && !srcEnd.After(dstEnd) {
|
||||
// dst completely contains src.
|
||||
if srcValue != nil {
|
||||
results[i].Add(srcValue)
|
||||
}
|
||||
} else {
|
||||
// dst partially overlaps src.
|
||||
overlapStart := maxTime(srcStart, dstStart)
|
||||
overlapEnd := minTime(srcEnd, dstEnd)
|
||||
base := srcEnd.Sub(srcStart)
|
||||
fraction := overlapEnd.Sub(overlapStart).Seconds() / base.Seconds()
|
||||
|
||||
used := ts.provider()
|
||||
if srcValue != nil {
|
||||
used.CopyFrom(srcValue)
|
||||
}
|
||||
used.Multiply(fraction)
|
||||
results[i].Add(used)
|
||||
}
|
||||
|
||||
if srcEnd.After(dstEnd) {
|
||||
break
|
||||
}
|
||||
}
|
||||
srcIndex++
|
||||
srcStart = srcStart.Add(srcInterval)
|
||||
}
|
||||
dstStart = dstStart.Add(dstInterval)
|
||||
}
|
||||
}
|
||||
|
||||
// resetObservation clears the content so the struct may be reused.
|
||||
func (ts *timeSeries) resetObservation(observation Observable) Observable {
|
||||
if observation == nil {
|
||||
observation = ts.provider()
|
||||
} else {
|
||||
observation.Clear()
|
||||
}
|
||||
return observation
|
||||
}
|
||||
|
||||
// TimeSeries tracks data at granularities from 1 second to 16 weeks.
|
||||
type TimeSeries struct {
|
||||
timeSeries
|
||||
}
|
||||
|
||||
// NewTimeSeries creates a new TimeSeries using the function provided for creating new Observable.
|
||||
func NewTimeSeries(f func() Observable) *TimeSeries {
|
||||
return NewTimeSeriesWithClock(f, defaultClockInstance)
|
||||
}
|
||||
|
||||
// NewTimeSeriesWithClock creates a new TimeSeries using the function provided for creating new Observable and the clock for
|
||||
// assigning timestamps.
|
||||
func NewTimeSeriesWithClock(f func() Observable, clock Clock) *TimeSeries {
|
||||
ts := new(TimeSeries)
|
||||
ts.timeSeries.init(timeSeriesResolutions, f, timeSeriesNumBuckets, clock)
|
||||
return ts
|
||||
}
|
||||
|
||||
// MinuteHourSeries tracks data at granularities of 1 minute and 1 hour.
|
||||
type MinuteHourSeries struct {
|
||||
timeSeries
|
||||
}
|
||||
|
||||
// NewMinuteHourSeries creates a new MinuteHourSeries using the function provided for creating new Observable.
|
||||
func NewMinuteHourSeries(f func() Observable) *MinuteHourSeries {
|
||||
return NewMinuteHourSeriesWithClock(f, defaultClockInstance)
|
||||
}
|
||||
|
||||
// NewMinuteHourSeriesWithClock creates a new MinuteHourSeries using the function provided for creating new Observable and the clock for
|
||||
// assigning timestamps.
|
||||
func NewMinuteHourSeriesWithClock(f func() Observable, clock Clock) *MinuteHourSeries {
|
||||
ts := new(MinuteHourSeries)
|
||||
ts.timeSeries.init(minuteHourSeriesResolutions, f,
|
||||
minuteHourSeriesNumBuckets, clock)
|
||||
return ts
|
||||
}
|
||||
|
||||
func (ts *MinuteHourSeries) Minute() Observable {
|
||||
return ts.timeSeries.Latest(0, 60)
|
||||
}
|
||||
|
||||
func (ts *MinuteHourSeries) Hour() Observable {
|
||||
return ts.timeSeries.Latest(1, 60)
|
||||
}
|
||||
|
||||
func minTime(a, b time.Time) time.Time {
|
||||
if a.Before(b) {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func maxTime(a, b time.Time) time.Time {
|
||||
if a.After(b) {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
93
vendor/golang.org/x/net/ipv4/bpf_test.go
generated
vendored
93
vendor/golang.org/x/net/ipv4/bpf_test.go
generated
vendored
@@ -1,93 +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 ipv4_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/bpf"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func TestBPF(t *testing.T) {
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
l, err := net.ListenPacket("udp4", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
p := ipv4.NewPacketConn(l)
|
||||
|
||||
// This filter accepts UDP packets whose first payload byte is
|
||||
// even.
|
||||
prog, err := bpf.Assemble([]bpf.Instruction{
|
||||
// Load the first byte of the payload (skipping UDP header).
|
||||
bpf.LoadAbsolute{Off: 8, Size: 1},
|
||||
// Select LSB of the byte.
|
||||
bpf.ALUOpConstant{Op: bpf.ALUOpAnd, Val: 1},
|
||||
// Byte is even?
|
||||
bpf.JumpIf{Cond: bpf.JumpEqual, Val: 0, SkipFalse: 1},
|
||||
// Accept.
|
||||
bpf.RetConstant{Val: 4096},
|
||||
// Ignore.
|
||||
bpf.RetConstant{Val: 0},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("compiling BPF: %s", err)
|
||||
}
|
||||
|
||||
if err = p.SetBPF(prog); err != nil {
|
||||
t.Fatalf("attaching filter to Conn: %s", err)
|
||||
}
|
||||
|
||||
s, err := net.Dial("udp4", l.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer s.Close()
|
||||
go func() {
|
||||
for i := byte(0); i < 10; i++ {
|
||||
s.Write([]byte{i})
|
||||
}
|
||||
}()
|
||||
|
||||
l.SetDeadline(time.Now().Add(2 * time.Second))
|
||||
seen := make([]bool, 5)
|
||||
for {
|
||||
var b [512]byte
|
||||
n, _, err := l.ReadFrom(b[:])
|
||||
if err != nil {
|
||||
t.Fatalf("reading from listener: %s", err)
|
||||
}
|
||||
if n != 1 {
|
||||
t.Fatalf("unexpected packet length, want 1, got %d", n)
|
||||
}
|
||||
if b[0] >= 10 {
|
||||
t.Fatalf("unexpected byte, want 0-9, got %d", b[0])
|
||||
}
|
||||
if b[0]%2 != 0 {
|
||||
t.Fatalf("got odd byte %d, wanted only even bytes", b[0])
|
||||
}
|
||||
seen[b[0]/2] = true
|
||||
|
||||
seenAll := true
|
||||
for _, v := range seen {
|
||||
if !v {
|
||||
seenAll = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if seenAll {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
12
vendor/golang.org/x/net/ipv4/doc.go
generated
vendored
12
vendor/golang.org/x/net/ipv4/doc.go
generated
vendored
@@ -21,7 +21,7 @@
|
||||
//
|
||||
// The options for unicasting are available for net.TCPConn,
|
||||
// net.UDPConn and net.IPConn which are created as network connections
|
||||
// that use the IPv4 transport. When a single TCP connection carrying
|
||||
// that use the IPv4 transport. When a single TCP connection carrying
|
||||
// a data flow of multiple packets needs to indicate the flow is
|
||||
// important, Conn is used to set the type-of-service field on the
|
||||
// IPv4 header for each packet.
|
||||
@@ -56,7 +56,7 @@
|
||||
//
|
||||
// The options for multicasting are available for net.UDPConn and
|
||||
// net.IPconn which are created as network connections that use the
|
||||
// IPv4 transport. A few network facilities must be prepared before
|
||||
// IPv4 transport. A few network facilities must be prepared before
|
||||
// you begin multicasting, at a minimum joining network interfaces and
|
||||
// multicast groups.
|
||||
//
|
||||
@@ -80,7 +80,7 @@
|
||||
// defer c.Close()
|
||||
//
|
||||
// Second, the application joins multicast groups, starts listening to
|
||||
// the groups on the specified network interfaces. Note that the
|
||||
// the groups on the specified network interfaces. Note that the
|
||||
// service port for transport layer protocol does not matter with this
|
||||
// operation as joining groups affects only network and link layer
|
||||
// protocols, such as IPv4 and Ethernet.
|
||||
@@ -94,7 +94,7 @@
|
||||
// }
|
||||
//
|
||||
// The application might set per packet control message transmissions
|
||||
// between the protocol stack within the kernel. When the application
|
||||
// between the protocol stack within the kernel. When the application
|
||||
// needs a destination address on an incoming packet,
|
||||
// SetControlMessage of PacketConn is used to enable control message
|
||||
// transmissions.
|
||||
@@ -145,7 +145,7 @@
|
||||
// More multicasting
|
||||
//
|
||||
// An application that uses PacketConn or RawConn may join multiple
|
||||
// multicast groups. For example, a UDP listener with port 1024 might
|
||||
// multicast groups. For example, a UDP listener with port 1024 might
|
||||
// join two different groups across over two different network
|
||||
// interfaces by using:
|
||||
//
|
||||
@@ -166,7 +166,7 @@
|
||||
// }
|
||||
//
|
||||
// It is possible for multiple UDP listeners that listen on the same
|
||||
// UDP port to join the same multicast group. The net package will
|
||||
// UDP port to join the same multicast group. The net package will
|
||||
// provide a socket that listens to a wildcard address with reusable
|
||||
// UDP port when an appropriate multicast address prefix is passed to
|
||||
// the net.ListenPacket or net.ListenUDP.
|
||||
|
||||
8
vendor/golang.org/x/net/ipv4/endpoint.go
generated
vendored
8
vendor/golang.org/x/net/ipv4/endpoint.go
generated
vendored
@@ -38,8 +38,8 @@ func NewConn(c net.Conn) *Conn {
|
||||
}
|
||||
|
||||
// A PacketConn represents a packet network endpoint that uses the
|
||||
// IPv4 transport. It is used to control several IP-level socket
|
||||
// options including multicasting. It also provides datagram based
|
||||
// IPv4 transport. It is used to control several IP-level socket
|
||||
// options including multicasting. It also provides datagram based
|
||||
// network I/O methods specific to the IPv4 and higher layer protocols
|
||||
// such as UDP.
|
||||
type PacketConn struct {
|
||||
@@ -118,8 +118,8 @@ func NewPacketConn(c net.PacketConn) *PacketConn {
|
||||
}
|
||||
|
||||
// A RawConn represents a packet network endpoint that uses the IPv4
|
||||
// transport. It is used to control several IP-level socket options
|
||||
// including IPv4 header manipulation. It also provides datagram
|
||||
// transport. It is used to control several IP-level socket options
|
||||
// including IPv4 header manipulation. It also provides datagram
|
||||
// based network I/O methods specific to the IPv4 and higher layer
|
||||
// protocols that handle IPv4 datagram directly such as OSPF, GRE.
|
||||
type RawConn struct {
|
||||
|
||||
224
vendor/golang.org/x/net/ipv4/example_test.go
generated
vendored
224
vendor/golang.org/x/net/ipv4/example_test.go
generated
vendored
@@ -1,224 +0,0 @@
|
||||
// Copyright 2012 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 ipv4_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/icmp"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func ExampleConn_markingTCP() {
|
||||
ln, err := net.Listen("tcp", "0.0.0.0:1024")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
for {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
go func(c net.Conn) {
|
||||
defer c.Close()
|
||||
if c.RemoteAddr().(*net.TCPAddr).IP.To4() != nil {
|
||||
p := ipv4.NewConn(c)
|
||||
if err := p.SetTOS(0x28); err != nil { // DSCP AF11
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := p.SetTTL(128); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := c.Write([]byte("HELLO-R-U-THERE-ACK")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}(c)
|
||||
}
|
||||
}
|
||||
|
||||
func ExamplePacketConn_servingOneShotMulticastDNS() {
|
||||
c, err := net.ListenPacket("udp4", "0.0.0.0:5353") // mDNS over UDP
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
|
||||
en0, err := net.InterfaceByName("en0")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
mDNSLinkLocal := net.UDPAddr{IP: net.IPv4(224, 0, 0, 251)}
|
||||
if err := p.JoinGroup(en0, &mDNSLinkLocal); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer p.LeaveGroup(en0, &mDNSLinkLocal)
|
||||
if err := p.SetControlMessage(ipv4.FlagDst, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
b := make([]byte, 1500)
|
||||
for {
|
||||
_, cm, peer, err := p.ReadFrom(b)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if !cm.Dst.IsMulticast() || !cm.Dst.Equal(mDNSLinkLocal.IP) {
|
||||
continue
|
||||
}
|
||||
answers := []byte("FAKE-MDNS-ANSWERS") // fake mDNS answers, you need to implement this
|
||||
if _, err := p.WriteTo(answers, nil, peer); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ExamplePacketConn_tracingIPPacketRoute() {
|
||||
// Tracing an IP packet route to www.google.com.
|
||||
|
||||
const host = "www.google.com"
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var dst net.IPAddr
|
||||
for _, ip := range ips {
|
||||
if ip.To4() != nil {
|
||||
dst.IP = ip
|
||||
fmt.Printf("using %v for tracing an IP packet route to %s\n", dst.IP, host)
|
||||
break
|
||||
}
|
||||
}
|
||||
if dst.IP == nil {
|
||||
log.Fatal("no A record found")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip4:1", "0.0.0.0") // ICMP for IPv4
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
|
||||
if err := p.SetControlMessage(ipv4.FlagTTL|ipv4.FlagSrc|ipv4.FlagDst|ipv4.FlagInterface, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
wm := icmp.Message{
|
||||
Type: ipv4.ICMPTypeEcho, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}
|
||||
|
||||
rb := make([]byte, 1500)
|
||||
for i := 1; i <= 64; i++ { // up to 64 hops
|
||||
wm.Body.(*icmp.Echo).Seq = i
|
||||
wb, err := wm.Marshal(nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := p.SetTTL(i); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// In the real world usually there are several
|
||||
// multiple traffic-engineered paths for each hop.
|
||||
// You may need to probe a few times to each hop.
|
||||
begin := time.Now()
|
||||
if _, err := p.WriteTo(wb, nil, &dst); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := p.SetReadDeadline(time.Now().Add(3 * time.Second)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
n, cm, peer, err := p.ReadFrom(rb)
|
||||
if err != nil {
|
||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||
fmt.Printf("%v\t*\n", i)
|
||||
continue
|
||||
}
|
||||
log.Fatal(err)
|
||||
}
|
||||
rm, err := icmp.ParseMessage(1, rb[:n])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
rtt := time.Since(begin)
|
||||
|
||||
// In the real world you need to determine whether the
|
||||
// received message is yours using ControlMessage.Src,
|
||||
// ControlMessage.Dst, icmp.Echo.ID and icmp.Echo.Seq.
|
||||
switch rm.Type {
|
||||
case ipv4.ICMPTypeTimeExceeded:
|
||||
names, _ := net.LookupAddr(peer.String())
|
||||
fmt.Printf("%d\t%v %+v %v\n\t%+v\n", i, peer, names, rtt, cm)
|
||||
case ipv4.ICMPTypeEchoReply:
|
||||
names, _ := net.LookupAddr(peer.String())
|
||||
fmt.Printf("%d\t%v %+v %v\n\t%+v\n", i, peer, names, rtt, cm)
|
||||
return
|
||||
default:
|
||||
log.Printf("unknown ICMP message: %+v\n", rm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleRawConn_advertisingOSPFHello() {
|
||||
c, err := net.ListenPacket("ip4:89", "0.0.0.0") // OSPF for IPv4
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
r, err := ipv4.NewRawConn(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
en0, err := net.InterfaceByName("en0")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
allSPFRouters := net.IPAddr{IP: net.IPv4(224, 0, 0, 5)}
|
||||
if err := r.JoinGroup(en0, &allSPFRouters); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer r.LeaveGroup(en0, &allSPFRouters)
|
||||
|
||||
hello := make([]byte, 24) // fake hello data, you need to implement this
|
||||
ospf := make([]byte, 24) // fake ospf header, you need to implement this
|
||||
ospf[0] = 2 // version 2
|
||||
ospf[1] = 1 // hello packet
|
||||
ospf = append(ospf, hello...)
|
||||
iph := &ipv4.Header{
|
||||
Version: ipv4.Version,
|
||||
Len: ipv4.HeaderLen,
|
||||
TOS: 0xc0, // DSCP CS6
|
||||
TotalLen: ipv4.HeaderLen + len(ospf),
|
||||
TTL: 1,
|
||||
Protocol: 89,
|
||||
Dst: allSPFRouters.IP.To4(),
|
||||
}
|
||||
|
||||
var cm *ipv4.ControlMessage
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "linux":
|
||||
cm = &ipv4.ControlMessage{IfIndex: en0.Index}
|
||||
default:
|
||||
if err := r.SetMulticastInterface(en0); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := r.WriteTo(iph, ospf, cm); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
152
vendor/golang.org/x/net/ipv4/header_test.go
generated
vendored
152
vendor/golang.org/x/net/ipv4/header_test.go
generated
vendored
@@ -1,152 +0,0 @@
|
||||
// Copyright 2012 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 ipv4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type headerTest struct {
|
||||
wireHeaderFromKernel [HeaderLen]byte
|
||||
wireHeaderToKernel [HeaderLen]byte
|
||||
wireHeaderFromTradBSDKernel [HeaderLen]byte
|
||||
wireHeaderToTradBSDKernel [HeaderLen]byte
|
||||
wireHeaderFromFreeBSD10Kernel [HeaderLen]byte
|
||||
wireHeaderToFreeBSD10Kernel [HeaderLen]byte
|
||||
*Header
|
||||
}
|
||||
|
||||
var headerLittleEndianTest = headerTest{
|
||||
// TODO(mikio): Add platform dependent wire header formats when
|
||||
// we support new platforms.
|
||||
wireHeaderFromKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xbe, 0xef,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xbe, 0xef,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderFromTradBSDKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xdb, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToTradBSDKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderFromFreeBSD10Kernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToFreeBSD10Kernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
Header: &Header{
|
||||
Version: Version,
|
||||
Len: HeaderLen,
|
||||
TOS: 1,
|
||||
TotalLen: 0xbeef,
|
||||
ID: 0xcafe,
|
||||
Flags: DontFragment,
|
||||
FragOff: 1500,
|
||||
TTL: 255,
|
||||
Protocol: 1,
|
||||
Checksum: 0xdead,
|
||||
Src: net.IPv4(172, 16, 254, 254),
|
||||
Dst: net.IPv4(192, 168, 0, 1),
|
||||
},
|
||||
}
|
||||
|
||||
func TestMarshalHeader(t *testing.T) {
|
||||
tt := &headerLittleEndianTest
|
||||
if nativeEndian != binary.LittleEndian {
|
||||
t.Skip("no test for non-little endian machine yet")
|
||||
}
|
||||
|
||||
b, err := tt.Header.Marshal()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var wh []byte
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
wh = tt.wireHeaderToTradBSDKernel[:]
|
||||
case "freebsd":
|
||||
switch {
|
||||
case freebsdVersion < 1000000:
|
||||
wh = tt.wireHeaderToTradBSDKernel[:]
|
||||
case 1000000 <= freebsdVersion && freebsdVersion < 1100000:
|
||||
wh = tt.wireHeaderToFreeBSD10Kernel[:]
|
||||
default:
|
||||
wh = tt.wireHeaderToKernel[:]
|
||||
}
|
||||
default:
|
||||
wh = tt.wireHeaderToKernel[:]
|
||||
}
|
||||
if !bytes.Equal(b, wh) {
|
||||
t.Fatalf("got %#v; want %#v", b, wh)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHeader(t *testing.T) {
|
||||
tt := &headerLittleEndianTest
|
||||
if nativeEndian != binary.LittleEndian {
|
||||
t.Skip("no test for big endian machine yet")
|
||||
}
|
||||
|
||||
var wh []byte
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
wh = tt.wireHeaderFromTradBSDKernel[:]
|
||||
case "freebsd":
|
||||
switch {
|
||||
case freebsdVersion < 1000000:
|
||||
wh = tt.wireHeaderFromTradBSDKernel[:]
|
||||
case 1000000 <= freebsdVersion && freebsdVersion < 1100000:
|
||||
wh = tt.wireHeaderFromFreeBSD10Kernel[:]
|
||||
default:
|
||||
wh = tt.wireHeaderFromKernel[:]
|
||||
}
|
||||
default:
|
||||
wh = tt.wireHeaderFromKernel[:]
|
||||
}
|
||||
h, err := ParseHeader(wh)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(h, tt.Header) {
|
||||
t.Fatalf("got %#v; want %#v", h, tt.Header)
|
||||
}
|
||||
s := h.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Fatalf("should be space-separated values: %s", s)
|
||||
}
|
||||
}
|
||||
95
vendor/golang.org/x/net/ipv4/icmp_test.go
generated
vendored
95
vendor/golang.org/x/net/ipv4/icmp_test.go
generated
vendored
@@ -1,95 +0,0 @@
|
||||
// Copyright 2014 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 ipv4_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
var icmpStringTests = []struct {
|
||||
in ipv4.ICMPType
|
||||
out string
|
||||
}{
|
||||
{ipv4.ICMPTypeDestinationUnreachable, "destination unreachable"},
|
||||
|
||||
{256, "<nil>"},
|
||||
}
|
||||
|
||||
func TestICMPString(t *testing.T) {
|
||||
for _, tt := range icmpStringTests {
|
||||
s := tt.in.String()
|
||||
if s != tt.out {
|
||||
t.Errorf("got %s; want %s", s, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestICMPFilter(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
default:
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
var f ipv4.ICMPFilter
|
||||
for _, toggle := range []bool{false, true} {
|
||||
f.SetAll(toggle)
|
||||
for _, typ := range []ipv4.ICMPType{
|
||||
ipv4.ICMPTypeDestinationUnreachable,
|
||||
ipv4.ICMPTypeEchoReply,
|
||||
ipv4.ICMPTypeTimeExceeded,
|
||||
ipv4.ICMPTypeParameterProblem,
|
||||
} {
|
||||
f.Accept(typ)
|
||||
if f.WillBlock(typ) {
|
||||
t.Errorf("ipv4.ICMPFilter.Set(%v, false) failed", typ)
|
||||
}
|
||||
f.Block(typ)
|
||||
if !f.WillBlock(typ) {
|
||||
t.Errorf("ipv4.ICMPFilter.Set(%v, true) failed", typ)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetICMPFilter(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
default:
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip4:icmp", "127.0.0.1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv4.NewPacketConn(c)
|
||||
|
||||
var f ipv4.ICMPFilter
|
||||
f.SetAll(true)
|
||||
f.Accept(ipv4.ICMPTypeEcho)
|
||||
f.Accept(ipv4.ICMPTypeEchoReply)
|
||||
if err := p.SetICMPFilter(&f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kf, err := p.ICMPFilter()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(kf, &f) {
|
||||
t.Fatalf("got %#v; want %#v", kf, f)
|
||||
}
|
||||
}
|
||||
334
vendor/golang.org/x/net/ipv4/multicast_test.go
generated
vendored
334
vendor/golang.org/x/net/ipv4/multicast_test.go
generated
vendored
@@ -1,334 +0,0 @@
|
||||
// Copyright 2012 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 ipv4_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/icmp"
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
var packetConnReadWriteMulticastUDPTests = []struct {
|
||||
addr string
|
||||
grp, src *net.UDPAddr
|
||||
}{
|
||||
{"224.0.0.0:0", &net.UDPAddr{IP: net.IPv4(224, 0, 0, 254)}, nil}, // see RFC 4727
|
||||
|
||||
{"232.0.1.0:0", &net.UDPAddr{IP: net.IPv4(232, 0, 1, 254)}, &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "solaris", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
for _, tt := range packetConnReadWriteMulticastUDPTests {
|
||||
c, err := net.ListenPacket("udp4", tt.addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
grp := *tt.grp
|
||||
grp.Port = c.LocalAddr().(*net.UDPAddr).Port
|
||||
p := ipv4.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
if tt.src == nil {
|
||||
if err := p.JoinGroup(ifi, &grp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveGroup(ifi, &grp)
|
||||
} else {
|
||||
if err := p.JoinSourceSpecificGroup(ifi, &grp, tt.src); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
default: // platforms that don't support IGMPv2/3 fail here
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveSourceSpecificGroup(ifi, &grp, tt.src)
|
||||
}
|
||||
if err := p.SetMulticastInterface(ifi); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastInterface(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetMulticastLoopback(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastLoopback(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
|
||||
wb := []byte("HELLO-R-U-THERE")
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.SetMulticastTTL(i + 1)
|
||||
if n, err := p.WriteTo(wb, nil, &grp); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !bytes.Equal(rb[:n], wb) {
|
||||
t.Fatalf("got %v; want %v", rb[:n], wb)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var packetConnReadWriteMulticastICMPTests = []struct {
|
||||
grp, src *net.IPAddr
|
||||
}{
|
||||
{&net.IPAddr{IP: net.IPv4(224, 0, 0, 254)}, nil}, // see RFC 4727
|
||||
|
||||
{&net.IPAddr{IP: net.IPv4(232, 0, 1, 254)}, &net.IPAddr{IP: net.IPv4(127, 0, 0, 1)}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "solaris", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
for _, tt := range packetConnReadWriteMulticastICMPTests {
|
||||
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv4.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
if tt.src == nil {
|
||||
if err := p.JoinGroup(ifi, tt.grp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveGroup(ifi, tt.grp)
|
||||
} else {
|
||||
if err := p.JoinSourceSpecificGroup(ifi, tt.grp, tt.src); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
default: // platforms that don't support IGMPv2/3 fail here
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveSourceSpecificGroup(ifi, tt.grp, tt.src)
|
||||
}
|
||||
if err := p.SetMulticastInterface(ifi); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastInterface(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetMulticastLoopback(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastLoopback(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cf := ipv4.FlagDst | ipv4.FlagInterface
|
||||
if runtime.GOOS != "solaris" {
|
||||
// Solaris never allows to modify ICMP properties.
|
||||
cf |= ipv4.FlagTTL
|
||||
}
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
wb, err := (&icmp.Message{
|
||||
Type: ipv4.ICMPTypeEcho, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff, Seq: i + 1,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}).Marshal(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.SetMulticastTTL(i + 1)
|
||||
if n, err := p.WriteTo(wb, nil, tt.grp); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
m, err := icmp.ParseMessage(iana.ProtocolICMP, rb[:n])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
switch {
|
||||
case m.Type == ipv4.ICMPTypeEchoReply && m.Code == 0: // net.inet.icmp.bmcastecho=1
|
||||
case m.Type == ipv4.ICMPTypeEcho && m.Code == 0: // net.inet.icmp.bmcastecho=0
|
||||
default:
|
||||
t.Fatalf("got type=%v, code=%v; want type=%v, code=%v", m.Type, m.Code, ipv4.ICMPTypeEchoReply, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var rawConnReadWriteMulticastICMPTests = []struct {
|
||||
grp, src *net.IPAddr
|
||||
}{
|
||||
{&net.IPAddr{IP: net.IPv4(224, 0, 0, 254)}, nil}, // see RFC 4727
|
||||
|
||||
{&net.IPAddr{IP: net.IPv4(232, 0, 1, 254)}, &net.IPAddr{IP: net.IPv4(127, 0, 0, 1)}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestRawConnReadWriteMulticastICMP(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("to avoid external network")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
for _, tt := range rawConnReadWriteMulticastICMPTests {
|
||||
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
r, err := ipv4.NewRawConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer r.Close()
|
||||
if tt.src == nil {
|
||||
if err := r.JoinGroup(ifi, tt.grp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer r.LeaveGroup(ifi, tt.grp)
|
||||
} else {
|
||||
if err := r.JoinSourceSpecificGroup(ifi, tt.grp, tt.src); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
default: // platforms that don't support IGMPv2/3 fail here
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer r.LeaveSourceSpecificGroup(ifi, tt.grp, tt.src)
|
||||
}
|
||||
if err := r.SetMulticastInterface(ifi); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.MulticastInterface(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.SetMulticastLoopback(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.MulticastLoopback(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
wb, err := (&icmp.Message{
|
||||
Type: ipv4.ICMPTypeEcho, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff, Seq: i + 1,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}).Marshal(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wh := &ipv4.Header{
|
||||
Version: ipv4.Version,
|
||||
Len: ipv4.HeaderLen,
|
||||
TOS: i + 1,
|
||||
TotalLen: ipv4.HeaderLen + len(wb),
|
||||
Protocol: 1,
|
||||
Dst: tt.grp.IP,
|
||||
}
|
||||
if err := r.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.SetMulticastTTL(i + 1)
|
||||
if err := r.WriteTo(wh, wb, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rb := make([]byte, ipv4.HeaderLen+128)
|
||||
if rh, b, _, err := r.ReadFrom(rb); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
m, err := icmp.ParseMessage(iana.ProtocolICMP, b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
switch {
|
||||
case (rh.Dst.IsLoopback() || rh.Dst.IsLinkLocalUnicast() || rh.Dst.IsGlobalUnicast()) && m.Type == ipv4.ICMPTypeEchoReply && m.Code == 0: // net.inet.icmp.bmcastecho=1
|
||||
case rh.Dst.IsMulticast() && m.Type == ipv4.ICMPTypeEcho && m.Code == 0: // net.inet.icmp.bmcastecho=0
|
||||
default:
|
||||
t.Fatalf("got type=%v, code=%v; want type=%v, code=%v", m.Type, m.Code, ipv4.ICMPTypeEchoReply, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
249
vendor/golang.org/x/net/ipv4/multicastlistener_test.go
generated
vendored
249
vendor/golang.org/x/net/ipv4/multicastlistener_test.go
generated
vendored
@@ -1,249 +0,0 @@
|
||||
// Copyright 2012 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 ipv4_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
var udpMultipleGroupListenerTests = []net.Addr{
|
||||
&net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}, // see RFC 4727
|
||||
&net.UDPAddr{IP: net.IPv4(224, 0, 0, 250)},
|
||||
&net.UDPAddr{IP: net.IPv4(224, 0, 0, 254)},
|
||||
}
|
||||
|
||||
func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if testing.Short() {
|
||||
t.Skip("to avoid external network")
|
||||
}
|
||||
|
||||
for _, gaddr := range udpMultipleGroupListenerTests {
|
||||
c, err := net.ListenPacket("udp4", "0.0.0.0:0") // wildcard address with no reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv4.NewPacketConn(c)
|
||||
var mift []*net.Interface
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
if _, ok := nettest.IsMulticastCapable("ip4", &ifi); !ok {
|
||||
continue
|
||||
}
|
||||
if err := p.JoinGroup(&ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mift = append(mift, &ift[i])
|
||||
}
|
||||
for _, ifi := range mift {
|
||||
if err := p.LeaveGroup(ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if testing.Short() {
|
||||
t.Skip("to avoid external network")
|
||||
}
|
||||
|
||||
for _, gaddr := range udpMultipleGroupListenerTests {
|
||||
c1, err := net.ListenPacket("udp4", "224.0.0.0:1024") // wildcard address with reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c1.Close()
|
||||
|
||||
c2, err := net.ListenPacket("udp4", "224.0.0.0:1024") // wildcard address with reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c2.Close()
|
||||
|
||||
var ps [2]*ipv4.PacketConn
|
||||
ps[0] = ipv4.NewPacketConn(c1)
|
||||
ps[1] = ipv4.NewPacketConn(c2)
|
||||
var mift []*net.Interface
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
if _, ok := nettest.IsMulticastCapable("ip4", &ifi); !ok {
|
||||
continue
|
||||
}
|
||||
for _, p := range ps {
|
||||
if err := p.JoinGroup(&ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
mift = append(mift, &ift[i])
|
||||
}
|
||||
for _, ifi := range mift {
|
||||
for _, p := range ps {
|
||||
if err := p.LeaveGroup(ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if testing.Short() {
|
||||
t.Skip("to avoid external network")
|
||||
}
|
||||
|
||||
gaddr := net.IPAddr{IP: net.IPv4(224, 0, 0, 254)} // see RFC 4727
|
||||
type ml struct {
|
||||
c *ipv4.PacketConn
|
||||
ifi *net.Interface
|
||||
}
|
||||
var mlt []*ml
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
ip, ok := nettest.IsMulticastCapable("ip4", &ifi)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket("udp4", ip.String()+":"+"1024") // unicast address with non-reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
if err := p.JoinGroup(&ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mlt = append(mlt, &ml{p, &ift[i]})
|
||||
}
|
||||
for _, m := range mlt {
|
||||
if err := m.c.LeaveGroup(m.ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if testing.Short() {
|
||||
t.Skip("to avoid external network")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0") // wildcard address
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
r, err := ipv4.NewRawConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gaddr := net.IPAddr{IP: net.IPv4(224, 0, 0, 254)} // see RFC 4727
|
||||
var mift []*net.Interface
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
if _, ok := nettest.IsMulticastCapable("ip4", &ifi); !ok {
|
||||
continue
|
||||
}
|
||||
if err := r.JoinGroup(&ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mift = append(mift, &ift[i])
|
||||
}
|
||||
for _, ifi := range mift {
|
||||
if err := r.LeaveGroup(ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPPerInterfaceSingleRawConnWithSingleGroupListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if testing.Short() {
|
||||
t.Skip("to avoid external network")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
gaddr := net.IPAddr{IP: net.IPv4(224, 0, 0, 254)} // see RFC 4727
|
||||
type ml struct {
|
||||
c *ipv4.RawConn
|
||||
ifi *net.Interface
|
||||
}
|
||||
var mlt []*ml
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
ip, ok := nettest.IsMulticastCapable("ip4", &ifi)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket("ip4:253", ip.String()) // unicast address
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
r, err := ipv4.NewRawConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.JoinGroup(&ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mlt = append(mlt, &ml{r, &ift[i]})
|
||||
}
|
||||
for _, m := range mlt {
|
||||
if err := m.c.LeaveGroup(m.ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
195
vendor/golang.org/x/net/ipv4/multicastsockopt_test.go
generated
vendored
195
vendor/golang.org/x/net/ipv4/multicastsockopt_test.go
generated
vendored
@@ -1,195 +0,0 @@
|
||||
// Copyright 2012 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 ipv4_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
var packetConnMulticastSocketOptionTests = []struct {
|
||||
net, proto, addr string
|
||||
grp, src net.Addr
|
||||
}{
|
||||
{"udp4", "", "224.0.0.0:0", &net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}, nil}, // see RFC 4727
|
||||
{"ip4", ":icmp", "0.0.0.0", &net.IPAddr{IP: net.IPv4(224, 0, 0, 250)}, nil}, // see RFC 4727
|
||||
|
||||
{"udp4", "", "232.0.0.0:0", &net.UDPAddr{IP: net.IPv4(232, 0, 1, 249)}, &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)}}, // see RFC 5771
|
||||
{"ip4", ":icmp", "0.0.0.0", &net.IPAddr{IP: net.IPv4(232, 0, 1, 250)}, &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestPacketConnMulticastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
m, ok := nettest.SupportsRawIPSocket()
|
||||
for _, tt := range packetConnMulticastSocketOptionTests {
|
||||
if tt.net == "ip4" && !ok {
|
||||
t.Log(m)
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
|
||||
if tt.src == nil {
|
||||
testMulticastSocketOptions(t, p, ifi, tt.grp)
|
||||
} else {
|
||||
testSourceSpecificMulticastSocketOptions(t, p, ifi, tt.grp, tt.src)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var rawConnMulticastSocketOptionTests = []struct {
|
||||
grp, src net.Addr
|
||||
}{
|
||||
{&net.IPAddr{IP: net.IPv4(224, 0, 0, 250)}, nil}, // see RFC 4727
|
||||
|
||||
{&net.IPAddr{IP: net.IPv4(232, 0, 1, 250)}, &net.IPAddr{IP: net.IPv4(127, 0, 0, 1)}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestRawConnMulticastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
for _, tt := range rawConnMulticastSocketOptionTests {
|
||||
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
r, err := ipv4.NewRawConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
if tt.src == nil {
|
||||
testMulticastSocketOptions(t, r, ifi, tt.grp)
|
||||
} else {
|
||||
testSourceSpecificMulticastSocketOptions(t, r, ifi, tt.grp, tt.src)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type testIPv4MulticastConn interface {
|
||||
MulticastTTL() (int, error)
|
||||
SetMulticastTTL(ttl int) error
|
||||
MulticastLoopback() (bool, error)
|
||||
SetMulticastLoopback(bool) error
|
||||
JoinGroup(*net.Interface, net.Addr) error
|
||||
LeaveGroup(*net.Interface, net.Addr) error
|
||||
JoinSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
LeaveSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
ExcludeSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
IncludeSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
}
|
||||
|
||||
func testMulticastSocketOptions(t *testing.T, c testIPv4MulticastConn, ifi *net.Interface, grp net.Addr) {
|
||||
const ttl = 255
|
||||
if err := c.SetMulticastTTL(ttl); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if v, err := c.MulticastTTL(); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if v != ttl {
|
||||
t.Errorf("got %v; want %v", v, ttl)
|
||||
return
|
||||
}
|
||||
|
||||
for _, toggle := range []bool{true, false} {
|
||||
if err := c.SetMulticastLoopback(toggle); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if v, err := c.MulticastLoopback(); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if v != toggle {
|
||||
t.Errorf("got %v; want %v", v, toggle)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.JoinGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func testSourceSpecificMulticastSocketOptions(t *testing.T, c testIPv4MulticastConn, ifi *net.Interface, grp, src net.Addr) {
|
||||
// MCAST_JOIN_GROUP -> MCAST_BLOCK_SOURCE -> MCAST_UNBLOCK_SOURCE -> MCAST_LEAVE_GROUP
|
||||
if err := c.JoinGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.ExcludeSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
default: // platforms that don't support IGMPv2/3 fail here
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
return
|
||||
}
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.IncludeSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// MCAST_JOIN_SOURCE_GROUP -> MCAST_LEAVE_SOURCE_GROUP
|
||||
if err := c.JoinSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// MCAST_JOIN_SOURCE_GROUP -> MCAST_LEAVE_GROUP
|
||||
if err := c.JoinSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
6
vendor/golang.org/x/net/ipv4/packet.go
generated
vendored
6
vendor/golang.org/x/net/ipv4/packet.go
generated
vendored
@@ -21,7 +21,7 @@ type packetHandler struct {
|
||||
func (c *packetHandler) ok() bool { return c != nil && c.c != nil }
|
||||
|
||||
// ReadFrom reads an IPv4 datagram from the endpoint c, copying the
|
||||
// datagram into b. It returns the received datagram as the IPv4
|
||||
// datagram into b. It returns the received datagram as the IPv4
|
||||
// header h, the payload p and the control message cm.
|
||||
func (c *packetHandler) ReadFrom(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
|
||||
if !c.ok() {
|
||||
@@ -57,9 +57,9 @@ func slicePacket(b []byte) (h, p []byte, err error) {
|
||||
}
|
||||
|
||||
// WriteTo writes an IPv4 datagram through the endpoint c, copying the
|
||||
// datagram from the IPv4 header h and the payload p. The control
|
||||
// datagram from the IPv4 header h and the payload p. The control
|
||||
// message cm allows the datagram path and the outgoing interface to be
|
||||
// specified. Currently only Darwin and Linux support this. The cm
|
||||
// specified. Currently only Darwin and Linux support this. The cm
|
||||
// may be nil if control of the outgoing datagram is not required.
|
||||
//
|
||||
// The IPv4 header h must contain appropriate fields that include:
|
||||
|
||||
8
vendor/golang.org/x/net/ipv4/payload_cmsg.go
generated
vendored
8
vendor/golang.org/x/net/ipv4/payload_cmsg.go
generated
vendored
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// ReadFrom reads a payload of the received IPv4 datagram, from the
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// bytes copied into b, the control message cm and the source address
|
||||
// src of the received datagram.
|
||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
||||
@@ -53,10 +53,10 @@ func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.
|
||||
}
|
||||
|
||||
// WriteTo writes a payload of the IPv4 datagram, to the destination
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// the datagram path and the outgoing interface to be specified.
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// control of the outgoing datagram is not required.
|
||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
|
||||
8
vendor/golang.org/x/net/ipv4/payload_nocmsg.go
generated
vendored
8
vendor/golang.org/x/net/ipv4/payload_nocmsg.go
generated
vendored
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// ReadFrom reads a payload of the received IPv4 datagram, from the
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// bytes copied into b, the control message cm and the source address
|
||||
// src of the received datagram.
|
||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
||||
@@ -26,10 +26,10 @@ func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.
|
||||
}
|
||||
|
||||
// WriteTo writes a payload of the IPv4 datagram, to the destination
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// the datagram path and the outgoing interface to be specified.
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// control of the outgoing datagram is not required.
|
||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
|
||||
174
vendor/golang.org/x/net/ipv4/readwrite_test.go
generated
vendored
174
vendor/golang.org/x/net/ipv4/readwrite_test.go
generated
vendored
@@ -1,174 +0,0 @@
|
||||
// Copyright 2012 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 ipv4_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func benchmarkUDPListener() (net.PacketConn, net.Addr, error) {
|
||||
c, err := net.ListenPacket("udp4", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
dst, err := net.ResolveUDPAddr("udp4", c.LocalAddr().String())
|
||||
if err != nil {
|
||||
c.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
return c, dst, nil
|
||||
}
|
||||
|
||||
func BenchmarkReadWriteNetUDP(b *testing.B) {
|
||||
c, dst, err := benchmarkUDPListener()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
wb, rb := []byte("HELLO-R-U-THERE"), make([]byte, 128)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
benchmarkReadWriteNetUDP(b, c, wb, rb, dst)
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkReadWriteNetUDP(b *testing.B, c net.PacketConn, wb, rb []byte, dst net.Addr) {
|
||||
if _, err := c.WriteTo(wb, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, err := c.ReadFrom(rb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkReadWriteIPv4UDP(b *testing.B) {
|
||||
c, dst, err := benchmarkUDPListener()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv4.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
cf := ipv4.FlagTTL | ipv4.FlagInterface
|
||||
if err := p.SetControlMessage(cf, true); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
|
||||
wb, rb := []byte("HELLO-R-U-THERE"), make([]byte, 128)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
benchmarkReadWriteIPv4UDP(b, p, wb, rb, dst, ifi)
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkReadWriteIPv4UDP(b *testing.B, p *ipv4.PacketConn, wb, rb []byte, dst net.Addr, ifi *net.Interface) {
|
||||
cm := ipv4.ControlMessage{TTL: 1}
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
if n, err := p.WriteTo(wb, &cm, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
b.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
if _, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("udp4", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
|
||||
dst, err := net.ResolveUDPAddr("udp4", c.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
cf := ipv4.FlagTTL | ipv4.FlagSrc | ipv4.FlagDst | ipv4.FlagInterface
|
||||
wb := []byte("HELLO-R-U-THERE")
|
||||
|
||||
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
reader := func() {
|
||||
defer wg.Done()
|
||||
rb := make([]byte, 128)
|
||||
if n, cm, _, err := p.ReadFrom(rb); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if !bytes.Equal(rb[:n], wb) {
|
||||
t.Errorf("got %v; want %v", rb[:n], wb)
|
||||
return
|
||||
} else {
|
||||
s := cm.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Errorf("should be space-separated values: %s", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
writer := func(toggle bool) {
|
||||
defer wg.Done()
|
||||
cm := ipv4.ControlMessage{
|
||||
Src: net.IPv4(127, 0, 0, 1),
|
||||
}
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if n, err := p.WriteTo(wb, &cm, dst); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if n != len(wb) {
|
||||
t.Errorf("short write: %v", n)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const N = 10
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
go reader()
|
||||
}
|
||||
wg.Add(2 * N)
|
||||
for i := 0; i < 2*N; i++ {
|
||||
go writer(i%2 != 0)
|
||||
}
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
go reader()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
250
vendor/golang.org/x/net/ipv4/unicast_test.go
generated
vendored
250
vendor/golang.org/x/net/ipv4/unicast_test.go
generated
vendored
@@ -1,250 +0,0 @@
|
||||
// Copyright 2012 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 ipv4_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/icmp"
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("udp4", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
dst, err := net.ResolveUDPAddr("udp4", c.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := ipv4.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
|
||||
wb := []byte("HELLO-R-U-THERE")
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.SetTTL(i + 1)
|
||||
if err := p.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, err := p.WriteTo(wb, nil, dst); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !bytes.Equal(rb[:n], wb) {
|
||||
t.Fatalf("got %v; want %v", rb[:n], wb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
dst, err := net.ResolveIPAddr("ip4", "127.0.0.1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := ipv4.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
cf := ipv4.FlagDst | ipv4.FlagInterface
|
||||
if runtime.GOOS != "solaris" {
|
||||
// Solaris never allows to modify ICMP properties.
|
||||
cf |= ipv4.FlagTTL
|
||||
}
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
wb, err := (&icmp.Message{
|
||||
Type: ipv4.ICMPTypeEcho, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff, Seq: i + 1,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}).Marshal(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.SetTTL(i + 1)
|
||||
if err := p.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, err := p.WriteTo(wb, nil, dst); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
loop:
|
||||
if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
m, err := icmp.ParseMessage(iana.ProtocolICMP, rb[:n])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if runtime.GOOS == "linux" && m.Type == ipv4.ICMPTypeEcho {
|
||||
// On Linux we must handle own sent packets.
|
||||
goto loop
|
||||
}
|
||||
if m.Type != ipv4.ICMPTypeEchoReply || m.Code != 0 {
|
||||
t.Fatalf("got type=%v, code=%v; want type=%v, code=%v", m.Type, m.Code, ipv4.ICMPTypeEchoReply, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRawConnReadWriteUnicastICMP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
dst, err := net.ResolveIPAddr("ip4", "127.0.0.1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r, err := ipv4.NewRawConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer r.Close()
|
||||
cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
wb, err := (&icmp.Message{
|
||||
Type: ipv4.ICMPTypeEcho, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff, Seq: i + 1,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}).Marshal(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wh := &ipv4.Header{
|
||||
Version: ipv4.Version,
|
||||
Len: ipv4.HeaderLen,
|
||||
TOS: i + 1,
|
||||
TotalLen: ipv4.HeaderLen + len(wb),
|
||||
TTL: i + 1,
|
||||
Protocol: 1,
|
||||
Dst: dst.IP,
|
||||
}
|
||||
if err := r.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.WriteTo(wh, wb, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rb := make([]byte, ipv4.HeaderLen+128)
|
||||
loop:
|
||||
if err := r.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, b, _, err := r.ReadFrom(rb); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
m, err := icmp.ParseMessage(iana.ProtocolICMP, b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if runtime.GOOS == "linux" && m.Type == ipv4.ICMPTypeEcho {
|
||||
// On Linux we must handle own sent packets.
|
||||
goto loop
|
||||
}
|
||||
if m.Type != ipv4.ICMPTypeEchoReply || m.Code != 0 {
|
||||
t.Fatalf("got type=%v, code=%v; want type=%v, code=%v", m.Type, m.Code, ipv4.ICMPTypeEchoReply, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
148
vendor/golang.org/x/net/ipv4/unicastsockopt_test.go
generated
vendored
148
vendor/golang.org/x/net/ipv4/unicastsockopt_test.go
generated
vendored
@@ -1,148 +0,0 @@
|
||||
// Copyright 2012 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 ipv4_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func TestConnUnicastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp4", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
errc <- c.Close()
|
||||
}()
|
||||
|
||||
c, err := net.Dial("tcp4", ln.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
testUnicastSocketOptions(t, ipv4.NewConn(c))
|
||||
|
||||
if err := <-errc; err != nil {
|
||||
t.Errorf("server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
var packetConnUnicastSocketOptionTests = []struct {
|
||||
net, proto, addr string
|
||||
}{
|
||||
{"udp4", "", "127.0.0.1:0"},
|
||||
{"ip4", ":icmp", "127.0.0.1"},
|
||||
}
|
||||
|
||||
func TestPacketConnUnicastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
m, ok := nettest.SupportsRawIPSocket()
|
||||
for _, tt := range packetConnUnicastSocketOptionTests {
|
||||
if tt.net == "ip4" && !ok {
|
||||
t.Log(m)
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
testUnicastSocketOptions(t, ipv4.NewPacketConn(c))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRawConnUnicastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip4:icmp", "127.0.0.1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
r, err := ipv4.NewRawConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testUnicastSocketOptions(t, r)
|
||||
}
|
||||
|
||||
type testIPv4UnicastConn interface {
|
||||
TOS() (int, error)
|
||||
SetTOS(int) error
|
||||
TTL() (int, error)
|
||||
SetTTL(int) error
|
||||
}
|
||||
|
||||
func testUnicastSocketOptions(t *testing.T, c testIPv4UnicastConn) {
|
||||
tos := iana.DiffServCS0 | iana.NotECNTransport
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
// IP_TOS option is supported on Windows 8 and beyond.
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
if err := c.SetTOS(tos); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v, err := c.TOS(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if v != tos {
|
||||
t.Fatalf("got %v; want %v", v, tos)
|
||||
}
|
||||
const ttl = 255
|
||||
if err := c.SetTTL(ttl); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v, err := c.TTL(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if v != ttl {
|
||||
t.Fatalf("got %v; want %v", v, ttl)
|
||||
}
|
||||
}
|
||||
96
vendor/golang.org/x/net/ipv6/bpf_test.go
generated
vendored
96
vendor/golang.org/x/net/ipv6/bpf_test.go
generated
vendored
@@ -1,96 +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 ipv6_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/bpf"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
func TestBPF(t *testing.T) {
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
l, err := net.ListenPacket("udp6", "[::1]:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
p := ipv6.NewPacketConn(l)
|
||||
|
||||
// This filter accepts UDP packets whose first payload byte is
|
||||
// even.
|
||||
prog, err := bpf.Assemble([]bpf.Instruction{
|
||||
// Load the first byte of the payload (skipping UDP header).
|
||||
bpf.LoadAbsolute{Off: 8, Size: 1},
|
||||
// Select LSB of the byte.
|
||||
bpf.ALUOpConstant{Op: bpf.ALUOpAnd, Val: 1},
|
||||
// Byte is even?
|
||||
bpf.JumpIf{Cond: bpf.JumpEqual, Val: 0, SkipFalse: 1},
|
||||
// Accept.
|
||||
bpf.RetConstant{Val: 4096},
|
||||
// Ignore.
|
||||
bpf.RetConstant{Val: 0},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("compiling BPF: %s", err)
|
||||
}
|
||||
|
||||
if err = p.SetBPF(prog); err != nil {
|
||||
t.Fatalf("attaching filter to Conn: %s", err)
|
||||
}
|
||||
|
||||
s, err := net.Dial("udp6", l.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer s.Close()
|
||||
go func() {
|
||||
for i := byte(0); i < 10; i++ {
|
||||
s.Write([]byte{i})
|
||||
}
|
||||
}()
|
||||
|
||||
l.SetDeadline(time.Now().Add(2 * time.Second))
|
||||
seen := make([]bool, 5)
|
||||
for {
|
||||
var b [512]byte
|
||||
n, _, err := l.ReadFrom(b[:])
|
||||
if err != nil {
|
||||
t.Fatalf("reading from listener: %s", err)
|
||||
}
|
||||
if n != 1 {
|
||||
t.Fatalf("unexpected packet length, want 1, got %d", n)
|
||||
}
|
||||
if b[0] >= 10 {
|
||||
t.Fatalf("unexpected byte, want 0-9, got %d", b[0])
|
||||
}
|
||||
if b[0]%2 != 0 {
|
||||
t.Fatalf("got odd byte %d, wanted only even bytes", b[0])
|
||||
}
|
||||
seen[b[0]/2] = true
|
||||
|
||||
seenAll := true
|
||||
for _, v := range seen {
|
||||
if !v {
|
||||
seenAll = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if seenAll {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
216
vendor/golang.org/x/net/ipv6/example_test.go
generated
vendored
216
vendor/golang.org/x/net/ipv6/example_test.go
generated
vendored
@@ -1,216 +0,0 @@
|
||||
// Copyright 2014 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 ipv6_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/icmp"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
func ExampleConn_markingTCP() {
|
||||
ln, err := net.Listen("tcp", "[::]:1024")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
for {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
go func(c net.Conn) {
|
||||
defer c.Close()
|
||||
if c.RemoteAddr().(*net.TCPAddr).IP.To16() != nil && c.RemoteAddr().(*net.TCPAddr).IP.To4() == nil {
|
||||
p := ipv6.NewConn(c)
|
||||
if err := p.SetTrafficClass(0x28); err != nil { // DSCP AF11
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := p.SetHopLimit(128); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := c.Write([]byte("HELLO-R-U-THERE-ACK")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}(c)
|
||||
}
|
||||
}
|
||||
|
||||
func ExamplePacketConn_servingOneShotMulticastDNS() {
|
||||
c, err := net.ListenPacket("udp6", "[::]:5353") // mDNS over UDP
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
|
||||
en0, err := net.InterfaceByName("en0")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
mDNSLinkLocal := net.UDPAddr{IP: net.ParseIP("ff02::fb")}
|
||||
if err := p.JoinGroup(en0, &mDNSLinkLocal); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer p.LeaveGroup(en0, &mDNSLinkLocal)
|
||||
if err := p.SetControlMessage(ipv6.FlagDst|ipv6.FlagInterface, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var wcm ipv6.ControlMessage
|
||||
b := make([]byte, 1500)
|
||||
for {
|
||||
_, rcm, peer, err := p.ReadFrom(b)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if !rcm.Dst.IsMulticast() || !rcm.Dst.Equal(mDNSLinkLocal.IP) {
|
||||
continue
|
||||
}
|
||||
wcm.IfIndex = rcm.IfIndex
|
||||
answers := []byte("FAKE-MDNS-ANSWERS") // fake mDNS answers, you need to implement this
|
||||
if _, err := p.WriteTo(answers, &wcm, peer); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ExamplePacketConn_tracingIPPacketRoute() {
|
||||
// Tracing an IP packet route to www.google.com.
|
||||
|
||||
const host = "www.google.com"
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var dst net.IPAddr
|
||||
for _, ip := range ips {
|
||||
if ip.To16() != nil && ip.To4() == nil {
|
||||
dst.IP = ip
|
||||
fmt.Printf("using %v for tracing an IP packet route to %s\n", dst.IP, host)
|
||||
break
|
||||
}
|
||||
}
|
||||
if dst.IP == nil {
|
||||
log.Fatal("no AAAA record found")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip6:58", "::") // ICMP for IPv6
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
|
||||
if err := p.SetControlMessage(ipv6.FlagHopLimit|ipv6.FlagSrc|ipv6.FlagDst|ipv6.FlagInterface, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
wm := icmp.Message{
|
||||
Type: ipv6.ICMPTypeEchoRequest, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}
|
||||
var f ipv6.ICMPFilter
|
||||
f.SetAll(true)
|
||||
f.Accept(ipv6.ICMPTypeTimeExceeded)
|
||||
f.Accept(ipv6.ICMPTypeEchoReply)
|
||||
if err := p.SetICMPFilter(&f); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var wcm ipv6.ControlMessage
|
||||
rb := make([]byte, 1500)
|
||||
for i := 1; i <= 64; i++ { // up to 64 hops
|
||||
wm.Body.(*icmp.Echo).Seq = i
|
||||
wb, err := wm.Marshal(nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// In the real world usually there are several
|
||||
// multiple traffic-engineered paths for each hop.
|
||||
// You may need to probe a few times to each hop.
|
||||
begin := time.Now()
|
||||
wcm.HopLimit = i
|
||||
if _, err := p.WriteTo(wb, &wcm, &dst); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := p.SetReadDeadline(time.Now().Add(3 * time.Second)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
n, rcm, peer, err := p.ReadFrom(rb)
|
||||
if err != nil {
|
||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||
fmt.Printf("%v\t*\n", i)
|
||||
continue
|
||||
}
|
||||
log.Fatal(err)
|
||||
}
|
||||
rm, err := icmp.ParseMessage(58, rb[:n])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
rtt := time.Since(begin)
|
||||
|
||||
// In the real world you need to determine whether the
|
||||
// received message is yours using ControlMessage.Src,
|
||||
// ControlMesage.Dst, icmp.Echo.ID and icmp.Echo.Seq.
|
||||
switch rm.Type {
|
||||
case ipv6.ICMPTypeTimeExceeded:
|
||||
names, _ := net.LookupAddr(peer.String())
|
||||
fmt.Printf("%d\t%v %+v %v\n\t%+v\n", i, peer, names, rtt, rcm)
|
||||
case ipv6.ICMPTypeEchoReply:
|
||||
names, _ := net.LookupAddr(peer.String())
|
||||
fmt.Printf("%d\t%v %+v %v\n\t%+v\n", i, peer, names, rtt, rcm)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ExamplePacketConn_advertisingOSPFHello() {
|
||||
c, err := net.ListenPacket("ip6:89", "::") // OSPF for IPv6
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
|
||||
en0, err := net.InterfaceByName("en0")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
allSPFRouters := net.IPAddr{IP: net.ParseIP("ff02::5")}
|
||||
if err := p.JoinGroup(en0, &allSPFRouters); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer p.LeaveGroup(en0, &allSPFRouters)
|
||||
|
||||
hello := make([]byte, 24) // fake hello data, you need to implement this
|
||||
ospf := make([]byte, 16) // fake ospf header, you need to implement this
|
||||
ospf[0] = 3 // version 3
|
||||
ospf[1] = 1 // hello packet
|
||||
ospf = append(ospf, hello...)
|
||||
if err := p.SetChecksum(true, 12); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
cm := ipv6.ControlMessage{
|
||||
TrafficClass: 0xc0, // DSCP CS6
|
||||
HopLimit: 1,
|
||||
IfIndex: en0.Index,
|
||||
}
|
||||
if _, err := p.WriteTo(ospf, &cm, &allSPFRouters); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
11
vendor/golang.org/x/net/ipv6/go19_test.go
generated
vendored
11
vendor/golang.org/x/net/ipv6/go19_test.go
generated
vendored
@@ -1,11 +0,0 @@
|
||||
// Copyright 2017 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.
|
||||
|
||||
// +build go1.9
|
||||
|
||||
package ipv6
|
||||
|
||||
func init() {
|
||||
disableTests = true
|
||||
}
|
||||
55
vendor/golang.org/x/net/ipv6/header_test.go
generated
vendored
55
vendor/golang.org/x/net/ipv6/header_test.go
generated
vendored
@@ -1,55 +0,0 @@
|
||||
// Copyright 2014 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 ipv6_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
var (
|
||||
wireHeaderFromKernel = [ipv6.HeaderLen]byte{
|
||||
0x69, 0x8b, 0xee, 0xf1,
|
||||
0xca, 0xfe, 0x2c, 0x01,
|
||||
0x20, 0x01, 0x0d, 0xb8,
|
||||
0x00, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01,
|
||||
0x20, 0x01, 0x0d, 0xb8,
|
||||
0x00, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01,
|
||||
}
|
||||
|
||||
testHeader = &ipv6.Header{
|
||||
Version: ipv6.Version,
|
||||
TrafficClass: iana.DiffServAF43,
|
||||
FlowLabel: 0xbeef1,
|
||||
PayloadLen: 0xcafe,
|
||||
NextHeader: iana.ProtocolIPv6Frag,
|
||||
HopLimit: 1,
|
||||
Src: net.ParseIP("2001:db8:1::1"),
|
||||
Dst: net.ParseIP("2001:db8:2::1"),
|
||||
}
|
||||
)
|
||||
|
||||
func TestParseHeader(t *testing.T) {
|
||||
h, err := ipv6.ParseHeader(wireHeaderFromKernel[:])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(h, testHeader) {
|
||||
t.Fatalf("got %#v; want %#v", h, testHeader)
|
||||
}
|
||||
s := h.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Fatalf("should be space-separated values: %s", s)
|
||||
}
|
||||
}
|
||||
96
vendor/golang.org/x/net/ipv6/icmp_test.go
generated
vendored
96
vendor/golang.org/x/net/ipv6/icmp_test.go
generated
vendored
@@ -1,96 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
var icmpStringTests = []struct {
|
||||
in ipv6.ICMPType
|
||||
out string
|
||||
}{
|
||||
{ipv6.ICMPTypeDestinationUnreachable, "destination unreachable"},
|
||||
|
||||
{256, "<nil>"},
|
||||
}
|
||||
|
||||
func TestICMPString(t *testing.T) {
|
||||
for _, tt := range icmpStringTests {
|
||||
s := tt.in.String()
|
||||
if s != tt.out {
|
||||
t.Errorf("got %s; want %s", s, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestICMPFilter(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
var f ipv6.ICMPFilter
|
||||
for _, toggle := range []bool{false, true} {
|
||||
f.SetAll(toggle)
|
||||
for _, typ := range []ipv6.ICMPType{
|
||||
ipv6.ICMPTypeDestinationUnreachable,
|
||||
ipv6.ICMPTypeEchoReply,
|
||||
ipv6.ICMPTypeNeighborSolicitation,
|
||||
ipv6.ICMPTypeDuplicateAddressConfirmation,
|
||||
} {
|
||||
f.Accept(typ)
|
||||
if f.WillBlock(typ) {
|
||||
t.Errorf("ipv6.ICMPFilter.Set(%v, false) failed", typ)
|
||||
}
|
||||
f.Block(typ)
|
||||
if !f.WillBlock(typ) {
|
||||
t.Errorf("ipv6.ICMPFilter.Set(%v, true) failed", typ)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetICMPFilter(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip6:ipv6-icmp", "::1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv6.NewPacketConn(c)
|
||||
|
||||
var f ipv6.ICMPFilter
|
||||
f.SetAll(true)
|
||||
f.Accept(ipv6.ICMPTypeEchoRequest)
|
||||
f.Accept(ipv6.ICMPTypeEchoReply)
|
||||
if err := p.SetICMPFilter(&f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kf, err := p.ICMPFilter()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(kf, &f) {
|
||||
t.Fatalf("got %#v; want %#v", kf, f)
|
||||
}
|
||||
}
|
||||
22
vendor/golang.org/x/net/ipv6/ipv6_test.go
generated
vendored
22
vendor/golang.org/x/net/ipv6/ipv6_test.go
generated
vendored
@@ -1,22 +0,0 @@
|
||||
// Copyright 2017 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 ipv6
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var disableTests = false
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if disableTests {
|
||||
fmt.Fprintf(os.Stderr, "ipv6 tests disabled in Go 1.9 until netreflect is fixed (Issue 19051)\n")
|
||||
os.Exit(0)
|
||||
}
|
||||
// call flag.Parse() here if TestMain uses flags
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
32
vendor/golang.org/x/net/ipv6/mocktransponder_test.go
generated
vendored
32
vendor/golang.org/x/net/ipv6/mocktransponder_test.go
generated
vendored
@@ -1,32 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func connector(t *testing.T, network, addr string, done chan<- bool) {
|
||||
defer func() { done <- true }()
|
||||
|
||||
c, err := net.Dial(network, addr)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
|
||||
func acceptor(t *testing.T, ln net.Listener, done chan<- bool) {
|
||||
defer func() { done <- true }()
|
||||
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
264
vendor/golang.org/x/net/ipv6/multicast_test.go
generated
vendored
264
vendor/golang.org/x/net/ipv6/multicast_test.go
generated
vendored
@@ -1,264 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/icmp"
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
var packetConnReadWriteMulticastUDPTests = []struct {
|
||||
addr string
|
||||
grp, src *net.UDPAddr
|
||||
}{
|
||||
{"[ff02::]:0", &net.UDPAddr{IP: net.ParseIP("ff02::114")}, nil}, // see RFC 4727
|
||||
|
||||
{"[ff30::8000:0]:0", &net.UDPAddr{IP: net.ParseIP("ff30::8000:1")}, &net.UDPAddr{IP: net.IPv6loopback}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
if !nettest.SupportsIPv6MulticastDeliveryOnLoopback() {
|
||||
t.Skipf("multicast delivery doesn't work correctly on %s", runtime.GOOS)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
for _, tt := range packetConnReadWriteMulticastUDPTests {
|
||||
c, err := net.ListenPacket("udp6", tt.addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
grp := *tt.grp
|
||||
grp.Port = c.LocalAddr().(*net.UDPAddr).Port
|
||||
p := ipv6.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
if tt.src == nil {
|
||||
if err := p.JoinGroup(ifi, &grp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveGroup(ifi, &grp)
|
||||
} else {
|
||||
if err := p.JoinSourceSpecificGroup(ifi, &grp, tt.src); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
default: // platforms that don't support MLDv2 fail here
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveSourceSpecificGroup(ifi, &grp, tt.src)
|
||||
}
|
||||
if err := p.SetMulticastInterface(ifi); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastInterface(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetMulticastLoopback(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastLoopback(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cm := ipv6.ControlMessage{
|
||||
TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
||||
Src: net.IPv6loopback,
|
||||
IfIndex: ifi.Index,
|
||||
}
|
||||
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
|
||||
wb := []byte("HELLO-R-U-THERE")
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cm.HopLimit = i + 1
|
||||
if n, err := p.WriteTo(wb, &cm, &grp); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !bytes.Equal(rb[:n], wb) {
|
||||
t.Fatalf("got %v; want %v", rb[:n], wb)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var packetConnReadWriteMulticastICMPTests = []struct {
|
||||
grp, src *net.IPAddr
|
||||
}{
|
||||
{&net.IPAddr{IP: net.ParseIP("ff02::114")}, nil}, // see RFC 4727
|
||||
|
||||
{&net.IPAddr{IP: net.ParseIP("ff30::8000:1")}, &net.IPAddr{IP: net.IPv6loopback}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
if !nettest.SupportsIPv6MulticastDeliveryOnLoopback() {
|
||||
t.Skipf("multicast delivery doesn't work correctly on %s", runtime.GOOS)
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
for _, tt := range packetConnReadWriteMulticastICMPTests {
|
||||
c, err := net.ListenPacket("ip6:ipv6-icmp", "::")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
pshicmp := icmp.IPv6PseudoHeader(c.LocalAddr().(*net.IPAddr).IP, tt.grp.IP)
|
||||
p := ipv6.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
if tt.src == nil {
|
||||
if err := p.JoinGroup(ifi, tt.grp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveGroup(ifi, tt.grp)
|
||||
} else {
|
||||
if err := p.JoinSourceSpecificGroup(ifi, tt.grp, tt.src); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
default: // platforms that don't support MLDv2 fail here
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer p.LeaveSourceSpecificGroup(ifi, tt.grp, tt.src)
|
||||
}
|
||||
if err := p.SetMulticastInterface(ifi); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastInterface(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetMulticastLoopback(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.MulticastLoopback(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cm := ipv6.ControlMessage{
|
||||
TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
||||
Src: net.IPv6loopback,
|
||||
IfIndex: ifi.Index,
|
||||
}
|
||||
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
|
||||
|
||||
var f ipv6.ICMPFilter
|
||||
f.SetAll(true)
|
||||
f.Accept(ipv6.ICMPTypeEchoReply)
|
||||
if err := p.SetICMPFilter(&f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var psh []byte
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
if toggle {
|
||||
psh = nil
|
||||
if err := p.SetChecksum(true, 2); err != nil {
|
||||
// Solaris never allows to
|
||||
// modify ICMP properties.
|
||||
if runtime.GOOS != "solaris" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
psh = pshicmp
|
||||
// Some platforms never allow to
|
||||
// disable the kernel checksum
|
||||
// processing.
|
||||
p.SetChecksum(false, -1)
|
||||
}
|
||||
wb, err := (&icmp.Message{
|
||||
Type: ipv6.ICMPTypeEchoRequest, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff, Seq: i + 1,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}).Marshal(psh)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cm.HopLimit = i + 1
|
||||
if n, err := p.WriteTo(wb, &cm, tt.grp); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 {
|
||||
t.Fatalf("got type=%v, code=%v; want type=%v, code=%v", m.Type, m.Code, ipv6.ICMPTypeEchoReply, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
246
vendor/golang.org/x/net/ipv6/multicastlistener_test.go
generated
vendored
246
vendor/golang.org/x/net/ipv6/multicastlistener_test.go
generated
vendored
@@ -1,246 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
var udpMultipleGroupListenerTests = []net.Addr{
|
||||
&net.UDPAddr{IP: net.ParseIP("ff02::114")}, // see RFC 4727
|
||||
&net.UDPAddr{IP: net.ParseIP("ff02::1:114")},
|
||||
&net.UDPAddr{IP: net.ParseIP("ff02::2:114")},
|
||||
}
|
||||
|
||||
func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
for _, gaddr := range udpMultipleGroupListenerTests {
|
||||
c, err := net.ListenPacket("udp6", "[::]:0") // wildcard address with non-reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv6.NewPacketConn(c)
|
||||
var mift []*net.Interface
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
|
||||
continue
|
||||
}
|
||||
if err := p.JoinGroup(&ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mift = append(mift, &ift[i])
|
||||
}
|
||||
for _, ifi := range mift {
|
||||
if err := p.LeaveGroup(ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
for _, gaddr := range udpMultipleGroupListenerTests {
|
||||
c1, err := net.ListenPacket("udp6", "[ff02::]:1024") // wildcard address with reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c1.Close()
|
||||
|
||||
c2, err := net.ListenPacket("udp6", "[ff02::]:1024") // wildcard address with reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c2.Close()
|
||||
|
||||
var ps [2]*ipv6.PacketConn
|
||||
ps[0] = ipv6.NewPacketConn(c1)
|
||||
ps[1] = ipv6.NewPacketConn(c2)
|
||||
var mift []*net.Interface
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
|
||||
continue
|
||||
}
|
||||
for _, p := range ps {
|
||||
if err := p.JoinGroup(&ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
mift = append(mift, &ift[i])
|
||||
}
|
||||
for _, ifi := range mift {
|
||||
for _, p := range ps {
|
||||
if err := p.LeaveGroup(ifi, gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727
|
||||
type ml struct {
|
||||
c *ipv6.PacketConn
|
||||
ifi *net.Interface
|
||||
}
|
||||
var mlt []*ml
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket("udp6", fmt.Sprintf("[%s%%%s]:1024", ip.String(), ifi.Name)) // unicast address with non-reusable port
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
if err := p.JoinGroup(&ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mlt = append(mlt, &ml{p, &ift[i]})
|
||||
}
|
||||
for _, m := range mlt {
|
||||
if err := m.c.LeaveGroup(m.ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip6:ipv6-icmp", "::") // wildcard address
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv6.NewPacketConn(c)
|
||||
gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727
|
||||
var mift []*net.Interface
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
|
||||
continue
|
||||
}
|
||||
if err := p.JoinGroup(&ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mift = append(mift, &ift[i])
|
||||
}
|
||||
for _, ifi := range mift {
|
||||
if err := p.LeaveGroup(ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "openbsd": // platforms that return fe80::1%lo0: bind: can't assign requested address
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727
|
||||
type ml struct {
|
||||
c *ipv6.PacketConn
|
||||
ifi *net.Interface
|
||||
}
|
||||
var mlt []*ml
|
||||
|
||||
ift, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, ifi := range ift {
|
||||
ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket("ip6:ipv6-icmp", fmt.Sprintf("%s%%%s", ip.String(), ifi.Name)) // unicast address
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
if err := p.JoinGroup(&ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mlt = append(mlt, &ml{p, &ift[i]})
|
||||
}
|
||||
for _, m := range mlt {
|
||||
if err := m.c.LeaveGroup(m.ifi, &gaddr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
157
vendor/golang.org/x/net/ipv6/multicastsockopt_test.go
generated
vendored
157
vendor/golang.org/x/net/ipv6/multicastsockopt_test.go
generated
vendored
@@ -1,157 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
var packetConnMulticastSocketOptionTests = []struct {
|
||||
net, proto, addr string
|
||||
grp, src net.Addr
|
||||
}{
|
||||
{"udp6", "", "[ff02::]:0", &net.UDPAddr{IP: net.ParseIP("ff02::114")}, nil}, // see RFC 4727
|
||||
{"ip6", ":ipv6-icmp", "::", &net.IPAddr{IP: net.ParseIP("ff02::115")}, nil}, // see RFC 4727
|
||||
|
||||
{"udp6", "", "[ff30::8000:0]:0", &net.UDPAddr{IP: net.ParseIP("ff30::8000:1")}, &net.UDPAddr{IP: net.IPv6loopback}}, // see RFC 5771
|
||||
{"ip6", ":ipv6-icmp", "::", &net.IPAddr{IP: net.ParseIP("ff30::8000:2")}, &net.IPAddr{IP: net.IPv6loopback}}, // see RFC 5771
|
||||
}
|
||||
|
||||
func TestPacketConnMulticastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
||||
if ifi == nil {
|
||||
t.Skipf("not available on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
m, ok := nettest.SupportsRawIPSocket()
|
||||
for _, tt := range packetConnMulticastSocketOptionTests {
|
||||
if tt.net == "ip6" && !ok {
|
||||
t.Log(m)
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
|
||||
if tt.src == nil {
|
||||
testMulticastSocketOptions(t, p, ifi, tt.grp)
|
||||
} else {
|
||||
testSourceSpecificMulticastSocketOptions(t, p, ifi, tt.grp, tt.src)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type testIPv6MulticastConn interface {
|
||||
MulticastHopLimit() (int, error)
|
||||
SetMulticastHopLimit(ttl int) error
|
||||
MulticastLoopback() (bool, error)
|
||||
SetMulticastLoopback(bool) error
|
||||
JoinGroup(*net.Interface, net.Addr) error
|
||||
LeaveGroup(*net.Interface, net.Addr) error
|
||||
JoinSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
LeaveSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
ExcludeSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
IncludeSourceSpecificGroup(*net.Interface, net.Addr, net.Addr) error
|
||||
}
|
||||
|
||||
func testMulticastSocketOptions(t *testing.T, c testIPv6MulticastConn, ifi *net.Interface, grp net.Addr) {
|
||||
const hoplim = 255
|
||||
if err := c.SetMulticastHopLimit(hoplim); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if v, err := c.MulticastHopLimit(); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if v != hoplim {
|
||||
t.Errorf("got %v; want %v", v, hoplim)
|
||||
return
|
||||
}
|
||||
|
||||
for _, toggle := range []bool{true, false} {
|
||||
if err := c.SetMulticastLoopback(toggle); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if v, err := c.MulticastLoopback(); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if v != toggle {
|
||||
t.Errorf("got %v; want %v", v, toggle)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.JoinGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func testSourceSpecificMulticastSocketOptions(t *testing.T, c testIPv6MulticastConn, ifi *net.Interface, grp, src net.Addr) {
|
||||
// MCAST_JOIN_GROUP -> MCAST_BLOCK_SOURCE -> MCAST_UNBLOCK_SOURCE -> MCAST_LEAVE_GROUP
|
||||
if err := c.JoinGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.ExcludeSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
default: // platforms that don't support MLDv2 fail here
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
return
|
||||
}
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.IncludeSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// MCAST_JOIN_SOURCE_GROUP -> MCAST_LEAVE_SOURCE_GROUP
|
||||
if err := c.JoinSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// MCAST_JOIN_SOURCE_GROUP -> MCAST_LEAVE_GROUP
|
||||
if err := c.JoinSourceSpecificGroup(ifi, grp, src); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := c.LeaveGroup(ifi, grp); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
189
vendor/golang.org/x/net/ipv6/readwrite_test.go
generated
vendored
189
vendor/golang.org/x/net/ipv6/readwrite_test.go
generated
vendored
@@ -1,189 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
func benchmarkUDPListener() (net.PacketConn, net.Addr, error) {
|
||||
c, err := net.ListenPacket("udp6", "[::1]:0")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
dst, err := net.ResolveUDPAddr("udp6", c.LocalAddr().String())
|
||||
if err != nil {
|
||||
c.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
return c, dst, nil
|
||||
}
|
||||
|
||||
func BenchmarkReadWriteNetUDP(b *testing.B) {
|
||||
if !supportsIPv6 {
|
||||
b.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
c, dst, err := benchmarkUDPListener()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
wb, rb := []byte("HELLO-R-U-THERE"), make([]byte, 128)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
benchmarkReadWriteNetUDP(b, c, wb, rb, dst)
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkReadWriteNetUDP(b *testing.B, c net.PacketConn, wb, rb []byte, dst net.Addr) {
|
||||
if _, err := c.WriteTo(wb, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, err := c.ReadFrom(rb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkReadWriteIPv6UDP(b *testing.B) {
|
||||
if !supportsIPv6 {
|
||||
b.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
c, dst, err := benchmarkUDPListener()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv6.NewPacketConn(c)
|
||||
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
|
||||
if err := p.SetControlMessage(cf, true); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
|
||||
|
||||
wb, rb := []byte("HELLO-R-U-THERE"), make([]byte, 128)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
benchmarkReadWriteIPv6UDP(b, p, wb, rb, dst, ifi)
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkReadWriteIPv6UDP(b *testing.B, p *ipv6.PacketConn, wb, rb []byte, dst net.Addr, ifi *net.Interface) {
|
||||
cm := ipv6.ControlMessage{
|
||||
TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
||||
HopLimit: 1,
|
||||
}
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
if n, err := p.WriteTo(wb, &cm, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
b.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
if _, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("udp6", "[::1]:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
|
||||
dst, err := net.ResolveUDPAddr("udp6", c.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
|
||||
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
|
||||
wb := []byte("HELLO-R-U-THERE")
|
||||
|
||||
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
reader := func() {
|
||||
defer wg.Done()
|
||||
rb := make([]byte, 128)
|
||||
if n, cm, _, err := p.ReadFrom(rb); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if !bytes.Equal(rb[:n], wb) {
|
||||
t.Errorf("got %v; want %v", rb[:n], wb)
|
||||
return
|
||||
} else {
|
||||
s := cm.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Errorf("should be space-separated values: %s", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
writer := func(toggle bool) {
|
||||
defer wg.Done()
|
||||
cm := ipv6.ControlMessage{
|
||||
TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
||||
Src: net.IPv6loopback,
|
||||
}
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if n, err := p.WriteTo(wb, &cm, dst); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if n != len(wb) {
|
||||
t.Errorf("got %v; want %v", n, len(wb))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const N = 10
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
go reader()
|
||||
}
|
||||
wg.Add(2 * N)
|
||||
for i := 0; i < 2*N; i++ {
|
||||
go writer(i%2 != 0)
|
||||
}
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
go reader()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
133
vendor/golang.org/x/net/ipv6/sockopt_test.go
generated
vendored
133
vendor/golang.org/x/net/ipv6/sockopt_test.go
generated
vendored
@@ -1,133 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
var supportsIPv6 bool = nettest.SupportsIPv6()
|
||||
|
||||
func TestConnInitiatorPathMTU(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp6", "[::1]:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
done := make(chan bool)
|
||||
go acceptor(t, ln, done)
|
||||
|
||||
c, err := net.Dial("tcp6", ln.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
if pmtu, err := ipv6.NewConn(c).PathMTU(); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // older darwin kernels don't support IPV6_PATHMTU option
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
default:
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
t.Logf("path mtu for %v: %v", c.RemoteAddr(), pmtu)
|
||||
}
|
||||
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestConnResponderPathMTU(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp6", "[::1]:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
done := make(chan bool)
|
||||
go connector(t, "tcp6", ln.Addr().String(), done)
|
||||
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
if pmtu, err := ipv6.NewConn(c).PathMTU(); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // older darwin kernels don't support IPV6_PATHMTU option
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
default:
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
t.Logf("path mtu for %v: %v", c.RemoteAddr(), pmtu)
|
||||
}
|
||||
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestPacketConnChecksum(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket(fmt.Sprintf("ip6:%d", iana.ProtocolOSPFIGP), "::") // OSPF for IPv6
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p := ipv6.NewPacketConn(c)
|
||||
offset := 12 // see RFC 5340
|
||||
|
||||
for _, toggle := range []bool{false, true} {
|
||||
if err := p.SetChecksum(toggle, offset); err != nil {
|
||||
if toggle {
|
||||
t.Fatalf("ipv6.PacketConn.SetChecksum(%v, %v) failed: %v", toggle, offset, err)
|
||||
} else {
|
||||
// Some platforms never allow to disable the kernel
|
||||
// checksum processing.
|
||||
t.Logf("ipv6.PacketConn.SetChecksum(%v, %v) failed: %v", toggle, offset, err)
|
||||
}
|
||||
}
|
||||
if on, offset, err := p.Checksum(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
t.Logf("kernel checksum processing enabled=%v, offset=%v", on, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
186
vendor/golang.org/x/net/ipv6/unicast_test.go
generated
vendored
186
vendor/golang.org/x/net/ipv6/unicast_test.go
generated
vendored
@@ -1,186 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/icmp"
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("udp6", "[::1]:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
|
||||
dst, err := net.ResolveUDPAddr("udp6", c.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cm := ipv6.ControlMessage{
|
||||
TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
||||
Src: net.IPv6loopback,
|
||||
}
|
||||
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
|
||||
ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
wb := []byte("HELLO-R-U-THERE")
|
||||
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
cm.HopLimit = i + 1
|
||||
if err := p.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, err := p.WriteTo(wb, &cm, dst); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !bytes.Equal(rb[:n], wb) {
|
||||
t.Fatalf("got %v; want %v", rb[:n], wb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
if m, ok := nettest.SupportsRawIPSocket(); !ok {
|
||||
t.Skip(m)
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("ip6:ipv6-icmp", "::1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv6.NewPacketConn(c)
|
||||
defer p.Close()
|
||||
|
||||
dst, err := net.ResolveIPAddr("ip6", "::1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pshicmp := icmp.IPv6PseudoHeader(c.LocalAddr().(*net.IPAddr).IP, dst.IP)
|
||||
cm := ipv6.ControlMessage{
|
||||
TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
||||
Src: net.IPv6loopback,
|
||||
}
|
||||
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
|
||||
ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
|
||||
var f ipv6.ICMPFilter
|
||||
f.SetAll(true)
|
||||
f.Accept(ipv6.ICMPTypeEchoReply)
|
||||
if err := p.SetICMPFilter(&f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var psh []byte
|
||||
for i, toggle := range []bool{true, false, true} {
|
||||
if toggle {
|
||||
psh = nil
|
||||
if err := p.SetChecksum(true, 2); err != nil {
|
||||
// Solaris never allows to modify
|
||||
// ICMP properties.
|
||||
if runtime.GOOS != "solaris" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
psh = pshicmp
|
||||
// Some platforms never allow to disable the
|
||||
// kernel checksum processing.
|
||||
p.SetChecksum(false, -1)
|
||||
}
|
||||
wb, err := (&icmp.Message{
|
||||
Type: ipv6.ICMPTypeEchoRequest, Code: 0,
|
||||
Body: &icmp.Echo{
|
||||
ID: os.Getpid() & 0xffff, Seq: i + 1,
|
||||
Data: []byte("HELLO-R-U-THERE"),
|
||||
},
|
||||
}).Marshal(psh)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
cm.HopLimit = i + 1
|
||||
if err := p.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, err := p.WriteTo(wb, &cm, dst); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != len(wb) {
|
||||
t.Fatalf("got %v; want %v", n, len(wb))
|
||||
}
|
||||
rb := make([]byte, 128)
|
||||
if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, _, _, err := p.ReadFrom(rb); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 {
|
||||
t.Fatalf("got type=%v, code=%v; want type=%v, code=%v", m.Type, m.Code, ipv6.ICMPTypeEchoReply, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
vendor/golang.org/x/net/ipv6/unicastsockopt_test.go
generated
vendored
120
vendor/golang.org/x/net/ipv6/unicastsockopt_test.go
generated
vendored
@@ -1,120 +0,0 @@
|
||||
// Copyright 2013 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 ipv6_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
func TestConnUnicastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp6", "[::1]:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
errc <- c.Close()
|
||||
}()
|
||||
|
||||
c, err := net.Dial("tcp6", ln.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
testUnicastSocketOptions(t, ipv6.NewConn(c))
|
||||
|
||||
if err := <-errc; err != nil {
|
||||
t.Errorf("server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
var packetConnUnicastSocketOptionTests = []struct {
|
||||
net, proto, addr string
|
||||
}{
|
||||
{"udp6", "", "[::1]:0"},
|
||||
{"ip6", ":ipv6-icmp", "::1"},
|
||||
}
|
||||
|
||||
func TestPacketConnUnicastSocketOptions(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
if !supportsIPv6 {
|
||||
t.Skip("ipv6 is not supported")
|
||||
}
|
||||
|
||||
m, ok := nettest.SupportsRawIPSocket()
|
||||
for _, tt := range packetConnUnicastSocketOptionTests {
|
||||
if tt.net == "ip6" && !ok {
|
||||
t.Log(m)
|
||||
continue
|
||||
}
|
||||
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
testUnicastSocketOptions(t, ipv6.NewPacketConn(c))
|
||||
}
|
||||
}
|
||||
|
||||
type testIPv6UnicastConn interface {
|
||||
TrafficClass() (int, error)
|
||||
SetTrafficClass(int) error
|
||||
HopLimit() (int, error)
|
||||
SetHopLimit(int) error
|
||||
}
|
||||
|
||||
func testUnicastSocketOptions(t *testing.T, c testIPv6UnicastConn) {
|
||||
tclass := iana.DiffServCS0 | iana.NotECNTransport
|
||||
if err := c.SetTrafficClass(tclass); err != nil {
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // older darwin kernels don't support IPV6_TCLASS option
|
||||
t.Logf("not supported on %s", runtime.GOOS)
|
||||
goto next
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v, err := c.TrafficClass(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if v != tclass {
|
||||
t.Fatalf("got %v; want %v", v, tclass)
|
||||
}
|
||||
|
||||
next:
|
||||
hoplim := 255
|
||||
if err := c.SetHopLimit(hoplim); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v, err := c.HopLimit(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if v != hoplim {
|
||||
t.Fatalf("got %v; want %v", v, hoplim)
|
||||
}
|
||||
}
|
||||
55
vendor/golang.org/x/net/proxy/per_host_test.go
generated
vendored
55
vendor/golang.org/x/net/proxy/per_host_test.go
generated
vendored
@@ -1,55 +0,0 @@
|
||||
// Copyright 2011 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 proxy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type recordingProxy struct {
|
||||
addrs []string
|
||||
}
|
||||
|
||||
func (r *recordingProxy) Dial(network, addr string) (net.Conn, error) {
|
||||
r.addrs = append(r.addrs, addr)
|
||||
return nil, errors.New("recordingProxy")
|
||||
}
|
||||
|
||||
func TestPerHost(t *testing.T) {
|
||||
var def, bypass recordingProxy
|
||||
perHost := NewPerHost(&def, &bypass)
|
||||
perHost.AddFromString("localhost,*.zone,127.0.0.1,10.0.0.1/8,1000::/16")
|
||||
|
||||
expectedDef := []string{
|
||||
"example.com:123",
|
||||
"1.2.3.4:123",
|
||||
"[1001::]:123",
|
||||
}
|
||||
expectedBypass := []string{
|
||||
"localhost:123",
|
||||
"zone:123",
|
||||
"foo.zone:123",
|
||||
"127.0.0.1:123",
|
||||
"10.1.2.3:123",
|
||||
"[1000::]:123",
|
||||
}
|
||||
|
||||
for _, addr := range expectedDef {
|
||||
perHost.Dial("tcp", addr)
|
||||
}
|
||||
for _, addr := range expectedBypass {
|
||||
perHost.Dial("tcp", addr)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedDef, def.addrs) {
|
||||
t.Errorf("Hosts which went to the default proxy didn't match. Got %v, want %v", def.addrs, expectedDef)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedBypass, bypass.addrs) {
|
||||
t.Errorf("Hosts which went to the bypass proxy didn't match. Got %v, want %v", bypass.addrs, expectedBypass)
|
||||
}
|
||||
}
|
||||
142
vendor/golang.org/x/net/proxy/proxy_test.go
generated
vendored
142
vendor/golang.org/x/net/proxy/proxy_test.go
generated
vendored
@@ -1,142 +0,0 @@
|
||||
// Copyright 2011 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 proxy
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFromURL(t *testing.T) {
|
||||
endSystem, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("net.Listen failed: %v", err)
|
||||
}
|
||||
defer endSystem.Close()
|
||||
gateway, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("net.Listen failed: %v", err)
|
||||
}
|
||||
defer gateway.Close()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go socks5Gateway(t, gateway, endSystem, socks5Domain, &wg)
|
||||
|
||||
url, err := url.Parse("socks5://user:password@" + gateway.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatalf("url.Parse failed: %v", err)
|
||||
}
|
||||
proxy, err := FromURL(url, Direct)
|
||||
if err != nil {
|
||||
t.Fatalf("FromURL failed: %v", err)
|
||||
}
|
||||
_, port, err := net.SplitHostPort(endSystem.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatalf("net.SplitHostPort failed: %v", err)
|
||||
}
|
||||
if c, err := proxy.Dial("tcp", "localhost:"+port); err != nil {
|
||||
t.Fatalf("FromURL.Dial failed: %v", err)
|
||||
} else {
|
||||
c.Close()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestSOCKS5(t *testing.T) {
|
||||
endSystem, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("net.Listen failed: %v", err)
|
||||
}
|
||||
defer endSystem.Close()
|
||||
gateway, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("net.Listen failed: %v", err)
|
||||
}
|
||||
defer gateway.Close()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go socks5Gateway(t, gateway, endSystem, socks5IP4, &wg)
|
||||
|
||||
proxy, err := SOCKS5("tcp", gateway.Addr().String(), nil, Direct)
|
||||
if err != nil {
|
||||
t.Fatalf("SOCKS5 failed: %v", err)
|
||||
}
|
||||
if c, err := proxy.Dial("tcp", endSystem.Addr().String()); err != nil {
|
||||
t.Fatalf("SOCKS5.Dial failed: %v", err)
|
||||
} else {
|
||||
c.Close()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func socks5Gateway(t *testing.T, gateway, endSystem net.Listener, typ byte, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
c, err := gateway.Accept()
|
||||
if err != nil {
|
||||
t.Errorf("net.Listener.Accept failed: %v", err)
|
||||
return
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
b := make([]byte, 32)
|
||||
var n int
|
||||
if typ == socks5Domain {
|
||||
n = 4
|
||||
} else {
|
||||
n = 3
|
||||
}
|
||||
if _, err := io.ReadFull(c, b[:n]); err != nil {
|
||||
t.Errorf("io.ReadFull failed: %v", err)
|
||||
return
|
||||
}
|
||||
if _, err := c.Write([]byte{socks5Version, socks5AuthNone}); err != nil {
|
||||
t.Errorf("net.Conn.Write failed: %v", err)
|
||||
return
|
||||
}
|
||||
if typ == socks5Domain {
|
||||
n = 16
|
||||
} else {
|
||||
n = 10
|
||||
}
|
||||
if _, err := io.ReadFull(c, b[:n]); err != nil {
|
||||
t.Errorf("io.ReadFull failed: %v", err)
|
||||
return
|
||||
}
|
||||
if b[0] != socks5Version || b[1] != socks5Connect || b[2] != 0x00 || b[3] != typ {
|
||||
t.Errorf("got an unexpected packet: %#02x %#02x %#02x %#02x", b[0], b[1], b[2], b[3])
|
||||
return
|
||||
}
|
||||
if typ == socks5Domain {
|
||||
copy(b[:5], []byte{socks5Version, 0x00, 0x00, socks5Domain, 9})
|
||||
b = append(b, []byte("localhost")...)
|
||||
} else {
|
||||
copy(b[:4], []byte{socks5Version, 0x00, 0x00, socks5IP4})
|
||||
}
|
||||
host, port, err := net.SplitHostPort(endSystem.Addr().String())
|
||||
if err != nil {
|
||||
t.Errorf("net.SplitHostPort failed: %v", err)
|
||||
return
|
||||
}
|
||||
b = append(b, []byte(net.ParseIP(host).To4())...)
|
||||
p, err := strconv.Atoi(port)
|
||||
if err != nil {
|
||||
t.Errorf("strconv.Atoi failed: %v", err)
|
||||
return
|
||||
}
|
||||
b = append(b, []byte{byte(p >> 8), byte(p)}...)
|
||||
if _, err := c.Write(b); err != nil {
|
||||
t.Errorf("net.Conn.Write failed: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
59
vendor/golang.org/x/net/proxy/socks5.go
generated
vendored
59
vendor/golang.org/x/net/proxy/socks5.go
generated
vendored
@@ -72,24 +72,28 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
closeConn := &conn
|
||||
defer func() {
|
||||
if closeConn != nil {
|
||||
(*closeConn).Close()
|
||||
}
|
||||
}()
|
||||
|
||||
host, portStr, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
if err := s.connect(conn, addr); err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// connect takes an existing connection to a socks5 proxy server,
|
||||
// and commands the server to extend that connection to target,
|
||||
// which must be a canonical address with a host and port.
|
||||
func (s *socks5) connect(conn net.Conn, target string) error {
|
||||
host, portStr, err := net.SplitHostPort(target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
port, err := strconv.Atoi(portStr)
|
||||
if err != nil {
|
||||
return nil, errors.New("proxy: failed to parse port number: " + portStr)
|
||||
return errors.New("proxy: failed to parse port number: " + portStr)
|
||||
}
|
||||
if port < 1 || port > 0xffff {
|
||||
return nil, errors.New("proxy: port number out of range: " + portStr)
|
||||
return errors.New("proxy: port number out of range: " + portStr)
|
||||
}
|
||||
|
||||
// the size here is just an estimate
|
||||
@@ -103,17 +107,17 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
}
|
||||
|
||||
if _, err := conn.Write(buf); err != nil {
|
||||
return nil, errors.New("proxy: failed to write greeting to SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to write greeting to SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
|
||||
if _, err := io.ReadFull(conn, buf[:2]); err != nil {
|
||||
return nil, errors.New("proxy: failed to read greeting from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to read greeting from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
if buf[0] != 5 {
|
||||
return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " has unexpected version " + strconv.Itoa(int(buf[0])))
|
||||
return errors.New("proxy: SOCKS5 proxy at " + s.addr + " has unexpected version " + strconv.Itoa(int(buf[0])))
|
||||
}
|
||||
if buf[1] == 0xff {
|
||||
return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " requires authentication")
|
||||
return errors.New("proxy: SOCKS5 proxy at " + s.addr + " requires authentication")
|
||||
}
|
||||
|
||||
if buf[1] == socks5AuthPassword {
|
||||
@@ -125,15 +129,15 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
buf = append(buf, s.password...)
|
||||
|
||||
if _, err := conn.Write(buf); err != nil {
|
||||
return nil, errors.New("proxy: failed to write authentication request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to write authentication request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
|
||||
if _, err := io.ReadFull(conn, buf[:2]); err != nil {
|
||||
return nil, errors.New("proxy: failed to read authentication reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to read authentication reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
|
||||
if buf[1] != 0 {
|
||||
return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " rejected username/password")
|
||||
return errors.New("proxy: SOCKS5 proxy at " + s.addr + " rejected username/password")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +154,7 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
buf = append(buf, ip...)
|
||||
} else {
|
||||
if len(host) > 255 {
|
||||
return nil, errors.New("proxy: destination hostname too long: " + host)
|
||||
return errors.New("proxy: destination hostname too long: " + host)
|
||||
}
|
||||
buf = append(buf, socks5Domain)
|
||||
buf = append(buf, byte(len(host)))
|
||||
@@ -159,11 +163,11 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
buf = append(buf, byte(port>>8), byte(port))
|
||||
|
||||
if _, err := conn.Write(buf); err != nil {
|
||||
return nil, errors.New("proxy: failed to write connect request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to write connect request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
|
||||
if _, err := io.ReadFull(conn, buf[:4]); err != nil {
|
||||
return nil, errors.New("proxy: failed to read connect reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to read connect reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
|
||||
failure := "unknown error"
|
||||
@@ -172,7 +176,7 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
}
|
||||
|
||||
if len(failure) > 0 {
|
||||
return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " failed to connect: " + failure)
|
||||
return errors.New("proxy: SOCKS5 proxy at " + s.addr + " failed to connect: " + failure)
|
||||
}
|
||||
|
||||
bytesToDiscard := 0
|
||||
@@ -184,11 +188,11 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
case socks5Domain:
|
||||
_, err := io.ReadFull(conn, buf[:1])
|
||||
if err != nil {
|
||||
return nil, errors.New("proxy: failed to read domain length from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to read domain length from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
bytesToDiscard = int(buf[0])
|
||||
default:
|
||||
return nil, errors.New("proxy: got unknown address type " + strconv.Itoa(int(buf[3])) + " from SOCKS5 proxy at " + s.addr)
|
||||
return errors.New("proxy: got unknown address type " + strconv.Itoa(int(buf[3])) + " from SOCKS5 proxy at " + s.addr)
|
||||
}
|
||||
|
||||
if cap(buf) < bytesToDiscard {
|
||||
@@ -197,14 +201,13 @@ func (s *socks5) Dial(network, addr string) (net.Conn, error) {
|
||||
buf = buf[:bytesToDiscard]
|
||||
}
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return nil, errors.New("proxy: failed to read address from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to read address from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
|
||||
// Also need to discard the port number
|
||||
if _, err := io.ReadFull(conn, buf[:2]); err != nil {
|
||||
return nil, errors.New("proxy: failed to read port from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
return errors.New("proxy: failed to read port from SOCKS5 proxy at " + s.addr + ": " + err.Error())
|
||||
}
|
||||
|
||||
closeConn = nil
|
||||
return conn, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
27
vendor/golang.org/x/net/route/LICENSE
generated
vendored
27
vendor/golang.org/x/net/route/LICENSE
generated
vendored
@@ -1,27 +0,0 @@
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
281
vendor/golang.org/x/net/route/address.go
generated
vendored
281
vendor/golang.org/x/net/route/address.go
generated
vendored
@@ -1,281 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package route
|
||||
|
||||
import "runtime"
|
||||
|
||||
// An Addr represents an address associated with packet routing.
|
||||
type Addr interface {
|
||||
// Family returns an address family.
|
||||
Family() int
|
||||
}
|
||||
|
||||
// A LinkAddr represents a link-layer address.
|
||||
type LinkAddr struct {
|
||||
Index int // interface index when attached
|
||||
Name string // interface name when attached
|
||||
Addr []byte // link-layer address when attached
|
||||
}
|
||||
|
||||
// Family implements the Family method of Addr interface.
|
||||
func (a *LinkAddr) Family() int { return sysAF_LINK }
|
||||
|
||||
func parseLinkAddr(b []byte) (Addr, error) {
|
||||
if len(b) < 8 {
|
||||
return nil, errInvalidAddr
|
||||
}
|
||||
_, a, err := parseKernelLinkAddr(sysAF_LINK, b[4:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.(*LinkAddr).Index = int(nativeEndian.Uint16(b[2:4]))
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// parseKernelLinkAddr parses b as a link-layer address in
|
||||
// conventional BSD kernel form.
|
||||
func parseKernelLinkAddr(_ int, b []byte) (int, Addr, error) {
|
||||
// The encoding looks like the following:
|
||||
// +----------------------------+
|
||||
// | Type (1 octet) |
|
||||
// +----------------------------+
|
||||
// | Name length (1 octet) |
|
||||
// +----------------------------+
|
||||
// | Address length (1 octet) |
|
||||
// +----------------------------+
|
||||
// | Selector length (1 octet) |
|
||||
// +----------------------------+
|
||||
// | Data (variable) |
|
||||
// +----------------------------+
|
||||
//
|
||||
// On some platforms, all-bit-one of length field means "don't
|
||||
// care".
|
||||
nlen, alen, slen := int(b[1]), int(b[2]), int(b[3])
|
||||
if nlen == 0xff {
|
||||
nlen = 0
|
||||
}
|
||||
if alen == 0xff {
|
||||
alen = 0
|
||||
}
|
||||
if slen == 0xff {
|
||||
slen = 0
|
||||
}
|
||||
l := 4 + nlen + alen + slen
|
||||
if len(b) < l {
|
||||
return 0, nil, errInvalidAddr
|
||||
}
|
||||
data := b[4:]
|
||||
var name string
|
||||
var addr []byte
|
||||
if nlen > 0 {
|
||||
name = string(data[:nlen])
|
||||
data = data[nlen:]
|
||||
}
|
||||
if alen > 0 {
|
||||
addr = data[:alen]
|
||||
data = data[alen:]
|
||||
}
|
||||
return l, &LinkAddr{Name: name, Addr: addr}, nil
|
||||
}
|
||||
|
||||
// An Inet4Addr represents an internet address for IPv4.
|
||||
type Inet4Addr struct {
|
||||
IP [4]byte // IP address
|
||||
}
|
||||
|
||||
// Family implements the Family method of Addr interface.
|
||||
func (a *Inet4Addr) Family() int { return sysAF_INET }
|
||||
|
||||
// An Inet6Addr represents an internet address for IPv6.
|
||||
type Inet6Addr struct {
|
||||
IP [16]byte // IP address
|
||||
ZoneID int // zone identifier
|
||||
}
|
||||
|
||||
// Family implements the Family method of Addr interface.
|
||||
func (a *Inet6Addr) Family() int { return sysAF_INET6 }
|
||||
|
||||
// parseInetAddr parses b as an internet address for IPv4 or IPv6.
|
||||
func parseInetAddr(af int, b []byte) (Addr, error) {
|
||||
switch af {
|
||||
case sysAF_INET:
|
||||
if len(b) < 16 {
|
||||
return nil, errInvalidAddr
|
||||
}
|
||||
a := &Inet4Addr{}
|
||||
copy(a.IP[:], b[4:8])
|
||||
return a, nil
|
||||
case sysAF_INET6:
|
||||
if len(b) < 28 {
|
||||
return nil, errInvalidAddr
|
||||
}
|
||||
a := &Inet6Addr{ZoneID: int(nativeEndian.Uint32(b[24:28]))}
|
||||
copy(a.IP[:], b[8:24])
|
||||
if a.IP[0] == 0xfe && a.IP[1]&0xc0 == 0x80 || a.IP[0] == 0xff && (a.IP[1]&0x0f == 0x01 || a.IP[1]&0x0f == 0x02) {
|
||||
// KAME based IPv6 protocol stack usually
|
||||
// embeds the interface index in the
|
||||
// interface-local or link-local address as
|
||||
// the kernel-internal form.
|
||||
id := int(bigEndian.Uint16(a.IP[2:4]))
|
||||
if id != 0 {
|
||||
a.ZoneID = id
|
||||
a.IP[2], a.IP[3] = 0, 0
|
||||
}
|
||||
}
|
||||
return a, nil
|
||||
default:
|
||||
return nil, errInvalidAddr
|
||||
}
|
||||
}
|
||||
|
||||
// parseKernelInetAddr parses b as an internet address in conventional
|
||||
// BSD kernel form.
|
||||
func parseKernelInetAddr(af int, b []byte) (int, Addr, error) {
|
||||
// The encoding looks similar to the NLRI encoding.
|
||||
// +----------------------------+
|
||||
// | Length (1 octet) |
|
||||
// +----------------------------+
|
||||
// | Address prefix (variable) |
|
||||
// +----------------------------+
|
||||
//
|
||||
// The differences between the kernel form and the NLRI
|
||||
// encoding are:
|
||||
//
|
||||
// - The length field of the kernel form indicates the prefix
|
||||
// length in bytes, not in bits
|
||||
//
|
||||
// - In the kernel form, zero value of the length field
|
||||
// doesn't mean 0.0.0.0/0 or ::/0
|
||||
//
|
||||
// - The kernel form appends leading bytes to the prefix field
|
||||
// to make the <length, prefix> tuple to be conformed with
|
||||
// the routing message boundary
|
||||
l := int(b[0])
|
||||
if runtime.GOOS == "darwin" {
|
||||
// On Darwn, an address in the kernel form is also
|
||||
// used as a message filler.
|
||||
if l == 0 || len(b) > roundup(l) {
|
||||
l = roundup(l)
|
||||
}
|
||||
} else {
|
||||
l = roundup(l)
|
||||
}
|
||||
if len(b) < l {
|
||||
return 0, nil, errInvalidAddr
|
||||
}
|
||||
// Don't reorder case expressions.
|
||||
// The case expressions for IPv6 must come first.
|
||||
const (
|
||||
off4 = 4 // offset of in_addr
|
||||
off6 = 8 // offset of in6_addr
|
||||
)
|
||||
switch {
|
||||
case b[0] == 28: // size of sockaddr_in6
|
||||
a := &Inet6Addr{}
|
||||
copy(a.IP[:], b[off6:off6+16])
|
||||
return int(b[0]), a, nil
|
||||
case af == sysAF_INET6:
|
||||
a := &Inet6Addr{}
|
||||
if l-1 < off6 {
|
||||
copy(a.IP[:], b[1:l])
|
||||
} else {
|
||||
copy(a.IP[:], b[l-off6:l])
|
||||
}
|
||||
return int(b[0]), a, nil
|
||||
case b[0] == 16: // size of sockaddr_in
|
||||
a := &Inet4Addr{}
|
||||
copy(a.IP[:], b[off4:off4+4])
|
||||
return int(b[0]), a, nil
|
||||
default: // an old fashion, AF_UNSPEC or unknown means AF_INET
|
||||
a := &Inet4Addr{}
|
||||
if l-1 < off4 {
|
||||
copy(a.IP[:], b[1:l])
|
||||
} else {
|
||||
copy(a.IP[:], b[l-off4:l])
|
||||
}
|
||||
return int(b[0]), a, nil
|
||||
}
|
||||
}
|
||||
|
||||
// A DefaultAddr represents an address of various operating
|
||||
// system-specific features.
|
||||
type DefaultAddr struct {
|
||||
af int
|
||||
Raw []byte // raw format of address
|
||||
}
|
||||
|
||||
// Family implements the Family method of Addr interface.
|
||||
func (a *DefaultAddr) Family() int { return a.af }
|
||||
|
||||
func parseDefaultAddr(b []byte) (Addr, error) {
|
||||
if len(b) < 2 || len(b) < int(b[0]) {
|
||||
return nil, errInvalidAddr
|
||||
}
|
||||
a := &DefaultAddr{af: int(b[1]), Raw: b[:b[0]]}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func parseAddrs(attrs uint, fn func(int, []byte) (int, Addr, error), b []byte) ([]Addr, error) {
|
||||
var as [sysRTAX_MAX]Addr
|
||||
af := int(sysAF_UNSPEC)
|
||||
for i := uint(0); i < sysRTAX_MAX && len(b) >= roundup(0); i++ {
|
||||
if attrs&(1<<i) == 0 {
|
||||
continue
|
||||
}
|
||||
if i <= sysRTAX_BRD {
|
||||
switch b[1] {
|
||||
case sysAF_LINK:
|
||||
a, err := parseLinkAddr(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
as[i] = a
|
||||
l := roundup(int(b[0]))
|
||||
if len(b) < l {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
b = b[l:]
|
||||
case sysAF_INET, sysAF_INET6:
|
||||
af = int(b[1])
|
||||
a, err := parseInetAddr(af, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
as[i] = a
|
||||
l := roundup(int(b[0]))
|
||||
if len(b) < l {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
b = b[l:]
|
||||
default:
|
||||
l, a, err := fn(af, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
as[i] = a
|
||||
ll := roundup(l)
|
||||
if len(b) < ll {
|
||||
b = b[l:]
|
||||
} else {
|
||||
b = b[ll:]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
a, err := parseDefaultAddr(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
as[i] = a
|
||||
l := roundup(int(b[0]))
|
||||
if len(b) < l {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
b = b[l:]
|
||||
}
|
||||
}
|
||||
return as[:], nil
|
||||
}
|
||||
90
vendor/golang.org/x/net/route/binary.go
generated
vendored
90
vendor/golang.org/x/net/route/binary.go
generated
vendored
@@ -1,90 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package route
|
||||
|
||||
// This file contains duplicates of encoding/binary package.
|
||||
//
|
||||
// This package is supposed to be used by the net package of standard
|
||||
// library. Therefore a package set used in the package must be the
|
||||
// same as net package.
|
||||
|
||||
var (
|
||||
littleEndian binaryLittleEndian
|
||||
bigEndian binaryBigEndian
|
||||
)
|
||||
|
||||
type binaryByteOrder interface {
|
||||
Uint16([]byte) uint16
|
||||
Uint32([]byte) uint32
|
||||
PutUint16([]byte, uint16)
|
||||
PutUint32([]byte, uint32)
|
||||
Uint64([]byte) uint64
|
||||
}
|
||||
|
||||
type binaryLittleEndian struct{}
|
||||
|
||||
func (binaryLittleEndian) Uint16(b []byte) uint16 {
|
||||
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint16(b[0]) | uint16(b[1])<<8
|
||||
}
|
||||
|
||||
func (binaryLittleEndian) PutUint16(b []byte, v uint16) {
|
||||
_ = b[1] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v)
|
||||
b[1] = byte(v >> 8)
|
||||
}
|
||||
|
||||
func (binaryLittleEndian) Uint32(b []byte) uint32 {
|
||||
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
|
||||
}
|
||||
|
||||
func (binaryLittleEndian) PutUint32(b []byte, v uint32) {
|
||||
_ = b[3] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v)
|
||||
b[1] = byte(v >> 8)
|
||||
b[2] = byte(v >> 16)
|
||||
b[3] = byte(v >> 24)
|
||||
}
|
||||
|
||||
func (binaryLittleEndian) Uint64(b []byte) uint64 {
|
||||
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
|
||||
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
|
||||
}
|
||||
|
||||
type binaryBigEndian struct{}
|
||||
|
||||
func (binaryBigEndian) Uint16(b []byte) uint16 {
|
||||
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint16(b[1]) | uint16(b[0])<<8
|
||||
}
|
||||
|
||||
func (binaryBigEndian) PutUint16(b []byte, v uint16) {
|
||||
_ = b[1] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v >> 8)
|
||||
b[1] = byte(v)
|
||||
}
|
||||
|
||||
func (binaryBigEndian) Uint32(b []byte) uint32 {
|
||||
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
|
||||
}
|
||||
|
||||
func (binaryBigEndian) PutUint32(b []byte, v uint32) {
|
||||
_ = b[3] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v >> 24)
|
||||
b[1] = byte(v >> 16)
|
||||
b[2] = byte(v >> 8)
|
||||
b[3] = byte(v)
|
||||
}
|
||||
|
||||
func (binaryBigEndian) Uint64(b []byte) uint64 {
|
||||
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
|
||||
uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
|
||||
}
|
||||
106
vendor/golang.org/x/net/route/defs_darwin.go
generated
vendored
106
vendor/golang.org/x/net/route/defs_darwin.go
generated
vendored
@@ -1,106 +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.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package route
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_ROUTE = C.AF_ROUTE
|
||||
sysAF_LINK = C.AF_LINK
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysNET_RT_DUMP = C.NET_RT_DUMP
|
||||
sysNET_RT_FLAGS = C.NET_RT_FLAGS
|
||||
sysNET_RT_IFLIST = C.NET_RT_IFLIST
|
||||
sysNET_RT_STAT = C.NET_RT_STAT
|
||||
sysNET_RT_TRASH = C.NET_RT_TRASH
|
||||
sysNET_RT_IFLIST2 = C.NET_RT_IFLIST2
|
||||
sysNET_RT_DUMP2 = C.NET_RT_DUMP2
|
||||
sysNET_RT_MAXID = C.NET_RT_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = C.CTL_MAXNAME
|
||||
|
||||
sysCTL_UNSPEC = C.CTL_UNSPEC
|
||||
sysCTL_KERN = C.CTL_KERN
|
||||
sysCTL_VM = C.CTL_VM
|
||||
sysCTL_VFS = C.CTL_VFS
|
||||
sysCTL_NET = C.CTL_NET
|
||||
sysCTL_DEBUG = C.CTL_DEBUG
|
||||
sysCTL_HW = C.CTL_HW
|
||||
sysCTL_MACHDEP = C.CTL_MACHDEP
|
||||
sysCTL_USER = C.CTL_USER
|
||||
sysCTL_MAXID = C.CTL_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = C.RTM_VERSION
|
||||
|
||||
sysRTM_ADD = C.RTM_ADD
|
||||
sysRTM_DELETE = C.RTM_DELETE
|
||||
sysRTM_CHANGE = C.RTM_CHANGE
|
||||
sysRTM_GET = C.RTM_GET
|
||||
sysRTM_LOSING = C.RTM_LOSING
|
||||
sysRTM_REDIRECT = C.RTM_REDIRECT
|
||||
sysRTM_MISS = C.RTM_MISS
|
||||
sysRTM_LOCK = C.RTM_LOCK
|
||||
sysRTM_OLDADD = C.RTM_OLDADD
|
||||
sysRTM_OLDDEL = C.RTM_OLDDEL
|
||||
sysRTM_RESOLVE = C.RTM_RESOLVE
|
||||
sysRTM_NEWADDR = C.RTM_NEWADDR
|
||||
sysRTM_DELADDR = C.RTM_DELADDR
|
||||
sysRTM_IFINFO = C.RTM_IFINFO
|
||||
sysRTM_NEWMADDR = C.RTM_NEWMADDR
|
||||
sysRTM_DELMADDR = C.RTM_DELMADDR
|
||||
sysRTM_IFINFO2 = C.RTM_IFINFO2
|
||||
sysRTM_NEWMADDR2 = C.RTM_NEWMADDR2
|
||||
sysRTM_GET2 = C.RTM_GET2
|
||||
|
||||
sysRTA_DST = C.RTA_DST
|
||||
sysRTA_GATEWAY = C.RTA_GATEWAY
|
||||
sysRTA_NETMASK = C.RTA_NETMASK
|
||||
sysRTA_GENMASK = C.RTA_GENMASK
|
||||
sysRTA_IFP = C.RTA_IFP
|
||||
sysRTA_IFA = C.RTA_IFA
|
||||
sysRTA_AUTHOR = C.RTA_AUTHOR
|
||||
sysRTA_BRD = C.RTA_BRD
|
||||
|
||||
sysRTAX_DST = C.RTAX_DST
|
||||
sysRTAX_GATEWAY = C.RTAX_GATEWAY
|
||||
sysRTAX_NETMASK = C.RTAX_NETMASK
|
||||
sysRTAX_GENMASK = C.RTAX_GENMASK
|
||||
sysRTAX_IFP = C.RTAX_IFP
|
||||
sysRTAX_IFA = C.RTAX_IFA
|
||||
sysRTAX_AUTHOR = C.RTAX_AUTHOR
|
||||
sysRTAX_BRD = C.RTAX_BRD
|
||||
sysRTAX_MAX = C.RTAX_MAX
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrDarwin15 = C.sizeof_struct_if_msghdr
|
||||
sizeofIfaMsghdrDarwin15 = C.sizeof_struct_ifa_msghdr
|
||||
sizeofIfmaMsghdrDarwin15 = C.sizeof_struct_ifma_msghdr
|
||||
sizeofIfMsghdr2Darwin15 = C.sizeof_struct_if_msghdr2
|
||||
sizeofIfmaMsghdr2Darwin15 = C.sizeof_struct_ifma_msghdr2
|
||||
sizeofIfDataDarwin15 = C.sizeof_struct_if_data
|
||||
sizeofIfData64Darwin15 = C.sizeof_struct_if_data64
|
||||
|
||||
sizeofRtMsghdrDarwin15 = C.sizeof_struct_rt_msghdr
|
||||
sizeofRtMsghdr2Darwin15 = C.sizeof_struct_rt_msghdr2
|
||||
sizeofRtMetricsDarwin15 = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
105
vendor/golang.org/x/net/route/defs_dragonfly.go
generated
vendored
105
vendor/golang.org/x/net/route/defs_dragonfly.go
generated
vendored
@@ -1,105 +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.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package route
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_ROUTE = C.AF_ROUTE
|
||||
sysAF_LINK = C.AF_LINK
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysNET_RT_DUMP = C.NET_RT_DUMP
|
||||
sysNET_RT_FLAGS = C.NET_RT_FLAGS
|
||||
sysNET_RT_IFLIST = C.NET_RT_IFLIST
|
||||
sysNET_RT_MAXID = C.NET_RT_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = C.CTL_MAXNAME
|
||||
|
||||
sysCTL_UNSPEC = C.CTL_UNSPEC
|
||||
sysCTL_KERN = C.CTL_KERN
|
||||
sysCTL_VM = C.CTL_VM
|
||||
sysCTL_VFS = C.CTL_VFS
|
||||
sysCTL_NET = C.CTL_NET
|
||||
sysCTL_DEBUG = C.CTL_DEBUG
|
||||
sysCTL_HW = C.CTL_HW
|
||||
sysCTL_MACHDEP = C.CTL_MACHDEP
|
||||
sysCTL_USER = C.CTL_USER
|
||||
sysCTL_P1003_1B = C.CTL_P1003_1B
|
||||
sysCTL_LWKT = C.CTL_LWKT
|
||||
sysCTL_MAXID = C.CTL_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = C.RTM_VERSION
|
||||
|
||||
sysRTM_ADD = C.RTM_ADD
|
||||
sysRTM_DELETE = C.RTM_DELETE
|
||||
sysRTM_CHANGE = C.RTM_CHANGE
|
||||
sysRTM_GET = C.RTM_GET
|
||||
sysRTM_LOSING = C.RTM_LOSING
|
||||
sysRTM_REDIRECT = C.RTM_REDIRECT
|
||||
sysRTM_MISS = C.RTM_MISS
|
||||
sysRTM_LOCK = C.RTM_LOCK
|
||||
sysRTM_OLDADD = C.RTM_OLDADD
|
||||
sysRTM_OLDDEL = C.RTM_OLDDEL
|
||||
sysRTM_RESOLVE = C.RTM_RESOLVE
|
||||
sysRTM_NEWADDR = C.RTM_NEWADDR
|
||||
sysRTM_DELADDR = C.RTM_DELADDR
|
||||
sysRTM_IFINFO = C.RTM_IFINFO
|
||||
sysRTM_NEWMADDR = C.RTM_NEWMADDR
|
||||
sysRTM_DELMADDR = C.RTM_DELMADDR
|
||||
sysRTM_IFANNOUNCE = C.RTM_IFANNOUNCE
|
||||
sysRTM_IEEE80211 = C.RTM_IEEE80211
|
||||
|
||||
sysRTA_DST = C.RTA_DST
|
||||
sysRTA_GATEWAY = C.RTA_GATEWAY
|
||||
sysRTA_NETMASK = C.RTA_NETMASK
|
||||
sysRTA_GENMASK = C.RTA_GENMASK
|
||||
sysRTA_IFP = C.RTA_IFP
|
||||
sysRTA_IFA = C.RTA_IFA
|
||||
sysRTA_AUTHOR = C.RTA_AUTHOR
|
||||
sysRTA_BRD = C.RTA_BRD
|
||||
sysRTA_MPLS1 = C.RTA_MPLS1
|
||||
sysRTA_MPLS2 = C.RTA_MPLS2
|
||||
sysRTA_MPLS3 = C.RTA_MPLS3
|
||||
|
||||
sysRTAX_DST = C.RTAX_DST
|
||||
sysRTAX_GATEWAY = C.RTAX_GATEWAY
|
||||
sysRTAX_NETMASK = C.RTAX_NETMASK
|
||||
sysRTAX_GENMASK = C.RTAX_GENMASK
|
||||
sysRTAX_IFP = C.RTAX_IFP
|
||||
sysRTAX_IFA = C.RTAX_IFA
|
||||
sysRTAX_AUTHOR = C.RTAX_AUTHOR
|
||||
sysRTAX_BRD = C.RTAX_BRD
|
||||
sysRTAX_MPLS1 = C.RTAX_MPLS1
|
||||
sysRTAX_MPLS2 = C.RTAX_MPLS2
|
||||
sysRTAX_MPLS3 = C.RTAX_MPLS3
|
||||
sysRTAX_MAX = C.RTAX_MAX
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrDragonFlyBSD4 = C.sizeof_struct_if_msghdr
|
||||
sizeofIfaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifa_msghdr
|
||||
sizeofIfmaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifma_msghdr
|
||||
sizeofIfAnnouncemsghdrDragonFlyBSD4 = C.sizeof_struct_if_announcemsghdr
|
||||
|
||||
sizeofRtMsghdrDragonFlyBSD4 = C.sizeof_struct_rt_msghdr
|
||||
sizeofRtMetricsDragonFlyBSD4 = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
329
vendor/golang.org/x/net/route/defs_freebsd.go
generated
vendored
329
vendor/golang.org/x/net/route/defs_freebsd.go
generated
vendored
@@ -1,329 +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.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package route
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
|
||||
struct if_data_freebsd7 {
|
||||
u_char ifi_type;
|
||||
u_char ifi_physical;
|
||||
u_char ifi_addrlen;
|
||||
u_char ifi_hdrlen;
|
||||
u_char ifi_link_state;
|
||||
u_char ifi_spare_char1;
|
||||
u_char ifi_spare_char2;
|
||||
u_char ifi_datalen;
|
||||
u_long ifi_mtu;
|
||||
u_long ifi_metric;
|
||||
u_long ifi_baudrate;
|
||||
u_long ifi_ipackets;
|
||||
u_long ifi_ierrors;
|
||||
u_long ifi_opackets;
|
||||
u_long ifi_oerrors;
|
||||
u_long ifi_collisions;
|
||||
u_long ifi_ibytes;
|
||||
u_long ifi_obytes;
|
||||
u_long ifi_imcasts;
|
||||
u_long ifi_omcasts;
|
||||
u_long ifi_iqdrops;
|
||||
u_long ifi_noproto;
|
||||
u_long ifi_hwassist;
|
||||
time_t __ifi_epoch;
|
||||
struct timeval __ifi_lastchange;
|
||||
};
|
||||
|
||||
struct if_data_freebsd8 {
|
||||
u_char ifi_type;
|
||||
u_char ifi_physical;
|
||||
u_char ifi_addrlen;
|
||||
u_char ifi_hdrlen;
|
||||
u_char ifi_link_state;
|
||||
u_char ifi_spare_char1;
|
||||
u_char ifi_spare_char2;
|
||||
u_char ifi_datalen;
|
||||
u_long ifi_mtu;
|
||||
u_long ifi_metric;
|
||||
u_long ifi_baudrate;
|
||||
u_long ifi_ipackets;
|
||||
u_long ifi_ierrors;
|
||||
u_long ifi_opackets;
|
||||
u_long ifi_oerrors;
|
||||
u_long ifi_collisions;
|
||||
u_long ifi_ibytes;
|
||||
u_long ifi_obytes;
|
||||
u_long ifi_imcasts;
|
||||
u_long ifi_omcasts;
|
||||
u_long ifi_iqdrops;
|
||||
u_long ifi_noproto;
|
||||
u_long ifi_hwassist;
|
||||
time_t __ifi_epoch;
|
||||
struct timeval __ifi_lastchange;
|
||||
};
|
||||
|
||||
struct if_data_freebsd9 {
|
||||
u_char ifi_type;
|
||||
u_char ifi_physical;
|
||||
u_char ifi_addrlen;
|
||||
u_char ifi_hdrlen;
|
||||
u_char ifi_link_state;
|
||||
u_char ifi_spare_char1;
|
||||
u_char ifi_spare_char2;
|
||||
u_char ifi_datalen;
|
||||
u_long ifi_mtu;
|
||||
u_long ifi_metric;
|
||||
u_long ifi_baudrate;
|
||||
u_long ifi_ipackets;
|
||||
u_long ifi_ierrors;
|
||||
u_long ifi_opackets;
|
||||
u_long ifi_oerrors;
|
||||
u_long ifi_collisions;
|
||||
u_long ifi_ibytes;
|
||||
u_long ifi_obytes;
|
||||
u_long ifi_imcasts;
|
||||
u_long ifi_omcasts;
|
||||
u_long ifi_iqdrops;
|
||||
u_long ifi_noproto;
|
||||
u_long ifi_hwassist;
|
||||
time_t __ifi_epoch;
|
||||
struct timeval __ifi_lastchange;
|
||||
};
|
||||
|
||||
struct if_data_freebsd10 {
|
||||
u_char ifi_type;
|
||||
u_char ifi_physical;
|
||||
u_char ifi_addrlen;
|
||||
u_char ifi_hdrlen;
|
||||
u_char ifi_link_state;
|
||||
u_char ifi_vhid;
|
||||
u_char ifi_baudrate_pf;
|
||||
u_char ifi_datalen;
|
||||
u_long ifi_mtu;
|
||||
u_long ifi_metric;
|
||||
u_long ifi_baudrate;
|
||||
u_long ifi_ipackets;
|
||||
u_long ifi_ierrors;
|
||||
u_long ifi_opackets;
|
||||
u_long ifi_oerrors;
|
||||
u_long ifi_collisions;
|
||||
u_long ifi_ibytes;
|
||||
u_long ifi_obytes;
|
||||
u_long ifi_imcasts;
|
||||
u_long ifi_omcasts;
|
||||
u_long ifi_iqdrops;
|
||||
u_long ifi_noproto;
|
||||
uint64_t ifi_hwassist;
|
||||
time_t __ifi_epoch;
|
||||
struct timeval __ifi_lastchange;
|
||||
};
|
||||
|
||||
struct if_data_freebsd11 {
|
||||
uint8_t ifi_type;
|
||||
uint8_t ifi_physical;
|
||||
uint8_t ifi_addrlen;
|
||||
uint8_t ifi_hdrlen;
|
||||
uint8_t ifi_link_state;
|
||||
uint8_t ifi_vhid;
|
||||
uint16_t ifi_datalen;
|
||||
uint32_t ifi_mtu;
|
||||
uint32_t ifi_metric;
|
||||
uint64_t ifi_baudrate;
|
||||
uint64_t ifi_ipackets;
|
||||
uint64_t ifi_ierrors;
|
||||
uint64_t ifi_opackets;
|
||||
uint64_t ifi_oerrors;
|
||||
uint64_t ifi_collisions;
|
||||
uint64_t ifi_ibytes;
|
||||
uint64_t ifi_obytes;
|
||||
uint64_t ifi_imcasts;
|
||||
uint64_t ifi_omcasts;
|
||||
uint64_t ifi_iqdrops;
|
||||
uint64_t ifi_oqdrops;
|
||||
uint64_t ifi_noproto;
|
||||
uint64_t ifi_hwassist;
|
||||
union {
|
||||
time_t tt;
|
||||
uint64_t ph;
|
||||
} __ifi_epoch;
|
||||
union {
|
||||
struct timeval tv;
|
||||
struct {
|
||||
uint64_t ph1;
|
||||
uint64_t ph2;
|
||||
} ph;
|
||||
} __ifi_lastchange;
|
||||
};
|
||||
|
||||
struct if_msghdr_freebsd7 {
|
||||
u_short ifm_msglen;
|
||||
u_char ifm_version;
|
||||
u_char ifm_type;
|
||||
int ifm_addrs;
|
||||
int ifm_flags;
|
||||
u_short ifm_index;
|
||||
struct if_data_freebsd7 ifm_data;
|
||||
};
|
||||
|
||||
struct if_msghdr_freebsd8 {
|
||||
u_short ifm_msglen;
|
||||
u_char ifm_version;
|
||||
u_char ifm_type;
|
||||
int ifm_addrs;
|
||||
int ifm_flags;
|
||||
u_short ifm_index;
|
||||
struct if_data_freebsd8 ifm_data;
|
||||
};
|
||||
|
||||
struct if_msghdr_freebsd9 {
|
||||
u_short ifm_msglen;
|
||||
u_char ifm_version;
|
||||
u_char ifm_type;
|
||||
int ifm_addrs;
|
||||
int ifm_flags;
|
||||
u_short ifm_index;
|
||||
struct if_data_freebsd9 ifm_data;
|
||||
};
|
||||
|
||||
struct if_msghdr_freebsd10 {
|
||||
u_short ifm_msglen;
|
||||
u_char ifm_version;
|
||||
u_char ifm_type;
|
||||
int ifm_addrs;
|
||||
int ifm_flags;
|
||||
u_short ifm_index;
|
||||
struct if_data_freebsd10 ifm_data;
|
||||
};
|
||||
|
||||
struct if_msghdr_freebsd11 {
|
||||
u_short ifm_msglen;
|
||||
u_char ifm_version;
|
||||
u_char ifm_type;
|
||||
int ifm_addrs;
|
||||
int ifm_flags;
|
||||
u_short ifm_index;
|
||||
struct if_data_freebsd11 ifm_data;
|
||||
};
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_ROUTE = C.AF_ROUTE
|
||||
sysAF_LINK = C.AF_LINK
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysNET_RT_DUMP = C.NET_RT_DUMP
|
||||
sysNET_RT_FLAGS = C.NET_RT_FLAGS
|
||||
sysNET_RT_IFLIST = C.NET_RT_IFLIST
|
||||
sysNET_RT_IFMALIST = C.NET_RT_IFMALIST
|
||||
sysNET_RT_IFLISTL = C.NET_RT_IFLISTL
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = C.CTL_MAXNAME
|
||||
|
||||
sysCTL_UNSPEC = C.CTL_UNSPEC
|
||||
sysCTL_KERN = C.CTL_KERN
|
||||
sysCTL_VM = C.CTL_VM
|
||||
sysCTL_VFS = C.CTL_VFS
|
||||
sysCTL_NET = C.CTL_NET
|
||||
sysCTL_DEBUG = C.CTL_DEBUG
|
||||
sysCTL_HW = C.CTL_HW
|
||||
sysCTL_MACHDEP = C.CTL_MACHDEP
|
||||
sysCTL_USER = C.CTL_USER
|
||||
sysCTL_P1003_1B = C.CTL_P1003_1B
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = C.RTM_VERSION
|
||||
|
||||
sysRTM_ADD = C.RTM_ADD
|
||||
sysRTM_DELETE = C.RTM_DELETE
|
||||
sysRTM_CHANGE = C.RTM_CHANGE
|
||||
sysRTM_GET = C.RTM_GET
|
||||
sysRTM_LOSING = C.RTM_LOSING
|
||||
sysRTM_REDIRECT = C.RTM_REDIRECT
|
||||
sysRTM_MISS = C.RTM_MISS
|
||||
sysRTM_LOCK = C.RTM_LOCK
|
||||
sysRTM_RESOLVE = C.RTM_RESOLVE
|
||||
sysRTM_NEWADDR = C.RTM_NEWADDR
|
||||
sysRTM_DELADDR = C.RTM_DELADDR
|
||||
sysRTM_IFINFO = C.RTM_IFINFO
|
||||
sysRTM_NEWMADDR = C.RTM_NEWMADDR
|
||||
sysRTM_DELMADDR = C.RTM_DELMADDR
|
||||
sysRTM_IFANNOUNCE = C.RTM_IFANNOUNCE
|
||||
sysRTM_IEEE80211 = C.RTM_IEEE80211
|
||||
|
||||
sysRTA_DST = C.RTA_DST
|
||||
sysRTA_GATEWAY = C.RTA_GATEWAY
|
||||
sysRTA_NETMASK = C.RTA_NETMASK
|
||||
sysRTA_GENMASK = C.RTA_GENMASK
|
||||
sysRTA_IFP = C.RTA_IFP
|
||||
sysRTA_IFA = C.RTA_IFA
|
||||
sysRTA_AUTHOR = C.RTA_AUTHOR
|
||||
sysRTA_BRD = C.RTA_BRD
|
||||
|
||||
sysRTAX_DST = C.RTAX_DST
|
||||
sysRTAX_GATEWAY = C.RTAX_GATEWAY
|
||||
sysRTAX_NETMASK = C.RTAX_NETMASK
|
||||
sysRTAX_GENMASK = C.RTAX_GENMASK
|
||||
sysRTAX_IFP = C.RTAX_IFP
|
||||
sysRTAX_IFA = C.RTAX_IFA
|
||||
sysRTAX_AUTHOR = C.RTAX_AUTHOR
|
||||
sysRTAX_BRD = C.RTAX_BRD
|
||||
sysRTAX_MAX = C.RTAX_MAX
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrlFreeBSD10 = C.sizeof_struct_if_msghdrl
|
||||
sizeofIfaMsghdrFreeBSD10 = C.sizeof_struct_ifa_msghdr
|
||||
sizeofIfaMsghdrlFreeBSD10 = C.sizeof_struct_ifa_msghdrl
|
||||
sizeofIfmaMsghdrFreeBSD10 = C.sizeof_struct_ifma_msghdr
|
||||
sizeofIfAnnouncemsghdrFreeBSD10 = C.sizeof_struct_if_announcemsghdr
|
||||
|
||||
sizeofRtMsghdrFreeBSD10 = C.sizeof_struct_rt_msghdr
|
||||
sizeofRtMetricsFreeBSD10 = C.sizeof_struct_rt_metrics
|
||||
|
||||
sizeofIfMsghdrFreeBSD7 = C.sizeof_struct_if_msghdr_freebsd7
|
||||
sizeofIfMsghdrFreeBSD8 = C.sizeof_struct_if_msghdr_freebsd8
|
||||
sizeofIfMsghdrFreeBSD9 = C.sizeof_struct_if_msghdr_freebsd9
|
||||
sizeofIfMsghdrFreeBSD10 = C.sizeof_struct_if_msghdr_freebsd10
|
||||
sizeofIfMsghdrFreeBSD11 = C.sizeof_struct_if_msghdr_freebsd11
|
||||
|
||||
sizeofIfDataFreeBSD7 = C.sizeof_struct_if_data_freebsd7
|
||||
sizeofIfDataFreeBSD8 = C.sizeof_struct_if_data_freebsd8
|
||||
sizeofIfDataFreeBSD9 = C.sizeof_struct_if_data_freebsd9
|
||||
sizeofIfDataFreeBSD10 = C.sizeof_struct_if_data_freebsd10
|
||||
sizeofIfDataFreeBSD11 = C.sizeof_struct_if_data_freebsd11
|
||||
|
||||
sizeofIfMsghdrlFreeBSD10Emu = C.sizeof_struct_if_msghdrl
|
||||
sizeofIfaMsghdrFreeBSD10Emu = C.sizeof_struct_ifa_msghdr
|
||||
sizeofIfaMsghdrlFreeBSD10Emu = C.sizeof_struct_ifa_msghdrl
|
||||
sizeofIfmaMsghdrFreeBSD10Emu = C.sizeof_struct_ifma_msghdr
|
||||
sizeofIfAnnouncemsghdrFreeBSD10Emu = C.sizeof_struct_if_announcemsghdr
|
||||
|
||||
sizeofRtMsghdrFreeBSD10Emu = C.sizeof_struct_rt_msghdr
|
||||
sizeofRtMetricsFreeBSD10Emu = C.sizeof_struct_rt_metrics
|
||||
|
||||
sizeofIfMsghdrFreeBSD7Emu = C.sizeof_struct_if_msghdr_freebsd7
|
||||
sizeofIfMsghdrFreeBSD8Emu = C.sizeof_struct_if_msghdr_freebsd8
|
||||
sizeofIfMsghdrFreeBSD9Emu = C.sizeof_struct_if_msghdr_freebsd9
|
||||
sizeofIfMsghdrFreeBSD10Emu = C.sizeof_struct_if_msghdr_freebsd10
|
||||
sizeofIfMsghdrFreeBSD11Emu = C.sizeof_struct_if_msghdr_freebsd11
|
||||
|
||||
sizeofIfDataFreeBSD7Emu = C.sizeof_struct_if_data_freebsd7
|
||||
sizeofIfDataFreeBSD8Emu = C.sizeof_struct_if_data_freebsd8
|
||||
sizeofIfDataFreeBSD9Emu = C.sizeof_struct_if_data_freebsd9
|
||||
sizeofIfDataFreeBSD10Emu = C.sizeof_struct_if_data_freebsd10
|
||||
sizeofIfDataFreeBSD11Emu = C.sizeof_struct_if_data_freebsd11
|
||||
)
|
||||
104
vendor/golang.org/x/net/route/defs_netbsd.go
generated
vendored
104
vendor/golang.org/x/net/route/defs_netbsd.go
generated
vendored
@@ -1,104 +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.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package route
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_ROUTE = C.AF_ROUTE
|
||||
sysAF_LINK = C.AF_LINK
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysNET_RT_DUMP = C.NET_RT_DUMP
|
||||
sysNET_RT_FLAGS = C.NET_RT_FLAGS
|
||||
sysNET_RT_IFLIST = C.NET_RT_IFLIST
|
||||
sysNET_RT_MAXID = C.NET_RT_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = C.CTL_MAXNAME
|
||||
|
||||
sysCTL_UNSPEC = C.CTL_UNSPEC
|
||||
sysCTL_KERN = C.CTL_KERN
|
||||
sysCTL_VM = C.CTL_VM
|
||||
sysCTL_VFS = C.CTL_VFS
|
||||
sysCTL_NET = C.CTL_NET
|
||||
sysCTL_DEBUG = C.CTL_DEBUG
|
||||
sysCTL_HW = C.CTL_HW
|
||||
sysCTL_MACHDEP = C.CTL_MACHDEP
|
||||
sysCTL_USER = C.CTL_USER
|
||||
sysCTL_DDB = C.CTL_DDB
|
||||
sysCTL_PROC = C.CTL_PROC
|
||||
sysCTL_VENDOR = C.CTL_VENDOR
|
||||
sysCTL_EMUL = C.CTL_EMUL
|
||||
sysCTL_SECURITY = C.CTL_SECURITY
|
||||
sysCTL_MAXID = C.CTL_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = C.RTM_VERSION
|
||||
|
||||
sysRTM_ADD = C.RTM_ADD
|
||||
sysRTM_DELETE = C.RTM_DELETE
|
||||
sysRTM_CHANGE = C.RTM_CHANGE
|
||||
sysRTM_GET = C.RTM_GET
|
||||
sysRTM_LOSING = C.RTM_LOSING
|
||||
sysRTM_REDIRECT = C.RTM_REDIRECT
|
||||
sysRTM_MISS = C.RTM_MISS
|
||||
sysRTM_LOCK = C.RTM_LOCK
|
||||
sysRTM_OLDADD = C.RTM_OLDADD
|
||||
sysRTM_OLDDEL = C.RTM_OLDDEL
|
||||
sysRTM_RESOLVE = C.RTM_RESOLVE
|
||||
sysRTM_NEWADDR = C.RTM_NEWADDR
|
||||
sysRTM_DELADDR = C.RTM_DELADDR
|
||||
sysRTM_IFANNOUNCE = C.RTM_IFANNOUNCE
|
||||
sysRTM_IEEE80211 = C.RTM_IEEE80211
|
||||
sysRTM_SETGATE = C.RTM_SETGATE
|
||||
sysRTM_LLINFO_UPD = C.RTM_LLINFO_UPD
|
||||
sysRTM_IFINFO = C.RTM_IFINFO
|
||||
sysRTM_CHGADDR = C.RTM_CHGADDR
|
||||
|
||||
sysRTA_DST = C.RTA_DST
|
||||
sysRTA_GATEWAY = C.RTA_GATEWAY
|
||||
sysRTA_NETMASK = C.RTA_NETMASK
|
||||
sysRTA_GENMASK = C.RTA_GENMASK
|
||||
sysRTA_IFP = C.RTA_IFP
|
||||
sysRTA_IFA = C.RTA_IFA
|
||||
sysRTA_AUTHOR = C.RTA_AUTHOR
|
||||
sysRTA_BRD = C.RTA_BRD
|
||||
sysRTA_TAG = C.RTA_TAG
|
||||
|
||||
sysRTAX_DST = C.RTAX_DST
|
||||
sysRTAX_GATEWAY = C.RTAX_GATEWAY
|
||||
sysRTAX_NETMASK = C.RTAX_NETMASK
|
||||
sysRTAX_GENMASK = C.RTAX_GENMASK
|
||||
sysRTAX_IFP = C.RTAX_IFP
|
||||
sysRTAX_IFA = C.RTAX_IFA
|
||||
sysRTAX_AUTHOR = C.RTAX_AUTHOR
|
||||
sysRTAX_BRD = C.RTAX_BRD
|
||||
sysRTAX_TAG = C.RTAX_TAG
|
||||
sysRTAX_MAX = C.RTAX_MAX
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrNetBSD7 = C.sizeof_struct_if_msghdr
|
||||
sizeofIfaMsghdrNetBSD7 = C.sizeof_struct_ifa_msghdr
|
||||
sizeofIfAnnouncemsghdrNetBSD7 = C.sizeof_struct_if_announcemsghdr
|
||||
|
||||
sizeofRtMsghdrNetBSD7 = C.sizeof_struct_rt_msghdr
|
||||
sizeofRtMetricsNetBSD7 = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
93
vendor/golang.org/x/net/route/defs_openbsd.go
generated
vendored
93
vendor/golang.org/x/net/route/defs_openbsd.go
generated
vendored
@@ -1,93 +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.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package route
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_ROUTE = C.AF_ROUTE
|
||||
sysAF_LINK = C.AF_LINK
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysNET_RT_DUMP = C.NET_RT_DUMP
|
||||
sysNET_RT_FLAGS = C.NET_RT_FLAGS
|
||||
sysNET_RT_IFLIST = C.NET_RT_IFLIST
|
||||
sysNET_RT_STATS = C.NET_RT_STATS
|
||||
sysNET_RT_TABLE = C.NET_RT_TABLE
|
||||
sysNET_RT_IFNAMES = C.NET_RT_IFNAMES
|
||||
sysNET_RT_MAXID = C.NET_RT_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = C.CTL_MAXNAME
|
||||
|
||||
sysCTL_UNSPEC = C.CTL_UNSPEC
|
||||
sysCTL_KERN = C.CTL_KERN
|
||||
sysCTL_VM = C.CTL_VM
|
||||
sysCTL_FS = C.CTL_FS
|
||||
sysCTL_NET = C.CTL_NET
|
||||
sysCTL_DEBUG = C.CTL_DEBUG
|
||||
sysCTL_HW = C.CTL_HW
|
||||
sysCTL_MACHDEP = C.CTL_MACHDEP
|
||||
sysCTL_DDB = C.CTL_DDB
|
||||
sysCTL_VFS = C.CTL_VFS
|
||||
sysCTL_MAXID = C.CTL_MAXID
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = C.RTM_VERSION
|
||||
|
||||
sysRTM_ADD = C.RTM_ADD
|
||||
sysRTM_DELETE = C.RTM_DELETE
|
||||
sysRTM_CHANGE = C.RTM_CHANGE
|
||||
sysRTM_GET = C.RTM_GET
|
||||
sysRTM_LOSING = C.RTM_LOSING
|
||||
sysRTM_REDIRECT = C.RTM_REDIRECT
|
||||
sysRTM_MISS = C.RTM_MISS
|
||||
sysRTM_LOCK = C.RTM_LOCK
|
||||
sysRTM_RESOLVE = C.RTM_RESOLVE
|
||||
sysRTM_NEWADDR = C.RTM_NEWADDR
|
||||
sysRTM_DELADDR = C.RTM_DELADDR
|
||||
sysRTM_IFINFO = C.RTM_IFINFO
|
||||
sysRTM_IFANNOUNCE = C.RTM_IFANNOUNCE
|
||||
sysRTM_DESYNC = C.RTM_DESYNC
|
||||
|
||||
sysRTA_DST = C.RTA_DST
|
||||
sysRTA_GATEWAY = C.RTA_GATEWAY
|
||||
sysRTA_NETMASK = C.RTA_NETMASK
|
||||
sysRTA_GENMASK = C.RTA_GENMASK
|
||||
sysRTA_IFP = C.RTA_IFP
|
||||
sysRTA_IFA = C.RTA_IFA
|
||||
sysRTA_AUTHOR = C.RTA_AUTHOR
|
||||
sysRTA_BRD = C.RTA_BRD
|
||||
sysRTA_SRC = C.RTA_SRC
|
||||
sysRTA_SRCMASK = C.RTA_SRCMASK
|
||||
sysRTA_LABEL = C.RTA_LABEL
|
||||
|
||||
sysRTAX_DST = C.RTAX_DST
|
||||
sysRTAX_GATEWAY = C.RTAX_GATEWAY
|
||||
sysRTAX_NETMASK = C.RTAX_NETMASK
|
||||
sysRTAX_GENMASK = C.RTAX_GENMASK
|
||||
sysRTAX_IFP = C.RTAX_IFP
|
||||
sysRTAX_IFA = C.RTAX_IFA
|
||||
sysRTAX_AUTHOR = C.RTAX_AUTHOR
|
||||
sysRTAX_BRD = C.RTAX_BRD
|
||||
sysRTAX_SRC = C.RTAX_SRC
|
||||
sysRTAX_SRCMASK = C.RTAX_SRCMASK
|
||||
sysRTAX_LABEL = C.RTAX_LABEL
|
||||
sysRTAX_MAX = C.RTAX_MAX
|
||||
)
|
||||
64
vendor/golang.org/x/net/route/interface.go
generated
vendored
64
vendor/golang.org/x/net/route/interface.go
generated
vendored
@@ -1,64 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package route
|
||||
|
||||
// An InterfaceMessage represents an interface message.
|
||||
type InterfaceMessage struct {
|
||||
Version int // message version
|
||||
Type int // message type
|
||||
Flags int // interface flags
|
||||
Index int // interface index
|
||||
Name string // interface name
|
||||
Addrs []Addr // addresses
|
||||
|
||||
extOff int // offset of header extension
|
||||
raw []byte // raw message
|
||||
}
|
||||
|
||||
// An InterfaceAddrMessage represents an interface address message.
|
||||
type InterfaceAddrMessage struct {
|
||||
Version int // message version
|
||||
Type int // message type
|
||||
Flags int // interface flags
|
||||
Index int // interface index
|
||||
Addrs []Addr // addresses
|
||||
|
||||
raw []byte // raw message
|
||||
}
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceAddrMessage) Sys() []Sys { return nil }
|
||||
|
||||
// An InterfaceMulticastAddrMessage represents an interface multicast
|
||||
// address message.
|
||||
type InterfaceMulticastAddrMessage struct {
|
||||
Version int // message version
|
||||
Type int // messsage type
|
||||
Flags int // interface flags
|
||||
Index int // interface index
|
||||
Addrs []Addr // addresses
|
||||
|
||||
raw []byte // raw message
|
||||
}
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceMulticastAddrMessage) Sys() []Sys { return nil }
|
||||
|
||||
// An InterfaceAnnounceMessage represents an interface announcement
|
||||
// message.
|
||||
type InterfaceAnnounceMessage struct {
|
||||
Version int // message version
|
||||
Type int // message type
|
||||
Index int // interface index
|
||||
Name string // interface name
|
||||
What int // what type of announcement
|
||||
|
||||
raw []byte // raw message
|
||||
}
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceAnnounceMessage) Sys() []Sys { return nil }
|
||||
32
vendor/golang.org/x/net/route/interface_announce.go
generated
vendored
32
vendor/golang.org/x/net/route/interface_announce.go
generated
vendored
@@ -1,32 +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.
|
||||
|
||||
// +build dragonfly freebsd netbsd
|
||||
|
||||
package route
|
||||
|
||||
func (w *wireFormat) parseInterfaceAnnounceMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < w.bodyOff {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &InterfaceAnnounceMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Index: int(nativeEndian.Uint16(b[4:6])),
|
||||
What: int(nativeEndian.Uint16(b[22:24])),
|
||||
raw: b[:l],
|
||||
}
|
||||
for i := 0; i < 16; i++ {
|
||||
if b[6+i] != 0 {
|
||||
continue
|
||||
}
|
||||
m.Name = string(b[6 : 6+i])
|
||||
break
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
66
vendor/golang.org/x/net/route/interface_classic.go
generated
vendored
66
vendor/golang.org/x/net/route/interface_classic.go
generated
vendored
@@ -1,66 +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.
|
||||
|
||||
// +build darwin dragonfly netbsd
|
||||
|
||||
package route
|
||||
|
||||
import "runtime"
|
||||
|
||||
func (w *wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < w.bodyOff {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
attrs := uint(nativeEndian.Uint32(b[4:8]))
|
||||
if attrs&sysRTA_IFP == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
m := &InterfaceMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Addrs: make([]Addr, sysRTAX_MAX),
|
||||
Flags: int(nativeEndian.Uint32(b[8:12])),
|
||||
Index: int(nativeEndian.Uint16(b[12:14])),
|
||||
extOff: w.extOff,
|
||||
raw: b[:l],
|
||||
}
|
||||
a, err := parseLinkAddr(b[w.bodyOff:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.Addrs[sysRTAX_IFP] = a
|
||||
m.Name = a.(*LinkAddr).Name
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (w *wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < w.bodyOff {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &InterfaceAddrMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[8:12])),
|
||||
raw: b[:l],
|
||||
}
|
||||
if runtime.GOOS == "netbsd" {
|
||||
m.Index = int(nativeEndian.Uint16(b[16:18]))
|
||||
} else {
|
||||
m.Index = int(nativeEndian.Uint16(b[12:14]))
|
||||
}
|
||||
var err error
|
||||
m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[4:8])), parseKernelInetAddr, b[w.bodyOff:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
78
vendor/golang.org/x/net/route/interface_freebsd.go
generated
vendored
78
vendor/golang.org/x/net/route/interface_freebsd.go
generated
vendored
@@ -1,78 +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 route
|
||||
|
||||
func (w *wireFormat) parseInterfaceMessage(typ RIBType, b []byte) (Message, error) {
|
||||
var extOff, bodyOff int
|
||||
if typ == sysNET_RT_IFLISTL {
|
||||
if len(b) < 20 {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
extOff = int(nativeEndian.Uint16(b[18:20]))
|
||||
bodyOff = int(nativeEndian.Uint16(b[16:18]))
|
||||
} else {
|
||||
extOff = w.extOff
|
||||
bodyOff = w.bodyOff
|
||||
}
|
||||
if len(b) < extOff || len(b) < bodyOff {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
attrs := uint(nativeEndian.Uint32(b[4:8]))
|
||||
if attrs&sysRTA_IFP == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
m := &InterfaceMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[8:12])),
|
||||
Index: int(nativeEndian.Uint16(b[12:14])),
|
||||
Addrs: make([]Addr, sysRTAX_MAX),
|
||||
extOff: extOff,
|
||||
raw: b[:l],
|
||||
}
|
||||
a, err := parseLinkAddr(b[bodyOff:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.Addrs[sysRTAX_IFP] = a
|
||||
m.Name = a.(*LinkAddr).Name
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (w *wireFormat) parseInterfaceAddrMessage(typ RIBType, b []byte) (Message, error) {
|
||||
var bodyOff int
|
||||
if typ == sysNET_RT_IFLISTL {
|
||||
if len(b) < 24 {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
bodyOff = int(nativeEndian.Uint16(b[16:18]))
|
||||
} else {
|
||||
bodyOff = w.bodyOff
|
||||
}
|
||||
if len(b) < bodyOff {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &InterfaceAddrMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[8:12])),
|
||||
Index: int(nativeEndian.Uint16(b[12:14])),
|
||||
raw: b[:l],
|
||||
}
|
||||
var err error
|
||||
m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[4:8])), parseKernelInetAddr, b[bodyOff:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
30
vendor/golang.org/x/net/route/interface_multicast.go
generated
vendored
30
vendor/golang.org/x/net/route/interface_multicast.go
generated
vendored
@@ -1,30 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd
|
||||
|
||||
package route
|
||||
|
||||
func (w *wireFormat) parseInterfaceMulticastAddrMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < w.bodyOff {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &InterfaceMulticastAddrMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[8:12])),
|
||||
Index: int(nativeEndian.Uint16(b[12:14])),
|
||||
raw: b[:l],
|
||||
}
|
||||
var err error
|
||||
m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[4:8])), parseKernelInetAddr, b[w.bodyOff:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
90
vendor/golang.org/x/net/route/interface_openbsd.go
generated
vendored
90
vendor/golang.org/x/net/route/interface_openbsd.go
generated
vendored
@@ -1,90 +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 route
|
||||
|
||||
func (*wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < 32 {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
attrs := uint(nativeEndian.Uint32(b[12:16]))
|
||||
if attrs&sysRTA_IFP == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
m := &InterfaceMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[16:20])),
|
||||
Index: int(nativeEndian.Uint16(b[6:8])),
|
||||
Addrs: make([]Addr, sysRTAX_MAX),
|
||||
raw: b[:l],
|
||||
}
|
||||
ll := int(nativeEndian.Uint16(b[4:6]))
|
||||
if len(b) < ll {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
a, err := parseLinkAddr(b[ll:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.Addrs[sysRTAX_IFP] = a
|
||||
m.Name = a.(*LinkAddr).Name
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (*wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < 24 {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
bodyOff := int(nativeEndian.Uint16(b[4:6]))
|
||||
if len(b) < bodyOff {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &InterfaceAddrMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[12:16])),
|
||||
Index: int(nativeEndian.Uint16(b[6:8])),
|
||||
raw: b[:l],
|
||||
}
|
||||
var err error
|
||||
m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[bodyOff:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (*wireFormat) parseInterfaceAnnounceMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < 26 {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &InterfaceAnnounceMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Index: int(nativeEndian.Uint16(b[6:8])),
|
||||
What: int(nativeEndian.Uint16(b[8:10])),
|
||||
raw: b[:l],
|
||||
}
|
||||
for i := 0; i < 16; i++ {
|
||||
if b[10+i] != 0 {
|
||||
continue
|
||||
}
|
||||
m.Name = string(b[10 : 10+i])
|
||||
break
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
76
vendor/golang.org/x/net/route/message.go
generated
vendored
76
vendor/golang.org/x/net/route/message.go
generated
vendored
@@ -1,76 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package route
|
||||
|
||||
// A Message represents a routing message.
|
||||
//
|
||||
// Note: This interface will be changed to support Marshal method in
|
||||
// future version.
|
||||
type Message interface {
|
||||
// Sys returns operating system-specific information.
|
||||
Sys() []Sys
|
||||
}
|
||||
|
||||
// A Sys reprensents operating system-specific information.
|
||||
type Sys interface {
|
||||
// SysType returns a type of operating system-specific
|
||||
// information.
|
||||
SysType() SysType
|
||||
}
|
||||
|
||||
// A SysType represents a type of operating system-specific
|
||||
// information.
|
||||
type SysType int
|
||||
|
||||
const (
|
||||
SysMetrics SysType = iota
|
||||
SysStats
|
||||
)
|
||||
|
||||
// ParseRIB parses b as a routing information base and returns a list
|
||||
// of routing messages.
|
||||
func ParseRIB(typ RIBType, b []byte) ([]Message, error) {
|
||||
if !typ.parseable() {
|
||||
return nil, errUnsupportedMessage
|
||||
}
|
||||
var msgs []Message
|
||||
nmsgs, nskips := 0, 0
|
||||
for len(b) > 4 {
|
||||
nmsgs++
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if l == 0 {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
if len(b) < l {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
if b[2] != sysRTM_VERSION {
|
||||
b = b[l:]
|
||||
continue
|
||||
}
|
||||
mtyp := int(b[3])
|
||||
if fn, ok := parseFns[mtyp]; !ok {
|
||||
nskips++
|
||||
} else {
|
||||
m, err := fn(typ, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m == nil {
|
||||
nskips++
|
||||
} else {
|
||||
msgs = append(msgs, m)
|
||||
}
|
||||
}
|
||||
b = b[l:]
|
||||
}
|
||||
// We failed to parse any of the messages - version mismatch?
|
||||
if nmsgs != len(msgs)+nskips {
|
||||
return nil, errMessageMismatch
|
||||
}
|
||||
return msgs, nil
|
||||
}
|
||||
74
vendor/golang.org/x/net/route/route.go
generated
vendored
74
vendor/golang.org/x/net/route/route.go
generated
vendored
@@ -1,74 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
// Package route provides basic functions for the manipulation of
|
||||
// packet routing facilities on BSD variants.
|
||||
//
|
||||
// The package supports any version of Darwin, any version of
|
||||
// DragonFly BSD, FreeBSD 7 through 11, NetBSD 6 and above, and
|
||||
// OpenBSD 5.6 and above.
|
||||
package route
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
errUnsupportedMessage = errors.New("unsupported message")
|
||||
errMessageMismatch = errors.New("message mismatch")
|
||||
errMessageTooShort = errors.New("message too short")
|
||||
errInvalidMessage = errors.New("invalid message")
|
||||
errInvalidAddr = errors.New("invalid address")
|
||||
)
|
||||
|
||||
// A RouteMessage represents a message conveying an address prefix, a
|
||||
// nexthop address and an output interface.
|
||||
type RouteMessage struct {
|
||||
Version int // message version
|
||||
Type int // message type
|
||||
Flags int // route flags
|
||||
Index int // interface index when atatched
|
||||
Addrs []Addr // addresses
|
||||
|
||||
extOff int // offset of header extension
|
||||
raw []byte // raw message
|
||||
}
|
||||
|
||||
// A RIBType reprensents a type of routing information base.
|
||||
type RIBType int
|
||||
|
||||
const (
|
||||
RIBTypeRoute RIBType = syscall.NET_RT_DUMP
|
||||
RIBTypeInterface RIBType = syscall.NET_RT_IFLIST
|
||||
)
|
||||
|
||||
// FetchRIB fetches a routing information base from the operating
|
||||
// system.
|
||||
//
|
||||
// The provided af must be an address family.
|
||||
//
|
||||
// The provided arg must be a RIBType-specific argument.
|
||||
// When RIBType is related to routes, arg might be a set of route
|
||||
// flags. When RIBType is related to network interfaces, arg might be
|
||||
// an interface index or a set of interface flags. In most cases, zero
|
||||
// means a wildcard.
|
||||
func FetchRIB(af int, typ RIBType, arg int) ([]byte, error) {
|
||||
mib := [6]int32{sysCTL_NET, sysAF_ROUTE, 0, int32(af), int32(typ), int32(arg)}
|
||||
n := uintptr(0)
|
||||
if err := sysctl(mib[:], nil, &n, nil, 0); err != nil {
|
||||
return nil, os.NewSyscallError("sysctl", err)
|
||||
}
|
||||
if n == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
b := make([]byte, n)
|
||||
if err := sysctl(mib[:], &b[0], &n, nil, 0); err != nil {
|
||||
return nil, os.NewSyscallError("sysctl", err)
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
31
vendor/golang.org/x/net/route/route_classic.go
generated
vendored
31
vendor/golang.org/x/net/route/route_classic.go
generated
vendored
@@ -1,31 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd
|
||||
|
||||
package route
|
||||
|
||||
func (w *wireFormat) parseRouteMessage(typ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < w.bodyOff {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &RouteMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[8:12])),
|
||||
Index: int(nativeEndian.Uint16(b[4:6])),
|
||||
extOff: w.extOff,
|
||||
raw: b[:l],
|
||||
}
|
||||
var err error
|
||||
m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[w.bodyOff:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
32
vendor/golang.org/x/net/route/route_openbsd.go
generated
vendored
32
vendor/golang.org/x/net/route/route_openbsd.go
generated
vendored
@@ -1,32 +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 route
|
||||
|
||||
func (*wireFormat) parseRouteMessage(_ RIBType, b []byte) (Message, error) {
|
||||
if len(b) < 40 {
|
||||
return nil, errMessageTooShort
|
||||
}
|
||||
l := int(nativeEndian.Uint16(b[:2]))
|
||||
if len(b) < l {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
m := &RouteMessage{
|
||||
Version: int(b[2]),
|
||||
Type: int(b[3]),
|
||||
Flags: int(nativeEndian.Uint32(b[16:20])),
|
||||
Index: int(nativeEndian.Uint16(b[6:8])),
|
||||
raw: b[:l],
|
||||
}
|
||||
ll := int(nativeEndian.Uint16(b[4:6]))
|
||||
if len(b) < ll {
|
||||
return nil, errInvalidMessage
|
||||
}
|
||||
as, err := parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[ll:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.Addrs = as
|
||||
return m, nil
|
||||
}
|
||||
40
vendor/golang.org/x/net/route/sys.go
generated
vendored
40
vendor/golang.org/x/net/route/sys.go
generated
vendored
@@ -1,40 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package route
|
||||
|
||||
import "unsafe"
|
||||
|
||||
var (
|
||||
nativeEndian binaryByteOrder
|
||||
kernelAlign int
|
||||
parseFns map[int]parseFn
|
||||
)
|
||||
|
||||
func init() {
|
||||
i := uint32(1)
|
||||
b := (*[4]byte)(unsafe.Pointer(&i))
|
||||
if b[0] == 1 {
|
||||
nativeEndian = littleEndian
|
||||
} else {
|
||||
nativeEndian = bigEndian
|
||||
}
|
||||
kernelAlign, parseFns = probeRoutingStack()
|
||||
}
|
||||
|
||||
func roundup(l int) int {
|
||||
if l == 0 {
|
||||
return kernelAlign
|
||||
}
|
||||
return (l + kernelAlign - 1) & ^(kernelAlign - 1)
|
||||
}
|
||||
|
||||
type parseFn func(RIBType, []byte) (Message, error)
|
||||
|
||||
type wireFormat struct {
|
||||
extOff int // offset of header extension
|
||||
bodyOff int // offset of message body
|
||||
}
|
||||
80
vendor/golang.org/x/net/route/sys_darwin.go
generated
vendored
80
vendor/golang.org/x/net/route/sys_darwin.go
generated
vendored
@@ -1,80 +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 route
|
||||
|
||||
func (typ RIBType) parseable() bool {
|
||||
switch typ {
|
||||
case sysNET_RT_STAT, sysNET_RT_TRASH:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// A RouteMetrics represents route metrics.
|
||||
type RouteMetrics struct {
|
||||
PathMTU int // path maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *RouteMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&RouteMetrics{
|
||||
PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// A InterfaceMetrics represents interface metrics.
|
||||
type InterfaceMetrics struct {
|
||||
Type int // interface type
|
||||
MTU int // maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&InterfaceMetrics{
|
||||
Type: int(m.raw[m.extOff]),
|
||||
MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func probeRoutingStack() (int, map[int]parseFn) {
|
||||
rtm := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdrDarwin15}
|
||||
rtm2 := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdr2Darwin15}
|
||||
ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDarwin15}
|
||||
ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2Darwin15}
|
||||
ifam := &wireFormat{extOff: sizeofIfaMsghdrDarwin15, bodyOff: sizeofIfaMsghdrDarwin15}
|
||||
ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDarwin15, bodyOff: sizeofIfmaMsghdrDarwin15}
|
||||
ifmam2 := &wireFormat{extOff: sizeofIfmaMsghdr2Darwin15, bodyOff: sizeofIfmaMsghdr2Darwin15}
|
||||
// Darwin kernels require 32-bit aligned access to routing facilities.
|
||||
return 4, map[int]parseFn{
|
||||
sysRTM_ADD: rtm.parseRouteMessage,
|
||||
sysRTM_DELETE: rtm.parseRouteMessage,
|
||||
sysRTM_CHANGE: rtm.parseRouteMessage,
|
||||
sysRTM_GET: rtm.parseRouteMessage,
|
||||
sysRTM_LOSING: rtm.parseRouteMessage,
|
||||
sysRTM_REDIRECT: rtm.parseRouteMessage,
|
||||
sysRTM_MISS: rtm.parseRouteMessage,
|
||||
sysRTM_LOCK: rtm.parseRouteMessage,
|
||||
sysRTM_RESOLVE: rtm.parseRouteMessage,
|
||||
sysRTM_NEWADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_DELADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_IFINFO: ifm.parseInterfaceMessage,
|
||||
sysRTM_NEWMADDR: ifmam.parseInterfaceMulticastAddrMessage,
|
||||
sysRTM_DELMADDR: ifmam.parseInterfaceMulticastAddrMessage,
|
||||
sysRTM_IFINFO2: ifm2.parseInterfaceMessage,
|
||||
sysRTM_NEWMADDR2: ifmam2.parseInterfaceMulticastAddrMessage,
|
||||
sysRTM_GET2: rtm2.parseRouteMessage,
|
||||
}
|
||||
}
|
||||
71
vendor/golang.org/x/net/route/sys_dragonfly.go
generated
vendored
71
vendor/golang.org/x/net/route/sys_dragonfly.go
generated
vendored
@@ -1,71 +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 route
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (typ RIBType) parseable() bool { return true }
|
||||
|
||||
// A RouteMetrics represents route metrics.
|
||||
type RouteMetrics struct {
|
||||
PathMTU int // path maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *RouteMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&RouteMetrics{
|
||||
PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// A InterfaceMetrics represents interface metrics.
|
||||
type InterfaceMetrics struct {
|
||||
Type int // interface type
|
||||
MTU int // maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&InterfaceMetrics{
|
||||
Type: int(m.raw[m.extOff]),
|
||||
MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func probeRoutingStack() (int, map[int]parseFn) {
|
||||
var p uintptr
|
||||
rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrDragonFlyBSD4}
|
||||
ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDragonFlyBSD4}
|
||||
ifam := &wireFormat{extOff: sizeofIfaMsghdrDragonFlyBSD4, bodyOff: sizeofIfaMsghdrDragonFlyBSD4}
|
||||
ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDragonFlyBSD4, bodyOff: sizeofIfmaMsghdrDragonFlyBSD4}
|
||||
ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4}
|
||||
return int(unsafe.Sizeof(p)), map[int]parseFn{
|
||||
sysRTM_ADD: rtm.parseRouteMessage,
|
||||
sysRTM_DELETE: rtm.parseRouteMessage,
|
||||
sysRTM_CHANGE: rtm.parseRouteMessage,
|
||||
sysRTM_GET: rtm.parseRouteMessage,
|
||||
sysRTM_LOSING: rtm.parseRouteMessage,
|
||||
sysRTM_REDIRECT: rtm.parseRouteMessage,
|
||||
sysRTM_MISS: rtm.parseRouteMessage,
|
||||
sysRTM_LOCK: rtm.parseRouteMessage,
|
||||
sysRTM_RESOLVE: rtm.parseRouteMessage,
|
||||
sysRTM_NEWADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_DELADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_IFINFO: ifm.parseInterfaceMessage,
|
||||
sysRTM_NEWMADDR: ifmam.parseInterfaceMulticastAddrMessage,
|
||||
sysRTM_DELMADDR: ifmam.parseInterfaceMulticastAddrMessage,
|
||||
sysRTM_IFANNOUNCE: ifanm.parseInterfaceAnnounceMessage,
|
||||
}
|
||||
}
|
||||
150
vendor/golang.org/x/net/route/sys_freebsd.go
generated
vendored
150
vendor/golang.org/x/net/route/sys_freebsd.go
generated
vendored
@@ -1,150 +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 route
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (typ RIBType) parseable() bool { return true }
|
||||
|
||||
// A RouteMetrics represents route metrics.
|
||||
type RouteMetrics struct {
|
||||
PathMTU int // path maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *RouteMessage) Sys() []Sys {
|
||||
if kernelAlign == 8 {
|
||||
return []Sys{
|
||||
&RouteMetrics{
|
||||
PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
|
||||
},
|
||||
}
|
||||
}
|
||||
return []Sys{
|
||||
&RouteMetrics{
|
||||
PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// A InterfaceMetrics represents interface metrics.
|
||||
type InterfaceMetrics struct {
|
||||
Type int // interface type
|
||||
MTU int // maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&InterfaceMetrics{
|
||||
Type: int(m.raw[m.extOff]),
|
||||
MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func probeRoutingStack() (int, map[int]parseFn) {
|
||||
var p uintptr
|
||||
wordSize := int(unsafe.Sizeof(p))
|
||||
align := int(unsafe.Sizeof(p))
|
||||
// In the case of kern.supported_archs="amd64 i386", we need
|
||||
// to know the underlying kernel's architecture because the
|
||||
// alignment for routing facilities are set at the build time
|
||||
// of the kernel.
|
||||
conf, _ := syscall.Sysctl("kern.conftxt")
|
||||
for i, j := 0, 0; j < len(conf); j++ {
|
||||
if conf[j] != '\n' {
|
||||
continue
|
||||
}
|
||||
s := conf[i:j]
|
||||
i = j + 1
|
||||
if len(s) > len("machine") && s[:len("machine")] == "machine" {
|
||||
s = s[len("machine"):]
|
||||
for k := 0; k < len(s); k++ {
|
||||
if s[k] == ' ' || s[k] == '\t' {
|
||||
s = s[1:]
|
||||
}
|
||||
break
|
||||
}
|
||||
if s == "amd64" {
|
||||
align = 8
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
var rtm, ifm, ifam, ifmam, ifanm *wireFormat
|
||||
if align != wordSize { // 386 emulation on amd64
|
||||
rtm = &wireFormat{extOff: sizeofRtMsghdrFreeBSD10Emu - sizeofRtMetricsFreeBSD10Emu, bodyOff: sizeofRtMsghdrFreeBSD10Emu}
|
||||
ifm = &wireFormat{extOff: 16}
|
||||
ifam = &wireFormat{extOff: sizeofIfaMsghdrFreeBSD10Emu, bodyOff: sizeofIfaMsghdrFreeBSD10Emu}
|
||||
ifmam = &wireFormat{extOff: sizeofIfmaMsghdrFreeBSD10Emu, bodyOff: sizeofIfmaMsghdrFreeBSD10Emu}
|
||||
ifanm = &wireFormat{extOff: sizeofIfAnnouncemsghdrFreeBSD10Emu, bodyOff: sizeofIfAnnouncemsghdrFreeBSD10Emu}
|
||||
} else {
|
||||
rtm = &wireFormat{extOff: sizeofRtMsghdrFreeBSD10 - sizeofRtMetricsFreeBSD10, bodyOff: sizeofRtMsghdrFreeBSD10}
|
||||
ifm = &wireFormat{extOff: 16}
|
||||
ifam = &wireFormat{extOff: sizeofIfaMsghdrFreeBSD10, bodyOff: sizeofIfaMsghdrFreeBSD10}
|
||||
ifmam = &wireFormat{extOff: sizeofIfmaMsghdrFreeBSD10, bodyOff: sizeofIfmaMsghdrFreeBSD10}
|
||||
ifanm = &wireFormat{extOff: sizeofIfAnnouncemsghdrFreeBSD10, bodyOff: sizeofIfAnnouncemsghdrFreeBSD10}
|
||||
}
|
||||
rel, _ := syscall.SysctlUint32("kern.osreldate")
|
||||
switch {
|
||||
case rel < 800000:
|
||||
if align != wordSize { // 386 emulation on amd64
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD7Emu
|
||||
} else {
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD7
|
||||
}
|
||||
case 800000 <= rel && rel < 900000:
|
||||
if align != wordSize { // 386 emulation on amd64
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD8Emu
|
||||
} else {
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD8
|
||||
}
|
||||
case 900000 <= rel && rel < 1000000:
|
||||
if align != wordSize { // 386 emulation on amd64
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD9Emu
|
||||
} else {
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD9
|
||||
}
|
||||
case 1000000 <= rel && rel < 1100000:
|
||||
if align != wordSize { // 386 emulation on amd64
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD10Emu
|
||||
} else {
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD10
|
||||
}
|
||||
default:
|
||||
if align != wordSize { // 386 emulation on amd64
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD11Emu
|
||||
} else {
|
||||
ifm.bodyOff = sizeofIfMsghdrFreeBSD11
|
||||
}
|
||||
}
|
||||
return align, map[int]parseFn{
|
||||
sysRTM_ADD: rtm.parseRouteMessage,
|
||||
sysRTM_DELETE: rtm.parseRouteMessage,
|
||||
sysRTM_CHANGE: rtm.parseRouteMessage,
|
||||
sysRTM_GET: rtm.parseRouteMessage,
|
||||
sysRTM_LOSING: rtm.parseRouteMessage,
|
||||
sysRTM_REDIRECT: rtm.parseRouteMessage,
|
||||
sysRTM_MISS: rtm.parseRouteMessage,
|
||||
sysRTM_LOCK: rtm.parseRouteMessage,
|
||||
sysRTM_RESOLVE: rtm.parseRouteMessage,
|
||||
sysRTM_NEWADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_DELADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_IFINFO: ifm.parseInterfaceMessage,
|
||||
sysRTM_NEWMADDR: ifmam.parseInterfaceMulticastAddrMessage,
|
||||
sysRTM_DELMADDR: ifmam.parseInterfaceMulticastAddrMessage,
|
||||
sysRTM_IFANNOUNCE: ifanm.parseInterfaceAnnounceMessage,
|
||||
}
|
||||
}
|
||||
67
vendor/golang.org/x/net/route/sys_netbsd.go
generated
vendored
67
vendor/golang.org/x/net/route/sys_netbsd.go
generated
vendored
@@ -1,67 +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 route
|
||||
|
||||
func (typ RIBType) parseable() bool { return true }
|
||||
|
||||
// A RouteMetrics represents route metrics.
|
||||
type RouteMetrics struct {
|
||||
PathMTU int // path maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *RouteMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&RouteMetrics{
|
||||
PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// A InterfaceMetrics represents interface metrics.
|
||||
type InterfaceMetrics struct {
|
||||
Type int // interface type
|
||||
MTU int // maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&InterfaceMetrics{
|
||||
Type: int(m.raw[m.extOff]),
|
||||
MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func probeRoutingStack() (int, map[int]parseFn) {
|
||||
rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrNetBSD7}
|
||||
ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrNetBSD7}
|
||||
ifam := &wireFormat{extOff: sizeofIfaMsghdrNetBSD7, bodyOff: sizeofIfaMsghdrNetBSD7}
|
||||
ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrNetBSD7, bodyOff: sizeofIfAnnouncemsghdrNetBSD7}
|
||||
// NetBSD 6 and above kernels require 64-bit aligned access to
|
||||
// routing facilities.
|
||||
return 8, map[int]parseFn{
|
||||
sysRTM_ADD: rtm.parseRouteMessage,
|
||||
sysRTM_DELETE: rtm.parseRouteMessage,
|
||||
sysRTM_CHANGE: rtm.parseRouteMessage,
|
||||
sysRTM_GET: rtm.parseRouteMessage,
|
||||
sysRTM_LOSING: rtm.parseRouteMessage,
|
||||
sysRTM_REDIRECT: rtm.parseRouteMessage,
|
||||
sysRTM_MISS: rtm.parseRouteMessage,
|
||||
sysRTM_LOCK: rtm.parseRouteMessage,
|
||||
sysRTM_RESOLVE: rtm.parseRouteMessage,
|
||||
sysRTM_NEWADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_DELADDR: ifam.parseInterfaceAddrMessage,
|
||||
sysRTM_IFANNOUNCE: ifanm.parseInterfaceAnnounceMessage,
|
||||
sysRTM_IFINFO: ifm.parseInterfaceMessage,
|
||||
}
|
||||
}
|
||||
72
vendor/golang.org/x/net/route/sys_openbsd.go
generated
vendored
72
vendor/golang.org/x/net/route/sys_openbsd.go
generated
vendored
@@ -1,72 +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 route
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (typ RIBType) parseable() bool {
|
||||
switch typ {
|
||||
case sysNET_RT_STATS, sysNET_RT_TABLE:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// A RouteMetrics represents route metrics.
|
||||
type RouteMetrics struct {
|
||||
PathMTU int // path maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *RouteMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&RouteMetrics{
|
||||
PathMTU: int(nativeEndian.Uint32(m.raw[60:64])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// A InterfaceMetrics represents interface metrics.
|
||||
type InterfaceMetrics struct {
|
||||
Type int // interface type
|
||||
MTU int // maximum transmission unit
|
||||
}
|
||||
|
||||
// SysType implements the SysType method of Sys interface.
|
||||
func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
|
||||
|
||||
// Sys implements the Sys method of Message interface.
|
||||
func (m *InterfaceMessage) Sys() []Sys {
|
||||
return []Sys{
|
||||
&InterfaceMetrics{
|
||||
Type: int(m.raw[24]),
|
||||
MTU: int(nativeEndian.Uint32(m.raw[28:32])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func probeRoutingStack() (int, map[int]parseFn) {
|
||||
var p uintptr
|
||||
nooff := &wireFormat{extOff: -1, bodyOff: -1}
|
||||
return int(unsafe.Sizeof(p)), map[int]parseFn{
|
||||
sysRTM_ADD: nooff.parseRouteMessage,
|
||||
sysRTM_DELETE: nooff.parseRouteMessage,
|
||||
sysRTM_CHANGE: nooff.parseRouteMessage,
|
||||
sysRTM_GET: nooff.parseRouteMessage,
|
||||
sysRTM_LOSING: nooff.parseRouteMessage,
|
||||
sysRTM_REDIRECT: nooff.parseRouteMessage,
|
||||
sysRTM_MISS: nooff.parseRouteMessage,
|
||||
sysRTM_LOCK: nooff.parseRouteMessage,
|
||||
sysRTM_RESOLVE: nooff.parseRouteMessage,
|
||||
sysRTM_NEWADDR: nooff.parseInterfaceAddrMessage,
|
||||
sysRTM_DELADDR: nooff.parseInterfaceAddrMessage,
|
||||
sysRTM_IFINFO: nooff.parseInterfaceMessage,
|
||||
sysRTM_IFANNOUNCE: nooff.parseInterfaceAnnounceMessage,
|
||||
}
|
||||
}
|
||||
33
vendor/golang.org/x/net/route/syscall.go
generated
vendored
33
vendor/golang.org/x/net/route/syscall.go
generated
vendored
@@ -1,33 +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.
|
||||
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package route
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// TODO: replace with runtime.KeepAlive when available
|
||||
//go:noescape
|
||||
func keepAlive(p unsafe.Pointer)
|
||||
|
||||
var zero uintptr
|
||||
|
||||
func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error {
|
||||
var p unsafe.Pointer
|
||||
if len(mib) > 0 {
|
||||
p = unsafe.Pointer(&mib[0])
|
||||
} else {
|
||||
p = unsafe.Pointer(&zero)
|
||||
}
|
||||
_, _, errno := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(p), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen))
|
||||
keepAlive(p)
|
||||
if errno != 0 {
|
||||
return error(errno)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
8
vendor/golang.org/x/net/route/syscall.s
generated
vendored
8
vendor/golang.org/x/net/route/syscall.s
generated
vendored
@@ -1,8 +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.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
TEXT ·keepAlive(SB),NOSPLIT,$0
|
||||
RET
|
||||
93
vendor/golang.org/x/net/route/zsys_darwin.go
generated
vendored
93
vendor/golang.org/x/net/route/zsys_darwin.go
generated
vendored
@@ -1,93 +0,0 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs defs_darwin.go
|
||||
|
||||
package route
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = 0x0
|
||||
sysAF_INET = 0x2
|
||||
sysAF_ROUTE = 0x11
|
||||
sysAF_LINK = 0x12
|
||||
sysAF_INET6 = 0x1e
|
||||
|
||||
sysNET_RT_DUMP = 0x1
|
||||
sysNET_RT_FLAGS = 0x2
|
||||
sysNET_RT_IFLIST = 0x3
|
||||
sysNET_RT_STAT = 0x4
|
||||
sysNET_RT_TRASH = 0x5
|
||||
sysNET_RT_IFLIST2 = 0x6
|
||||
sysNET_RT_DUMP2 = 0x7
|
||||
sysNET_RT_MAXID = 0xa
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = 0xc
|
||||
|
||||
sysCTL_UNSPEC = 0x0
|
||||
sysCTL_KERN = 0x1
|
||||
sysCTL_VM = 0x2
|
||||
sysCTL_VFS = 0x3
|
||||
sysCTL_NET = 0x4
|
||||
sysCTL_DEBUG = 0x5
|
||||
sysCTL_HW = 0x6
|
||||
sysCTL_MACHDEP = 0x7
|
||||
sysCTL_USER = 0x8
|
||||
sysCTL_MAXID = 0x9
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = 0x5
|
||||
|
||||
sysRTM_ADD = 0x1
|
||||
sysRTM_DELETE = 0x2
|
||||
sysRTM_CHANGE = 0x3
|
||||
sysRTM_GET = 0x4
|
||||
sysRTM_LOSING = 0x5
|
||||
sysRTM_REDIRECT = 0x6
|
||||
sysRTM_MISS = 0x7
|
||||
sysRTM_LOCK = 0x8
|
||||
sysRTM_OLDADD = 0x9
|
||||
sysRTM_OLDDEL = 0xa
|
||||
sysRTM_RESOLVE = 0xb
|
||||
sysRTM_NEWADDR = 0xc
|
||||
sysRTM_DELADDR = 0xd
|
||||
sysRTM_IFINFO = 0xe
|
||||
sysRTM_NEWMADDR = 0xf
|
||||
sysRTM_DELMADDR = 0x10
|
||||
sysRTM_IFINFO2 = 0x12
|
||||
sysRTM_NEWMADDR2 = 0x13
|
||||
sysRTM_GET2 = 0x14
|
||||
|
||||
sysRTA_DST = 0x1
|
||||
sysRTA_GATEWAY = 0x2
|
||||
sysRTA_NETMASK = 0x4
|
||||
sysRTA_GENMASK = 0x8
|
||||
sysRTA_IFP = 0x10
|
||||
sysRTA_IFA = 0x20
|
||||
sysRTA_AUTHOR = 0x40
|
||||
sysRTA_BRD = 0x80
|
||||
|
||||
sysRTAX_DST = 0x0
|
||||
sysRTAX_GATEWAY = 0x1
|
||||
sysRTAX_NETMASK = 0x2
|
||||
sysRTAX_GENMASK = 0x3
|
||||
sysRTAX_IFP = 0x4
|
||||
sysRTAX_IFA = 0x5
|
||||
sysRTAX_AUTHOR = 0x6
|
||||
sysRTAX_BRD = 0x7
|
||||
sysRTAX_MAX = 0x8
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrDarwin15 = 0x70
|
||||
sizeofIfaMsghdrDarwin15 = 0x14
|
||||
sizeofIfmaMsghdrDarwin15 = 0x10
|
||||
sizeofIfMsghdr2Darwin15 = 0xa0
|
||||
sizeofIfmaMsghdr2Darwin15 = 0x14
|
||||
sizeofIfDataDarwin15 = 0x60
|
||||
sizeofIfData64Darwin15 = 0x80
|
||||
|
||||
sizeofRtMsghdrDarwin15 = 0x5c
|
||||
sizeofRtMsghdr2Darwin15 = 0x5c
|
||||
sizeofRtMetricsDarwin15 = 0x38
|
||||
)
|
||||
92
vendor/golang.org/x/net/route/zsys_dragonfly.go
generated
vendored
92
vendor/golang.org/x/net/route/zsys_dragonfly.go
generated
vendored
@@ -1,92 +0,0 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs defs_dragonfly.go
|
||||
|
||||
package route
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = 0x0
|
||||
sysAF_INET = 0x2
|
||||
sysAF_ROUTE = 0x11
|
||||
sysAF_LINK = 0x12
|
||||
sysAF_INET6 = 0x1c
|
||||
|
||||
sysNET_RT_DUMP = 0x1
|
||||
sysNET_RT_FLAGS = 0x2
|
||||
sysNET_RT_IFLIST = 0x3
|
||||
sysNET_RT_MAXID = 0x4
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = 0xc
|
||||
|
||||
sysCTL_UNSPEC = 0x0
|
||||
sysCTL_KERN = 0x1
|
||||
sysCTL_VM = 0x2
|
||||
sysCTL_VFS = 0x3
|
||||
sysCTL_NET = 0x4
|
||||
sysCTL_DEBUG = 0x5
|
||||
sysCTL_HW = 0x6
|
||||
sysCTL_MACHDEP = 0x7
|
||||
sysCTL_USER = 0x8
|
||||
sysCTL_P1003_1B = 0x9
|
||||
sysCTL_LWKT = 0xa
|
||||
sysCTL_MAXID = 0xb
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = 0x6
|
||||
|
||||
sysRTM_ADD = 0x1
|
||||
sysRTM_DELETE = 0x2
|
||||
sysRTM_CHANGE = 0x3
|
||||
sysRTM_GET = 0x4
|
||||
sysRTM_LOSING = 0x5
|
||||
sysRTM_REDIRECT = 0x6
|
||||
sysRTM_MISS = 0x7
|
||||
sysRTM_LOCK = 0x8
|
||||
sysRTM_OLDADD = 0x9
|
||||
sysRTM_OLDDEL = 0xa
|
||||
sysRTM_RESOLVE = 0xb
|
||||
sysRTM_NEWADDR = 0xc
|
||||
sysRTM_DELADDR = 0xd
|
||||
sysRTM_IFINFO = 0xe
|
||||
sysRTM_NEWMADDR = 0xf
|
||||
sysRTM_DELMADDR = 0x10
|
||||
sysRTM_IFANNOUNCE = 0x11
|
||||
sysRTM_IEEE80211 = 0x12
|
||||
|
||||
sysRTA_DST = 0x1
|
||||
sysRTA_GATEWAY = 0x2
|
||||
sysRTA_NETMASK = 0x4
|
||||
sysRTA_GENMASK = 0x8
|
||||
sysRTA_IFP = 0x10
|
||||
sysRTA_IFA = 0x20
|
||||
sysRTA_AUTHOR = 0x40
|
||||
sysRTA_BRD = 0x80
|
||||
sysRTA_MPLS1 = 0x100
|
||||
sysRTA_MPLS2 = 0x200
|
||||
sysRTA_MPLS3 = 0x400
|
||||
|
||||
sysRTAX_DST = 0x0
|
||||
sysRTAX_GATEWAY = 0x1
|
||||
sysRTAX_NETMASK = 0x2
|
||||
sysRTAX_GENMASK = 0x3
|
||||
sysRTAX_IFP = 0x4
|
||||
sysRTAX_IFA = 0x5
|
||||
sysRTAX_AUTHOR = 0x6
|
||||
sysRTAX_BRD = 0x7
|
||||
sysRTAX_MPLS1 = 0x8
|
||||
sysRTAX_MPLS2 = 0x9
|
||||
sysRTAX_MPLS3 = 0xa
|
||||
sysRTAX_MAX = 0xb
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrDragonFlyBSD4 = 0xb0
|
||||
sizeofIfaMsghdrDragonFlyBSD4 = 0x14
|
||||
sizeofIfmaMsghdrDragonFlyBSD4 = 0x10
|
||||
sizeofIfAnnouncemsghdrDragonFlyBSD4 = 0x18
|
||||
|
||||
sizeofRtMsghdrDragonFlyBSD4 = 0x98
|
||||
sizeofRtMetricsDragonFlyBSD4 = 0x70
|
||||
)
|
||||
120
vendor/golang.org/x/net/route/zsys_freebsd_386.go
generated
vendored
120
vendor/golang.org/x/net/route/zsys_freebsd_386.go
generated
vendored
@@ -1,120 +0,0 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs defs_freebsd.go
|
||||
|
||||
package route
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = 0x0
|
||||
sysAF_INET = 0x2
|
||||
sysAF_ROUTE = 0x11
|
||||
sysAF_LINK = 0x12
|
||||
sysAF_INET6 = 0x1c
|
||||
|
||||
sysNET_RT_DUMP = 0x1
|
||||
sysNET_RT_FLAGS = 0x2
|
||||
sysNET_RT_IFLIST = 0x3
|
||||
sysNET_RT_IFMALIST = 0x4
|
||||
sysNET_RT_IFLISTL = 0x5
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = 0x18
|
||||
|
||||
sysCTL_UNSPEC = 0x0
|
||||
sysCTL_KERN = 0x1
|
||||
sysCTL_VM = 0x2
|
||||
sysCTL_VFS = 0x3
|
||||
sysCTL_NET = 0x4
|
||||
sysCTL_DEBUG = 0x5
|
||||
sysCTL_HW = 0x6
|
||||
sysCTL_MACHDEP = 0x7
|
||||
sysCTL_USER = 0x8
|
||||
sysCTL_P1003_1B = 0x9
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = 0x5
|
||||
|
||||
sysRTM_ADD = 0x1
|
||||
sysRTM_DELETE = 0x2
|
||||
sysRTM_CHANGE = 0x3
|
||||
sysRTM_GET = 0x4
|
||||
sysRTM_LOSING = 0x5
|
||||
sysRTM_REDIRECT = 0x6
|
||||
sysRTM_MISS = 0x7
|
||||
sysRTM_LOCK = 0x8
|
||||
sysRTM_RESOLVE = 0xb
|
||||
sysRTM_NEWADDR = 0xc
|
||||
sysRTM_DELADDR = 0xd
|
||||
sysRTM_IFINFO = 0xe
|
||||
sysRTM_NEWMADDR = 0xf
|
||||
sysRTM_DELMADDR = 0x10
|
||||
sysRTM_IFANNOUNCE = 0x11
|
||||
sysRTM_IEEE80211 = 0x12
|
||||
|
||||
sysRTA_DST = 0x1
|
||||
sysRTA_GATEWAY = 0x2
|
||||
sysRTA_NETMASK = 0x4
|
||||
sysRTA_GENMASK = 0x8
|
||||
sysRTA_IFP = 0x10
|
||||
sysRTA_IFA = 0x20
|
||||
sysRTA_AUTHOR = 0x40
|
||||
sysRTA_BRD = 0x80
|
||||
|
||||
sysRTAX_DST = 0x0
|
||||
sysRTAX_GATEWAY = 0x1
|
||||
sysRTAX_NETMASK = 0x2
|
||||
sysRTAX_GENMASK = 0x3
|
||||
sysRTAX_IFP = 0x4
|
||||
sysRTAX_IFA = 0x5
|
||||
sysRTAX_AUTHOR = 0x6
|
||||
sysRTAX_BRD = 0x7
|
||||
sysRTAX_MAX = 0x8
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrlFreeBSD10 = 0x68
|
||||
sizeofIfaMsghdrFreeBSD10 = 0x14
|
||||
sizeofIfaMsghdrlFreeBSD10 = 0x6c
|
||||
sizeofIfmaMsghdrFreeBSD10 = 0x10
|
||||
sizeofIfAnnouncemsghdrFreeBSD10 = 0x18
|
||||
|
||||
sizeofRtMsghdrFreeBSD10 = 0x5c
|
||||
sizeofRtMetricsFreeBSD10 = 0x38
|
||||
|
||||
sizeofIfMsghdrFreeBSD7 = 0x60
|
||||
sizeofIfMsghdrFreeBSD8 = 0x60
|
||||
sizeofIfMsghdrFreeBSD9 = 0x60
|
||||
sizeofIfMsghdrFreeBSD10 = 0x64
|
||||
sizeofIfMsghdrFreeBSD11 = 0xa8
|
||||
|
||||
sizeofIfDataFreeBSD7 = 0x50
|
||||
sizeofIfDataFreeBSD8 = 0x50
|
||||
sizeofIfDataFreeBSD9 = 0x50
|
||||
sizeofIfDataFreeBSD10 = 0x54
|
||||
sizeofIfDataFreeBSD11 = 0x98
|
||||
|
||||
// MODIFIED BY HAND FOR 386 EMULATION ON AMD64
|
||||
// 386 EMULATION USES THE UNDERLYING RAW DATA LAYOUT
|
||||
|
||||
sizeofIfMsghdrlFreeBSD10Emu = 0xb0
|
||||
sizeofIfaMsghdrFreeBSD10Emu = 0x14
|
||||
sizeofIfaMsghdrlFreeBSD10Emu = 0xb0
|
||||
sizeofIfmaMsghdrFreeBSD10Emu = 0x10
|
||||
sizeofIfAnnouncemsghdrFreeBSD10Emu = 0x18
|
||||
|
||||
sizeofRtMsghdrFreeBSD10Emu = 0x98
|
||||
sizeofRtMetricsFreeBSD10Emu = 0x70
|
||||
|
||||
sizeofIfMsghdrFreeBSD7Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD8Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD9Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD10Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD11Emu = 0xa8
|
||||
|
||||
sizeofIfDataFreeBSD7Emu = 0x98
|
||||
sizeofIfDataFreeBSD8Emu = 0x98
|
||||
sizeofIfDataFreeBSD9Emu = 0x98
|
||||
sizeofIfDataFreeBSD10Emu = 0x98
|
||||
sizeofIfDataFreeBSD11Emu = 0x98
|
||||
)
|
||||
117
vendor/golang.org/x/net/route/zsys_freebsd_amd64.go
generated
vendored
117
vendor/golang.org/x/net/route/zsys_freebsd_amd64.go
generated
vendored
@@ -1,117 +0,0 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs defs_freebsd.go
|
||||
|
||||
package route
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = 0x0
|
||||
sysAF_INET = 0x2
|
||||
sysAF_ROUTE = 0x11
|
||||
sysAF_LINK = 0x12
|
||||
sysAF_INET6 = 0x1c
|
||||
|
||||
sysNET_RT_DUMP = 0x1
|
||||
sysNET_RT_FLAGS = 0x2
|
||||
sysNET_RT_IFLIST = 0x3
|
||||
sysNET_RT_IFMALIST = 0x4
|
||||
sysNET_RT_IFLISTL = 0x5
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = 0x18
|
||||
|
||||
sysCTL_UNSPEC = 0x0
|
||||
sysCTL_KERN = 0x1
|
||||
sysCTL_VM = 0x2
|
||||
sysCTL_VFS = 0x3
|
||||
sysCTL_NET = 0x4
|
||||
sysCTL_DEBUG = 0x5
|
||||
sysCTL_HW = 0x6
|
||||
sysCTL_MACHDEP = 0x7
|
||||
sysCTL_USER = 0x8
|
||||
sysCTL_P1003_1B = 0x9
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = 0x5
|
||||
|
||||
sysRTM_ADD = 0x1
|
||||
sysRTM_DELETE = 0x2
|
||||
sysRTM_CHANGE = 0x3
|
||||
sysRTM_GET = 0x4
|
||||
sysRTM_LOSING = 0x5
|
||||
sysRTM_REDIRECT = 0x6
|
||||
sysRTM_MISS = 0x7
|
||||
sysRTM_LOCK = 0x8
|
||||
sysRTM_RESOLVE = 0xb
|
||||
sysRTM_NEWADDR = 0xc
|
||||
sysRTM_DELADDR = 0xd
|
||||
sysRTM_IFINFO = 0xe
|
||||
sysRTM_NEWMADDR = 0xf
|
||||
sysRTM_DELMADDR = 0x10
|
||||
sysRTM_IFANNOUNCE = 0x11
|
||||
sysRTM_IEEE80211 = 0x12
|
||||
|
||||
sysRTA_DST = 0x1
|
||||
sysRTA_GATEWAY = 0x2
|
||||
sysRTA_NETMASK = 0x4
|
||||
sysRTA_GENMASK = 0x8
|
||||
sysRTA_IFP = 0x10
|
||||
sysRTA_IFA = 0x20
|
||||
sysRTA_AUTHOR = 0x40
|
||||
sysRTA_BRD = 0x80
|
||||
|
||||
sysRTAX_DST = 0x0
|
||||
sysRTAX_GATEWAY = 0x1
|
||||
sysRTAX_NETMASK = 0x2
|
||||
sysRTAX_GENMASK = 0x3
|
||||
sysRTAX_IFP = 0x4
|
||||
sysRTAX_IFA = 0x5
|
||||
sysRTAX_AUTHOR = 0x6
|
||||
sysRTAX_BRD = 0x7
|
||||
sysRTAX_MAX = 0x8
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrlFreeBSD10 = 0xb0
|
||||
sizeofIfaMsghdrFreeBSD10 = 0x14
|
||||
sizeofIfaMsghdrlFreeBSD10 = 0xb0
|
||||
sizeofIfmaMsghdrFreeBSD10 = 0x10
|
||||
sizeofIfAnnouncemsghdrFreeBSD10 = 0x18
|
||||
|
||||
sizeofRtMsghdrFreeBSD10 = 0x98
|
||||
sizeofRtMetricsFreeBSD10 = 0x70
|
||||
|
||||
sizeofIfMsghdrFreeBSD7 = 0xa8
|
||||
sizeofIfMsghdrFreeBSD8 = 0xa8
|
||||
sizeofIfMsghdrFreeBSD9 = 0xa8
|
||||
sizeofIfMsghdrFreeBSD10 = 0xa8
|
||||
sizeofIfMsghdrFreeBSD11 = 0xa8
|
||||
|
||||
sizeofIfDataFreeBSD7 = 0x98
|
||||
sizeofIfDataFreeBSD8 = 0x98
|
||||
sizeofIfDataFreeBSD9 = 0x98
|
||||
sizeofIfDataFreeBSD10 = 0x98
|
||||
sizeofIfDataFreeBSD11 = 0x98
|
||||
|
||||
sizeofIfMsghdrlFreeBSD10Emu = 0xb0
|
||||
sizeofIfaMsghdrFreeBSD10Emu = 0x14
|
||||
sizeofIfaMsghdrlFreeBSD10Emu = 0xb0
|
||||
sizeofIfmaMsghdrFreeBSD10Emu = 0x10
|
||||
sizeofIfAnnouncemsghdrFreeBSD10Emu = 0x18
|
||||
|
||||
sizeofRtMsghdrFreeBSD10Emu = 0x98
|
||||
sizeofRtMetricsFreeBSD10Emu = 0x70
|
||||
|
||||
sizeofIfMsghdrFreeBSD7Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD8Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD9Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD10Emu = 0xa8
|
||||
sizeofIfMsghdrFreeBSD11Emu = 0xa8
|
||||
|
||||
sizeofIfDataFreeBSD7Emu = 0x98
|
||||
sizeofIfDataFreeBSD8Emu = 0x98
|
||||
sizeofIfDataFreeBSD9Emu = 0x98
|
||||
sizeofIfDataFreeBSD10Emu = 0x98
|
||||
sizeofIfDataFreeBSD11Emu = 0x98
|
||||
)
|
||||
117
vendor/golang.org/x/net/route/zsys_freebsd_arm.go
generated
vendored
117
vendor/golang.org/x/net/route/zsys_freebsd_arm.go
generated
vendored
@@ -1,117 +0,0 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs defs_freebsd.go
|
||||
|
||||
package route
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = 0x0
|
||||
sysAF_INET = 0x2
|
||||
sysAF_ROUTE = 0x11
|
||||
sysAF_LINK = 0x12
|
||||
sysAF_INET6 = 0x1c
|
||||
|
||||
sysNET_RT_DUMP = 0x1
|
||||
sysNET_RT_FLAGS = 0x2
|
||||
sysNET_RT_IFLIST = 0x3
|
||||
sysNET_RT_IFMALIST = 0x4
|
||||
sysNET_RT_IFLISTL = 0x5
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = 0x18
|
||||
|
||||
sysCTL_UNSPEC = 0x0
|
||||
sysCTL_KERN = 0x1
|
||||
sysCTL_VM = 0x2
|
||||
sysCTL_VFS = 0x3
|
||||
sysCTL_NET = 0x4
|
||||
sysCTL_DEBUG = 0x5
|
||||
sysCTL_HW = 0x6
|
||||
sysCTL_MACHDEP = 0x7
|
||||
sysCTL_USER = 0x8
|
||||
sysCTL_P1003_1B = 0x9
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = 0x5
|
||||
|
||||
sysRTM_ADD = 0x1
|
||||
sysRTM_DELETE = 0x2
|
||||
sysRTM_CHANGE = 0x3
|
||||
sysRTM_GET = 0x4
|
||||
sysRTM_LOSING = 0x5
|
||||
sysRTM_REDIRECT = 0x6
|
||||
sysRTM_MISS = 0x7
|
||||
sysRTM_LOCK = 0x8
|
||||
sysRTM_RESOLVE = 0xb
|
||||
sysRTM_NEWADDR = 0xc
|
||||
sysRTM_DELADDR = 0xd
|
||||
sysRTM_IFINFO = 0xe
|
||||
sysRTM_NEWMADDR = 0xf
|
||||
sysRTM_DELMADDR = 0x10
|
||||
sysRTM_IFANNOUNCE = 0x11
|
||||
sysRTM_IEEE80211 = 0x12
|
||||
|
||||
sysRTA_DST = 0x1
|
||||
sysRTA_GATEWAY = 0x2
|
||||
sysRTA_NETMASK = 0x4
|
||||
sysRTA_GENMASK = 0x8
|
||||
sysRTA_IFP = 0x10
|
||||
sysRTA_IFA = 0x20
|
||||
sysRTA_AUTHOR = 0x40
|
||||
sysRTA_BRD = 0x80
|
||||
|
||||
sysRTAX_DST = 0x0
|
||||
sysRTAX_GATEWAY = 0x1
|
||||
sysRTAX_NETMASK = 0x2
|
||||
sysRTAX_GENMASK = 0x3
|
||||
sysRTAX_IFP = 0x4
|
||||
sysRTAX_IFA = 0x5
|
||||
sysRTAX_AUTHOR = 0x6
|
||||
sysRTAX_BRD = 0x7
|
||||
sysRTAX_MAX = 0x8
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrlFreeBSD10 = 0x68
|
||||
sizeofIfaMsghdrFreeBSD10 = 0x14
|
||||
sizeofIfaMsghdrlFreeBSD10 = 0x6c
|
||||
sizeofIfmaMsghdrFreeBSD10 = 0x10
|
||||
sizeofIfAnnouncemsghdrFreeBSD10 = 0x18
|
||||
|
||||
sizeofRtMsghdrFreeBSD10 = 0x5c
|
||||
sizeofRtMetricsFreeBSD10 = 0x38
|
||||
|
||||
sizeofIfMsghdrFreeBSD7 = 0x70
|
||||
sizeofIfMsghdrFreeBSD8 = 0x70
|
||||
sizeofIfMsghdrFreeBSD9 = 0x70
|
||||
sizeofIfMsghdrFreeBSD10 = 0x70
|
||||
sizeofIfMsghdrFreeBSD11 = 0xa8
|
||||
|
||||
sizeofIfDataFreeBSD7 = 0x60
|
||||
sizeofIfDataFreeBSD8 = 0x60
|
||||
sizeofIfDataFreeBSD9 = 0x60
|
||||
sizeofIfDataFreeBSD10 = 0x60
|
||||
sizeofIfDataFreeBSD11 = 0x98
|
||||
|
||||
sizeofIfMsghdrlFreeBSD10Emu = 0x68
|
||||
sizeofIfaMsghdrFreeBSD10Emu = 0x14
|
||||
sizeofIfaMsghdrlFreeBSD10Emu = 0x6c
|
||||
sizeofIfmaMsghdrFreeBSD10Emu = 0x10
|
||||
sizeofIfAnnouncemsghdrFreeBSD10Emu = 0x18
|
||||
|
||||
sizeofRtMsghdrFreeBSD10Emu = 0x5c
|
||||
sizeofRtMetricsFreeBSD10Emu = 0x38
|
||||
|
||||
sizeofIfMsghdrFreeBSD7Emu = 0x70
|
||||
sizeofIfMsghdrFreeBSD8Emu = 0x70
|
||||
sizeofIfMsghdrFreeBSD9Emu = 0x70
|
||||
sizeofIfMsghdrFreeBSD10Emu = 0x70
|
||||
sizeofIfMsghdrFreeBSD11Emu = 0xa8
|
||||
|
||||
sizeofIfDataFreeBSD7Emu = 0x60
|
||||
sizeofIfDataFreeBSD8Emu = 0x60
|
||||
sizeofIfDataFreeBSD9Emu = 0x60
|
||||
sizeofIfDataFreeBSD10Emu = 0x60
|
||||
sizeofIfDataFreeBSD11Emu = 0x98
|
||||
)
|
||||
91
vendor/golang.org/x/net/route/zsys_netbsd.go
generated
vendored
91
vendor/golang.org/x/net/route/zsys_netbsd.go
generated
vendored
@@ -1,91 +0,0 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs defs_netbsd.go
|
||||
|
||||
package route
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = 0x0
|
||||
sysAF_INET = 0x2
|
||||
sysAF_ROUTE = 0x22
|
||||
sysAF_LINK = 0x12
|
||||
sysAF_INET6 = 0x18
|
||||
|
||||
sysNET_RT_DUMP = 0x1
|
||||
sysNET_RT_FLAGS = 0x2
|
||||
sysNET_RT_IFLIST = 0x5
|
||||
sysNET_RT_MAXID = 0x6
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = 0xc
|
||||
|
||||
sysCTL_UNSPEC = 0x0
|
||||
sysCTL_KERN = 0x1
|
||||
sysCTL_VM = 0x2
|
||||
sysCTL_VFS = 0x3
|
||||
sysCTL_NET = 0x4
|
||||
sysCTL_DEBUG = 0x5
|
||||
sysCTL_HW = 0x6
|
||||
sysCTL_MACHDEP = 0x7
|
||||
sysCTL_USER = 0x8
|
||||
sysCTL_DDB = 0x9
|
||||
sysCTL_PROC = 0xa
|
||||
sysCTL_VENDOR = 0xb
|
||||
sysCTL_EMUL = 0xc
|
||||
sysCTL_SECURITY = 0xd
|
||||
sysCTL_MAXID = 0xe
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = 0x4
|
||||
|
||||
sysRTM_ADD = 0x1
|
||||
sysRTM_DELETE = 0x2
|
||||
sysRTM_CHANGE = 0x3
|
||||
sysRTM_GET = 0x4
|
||||
sysRTM_LOSING = 0x5
|
||||
sysRTM_REDIRECT = 0x6
|
||||
sysRTM_MISS = 0x7
|
||||
sysRTM_LOCK = 0x8
|
||||
sysRTM_OLDADD = 0x9
|
||||
sysRTM_OLDDEL = 0xa
|
||||
sysRTM_RESOLVE = 0xb
|
||||
sysRTM_NEWADDR = 0xc
|
||||
sysRTM_DELADDR = 0xd
|
||||
sysRTM_IFANNOUNCE = 0x10
|
||||
sysRTM_IEEE80211 = 0x11
|
||||
sysRTM_SETGATE = 0x12
|
||||
sysRTM_LLINFO_UPD = 0x13
|
||||
sysRTM_IFINFO = 0x14
|
||||
sysRTM_CHGADDR = 0x15
|
||||
|
||||
sysRTA_DST = 0x1
|
||||
sysRTA_GATEWAY = 0x2
|
||||
sysRTA_NETMASK = 0x4
|
||||
sysRTA_GENMASK = 0x8
|
||||
sysRTA_IFP = 0x10
|
||||
sysRTA_IFA = 0x20
|
||||
sysRTA_AUTHOR = 0x40
|
||||
sysRTA_BRD = 0x80
|
||||
sysRTA_TAG = 0x100
|
||||
|
||||
sysRTAX_DST = 0x0
|
||||
sysRTAX_GATEWAY = 0x1
|
||||
sysRTAX_NETMASK = 0x2
|
||||
sysRTAX_GENMASK = 0x3
|
||||
sysRTAX_IFP = 0x4
|
||||
sysRTAX_IFA = 0x5
|
||||
sysRTAX_AUTHOR = 0x6
|
||||
sysRTAX_BRD = 0x7
|
||||
sysRTAX_TAG = 0x8
|
||||
sysRTAX_MAX = 0x9
|
||||
)
|
||||
|
||||
const (
|
||||
sizeofIfMsghdrNetBSD7 = 0x98
|
||||
sizeofIfaMsghdrNetBSD7 = 0x18
|
||||
sizeofIfAnnouncemsghdrNetBSD7 = 0x18
|
||||
|
||||
sizeofRtMsghdrNetBSD7 = 0x78
|
||||
sizeofRtMetricsNetBSD7 = 0x50
|
||||
)
|
||||
80
vendor/golang.org/x/net/route/zsys_openbsd.go
generated
vendored
80
vendor/golang.org/x/net/route/zsys_openbsd.go
generated
vendored
@@ -1,80 +0,0 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs defs_openbsd.go
|
||||
|
||||
package route
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = 0x0
|
||||
sysAF_INET = 0x2
|
||||
sysAF_ROUTE = 0x11
|
||||
sysAF_LINK = 0x12
|
||||
sysAF_INET6 = 0x18
|
||||
|
||||
sysNET_RT_DUMP = 0x1
|
||||
sysNET_RT_FLAGS = 0x2
|
||||
sysNET_RT_IFLIST = 0x3
|
||||
sysNET_RT_STATS = 0x4
|
||||
sysNET_RT_TABLE = 0x5
|
||||
sysNET_RT_IFNAMES = 0x6
|
||||
sysNET_RT_MAXID = 0x7
|
||||
)
|
||||
|
||||
const (
|
||||
sysCTL_MAXNAME = 0xc
|
||||
|
||||
sysCTL_UNSPEC = 0x0
|
||||
sysCTL_KERN = 0x1
|
||||
sysCTL_VM = 0x2
|
||||
sysCTL_FS = 0x3
|
||||
sysCTL_NET = 0x4
|
||||
sysCTL_DEBUG = 0x5
|
||||
sysCTL_HW = 0x6
|
||||
sysCTL_MACHDEP = 0x7
|
||||
sysCTL_DDB = 0x9
|
||||
sysCTL_VFS = 0xa
|
||||
sysCTL_MAXID = 0xb
|
||||
)
|
||||
|
||||
const (
|
||||
sysRTM_VERSION = 0x5
|
||||
|
||||
sysRTM_ADD = 0x1
|
||||
sysRTM_DELETE = 0x2
|
||||
sysRTM_CHANGE = 0x3
|
||||
sysRTM_GET = 0x4
|
||||
sysRTM_LOSING = 0x5
|
||||
sysRTM_REDIRECT = 0x6
|
||||
sysRTM_MISS = 0x7
|
||||
sysRTM_LOCK = 0x8
|
||||
sysRTM_RESOLVE = 0xb
|
||||
sysRTM_NEWADDR = 0xc
|
||||
sysRTM_DELADDR = 0xd
|
||||
sysRTM_IFINFO = 0xe
|
||||
sysRTM_IFANNOUNCE = 0xf
|
||||
sysRTM_DESYNC = 0x10
|
||||
|
||||
sysRTA_DST = 0x1
|
||||
sysRTA_GATEWAY = 0x2
|
||||
sysRTA_NETMASK = 0x4
|
||||
sysRTA_GENMASK = 0x8
|
||||
sysRTA_IFP = 0x10
|
||||
sysRTA_IFA = 0x20
|
||||
sysRTA_AUTHOR = 0x40
|
||||
sysRTA_BRD = 0x80
|
||||
sysRTA_SRC = 0x100
|
||||
sysRTA_SRCMASK = 0x200
|
||||
sysRTA_LABEL = 0x400
|
||||
|
||||
sysRTAX_DST = 0x0
|
||||
sysRTAX_GATEWAY = 0x1
|
||||
sysRTAX_NETMASK = 0x2
|
||||
sysRTAX_GENMASK = 0x3
|
||||
sysRTAX_IFP = 0x4
|
||||
sysRTAX_IFA = 0x5
|
||||
sysRTAX_AUTHOR = 0x6
|
||||
sysRTAX_BRD = 0x7
|
||||
sysRTAX_SRC = 0x8
|
||||
sysRTAX_SRCMASK = 0x9
|
||||
sysRTAX_LABEL = 0xa
|
||||
sysRTAX_MAX = 0xb
|
||||
)
|
||||
Reference in New Issue
Block a user