bpf: Rename SkSkbContext to SkBuffContext

This is necessary since the context is used in many other program types
and not just in SK_SKB programs.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/106/head
Dave Tucker 3 years ago
parent 685b68359e
commit 8a6fe4a640

@ -205,7 +205,7 @@ impl SchedClassifier {
#[no_mangle] #[no_mangle]
#[link_section = #section_name] #[link_section = #section_name]
fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> i32 { fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> i32 {
return #fn_name(::aya_bpf::programs::SkSkbContext::new(ctx)); return #fn_name(::aya_bpf::programs::SkBuffContext::new(ctx));
#item #item
} }
@ -244,7 +244,7 @@ impl CgroupSkb {
#[no_mangle] #[no_mangle]
#[link_section = #section_name] #[link_section = #section_name]
fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> i32 { fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> i32 {
return #fn_name(::aya_bpf::programs::SkSkbContext::new(ctx)); return #fn_name(::aya_bpf::programs::SkBuffContext::new(ctx));
#item #item
} }
@ -484,7 +484,7 @@ impl SkSkb {
#[no_mangle] #[no_mangle]
#[link_section = #section_name] #[link_section = #section_name]
fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> u32 { fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> u32 {
return #fn_name(::aya_bpf::programs::SkSkbContext::new(ctx)); return #fn_name(::aya_bpf::programs::SkBuffContext::new(ctx));
#item #item
} }
@ -516,7 +516,7 @@ impl SocketFilter {
#[no_mangle] #[no_mangle]
#[link_section = #section_name] #[link_section = #section_name]
fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> i64 { fn #fn_name(ctx: *mut ::aya_bpf::bindings::__sk_buff) -> i64 {
return #fn_name(::aya_bpf::programs::SkSkbContext::new(ctx)); return #fn_name(::aya_bpf::programs::SkBuffContext::new(ctx));
#item #item
} }

@ -257,18 +257,18 @@ pub fn btf_tracepoint(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya_bpf::{macros::stream_parser, programs::SkSkbContext}; /// use aya_bpf::{macros::stream_parser, programs::SkBuffContext};
/// ///
/// ///
///#[stream_parser] ///#[stream_parser]
///fn stream_parser(ctx: SkSkbContext) -> u32 { ///fn stream_parser(ctx: SkBuffContext) -> u32 {
/// match { try_stream_parser(ctx) } { /// match { try_stream_parser(ctx) } {
/// Ok(ret) => ret, /// Ok(ret) => ret,
/// Err(ret) => ret, /// Err(ret) => ret,
/// } /// }
///} ///}
/// ///
///fn try_stream_parser(ctx: SkSkbContext) -> Result<u32, u32> { ///fn try_stream_parser(ctx: SkBuffContext) -> Result<u32, u32> {
/// Ok(ctx.len()) /// Ok(ctx.len())
///} ///}
/// ``` /// ```
@ -287,18 +287,18 @@ pub fn stream_parser(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya_bpf::{macros::stream_verdict, programs::SkSkbContext, bindings::sk_action}; /// use aya_bpf::{macros::stream_verdict, programs::SkBuffContext, bindings::sk_action};
/// ///
/// ///
///#[stream_verdict] ///#[stream_verdict]
///fn stream_verdict(ctx: SkSkbContext) -> u32 { ///fn stream_verdict(ctx: SkBuffContext) -> u32 {
/// match { try_stream_verdict(ctx) } { /// match { try_stream_verdict(ctx) } {
/// Ok(ret) => ret, /// Ok(ret) => ret,
/// Err(ret) => ret, /// Err(ret) => ret,
/// } /// }
///} ///}
/// ///
///fn try_stream_verdict(_ctx: SkSkbContext) -> Result<u32, u32> { ///fn try_stream_verdict(_ctx: SkBuffContext) -> Result<u32, u32> {
/// Ok(sk_action::SK_PASS) /// Ok(sk_action::SK_PASS)
///} ///}
/// ``` /// ```
@ -327,10 +327,10 @@ fn sk_skb(kind: SkSkbKind, attrs: TokenStream, item: TokenStream) -> TokenStream
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use aya_bpf::{macros::socket_filter, programs::SkSkbContext}; /// use aya_bpf::{macros::socket_filter, programs::SkBuffContext};
/// ///
/// #[socket_filter(name = "accept_all")] /// #[socket_filter(name = "accept_all")]
/// pub fn accept_all(_ctx: SkSkbContext) -> i64 { /// pub fn accept_all(_ctx: SkBuffContext) -> i64 {
/// return 0 /// return 0
/// } /// }
/// ``` /// ```

@ -6,7 +6,7 @@ use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_SOCKHASH, bpf_sock_ops}, bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_SOCKHASH, bpf_sock_ops},
helpers::{bpf_msg_redirect_hash, bpf_sk_redirect_hash, bpf_sock_hash_update}, helpers::{bpf_msg_redirect_hash, bpf_sk_redirect_hash, bpf_sock_hash_update},
maps::PinningType, maps::PinningType,
programs::{SkMsgContext, SkSkbContext}, programs::{SkBuffContext, SkMsgContext},
BpfContext, BpfContext,
}; };
@ -75,7 +75,7 @@ impl<K> SockHash<K> {
) )
} }
pub unsafe fn redirect_skb(&mut self, ctx: &SkSkbContext, key: &mut K, flags: u64) -> i64 { pub unsafe fn redirect_skb(&mut self, ctx: &SkBuffContext, key: &mut K, flags: u64) -> i64 {
bpf_sk_redirect_hash( bpf_sk_redirect_hash(
ctx.as_ptr() as *mut _, ctx.as_ptr() as *mut _,
&mut self.def as *mut _ as *mut _, &mut self.def as *mut _ as *mut _,

@ -6,7 +6,7 @@ use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_SOCKMAP, bpf_sock_ops}, bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_SOCKMAP, bpf_sock_ops},
helpers::{bpf_msg_redirect_map, bpf_sk_redirect_map, bpf_sock_map_update}, helpers::{bpf_msg_redirect_map, bpf_sk_redirect_map, bpf_sock_map_update},
maps::PinningType, maps::PinningType,
programs::{SkMsgContext, SkSkbContext}, programs::{SkBuffContext, SkMsgContext},
BpfContext, BpfContext,
}; };
@ -72,7 +72,7 @@ impl SockMap {
) )
} }
pub unsafe fn redirect_skb(&mut self, ctx: &SkSkbContext, index: u32, flags: u64) -> i64 { pub unsafe fn redirect_skb(&mut self, ctx: &SkBuffContext, index: u32, flags: u64) -> i64 {
bpf_sk_redirect_map( bpf_sk_redirect_map(
ctx.as_ptr() as *mut _, ctx.as_ptr() as *mut _,
&mut self.def as *mut _ as *mut _, &mut self.def as *mut _ as *mut _,

@ -2,8 +2,8 @@ pub mod lsm;
pub mod perf_event; pub mod perf_event;
pub mod probe; pub mod probe;
pub mod raw_tracepoint; pub mod raw_tracepoint;
pub mod sk_buff;
pub mod sk_msg; pub mod sk_msg;
pub mod sk_skb;
pub mod sock_ops; pub mod sock_ops;
pub mod tp_btf; pub mod tp_btf;
pub mod tracepoint; pub mod tracepoint;
@ -13,8 +13,8 @@ pub use lsm::LsmContext;
pub use perf_event::PerfEventContext; pub use perf_event::PerfEventContext;
pub use probe::ProbeContext; pub use probe::ProbeContext;
pub use raw_tracepoint::RawTracePointContext; pub use raw_tracepoint::RawTracePointContext;
pub use sk_buff::SkBuffContext;
pub use sk_msg::SkMsgContext; pub use sk_msg::SkMsgContext;
pub use sk_skb::SkSkbContext;
pub use sock_ops::SockOpsContext; pub use sock_ops::SockOpsContext;
pub use tp_btf::BtfTracePointContext; pub use tp_btf::BtfTracePointContext;
pub use tracepoint::TracePointContext; pub use tracepoint::TracePointContext;

@ -11,13 +11,13 @@ use aya_bpf_cty::c_long;
use crate::{bindings::__sk_buff, BpfContext}; use crate::{bindings::__sk_buff, BpfContext};
pub struct SkSkbContext { pub struct SkBuffContext {
skb: *mut __sk_buff, skb: *mut __sk_buff,
} }
impl SkSkbContext { impl SkBuffContext {
pub fn new(skb: *mut __sk_buff) -> SkSkbContext { pub fn new(skb: *mut __sk_buff) -> SkBuffContext {
SkSkbContext { skb } SkBuffContext { skb }
} }
#[allow(clippy::len_without_is_empty)] #[allow(clippy::len_without_is_empty)]
@ -144,7 +144,7 @@ impl SkSkbContext {
} }
} }
impl BpfContext for SkSkbContext { impl BpfContext for SkBuffContext {
fn as_ptr(&self) -> *mut c_void { fn as_ptr(&self) -> *mut c_void {
self.skb as *mut _ self.skb as *mut _
} }
Loading…
Cancel
Save