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"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "netlink-bindings"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e639b3a966932d8ab55cfc1e606e5421aef3d30a2610284535b854f11f6e4b44"
|
||||
|
||||
[[package]]
|
||||
name = "netlink-bindings"
|
||||
version = "0.3.0"
|
||||
@@ -284,7 +278,7 @@ checksum = "1065c80f8da85e6e0264bd73b85059427d0579893036cdb0e1f912612345240a"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"maybe-async",
|
||||
"netlink-bindings 0.3.0",
|
||||
"netlink-bindings",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -405,7 +399,7 @@ dependencies = [
|
||||
"icmp-socket2",
|
||||
"libc",
|
||||
"log",
|
||||
"netlink-bindings 0.2.4",
|
||||
"netlink-bindings",
|
||||
"netlink-socket2",
|
||||
"rust-uci",
|
||||
"rustix",
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ strip = "symbols"
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
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"
|
||||
fastrand = "2"
|
||||
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")]
|
||||
Utf8Error(#[from] Utf8Error),
|
||||
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -43,32 +42,30 @@ impl Netlink {
|
||||
pub fn find_interface(ifname: &str) -> Result<i32, NetlinkError> {
|
||||
let mut socket = NetlinkSocket::new();
|
||||
|
||||
let mut request = rt_link::Request::new()
|
||||
.op_getlink_do_request(&Default::default());
|
||||
let mut request = rt_link::Request::new().op_getlink_do(&Default::default());
|
||||
request.encode().push_ifname_bytes(ifname.as_bytes());
|
||||
|
||||
let mut iter = socket.request(&request)?;
|
||||
let (header, _) = iter.recv_one()
|
||||
let (header, _) = iter
|
||||
.recv_one()
|
||||
.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> {
|
||||
let mut socket = NetlinkSocket::new();
|
||||
|
||||
let mut request = rt_link::Request::new()
|
||||
.op_getlink_do_request(&Default::default());
|
||||
request.encode()
|
||||
let mut request = rt_link::Request::new().op_getlink_do(&Default::default());
|
||||
request
|
||||
.encode()
|
||||
.push_ifname_bytes(ifname.as_bytes())
|
||||
.push_ext_mask(1 /* RTEXT_FILTER_VF */);
|
||||
|
||||
let mut iter = socket.request(&request)?;
|
||||
while let Some(reply) = iter.recv() {
|
||||
let (_, attrs) = reply?;
|
||||
for attr in attrs {
|
||||
if let Ok(rt_link::OpGetlinkDoReply::Stats64(stats)) = attr {
|
||||
return Ok((stats.rx_bytes(), stats.tx_bytes()));
|
||||
}
|
||||
if let Ok(stats) = attrs.get_stats64() {
|
||||
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> {
|
||||
let mut socket = NetlinkSocket::new();
|
||||
let header = tc::PushTcmsg::new();
|
||||
let request = tc::Request::new().op_getqdisc_dump_request(&header);
|
||||
let header = tc::Tcmsg::new();
|
||||
let request = tc::Request::new().op_getqdisc_dump(&header);
|
||||
|
||||
let mut iter = socket.request(&request)?;
|
||||
while let Some(reply) = iter.recv() {
|
||||
let (header, attrs) = reply?;
|
||||
|
||||
if header.ifindex() == ifindex {
|
||||
let mut is_cake = false;
|
||||
for attr in attrs {
|
||||
if let Ok(tc::OpGetqdiscDumpReply::Kind(kind)) = attr {
|
||||
if kind.to_str().map_err(|_| NetlinkError::NlQdiscError("Invalid UTF-8".to_string()))? == "cake" {
|
||||
is_cake = true;
|
||||
break;
|
||||
}
|
||||
if header.ifindex == ifindex {
|
||||
if let Ok(kind) = attrs.get_kind() {
|
||||
if kind
|
||||
.to_str()
|
||||
.map_err(|_| NetlinkError::NlQdiscError("Invalid UTF-8".to_string()))?
|
||||
== "cake"
|
||||
{
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
info!(
|
||||
"dry-run: would set qdisc ifindex={} to {} kbit/s",
|
||||
@@ -124,14 +121,12 @@ impl Netlink {
|
||||
let mut socket = NetlinkSocket::new();
|
||||
let bandwidth = bandwidth_kbit * 1000 / 8;
|
||||
|
||||
let mut header = tc::PushTcmsg::new();
|
||||
header.set_ifindex(qdisc.ifindex);
|
||||
header.set_parent(qdisc.parent);
|
||||
|
||||
let mut request = tc::Request::new()
|
||||
.set_change()
|
||||
.op_newqdisc_do_request(&header);
|
||||
request.encode()
|
||||
let mut header = tc::Tcmsg::new();
|
||||
header.ifindex = qdisc.ifindex;
|
||||
header.parent = qdisc.parent;
|
||||
let mut request = tc::Request::new().set_change().op_newqdisc_do(&header);
|
||||
request
|
||||
.encode()
|
||||
.push_kind(c"cake")
|
||||
.nested_options_cake()
|
||||
.push_base_rate64(bandwidth)
|
||||
|
||||
Reference in new issue
Block a user