ovpn-dco: leftovers
v100 cover ovpn-dco: leftovers
This patchset is essentially a resending of the patches that were already on the mailing list, but were not appled yet.
Some of them required extra work, while some required reordering.
To make things simpler, I am resending them as a patchset, with some extra bonus patches too.
I am going with v100 to kinda restart from zero, without mixing up existing versions of these patches.
Enjoy!
Antonio Quartulli (10):
do_open_tun: restyle "can preserve TUN" check
dco-win: introduce low-level code for handling ovpn-dco-win in Windows
dco-win: add platform dependant check on incompatible options
dco-win: implement ovpn-dco support in P2P Windows code path
dco-win: add documentation to README.dco.md
dco-win: update GH Actions config file
dco-win: ensure the DCO API is not used when running on Windows
ovpn-dco: print some netlink messages to debug level
dco: properly name variables
dco: move message to DCO debug level and reword a bit
.github/workflows/build.yaml | 7 +- README.dco.md | 11 +- config-msvc.h | 2 + configure.ac | 9 +- dev-tools/special-files.lst | 1 + src/openvpn/Makefile.am | 4 +- src/openvpn/dco.c | 34 ++- src/openvpn/dco_internal.h | 1 + src/openvpn/dco_linux.c | 5 +- src/openvpn/dco_win.c | 397 ++++++++++++++++++++++++++++ src/openvpn/dco_win.h | 57 ++++ src/openvpn/forward.c | 31 ++- src/openvpn/init.c | 307 +++++++++++---------- src/openvpn/openvpn.vcxproj | 3 + src/openvpn/openvpn.vcxproj.filters | 9 + src/openvpn/options.c | 28 +- src/openvpn/options.h | 15 +- src/openvpn/ovpn-dco-win.h | 108 ++++++++ src/openvpn/socket.c | 93 ++++++- src/openvpn/socket.h | 25 +- src/openvpn/tun.c | 56 +++- src/openvpn/tun.h | 77 ++++-- 22 files changed, 1059 insertions(+), 221 deletions(-) create mode 100644 src/openvpn/dco_win.c create mode 100644 src/openvpn/dco_win.h create mode 100644 src/openvpn/ovpn-dco-win.h
Signature · 1 line
2.35.1
PATCH v100 1/10 do_open_tun: restyle "can preserve TUN" check
The current condition checking if the TUN interface was preserved is dependant on the platform being Android or not. This makes the code reasonably ugly, especially because uncrustify can't indent properly.
On top of that, we will require an extra condition only for windows+DCO, which will make the check even uglier.
For this reason, factor out the check in a separate function which can keep the ifdefs craziness well hidden, while do_open_tun becomes (a bit) cleaner.
--- src/openvpn/init.c | 282 +++++++++++++++++++++++---------------------- 1 file changed, 144 insertions(+), 138 deletions(-)
src/openvpn/init.c +144 -138
@@ -1716,161 +1716,120 @@ do_init_tun(struct context *c)* Open tun/tap device, ifconfig, call up script, etc. */ + +static bool +can_preserve_tun (struct tuntap *tt) +{ +#ifdef TARGET_ANDROID +return false; +#else +return tt; +#endif +} +static bool do_open_tun (struct context *c) {struct gc_arena gc =gc_new ();bool ret = false; -#ifndef TARGET_ANDROID - if (!c->c1.tuntap) +if (!can_preserve_tun (c->c1.tuntap)) { -#endif -#ifdef TARGET_ANDROID - /* If we emulate persist-tun on android we still have to open a new tun and - * then close the old */ - int oldtunfd = -1; - if (c->c1.tuntap) - { - oldtunfd = c->c1.tuntap->fd; - free(c->c1.tuntap); - c->c1.tuntap = NULL; - c->c1.tuntap_owned = false; - } +/* If we emulate persist-tun on android we still have to open a new tun and +* then close the old */ +int oldtunfd =-1 ; +if (c->c1.tuntap) + { + oldtunfd = c->c1.tuntap->fd; +free (c->c1.tuntap); + c->c1.tuntap =NULL ; + c->c1.tuntap_owned = false; + }#endif - /* initialize (but do not open) tun/tap object */ - do_init_tun(c); +/* initialize (but do not open) tun/tap object */ +do_init_tun (c); - /* inherit the dco context from the tuntap object */ - if (c->c2.tls_multi) - { - c->c2.tls_multi->dco = &c->c1.tuntap->dco; - } +/* inherit the dco context from the tuntap object */ +if (c->c2.tls_multi) + { + c->c2.tls_multi->dco = &c->c1.tuntap->dco; + }#ifdef _WIN32 - /* store (hide) interactive service handle in tuntap_options */ - c->c1.tuntap->options.msg_channel = c->options.msg_channel; - msg(D_ROUTE, "interactive service msg_channel=%" PRIu64, (unsigned long long) c->options.msg_channel); +/* store (hide) interactive service handle in tuntap_options */ + c->c1.tuntap->options.msg_channel = c->options.msg_channel; +msg (D_ROUTE ,"interactive service msg_channel=%" PRIu64, (unsigned long long ) c->options.msg_channel);#endif - /* allocate route list structure */ - do_alloc_route_list(c); +/* allocate route list structure */ +do_alloc_route_list (c); - /* parse and resolve the route option list */ - ASSERT(c->c2.link_socket); - if (c->options.routes && c->c1.route_list) - { - do_init_route_list(&c->options, c->c1.route_list, - &c->c2.link_socket->info, c->c2.es, &c->net_ctx); - } - if (c->options.routes_ipv6 && c->c1.route_ipv6_list) - { - do_init_route_ipv6_list(&c->options, c->c1.route_ipv6_list, - &c->c2.link_socket->info, c->c2.es, - &c->net_ctx); - } +/* parse and resolve the route option list */ +ASSERT (c->c2.link_socket); +if (c->options.routes && c->c1.route_list) + { +do_init_route_list (&c->options, c->c1.route_list, + &c->c2.link_socket->info, c->c2.es, &c->net_ctx); + } +if (c->options.routes_ipv6 && c->c1.route_ipv6_list) + { +do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, + &c->c2.link_socket->info, c->c2.es, + &c->net_ctx); + } - /* do ifconfig */ - if (!c->options.ifconfig_noexec - && ifconfig_order() == IFCONFIG_BEFORE_TUN_OPEN) - { - /* guess actual tun/tap unit number that will be returned - * by open_tun */ - const char *guess = guess_tuntap_dev(c->options.dev, - c->options.dev_type, - c->options.dev_node, - &gc); - do_ifconfig(c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); - } +/* do ifconfig */ +if (!c->options.ifconfig_noexec + &&ifconfig_order () ==IFCONFIG_BEFORE_TUN_OPEN ) + { +/* guess actual tun/tap unit number that will be returned +* by open_tun */ +const char *guess =guess_tuntap_dev (c->options.dev, + c->options.dev_type, + c->options.dev_node, + &gc); +do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, + &c->net_ctx); + } - /* possibly add routes */ - if (route_order() == ROUTE_BEFORE_TUN) - { - /* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ - do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); - } +/* possibly add routes */ +if (route_order () ==ROUTE_BEFORE_TUN ) + { +/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + }#ifdef TARGET_ANDROID - /* Store the old fd inside the fd so open_tun can use it */ - c->c1.tuntap->fd = oldtunfd; -#endif - if (dco_enabled(&c->options)) - { - ovpn_dco_init(c->mode, &c->c1.tuntap->dco); - } - - /* open the tun device */ - open_tun(c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap, &c->net_ctx); - - /* set the hardware address */ - if (c->options.lladdr) - { - set_lladdr(&c->net_ctx, c->c1.tuntap->actual_name, c->options.lladdr, - c->c2.es); - } - - /* do ifconfig */ - if (!c->options.ifconfig_noexec - && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) - { - do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); - } - - /* run the up script */ - run_up_down(c->options.up_script, - c->plugins, - OPENVPN_PLUGIN_UP, - c->c1.tuntap->actual_name, -#ifdef _WIN32 - c->c1.tuntap->adapter_index, +/* Store the old fd inside the fd so open_tun can use it */ + c->c1.tuntap->fd = oldtunfd;#endif - dev_type_string(c->options.dev, c->options.dev_type), - c->c2.frame.tun_mtu, - print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &gc), - "init", - NULL, - "up", - c->c2.es); - -#if defined(_WIN32) - if (c->options.block_outside_dns) - { - dmsg(D_LOW, "Blocking outside DNS"); - if (!win_wfp_block_dns(c->c1.tuntap->adapter_index, c->options.msg_channel)) +if (dco_enabled (&c->options)) { - msg(M_FATAL, "Blocking DNS failed!"); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco); } - } -#endif - /* possibly add routes */ - if ((route_order() == ROUTE_AFTER_TUN) && (!c->options.route_delay_defined)) - { - do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); - } +/* open the tun device */ +open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, + c->c1.tuntap, &c->net_ctx); - ret = true; - static_context = c; -#ifndef TARGET_ANDROID -} -else -{ - msg(M_INFO, "Preserving previous TUN/TAP instance: %s", - c->c1.tuntap->actual_name); +/* set the hardware address */ +if (c->options.lladdr) + { +set_lladdr (&c->net_ctx, c->c1.tuntap->actual_name, c->options.lladdr, + c->c2.es); + } - /* explicitly set the ifconfig_* env vars */ - do_ifconfig_setenv(c->c1.tuntap, c->c2.es); +/* do ifconfig */ +if (!c->options.ifconfig_noexec + &&ifconfig_order () ==IFCONFIG_AFTER_TUN_OPEN ) + { +do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + } - /* run the up script if user specified --up-restart */ - if (c->options.up_restart) - { +/* run the up script */ run_up_down(c->options.up_script, c->plugins, OPENVPN_PLUGIN_UP,
@@ -1882,24 +1841,71 @@ else c->c2.frame.tun_mtu,print_in_addr_t (c->c1.tuntap->local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF , &gc), -"restart" , +"init" ,NULL ,"up" , c->c2.es); - } +#if defined(_WIN32) -if (c->options.block_outside_dns) - { -dmsg (D_LOW ,"Blocking outside DNS" ); -if (!win_wfp_block_dns (c->c1.tuntap->adapter_index, c->options.msg_channel)) +if (c->options.block_outside_dns) + { +dmsg (D_LOW ,"Blocking outside DNS" ); +if (!win_wfp_block_dns (c->c1.tuntap->adapter_index, c->options.msg_channel)) + { +msg (M_FATAL ,"Blocking DNS failed!" ); + } + } +#endif + +/* possibly add routes */ +if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -msg (M_FATAL ,"Blocking DNS failed!" ); +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); } + + ret = true; + static_context = c; } +else + { +msg (M_INFO ,"Preserving previous TUN/TAP instance: %s" , + c->c1.tuntap->actual_name); + +/* explicitly set the ifconfig_* env vars */ +do_ifconfig_setenv (c->c1.tuntap, c->c2.es); + +/* run the up script if user specified --up-restart */ +if (c->options.up_restart) + { +run_up_down (c->options.up_script, + c->plugins, +OPENVPN_PLUGIN_UP , + c->c1.tuntap->actual_name, +#ifdef _WIN32 + c->c1.tuntap->adapter_index, +#endif +dev_type_string (c->options.dev, c->options.dev_type), + c->c2.frame.tun_mtu, +print_in_addr_t (c->c1.tuntap->local,IA_EMPTY_IF_UNDEF , &gc), +print_in_addr_t (c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF , &gc), +"restart" , +NULL , +"up" , + c->c2.es); + } +#if defined(_WIN32) +if (c->options.block_outside_dns) + { +dmsg (D_LOW ,"Blocking outside DNS" ); +if (!win_wfp_block_dns (c->c1.tuntap->adapter_index, c->options.msg_channel)) + { +msg (M_FATAL ,"Blocking DNS failed!" ); + } + }#endif -} -#endif /* ifndef TARGET_ANDROID */ + }gc_free (&gc);return ret; }
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH v100 01/10] do_open_tun: restyle "can preserve TUN" check
Stared at the code and slightly tested on Windows.
Functionality hasn't changed and code is now easier to read.
pe 12. elok. 2022 klo 16.08 Antonio Quartulli ([email protected]...) kirjoitti:
Quoted 386 lines
The current condition checking if the TUN interface was preserved is dependant on the platform being Android or not. This makes the code reasonably ugly, especially because uncrustify can't indent properly.
On top of that, we will require an extra condition only for windows+DCO, which will make the check even uglier.
For this reason, factor out the check in a separate function which can keep the ifdefs craziness well hidden, while
do_open_tunbecomes (a bit) cleaner.Signed-off-by Antonio Quartulli <[email protected]...>--- src/openvpn/init.c | 282 +++++++++++++++++++++++---------------------- 1 file changed, 144 insertions(+), 138 deletions(-)src/openvpn/init.c +12
-5@@ -1716,161 +1716,120 @@ do_init_tun(struct context *c)* Open tun/tap device, ifconfig, call up script, etc. */ + +static bool +can_preserve_tun (struct tuntap *tt) +{ +#ifdef TARGET_ANDROID +return false; +#else +return tt; +#endif +} +static bool do_open_tun (struct context *c) {struct gc_arena gc =gc_new ();bool ret = false; -#ifndef TARGET_ANDROID -if (!c->c1.tuntap) +if (!can_preserve_tun (c->c1.tuntap)) { -#endif -#ifdef TARGET_ANDROID -/* If we emulate persist-tun on android we still have to open a new tun and
src/openvpn/init.c +1
-9-* then close the old */ -int oldtunfd =-1 ; -if (c->c1.tuntap) - { - oldtunfd = c->c1.tuntap->fd; -free (c->c1.tuntap); - c->c1.tuntap =NULL ; - c->c1.tuntap_owned = false; - } +/* If we emulate persist-tun on android we still have to open a new tun and
src/openvpn/init.c +16
-10+* then close the old */ +int oldtunfd =-1 ; +if (c->c1.tuntap) + { + oldtunfd = c->c1.tuntap->fd; +free (c->c1.tuntap); + c->c1.tuntap =NULL ; + c->c1.tuntap_owned = false; + }#endif -/* initialize (but do not open) tun/tap object */ -do_init_tun (c); +/* initialize (but do not open) tun/tap object */ +do_init_tun (c); -/* inherit the dco context from the tuntap object */ -if (c->c2.tls_multi) - { - c->c2.tls_multi->dco = &c->c1.tuntap->dco; - } +/* inherit the dco context from the tuntap object */ +if (c->c2.tls_multi) + { + c->c2.tls_multi->dco = &c->c1.tuntap->dco; + }#ifdef _WIN32 -/* store (hide) interactive service handle in tuntap_options */ - c->c1.tuntap->options.msg_channel = c->options.msg_channel; - msg(D_ROUTE, "interactive service msg_channel=%" PRIu64, (unsignedlong long)
c->options.msg_channel);src/openvpn/init.c +3
-0+/* store (hide) interactive service handle in tuntap_options */ + c->c1.tuntap->options.msg_channel = c->options.msg_channel; + msg(D_ROUTE, "interactive service msg_channel=%" PRIu64,(unsigned long long)
c->options.msg_channel);
#endifsrc/openvpn/init.c +2
-8-/* allocate route list structure */ -do_alloc_route_list (c); +/* allocate route list structure */ +do_alloc_route_list (c); -/* parse and resolve the route option list */ -ASSERT (c->c2.link_socket); -if (c->options.routes && c->c1.route_list) - { - do_init_route_list(&c->options, c->c1.route_list, - &c->c2.link_socket->info, c->c2.es,
&c->net_ctx);src/openvpn/init.c +6
-7- } -if (c->options.routes_ipv6 && c->c1.route_ipv6_list) - { -do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, - &c->c2.link_socket->info, c->c2.es, - &c->net_ctx); - } +/* parse and resolve the route option list */ +ASSERT (c->c2.link_socket); +if (c->options.routes && c->c1.route_list) + { + do_init_route_list(&c->options, c->c1.route_list, + &c->c2.link_socket->info, c->c2.es,
&c->net_ctx);src/openvpn/init.c +18
-13+ } +if (c->options.routes_ipv6 && c->c1.route_ipv6_list) + { +do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, + &c->c2.link_socket->info, c->c2.es, + &c->net_ctx); + } -/* do ifconfig */ -if (!c->options.ifconfig_noexec - &&ifconfig_order () ==IFCONFIG_BEFORE_TUN_OPEN ) - { -/* guess actual tun/tap unit number that will be returned -* by open_tun */ -const char *guess =guess_tuntap_dev (c->options.dev, - c->options.dev_type, - c->options.dev_node, - &gc); -do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, - &c->net_ctx); - } +/* do ifconfig */ +if (!c->options.ifconfig_noexec + &&ifconfig_order () ==IFCONFIG_BEFORE_TUN_OPEN ) + { +/* guess actual tun/tap unit number that will be returned +* by open_tun */ +const char *guess =guess_tuntap_dev (c->options.dev, + c->options.dev_type, + c->options.dev_node, + &gc); + do_ifconfig(c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es,
src/openvpn/init.c +2
-4+ &c->net_ctx); + } -/* possibly add routes */ -if (route_order () ==ROUTE_BEFORE_TUN ) - { -/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */
src/openvpn/init.c +4
-3-do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); - } +/* possibly add routes */ +if (route_order () ==ROUTE_BEFORE_TUN ) + { +/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */
src/openvpn/init.c +3
-16+do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); + }#ifdef TARGET_ANDROID -/* Store the old fd inside the fd so open_tun can use it */ - c->c1.tuntap->fd = oldtunfd; -#endif -if (dco_enabled (&c->options)) - { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); - } - -/* open the tun device */ -open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap, &c->net_ctx); - -/* set the hardware address */ -if (c->options.lladdr) - { - set_lladdr(&c->net_ctx, c->c1.tuntap->actual_name,
c->options.lladdr,src/openvpn/init.c +2
-21- c->c2.es); - } - -/* do ifconfig */ -if (!c->options.ifconfig_noexec - &&ifconfig_order () ==IFCONFIG_AFTER_TUN_OPEN ) - { -do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); - } - -/* run the up script */ - run_up_down(c->options.up_script, - c->plugins, - OPENVPN_PLUGIN_UP, - c->c1.tuntap->actual_name, -#ifdef _WIN32 - c->c1.tuntap->adapter_index, +/* Store the old fd inside the fd so open_tun can use it */ + c->c1.tuntap->fd = oldtunfd;#endif - dev_type_string(c->options.dev, c->options.dev_type), - c->c2.frame.tun_mtu, - print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF,&gc),
- print_in_addr_t(c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF, &gc),src/openvpn/init.c +0
-10- "init", - NULL, - "up", - c->c2.es); - -#if defined(_WIN32) - if (c->options.block_outside_dns) - { - dmsg(D_LOW, "Blocking outside DNS"); - if (!win_wfp_block_dns(c->c1.tuntap->adapter_index,
c->options.msg_channel))src/openvpn/init.c +2
-5+if (dco_enabled (&c->options)) { -msg (M_FATAL ,"Blocking DNS failed!" ); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco); } - } -#endif -/* possibly add routes */ - if ((route_order() == ROUTE_AFTER_TUN) &&(!c->options.route_delay_defined))
src/openvpn/init.c +2
-4- { -do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); - } +/* open the tun device */ + open_tun(c->options.dev, c->options.dev_type,
c->options.dev_node,src/openvpn/init.c +5
-8+ c->c1.tuntap, &c->net_ctx); - ret = true; - static_context = c; -#ifndef TARGET_ANDROID -} -else -{ -msg (M_INFO ,"Preserving previous TUN/TAP instance: %s" , - c->c1.tuntap->actual_name); +/* set the hardware address */ +if (c->options.lladdr) + { + set_lladdr(&c->net_ctx, c->c1.tuntap->actual_name,
c->options.lladdr,src/openvpn/init.c +51
-12+ c->c2.es); + } -/* explicitly set the ifconfig_* env vars */ -do_ifconfig_setenv (c->c1.tuntap, c->c2.es); +/* do ifconfig */ +if (!c->options.ifconfig_noexec + &&ifconfig_order () ==IFCONFIG_AFTER_TUN_OPEN ) + { +do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + } -/* run the up script if user specified --up-restart */ -if (c->options.up_restart) - { +/* run the up script */ run_up_down(c->options.up_script, c->plugins, OPENVPN_PLUGIN_UP,@@ -1882,24 +1841,71 @@ else c->c2.frame.tun_mtu,print_in_addr_t (c->c1.tuntap->local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF , &gc), -"restart" , +"init" ,NULL ,"up" , c->c2.es); - } +#if defined(_WIN32) -if (c->options.block_outside_dns) - { -dmsg (D_LOW ,"Blocking outside DNS" ); -if (!win_wfp_block_dns (c->c1.tuntap->adapter_index, c->options.msg_channel)) +if (c->options.block_outside_dns) + { +dmsg (D_LOW ,"Blocking outside DNS" ); +if (!win_wfp_block_dns (c->c1.tuntap->adapter_index, c->options.msg_channel)) + { +msg (M_FATAL ,"Blocking DNS failed!" ); + } + } +#endif + +/* possibly add routes */ +if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -msg (M_FATAL ,"Blocking DNS failed!" ); +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); } + + ret = true; + static_context = c; } +else + { +msg (M_INFO ,"Preserving previous TUN/TAP instance: %s" , + c->c1.tuntap->actual_name); + +/* explicitly set the ifconfig_* env vars */ +do_ifconfig_setenv (c->c1.tuntap, c->c2.es); + +/* run the up script if user specified --up-restart */ +if (c->options.up_restart) + { + run_up_down(c->options.up_script, + c->plugins, + OPENVPN_PLUGIN_UP, + c->c1.tuntap->actual_name, +#ifdef _WIN32 + c->c1.tuntap->adapter_index, +#endif + dev_type_string(c->options.dev, c->options.dev_type), + c->c2.frame.tun_mtu, + print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc), + print_in_addr_t(c->c1.tuntap->remote_netmask,
IA_EMPTY_IF_UNDEF, &gc),src/openvpn/init.c +10
-0+"restart" , +NULL , +"up" , + c->c2.es); + } +#if defined(_WIN32) + if (c->options.block_outside_dns) + { + dmsg(D_LOW, "Blocking outside DNS"); + if (!win_wfp_block_dns(c->c1.tuntap->adapter_index,
c->options.msg_channel))src/openvpn/init.c +5
-3+ { +msg (M_FATAL ,"Blocking DNS failed!" ); + } + }#endif -} -#endif /* ifndef TARGET_ANDROID */ + }gc_free (&gc);return ret; } --2.35.1
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
[Openvpn-devel] [PATCH applied] Re: do_open_tun: restyle 'can preserve TUN' check
In reply to Antonio QuartulliThis one really needs "git show -w"... and indeed, the old one was amazingly ugly, including "confusing uncrustify enough so the 'else' with no indent happened"...
Client-tested on Linux.
Your patch has been applied to the master branch.
commit bd139689a4d2f813081aaf93149eabee8d941731
Author: Antonio Quartulli Date: Fri Aug 12 15:06:48 2022 +0200
do_open_tun: restyle 'can preserve TUN' check
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24884.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v100 2/10 dco-win: introduce low-level code for handling ovpn-dco-win in Windows
In reply to Antonio Quartulli--- config-msvc.h | 2 + configure.ac | 9 +- dev-tools/special-files.lst | 1 + src/openvpn/Makefile.am | 4 +- src/openvpn/dco_internal.h | 1 + src/openvpn/dco_win.c | 397 ++++++++++++++++++++++++++++ src/openvpn/dco_win.h | 58 ++++ src/openvpn/openvpn.vcxproj | 3 + src/openvpn/openvpn.vcxproj.filters | 9 + src/openvpn/ovpn-dco-win.h | 108 ++++++++ src/openvpn/tun.h | 3 +- 11 files changed, 590 insertions(+), 5 deletions(-) create mode 100644 src/openvpn/dco_win.c create mode 100644 src/openvpn/dco_win.h create mode 100644 src/openvpn/ovpn-dco-win.h
config-msvc.h +2 -0
@@ -87,3 +87,5 @@ typedef uint16_t in_port_t;#ifdef HAVE_CONFIG_MSVC_LOCAL_H #include <config-msvc-local.h> #endif + +#define ENABLE_DCO 1
configure.ac +6 -3
@@ -144,7 +144,7 @@ AC_ARG_ENABLE( AC_ARG_ENABLE( [dco], - [AS_HELP_STRING([--enable-dco], [enable data channel offload support using ovpn-dco kernel module @<:@default=no@:>@])], + [AS_HELP_STRING([--enable-dco], [enable data channel offload support using the ovpn-dco kernel module (always enabled on Windows) @<:@default=no@:>@])], , [enable_dco="no"] )
@@ -328,6 +328,7 @@ case "$host" in ;; *-mingw*) AC_DEFINE([TARGET_WIN32], [1], [Are we running WIN32?]) + AC_DEFINE([ENABLE_DCO], [1], [DCO is always enabled on Windows]) AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["W"], [Target prefix]) CPPFLAGS="${CPPFLAGS} -DWIN32_LEAN_AND_MEAN" CPPFLAGS="${CPPFLAGS} -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA"
@@ -772,7 +773,6 @@ if test "$enable_dco" = "yes"; then dnl dnl Include generic netlink library used to talk to ovpn-dco dnl - case "$host" in *-*-linux*) PKG_CHECK_MODULES([LIBNL_GENL],
@@ -787,8 +787,11 @@ dnl AC_DEFINE(ENABLE_DCO, 1, [Enable shared data channel offload]) AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) ;; + *-mingw*) + AC_MSG_NOTICE([NOTE: --enable-dco ignored on Windows because it's always enabled]) + ;; *) - AC_MSG_NOTICE([Ignoring --enable-dco on non Linux platform]) + AC_MSG_NOTICE([Ignoring --enable-dco on non supported platform]) ;; esac fi
dev-tools/special-files.lst +1 -0
@@ -2,3 +2,4 @@ E:doc/doxygen/doc_key_generation.h # @verbatim section gets mistreated, excl E:src/compat/compat-lz4.c # Preserve LZ4 upstream formatting E:src/compat/compat-lz4.h # Preserve LZ4 upstream formatting E:src/openvpn/ovpn_dco_linux.h # Preserve ovpn-dco upstream formatting +E:src/openvpn/ovpn-dco-win.h # Preserve ovpn-dco-win upstream formatting
src/openvpn/Makefile.am +3 -1
@@ -55,6 +55,7 @@ openvpn_SOURCES = \ crypto_mbedtls.c crypto_mbedtls.h \ dco.c dco.h dco_internal.h \ dco_linux.c dco_linux.h \ + dco_win.c dco_win.h \ dhcp.c dhcp.h \ dns.c dns.h \ env_set.c env_set.h \
@@ -77,6 +78,7 @@ openvpn_SOURCES = \ mbuf.c mbuf.h \ memdbg.h \ misc.c misc.h \ + ovpn-dco-win.h \ ovpn_dco_linux.h \ platform.c platform.h \ console.c console.h console_builtin.c console_systemd.c \
@@ -151,5 +153,5 @@ openvpn_LDADD = \ $(OPTIONAL_INOTIFY_LIBS) if WIN32 openvpn_SOURCES += openvpn_win32_resources.rc block_dns.c block_dns.h ring_buffer.h -openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi +openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt endif
src/openvpn/dco_internal.h +1 -0
@@ -28,6 +28,7 @@#if defined(ENABLE_DCO )#include "dco_linux.h" +#include "dco_win.h" /** * This file contains the internal DCO API definition.
src/openvpn/dco_win.c new file +397 -0
397 lines not on this page · raw message
src/openvpn/dco_win.h new file +58 -0
58 lines not on this page · raw message
src/openvpn/openvpn.vcxproj +3 -0
@@ -278,6 +278,7 @@ <ClCompile Include="cryptoapi.c" /> <ClCompile Include="dco.c" /> <ClCompile Include="dco_linux.c" /> + <ClCompile Include="dco_win.c" /> <ClCompile Include="dhcp.c" /> <ClCompile Include="dns.c" /> <ClCompile Include="env_set.c" />
@@ -367,6 +368,7 @@ <ClInclude Include="dco.h" /> <ClInclude Include="dco_internal.h" /> <ClInclude Include="dco_linux.h" /> + <ClInclude Include="dco_win.h" /> <ClInclude Include="dhcp.h" /> <ClInclude Include="dns.h" /> <ClInclude Include="env_set.h" />
@@ -401,6 +403,7 @@ <ClInclude Include="openvpn.h" /> <ClInclude Include="options.h" /> <ClInclude Include="otime.h" /> + <ClInclude Include="ovpn-dco-win.h" /> <ClInclude Include="ovpn_dco_linux.h" /> <ClInclude Include="packet_id.h" /> <ClInclude Include="perf.h" />
src/openvpn/openvpn.vcxproj.filters +9 -0
@@ -42,6 +42,9 @@ <ClCompile Include="dco_linux.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="dco_win.c"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="dhcp.c"> <Filter>Source Files</Filter> </ClCompile>
@@ -314,6 +317,9 @@ <ClInclude Include="dco_linux.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="dco_win.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="dhcp.h"> <Filter>Header Files</Filter> </ClInclude>
@@ -413,6 +419,9 @@ <ClInclude Include="otime.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ovpn-dco-win.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="ovpn_dco_linux.h"> <Filter>Header Files</Filter> </ClInclude>
src/openvpn/ovpn-dco-win.h new file +108 -0
108 lines not on this page · raw message
src/openvpn/tun.h +2 -1
@@ -48,7 +48,8 @@enum windows_driver_type {WINDOWS_DRIVER_UNSPECIFIED ,WINDOWS_DRIVER_TAP_WINDOWS6 , -WINDOWS_DRIVER_WINTUN +WINDOWS_DRIVER_WINTUN , +WINDOWS_DRIVER_DCO };#endif
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH v100 02/10] dco-win: introduce low-level code for handling ovpn-dco-win in Windows
Hi,
General note - this commit has no commit message and introduces a set of functions which are not yet called. Does it really make sense to split dco-win support into two commits?
src/openvpn/ovpn-dco-win.h | 108 ++++++++
Quoted 1 line
We have ovpn_dco_linux.h and ovpn-dco-win.h. Should we unify the naming?
+
Quoted 10 lines
src/openvpn/dco_win.c new file +9
-0+int +dco_do_read (dco_context_t *dco) +{ +/* no-op on windows */ +return 0 ; +} + +int +dco_do_write (dco_context_t *dco,int peer_id,struct buffer *buf)
src/openvpn/dco_win.c line 373
Quoted 10 lines
src/openvpn/dco_win.c new file +10
-0+{ +/* no-op on windows */ +return 0 ; +} + +void +dco_event_set (dco_context_t *dco,struct event_set *es,void *arg) +{ +/* no-op on windows */ +}
Those are not supposed to be called on Windows. Shall we assert?
src/openvpn/dco_win.h line 36
Quoted 5 lines
src/openvpn/dco_win.h new file +4
-0+struct dco_context { +bool real_tun_init; +struct tuntap *tt; +};
Hm.. we add "real_tun_init" in this commit and remove in the follow-up("dco-win: implement ovpn-dco support in P2P Windows code path") commit.
-Lev
Re: [Openvpn-devel] [PATCH v100 02/10] dco-win: introduce low-level code for handling ovpn-dco-win in Windows
Oh and also:
6>C:\Users\lev\Projects\openvpn\src\openvpn\dco.c(280,27): error C2039:
'disable_dco': is not a member of 'tuntap_options' 6>C:\Users\lev\Projects\openvpn\src\openvpn\tun.h(64): message : see declaration of 'tuntap_options'
-Lev
Re: [Openvpn-devel] [PATCH v100 02/10] dco-win: introduce low-level code for handling ovpn-dco-win in Windows
In reply to Antonio QuartulliHi,
src/openvpn/Makefile.am openvpn_SOURCES = \ · line 81
Quoted 4 lines · Antonio Quartulli
src/openvpn/Makefile.am +1
-0mbuf.c mbuf.h \ memdbg.h \ misc.c misc.h \ + ovpn-dco-win.h \
Can we please make this ovpn_dco_win.h, with underscores?
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v100 3/10 dco-win: add platform dependant check on incompatible options
In reply to Antonio QuartulliSome platforms may have different constraints in terms of incompatible opions, therefore we add a function that explicitly checks those.
Also, add generic option check for when ovpn-dco-win is in use.
--- src/openvpn/dco.c | 17 +++++++++++++++-- src/openvpn/options.c | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)
src/openvpn/dco.c +15 -2
@@ -221,7 +221,20 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)static bool dco_check_option_conflict_platform (int msglevel,const struct options *o) { -#if defined(TARGET_LINUX ) +#if defined(_WIN32) +if (o->mode ==MODE_SERVER ) + { +msg (msglevel,"Only client and p2p data channel offload is supported " +"with ovpn-dco-win." ); +return false; + } + +if (o->persist_tun) + { +msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +return false; + } +#elif defined(TARGET_LINUX )/* if the device name is fixed, we need to check if an interface with this * name already exists. IF it does, it must be a DCO interface, otherwise * DCO has to be disabled in order to continue.
@@ -246,7 +259,7 @@ dco_check_option_conflict_platform(int msglevel, const struct options *o) strerror(-ret), ret); } } -#endif /* if defined(TARGET_LINUX) */ +#endif /* if defined(_WIN32) */ return true; }
src/openvpn/options.c +5 -0
@@ -2450,6 +2450,11 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--windows-driver wintun requires --dev tun" ); } + +if (options->windows_driver ==WINDOWS_DRIVER_DCO ) + { +dco_check_option_conflict (M_USAGE , options); + }#endif /* ifdef _WIN32 */ /*
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH v100 03/10] dco-win: add platform dependant check on incompatible options
Hi,
I think commit message is a bit misleading:
Quoted 4 lines
dco-win: add platform dependant check on incompatible options Some platforms may have different constraints in terms of incompatible opions, therefore we add a function that explicitly checks those. Also, add generic option check for when ovpn-dco-win is in use.
We already have a function which does platform-specific checks on options and this code only adds Windows-specific checks.
How about:
dco-win: check for incompatible options
At the moment dco-win doesn't support --persist-tun and --server, so add this to options check.
pe 12. elok. 2022 klo 16.07 Antonio Quartulli ([email protected]...) kirjoitti:
Quoted 80 lines
Some platforms may have different constraints in terms of incompatible opions, therefore we add a function that explicitly checks those.
Also, add generic option check for when ovpn-dco-win is in use.
Signed-off-by Antonio Quartulli <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>--- src/openvpn/dco.c | 17 +++++++++++++++-- src/openvpn/options.c | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)src/openvpn/dco.c +4
-1@@ -221,7 +221,20 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi) static bool dco_check_option_conflict_platform(int msglevel, const struct options *o) { -#if defined(TARGET_LINUX ) +#if defined(_WIN32) + if (o->mode == MODE_SERVER) + { + msg(msglevel, "Only client and p2p data channel offload issupported "
src/openvpn/dco.c +7
-0+ "with ovpn-dco-win."); +return false; + } + +if (o->persist_tun) + { + msg(msglevel, "--persist-tun is not supported withovpn-dco-win.");
src/openvpn/dco.c +3
-0+ return false; + } +#elif defined(TARGET_LINUX)/* if the device name is fixed, we need to check if an interface with this
* name already exists. IF it does, it must be a DCO interface,
otherwise
* DCO has to be disabled in order to continue.src/openvpn/dco.c +1
-1@@ -246,7 +259,7 @@ dco_check_option_conflict_platform(int msglevel, const struct options *o) strerror(-ret), ret); } } -#endif /* if defined(TARGET_LINUX) */ +#endif /* if defined(_WIN32) */ return true; }src/openvpn/options.c +5
-0@@ -2450,6 +2450,11 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--windows-driver wintun requires --dev tun" ); } + +if (options->windows_driver ==WINDOWS_DRIVER_DCO ) + { +dco_check_option_conflict (M_USAGE , options); + }#endif /* ifdef _WIN32 */ /*--
2.35.1_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
PATCH v100 4/10 dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Antonio QuartulliWith this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
---
Changes from v3:
* rename WINDOWS_DRIVER_WINDCO to WINDOWS_DRIVER_DCO
* add reference string check
Changes from v2:
* added is_tun_type_set() and removed real_tun_init flag
* moved link-close to do_close_tun()
Changes from v1:
* use suffix _dco_win instead of _windco
* create helper function to retrieve last error from socket object
--- src/openvpn/dco_win.h | 1 - src/openvpn/forward.c | 8 ++++ src/openvpn/init.c | 33 ++++++++++++--- src/openvpn/options.c | 23 ++++++++--- src/openvpn/options.h | 15 +++---- src/openvpn/socket.c | 93 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/socket.h | 25 ++++++++---- src/openvpn/tun.c | 56 ++++++++++++++++++++------ src/openvpn/tun.h | 74 +++++++++++++++++++++++++++------- 9 files changed, 265 insertions(+), 63 deletions(-)
src/openvpn/dco_win.h +0 -1
@@ -31,7 +31,6 @@ typedef OVPN_KEY_SLOT dco_key_slot_t;typedef OVPN_CIPHER_ALG dco_cipher_t ;struct dco_context { -bool real_tun_init;struct tuntap *tt; };
src/openvpn/forward.c +8 -0
@@ -864,9 +864,17 @@ read_incoming_link(struct context *c)return ; } +/* check_status() call below resets last-error code */ +bool dco_win_timeout =tuntap_is_dco_win_timeout (c->c1.tuntap, status); +/* check recvfrom status */ check_status (status,"read" , c->c2.link_socket,NULL ); +if (dco_win_timeout) + { +trigger_ping_timeout_signal (c); + } +/* Remove socks header if applicable */ socks_postprocess_incoming_link (c);
src/openvpn/init.c +28 -5
@@ -1699,7 +1699,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es, - &c->net_ctx); + &c->net_ctx, + c->c1.tuntap);#ifdef _WIN32 c->c1.tuntap->windows_driver = c->options.windows_driver;
@@ -1723,7 +1724,7 @@ can_preserve_tun(struct tuntap *tt)#ifdef TARGET_ANDROID return false;#else -return tt; +return is_tun_type_set (tt);#endif }
@@ -1810,9 +1811,12 @@ do_open_tun(struct context *c)ovpn_dco_init (c->mode, &c->c1.tuntap->dco); } -/* open the tun device */ -open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap, &c->net_ctx); +/* open the tun device (ovpn-dco-win already opened the device for the socket) */ +if (!tuntap_is_dco_win (c->c1.tuntap)) + { +open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, + c->c1.tuntap, &c->net_ctx); + }/* set the hardware address */ if (c->options.lladdr)
@@ -1930,6 +1934,16 @@ do_close_tun_simple(struct context *c)static void do_close_tun (struct context *c,bool force) { +/* With dco-win we open tun handle in the very beginning. +* In case when tun wasn't opened - like we haven't connected, +* we still need to close tun handle +*/ +if (tuntap_is_dco_win (c->c1.tuntap) && !is_tun_type_set (c->c1.tuntap)) + { +do_close_tun_simple (c); +return ; + } +if (!c->c1.tuntap || !c->c1.tuntap_owned) {return ;
@@ -3570,6 +3584,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/options.c +17 -6
@@ -3343,9 +3343,11 @@ options_postprocess_mutate_invariant(struct options *options)#ifdef _WIN32const int dev =dev_type_enum (options->dev, options->dev_type); -/* when using wintun, kernel doesn't send DHCP requests, so don't use it */ -if (options->windows_driver ==WINDOWS_DRIVER_WINTUN - && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) +/* when using wintun/ovpn-dco-win, kernel doesn't send DHCP requests, so don't use it */ +if ((options->windows_driver ==WINDOWS_DRIVER_WINTUN + || options->windows_driver ==WINDOWS_DRIVER_DCO ) + && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ + || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) { options->tuntap_options.ip_win32_type =IPW32_SET_NETSH ; }
@@ -3439,10 +3441,12 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +#if !defined(_WIN32) else if (cipher_valid("CHACHA20-POLY1305")) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ; } +#endif else { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM" ;
@@ -4165,7 +4169,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4552,13 +4557,19 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco-win")) + { +return WINDOWS_DRIVER_DCO ; + } else { -msg (msglevel,"--windows-driver must be tap-windows6 or wintun" ); +msg (msglevel,"--windows-driver must be tap-windows6, wintun " +"or ovpn-dco-win" );return WINDOWS_DRIVER_UNSPECIFIED ; } } -#endif +#endif /* ifdef _WIN32 */ /* * parse/print topology coding
src/openvpn/options.h +5 -10
@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) -/** * Returns whether the current configuration has dco enabled. */ static inline bool dco_enabled (const struct options *o) { +#if defined(_WIN32) +return o->windows_driver ==WINDOWS_DRIVER_DCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} - -#else /* if defined(ENABLE_DCO) && defined(TARGET_LINUX) */ - -static inline bool -dco_enabled (const struct options *o) -{ +#else return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/socket.c +87 -6
141 lines not on this page · raw message
src/openvpn/socket.h +18 -7
@@ -34,6 +34,7 @@#include "proxy.h" #include "socks.h" #include "misc.h" +#include "tun.h" /* * OpenVPN's default port number as assigned by IANA.
@@ -937,7 +938,8 @@ socket_connection_reset(const struct link_socket *sock, int status) {const int err =openvpn_errno ();#ifdef _WIN32 -return err ==WSAECONNRESET || err ==WSAECONNABORTED ; +return err ==WSAECONNRESET || err ==WSAECONNABORTED + || err ==ERROR_CONNECTION_ABORTED ;#else return err ==ECONNRESET ;#endif
@@ -1048,6 +1050,11 @@ link_socket_read_udp_win32(struct link_socket *sock, struct link_socket_actual *from) {sockethandle_t sh = { .s = sock->sd }; +if (sock->info.dco_installed) + { +addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + sh.is_handle = true; + }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1057,7 +1064,7 @@ int link_socket_read_udp_posix(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from); -#endif +#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int
@@ -1065,7 +1072,10 @@ link_socket_read(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) + || sock->info.dco_installed) + /* unified UDPv4 and UDPv6, for DCO the kernel + * will strip the length header */ { int res;
@@ -1106,19 +1116,19 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );if (status <0 ) { - err =WSAGetLastError (); + err =SocketHandleGetLastError (sh); } }socket_send_queue (sock, buf, to);if (status <0 ) { -WSASetLastError (err); +SocketHandleSetLastError (sh, err);return status; }else
@@ -1180,8 +1190,9 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) { + /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); } else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
src/openvpn/tun.c +43 -13
118 lines not on this page · raw message
src/openvpn/tun.h +59 -15
130 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH v100 5/10 dco-win: add documentation to README.dco.md
In reply to Antonio Quartulli--- README.dco.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
README.dco.md +10 -1
@@ -57,6 +57,13 @@ see a message like in your log. +Getting started (Windows) +------------------------- +Getting started under windows is currently for brave people having experience +with windows development. You need to compile openvpn yourself and also need +to get the test driver installed on your system. + + DCO and P2P mode ---------------- DCO is also available when running OpenVPN in P2P mode without `--pull` /
@@ -111,7 +118,9 @@ Limitations by design - older versions are missing support for the AEAD ciphers; - topology subnet is the only supported `--topology` for servers; - iroute directives install routes on the host operating system, see also - Routing with ovpn-dco. + Routing with ovpn-dco; +- (ovpn-dco-win) client and p2p mode only; +- (ovpn-dco-win) Chacha20-Poly1305 support available starting with Windows 11. Current implementation limitations
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH v100 05/10] dco-win: add documentation to README.dco.md
Hi,
+Getting started (Windows)
Quoted 7 lines
+-------------------------
+Getting started under windows is currently for brave people having experience
+with windows development. You need to compile openvpn yourself and also need
+to get the test driver installed on your system.
While I consider building openvpn and installing test-signed drivers as common knowledge,
this is not necessarily needed to try out dco-win.
We have GHA-based automation which builds openvpn, builds MSI installers for x86/x64/arm64 and uploads those to build.openvpn.net.
So to try out dco-win, one just needs to get installation package from
https://build.openvpn.net/downloads/snapshots/github-actions/openvpn2/
-Lev
PATCH v100 6/10 dco-win: update GH Actions config file
In reply to Antonio Quartulli--- .github/workflows/build.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
.github/workflows/build.yaml +1 -6
@@ -59,11 +59,6 @@ jobs: steps: - name: Install dependencies run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip - - name: Checkout ovpn-dco-win - uses: actions/[email protected]... - with: - repository: OpenVPN/ovpn-dco-win - path: ovpn-dco-win - name: Checkout OpenVPN uses: actions/[email protected]... with:
@@ -151,7 +146,7 @@ jobs: run: cp ./tap-windows-${TAP_WINDOWS_VERSION}/include/tap-windows.h ${HOME}/mingw/opt/include/ - name: configure OpenVPN - run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig DCO_SOURCEDIR=$(realpath ../ovpn-dco-win) LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 --enable-dco + run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 working-directory: openvpn - name: build OpenVPN
Signature · 1 line
2.35.1
PATCH v100 7/10 dco-win: ensure the DCO API is not used when running on Windows
In reply to Antonio QuartulliOn Windows the high level API should still use the link_socket object to read and write packets. For this reason, even if dco_installed is true, we still need to rely on the classic link_socket object.
--- src/openvpn/dco_win.c | 4 ++-- src/openvpn/forward.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-)
src/openvpn/dco_win.c +2 -2
@@ -355,14 +355,14 @@ dco_available(int msglevel)int dco_do_read (dco_context_t *dco) { -/* no-op on windows */ +ASSERT (false);return 0 ; }int dco_do_write (dco_context_t *dco,int peer_id,struct buffer *buf) { -/* no-op on windows */ +ASSERT (false);return 0 ; }
src/openvpn/forward.c +22 -1
@@ -1601,6 +1601,27 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) } } +/* Depending on the platform, we may have to not use the DCO socket, even if DCO +* is being used for a specific link. +* +* This happens with Windows, where the standard link_socket API have to be used +* also with DCO. +* +* For this reason we must make the right decision and not always look at +* dco_installed. Note that on Windows the dco_installed field is still supposed +* to be true, because it is used in the lower level code to use the proper API +* (socket vs handle). This is why we need this function with some ifdef sauce +*/ +static bool +should_use_dco_socket (struct link_socket *sock) +{ +#if defined(TARGET_LINUX ) +return sock->info.dco_installed; +#else +return false; +#endif +} +/* * Input: c->c2.to_link */
@@ -1674,7 +1695,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (c->c2.link_socket->info.dco_installed) +if (should_use_dco_socket (c->c2.link_socket)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH v100 07/10] dco-win: ensure the DCO API is not used when running on Windows
Hi,
Quoted 15 lines · Antonio Quartulli
On Windows the high level API should still use the
link_socketobject to read and write packets. For this reason, even ifdco_installedis true, we still need to rely on the classiclink_socketobject.Signed-off-by Antonio Quartulli <[email protected]...>--- src/openvpn/dco_win.c | 4 ++-- src/openvpn/forward.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-)src/openvpn/dco_win.c +0
-0
src/openvpn/dco_win.c dco_available(int msglevel) · line 360
Quoted 7 lines
src/openvpn/dco_win.c +1
-1@@ -355,14 +355,14 @@ dco_available(int msglevel)int dco_do_read (dco_context_t *dco) { -/* no-op on windows */ +ASSERT (false);return 0 ; }
I think this ASSERT(0) should go into the patch that introduces dco_win.c - this is just a few patches upstream, so introducing it and then changing it right again sounds like a bit of needless commit noise...
Quoted 9 lines
src/openvpn/forward.c +1
-0@@ -1601,6 +1601,27 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) } } +/* Depending on the platform, we may have to not use the DCO socket, even if DCO
src/openvpn/forward.c process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) · line 1614
Quoted 10 lines
src/openvpn/forward.c +10
-0+* is being used for a specific link. +* +* This happens with Windows, where the standard link_socket API have to be used +* also with DCO. +* +* For this reason we must make the right decision and not always look at +* dco_installed. Note that on Windows the dco_installed field is still supposed +* to be true, because it is used in the lower level code to use the proper API +* (socket vs handle). This is why we need this function with some ifdef sauce +*/
This comment could use a bit of rewording, like
/* Linux-like DCO implementations pass the socket to the kernel and
* disallow usage of it from userland, so (control) packets sent and
* received by OpenVPN need to go through the DCO interface. *
* Windows DCO needs the control packets to be sent via the normal
* Socket API.
*
* Hide that complexity (... especially if more platforms show up
* in future...) in a small inline function
*/
src/openvpn/forward.c process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) · line 1623
Quoted 9 lines
src/openvpn/forward.c +9
-0+static bool +should_use_dco_socket (struct link_socket *sock) +{ +#if defined(TARGET_LINUX ) +return sock->info.dco_installed; +#else +return false; +#endif +}
... which really should be "inline", no? ;-)
**WARNING** - this breaks FreeBSD DCO, so with FreeBSD DCO merged now, it needs to be #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD).
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v100 8/10 ovpn-dco: print some netlink messages to debug level
In reply to Antonio QuartulliNetlink errors detected during dco availability detection are not really required and can confuse the user.
Have them printed to the dco debug level.
--- src/openvpn/dco_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/dco_linux.c +1 -1
@@ -913,7 +913,7 @@ nla_put_failure:bool dco_available (int msglevel) { -if (resolve_ovpn_netlink_id (msglevel) <0 ) +if (resolve_ovpn_netlink_id (D_DCO_DEBUG ) <0 ) {msg (msglevel,"Note: Kernel support for ovpn-dco missing, disabling data channel offload." );
Signature · 1 line
2.35.1
[Openvpn-devel] [PATCH applied] Re: ovpn-dco: print some netlink messages to debug level
As we discussed :-) - trivial enough.
Without that patch:
$ openvpn --verb 3 ... 2022-08-13 20:51:06 Cannot find ovpn_dco netlink component: Object not found 2022-08-13 20:51:06 Note: Kernel support for ovpn-dco missing, disabling data channel offload. 2022-08-13 20:51:06 OpenVPN 2.6_git [git:master/d7f16eea8e939b42] x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] [DCO] built on Aug 13 2022
with that patch:
2022-08-13 20:52:12 Note: Kernel support for ovpn-dco missing, disabling data channel offload. 2022-08-13 20:52:12 OpenVPN 2.6_git [git:master/29f20e738531f0e6] x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] [DCO] built on Aug 13 2022
and with --verb 7 it shows up again.
The way we currently print some informational messages before and others after the version number is highly improvable, and I've opened a Trac ticket for it... (#1470)
Your patch has been applied to the master branch.
commit 29f20e738531f0e65df1bc330f598b3d1eb60b22
Author: Antonio Quartulli Date: Fri Aug 12 15:06:55 2022 +0200
ovpn-dco: print some netlink messages to debug level
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24892.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v100 9/10 dco: properly name variables
In reply to Antonio Quartullirenamed remote_addrX variables to vpn_addrX to make it clear that they refer to the address over the VPN/tunnel
--- src/openvpn/dco.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
src/openvpn/dco.c +9 -8
@@ -553,19 +553,20 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; } -struct in_addr remote_ip4 = {0 }; -struct in6_addr *remote_addr6 =NULL ; -struct in_addr *remote_addr4 =NULL ; -/* In server mode we need to fetch the remote addresses from the push config */ + +struct in_addr vpn_ip4 = {0 }; +struct in_addr *vpn_addr4 =NULL ;if (c->c2.push_ifconfig_defined) { - remote_ip4.s_addr =htonl (c->c2.push_ifconfig_local); - remote_addr4 = &remote_ip4; + vpn_ip4.s_addr =htonl (c->c2.push_ifconfig_local); + vpn_addr4 = &vpn_ip4; } + +struct in6_addr *vpn_addr6 =NULL ;if (c->c2.push_ifconfig_ipv6_defined) { - remote_addr6 = &c->c2.push_ifconfig_ipv6_local; + vpn_addr6 = &c->c2.push_ifconfig_ipv6_local; }if (dco_multi_get_localaddr (m, mi, &local))
@@ -574,7 +575,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) }int ret =dco_new_peer (&c->c1.tuntap->dco, peer_id, sd, localaddr, - remoteaddr, remote_addr4, remote_addr6); + remoteaddr, vpn_addr4, vpn_addr6);if (ret <0 ) {return ret;
Signature · 1 line
2.35.1
PATCH v100 10/10 dco: move message to DCO debug level and reword a bit
In reply to Antonio QuartulliThis message is purely a debug message, so it should go to the appropriate log level. At the same time make it more clear.
--- src/openvpn/dco_linux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpn/dco_linux.c +2 -1
@@ -760,7 +760,8 @@ ovpn_handle_msg(struct nl_msg *msg, void *arg)uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]);if (ifindex != dco->ifindex) { -msg (D_DCO ,"ovpn-dco: received message type %d with mismatched ifindex %d\n" , +msg (D_DCO_DEBUG , +"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex);return NL_SKIP ; }
Signature · 1 line
2.35.1
[Openvpn-devel] [PATCH applied] Re: dco: move message to DCO debug level and reword a bit
Indeed :-) - this message is fairly confusing on systems with multiple DCO-using OpenVPN instances, running with --verb 3 - for all new clients and client disconnects, there's noise in "other" instances, which looked quite scary.
I haven't tested this (beyond a compile test), but I know when and where I saw these, and making them go to DCO debug level is reasonable.
Your patch has been applied to the master branch.
commit f088db208621ead8e8c7151f3e705f5ff9a0cbb5
Author: Antonio Quartulli Date: Fri Aug 12 15:06:57 2022 +0200
dco: move message to DCO debug level and reword a bit
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24893.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering