Windows: do_ifconfig() after open_tun()
PATCH 1/1 Windows: do_ifconfig() after open_tun()
When you had multiple TAP adapters and IPv6 configured you got an error message about "you must also specify --dev-node" and openvpn exited. Very inconvenient especially since this is only due to the fact that Windows tries to set the adapter address before it is opened; for no good reason.
This patch changes the order to IFCONFIG_AFTER_TUN_OPEN, moves some initialization code to init_tun, where it belongs, and removes duplicate code that is now no longer needed.
--- src/openvpn/tun.c | 56 ++++++++++++++++++------------------------------------- src/openvpn/tun.h | 2 +- 2 files changed, 19 insertions(+), 39 deletions(-)
src/openvpn/tun.c +18 -38
@@ -611,6 +611,21 @@ init_tun (const char *dev, /* --dev option */ tt->broadcast =generate_ifconfig_broadcast_addr (tt->local, tt->remote_netmask); } +#ifdef WIN32 +/* +* Make sure that both ifconfig addresses are part of the +* same .252 subnet. +*/ +if (tun) + { +verify_255_255_255_252 (tt->local, tt->remote_netmask); + tt->adapter_netmask = ~3 ; + } +else + { + tt->adapter_netmask = tt->remote_netmask; + } +#endif tt->did_ifconfig_setup = true; }
@@ -1327,19 +1342,7 @@ do_ifconfig (struct tuntap *tt, }#elif defined (WIN32) { -/* -* Make sure that both ifconfig addresses are part of the -* same .252 subnet. -*/ -if (tun) - { -verify_255_255_255_252 (tt->local, tt->remote_netmask); - tt->adapter_netmask = ~3 ; - } -else - { - tt->adapter_netmask = tt->remote_netmask; - } +ASSERT (actual !=NULL );switch (tt->options.ip_win32_type) {
@@ -1350,9 +1353,6 @@ do_ifconfig (struct tuntap *tt, print_in_addr_t (tt->adapter_netmask, 0, &gc));break ;case IPW32_SET_NETSH : -if (!strcmp (actual,"NULL" )) -msg (M_FATAL ,"Error: When using --ip-win32 netsh, if you have more than one TAP-Windows adapter, you must also specify --dev-node" ); - netsh_ifconfig (&tt->options, actual, tt->local,
@@ -1366,25 +1366,6 @@ do_ifconfig (struct tuntap *tt,if ( do_ipv6 ) { -char * saved_actual; -char iface[64 ]; -DWORD idx; - -if (!strcmp (actual,"NULL" )) -msg (M_FATAL ,"Error: When using --tun-ipv6, if you have more than one TAP-Windows adapter, you must also specify --dev-node" ); - - idx =get_adapter_index_flexible (actual); -openvpn_snprintf (iface,sizeof (iface),"interface=%lu" , idx); - -/* on windows, OpenVPN does ifconfig first, open_tun later, so -* tt->actual_name might not yet be initialized, but routing code -* needs to know interface name - point to "actual", restore later -*/ - saved_actual = tt->actual_name; - tt->actual_name = (char *) actual; -/* we use adapter_index in add_route_ipv6 */ - tt->adapter_index = idx; -if (tt->options.msg_channel) {do_address_service (true,AF_INET6 , tt);
@@ -1393,17 +1374,16 @@ do_ifconfig (struct tuntap *tt, {/* example: netsh interface ipv6 set address interface=42 2001:608:8003::d store=active */ argv_printf (&argv, -"%s%sc interface ipv6 set address %s %s store=active" , +"%s%sc interface ipv6 set address interface=%lu %s store=active" ,get_win_sys_path (),NETSH_PATH_SUFFIX , - iface, + tt->adapter_index, ifconfig_ipv6_local );netsh_command (&argv,4 ,M_FATAL ); }/* explicit route needed */ add_route_connected_v6_net(tt, es); - tt->actual_name = saved_actual; }#else msg (M_FATAL ,"Sorry, but I don't know how to do 'ifconfig' commands on this operating system. You should ifconfig your TUN/TAP device manually or use an --up script." );
src/openvpn/tun.h +1 -1
@@ -301,7 +301,7 @@ ifconfig_order(void)#elif defined(TARGET_NETBSD )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(WIN32 ) -return IFCONFIG_BEFORE_TUN_OPEN ; +return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_ANDROID )return IFCONFIG_BEFORE_TUN_OPEN ;#else
Signature · 1 line
2.7.4
Hi,
Quoted 3 lines · Heiko Hund
This patch changes the order to
IFCONFIG_AFTER_TUN_OPEN, moves some initialization code toinit_tun, where it belongs, and removes duplicate code that is now no longer needed.
While I totally like this, I'm still baffled why we had the other order before, and what might break due to the change. I assume you've already run quite a few --route-method variations in testing?
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]...Quoted 3 lines · On Freitag, 24. Juni 2016 19:37:13 CEST Gert Doering wrote:
This patch changes the order to
IFCONFIG_AFTER_TUN_OPEN, moves some initialization code toinit_tun, where it belongs, and removes duplicate code that is now no longer needed.
Yeah, I was skeptic at first, too. But it seems to work. That said, I've only tested with the interactive service in place. It's the only option how to run Openvpn in a sane manner on Windows anyways. =)
Cheers
Heiko
Quoted 5 lines · Heiko Hund
Quoted 3 lines · On Freitag, 24. Juni 2016 19:37:13 CEST Gert Doering wrote:
This patch changes the order to
IFCONFIG_AFTER_TUN_OPEN, moves some initialization code toinit_tun, where it belongs, and removes duplicate code that is now no longer needed.
Quoted 7 lines
Yeah, I was skeptic at first, too. But it seems to work. That said, I've only
tested with the interactive service in place. It's the only option how to run
Openvpn in a sane manner on Windows anyways. =)
True but not yet practical in some cases. For example, we do not yet have way to start openvpn using interactive service without using the GUI -- say run a client or a server (as from an init script). We should do something about it, but until then testing without interactive service is important -- easy to do, just run from the command line.
Also, a test against the old tap driver (NDIS 5.x) is in order..
Selva
Hi,
Quoted 3 lines · Heiko Hund
This patch changes the order to
IFCONFIG_AFTER_TUN_OPEN, moves some initialization code toinit_tun, where it belongs, and removes duplicate code that is now no longer needed.
Plus "it tries to make code look nicer and breaks it"...
Quoted 4 lines
src/openvpn/tun.c +0
-0@@ -1366,25 +1366,6 @@ do_ifconfig (struct tuntap *tt,if ( do_ipv6 ) {
src/openvpn/tun.c do_ifconfig (struct tuntap *tt, · line 1378
Quoted 10 lines
src/openvpn/tun.c +0
-10-char * saved_actual; -char iface[64 ]; -DWORD idx; - -if (!strcmp (actual,"NULL" )) -msg (M_FATAL ,"Error: When using --tun-ipv6, if you have more than one TAP-Windows adapter, you must also specify --dev-node" ); - - idx =get_adapter_index_flexible (actual); -openvpn_snprintf (iface,sizeof (iface),"interface=%lu" , idx); -
The reason why "interface=%lu" is snprintf()'ed into "iface" is that...
src/openvpn/tun.c do_ifconfig (struct tuntap *tt, · line 1377
Quoted 6 lines
src/openvpn/tun.c +1
-1@@ -1393,17 +1374,16 @@ do_ifconfig (struct tuntap *tt, {/* example: netsh interface ipv6 set address interface=42 2001:608:8003::d store=active */ argv_printf (&argv, - "%s%sc interface ipv6 set address %s %s store=active", + "%s%sc interface ipv6 set address interface=%lu %s store=active",
... argv_printf() does not understand "%lu", thus ignores it, finds "%s" as the next argument, and blows up trying to string-copy "tt->adapter_index".
When doing massive changes, please do not "optimize" at the same time...
Running more tests with that hunk reverted next...
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]...Hi,
Quoted 1 line · Gert Doering
Running more tests with that hunk reverted next...
With the following patch applied on top of Heiko's patch
src/openvpn/tun.c +4 -2
@@ -1373,11 +1373,13 @@ do_ifconfig (struct tuntap *tt,else {/* example: netsh interface ipv6 set address interface=42 2001:608:8003::d store=active */ +char iface[64 ]; +openvpn_snprintf (iface,sizeof (iface),"interface=%lu" , tt->adapter_index );argv_printf (&argv, -"%s%sc interface ipv6 set address interface=%lu %s store=active" , +"%s%sc interface ipv6 set address %s %s store=active" ,get_win_sys_path (),NETSH_PATH_SUFFIX , - tt->adapter_index, + iface, ifconfig_ipv6_local );netsh_command (&argv,4 ,M_FATAL ); }
... the resulting binary now actually works :-) - tested on win7, without(!) iservice (because Heiko already tested that), testing all the variants of "--ip-win32". Only a single tap adapter in the system, but will test with 2-3 taps next (and trying to run multiple instances).
I've done a "v2" of Heiko's patch with that change included, which I'll append below. Samuli, could you build us a windows installer with master plus that patch, for "windows early alpha testing"? If that change works for people, we are very close to 2.4_alpha1...
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 a98ac9043ea9445537936a88808d3d1939102e39 Mon Sep 17 00:00:00 2001
From: Heiko Hund <[email protected]...>
Date: Fri, 24 Jun 2016 18:01:41 +0200
Subject: [PATCH] Windows: do_ifconfig() after open_tun()
When you had multiple TAP adapters and IPv6 configured you got an error message about "you must also specify --dev-node" and openvpn exited. Very inconvenient especially since this is only due to the fact that Windows tries to set the adapter address before it is opened; for no good reason.
This patch changes the order to IFCONFIG_AFTER_TUN_OPEN, moves some initialization code to init_tun, where it belongs, and removes duplicate code that is now no longer needed.
v2: do not use "%lu" in argv_printf(), crashes non-iservice usage
--- src/openvpn/tun.c | 54 ++++++++++++++++++------------------------------------ src/openvpn/tun.h | 2 +- 2 files changed, 19 insertions(+), 37 deletions(-)
src/openvpn/tun.c +18 -36
90 lines not on this page · raw message
src/openvpn/tun.h +1 -1
@@ -301,7 +301,7 @@ ifconfig_order(void)#elif defined(TARGET_NETBSD )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(WIN32 ) -return IFCONFIG_BEFORE_TUN_OPEN ; +return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_ANDROID )return IFCONFIG_BEFORE_TUN_OPEN ;#else
Signature · 1 line
1.9.1
Il 09/10/2016 18:25, Gert Doering ha scritto:
Quoted 34 lines
Hi,
Quoted 1 line · Gert Doering
Running more tests with that hunk reverted next...
With the following patch applied on top of Heiko's patch
src/openvpn/tun.c +4
-2@@ -1373,11 +1373,13 @@ do_ifconfig (struct tuntap *tt,else {/* example: netsh interface ipv6 set address interface=42 2001:608:8003::d store=active */ +char iface[64 ]; +openvpn_snprintf (iface,sizeof (iface),"interface=%lu" , tt->adapter_index );argv_printf (&argv, -"%s%sc interface ipv6 set address interface=%lu %s store=active" , +"%s%sc interface ipv6 set address %s %s store=active" ,get_win_sys_path (),NETSH_PATH_SUFFIX , - tt->adapter_index, + iface, ifconfig_ipv6_local );netsh_command (&argv,4 ,M_FATAL ); }... the resulting binary now actually works :-) - tested on win7, without(!) iservice (because Heiko already tested that), testing all the variants of "--ip-win32". Only a single tap adapter in the system, but will test with 2-3 taps next (and trying to run multiple instances).
Quoted 7 lines
I've done a "v2" of Heiko's patch with that change included, which I'll append below. Samuli, could you build us a windows installer with master plus that patch, for "windows early alpha testing"? If that change works for people, we are very close to 2.4_alpha1...
gert
Installers with the attached patch:
<http://build.openvpn.net/downloads/temp/openvpn-install-2.3_git-do-ifconfig-after-tun-v2-I601-i686.exe>
<http://build.openvpn.net/downloads/temp/openvpn-install-2.3_git-do-ifconfig-after-tun-v2-I601-x86_64.exe>
Signature · 5 lines
Samuli Seppänen Community Manager OpenVPN Technologies, Inc irc freenode net: mattock
Hi
Quoted 5 lines · Samuli Seppänen
Installers with the attached patch:
<http://build.openvpn.net/downloads/temp/openvpn-install-2.3_git-do-ifconfig-after-tun-v2-I601-i686.exe>
<http://build.openvpn.net/downloads/temp/openvpn-install-2.3_git-do-ifconfig-after-tun-v2-I601-x86_64.exe>
For the hell of it I tested -i686 on WXP ..
It successfully installs but then fails to run, missing fwpuclnt.dll
You may want to include a refusal to install on WXP ?
Regards
Il 10/10/2016 18:09, debbie10t ha scritto:
Quoted 6 lines
Hi
Quoted 2 lines · Samuli Seppänen
Installers with the attached patch:
Quoted 9 lines
Quoted 3 lines
<http://build.openvpn.net/downloads/temp/openvpn-install-2.3_git-do-ifconfig-after-tun-v2-I601-i686.exe>
<http://build.openvpn.net/downloads/temp/openvpn-install-2.3_git-do-ifconfig-after-tun-v2-I601-x86_64.exe>For the hell of it I tested -i686 on WXP ..
It successfully installs but then fails to run, missing fwpuclnt.dllYou may want to include a refusal to install on WXP ?
Hi,
We did exactly that in "Fail if trying to run I60x installer on Windows XP" commit:
<https://github.com/OpenVPN/openvpn-build/commit/65e328c89182c47d1a93398e04ca92199bf17af3>
Even though that change was crafted pretty carefully, it made all installers - including I00x ones - fail on Windows XP. So we had to revert the change:
<https://github.com/OpenVPN/openvpn-build/commit/42aed3b6e1267258830a6a071b477b5524500a4b>
I have not had time to look into that issue again. If somebody has a clue why the NSI code in commit 65e328c89 did not work please let me know.
Signature · 5 lines
Samuli Seppänen Community Manager OpenVPN Technologies, Inc irc freenode net: mattock
Quoted 21 lines · On Sonntag, 9. Oktober 2016 17:25:50 CEST Gert Doering wrote:
src/openvpn/tun.c +3
-2@@ -1373,11 +1373,13 @@ do_ifconfig (struct tuntap *tt,else {/* example: netsh interface ipv6 set address interface=42 2001:608:8003::d store=active */ + char iface[64]; +openvpn_snprintf (iface,sizeof (iface),"interface=%lu" , tt->adapter_index );argv_printf (&argv, -"%s%sc interface ipv6 set address interface=%lu %s store=active" , +"%s%sc interface ipv6 set address %s %s store=active" ,get_win_sys_path (),NETSH_PATH_SUFFIX , - tt->adapter_index, + iface, ifconfig_ipv6_local );netsh_command (&argv,4 ,M_FATAL ); }
Quoted 4 lines
I've done a "v2" of Heiko's patch with that change included, which I'll append below. Samuli, could you build us a windows installer with master plus that patch, for "windows early alpha testing"? If that change works for people, we are very close to 2.4_alpha1...
ACK for the partial rollback.
Shakes fist at argv_printf(). =)
Thanks Gert
Your patch has been applied to the master branch.
(ACK for v1 from me, ACK for v2 from Heiko, so stuff indeed got reviewed
- and with all the windows testing reports, it even got *tested* properly)
commit 533495298bd93ddaaf4418dc666922779ce5ef9b
Author: Heiko Hund Date: Fri Jun 24 18:01:41 2016 +0200
Windows: do_ifconfig() after open_tun()
Signed-off-by: Heiko Hund <[email protected]...>
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Acked-by: Heiko Hund <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg12631.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering