Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All helper functions and context methods are returning
c_long
as an error. Before this change, aya-template and book examples were adjusting the error type intry_*
functionns return type of the program. For example, for XDP programs programs, which returnu32
, the type returned bytry_*
functions, wasResult<u32, u32>
.This approach is forcing people to write boilerplate code for casting errors from
c_long
to the expected type, like:This change solves that problem by:
Result<i32, c_long>
as a type fortry_*
functions for SKB-based programs and then replacing errors withTC_ACT_SHOT
or0
once in the main program function.Result<u32, c_long>
as a type fortry_*
functions intry_*
funnctions for XDP programs and then replacing errors withXDP_ABORT
.Result<u32, c_long>
orResult<i32, c_long>
as types intry_*
functions for all other program types where the return value matters (LSM, sysctl etc.) and replacing the error either with0
or1
(depending on which number means "block the action" for particular type of program).Result<(), c_long
for all other program types where the return value doesn't matter (kprobe, uprobe etc.).So errors can be handled without casting, like:
The other changes included in this commit are:
core::ffi::c_long
instead ofaya_cty::c_long
, like book examples (they have to be changed too).