From e7e98f7da95d44d35e4abea2f6ad7a285e91f8ac Mon Sep 17 00:00:00 2001 From: Payn Date: Thu, 29 May 2025 17:31:49 +0200 Subject: [PATCH 1/2] Fix parsing correct IPv6 gateway on linux Currently all IPs from routes /proc/net/ipv6_route are selected instead of just the gateway. Added filter for selecting default route. --- src/gateway/linux.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gateway/linux.rs b/src/gateway/linux.rs index a17e1c4..410c921 100644 --- a/src/gateway/linux.rs +++ b/src/gateway/linux.rs @@ -93,9 +93,16 @@ fn get_ipv6_gateway_map() -> HashMap { for row in route_table { let fields: Vec<&str> = row.split_whitespace().collect(); if fields.len() >= 10 { + // fields[0]: destination + // fields[1]: destination prefix length // fields[4]: IPv6 Address 32 hex chars without colons // fields[9]: Interface Name - if fields[4] != "00000000000000000000000000000000" { + + // default route has zero destination and zero prefix length + if fields[0] == "00000000000000000000000000000000" && + fields[1] == "00" && + fields[4] != "00000000000000000000000000000000" + { ipv6_gateway_map.insert(fields[9].to_string(), convert_hex_ipv6(fields[4])); } } From f5c0762161a84c6a6b0ee9afade094863e24375e Mon Sep 17 00:00:00 2001 From: Payn Date: Thu, 29 May 2025 17:39:21 +0200 Subject: [PATCH 2/2] formatting --- src/gateway/linux.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gateway/linux.rs b/src/gateway/linux.rs index 410c921..34543b9 100644 --- a/src/gateway/linux.rs +++ b/src/gateway/linux.rs @@ -99,9 +99,9 @@ fn get_ipv6_gateway_map() -> HashMap { // fields[9]: Interface Name // default route has zero destination and zero prefix length - if fields[0] == "00000000000000000000000000000000" && - fields[1] == "00" && - fields[4] != "00000000000000000000000000000000" + if fields[0] == "00000000000000000000000000000000" + && fields[1] == "00" + && fields[4] != "00000000000000000000000000000000" { ipv6_gateway_map.insert(fields[9].to_string(), convert_hex_ipv6(fields[4])); }