]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Del ipv6 addr on close of linux tun interface
authorHolger Kummert <Holger.Kummert@Sophos.com>
Thu, 25 Jun 2015 16:01:20 +0000 (18:01 +0200)
committerGert Doering <gert@greenie.muc.de>
Fri, 26 Jun 2015 19:41:33 +0000 (21:41 +0200)
When a linux tun interface is closed (e.g. on disconnect)
an optional ipv6 addr that was previously set is deleted now.
Without this patch a later reconnect could fail with
'Linux ip -6 addr add failed: external program exited with error status: 2'
and openvpn would exit.

This is mainly relevant for persistant tun devices (staying around
after openvpn exits) but can also happen at reconnect.

If addresses are *supposed* to stay around on openvpn exit, run
openvpn with --ifconfig-noexec and configure IPv4/IPv6 addresses
manually before openvpn starts (or using an --up script).

Trac #141

Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1435248080-12670-1-git-send-email-Holger.Kummert@Sophos.com>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9810

Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/tun.c

index 59e7436bf66fdbf6e17fa933c838ca51943e5ba1..13e38267307b75a9d2736b38348ed422c0459b46 100644 (file)
@@ -1860,6 +1860,32 @@ close_tun (struct tuntap *tt)
            argv_msg (M_INFO, &argv);
            openvpn_execve_check (&argv, NULL, 0, "Linux ip addr del failed");
 
+            if (tt->ipv6 && tt->did_ifconfig_ipv6_setup)
+              {
+                const char * ifconfig_ipv6_local = print_in6_addr (tt->local_ipv6, 0, &gc);
+
+#ifdef ENABLE_IPROUTE
+                argv_printf (&argv, "%s -6 addr del %s/%d dev %s",
+                                    iproute_path,
+                                    ifconfig_ipv6_local,
+                                    tt->netbits_ipv6,
+                                    tt->actual_name
+                                    );
+                argv_msg (M_INFO, &argv);
+                openvpn_execve_check (&argv, NULL, 0, "Linux ip -6 addr del failed");
+#else
+                argv_printf (&argv,
+                            "%s %s del %s/%d",
+                            IFCONFIG_PATH,
+                            tt->actual_name,
+                            ifconfig_ipv6_local,
+                            tt->netbits_ipv6
+                            );
+                argv_msg (M_INFO, &argv);
+                openvpn_execve_check (&argv, NULL, 0, "Linux ifconfig inet6 del failed");
+#endif
+              }
+
            argv_reset (&argv);
            gc_free (&gc);
          }