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-ebpf: XdpContext adjust_{head|tail|meta} API #949

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion ebpf/aya-ebpf/src/programs/xdp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use core::ffi::c_void;

use crate::{bindings::xdp_md, EbpfContext};
use crate::{
bindings::xdp_md,
helpers::{bpf_xdp_adjust_head, bpf_xdp_adjust_meta, bpf_xdp_adjust_tail},
EbpfContext,
};

pub struct XdpContext {
pub ctx: *mut xdp_md,
Expand Down Expand Up @@ -32,6 +36,42 @@ impl XdpContext {
pub fn metadata_end(&self) -> usize {
self.data()
}

/// Adjusts the head of the Packet by given 'delta' (both positive and negative values are
/// possible.)
#[inline(always)]
pub fn adjust_head(&mut self, delta: crate::cty::c_int) -> Result<(), ()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

here and in the other methods I think we should use i32, not c_int.

unsafe {
match bpf_xdp_adjust_head(self.ctx, delta) {
0 => Ok(()),
_ => Err(()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not return the error?

}
}
}

/// Adjusts the tail of the Packet by given 'delta' (both positive and negative values are
/// possible.)
#[inline(always)]
pub fn adjust_tail(&mut self, delta: crate::cty::c_int) -> Result<(), ()> {
unsafe {
match bpf_xdp_adjust_tail(self.ctx, delta) {
0 => Ok(()),
_ => Err(()),
}
}
}

/// Adjusts the tail of the Packet by given 'delta' (both positive and negative values are
/// possible.)
#[inline(always)]
pub fn adjust_metadata(&mut self, delta: crate::cty::c_int) -> Result<(), ()> {
unsafe {
match bpf_xdp_adjust_meta(self.ctx, delta) {
0 => Ok(()),
_ => Err(()),
}
}
}
}

impl EbpfContext for XdpContext {
Expand Down
6 changes: 6 additions & 0 deletions xtask/public-api/aya-ebpf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,9 @@ pub mod aya_ebpf::programs::xdp
pub struct aya_ebpf::programs::xdp::XdpContext
pub aya_ebpf::programs::xdp::XdpContext::ctx: *mut aya_ebpf_bindings::x86_64::bindings::xdp_md
impl aya_ebpf::programs::xdp::XdpContext
pub fn aya_ebpf::programs::xdp::XdpContext::adjust_head(&mut self, delta: aya_ebpf_cty::ad::c_int) -> core::result::Result<(), ()>
pub fn aya_ebpf::programs::xdp::XdpContext::adjust_metadata(&mut self, delta: aya_ebpf_cty::ad::c_int) -> core::result::Result<(), ()>
pub fn aya_ebpf::programs::xdp::XdpContext::adjust_tail(&mut self, delta: aya_ebpf_cty::ad::c_int) -> core::result::Result<(), ()>
pub fn aya_ebpf::programs::xdp::XdpContext::data(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::data_end(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::metadata(&self) -> usize
Expand Down Expand Up @@ -2624,6 +2627,9 @@ pub fn aya_ebpf::programs::tracepoint::TracePointContext::from(t: T) -> T
pub struct aya_ebpf::programs::XdpContext
pub aya_ebpf::programs::XdpContext::ctx: *mut aya_ebpf_bindings::x86_64::bindings::xdp_md
impl aya_ebpf::programs::xdp::XdpContext
pub fn aya_ebpf::programs::xdp::XdpContext::adjust_head(&mut self, delta: aya_ebpf_cty::ad::c_int) -> core::result::Result<(), ()>
pub fn aya_ebpf::programs::xdp::XdpContext::adjust_metadata(&mut self, delta: aya_ebpf_cty::ad::c_int) -> core::result::Result<(), ()>
pub fn aya_ebpf::programs::xdp::XdpContext::adjust_tail(&mut self, delta: aya_ebpf_cty::ad::c_int) -> core::result::Result<(), ()>
pub fn aya_ebpf::programs::xdp::XdpContext::data(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::data_end(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::metadata(&self) -> usize
Expand Down