diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index 647b281a2..1d488b388 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -312,7 +312,6 @@ impl Handle { for route in list { let link = self.find_link(LinkFilter::Name(&route.device)).await?; - let is_v6 = is_ipv6(route.get_gateway()) || is_ipv6(route.get_dest()); const MAIN_TABLE: u8 = packet::constants::RT_TABLE_MAIN; const UNICAST: u8 = packet::constants::RTN_UNICAST; @@ -334,7 +333,7 @@ impl Handle { // `rtnetlink` offers a separate request builders for different IP versions (IP v4 and v6). // This if branch is a bit clumsy because it does almost the same. - if is_v6 { + if route.get_family() == IPFamily::v6 { let dest_addr = if !route.dest.is_empty() { Ipv6Network::from_str(&route.dest)? } else { @@ -594,10 +593,6 @@ fn format_address(data: &[u8]) -> Result { } } -fn is_ipv6(str: &str) -> bool { - Ipv6Addr::from_str(str).is_ok() -} - fn parse_mac_address(addr: &str) -> Result<[u8; 6]> { let mut split = addr.splitn(6, ':'); @@ -932,16 +927,6 @@ mod tests { assert_eq!(bytes, [0xAB, 0x0C, 0xDE, 0x12, 0x34, 0x56]); } - #[test] - fn check_ipv6() { - assert!(is_ipv6("::1")); - assert!(is_ipv6("2001:0:3238:DFE1:63::FEFB")); - - assert!(!is_ipv6("")); - assert!(!is_ipv6("127.0.0.1")); - assert!(!is_ipv6("10.10.10.10")); - } - fn clean_env_for_test_add_one_arp_neighbor(dummy_name: &str, ip: &str) { // ip link delete dummy Command::new("ip")