net/mwan3: add custom address from ip tables to connected ipset
authorFlorian Eckert <redacted>
Mon, 15 Oct 2018 09:22:35 +0000 (11:22 +0200)
committerFlorian Eckert <redacted>
Tue, 23 Oct 2018 12:49:34 +0000 (14:49 +0200)
With the list param "rt_table_lookup" in the mwan3 section globals,
it is now possible to add a additional routing table numbers which would get
also parsed and will be added to the connected network.
So mwan3 will treat them as they are directly connected to this device.

This could be usefull if we use ipsec.

Signed-off-by: Florian Eckert <redacted>
net/mwan3/files/etc/hotplug.d/iface/15-mwan3
net/mwan3/files/lib/mwan3/mwan3.sh

index a02f88baa70ed245880f531ae8245c1c088b9cf2..897872e68b4cd2206653184c8d6b043a5b72647e 100644 (file)
@@ -19,6 +19,7 @@ config_get_bool enabled globals 'enabled' '0'
 mwan3_lock
 mwan3_init
 mwan3_set_connected_iptables
+mwan3_set_custom_ipset
 mwan3_unlock
 
 config_get enabled $INTERFACE enabled 0
index eff51892b6afc34b2e0e083dd857fed8bf7e58aa..712abe07ca087f5b5cf1a4ecae924cf6a67d7243 100644 (file)
@@ -188,6 +188,46 @@ mwan3_get_iface_id()
        export "$1=$_tmp"
 }
 
+mwan3_set_custom_ipset_v4()
+{
+       local custom_network_v4
+
+       for custom_network_v4 in $($IP4 route list table "$1" | awk '{print $1}' | egrep '[0-9]{1,3}(\.[0-9]{1,3}){3}'); do
+               $LOG notice "Adding network $custom_network_v4 from table $1 to mwan3_custom_v4 ipset"
+               $IPS -! add mwan3_custom_v4_temp $custom_network_v4
+       done
+}
+
+mwan3_set_custom_ipset_v6()
+{
+       local custom_network_v6
+
+       for custom_network_v6 in $($IP6 route list table "$1" | awk '{print $1}' | egrep "$IPv6_REGEX"); do
+               $LOG notice "Adding network $custom_network_v6 from table $1 to mwan3_custom_v6 ipset"
+               $IPS -! add mwan3_custom_v6_temp $custom_network_v6
+       done
+}
+
+mwan3_set_custom_ipset()
+{
+       $IPS -! create mwan3_custom_v4 hash:net
+       $IPS create mwan3_custom_v4_temp hash:net
+       config_list_foreach "globals" "rt_table_lookup" mwan3_set_custom_ipset_v4
+       $IPS swap mwan3_custom_v4_temp mwan3_custom_v4
+       $IPS destroy mwan3_custom_v4_temp
+
+
+       $IPS -! create mwan3_custom_v6 hash:net family inet6
+       $IPS create mwan3_custom_v6_temp hash:net family inet6
+       config_list_foreach "globals" "rt_table_lookup" mwan3_set_custom_ipset_v6
+       $IPS swap mwan3_custom_v6_temp mwan3_custom_v6
+       $IPS destroy mwan3_custom_v6_temp
+
+       $IPS -! create mwan3_connected list:set
+       $IPS -! add mwan3_connected mwan3_custom_v4
+       $IPS -! add mwan3_connected mwan3_custom_v6
+}
+
 mwan3_set_connected_iptables()
 {
        local connected_network_v4 connected_network_v6
git clone https://git.99rst.org/PROJECT