Detecting Windows version
PATCH 1/1 Detecting Windows version
* Use adapter name instead of index on WinXP - sadly XP does not support indexes
* Write Windows version to log
* Send it with peer-info as IV_PLAT_VER
--- config-msvc.h | 1 + configure.ac | 1 + src/compat/compat-versionhelpers.h | 81 ++++++++++++++++++++++++++++++++++++++ src/openvpn/openvpn.c | 3 ++ src/openvpn/options.c | 12 ++++++ src/openvpn/options.h | 4 ++ src/openvpn/route.c | 19 ++++++--- src/openvpn/ssl.c | 2 + src/openvpn/tun.c | 2 +- src/openvpn/win32.c | 63 +++++++++++++++++++++++++++++ src/openvpn/win32.h | 13 ++++++ 11 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 src/compat/compat-versionhelpers.h
config-msvc.h +1 -0
@@ -45,6 +45,7 @@#define HAVE_SYS_STAT_H 1#define HAVE_LZO_LZO1X_H 1#define HAVE_LZO_LZOUTIL_H 1 +#define HAVE_VERSIONHELPERS_H 1#define HAVE_ACCESS 1#define HAVE_CHDIR 1
configure.ac +1 -0
@@ -423,6 +423,7 @@ AC_CHECK_HEADERS([ \ netinet/in.h netinet/in_systm.h \ netinet/tcp.h arpa/inet.h netdb.h \ windows.h winsock2.h ws2tcpip.h \ + versionhelpers.h \ ]) AC_CHECK_HEADERS([ \ sys/time.h sys/ioctl.h sys/stat.h \
src/compat/compat-versionhelpers.h new file +81 -0
81 lines not on this page · raw message
src/openvpn/openvpn.c +3 -0
@@ -220,6 +220,9 @@ openvpn_main (int argc, char *argv[])/* print version number */ msg (M_INFO ,"%s" , title_string); +#ifdef WIN32 +show_windows_version (M_INFO ); +#endif show_library_versions (M_INFO );/* misc stuff */
src/openvpn/options.c +12 -0
@@ -3489,6 +3489,15 @@ usage_small (void)openvpn_exit (OPENVPN_EXIT_STATUS_USAGE );/* exit point */ } +#ifdef WIN32 +void show_windows_version (const unsigned int flags) +{ +struct gc_arena gc =gc_new (); +msg (flags,"Windows version %s" ,win32_version_string (&gc, true)); +gc_free (&gc); +} +#endif +void show_library_versions (const unsigned int flags) {
@@ -3514,6 +3523,9 @@ usage_version (void) {msg (M_INFO |M_NOPREFIX ,"%s" , title_string);show_library_versions (M_INFO |M_NOPREFIX ); +#ifdef WIN32 +show_windows_version (M_INFO |M_NOPREFIX ); +#endif msg (M_INFO |M_NOPREFIX ,"Originally developed by James Yonan" );msg (M_INFO |M_NOPREFIX ,"Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <[email protected]...>" );#ifndef ENABLE_SMALL
src/openvpn/options.h +4 -0
@@ -690,6 +690,10 @@ void usage_small (void);void show_library_versions (const unsigned int flags); +#ifdef WIN32 +void show_windows_version (const unsigned int flags); +#endif +void init_options (struct options *o,const bool init_gc);void uninit_options (struct options *o);
src/openvpn/route.c +13 -6
@@ -42,6 +42,7 @@#include "manage.h" #include "win32.h" #include "options.h" +#include "win32.h" #include "memdbg.h"
@@ -1623,9 +1624,12 @@ add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int fla#elif defined (WIN32 ) -struct buffer out =alloc_buf_gc (64 , &gc); -buf_printf (&out,"interface=%d" , tt->adapter_index ); - device =buf_bptr (&out); +if (win32_version_info () !=WIN_XP ) + { +struct buffer out =alloc_buf_gc (64 , &gc); +buf_printf (&out,"interface=%d" , tt->adapter_index ); + device =buf_bptr (&out); + }/* netsh interface ipv6 add route 2001:db8::/32 MyTunDevice */ argv_printf (&argv, "%s%sc interface ipv6 add route %s/%d %s",
@@ -1958,9 +1962,12 @@ delete_route_ipv6 (const struct route_ipv6 *r6, const struct tuntap *tt, unsigne#elif defined (WIN32 ) -struct buffer out =alloc_buf_gc (64 , &gc); -buf_printf (&out,"interface=%d" , tt->adapter_index ); - device =buf_bptr (&out); +if (win32_version_info () !=WIN_XP ) + { +struct buffer out =alloc_buf_gc (64 , &gc); +buf_printf (&out,"interface=%d" , tt->adapter_index ); + device =buf_bptr (&out); + }/* netsh interface ipv6 delete route 2001:db8::/32 MyTunDevice */ argv_printf (&argv, "%s%sc interface ipv6 delete route %s/%d %s",
src/openvpn/ssl.c +2 -0
@@ -43,6 +43,7 @@#endif #include "syshead.h" +#include "win32.h" #if defined(ENABLE_CRYPTO ) && defined(ENABLE_SSL )
@@ -1831,6 +1832,7 @@ push_peer_info(struct buffer *buf, struct tls_session *session)buf_printf (&out,"IV_PLAT=freebsd\n" );#elif defined(WIN32 )buf_printf (&out,"IV_PLAT=win\n" ); +buf_printf (&out,"IV_PLAT_VER=%s\n" ,win32_version_string (&gc, false));#endif /* push LZO status */
src/openvpn/tun.c +1 -1
@@ -1244,7 +1244,7 @@ do_ifconfig (struct tuntap *tt,"%s%sc interface ipv6 set address %s %s store=active" ,get_win_sys_path (),NETSH_PATH_SUFFIX , - iface, +win32_version_info () ==WIN_XP ? actual : iface, ifconfig_ipv6_local);netsh_command (&argv,4 );
src/openvpn/win32.c +63 -0
73 lines not on this page · raw message
src/openvpn/win32.h +13 -0
@@ -275,5 +275,18 @@ bool win_wfp_init_funcs();bool win_wfp_block_dns (const NET_IFINDEX index);bool win_wfp_uninit (); +#define WIN_XP 0 +#define WIN_VISTA 1 +#define WIN_7 2 +#define WIN_8 3 + +int win32_version_info (); + +/* +String representation of Windows version number and name, see +https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx +*/ +const char *win32_version_string (struct gc_arena *gc,bool add_name); +#endif #endif
Signature · 1 line
1.9.1
Hi,
Quoted 3 lines · Lev Stipakov
* Use adapter name instead of index on WinXP - sadly XP does not support indexes
* Write Windows version to log
* Send it with peer-info asIV_PLAT_VER
Overall, I'm fine with the patch - thanks a lot.
I've built release/2.3 + patch on ubuntu 14.04 and tested on XP SP3, and it nicely worked - sending IV_PLAT_VER=5.1 ("WIN_XP"), and using interface name again.
A few small details (half of them already discussed on IRC):
- please send IV_PLAT_VER only if the client requested this (push-peer-info) (this is slightly more sensitive information, comparable to library versions, and when introducing library versions in IV_SSL, we decided to not send such information by default)
- and please send a patch of the windows version bits for master ("all but the changes against route.c and tun.c" :) )
- src/compat/compat-versionhelpers.h needs to be listed "somewhere" (src/compat/Makefile.am libcompat_la_SOURCES=... maybe?) so that "make dist" will include it into the generated .tar.gz
src/openvpn/route.c add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int fla · line 1632
Quoted 11 lines
#elif defined (WIN32)
src/openvpn/route.c +6
-3-struct buffer out =alloc_buf_gc (64 , &gc); -buf_printf (&out,"interface=%d" , tt->adapter_index ); - device =buf_bptr (&out); +if (win32_version_info () !=WIN_XP ) + { +struct buffer out =alloc_buf_gc (64 , &gc); +buf_printf (&out,"interface=%d" , tt->adapter_index ); + device =buf_bptr (&out); + }
the indentation on these is off - they are indented with a full <tab> but our funny 2.3 convention requires *six* spaces here... (sorry for being a pain... trying to be consistent)
Same thing for delete_route_ipv6().
Functionally, this all looks perfectly fine (I only tested on XP, but as the rest is just existing code, it will "obviously" work for the non-XP case).
[..]
src/openvpn/win32.c win_wfp_uninit() · line 1309
Quoted 12 lines
src/openvpn/win32.c +12
-0+int +win32_version_info () +{ +if (!IsWindowsXPOrGreater ()) + { +msg (M_FATAL ,"Error: Windows version must be XP or greater." ); + } + +if (!IsWindowsVistaOrGreater ()) + { +return WIN_XP ; + }
I'm not sure if this is the canonical best version to deal with it or not, but I don't particularily *want* to get myself involved into this.
If someone else thinks this needs improvement (like, working Win10 detection :-) ) I'm all open to accept additional patches on top of it, but to solve our immediate needs, this is good enough for me and does not *need* changes.
thanks, and waiting for v2 :-)
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]...PATCH v2 1/1 Repair IPv6 netsh calls if Win XP is detected
v2:
* Add compat-versionhelpers.h to compat/Makefile.am so that "make dist" will include it into tarball.
* Indentation
v1:
* Use adapter name instead of index on WinXP - sadly XP does not support indexes
* Write Windows version to log
* Send it with peer-info as IV_PLAT_VER
--- config-msvc.h | 1 + configure.ac | 1 + src/compat/Makefile.am | 3 +- src/compat/compat-versionhelpers.h | 81 ++++++++++++++++++++++++++++++++++++++ src/openvpn/openvpn.c | 3 ++ src/openvpn/options.c | 12 ++++++ src/openvpn/options.h | 4 ++ src/openvpn/route.c | 19 ++++++--- src/openvpn/ssl.c | 3 ++ src/openvpn/tun.c | 2 +- src/openvpn/win32.c | 63 +++++++++++++++++++++++++++++ src/openvpn/win32.h | 13 ++++++ 12 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 src/compat/compat-versionhelpers.h
config-msvc.h +1 -0
@@ -45,6 +45,7 @@#define HAVE_SYS_STAT_H 1#define HAVE_LZO_LZO1X_H 1#define HAVE_LZO_LZOUTIL_H 1 +#define HAVE_VERSIONHELPERS_H 1#define HAVE_ACCESS 1#define HAVE_CHDIR 1
configure.ac +1 -0
@@ -423,6 +423,7 @@ AC_CHECK_HEADERS([ \ netinet/in.h netinet/in_systm.h \ netinet/tcp.h arpa/inet.h netdb.h \ windows.h winsock2.h ws2tcpip.h \ + versionhelpers.h \ ]) AC_CHECK_HEADERS([ \ sys/time.h sys/ioctl.h sys/stat.h \
src/compat/Makefile.am +2 -1
@@ -26,4 +26,5 @@ libcompat_la_SOURCES = \ compat-gettimeofday.c \ compat-daemon.c \ compat-inet_ntop.c \ - compat-inet_pton.c + compat-inet_pton.c \ + compat-versionhelpers.h
src/compat/compat-versionhelpers.h new file +81 -0
81 lines not on this page · raw message
src/openvpn/openvpn.c +3 -0
@@ -220,6 +220,9 @@ openvpn_main (int argc, char *argv[])/* print version number */ msg (M_INFO ,"%s" , title_string); +#ifdef WIN32 +show_windows_version (M_INFO ); +#endif show_library_versions (M_INFO );/* misc stuff */
src/openvpn/options.c +12 -0
@@ -3489,6 +3489,15 @@ usage_small (void)openvpn_exit (OPENVPN_EXIT_STATUS_USAGE );/* exit point */ } +#ifdef WIN32 +void show_windows_version (const unsigned int flags) +{ +struct gc_arena gc =gc_new (); +msg (flags,"Windows version %s" ,win32_version_string (&gc, true)); +gc_free (&gc); +} +#endif +void show_library_versions (const unsigned int flags) {
@@ -3514,6 +3523,9 @@ usage_version (void) {msg (M_INFO |M_NOPREFIX ,"%s" , title_string);show_library_versions (M_INFO |M_NOPREFIX ); +#ifdef WIN32 +show_windows_version (M_INFO |M_NOPREFIX ); +#endif msg (M_INFO |M_NOPREFIX ,"Originally developed by James Yonan" );msg (M_INFO |M_NOPREFIX ,"Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <[email protected]...>" );#ifndef ENABLE_SMALL
src/openvpn/options.h +4 -0
@@ -690,6 +690,10 @@ void usage_small (void);void show_library_versions (const unsigned int flags); +#ifdef WIN32 +void show_windows_version (const unsigned int flags); +#endif +void init_options (struct options *o,const bool init_gc);void uninit_options (struct options *o);
src/openvpn/route.c +13 -6
@@ -42,6 +42,7 @@#include "manage.h" #include "win32.h" #include "options.h" +#include "win32.h" #include "memdbg.h"
@@ -1623,9 +1624,12 @@ add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int fla#elif defined (WIN32 ) -struct buffer out =alloc_buf_gc (64 , &gc); -buf_printf (&out,"interface=%d" , tt->adapter_index ); - device =buf_bptr (&out); +if (win32_version_info () !=WIN_XP ) + { +struct buffer out =alloc_buf_gc (64 , &gc); +buf_printf (&out,"interface=%d" , tt->adapter_index ); + device =buf_bptr (&out); + }/* netsh interface ipv6 add route 2001:db8::/32 MyTunDevice */ argv_printf (&argv, "%s%sc interface ipv6 add route %s/%d %s",
@@ -1958,9 +1962,12 @@ delete_route_ipv6 (const struct route_ipv6 *r6, const struct tuntap *tt, unsigne#elif defined (WIN32 ) -struct buffer out =alloc_buf_gc (64 , &gc); -buf_printf (&out,"interface=%d" , tt->adapter_index ); - device =buf_bptr (&out); +if (win32_version_info () !=WIN_XP ) + { +struct buffer out =alloc_buf_gc (64 , &gc); +buf_printf (&out,"interface=%d" , tt->adapter_index ); + device =buf_bptr (&out); + }/* netsh interface ipv6 delete route 2001:db8::/32 MyTunDevice */ argv_printf (&argv, "%s%sc interface ipv6 delete route %s/%d %s",
src/openvpn/ssl.c +3 -0
@@ -43,6 +43,7 @@#endif #include "syshead.h" +#include "win32.h" #if defined(ENABLE_CRYPTO ) && defined(ENABLE_SSL )
@@ -1848,6 +1849,8 @@ push_peer_info(struct buffer *buf, struct tls_session *session)if (rgi.flags &RGI_HWADDR_DEFINED )buf_printf (&out,"IV_HWADDR=%s\n" ,format_hex_ex (rgi.hwaddr,6 ,0 ,1 ,":" , &gc));buf_printf (&out,"IV_SSL=%s\n" ,get_ssl_library_version () ); + +buf_printf (&out,"IV_PLAT_VER=%s\n" ,win32_version_string (&gc, false)); }/* push env vars that begin with UV_ and IV_GUI_VER */
src/openvpn/tun.c +1 -1
@@ -1244,7 +1244,7 @@ do_ifconfig (struct tuntap *tt,"%s%sc interface ipv6 set address %s %s store=active" ,get_win_sys_path (),NETSH_PATH_SUFFIX , - iface, +win32_version_info () ==WIN_XP ? actual : iface, ifconfig_ipv6_local);netsh_command (&argv,4 );
src/openvpn/win32.c +63 -0
73 lines not on this page · raw message
src/openvpn/win32.h +13 -0
@@ -275,5 +275,18 @@ bool win_wfp_init_funcs();bool win_wfp_block_dns (const NET_IFINDEX index);bool win_wfp_uninit (); +#define WIN_XP 0 +#define WIN_VISTA 1 +#define WIN_7 2 +#define WIN_8 3 + +int win32_version_info (); + +/* +String representation of Windows version number and name, see +https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx +*/ +const char *win32_version_string (struct gc_arena *gc,bool add_name); +#endif #endif
Signature · 1 line
1.9.1
[Openvpn-devel] [PATCH applied] Re: Repair IPv6 netsh calls if Win XP is detected
ACK. Thanks.
Your patch has been applied to the release/2.3 branch.
(I've added a note to Changes.rst about the change and the new feature)
commit de627cd7d450a0c32de252c098b1ca16912d595e (release/2.3)
Author: Lev Stipakov Date: Tue Dec 29 22:56:01 2015 +0200
Repair IPv6 netsh calls if Win XP is detected
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10903
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied (WITH FIX)] Re: Repair IPv6 netsh calls if Win XP is detected
In reply to Lev StipakovUPDATE...
ACK. Thanks.
Your patch has been applied to the release/2.3 branch.
(I've added a note to Changes.rst about the change and the new feature - *and* I've added #ifdef WIN32 around the IV_PLAT_VER= bit, as the v2 code moved that to a "global" part of the code, and fails compilation on non-windows...)
commit 84eb66bf78b072a713d50151ba6f75e623f9aaf8 (release/2.3)
Author: Lev Stipakov Date: Tue Dec 29 22:56:01 2015 +0200
Repair IPv6 netsh calls if Win XP is detected
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10903
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 1/1 Detecting and logging Windows versions
In reply to Gert DoeringAlso send it with peer-info as IV_PLAT_VER.
--- config-msvc.h | 1 + configure.ac | 1 + src/compat/Makefile.am | 3 +- src/compat/compat-versionhelpers.h | 81 ++++++++++++++++++++++++++++++++++++++ src/openvpn/openvpn.c | 3 ++ src/openvpn/options.c | 12 ++++++ src/openvpn/options.h | 4 ++ src/openvpn/ssl.c | 3 ++ src/openvpn/win32.c | 63 +++++++++++++++++++++++++++++ src/openvpn/win32.h | 13 ++++++ 10 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 src/compat/compat-versionhelpers.h
config-msvc.h +1 -0
@@ -44,6 +44,7 @@#define HAVE_SYS_STAT_H 1#define HAVE_LZO_LZO1X_H 1#define HAVE_LZO_LZOUTIL_H 1 +#define HAVE_VERSIONHELPERS_H 1#define HAVE_ACCESS 1#define HAVE_CHDIR 1
configure.ac +1 -0
@@ -434,6 +434,7 @@ AC_CHECK_HEADERS([ \ netinet/in.h netinet/in_systm.h \ netinet/tcp.h arpa/inet.h netdb.h \ windows.h winsock2.h ws2tcpip.h \ + versionhelpers.h \ ]) AC_CHECK_HEADERS([ \ sys/time.h sys/ioctl.h sys/stat.h \
src/compat/Makefile.am +2 -1
@@ -27,4 +27,5 @@ libcompat_la_SOURCES = \ compat-daemon.c \ compat-inet_ntop.c \ compat-inet_pton.c \ - compat-lz4.c compat-lz4.h + compat-lz4.c compat-lz4.h \ + compat-versionhelpers.h
src/compat/compat-versionhelpers.h new file +81 -0
81 lines not on this page · raw message
src/openvpn/openvpn.c +3 -0
@@ -220,6 +220,9 @@ openvpn_main (int argc, char *argv[])/* print version number */ msg (M_INFO ,"%s" , title_string); +#ifdef WIN32 +show_windows_version (M_INFO ); +#endif show_library_versions (M_INFO );/* misc stuff */
src/openvpn/options.c +12 -0
@@ -3438,6 +3438,15 @@ usage_small (void)openvpn_exit (OPENVPN_EXIT_STATUS_USAGE );/* exit point */ } +#ifdef WIN32 +void show_windows_version (const unsigned int flags) +{ +struct gc_arena gc =gc_new (); +msg (flags,"Windows version %s" ,win32_version_string (&gc, true)); +gc_free (&gc); +} +#endif +void show_library_versions (const unsigned int flags) {
@@ -3463,6 +3472,9 @@ usage_version (void) {msg (M_INFO |M_NOPREFIX ,"%s" , title_string);show_library_versions (M_INFO |M_NOPREFIX ); +#ifdef WIN32 +show_windows_version (M_INFO |M_NOPREFIX ); +#endif msg (M_INFO |M_NOPREFIX ,"Originally developed by James Yonan" );msg (M_INFO |M_NOPREFIX ,"Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <[email protected]...>" );#ifndef ENABLE_SMALL
src/openvpn/options.h +4 -0
@@ -688,6 +688,10 @@ void usage_small (void);void show_library_versions (const unsigned int flags); +#ifdef WIN32 +void show_windows_version (const unsigned int flags); +#endif +void init_options (struct options *o,const bool init_gc);void uninit_options (struct options *o);
src/openvpn/ssl.c +3 -0
@@ -42,6 +42,7 @@#endif #include "syshead.h" +#include "win32.h" #if defined(ENABLE_CRYPTO )
@@ -1868,6 +1869,8 @@ push_peer_info(struct buffer *buf, struct tls_session *session)if (rgi.flags &RGI_HWADDR_DEFINED )buf_printf (&out,"IV_HWADDR=%s\n" ,format_hex_ex (rgi.hwaddr,6 ,0 ,1 ,":" , &gc));buf_printf (&out,"IV_SSL=%s\n" ,get_ssl_library_version () ); + +buf_printf (&out,"IV_PLAT_VER=%s\n" ,win32_version_string (&gc, false)); }/* push env vars that begin with UV_ and IV_GUI_VER */
src/openvpn/win32.c +63 -0
73 lines not on this page · raw message
src/openvpn/win32.h +13 -0
@@ -274,5 +274,18 @@ WCHAR *wide_string (const char* utf8, struct gc_arena *gc);bool win_wfp_block_dns (const NET_IFINDEX index);bool win_wfp_uninit (); +#define WIN_XP 0 +#define WIN_VISTA 1 +#define WIN_7 2 +#define WIN_8 3 + +int win32_version_info (); + +/* +String representation of Windows version number and name, see +https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx +*/ +const char *win32_version_string (struct gc_arena *gc,bool add_name); +#endif #endif
Signature · 1 line
1.9.1
[Openvpn-devel] [PATCH applied] Re: Detecting and logging Windows versions
ACK. Thanks.
Your patch has been applied to the master branch.
Changes as for release/2.3 patch - added text to Changes.rst and #if defined(WIN32) to ssl.c change (IV_PLAT_VER)
commit cdc65ea0f1f94974f55352d794627561c78c4151 (master)
Author: Lev Stipakov Date: Tue Dec 29 23:02:37 2015 +0200
Detecting and logging Windows versions
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10904
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering