Re: [Openvpn-devel] [PATCH] wintun: upgrade error message in case of ring registration failure

2020-03-10 Thread Lev Stipakov
Sorry, my bad - this is correct.

Compiled, tested with MSVC,

Acked-by: Lev Stipakov 


___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH applied] Re: wintun: upgrade error message in case of ring registration failure

2020-03-10 Thread Gert Doering
Your patch has been applied to the master branch.

"If Lev says so" :-) - code looks reasonable, test compiles fine (MinGW).

commit 089fbe653c3a8efd6dac8cc84448ccbe1d3aa887
Author: Simon Rozman
Date:   Wed Feb 5 19:38:41 2020 +0100

 wintun: upgrade error message in case of ring registration failure

 Signed-off-by: Simon Rozman 
 Acked-by: Lev Stipakov 
 Message-Id: <20200205183841.1118-1-si...@rozman.si>
 URL: 
https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg19367.html
 Signed-off-by: Gert Doering 


--
kind regards,

Gert Doering



___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH 2/2] tun.c: revise the IPv4 ifconfig flow on Windows

2020-03-10 Thread Simon Rozman
When provisioning IP configuration, we shall not ask what kind of
adapter this is. Rather, we should ask what method of provisioning we
are configured to use.

It is options.c's job to rule out invalid combinations.

- do_ifconfig_ipv4(): unify the workflow with its IPv6 counterpart
  No need to distinguish Wintun and TAP-Windows6 here. This also fixes
  an issue with --windows-driver wintun overriding --ip-win32 manual,
  the later being perfectly fine choice for Wintun too.

- open_tun() & tuntap_post_open(): unify Wintun and TAP-Windows6
  workflow. This allows allows --ip-win32 ipapi now.

- close_tun() the cleanup has been revised to match the ifconfig
  workflow in reverse.

Signed-off-by: Simon Rozman 
---
 src/openvpn/tun.c | 127 --
 1 file changed, 65 insertions(+), 62 deletions(-)

diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 42193d97..f7224093 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -1381,34 +1381,29 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, 
int tun_mtu,
 env_set_destroy(aix_es);
 }
 #elif defined (_WIN32)
