4
0
Эх сурвалжийг харах

bpf: don't generate bpf_map_def and fix aya_bpf::bindings overrides

Alessandro Decina 3 жил өмнө
parent
commit
35e9b4e639

+ 0 - 9
bpf/aya-bpf-bindings/src/aarch64/bindings.rs

@@ -1172,12 +1172,3 @@ pub struct socket {
 pub struct file {
     _unused: [u8; 0],
 }
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct bpf_map_def {
-    pub type_: ::aya_bpf_cty::c_uint,
-    pub key_size: ::aya_bpf_cty::c_uint,
-    pub value_size: ::aya_bpf_cty::c_uint,
-    pub max_entries: ::aya_bpf_cty::c_uint,
-    pub map_flags: ::aya_bpf_cty::c_uint,
-}

+ 0 - 17
bpf/aya-bpf-bindings/src/aarch64/getters.rs

@@ -1144,20 +1144,3 @@ impl path {}
 impl inode {}
 impl socket {}
 impl file {}
-impl bpf_map_def {
-    pub fn type_(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.type_) }.ok()
-    }
-    pub fn key_size(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.key_size) }.ok()
-    }
-    pub fn value_size(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.value_size) }.ok()
-    }
-    pub fn max_entries(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.max_entries) }.ok()
-    }
-    pub fn map_flags(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.map_flags) }.ok()
-    }
-}

+ 29 - 25
bpf/aya-bpf-bindings/src/lib.rs

@@ -14,7 +14,35 @@ mod gen {
     #[cfg(bpf_target_arch = "aarch64")]
     pub use super::aarch64::*;
 }
-pub use gen::*;
+pub use gen::{getters, helpers};
+
+pub mod bindings {
+    pub use crate::gen::bindings::*;
+
+    pub const TC_ACT_OK: i32 = crate::gen::bindings::TC_ACT_OK as i32;
+    pub const TC_ACT_RECLASSIFY: i32 = crate::gen::bindings::TC_ACT_RECLASSIFY as i32;
+    pub const TC_ACT_SHOT: i32 = crate::gen::bindings::TC_ACT_SHOT as i32;
+    pub const TC_ACT_PIPE: i32 = crate::gen::bindings::TC_ACT_PIPE as i32;
+    pub const TC_ACT_STOLEN: i32 = crate::gen::bindings::TC_ACT_STOLEN as i32;
+    pub const TC_ACT_QUEUED: i32 = crate::gen::bindings::TC_ACT_QUEUED as i32;
+    pub const TC_ACT_REPEAT: i32 = crate::gen::bindings::TC_ACT_REPEAT as i32;
+    pub const TC_ACT_REDIRECT: i32 = crate::gen::bindings::TC_ACT_REDIRECT as i32;
+    pub const TC_ACT_TRAP: i32 = crate::gen::bindings::TC_ACT_TRAP as i32;
+    pub const TC_ACT_VALUE_MAX: i32 = crate::gen::bindings::TC_ACT_VALUE_MAX as i32;
+    pub const TC_ACT_EXT_VAL_MASK: i32 = 268435455;
+
+    #[repr(C)]
+    #[derive(Debug, Copy, Clone)]
+    pub struct bpf_map_def {
+        pub type_: ::aya_bpf_cty::c_uint,
+        pub key_size: ::aya_bpf_cty::c_uint,
+        pub value_size: ::aya_bpf_cty::c_uint,
+        pub max_entries: ::aya_bpf_cty::c_uint,
+        pub map_flags: ::aya_bpf_cty::c_uint,
+        pub id: ::aya_bpf_cty::c_uint,
+        pub pinning: ::aya_bpf_cty::c_uint,
+    }
+}
 
 use aya_bpf_cty::{c_long, c_void};
 use core::mem::{self, MaybeUninit};
@@ -33,27 +61,3 @@ unsafe fn bpf_probe_read<T>(src: *const T) -> Result<T, c_long> {
 
     Ok(v.assume_init())
 }
-
-pub const TC_ACT_OK: i32 = gen::bindings::TC_ACT_OK as i32;
-pub const TC_ACT_RECLASSIFY: i32 = gen::bindings::TC_ACT_RECLASSIFY as i32;
-pub const TC_ACT_SHOT: i32 = gen::bindings::TC_ACT_SHOT as i32;
-pub const TC_ACT_PIPE: i32 = gen::bindings::TC_ACT_PIPE as i32;
-pub const TC_ACT_STOLEN: i32 = gen::bindings::TC_ACT_STOLEN as i32;
-pub const TC_ACT_QUEUED: i32 = gen::bindings::TC_ACT_QUEUED as i32;
-pub const TC_ACT_REPEAT: i32 = gen::bindings::TC_ACT_REPEAT as i32;
-pub const TC_ACT_REDIRECT: i32 = gen::bindings::TC_ACT_REDIRECT as i32;
-pub const TC_ACT_TRAP: i32 = gen::bindings::TC_ACT_TRAP as i32;
-pub const TC_ACT_VALUE_MAX: i32 = gen::bindings::TC_ACT_VALUE_MAX as i32;
-pub const TC_ACT_EXT_VAL_MASK: i32 = 268435455;
-
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct bpf_map_def {
-    pub type_: ::aya_bpf_cty::c_uint,
-    pub key_size: ::aya_bpf_cty::c_uint,
-    pub value_size: ::aya_bpf_cty::c_uint,
-    pub max_entries: ::aya_bpf_cty::c_uint,
-    pub map_flags: ::aya_bpf_cty::c_uint,
-    pub id: ::aya_bpf_cty::c_uint,
-    pub pinning: ::aya_bpf_cty::c_uint,
-}

+ 0 - 9
bpf/aya-bpf-bindings/src/x86_64/bindings.rs

@@ -1172,12 +1172,3 @@ pub struct socket {
 pub struct file {
     _unused: [u8; 0],
 }
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct bpf_map_def {
-    pub type_: ::aya_bpf_cty::c_uint,
-    pub key_size: ::aya_bpf_cty::c_uint,
-    pub value_size: ::aya_bpf_cty::c_uint,
-    pub max_entries: ::aya_bpf_cty::c_uint,
-    pub map_flags: ::aya_bpf_cty::c_uint,
-}

+ 0 - 17
bpf/aya-bpf-bindings/src/x86_64/getters.rs

@@ -1144,20 +1144,3 @@ impl path {}
 impl inode {}
 impl socket {}
 impl file {}
-impl bpf_map_def {
-    pub fn type_(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.type_) }.ok()
-    }
-    pub fn key_size(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.key_size) }.ok()
-    }
-    pub fn value_size(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.value_size) }.ok()
-    }
-    pub fn max_entries(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.max_entries) }.ok()
-    }
-    pub fn map_flags(&self) -> Option<::aya_bpf_cty::c_uint> {
-        unsafe { crate::bpf_probe_read(&self.map_flags) }.ok()
-    }
-}

+ 4 - 0
xtask/src/codegen/aya_bpf_bindings.rs

@@ -55,6 +55,10 @@ pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
             bindgen = bindgen.whitelist_type(x);
         }
 
+        // we define our own version which is compatible with both libbpf and
+        // iproute2
+        bindgen = bindgen.blacklist_type("bpf_map_def");
+
         for x in &vars {
             bindgen = bindgen.whitelist_var(x);
         }