mwan3: don't add single ipv4 to connected list if already covered by a cidr
authorAaron Goodman <aaronjg@stanford.edu>
Fri, 29 May 2020 23:47:38 +0000 (19:47 -0400)
committerFlorian Eckert <fe@dev.tdt.de>
Mon, 27 Jul 2020 10:18:18 +0000 (12:18 +0200)
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
(cherry picked from commit da9a626f78791b953a58ccd30987983ff52c8afc)

net/mwan3/files/lib/mwan3/mwan3.sh

index 5ffef9405e1ee6da1a06aa8c1423d2895a2b87c9..eecd4a380778566bde0448a622b41b1dbc499abe 100644 (file)
@@ -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