瀏覽代碼

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>
Dave Tucker 3 年之前
父節點
當前提交
8a6fe4a640

+ 4 - 4
bpf/aya-bpf-macros/src/expand.rs

@@ -205,7 +205,7 @@ impl SchedClassifier {
             #[no_mangle]
             #[link_section = #section_name]
             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
             }
@@ -244,7 +244,7 @@ impl CgroupSkb {
             #[no_mangle]
             #[link_section = #section_name]
             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
             }
@@ -484,7 +484,7 @@ impl SkSkb {
             #[no_mangle]
             #[link_section = #section_name]
             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
             }
@@ -516,7 +516,7 @@ impl SocketFilter {
             #[no_mangle]
             #[link_section = #section_name]
             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
             }

+ 8 - 8
bpf/aya-bpf-macros/src/lib.rs

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

+ 2 - 2
bpf/aya-bpf/src/maps/sock_hash.rs

@@ -6,7 +6,7 @@ use crate::{
     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},
     maps::PinningType,
-    programs::{SkMsgContext, SkSkbContext},
+    programs::{SkBuffContext, SkMsgContext},
     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(
             ctx.as_ptr() as *mut _,
             &mut self.def as *mut _ as *mut _,

+ 2 - 2
bpf/aya-bpf/src/maps/sock_map.rs

@@ -6,7 +6,7 @@ use crate::{
     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},
     maps::PinningType,
-    programs::{SkMsgContext, SkSkbContext},
+    programs::{SkBuffContext, SkMsgContext},
     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(
             ctx.as_ptr() as *mut _,
             &mut self.def as *mut _ as *mut _,

+ 2 - 2
bpf/aya-bpf/src/programs/mod.rs

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

+ 5 - 5
bpf/aya-bpf/src/programs/sk_skb.rs → bpf/aya-bpf/src/programs/sk_buff.rs

@@ -11,13 +11,13 @@ use aya_bpf_cty::c_long;
 
 use crate::{bindings::__sk_buff, BpfContext};
 
-pub struct SkSkbContext {
+pub struct SkBuffContext {
     skb: *mut __sk_buff,
 }
 
-impl SkSkbContext {
-    pub fn new(skb: *mut __sk_buff) -> SkSkbContext {
-        SkSkbContext { skb }
+impl SkBuffContext {
+    pub fn new(skb: *mut __sk_buff) -> SkBuffContext {
+        SkBuffContext { skb }
     }
 
     #[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 {
         self.skb as *mut _
     }