Commit Graph

23 Commits

Author SHA1 Message Date
cui fliter
bea034e7d5 all: remove redundant type conversion
Change-Id: I37550b85567abd2f5b422e742fcea9b26fd80f2b
GitHub-Last-Rev: b2e840379d
GitHub-Pull-Request: golang/net#148
Reviewed-on: https://go-review.googlesource.com/c/net/+/428937
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-09 16:43:09 +00:00
Russ Cox
290c469a71 all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: Iae68a9cd600060577271575e893ecb23bed1e509
Reviewed-on: https://go-review.googlesource.com/c/net/+/399599
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-12 02:06:05 +00:00
Arthur Fabre
27ecd3f315 bpf: fix VM out of bounds LoadMemShift check
The bpf VM did not correctly check the bounds of LoadMemShift
instructions, as it used a size of 0 instead of the correct 1.

A LoadMemShift instruction 1 past the end of the input resulted in a
runtime panic:

    panic(0x5c1d40, 0x7cec00)
            /usr/local/go/src/runtime/panic.go:522 +0x1b5
    golang.org/x/net/bpf.loadMemShift(...)
            /home/afabre/go/pkg/mod/golang.org/x/net@v0.0.0-20190603091049-60506f45cf65/bpf/vm_instructions.go:137
    golang.org/x/net/bpf.(*VM).Run(0xc00000ec40, 0xc0000173c8, 0x2, 0x8, 0x2, 0xc0000173c8, 0x0)
            /home/afabre/go/pkg/mod/golang.org/x/net@v0.0.0-20190603091049-60506f45cf65/bpf/vm.go:131 +0xb0a

Fix this, and rework the out of bounds tests for load instructions to:

* Use an offset one past the end of the input, to catch this

* Use a filter that returns 1, to catch cases were the out of bounds
load does not cause a panic, but does not cause the VM to return 0.

Change-Id: I1e68886915207a34f59765805f907f36dc031f70
Reviewed-on: https://go-review.googlesource.com/c/net/+/180979
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2019-06-07 17:17:31 +00:00
Mikio Hara
9bff7f1a9d bpf: use of nettest
To ensure tests never fail on IPv6-only kernels.

Change-Id: I40713d00ba6066da69c84f5cd506a2243360e057
Reviewed-on: https://go-review.googlesource.com/c/net/+/169577
Run-TryBot: Mikio Hara <mikioh.public.networking@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2019-03-27 21:43:19 +00:00
Arthur Fabre
49bb7cea24 bpf: support JumpIf on RegX instead of K
Add a JumpIfX instruction which implements conditional jumps using
RegA and RegX. This is in addition to the pre-existing JumpIf
instruction which uses RegA and K.

This instruction / addressing mode is not mentionned in the original BPF
paper, but is supported by tools like bpf_asm, and has recently been
added to the kernel's filter.txt.

Simplify some of the parsing logic, and add a separate helper for
checking for "fake" JumpIfs.

Add JumpIfX support to the BPF vm.

Update testdata with JumpIfX instructions, and add tests
for both the assembler/disassembler and vm.

Fixes golang/go#27814

Change-Id: I0c3f6ac7eb5b4cd4d9c5af8784ee2e8d25195a0a
GitHub-Last-Rev: 39a88165b2
GitHub-Pull-Request: golang/net#20
Reviewed-on: https://go-review.googlesource.com/c/136895
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-11 14:41:30 +00:00
namusyaka
cbe0f9307d all: remove "the" duplications
Change-Id: I5dc9a8fa647ccb34caae9a1342012cb36d1fcc22
Reviewed-on: https://go-review.googlesource.com/94975
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-18 17:54:43 +00:00
Matt Layher
9c9a3f3e9f bpf: add Setter interface
This interface can be implemented by types which are capable of
attaching compiled BPF filters to themselves, such as
x/net/ipv{4,6}.PacketConn.

Fixes golang/go#19912

Change-Id: I4674c3e312c173d5a7a3beb3cd53704f8c08e29b
Reviewed-on: https://go-review.googlesource.com/44972
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2017-06-13 04:21:24 +00:00
Lucas Bremgartner
e4fa1c5465 bpf: fix type of Extension constants
Fixes golang/go#20559

Change-Id: Ieb794badb56c6830e32028133f67223424323ea2
Reviewed-on: https://go-review.googlesource.com/44710
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-02 20:15:53 +00:00
Mikio Hara
aa0b216c89 Revert "ipv4, ipv6, internal/netreflect, bpf: fix the x/net build"
This reverts https://go-review.googlesource.com/c/37401

Updates golang/go#19051.

Change-Id: Ia3cbc42213e3c519f91650e6308a7ca1f56b6189
Reviewed-on: https://go-review.googlesource.com/37417
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-05-24 08:43:35 +00:00
Brad Fitzpatrick
b64f02211f ipv4, ipv6, internal/netreflect, bpf: fix the x/net build
The x/net package is currently broken for Go 1.9 (#19051) so
I am unable to use trybots for x/net/http2.

This disables the tests for the broken stuff and makes things compile
at least, so x/net trybots aren't broken for others.

Updates golang/go#19051

Change-Id: I67401d7ad32d855e99a417545328eb4e803287cc
Reviewed-on: https://go-review.googlesource.com/37401
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2017-02-23 22:48:12 +00:00
Dmitri Shuralyov
357296a763 all: single space after period
The tree's pretty inconsistent about single space vs double space
after a period in documentation. Make it consistently a single space,
per earlier decisions, and changes in go repository. This means
contributors won't be confused by misleading precedence.

This CL was generated with:

	perl -i -npe 's,^(\s*// .+[a-z]\.)  +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.)  +([A-Z])')

