mirror of https://github.com/aya-rs/aya
[TBS] addressing dave's comments
parent
7edbf20563
commit
401edc1c9a
@ -1,34 +1,44 @@
|
|||||||
use aya_ebpf_cty::c_void;
|
use aya_ebpf_cty::{c_long, c_void};
|
||||||
|
|
||||||
use crate::{EbpfContext, bindings::__sk_buff};
|
use crate::{
|
||||||
|
EbpfContext,
|
||||||
|
bindings::{__sk_buff, bpf_flow_keys},
|
||||||
|
programs::sk_buff::SkBuff,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct FlowDissectorContext {
|
pub struct FlowDissectorContext {
|
||||||
skb: *mut __sk_buff,
|
skb: SkBuff,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlowDissectorContext {
|
impl FlowDissectorContext {
|
||||||
pub fn new(skb: *mut __sk_buff) -> FlowDissectorContext {
|
pub fn new(skb: *mut __sk_buff) -> FlowDissectorContext {
|
||||||
|
let skb = SkBuff { skb };
|
||||||
FlowDissectorContext { skb }
|
FlowDissectorContext { skb }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn data(&self) -> usize {
|
pub fn data(&self) -> usize {
|
||||||
unsafe { (*self.skb).data as usize }
|
self.skb.data()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn data_end(&self) -> usize {
|
pub fn data_end(&self) -> usize {
|
||||||
unsafe { (*self.skb).data_end as usize }
|
self.skb.data_end()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn flow_keys(&self) -> usize {
|
pub fn flow_keys(&mut self) -> &mut bpf_flow_keys {
|
||||||
unsafe { (*self.skb).__bindgen_anon_1.flow_keys as usize }
|
unsafe { &mut *(*self.skb.skb).__bindgen_anon_1.flow_keys }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn load_bytes(&self, offset: usize, dst: &mut [u8]) -> Result<usize, c_long> {
|
||||||
|
self.skb.load_bytes(offset, dst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EbpfContext for FlowDissectorContext {
|
impl EbpfContext for FlowDissectorContext {
|
||||||
fn as_ptr(&self) -> *mut c_void {
|
fn as_ptr(&self) -> *mut c_void {
|
||||||
self.skb as *mut _
|
self.skb.as_ptr()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue