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

aya is missing query features #2

Closed
seanyoung opened this issue Jun 16, 2021 · 6 comments
Closed

aya is missing query features #2

seanyoung opened this issue Jun 16, 2021 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@seanyoung
Copy link
Contributor

libbpf has the bpf_prog_query() function to get a list of the all attached programs; it is also possible to deattach them and get their names.

I am currently re-writing ir-keytable in rust https://github.com/seanyoung/ir (early stages). For aya to be useful for this work, it would require this functionality.

@alessandrod
Copy link
Collaborator

The query I'm thinking should probably be a helper function in the aya::programs, and be something like

fn query<T: AsRawFd>(target_fd: T, attach_type: XXX, flags: u32) -> Result<(Vec<u32>, u32), io::Error>

Where the result is a Vec of prog ids and the attach flags. As for the XXX type , we could re-export crate::generated::bpf_attach_type as aya::programs::AttachType for now, or we could create a new enum and keep it in sync, bpf_attach_type doesn't change that often anyway.

To get the name then you'd use a separate syscall right?

As for detaching, I'm not sure yet what we could do. I know I want to add a forget() method to the Link trait (related to your other PR), but haven't thought about what the API to detach an arbitrary fd/type would look like.

@seanyoung
Copy link
Contributor Author

I do wonder if it is possible to create a higher level of abstraction than (Vec<u32>, u32). I think it would be nicer if we returned a list of programs, which had a detach() and info() method of some sort. struct bpf_prog_info contains a lot of information, not just the name.

@alessandrod
Copy link
Collaborator

Yes you're right, we should definitely create a higher level API. I guess my thinking was that coming up with a higher level interface would probably require some work (see below), so we could start by wrapping the syscall. Now that I've thought about it though, I think I was overthinking it.

Agreed on info(), we should have it return a type that contains everything useful from struct bpf_prog_info. And about detach(), I was thinking that it would be tricky ensuring that it doesn't break things if you have other Links laying around, but that's not the case. All the existing Link::detach() impls already ignore errors on detach. And regardless of what interface we come up with, we need to handle other programs (eg bpftool) potentially detaching our links anyway.

So yeah, this is easier than I first thought :)

@alessandrod alessandrod added the enhancement New feature or request label Jun 21, 2021
@alessandrod
Copy link
Collaborator

@seanyoung are you planning to do or have you done any work on this? Otherwise I might get to it next week

@seanyoung
Copy link
Contributor Author

@alessandrod I had started on this, see my query branch https://github.com/seanyoung/aya/commits/query. The query of programs and their names works, but not detaching or any other field than name.

There are some issues which I haven't figured out yet. This where I am at.

  • The query interface is bpf program dependent, for example the query_flags are bpf program/attach dependent, so I think the query interface should exist on the specific program type (e.g. LircMode2)
  • The interface for querying the bpf_info is generic and can be shared
  • The interface for detaching the program is specific for the program type and should probably be shared with the bpf program specific detach code (for programs which were attached, not found via query interface).

So I was kind of stuck on how to model this. The QueryProgram isn't going to work for detaching, but will work for a generic info querying.

@tamird
Copy link
Member

tamird commented Jul 19, 2023

Looks like #32 was meant to close this.

@tamird tamird closed this as completed Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants