+
Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Conversation

raftario
Copy link
Contributor

@raftario raftario commented Nov 9, 2021

This pull request is pretty simple and just adds support for loading sk_lookup programs to the redbpf crate. I'm opening it as a draft as

  1. Support hasn't been added to the rest of the crates
    2. sk_lookup requires a relatively recent kernel version (5.9) and merging this would probably break things for many people

Point 1 could be addressed by simply building upon this to add support everywhere else (I'll probably do it at some point but I don't personally need it at the moment), while for point 2 it might be interesting to consider feature-gating different program types.

@rhdxmr
Copy link
Collaborator

rhdxmr commented Nov 10, 2021

Hello @raftario

This feature looks cool!

Thanks to this PR I got to know about sk lookup feature.
I just read this article: https://lwn.net/Articles/819618/
(I don't understand all yet)

IMO it's okay to include new kernel features in RedBPF. Even though sk lookup feature
exists in RedBPF, users who don't use this feature can continue to use RedBPF
with the older Linux kernel. Because nothing would be executed unless they call
the new functions.

If users have problems while they try calling the sk lookup functions with the
older kernel, users should handle their kernel version issue. But brief note
about the minimum kernel version for sk lookup would be helpful to users.

And you concerned that you implemented only the userspace part of sk
lookup. Don't worry about this. Somebody or you can freely implement the half
part for BPF programs later.


pub fn set(&mut self, mut idx: u32, mut fd: RawFd) -> Result<()> {
pub fn set(&mut self, mut idx: u32, fd: RawFd) -> Result<()> {
let mut fd = fd as u64;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raftario
I'm not sure why you changed this.
Can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a temporary fix of mine, I tested my changes with the code from this talk which uses sizeof(__u64) as the value size for its socket map, so passing it a pointer to a 32bit value caused errors. This can probably be removed given the value size should be sizeof(int).

@raftario
Copy link
Contributor Author

raftario commented Nov 10, 2021

I'm not particularly familiar with the library so I was probably confused. I just assumed that since bpf-sys uses bindgen, and bpf.h in libbpf includes linux/bpf.h, the bindings for sk_lookup types would not be generated on older kernels since they aren't present in the kernel headers, and useing them from redbpf would fail to compile on those systems.

@raftario
Copy link
Contributor Author

Would you be interested in merging this without support in the other crates ?

@rhdxmr
Copy link
Collaborator

rhdxmr commented Nov 11, 2021

@raftario
Yes, I welcome your contribution.
API for BPF programs can be implemented later.
Before this PR get merged to main branch, we have to make sure userspace API clear.

I wonder how you used this API. Can you add some example as a doc comment in the SkLookup structure?

@raftario
Copy link
Contributor Author

I'll add some documentation and convert to a proper PR then !

Signed-off-by: Raphaël Thériault <self@raftar.io>
Signed-off-by: Raphaël Thériault <self@raftar.io>
Signed-off-by: Raphaël Thériault <self@raftar.io>
Signed-off-by: Raphaël Thériault <self@raftar.io>
Signed-off-by: Raphaël Thériault <self@raftar.io>
@raftario raftario marked this pull request as ready for review November 15, 2021 05:49
fn drop(&mut self) {
if let Some((nfd, lfd)) = self.link.take() {
unsafe {
libc::close(lfd);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raftario
I am confused that bpf_link_detach is needed or not.

  • Only close is needed?
  • bpf_link_detach has nothing to do with cleanup?
  • bpf_link_detach is called first and then close should be called?

Can you explain about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you never pin the link, it'll automatically be cleaned up when the file descriptor is closed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I got it. Thank you.

Copy link
Collaborator

@rhdxmr rhdxmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is great! 👍
Code is very neat and clean. Doc comment is elaborate.
Added code looks harmonious.

Thank you for your contribution I am going to merge this happily 🙋

@rhdxmr rhdxmr merged commit e09f22c into foniod:main Nov 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载