diff --git a/Cargo.lock b/Cargo.lock index 2352848..6169ff4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -470,6 +470,7 @@ dependencies = [ "aya-ebpf", "network-types", "serde", + "zerocopy 0.8.33", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6330603..bd4a9aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ cargo_metadata = { version = "0.23.1", default-features = false } libc = { version = "0.2.159", default-features = false } network-types = "0.1.0" serde = { version = "1.0.215", features = ["derive"] } +zerocopy = { version = "0.8", default-features = false, features = ["derive"] } xsk-rs = { version = "0.8.0", default-features = false } [profile.dev] diff --git a/common/Cargo.toml b/common/Cargo.toml index 1cfaa89..2a36f92 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,13 +5,14 @@ edition = "2024" [features] default = [] -user = ["aya", "serde"] +user = ["aya", "serde", "dep:zerocopy"] kernel = ["aya-ebpf"] [dependencies] aya = { workspace = true, optional = true } aya-ebpf = { workspace = true, optional = true } serde = { workspace = true, optional = true } +zerocopy = { workspace = true, optional = true } network-types = { workspace = true } [lib] diff --git a/common/src/model/flow_stats.rs b/common/src/model/flow_stats.rs index d9ccb5c..6845890 100644 --- a/common/src/model/flow_stats.rs +++ b/common/src/model/flow_stats.rs @@ -2,10 +2,12 @@ use aya::Pod; #[cfg(feature = "user")] use serde::Serialize; +#[cfg(feature = "user")] +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[repr(C, align(8))] #[derive(Clone, Copy)] -#[cfg_attr(feature = "user", derive(Serialize, Debug))] +#[cfg_attr(feature = "user", derive(Serialize, Debug, FromBytes, IntoBytes, KnownLayout, Immutable))] pub struct FlowStats { pub bytes: u64, pub packets: u64, diff --git a/common/src/model/ip_address.rs b/common/src/model/ip_address.rs index 84a0e99..bc09241 100644 --- a/common/src/model/ip_address.rs +++ b/common/src/model/ip_address.rs @@ -1,5 +1,7 @@ #[cfg(feature = "user")] use aya::Pod; +#[cfg(feature = "user")] +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; pub type IPv4 = u32; pub type IPv6 = u128; @@ -7,6 +9,7 @@ pub type Port = u16; #[repr(transparent)] #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "user", derive(FromBytes, IntoBytes, KnownLayout, Immutable))] pub struct AddrPortV4([u8; 8]); impl AddrPortV4 { @@ -43,6 +46,7 @@ unsafe impl Pod for AddrPortV4 {} #[repr(transparent)] #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "user", derive(FromBytes, IntoBytes, KnownLayout, Immutable))] pub struct AddrPortV6([u8; 32]); impl AddrPortV6 {