fix(deps): update rust crate netlink-bindings to 0.3
Adjust netlink and traffic control logic to accommodate breaking API changes, including shifts from method calls to direct field access.
This commit is contained in:
3 files changed
+36
-47
No files matched your search
Generated
+2
-8
@@ -264,12 +264,6 @@ version = "2.8.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "netlink-bindings"
|
|
||||||
version = "0.2.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e639b3a966932d8ab55cfc1e606e5421aef3d30a2610284535b854f11f6e4b44"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "netlink-bindings"
|
name = "netlink-bindings"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@@ -284,7 +278,7 @@ checksum = "1065c80f8da85e6e0264bd73b85059427d0579893036cdb0e1f912612345240a"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"maybe-async",
|
"maybe-async",
|
||||||
"netlink-bindings 0.3.0",
|
"netlink-bindings",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -405,7 +399,7 @@ dependencies = [
|
|||||||
"icmp-socket2",
|
"icmp-socket2",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"netlink-bindings 0.2.4",
|
"netlink-bindings",
|
||||||
"netlink-socket2",
|
"netlink-socket2",
|
||||||
"rust-uci",
|
"rust-uci",
|
||||||
"rustix",
|
"rustix",
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ strip = "symbols"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
icmp-socket2 = "0.4.2"
|
icmp-socket2 = "0.4.2"
|
||||||
netlink-bindings = { version = "0.2", features = ["rt-link", "tc"] }
|
netlink-bindings = { version = "0.3", features = ["rt-link", "tc"] }
|
||||||
netlink-socket2 = "0.3"
|
netlink-socket2 = "0.3"
|
||||||
fastrand = "2"
|
fastrand = "2"
|
||||||
rustix = { version = "1.1", features = ["fs", "system", "thread", "time"] }
|
rustix = { version = "1.1", features = ["fs", "system", "thread", "time"] }
|
||||||
|
|||||||
+33
-38
@@ -28,7 +28,6 @@ pub enum NetlinkError {
|
|||||||
|
|
||||||
#[error("Error happened while parsing UTF-8 string")]
|
#[error("Error happened while parsing UTF-8 string")]
|
||||||
Utf8Error(#[from] Utf8Error),
|
Utf8Error(#[from] Utf8Error),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
@@ -43,32 +42,30 @@ impl Netlink {
|
|||||||
pub fn find_interface(ifname: &str) -> Result<i32, NetlinkError> {
|
pub fn find_interface(ifname: &str) -> Result<i32, NetlinkError> {
|
||||||
let mut socket = NetlinkSocket::new();
|
let mut socket = NetlinkSocket::new();
|
||||||
|
|
||||||
let mut request = rt_link::Request::new()
|
let mut request = rt_link::Request::new().op_getlink_do(&Default::default());
|
||||||
.op_getlink_do_request(&Default::default());
|
|
||||||
request.encode().push_ifname_bytes(ifname.as_bytes());
|
request.encode().push_ifname_bytes(ifname.as_bytes());
|
||||||
|
|
||||||
let mut iter = socket.request(&request)?;
|
let mut iter = socket.request(&request)?;
|
||||||
let (header, _) = iter.recv_one()
|
let (header, _) = iter
|
||||||
|
.recv_one()
|
||||||
.map_err(|_| NetlinkError::InterfaceNotFound(ifname.to_string()))?;
|
.map_err(|_| NetlinkError::InterfaceNotFound(ifname.to_string()))?;
|
||||||
Ok(header.ifi_index())
|
Ok(header.ifi_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_interface_stats(ifname: &str) -> Result<(u64, u64), NetlinkError> {
|
pub fn get_interface_stats(ifname: &str) -> Result<(u64, u64), NetlinkError> {
|
||||||
let mut socket = NetlinkSocket::new();
|
let mut socket = NetlinkSocket::new();
|
||||||
|
|
||||||
let mut request = rt_link::Request::new()
|
let mut request = rt_link::Request::new().op_getlink_do(&Default::default());
|
||||||
.op_getlink_do_request(&Default::default());
|
request
|
||||||
request.encode()
|
.encode()
|
||||||
.push_ifname_bytes(ifname.as_bytes())
|
.push_ifname_bytes(ifname.as_bytes())
|
||||||
.push_ext_mask(1 /* RTEXT_FILTER_VF */);
|
.push_ext_mask(1 /* RTEXT_FILTER_VF */);
|
||||||
|
|
||||||
let mut iter = socket.request(&request)?;
|
let mut iter = socket.request(&request)?;
|
||||||
while let Some(reply) = iter.recv() {
|
while let Some(reply) = iter.recv() {
|
||||||
let (_, attrs) = reply?;
|
let (_, attrs) = reply?;
|
||||||
for attr in attrs {
|
if let Ok(stats) = attrs.get_stats64() {
|
||||||
if let Ok(rt_link::OpGetlinkDoReply::Stats64(stats)) = attr {
|
return Ok((stats.rx_bytes, stats.tx_bytes));
|
||||||
return Ok((stats.rx_bytes(), stats.tx_bytes()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,30 +74,26 @@ impl Netlink {
|
|||||||
|
|
||||||
pub fn qdisc_from_ifindex(ifindex: i32, ifname: &str) -> Result<Qdisc, NetlinkError> {
|
pub fn qdisc_from_ifindex(ifindex: i32, ifname: &str) -> Result<Qdisc, NetlinkError> {
|
||||||
let mut socket = NetlinkSocket::new();
|
let mut socket = NetlinkSocket::new();
|
||||||
let header = tc::PushTcmsg::new();
|
let header = tc::Tcmsg::new();
|
||||||
let request = tc::Request::new().op_getqdisc_dump_request(&header);
|
let request = tc::Request::new().op_getqdisc_dump(&header);
|
||||||
|
|
||||||
let mut iter = socket.request(&request)?;
|
let mut iter = socket.request(&request)?;
|
||||||
while let Some(reply) = iter.recv() {
|
while let Some(reply) = iter.recv() {
|
||||||
let (header, attrs) = reply?;
|
let (header, attrs) = reply?;
|
||||||
|
|
||||||
if header.ifindex() == ifindex {
|
if header.ifindex == ifindex {
|
||||||
let mut is_cake = false;
|
if let Ok(kind) = attrs.get_kind() {
|
||||||
for attr in attrs {
|
if kind
|
||||||
if let Ok(tc::OpGetqdiscDumpReply::Kind(kind)) = attr {
|
.to_str()
|
||||||
if kind.to_str().map_err(|_| NetlinkError::NlQdiscError("Invalid UTF-8".to_string()))? == "cake" {
|
.map_err(|_| NetlinkError::NlQdiscError("Invalid UTF-8".to_string()))?
|
||||||
is_cake = true;
|
== "cake"
|
||||||
break;
|
{
|
||||||
}
|
return Ok(Qdisc {
|
||||||
|
ifindex,
|
||||||
|
parent: header.parent,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_cake {
|
|
||||||
return Ok(Qdisc {
|
|
||||||
ifindex,
|
|
||||||
parent: header.parent(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +105,11 @@ impl Netlink {
|
|||||||
Netlink::qdisc_from_ifindex(ifindex, ifname)
|
Netlink::qdisc_from_ifindex(ifindex, ifname)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_qdisc_rate(qdisc: Qdisc, bandwidth_kbit: u64, dry_run: bool) -> Result<(), NetlinkError> {
|
pub fn set_qdisc_rate(
|
||||||
|
qdisc: Qdisc,
|
||||||
|
bandwidth_kbit: u64,
|
||||||
|
dry_run: bool,
|
||||||
|
) -> Result<(), NetlinkError> {
|
||||||
if dry_run {
|
if dry_run {
|
||||||
info!(
|
info!(
|
||||||
"dry-run: would set qdisc ifindex={} to {} kbit/s",
|
"dry-run: would set qdisc ifindex={} to {} kbit/s",
|
||||||
@@ -124,14 +121,12 @@ impl Netlink {
|
|||||||
let mut socket = NetlinkSocket::new();
|
let mut socket = NetlinkSocket::new();
|
||||||
let bandwidth = bandwidth_kbit * 1000 / 8;
|
let bandwidth = bandwidth_kbit * 1000 / 8;
|
||||||
|
|
||||||
let mut header = tc::PushTcmsg::new();
|
let mut header = tc::Tcmsg::new();
|
||||||
header.set_ifindex(qdisc.ifindex);
|
header.ifindex = qdisc.ifindex;
|
||||||
header.set_parent(qdisc.parent);
|
header.parent = qdisc.parent;
|
||||||
|
let mut request = tc::Request::new().set_change().op_newqdisc_do(&header);
|
||||||
let mut request = tc::Request::new()
|
request
|
||||||
.set_change()
|
.encode()
|
||||||
.op_newqdisc_do_request(&header);
|
|
||||||
request.encode()
|
|
||||||
.push_kind(c"cake")
|
.push_kind(c"cake")
|
||||||
.nested_options_cake()
|
.nested_options_cake()
|
||||||
.push_base_rate64(bandwidth)
|
.push_base_rate64(bandwidth)
|
||||||
|
|||||||
Reference in new issue
Block a user