Skip to contentSkip to conversation

OpenVPN netsh.exe patch

Openvpn-devel Seth Mos 5 participants 8 messages May 10, 2011 – May 23, 2011

lore
Share & tools
lore
#2 lore raw

Hi,

Quoted 10 lines · Jan Just Keijser
Quoted 6 lines · Seth Mos

Here is the tun.c patch for correction of the netsh.exe commands.

I've confirmed that the patch works on Windows XP SP2 and Windows 7.

Patch!
http://iserv.nl/files/pfsense/0001-Change-the-netsh.exe-command-from-add-to-set-.-Th.patch

please explain the rationale behind this patch: is something wrong when using 'ipv6 add address' ?

Without "store=active", address assignment is "sticky" and will even survive reboots - thus making the next tunnel setup fail, because the address is already there. On WinXP, that was not needed, but Win7 seems to have changed the default.

Quoted 1 line

why is the patch applied only for IPv6 addresses?

OpenVPN by default doesn't use netsh to configure IPv4 - so it might be necessary there as well, but didn't show up yet. For IPv6, there is only a single method of configuration - netsh - and that breaks on Win7 otherwise.

I have not yet tested this, but Seth has, both on XP and Win7, so "ACK!"...

David: I think it's easiest in this case if I integrate it, and then send it to you. It needs to go to my "based on 2.2" branch as well.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#3 lore raw

Hi,

Quoted 13 lines · Gert Doering

Hi,

Quoted 9 lines · Jan Just Keijser
Quoted 7 lines · Seth Mos

Here is the tun.c patch for correction of the netsh.exe commands.

I've confirmed that the patch works on Windows XP SP2 and Windows 7.

Patch!
http://iserv.nl/files/pfsense/0001-Change-the-netsh.exe-command-from-add-to-set-.-Th.patch

Quoted 10 lines
Quoted 3 lines

please explain the rationale behind this patch: is something wrong when using 'ipv6 add address' ?

Without "store=active", address assignment is "sticky" and will even survive reboots - thus making the next tunnel setup fail, because the address is already there. On WinXP, that was not needed, but Win7 seems to have changed the default.

but then why not use
add address <> store=active
? why switch to "set address" ? what's the difference?

JJK

#5 lore raw
In reply to Gert Doering

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Gert Doering

I have not yet tested this, but Seth has, both on XP and Win7, so "ACK!"...

Windows XP SP2 is tested ... what about older XPs? Personally, I am in favour of only supporting Windows versions which Microsoft officially supports.

<http://windows.microsoft.com/en-us/windows/products/lifecycle>

Windows XP SP2 was supported until June 13, 2010. Now only Windows XP SP3 is supported.

Quoted 2 lines

David: I think it's easiest in this case if I integrate it, and then send it to you. It needs to go to my "based on 2.2" branch as well.

It doesn't matter for me. You either pull it in, and I merge in your tree.
Or I pull it in and you rebase your 2.3 working branch against my master
and then you can cherry-pick this commit for your IPv6 2.2 branch.

kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk3JSrIACgkQDC186MBRfrp9MwCgk/df5IPuAEoTZS3vse6TjDX3 JaAAoJNPMglECeeC6flBczbRhT0An9cx
=MmyN
-----END PGP SIGNATURE-----

#6 lore raw
In reply to Gert Doering
Quoted 23 lines · Gert Doering

Hi,

Quoted 9 lines · Jan Just Keijser
Quoted 6 lines · Seth Mos

Here is the tun.c patch for correction of the netsh.exe commands.

I've confirmed that the patch works on Windows XP SP2 and Windows 7.

Patch!
http://iserv.nl/files/pfsense/0001-Change-the-netsh.exe-command-from-add-to-set-.-Th.patch

please explain the rationale behind this patch: is something wrong when using 'ipv6 add address' ?

Without "store=active", address assignment is "sticky" and will even survive reboots - thus making the next tunnel setup fail, because the address is already there. On WinXP, that was not needed, but Win7 seems to have changed the default.

Quoted 1 line

why is the patch applied only for IPv6 addresses?

