qmonnet / rbpf

Rust virtual machine and JIT compiler for eBPF programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider moving exampels to examples/ directory

badboy opened this issue · comments

This way they are automatically compiled on test and provide a ready-to-use example file for user.
For the bigger example loading an elf it might be a nice idea to include a minimal C file and how to compile it to use with the example. Dependencies for that example need dependencies, which can be added as dev-dependencies.

If interested I can take care of that.

What examples do you intend to move? Do you mean the one from the README? If so, most of them (or in very similar form) are already compiled from the tests directory, so that would not make sense duplicating them I guess.

The notable exception is the test loading the program from an object file. I did not wanted to compile it since it requires dependencies for this test only, and not for the lib. Do you mean that with dev-dependencies, we can import the deps for the tests only, not when using the crate from another project? If so, that would be a great addition indeed.

Including a minimal C file is something I would like to do, but there is an issue: a program compiled from clang cannot work “as is” if it takes packet data, because a small number of instructions have to be modified (see details in these comments and in the program bytecode of the related example). In the Linux kernel, these instructions are re-written by the verifier. Unless we can find a way to fix this, I am not sure we should have an example that tells people how to compile + manually edit the code to have it work. This is not very clean. But on the other hand, having a small “tutorial” for this could be a workaround until we manage to fix it… Thoughts? Is my description of the problem clear enough?

Oh, I see. I could have read the text surrounding the examples from the README, it clearly says so :D
I did not take a too deep look into the other example at the moment, so I didn't know it can't run as-is.

Regarding dev-dependencies: Yes, they would only be needed when developing this crate (e.g. executing its examples), but are not required for any other crates depending on rbpf directly.

Once I got through a bit of the code and the example I'll think about a better way to provide the example to users. Until then we can close this.

P.S.: Also thanks for this project. I'm currently heavily working with ebpf and thus also thought about implementing something like this just for fun.

Ok, then I think it would be nice to add the example that loads an object file at some point, even if it is modified after compiling (to show how to load an object file). And later add an example with a file to compile, if we find a way to support it.

Anyway, thanks a lot! On a side note I am discovering Rust, and you seem much more comfortable with it, so don't hesitate to provide hints if you see “poorly rusted” code when playing with the lib :-)