-{
-ASSERT(ifname != NULL);
-
-if (tt->options.msg_channel && tt->windows_driver == 
WINDOWS_DRIVER_WINTUN)
-{
-do_address_service(true, AF_INET, tt);
-do_dns_service(true, AF_INET, tt);
-}
-else
-{
-switch (tt->options.ip_win32_type)
-{
-case IPW32_SET_MANUAL:
-msg(M_INFO,
-" NOTE:  Please manually set the IP/netmask of 
'%s' to %s/%s (if it is not already set)",
-ifname, ifconfig_local,
-print_in_addr_t(tt->adapter_netmask, 0, &gc));
-break;
+ASSERT(ifname != NULL);
 
-case IPW32_SET_NETSH:
-netsh_ifconfig(&tt->options, ifname, tt->local,
-   tt->adapter_netmask, 
NI_IP_NETMASK|NI_OPTIONS);
-
-break;
-}
-}
+if (tt->options.ip_win32_type == IPW32_SET_MANUAL)
+{
+msg(M_INFO,
+" NOTE:  Please manually set the IP/netmask of '%s' to 
%s/%s (if it is not already set)",
+ifname, ifconfig_local,
+print_in_addr_t(tt->adapter_netmask, 0, &gc));
+}
+else if (tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ || 
tt->options.ip_win32_type == IPW32_SET_ADAPTIVE)
+{
+/* Let the DHCP configure the interface. */
+}
+else if (tt->options.msg_channel)
+{
+do_address_service(true, AF_INET, tt);
+do_dns_service(true, AF_INET, tt);
+}
+else if (tt->options.ip_win32_type == IPW32_SET_NETSH)
+{
+netsh_ifconfig(&tt->options, ifname, tt->local,
+   tt->adapter_netmask, NI_IP_NETMASK|NI_OPTIONS);
 }
-
 #else  /* if defined(TARGET_LINUX) */
 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.");
 #endif /* if defined(TARGET_LINUX) */
@@ -6357,36 +6352,39 @@ tuntap_post_open(struct tuntap *tt, const char 
*device_guid)
 bool dhcp_masq = false;
 bool dhcp_masq_post = false;
 
-/* get driver version info */
-tuntap_get_version_info(tt);
+if (tt->windows_driver == WINDOWS_DRIVER_TAP_WINDOWS6)
+{
+/* get driver version info */
+tuntap_get_version_info(tt);
 
-/* get driver MTU */
-tuntap_get_mtu(tt);
+/* get driver MTU */
+tuntap_get_mtu(tt);
 
-/*
- * Preliminaries for setting TAP-Windows adapter TCP/IP
- * properties via --ip-win32 dynamic or --ip-win32 adaptive.
- */
-if (tt->did_ifconfig_setup)
-{
-tuntap_set_ip_props(tt, &dhcp_masq, &dhcp_masq_post);
-}
+/*
+ * Preliminaries for setting TAP-Windows adapter TCP/IP
+ * properties via --ip-win32 dynamic or --ip-win32 adaptive.
+ */
+if (tt->did_ifconfig_setup)
+{
+tuntap_set_ip_props(tt, &dhcp_masq, &dhcp_masq_post);
+}
 
-/* set point-to-point mode if TUN device */
-if (tt->type == DEV_TYPE_TUN)
-{
-tuntap_set_ptp(tt);
-}
+/* set point-to-point mode if TUN device */
+if (tt->type == DEV_TYPE_TUN)
+{
+tuntap_set_ptp(tt);
+}
 
-/* should we tell the TAP-Windows driver to masquerade as a DHCP server as 
a means
- * of setting the adapter address? */
-if (dhcp_masq)
-{
-tuntap_dhcp_mask(tt, device_guid);
-}
+/* should we tell the TAP-Windows driver to masquerade as a DHCP 
server as a means
+ * of setting the adapter address? */
+if (dhcp_masq)
+{
+tuntap_dhcp_mask(tt, device_guid);
+}
 
-/* set driver media status to 'connected' */
-tuntap_set_co

[Openvpn-devel] [PATCH 1/2] tun.c: reorder IPv6 ifconfig on Windows

2020-03-10 Thread Simon Rozman
The IPv6 interface network route should be setup as soon as possible
after the interface address is set. Actually, all routes should be added
before DNS servers are configured. This would allow Windows to validate
DNS servers properly instead of shutting the validation off.

The cleanup order has been changed to match reverse order of ifconfig.
An additional check was added to skip the cleanup when --ip-win32 is set
to manual.

Signed-off-by: Simon Rozman 
---
 src/openvpn/tun.c | 51 +--
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 1f848d24..42193d97 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -1016,6 +1016,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, 
int tun_mtu,
 else if (tt->options.msg_channel)
 {
 do_address_service(true, AF_INET6, tt);
+add_route_connected_v6_net(tt, es);
 do_dns_service(true, AF_INET6, tt);
 }
 else
@@ -1031,15 +1032,10 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, 
int tun_mtu,
 get_win_sys_path(), NETSH_PATH_SUFFIX, iface,
 ifconfig_ipv6_local);
 netsh_command(&argv, 4, M_FATAL);
+add_route_connected_v6_net(tt, es);
 /* set ipv6 dns servers if any are specified */
 netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname);
 }
