-
Notifications
You must be signed in to change notification settings - Fork 286
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: Add from_pin for Programs #496
Conversation
✅ Deploy Preview for aya-rs-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
ea44857
to
662548d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems largely ok! See comments
3027156
to
6289b77
Compare
@alessandrod changes addressed.
|
45923f6
to
75e6444
Compare
Updated to fix CI... {
let prog = Xdp::from_pin("/path/to/prog").unwrap();
prog.attach("eth0");
}
// Link should get detached here and program fd should be closed When I moved |
This now will not drop programs unless you access them through concrete program types tho right? Eg if you Bpf::load and never create a concrete program |
75e6444
to
0806b9e
Compare
aya/src/programs/mod.rs
Outdated
pub(crate) fn from_pinned_path<P: AsRef<Path>>( | ||
path: P, | ||
) -> Result<ProgramData<T>, ProgramError> { | ||
let path_string = std::ffi::CString::new(path.as_ref().to_str().unwrap()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use to_string_lossy here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also import types, don't use full qualified paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, so Path -> Cstring isn't exactly easy, but this is what I settled on.
CString::new(path.as_ref().as_os_str().to_string_lossy().as_bytes())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
This commit adds from_pin() which allows the creation of a Program from a path on bpffs. This is useful to be able to call `attach` or other APIs for programs that are already loaded to the kernel. This differs from aya-rs#444 since it implements this on the concrete program type, not the Program enum, allowing the user to pass in any additional context that isn't available from bpf_prog_info. Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
0806b9e
to
7a720ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Feel free to merge on green
This commit adds from_pin() which allows the creation of a Program from a path on bpffs. This is useful to be able to call
attach
or other APIs for programs that are already loaded to the kernel.This differs from #444 since it implements this on the concrete program type, not the Program enum, allowing the user to pass in any additional context that isn't available from bpf_prog_info.
Signed-off-by: Dave Tucker dave@dtucker.co.uk