aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-08-17 15:13:57 +0200
committerHimbeer <himbeer@disroot.org>2024-08-17 15:13:57 +0200
commitb931675ccfe4a00fd8edb5ba058f650a42bc7003 (patch)
tree000a7d9cc0efd36546f7390eef7e2775f093c1c6
parent2dccff982966a034947b96c3babc6e01d2295ef5 (diff)
Update rtnetlink to 0.14.1
-rw-r--r--Cargo.toml4
-rw-r--r--src/addr.rs49
-rw-r--r--src/link.rs4
-rw-r--r--src/route.rs42
4 files changed, 50 insertions, 49 deletions
diff --git a/Cargo.toml b/Cargo.toml
index becfff2..a0b3836 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,9 +8,9 @@ edition = "2021"
[dependencies]
futures = { version = "0.3.11", default-features = false, features = ["std"] }
libc = "0.2.150"
-netlink-packet-route = "^0.17"
+netlink-packet-route = "^0.19"
netlink-proto = "^0.11"
-rtnetlink = { version = "0.13.1" }
+rtnetlink = { version = "0.14.1" }
thiserror = "1.0"
tokio = { version = "1.0", features = ["time"] }
diff --git a/src/addr.rs b/src/addr.rs
index 97e87d4..86b67f1 100644
--- a/src/addr.rs
+++ b/src/addr.rs
@@ -2,12 +2,11 @@
use crate::{Connection, Error, Result};
-use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
+use std::net::IpAddr;
use futures::{future, TryStream, TryStreamExt};
-use netlink_packet_route::{
- address::Nla, AddressMessage, AF_INET, AF_INET6, RT_SCOPE_LINK, RT_SCOPE_UNIVERSE,
-};
+use netlink_packet_route::address::{AddressAttribute, AddressMessage, AddressScope};
+use netlink_packet_route::AddressFamily;
impl Connection {
/// Flushes all addresses of an interface.
@@ -60,7 +59,7 @@ impl Connection {
.get()
.set_link_index_filter(id)
.execute()
- .try_filter(|addr| future::ready(addr.header.family == AF_INET as u8))
+ .try_filter(|addr| future::ready(addr.header.family == AddressFamily::Inet))
.try_collect()
.await?;
@@ -91,7 +90,7 @@ impl Connection {
.get()
.set_link_index_filter(id)
.execute()
- .try_filter(|addr| future::ready(addr.header.family == AF_INET6 as u8))
+ .try_filter(|addr| future::ready(addr.header.family == AddressFamily::Inet6))
.try_collect()
.await?;
@@ -111,7 +110,8 @@ impl Connection {
.execute()
.try_filter(|addr| {
future::ready(
- addr.header.family == AF_INET6 as u8 && addr.header.scope == RT_SCOPE_UNIVERSE,
+ addr.header.family == AddressFamily::Inet6
+ && addr.header.scope == AddressScope::Universe,
)
})
.try_collect()
@@ -168,7 +168,7 @@ impl Connection {
let id = link.header.index;
let mut req = self.handle().address().add(id, addr, prefix_len);
- req.message_mut().header.scope = RT_SCOPE_LINK;
+ req.message_mut().header.scope = AddressScope::Link;
req.execute().await?;
@@ -198,31 +198,16 @@ impl Connection {
.execute()
.err_into::<Error>()
.try_filter_map(|msg| {
- future::ready(Ok(if let Some(Nla::Address(bytes)) = msg.nlas.first() {
- match msg.header.family as u16 {
- AF_INET => {
- let octets: [u8; 4] = (*bytes)
- .clone()
- .try_into()
- .expect("nla does not match ipv4 address length");
- let ip = IpAddr::from(Ipv4Addr::from(octets));
-
- Some(ip)
+ future::ready(Ok(
+ if let Some(AddressAttribute::Address(ip)) = msg.attributes.first() {
+ match msg.header.family {
+ AddressFamily::Inet | AddressFamily::Inet6 => Some(*ip),
+ _ => None,
}
- AF_INET6 => {
- let octets: [u8; 16] = (*bytes)
- .clone()
- .try_into()
- .expect("nla does not match ipv6 address length");
- let ip = IpAddr::from(Ipv6Addr::from(octets));
-
- Some(ip)
- }
- _ => None,
- }
- } else {
- None
- }))
+ } else {
+ None
+ },
+ ))
}))
}
}
diff --git a/src/link.rs b/src/link.rs
index 30a432b..46cefab 100644
--- a/src/link.rs
+++ b/src/link.rs
@@ -7,7 +7,7 @@ use std::time::Duration;
use tokio::time::sleep;
use futures::TryStreamExt;
-use netlink_packet_route::rtnl::IFF_UP;
+use netlink_packet_route::link::LinkFlag;
impl Connection {
/// Brings an interface up or down.
@@ -52,7 +52,7 @@ impl Connection {
.await?
.ok_or(Error::LinkNotFound(link))?;
- let is_up = link.header.flags & IFF_UP == IFF_UP;
+ let is_up = link.header.flags.iter().any(|flag| *flag == LinkFlag::Up);
Ok(is_up)
}
diff --git a/src/route.rs b/src/route.rs
index 6b11054..2283072 100644
--- a/src/route.rs
+++ b/src/route.rs
@@ -5,7 +5,7 @@ use crate::{Connection, Error, Result};
use std::net::{Ipv4Addr, Ipv6Addr};
use futures::{future, TryStreamExt};
-use netlink_packet_route::{RouteMessage, RT_SCOPE_LINK};
+use netlink_packet_route::route::{RouteAttribute, RouteMessage, RouteScope};
use rtnetlink::IpVersion;
impl Connection {
@@ -29,11 +29,19 @@ impl Connection {
.get(IpVersion::V4)
.execute()
.try_filter(|route| {
- future::ready(if let Some(ifi) = route.output_interface() {
- ifi == id
- } else {
- false
- })
+ future::ready(
+ if let Some(ifi) = route.attributes.iter().find_map(|attr| {
+ if let RouteAttribute::Oif(oif) = *attr {
+ Some(oif)
+ } else {
+ None
+ }
+ }) {
+ ifi == id
+ } else {
+ false
+ },
+ )
})
.try_collect()
.await?;
@@ -65,11 +73,19 @@ impl Connection {
.get(IpVersion::V6)
.execute()
.try_filter(|route| {
- future::ready(if let Some(ifi) = route.output_interface() {
- ifi == id
- } else {
- false
- })
+ future::ready(
+ if let Some(ifi) = route.attributes.iter().find_map(|attr| {
+ if let RouteAttribute::Oif(oif) = *attr {
+ Some(oif)
+ } else {
+ None
+ }
+ }) {
+ ifi == id
+ } else {
+ false
+ },
+ )
})
.try_collect()
.await?;
@@ -120,7 +136,7 @@ impl Connection {
if let Some(rtr) = rtr {
add = add.gateway(rtr);
} else {
- add = add.scope(RT_SCOPE_LINK);
+ add = add.scope(RouteScope::Link);
}
add.execute().await?;
@@ -158,7 +174,7 @@ impl Connection {
if let Some(rtr) = rtr {
add = add.gateway(rtr);
} else {
- add = add.scope(RT_SCOPE_LINK);
+ add = add.scope(RouteScope::Link);
}
add.execute().await?;