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: implement interface fmt.Stringer on BPF instructions #18538
Comments
/cc @danderson @mikioh |
This seems fine, and a CL would be welcome as far as I'm concerned (though I don't have direct commit access, @mikioh has the final say there). The only thing I'm worried about is what to do about RawInstruction. By design, RawInstruction is also an Instruction, so that programmers can specify custom opcodes for forks of the BPF machine. Those instructions might not match a known instruction of the Linux BPF implementation, so... What does String() return for that? I suppose the simplest option is simply to not implement |
It is not my intend to extend the existing |
I'll push the submit button once @danderson is happy. |
@breml's plan sounds great to me. Is there a CL already? I'll happily review one. |
@danderson there is not yet a CL. The implementation is straight forward. Currently I am looking for the best way to implement the tests. One possibility would be to add a go style table driven test which includes for every bpf.Instruction the expected string. @danderson what do you suggest? |
@danderson Just uploaded a CL, which uses option 1 for the tests (see my previous comment). |
CL https://golang.org/cl/35171 mentions this issue. |
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>
What version of Go are you using (
go version
)?go version go1.7.4 linux/amd64
What operating system and processor architecture are you using (
go env
)?linux, amd64
What did you do?
I would like to print bpf.Instructions in the assembler notation defined in https://www.kernel.org/doc/Documentation/networking/filter.txt.
What did you expect to see?
I suggest to implement
fmt.Stringer
an all types which implementbpf.Instruction
.For example the instructions
could be printed as
I have an implementation for the output in assembler notation (without
fmt.Stringer
): https://github.com/breml/bpfutils/blob/master/string.go#L26-L218 and I offer to provide a CL for the above suggestion, if this change is accepted.What did you see instead?
Is not implemented.
The text was updated successfully, but these errors were encountered: