]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
vpnc-script-win: make VPN addresses/gateways "non-persistent", and delete them on...
authorDaniel Lenski <dlenski@gmail.com>
Wed, 31 Mar 2021 23:23:38 +0000 (16:23 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Thu, 1 Apr 2021 01:11:39 +0000 (01:11 +0000)
Persisting the state of IPv4 configuration of these interfaces is generally
unhelpful (as with DNS/WINS settings).

Two approaches. We do both:

1. Make the addresses ephemeral ("netsh ... store=active", as opposed to the
   "store=persistent" default). This ensures that the addresses won't last
   past reboot.
2. Delete the addresses upon disconnection.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
vpnc-script-win.js

index 3b698f688d5949ebe8e061297df8c143d07ccc62..91a575289b334b9a0b89ccd3c09b45ad302f1a02 100644 (file)
@@ -88,16 +88,17 @@ case "connect":
 
     if (!env("CISCO_SPLIT_INC") && REDIRECT_GATEWAY_METHOD != 2) {
         // Interface metric must be set to 1 in order to add a route with metric 1 since Windows Vista
-        run("netsh interface ip set interface \"" + env("TUNIDX") + "\" metric=1");
+        run("netsh interface ip set interface \"" + env("TUNIDX") + "\" metric=1 store=active");
     }
 
     if (env("CISCO_SPLIT_INC") || REDIRECT_GATEWAY_METHOD > 0) {
         run("netsh interface ip set address \"" + env("TUNIDX") + "\" static " +
-            env("INTERNAL_IP4_ADDRESS") + " " + env("INTERNAL_IP4_NETMASK"));
+            env("INTERNAL_IP4_ADDRESS") + " " + env("INTERNAL_IP4_NETMASK") + " store=active");
     } else {
         // The default route will be added automatically
         run("netsh interface ip set address \"" + env("TUNIDX") + "\" static " +
-            env("INTERNAL_IP4_ADDRESS") + " " + env("INTERNAL_IP4_NETMASK") + " " + internal_gw + " 1");
+            env("INTERNAL_IP4_ADDRESS") + " " + env("INTERNAL_IP4_NETMASK") + " " + internal_gw +
+            " gwmetric=1 store=active");
     }
 
     // Add direct route for the VPN gateway to avoid routing loops
@@ -201,6 +202,14 @@ case "disconnect":
     // FIXME: handle IPv6 gateway address
     run("route delete " + env("VPNGATEWAY") + " mask 255.255.255.255");
 
+    // Delete address
+    run("netsh interface ipv4 del address " + env("TUNIDX") + " " +
+        env("INTERNAL_IP4_ADDRESS") + " gateway=all");
+    if (env("INTERNAL_IP6_ADDRESS")) {
+        run("netsh interface ipv6 del address " + env("TUNIDX") + " " +
+            env("INTERNAL_IP6_ADDRESS"));
+    }
+
     // Delete Legacy IP split-exclude routes
     if (env("CISCO_SPLIT_EXC")) {
         for (var i = 0 ; i < parseInt(env("CISCO_SPLIT_EXC")); i++) {