]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/scripts/ipsec-interfaces
ipsec: Find correct RED IP address when using %defaultroute
[ipfire-2.x.git] / src / scripts / ipsec-interfaces
index 4ba2980e57e416e0b4f46d8da964fcf8689512bf..521bf54eb1cbf476011b0f884ba2ea0601a54726 100644 (file)
@@ -23,6 +23,7 @@ shopt -s nullglob
 
 VPN_CONFIG="/var/ipfire/vpn/config"
 
+eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
 eval $(/usr/local/bin/readhash /var/ipfire/vpn/settings)
 
 VARS=(
@@ -42,6 +43,20 @@ main() {
        local action
 
        local interfaces=()
+       local vpn_ip
+
+       # Handle %defaultroute
+       if [ "${VPN_IP}" = "%defaultroute" ]; then
+               if [ -r "/var/ipfire/red/local-ipaddress" ]; then
+                       vpn_ip="$(</var/ipfire/red/local-ipaddress)"
+
+               elif [ "${RED_TYPE}" = "STATIC" -a -n "${RED_ADDRESS}" ]; then
+                       vpn_ip="${RED_ADDRESS}"
+
+               fi
+       else
+               vpn_ip="${VPM_IP}"
+       fi
 
        # We are done when IPsec is not enabled
        if [ "${ENABLED}" = "on" ]; then
@@ -66,7 +81,7 @@ main() {
                        interfaces+=( "${intf}" )
 
                        local args=(
-                               "local" "${VPN_IP}"
+                               "local" "${vpn_ip}"
                                "remote" "${righthost}"
                                "ttl" "255"
                        )