Refactor(netlink): Replaces zerocopy with bytemuck
Migrates from `zerocopy` to `bytemuck` for improved data serialization and deserialization in netlink communication. This enhances maintainability.
This commit is contained in:
3 files changed
+29
-31
No files matched your search
Generated
+21
-22
@@ -72,6 +72,26 @@ version = "2.11.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck"
|
||||||
|
version = "1.25.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec"
|
||||||
|
dependencies = [
|
||||||
|
"bytemuck_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck_derive"
|
||||||
|
version = "1.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@@ -766,6 +786,7 @@ name = "sqm-autorate-rust"
|
|||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"bytemuck",
|
||||||
"icmp-socket",
|
"icmp-socket",
|
||||||
"log",
|
"log",
|
||||||
"neli",
|
"neli",
|
||||||
@@ -774,8 +795,6 @@ dependencies = [
|
|||||||
"rustix",
|
"rustix",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
"zerocopy",
|
|
||||||
"zerocopy-derive",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1169,26 +1188,6 @@ dependencies = [
|
|||||||
"wasmparser",
|
"wasmparser",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerocopy"
|
|
||||||
version = "0.8.39"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a"
|
|
||||||
dependencies = [
|
|
||||||
"zerocopy-derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerocopy-derive"
|
|
||||||
version = "0.8.39"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zmij"
|
name = "zmij"
|
||||||
version = "1.0.21"
|
version = "1.0.21"
|
||||||
|
|||||||
+1
-2
@@ -20,14 +20,13 @@ strip = "symbols"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
bytemuck = { version = "1.25.0", features = ["derive"] }
|
||||||
icmp-socket = "0.4.0"
|
icmp-socket = "0.4.0"
|
||||||
neli = "0.7"
|
neli = "0.7"
|
||||||
rand = "0.10"
|
rand = "0.10"
|
||||||
rustix = { version = "1.1", features = ["fs", "thread", "time"] }
|
rustix = { version = "1.1", features = ["fs", "thread", "time"] }
|
||||||
rust-uci = { version = "0.1", optional = true }
|
rust-uci = { version = "0.1", optional = true }
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
zerocopy = "0.8.39"
|
|
||||||
zerocopy-derive = "0.8.39"
|
|
||||||
|
|
||||||
[dependencies.log]
|
[dependencies.log]
|
||||||
features = ["std"]
|
features = ["std"]
|
||||||
|
|||||||
+7
-7
@@ -1,3 +1,5 @@
|
|||||||
|
use bytemuck::AnyBitPattern;
|
||||||
|
use bytemuck::checked::{CheckedCastError, try_from_bytes};
|
||||||
use neli::consts::nl::NlmF;
|
use neli::consts::nl::NlmF;
|
||||||
use neli::consts::rtnl::{Arphrd, Iff, Ifla, RtAddrFamily, Rtm, Tca};
|
use neli::consts::rtnl::{Arphrd, Iff, Ifla, RtAddrFamily, Rtm, Tca};
|
||||||
use neli::consts::socket::NlFamily;
|
use neli::consts::socket::NlFamily;
|
||||||
@@ -10,13 +12,11 @@ use neli::utils::Groups;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use zerocopy::FromBytes;
|
|
||||||
use zerocopy_derive::{FromBytes, Immutable, KnownLayout};
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum NetlinkError {
|
pub enum NetlinkError {
|
||||||
#[error("Couldn't deserialize to struct: {0}")]
|
#[error("Couldn't deserialize to struct: {0}")]
|
||||||
Deserialization(String),
|
Deserialization(CheckedCastError),
|
||||||
|
|
||||||
#[error("Couldn't find intreface `{0}`")]
|
#[error("Couldn't find intreface `{0}`")]
|
||||||
InterfaceNotFound(String),
|
InterfaceNotFound(String),
|
||||||
@@ -52,7 +52,7 @@ pub struct Qdisc {
|
|||||||
parent: u32,
|
parent: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Debug, FromBytes, Immutable, KnownLayout)]
|
#[derive(AnyBitPattern, Copy, Clone, Default, Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct RtnlLinkStats64 {
|
pub struct RtnlLinkStats64 {
|
||||||
pub rx_packets: u64,
|
pub rx_packets: u64,
|
||||||
@@ -172,10 +172,10 @@ impl Netlink {
|
|||||||
for attr in p.rtattrs().iter() {
|
for attr in p.rtattrs().iter() {
|
||||||
if attr.rta_type() == &Ifla::Stats64 {
|
if attr.rta_type() == &Ifla::Stats64 {
|
||||||
let buf = attr.rta_payload().as_ref();
|
let buf = attr.rta_payload().as_ref();
|
||||||
let stats = RtnlLinkStats64::read_from_bytes(buf)
|
let stats: &RtnlLinkStats64 = try_from_bytes::<RtnlLinkStats64>(buf)
|
||||||
.map_err(|e| NetlinkError::Deserialization(e.to_string()))?;
|
.map_err(|e| NetlinkError::Deserialization(e))?;
|
||||||
|
|
||||||
return Ok(stats);
|
return Ok(stats.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user