Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net/bpf: NegateA is not implemented for VM #16109

Closed
mdlayher opened this issue Jun 18, 2016 · 1 comment
Closed

x/net/bpf: NegateA is not implemented for VM #16109

mdlayher opened this issue Jun 18, 2016 · 1 comment

Comments

@mdlayher
Copy link
Member

@mdlayher mdlayher commented Jun 18, 2016

Using this as a tracking issue to see if it's feasible to allow bpf.NegateA to be processed by the bpf.VM type.

My research thus far shows that the BPF VM treats any negative result as "return all bytes".

Here's the test I'm writing:

func TestVMNegateA(t *testing.T) {
        vm, done, err := testVM(t, []bpf.Instruction{
                bpf.LoadAbsolute{
                        Off:  8,
                        Size: 1,
                },
                bpf.NegateA{},
                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, 4, 5,
        })
        if err != nil {
                t.Fatalf("unexpected error while running program: %v", err)
        }
        if want, got := 5, out; want != got {
                t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
                        want, got)
        }
}

And the results using the current VM:

$ go test -v -run=TestVMNegateA .
=== RUN   TestVMNegateA
--- FAIL: TestVMNegateA (0.00s)
        vm_bpf_test.go:120: output byte count does not match:
                - go: 0
                - os: 5
        vm_bpf_test.go:124: Go BPF and OS BPF packet outputs do not match
FAIL
exit status 1
FAIL    golang.org/x/net/bpf    0.002s

Same logic seems to apply when subtraction brings the register results below zero. Will keep working on this and try to submit a CL to enable this functionality in the near future.

/cc @danderson

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jun 20, 2016
@mdlayher
Copy link
Member Author

@mdlayher mdlayher commented Mar 18, 2019

I'm going to close this out as unnecessary.

@golang golang locked and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants