mirror of https://github.com/aya-rs/aya
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
883 B
Rust
42 lines
883 B
Rust
use core::ffi::c_void;
|
|
|
|
use crate::{bindings::xdp_md, EbpfContext};
|
|
|
|
pub struct XdpContext {
|
|
pub ctx: *mut xdp_md,
|
|
}
|
|
|
|
impl XdpContext {
|
|
pub fn new(ctx: *mut xdp_md) -> XdpContext {
|
|
XdpContext { ctx }
|
|
}
|
|
|
|
#[inline]
|
|
pub fn data(&self) -> usize {
|
|
unsafe { (*self.ctx).data as usize }
|
|
}
|
|
|
|
#[inline]
|
|
pub fn data_end(&self) -> usize {
|
|
unsafe { (*self.ctx).data_end as usize }
|
|
}
|
|
|
|
/// Return the raw address of the XdpContext metadata.
|
|
#[inline(always)]
|
|
pub fn metadata(&self) -> usize {
|
|
unsafe { (*self.ctx).data_meta as usize }
|
|
}
|
|
|
|
/// Return the raw address immediately after the XdpContext's metadata.
|
|
#[inline(always)]
|
|
pub fn metadata_end(&self) -> usize {
|
|
self.data()
|
|
}
|
|
}
|
|
|
|
impl EbpfContext for XdpContext {
|
|
fn as_ptr(&self) -> *mut c_void {
|
|
self.ctx as *mut _
|
|
}
|
|
}
|