-
-/* explicit route needed */
-if (tt->options.ip_win32_type != IPW32_SET_MANUAL)
-{
-add_route_connected_v6_net(tt, es);
-}
 #else /* platforms we have no IPv6 code for */
 msg(M_FATAL, "Sorry, but I don't know how to do IPv6 'ifconfig' commands 
on this operating system.  You should ifconfig your TUN/TAP device manually or 
use an --up script.");
 #endif /* outer "if defined(TARGET_xxx)" conditional */
@@ -6467,6 +6463,24 @@ netsh_delete_address_dns(const struct tuntap *tt, bool 
ipv6, struct gc_arena *gc
 const char *ifconfig_ip_local;
 struct argv argv = argv_new();
 
+/* delete ipvX dns servers if any were set */
+int len = ipv6 ? tt->options.dns6_len : tt->options.dns_len;
+if (len > 0)
+{
+argv_printf(&argv,
+"%s%s interface %s delete dns %s all",
+get_win_sys_path(),
+NETSH_PATH_SUFFIX,
+ipv6 ? "ipv6" : "ipv4",
+tt->actual_name);
+netsh_command(&argv, 1, M_WARN);
+}
+
+if (ipv6)
+{
+delete_route_connected_v6_net(tt, NULL);
+}
+
 /* "store=active" is needed in Windows 8(.1) to delete the
  * address we added (pointed out by Cedric Tabary).
  */
@@ -6487,21 +6501,8 @@ netsh_delete_address_dns(const struct tuntap *tt, bool 
ipv6, struct gc_arena *gc
 ipv6 ? "ipv6" : "ipv4",
 tt->actual_name,
 ifconfig_ip_local);
-
 netsh_command(&argv, 1, M_WARN);
 
-/* delete ipvX dns servers if any were set */
-int len = ipv6 ? tt->options.dns6_len : tt->options.dns_len;
-if (len > 0)
-{
-argv_printf(&argv,
-"%s%s interface %s delete dns %s all",
-get_win_sys_path(),
-NETSH_PATH_SUFFIX,
-ipv6 ? "ipv6" : "ipv4",
-tt->actual_name);
-netsh_command(&argv, 1, M_WARN);
-}
 argv_free(&argv);
 }
 
@@ -6514,16 +6515,18 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
 
 if (tt->did_ifconfig_ipv6_setup)
 {
-/* remove route pointing to interface */
-delete_route_connected_v6_net(tt, NULL);
-
-if (tt->options.msg_channel)
+if (tt->options.ip_win32_type == IPW32_SET_MANUAL)
+{
+/* We didn't do ifconfig. */
+}
+else if (tt->options.msg_channel)
 {
-do_address_service(false, AF_INET6, tt);
 if (tt->options.dns6_len > 0)
 {
 do_dns_service(false, AF_INET6, tt);
 }
+delete_route_connected_v6_net(tt, NULL);
+do_address_service(false, AF_INET6, tt);
 }
 else
 {
-- 
2.24.1.windows.2



___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH v2 12/12] tapctl: Support multiple hardware IDs

2020-03-10 Thread Simon Rozman
TAP-Windows6 adapters created with tapinstall/devcon.exe have hardware
ID "tap0901", where TAP-Windows6 adapters created with tapctl.exe have
hardware ID "root\\tap0901".

The enumeration of the network adapters have been extended to detect
adapters using a list of acceptable hardware IDs.

Signed-off-by: Simon Rozman 
---
 src/openvpnmsica/openvpnmsica.c | 43 ++---
 src/tapctl/main.c   | 24 +++---
 src/tapctl/tap.c| 21 
 src/tapctl/tap.h|  8 +++---
 4 files changed, 58 insertions(+), 38 deletions(-)

diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c
index 28cf16b5..31e90bd2 100644
--- a/src/openvpnmsica/openvpnmsica.c
+++ b/src/openvpnmsica/openvpnmsica.c
@@ -251,7 +251,7 @@ cleanup_OpenSCManager:
 static UINT
 find_adapters(
 _In_ MSIHANDLE hInstall,
-_In_z_ LPCTSTR szHardwareId,
+_In_z_ LPCTSTR szzHardwareIDs,
 _In_z_ LPCTSTR szAdaptersPropertyName,
 _In_z_ LPCTSTR szActiveAdaptersPropertyName)
 {
@@ -259,7 +259,7 @@ find_adapters(
 
 /* Get network adapters with given hardware ID. */
 struct tap_adapter_node *pAdapterList = NULL;
-uiResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList);
+uiResult = tap_list_adapters(NULL, szzHardwareIDs, &pAdapterList);
 if (uiResult != ERROR_SUCCESS)
 {
 return uiResult;
@@ -414,12 +414,12 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
 set_openvpnserv_state(hInstall);
 find_adapters(
 hInstall,
-TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID),
+TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0") 
TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0"),
 TEXT("TAPWINDOWS6ADAPTERS"),
 TEXT("ACTIVETAPWINDOWS6ADAPTERS"));
 find_adapters(
 hInstall,
-TEXT("Wintun"),
+TEXT("Wintun") TEXT("\0"),
 TEXT("WINTUNADAPTERS"),
 TEXT("ACTIVEWINTUNADAPTERS"));
 
@@ -652,7 +652,7 @@ cleanup_pAdapterList:
  *
  * @param szDisplayName  Adapter display name
  *
- * @param szHardwareId  Adapter hardware ID
+ * @param szzHardwareIDs  String of strings with acceptable adapter hardware 
IDs
  *
  * @param iTicksPointer to an integer that represents amount of work 
(on progress
  *  indicator) the UninstallTUNTAPAdapters will take. This 
function increments
@@ -666,12 +666,12 @@ schedule_adapter_delete(
 _Inout_opt_ struct msica_arg_seq *seqCommit,
 _Inout_opt_ struct msica_arg_seq *seqRollback,
 _In_z_ LPCTSTR szDisplayName,
-_In_z_ LPCTSTR szHardwareId,
+_In_z_ LPCTSTR szzHardwareIDs,
 _Inout_ int *iTicks)
 {
 /* Get adapters with given hardware ID. */
 struct tap_adapter_node *pAdapterList = NULL;
-DWORD dwResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList);
+DWORD dwResult = tap_list_adapters(NULL, szzHardwareIDs, &pAdapterList);
 if (dwResult != ERROR_SUCCESS)
 {
 return dwResult;
@@ -858,11 +858,16 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 szDisplayNameEx = szDisplayNameEx != NULL ? szDisplayNameEx + 1 : 
szDisplayName;
 
 /* Get adapter hardware ID (`HardwareId` is field #5). */
-LPTSTR szHardwareId = NULL;
-uiResult = msi_get_record_string(hRecord, 5, &szHardwareId);
-if (uiResult != ERROR_SUCCESS)
+TCHAR szzHardwareIDs[0x100] = { 0 };
 {
-goto cleanup_szDisplayName;
+LPTSTR szHwId = NULL;
+uiResult = msi_get_record_string(hRecord, 5, &szHwId);
+if (uiResult != ERROR_SUCCESS)
+{
+goto cleanup_szDisplayName;
+}
+memcpy_s(szzHardwareIDs, sizeof(szzHardwareIDs) - 2*sizeof(TCHAR) 
/*requires double zero termination*/, szHwId, _tcslen(szHwId)*sizeof(TCHAR));
+free(szHwId);
 }
 
 if (iAction > INSTALLSTATE_BROKEN)
@@ -876,7 +881,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 uiResult = msi_get_record_string(hRecord, 3, &szValue);
 if (uiResult != ERROR_SUCCESS)
 {
-goto cleanup_szHardwareId;
+goto cleanup_szDisplayName;
 }
 #ifdef __GNUC__
 /*
@@ -890,13 +895,13 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 {
 case MSICONDITION_FALSE:
 free(szValue);
-goto cleanup_szHardwareId;
+goto cleanup_szDisplayName;
 
 case MSICONDITION_ERROR:
 uiResult = ERROR_INVALID_FIELD;
 msg(M_NONFATAL | M_ERRNO, "%s: 
MsiEvaluateCondition(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szValue);
 free(szValue);
-goto cleanup_szHardwareId;
+goto cleanup_szDisplayName;
 }
 #ifdef __GNUC__
 #pragma GCC diagnost