OpenVPN by default doesn't use netsh to configure IPv4 - so it might be necessary there as well, but didn't show up yet. For IPv6, there is only a single method of configuration - netsh - and that breaks on Win7 otherwise.

Quoted 7 lines

I have not yet tested this, but Seth has, both on XP and Win7, so "ACK!"...

David: I think it's easiest in this case if I integrate it, and then send it to you. It needs to go to my "based on 2.2" branch as well.

gert

I can confirm that the IPv6 configuration stays around after disconnect. I run a openvpn server with Gert's patches, and I have to run a "cleanup" down script after I disconnect to remove the IPv6 address and route.

#4 lore raw
In reply to Jan Just Keijser

Hi,

Quoted 8 lines · Jan Just Keijser
Quoted 5 lines

Without "store=active", address assignment is "sticky" and will even survive reboots - thus making the next tunnel setup fail, because the address is already there. On WinXP, that was not needed, but Win7 seems to have changed the default.

but then why not use
add address <> store=active
? why switch to "set address" ? what's the difference?

Sorry for taking a while to come back to this. I needed to re-read the Windows reference docs to be sure.

I originally had "add address" there because that's what I tried and what worked - and that's sort of based on "ip -6 addr add" thinking in the back of my head, where there is basically only "add" and "delete" (and "replace a *given* address").

OTOH, what I really want here is "whatever is on the interface, make it go away and use only the address that I'm telling you to use!", and that's "netsh interface ipv6 *set*"...

Reference is here:
http://technet.microsoft.com/en-us/library/cc740203%28WS.10%29.aspx#BKMK_20

So, strictly speaking, the change "add" -> "set" is not required to make it work on Win7, it actually better fits what the code is trying to do.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
Acked-by
#7 lore raw
In reply to Seth Mos

Hi,

Quoted 1 line · Seth Mos

Here is the tun.c patch for correction of the netsh.exe commands.

So. Took me a while to incorporate it, and I took the opportunity to do more windows ipv6 related cleanups:

- add routes with "store=active" as well (so if the machine crashes while OpenVPN is connectes, routes don't survive)

- remove ifconfig and routes on disconnect - the latter part needed changes in more generic parts of route.c, route.h and tun.c

I have built and tested the resulting code on Linux, OpenBSD (because that would be affected by a breakage in the changed route.c code), WinXP and Win7 - and I also got independent test success reports for Win7 from Tony Lim (thanks!), so I consider this code sane :-)

Patches attached for review.

David: please pull from git://compile.svr01.mucip.net/openvpn-gert.git,
all that is in the "feat_ipv6_payload_2.3" branch

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...

From 39990a2b83308baf1372bbc8846136036a55cf50 Mon Sep 17 00:00:00 2001
From: smos <[email protected]...>
Date: Tue, 10 May 2011 10:01:48 +0200
Subject: [PATCH 1/2] Change the netsh.exe command from "add" to "set".

This prevents the netsh.exe command from exiting with a status 1 when the address already exists. By adding store=active the address will not survive a reboot and be assigned temporarily.

Tested on Windows 7 and Windows XP SP 2.

---
 tun.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tun.c +2 -2
