From d6b051b8c0c2df246a1567555030d21690bdc011 Mon Sep 17 00:00:00 2001 From: Aaron Goodman Date: Fri, 29 May 2020 19:47:38 -0400 Subject: [PATCH] mwan3: don't add single ipv4 to connected list if already covered by a cidr Signed-off-by: Aaron Goodman (cherry picked from commit da9a626f78791b953a58ccd30987983ff52c8afc) --- net/mwan3/files/lib/mwan3/mwan3.sh | 36 ++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 5ffef9405e..eecd4a3807 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -238,26 +238,48 @@ mwan3_set_custom_ipset() $IPS -! add mwan3_connected mwan3_custom_v6 } -mwan3_set_connected_iptables() -{ - local connected_network_v4 connected_network_v6 source_network_v6 - - $IPS -! create mwan3_connected_v4 hash:net - $IPS create mwan3_connected_v4_temp hash:net +mwan3_set_connected_ipv4() +{ + local connected_network_v4 candidate_list cidr_list + candidate_list="" + cidr_list="" for connected_network_v4 in $($IP4 route | awk '{print $1}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do - $IPS -! add mwan3_connected_v4_temp "$connected_network_v4" + [ -z "${connected_network_v4##*/*}" ] && + cidr_list="$cidr_list $connected_network_v4" || + candidate_list="$candidate_list $connected_network_v4" done for connected_network_v4 in $($IP4 route list table 0 | awk '{print $2}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do + [ -z "${connected_network_v4##*/*}" ] && + cidr_list="$cidr_list $connected_network_v4" || + candidate_list="$candidate_list $connected_network_v4" + done + + for connected_network_v4 in $cidr_list; do $IPS -! add mwan3_connected_v4_temp "$connected_network_v4" done + for connected_network_v4 in $candidate_list; do + ipset -q test mwan3_connected_v4_temp "$connected_network_v4" || + $IPS -! add mwan3_connected_v4_temp "$connected_network_v4" + done $IPS add mwan3_connected_v4_temp 224.0.0.0/3 $IPS swap mwan3_connected_v4_temp mwan3_connected_v4 $IPS destroy mwan3_connected_v4_temp +} + +mwan3_set_connected_iptables() +{ + local connected_network_v6 source_network_v6 + + $IPS -! create mwan3_connected_v4 hash:net + $IPS create mwan3_connected_v4_temp hash:net + + mwan3_set_connected_ipv4 + $IPS -! create mwan3_connected_v6 hash:net family inet6 $IPS create mwan3_connected_v6_temp hash:net family inet6 -- 2.30.2