on top of copyright headers change in https://golang.org/cl/32878.

Follows https://golang.org/cl/20022.

Change-Id: I821e4a300122b4668aa31e12eaa914db615e5369
Reviewed-on: https://go-review.googlesource.com/32879
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-01 21:02:21 +00:00
Lucas Bremgartner
0ab64c594a bpf: implement fmt.Stringer for BPF instructions
Fixes golang/go#18538

Change-Id: Ic0627352f96ad5fa138633d1e1ccfaf76294d621
Reviewed-on: https://go-review.googlesource.com/35171
Run-TryBot: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: David Anderson <dave@natulte.net>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-01-13 23:27:50 +00:00
Lucas Bremgartner
da2b4fa285 x/net/bpf: cleanup TestAsmDisasm
The "fake" jump conditions as well as the LoadExtension instructions
are now disassembled correctly. Therefore the workaround to reassemble
the disassembly is no longer necessary.

This simplification was annonced already in golang/go#18470.

Result of `go test -cover .` stays the same with this simplification.

$ go test -cover golang.org/x/net/bpf
ok  	golang.org/x/net/bpf	0.495s	coverage: 92.3% of statements

Change-Id: I3f9eb46148287c76059437b773b80c4c99eb5b53
Reviewed-on: https://go-review.googlesource.com/34951
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2017-01-08 16:05:05 +00:00
Lucas Bremgartner
ae05321a78 bpf: disasm load extension to type LoadExtension
Load extension in BPF is an overload of the load absolute
instruction with a 'negative offset'. Disassemble load
absolute instructions to load extension, if the offset
is 'negative', respectively > (0xFFFFFFFF - 0x1000).

Fixes golang/go#18469

Change-Id: I13af8f5af89ce26b13a35d2b06879dd6e1c7434e
Reviewed-on: https://go-review.googlesource.com/34771
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2017-01-07 11:07:15 +00:00
Lucas Bremgartner
279e808814 bpf: disasm "fake" jump conditions
JumpNotEqual, JumpLessThan and JumpLessOrEqual are "fake" jump
conditions that don't appear in the machine code. Nevertheless
these instructions (jneq/jne, jlt, jle) are listed in the
specification and therefore they should be reconstructed from the
machine code.

Fixes golang/go#18470

Specification: https://www.kernel.org/doc/Documentation/networking/filter.txt

Change-Id: I9116b99056e379d89e71adc90516c6747d388e5d
Reviewed-on: https://go-review.googlesource.com/34772
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2017-01-07 00:14:27 +00:00
Matt Layher
7c71ca708c bpf: implement LoadExtension and ExtLen for VM
Change-Id: I29487b0c1fdea97b5c35d22b4f7c23e11e7ceeed
Reviewed-on: https://go-review.googlesource.com/24272
Reviewed-by: David Anderson <danderson@google.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
2016-06-20 21:42:44 +00:00
Mikio Hara
8bf2b39827 bpf: fix a typo
Change-Id: I5b865483bf6a8bba07934ae3b1ff5bbbf6dd6a00
Reviewed-on: https://go-review.googlesource.com/24240
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Tom Heng <zhm20070928@gmail.com>
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
2016-06-19 23:45:41 +00:00
Matt Layher
1961d9def2 bpf: add Go implementation of virtual machine
Fixes golang/go#16055.

Change-Id: I80437e2895b0f2bf23e090dec29bd20c2900db9a
Reviewed-on: https://go-review.googlesource.com/24136
Reviewed-by: David Anderson <danderson@google.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2016-06-18 00:31:17 +00:00
David Anderson
3e8a7b0329 bpf: rename LoadIPv4HeaderLen to the more generic LoadMemShift.
The instruction itself doesn't care what the bits it's twiddling represents,
even though the it was introduced to more efficiently manipulate IPv4 packets.

Change-Id: Ie65a6df4041ad2090060636ccf7128680fcf75b7
Reviewed-on: https://go-review.googlesource.com/21244
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2016-03-31 21:48:25 +00:00
David Anderson
1dd0d85fc0 bpf: correct spelling of marshaling in package doc.
Change-Id: Ied9b2589b4aa5cb445dd368864df047c84848a95
Reviewed-on: https://go-review.googlesource.com/21217
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2016-03-28 08:44:40 +00:00
David Anderson
27276f6b36 bpf: add package documentation describing the BPF virtual machine.
Change-Id: I2fcb07bdc104c488aa61a6c6b6ee8797e60e868a
Reviewed-on: https://go-review.googlesource.com/21216
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2016-03-28 07:53:43 +00:00
David Anderson
9c7b3c72db bpf: simplify disasm state machine.
The code ends up slightly longer, but the decoding is more consistent from
one instruction class to another, so hopefully it's easier to make sense of it.

Change-Id: Ia22c2ebb0865536da0c3dac6876bdb0b20075f04
Reviewed-on: https://go-review.googlesource.com/21215
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-28 07:27:13 +00:00
David Anderson
3c208088b6 bpf: new package to assemble and disassemble Berkeley Packet Filter programs.
The package currently implements the operations defined by
https://www.kernel.org/doc/Documentation/networking/filter.txt , which
comprises the base BPF virtual machine plus the Linux kernel's extension
opcodes.

Updates golang/go#14982

Change-Id: Iafb43d80e067040e60465a9bfb7d5f2ca90cc2ae
Reviewed-on: https://go-review.googlesource.com/21212
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2016-03-28 06:22:12 +00:00