index 45db2b5..55d66e1 100644
@@ -1167,9 +1167,9 @@ do_ifconfig (struct tuntap *tt,
 	if (!strcmp (actual, "NULL"))
 	  msg (M_FATAL, "Error: When using --tun-ipv6, if you have more than one TAP-Win32 adapter, you must also specify --dev-node");
 
-	/* example: netsh interface ipv6 add address MyTap 2001:608:8003::d */
+	/* example: netsh interface ipv6 set address MyTap 2001:608:8003::d store=active */
 	argv_printf (&argv,
-		    "%s%sc interface ipv6 add address %s %s",
+		    "%s%sc interface ipv6 set address %s %s store=active",
 		     get_win_sys_path(),
 		     NETSH_PATH_SUFFIX,
 		     actual,
Signature · 1 line
1.7.3.4

From b55e49bd69484fdd440098f9485de159251e1cce Mon Sep 17 00:00:00 2001
From: Gert Doering <[email protected]...>
Date: Sun, 22 May 2011 19:02:39 +0200
Subject: [PATCH 2/2] Windows IPv6 cleanup - properly remove IPv6 routes and interface config
after tunnel shutdown. Needs to make delete_route_ipv6() visible from
tun.c (route.c, route.h) and to properly zero-out host bits from IPv6 "network" at interface route clearing. Further, add IPv6 routes with "store=active" to make sure nothing lingers after a system crash while OpenVPN was running.

While at it, small Solaris cleanup - use CLEAR() to zero-out "ifr" struct.

Tested on Windows XP SP3 and Win7 by Gert Doering and Tony Lim.

---
 ChangeLog.IPv6 |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 options.c      |    2 +-
 route.c        |   52 +++++++++++++++++++++++++++++++---------------------
 route.h        |    1 +
 tun.c          |   30 ++++++++++++++++++++++++++++--
 5 files changed, 107 insertions(+), 24 deletions(-)
ChangeLog.IPv6 +46 -0

49 lines not on this page · raw message

options.c +1 -1
index 6f98d14..824492e 100644
@@ -80,7 +80,7 @@ const char title_string[] =
 #ifdef ENABLE_EUREPHIA
   " [eurephia]"
 #endif
-  " [IPv6 payload 20110424-2 (2.2RC2)]"
+  " [IPv6 payload 20110522-1 (2.2.0)]"
   " built on " __DATE__
 ;
 
route.c +31 -21

94 lines not on this page · raw message

route.h +1 -0
index 739d12d..6a7704f 100644
@@ -176,6 +176,7 @@ struct route_ipv6_list *new_route_ipv6_list (const int max_routes, struct gc_are
 
 void add_route (struct route *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
 void add_route_ipv6 (struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
+void delete_route_ipv6 (const struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
 
 void add_route_to_option_list (struct route_option_list *l,
 			       const char *network,
tun.c +28 -2
index 55d66e1..cea1784 100644
@@ -591,6 +591,18 @@ void add_route_connected_v6_net(struct tuntap * tt,
     r6.gateway = tt->local_ipv6;
     add_route_ipv6 (&r6, tt, 0, es);
 }
+
+void delete_route_connected_v6_net(struct tuntap * tt,
+	                           const struct env_set *es)
+{
+    struct route_ipv6 r6;
+
+    r6.defined = true;
+    r6.network = tt->local_ipv6;
+    r6.netbits = tt->netbits_ipv6;
+    r6.gateway = tt->local_ipv6;
+    delete_route_ipv6 (&r6, tt, 0, es);
+}
 #endif
 
 
@@ -1649,7 +1661,7 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu
    * http://www.whiteboard.ne.jp/~admin2/tuntap/
    * has IPv6 support
    */
-  memset(&ifr, 0x0, sizeof(ifr));
+  CLEAR(ifr);
 
   if (tt->type == DEV_TYPE_NULL)
     {
@@ -4851,9 +4863,23 @@ close_tun (struct tuntap *tt)
     {
       if ( tt->ipv6 && tt->did_ifconfig_ipv6_setup )
         {
+	  struct argv argv;
+	  argv_init (&argv);
+
+	  /* remove route pointing to interface */
+	  delete_route_connected_v6_net(tt, NULL);
+
 	  /* netsh interface ipv6 delete address \"%s\" %s */
 	  const char * ifconfig_ipv6_local = print_in6_addr (tt->local_ipv6, 0, &gc);
-	  msg( M_WARN, "TODO: remove IPv6 address %s", ifconfig_ipv6_local );
+	  argv_printf (&argv,
+		    "%s%sc interface ipv6 delete address %s %s",
+		     get_win_sys_path(),
+		     NETSH_PATH_SUFFIX,
+		     tt->actual_name,
+		     ifconfig_ipv6_local );
+
+	  netsh_command (&argv, 1);
+          argv_reset (&argv);
 	}
 #if 1
       if (tt->ipapi_context_defined)
Signature · 1 line
1.7.3.4