Skip to content

Commit

Permalink
chore: update forked rtnetlink crate
Browse files Browse the repository at this point in the history
  • Loading branch information
hack3ric committed Jan 17, 2025
1 parent c95fdef commit d8299a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 24 additions & 13 deletions src/integration_tests/kernel_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use nftables::stmt;
use rand::distributions::Alphanumeric;
use rand::Rng;
use rtnetlink::{IpVersion, RouteMessageBuilder};
use std::net::IpAddr;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::time::Duration;
use tokio::select;
use tokio::time::sleep;
Expand Down Expand Up @@ -107,17 +107,17 @@ async fn test_redirect_to_ip() -> anyhow::Result<()> {
assert!(ip_rules.contains(&ip_rule_exp));

let mut ip_routes_exp = [
RouteMessageBuilder::<IpAddr>::new()
RouteMessageBuilder::<Ipv4Addr>::new()
.table_id(table_index)
.destination_prefix("172.20.0.0".parse()?, 16)?
.destination_prefix("172.20.0.0".parse()?, 16)
.output_interface(dummy_index)
.gateway("10.128.128.1".parse()?)?
.gateway("10.128.128.1".parse()?)
.build(),
RouteMessageBuilder::<IpAddr>::new()
RouteMessageBuilder::<Ipv4Addr>::new()
.table_id(table_index)
.destination_prefix("172.21.0.0".parse()?, 16)?
.destination_prefix("172.21.0.0".parse()?, 16)
.output_interface(dummy_index)
.gateway("10.128.128.1".parse()?)?
.gateway("10.128.128.1".parse()?)
.build(),
];
ip_routes_exp.iter_mut().for_each(route_msg_normalize);
Expand Down Expand Up @@ -169,17 +169,17 @@ async fn test_redirect_to_ipv6() -> anyhow::Result<()> {
assert!(ip_rules.contains(&ip_rule_exp));

let mut ip_routes_exp = [
RouteMessageBuilder::<IpAddr>::new()
RouteMessageBuilder::<Ipv6Addr>::new()
.table_id(table_index)
.destination_prefix("fc00::".parse()?, 16)?
.destination_prefix("fc00::".parse()?, 16)
.output_interface(dummy_index)
.gateway("fc64::ffff".parse()?)?
.gateway("fc64::ffff".parse()?)
.build(),
RouteMessageBuilder::<IpAddr>::new()
RouteMessageBuilder::<Ipv6Addr>::new()
.table_id(table_index)
.destination_prefix("fc65:6565::".parse()?, 32)?
.destination_prefix("fc65:6565::".parse()?, 32)
.output_interface(dummy_index)
.gateway("fc64::2333".parse()?)?
.gateway("fc64::2333".parse()?)
.build(),
];
ip_routes_exp.iter_mut().for_each(route_msg_normalize);
Expand All @@ -188,6 +188,17 @@ async fn test_redirect_to_ipv6() -> anyhow::Result<()> {
Ok(())
}

#[apply(test_local!)]
async fn test_random_114514() -> anyhow::Result<()> {
let (conn, handle, _) = rtnetlink::new_connection()?;
tokio::spawn(conn);
let ip_routes = get_ip_route(&handle, IpVersion::V4, 254).await?;

println!("{ip_routes:?}");

Ok(())
}

// TODO: test IPv4 with IPv6 nexthop
// TODO: test IPv6 offset

Expand Down
2 changes: 1 addition & 1 deletion src/kernel/rtnl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl<K: Kernel> RtNetlink<K> {
.destination_prefix(ip, if ip.is_ipv4() { 32 } else { 128 })
.expect("destination prefix should be valid")
.build();
let mut msg = (handle.route()).get(msg).dump(false).execute();
let mut msg = handle.route().get(msg).execute();
let Some(rt) = msg.try_next().await? else {
unreachable!();
};
Expand Down

0 comments on commit d8299a5

Please sign in to comment.