Closed jrester closed 3 years ago
Thanks for the PR! This will be great to add.
I would like an example added to the repo and added to the CI test suite. I think it's okay to add the dev-dependency for the example.
One thing that's unclear to me - it looks like we can only add a single BPF program that attaches to a socket? This seems like it might be a limitation for systems with multiple NICs. I'm unsure if BPF would allow us to attach multiple programs to the same interface, but if that's possible, we should allow for that here too. I think we'd just need to switch to using a HashSet<Socket>
unless there are specific limitations I'm unaware of.
Thanks again!
I added the example and it now also supports multiple interfaces.
Any chance of this getting merged?
First, thanks for this PR and for iterating on this. I do appreciate the effort to add additional functionality to this crate.
At this point, I'm concerned that this addition isn't fitting with the rest of the crate's goal of providing friendly Rust-y interface and experience for its users. I suspect this could be fixed, perhaps by using the raw socket types in socket2
crate? To be honest I'm not quite sure what the fix is going to be. Sorry that I'm unable to give some more concrete guidance on this, I'd need to spend some time to become more familiar with this BPF functionality and consider how we could provide it in a friendly way within this crate.
In the interest of preserving a consistent feel for our users, I am currently unwilling to merge this PR as it stands.
ok, than i am closing this.
This adds support for attach_raw_socket. The interface is exposed by a new struct
Socket
. To attach to a socket it first has to be created the file descriptor has to be available to the user. As such I introducedBPF::get_socket_fd
. I wasn't sure about the use of the feature flags so I didn't include any. Do I need to add those?Fixes #65
An example requires
libc
as such I didn't include it in the PR. A possible example, which is inspired by http_filter:main.rs:
filter.c:
Just run
$ curl localhost
and one should see the packet content as bytes printed to stdout.If you want, I can also add this example to the PR.