Introduce ovpn-dco(-win) support
cover Introduce ovpn-dco(-win) support
Hi all,
this is the first official submission of the ovpn-dco support for OpenVPN 2. This patchset is ready for review (and possible merge).
Please have a look, test and try to break it!
What has changed from the RFCv2 (sent on Jan 14th):
* DCO API has been modified to allow specifying a value for mssfix. However only ovpn-dco-win will pick up this value and do something meaningful. On linux is yet to be decided how to handle it.
* peer_add() and peer_set() have been decoupled so that the latter can be invoked at the right time, after some parameters have been computed (i.e. mssfix).
* routes and iroutes are now installed with a default metric of 200 for the former and 100 for the latter. this guarantees that iroutes always have higher priority (iroutes are basically routes with a specific nexthop).
* The ovpn-dco interface is now configured in p2p mode when launching OpenVPN as client or p2p, while it is configured in mp (multipeer) mode when launching OpenVPN in server mode.
* Reverse Path Filtering is now enabled automatically when the interface is configured in mp mode (this is a change in ovpn-dco itself).
* some more intra-OpenVPN DCO API polishing.
* a few minor things I may not be recalling now...
A working copy of this patchset, always based on top of laest master, is available in the OpenVPN repo in the "dco" branch.
Thanks a lot!
Regards,
Antonio Quartulli (4):
networking: silence warnings about unused arguments
networking: implement net_iface_new and net_iface_del APIs
ovpn-dco: introduce linux data-channel offload support GitHub Actions: add Linux DCO build (on Ubuntu 20.04)
Arne Schwabe (3):
networking: remove duplicate methods from networking_sitnl.c
tun: extract close_tun_handle into its own fucntion and print correct
type
ovpn-dco-win: introduce windows data-channel offload support
.github/workflows/build.yaml | 16 +- Changes.rst | 7 + README.dco.md | 138 +++ config-msvc.h | 2 + configure.ac | 35 + doc/man-sections/advanced-options.rst | 13 + doc/man-sections/server-options.rst | 6 + src/compat/Makefile.am | 3 +- src/compat/compat-dco_get_overlapped_result.c | 44 + src/compat/compat.h | 6 + src/compat/compat.vcxproj | 1 + src/compat/compat.vcxproj.filters | 3 + src/openvpn/Makefile.am | 5 +- src/openvpn/crypto.c | 1 + src/openvpn/dco.c | 631 +++++++++++++ src/openvpn/dco.h | 310 ++++++ src/openvpn/dco_internal.h | 81 ++ src/openvpn/dco_linux.c | 888 ++++++++++++++++++ src/openvpn/dco_linux.h | 61 ++ src/openvpn/dco_win.c | 397 ++++++++ src/openvpn/dco_win.h | 57 ++ src/openvpn/errlevel.h | 2 + src/openvpn/event.h | 3 + src/openvpn/forward.c | 79 +- src/openvpn/init.c | 204 +++- src/openvpn/init.h | 2 +- src/openvpn/misc.h | 3 +- src/openvpn/mtcp.c | 61 +- src/openvpn/mudp.c | 13 + src/openvpn/multi.c | 227 ++++- src/openvpn/multi.h | 6 +- src/openvpn/networking.h | 37 +- src/openvpn/networking_iproute2.c | 35 + src/openvpn/networking_sitnl.c | 100 +- src/openvpn/openvpn.vcxproj | 6 +- src/openvpn/openvpn.vcxproj.filters | 15 + src/openvpn/options.c | 51 +- src/openvpn/options.h | 15 + src/openvpn/ovpn-dco-win.h | 108 +++ src/openvpn/ovpn_dco_linux.h | 265 ++++++ src/openvpn/socket.c | 105 ++- src/openvpn/socket.h | 21 +- src/openvpn/ssl.c | 80 +- src/openvpn/ssl.h | 7 +- src/openvpn/ssl_common.h | 23 + src/openvpn/ssl_ncp.c | 2 +- src/openvpn/tun.c | 245 +++-- src/openvpn/tun.h | 62 +- tests/unit_tests/openvpn/test_networking.c | 25 +- 49 files changed, 4239 insertions(+), 268 deletions(-) create mode 100644 README.dco.md create mode 100644 src/compat/compat-dco_get_overlapped_result.c create mode 100644 src/openvpn/dco.c create mode 100644 src/openvpn/dco.h create mode 100644 src/openvpn/dco_internal.h create mode 100644 src/openvpn/dco_linux.c create mode 100644 src/openvpn/dco_linux.h 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 create mode 100644 src/openvpn/ovpn_dco_linux.h
Signature · 1 line
2.35.1
PATCH 1/7 networking: remove duplicate methods from networking_sitnl.c
From: Arne Schwabe <[email protected]...>
The net_ctx_init/reset/free methods of sitnl are the same dummy methods that are already defined for non-Linux platforms in the networking.h header.
--- src/openvpn/networking.h | 7 ++++++- src/openvpn/networking_sitnl.c | 22 ---------------------- 2 files changed, 6 insertions(+), 23 deletions(-)
src/openvpn/networking.h +6 -1
@@ -33,7 +33,12 @@ struct context;/* define mock types to ensure code builds on any platform */ typedef void *openvpn_net_ctx_t ;typedef void *openvpn_net_iface_t ; +#endif /* ifdef ENABLE_SITNL */ +/* Only the iproute2 backend implements these functions, +* the rest can rely on these stubs +*/ +#if !defined(ENABLE_IPROUTE )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -51,7 +56,7 @@ net_ctx_free(openvpn_net_ctx_t *ctx) { (void )ctx; } -#endif /* ifdef ENABLE_SITNL */ +#endif /* !defined(ENABLE_IPROUTE) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +0 -22
@@ -596,28 +596,6 @@ net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, }#ifdef ENABLE_SITNL - -int -net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) -{ - (void )c; - (void )ctx; - -return 0 ; -} - -void -net_ctx_reset (openvpn_net_ctx_t *ctx) -{ - (void )ctx; -} - -void -net_ctx_free (openvpn_net_ctx_t *ctx) -{ - (void )ctx; -} -int net_route_v4_best_gw (openvpn_net_ctx_t *ctx,const in_addr_t *dst,in_addr_t *best_gw,char *best_iface)
Signature · 1 line
2.35.1
[Openvpn-devel] [PATCH applied] Re: networking: remove duplicate methods from networking_sitnl.c
Trivial enough. Compile-tested with sitnl and --enable-iproute2.
Your patch has been applied to the master branch.
commit c0fa37eda2a12c6587e9b2db2c0a33c91d3ced6e
Author: Arne Schwabe Date: Sat Apr 2 09:08:56 2022 +0200
networking: remove duplicate methods from networking_sitnl.c
Signed-off-by: Arne Schwabe <[email protected]...>
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]/msg24054.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 2/7 networking: silence warnings about unused arguments
In reply to Antonio QuartulliIn the net_ctx_init() stub definition, arguments are not used and therefore they should be explicitly marked to avoid compiler warnings.
--- src/openvpn/networking.h | 3 +++ 1 file changed, 3 insertions(+)
src/openvpn/networking.h +3 -0
@@ -42,6 +42,9 @@ typedef void *openvpn_net_iface_t;static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) { + (void )c; + (void )ctx; +return 0 ; }
Signature · 1 line
2.35.1
[Openvpn-devel] [PATCH applied] Re: networking: silence warnings about unused arguments
While my compiler (gcc 11.2.1) does not warn about them, having these (void) for two of the three functions and not all of them is at least slightly silly... so, yeah, why not.
Your patch has been applied to the master branch.
commit c3aa44699c69811493a81bda340a03530059929b
Author: Antonio Quartulli Date: Sat Apr 2 09:08:57 2022 +0200
networking: silence warnings about unused arguments
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]/msg24052.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 3/7 networking: implement net_iface_new and net_iface_del APIs
In reply to Antonio QuartulliThese two new methods can be used to create and delete a tun or an ovpn-dco interface via networking API.
Implementations for SITNL and iproute2 are provided
--- src/openvpn/networking.h | 27 ++++++++ src/openvpn/networking_iproute2.c | 35 +++++++++++ src/openvpn/networking_sitnl.c | 71 ++++++++++++++++++++++ tests/unit_tests/openvpn/test_networking.c | 22 ++++++- 4 files changed, 154 insertions(+), 1 deletion(-)
src/openvpn/networking.h +27 -0
@@ -35,6 +35,12 @@ typedef void *openvpn_net_ctx_t;typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ +enum iface_type { +IFACE_DUMMY , +IFACE_TUN , +IFACE_OVPN_DCO , +}; +/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */
@@ -87,6 +93,27 @@ void net_ctx_reset(openvpn_net_ctx_t *ctx);*/ void net_ctx_free (openvpn_net_ctx_t *ctx); +/** +* Add a new interface +* +* @param ctx the implementation specific context +* @param iface interface to create +* @param type interface type (see enum iface_type declaration) +* @param arg extra data required by the specific type +* @return int 0 on success, negative error code on error +*/ +int net_iface_new (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface, +enum iface_type type,void *arg); + +/** +* Remove an interface +* +* @param ctx the implementation specific context +* @param iface interface to delete +* @return int 0 on success, negative error code on error +*/ +int net_iface_del (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface); +/** * Bring interface up or down. *
src/openvpn/networking_iproute2.c +35 -0
@@ -38,6 +38,12 @@#include <stdbool.h> #include <netinet/in.h> +static const char *iface_type_str[] = { + [IFACE_DUMMY ] ="dummy" , + [IFACE_TUN ] ="tun" , + [IFACE_OVPN_DCO ] ="ovpn-dco" , +}; +int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,6 +69,35 @@ net_ctx_free(openvpn_net_ctx_t *ctx)gc_free (&ctx->gc); } +int +net_iface_new (openvpn_net_ctx_t *ctx,const char *iface,enum iface_type type, +void *arg) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link add %s type %s" , iproute_path, iface, + iface_type_str[type]); +argv_msg (M_INFO , &argv); +openvpn_execve_check (&argv, ctx->es,S_FATAL ,"Linux ip link add failed" ); + +argv_free (&argv); + +return 0 ; +} + +int +net_iface_del (openvpn_net_ctx_t *ctx,const char *iface) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link del %s" , iproute_path, iface); +openvpn_execve_check (&argv, ctx->es,S_FATAL ,"Linux ip link del failed" ); + +argv_free (&argv); + +return 0 ; +} +int net_iface_up (openvpn_net_ctx_t *ctx,const char *iface,bool up) {
src/openvpn/networking_sitnl.c +71 -0
89 lines not on this page · raw message
tests/unit_tests/openvpn/test_networking.c +21 -1
@@ -13,6 +13,20 @@ net__iface_up(bool up)return net_iface_up (NULL , iface, up); } +static int +net__iface_new (const char *name,enum iface_type type,char *type_str) +{ +printf ("CMD: ip link add %s type %s\n" , name, type_str); +return net_iface_new (NULL , name, type,NULL ); +} + +static int +net__iface_del (const char *name) +{ +printf ("CMD: ip link del %s\n" , name); +return net_iface_del (NULL , name); +} +static int net__iface_mtu_set (int mtu) {
@@ -191,7 +205,7 @@ net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_str,static void usage (char *name) { -printf ("Usage: %s <0-7>\n" , name); +printf ("Usage: %s <0-9>\n" , name); }int
@@ -243,6 +257,12 @@ main(int argc, char *argv[])case 7 :return net__route_v6_add_gw ("2001:cafe:babe::" ,48 ,"2001::2" ,600 ); +case 8 : +return net__iface_new ("dummy0815" ,IFACE_DUMMY ,"dummy" ); + +case 9 : +return net__iface_del ("dummy0815" ); +default :printf ("invalid test: %d\n" , test);break ;
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH 3/7] networking: implement net_iface_new and net_iface_del APIs
Hi,
src/openvpn/networking_iproute2.c line 45
Quoted 10 lines · Antonio Quartulli
+++
b/src/openvpn/networking_iproute2.csrc/openvpn/networking_iproute2.c +5
-0@@ -38,6 +38,12 @@#include <stdbool.h> #include <netinet/in.h> +static const char *iface_type_str[] = { + [IFACE_DUMMY ] ="dummy" , + [IFACE_TUN ] ="tun" , + [IFACE_OVPN_DCO ] ="ovpn-dco" , +};
I find this notation surprising - I guess it's "ensure that array indexes match enum values", but it's a construct we do not use anywhere else in OpenVPN (I think).
src/openvpn/networking_iproute2.c net_ctx_free(openvpn_net_ctx_t *ctx) · line 79
Quoted 7 lines
src/openvpn/networking_iproute2.c +7
-0+net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, enum iface_type type, + void *arg) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link add %s type %s" , iproute_path, iface, + iface_type_str[type]);
Also, there is no array bounds check here...
src/openvpn/networking_sitnl.c net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, · line 616
Quoted 7 lines
#ifdef
ENABLE_SITNLsrc/openvpn/networking_sitnl.c +6
-0+ +static const char *iface_type_str[] = { + [IFACE_DUMMY ] ="dummy" , + [IFACE_TUN ] ="tun" , + [IFACE_OVPN_DCO ] ="ovpn-dco" , +};
Plus, it is repeated here... (and no bounds check either).
Can we come up with something more in line with the rest of OpenVPN, like a static function that will return the name of that thing, for consumers that want a name, and "dummy" or "unknown" for out-of-bounds access?
(Right now, all consumers want a string, and the caller passes in a single-use enum, which is not used for anything but "convert back to string", so the value of having an enum here is not really obvious)
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]...Re: [Openvpn-devel] [PATCH 3/7] networking: implement net_iface_new and net_iface_del APIs
In reply to Antonio QuartulliHi,
src/openvpn/networking_iproute2.c net_ctx_free(openvpn_net_ctx_t *ctx) · line 96
Quoted 9 lines · Antonio Quartulli
src/openvpn/networking_iproute2.c +9
-0+int +net_iface_del (openvpn_net_ctx_t *ctx,const char *iface) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link del %s" , iproute_path, iface); +openvpn_execve_check (&argv, ctx->es,S_FATAL ,"Linux ip link del failed" ); + +argv_free (&argv);
On "failure to remove something" we generally do not hard-abort right away but just report the error, and continue with cleaning up things.
So maybe net_iface_del() should do the same thing?
(See "undo_ifconfig_ipv4()", for example, or most other close_tun() related openvpn_execve_check() calls)
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 v2 3/7 networking: implement net_iface_new and net_iface_del APIs
In reply to Antonio QuartulliThese two new methods can be used to create and delete a tun or an ovpn-dco interface via networking API.
Implementations for SITNL and iproute2 are provided
---
Changes from v1:
* removed enum iface_type -> just use strings to make code simpler ** adapt test_networking.c accordigly
* don't initialize ifichange as we are not changing any ifi_flag
* remove S_FATAL flag from net_iface_del() iproute2 implementation
--- src/openvpn/networking.h | 21 ++++++++ src/openvpn/networking_iproute2.c | 28 ++++++++++ src/openvpn/networking_sitnl.c | 63 ++++++++++++++++++++++ tests/unit_tests/openvpn/test_networking.c | 22 +++++++- 4 files changed, 133 insertions(+), 1 deletion(-)
src/openvpn/networking.h +21 -0
@@ -87,6 +87,27 @@ void net_ctx_reset(openvpn_net_ctx_t *ctx);*/ void net_ctx_free (openvpn_net_ctx_t *ctx); +/** +* Add a new interface +* +* @param ctx the implementation specific context +* @param iface interface to create +* @param type string describing interface type +* @param arg extra data required by the specific type +* @return int 0 on success, negative error code on error +*/ +int net_iface_new (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface, +const char *type,void *arg); + +/** +* Remove an interface +* +* @param ctx the implementation specific context +* @param iface interface to delete +* @return int 0 on success, negative error code on error +*/ +int net_iface_del (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface); +/** * Bring interface up or down. *
src/openvpn/networking_iproute2.c +28 -0
@@ -63,6 +63,34 @@ net_ctx_free(openvpn_net_ctx_t *ctx)gc_free (&ctx->gc); } +int +net_iface_new (openvpn_net_ctx_t *ctx,const char *iface,const char *type, +void *arg) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link add %s type %s" , iproute_path, iface, iface_type); +argv_msg (M_INFO , &argv); +openvpn_execve_check (&argv, ctx->es,S_FATAL ,"Linux ip link add failed" ); + +argv_free (&argv); + +return 0 ; +} + +int +net_iface_del (openvpn_net_ctx_t *ctx,const char *iface) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link del %s" , iproute_path, iface); +openvpn_execve_check (&argv, ctx->es,0 ,"Linux ip link del failed" ); + +argv_free (&argv); + +return 0 ; +} +int net_iface_up (openvpn_net_ctx_t *ctx,const char *iface,bool up) {
src/openvpn/networking_sitnl.c +63 -0
81 lines not on this page · raw message
tests/unit_tests/openvpn/test_networking.c +21 -1
@@ -13,6 +13,20 @@ net__iface_up(bool up)return net_iface_up (NULL , iface, up); } +static int +net__iface_new (const char *name,const char *type) +{ +printf ("CMD: ip link add %s type %s\n" , name, type); +return net_iface_new (NULL , name, type,NULL ); +} + +static int +net__iface_del (const char *name) +{ +printf ("CMD: ip link del %s\n" , name); +return net_iface_del (NULL , name); +} +static int net__iface_mtu_set (int mtu) {
@@ -191,7 +205,7 @@ net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_str,static void usage (char *name) { -printf ("Usage: %s <0-7>\n" , name); +printf ("Usage: %s <0-9>\n" , name); }int
@@ -243,6 +257,12 @@ main(int argc, char *argv[])case 7 :return net__route_v6_add_gw ("2001:cafe:babe::" ,48 ,"2001::2" ,600 ); +case 8 : +return net__iface_new ("dummy0815" ,"dummy" ); + +case 9 : +return net__iface_del ("dummy0815" ); +default :printf ("invalid test: %d\n" , test);break ;
Signature · 1 line
2.35.1
PATCH v3 3/7 networking: implement net_iface_new and net_iface_del APIs
These two new methods can be used to create and delete a tun or an ovpn-dco interface via networking API.
Implementations for SITNL and iproute2 are provided
---
Changes from v1:
* removed enum iface_type -> just use strings to make code simpler ** adapt test_networking.c accordigly
* don't initialize ifichange as we are not changing any ifi_flag
* remove S_FATAL flag from net_iface_del() iproute2 implementation
Changes from v2:
* fix leftover variable (iface_type -> type) in net_iface_new() for iproute2
--- src/openvpn/networking.h | 21 ++++++++ src/openvpn/networking_iproute2.c | 28 ++++++++++ src/openvpn/networking_sitnl.c | 63 ++++++++++++++++++++++ tests/unit_tests/openvpn/test_networking.c | 22 +++++++- 4 files changed, 133 insertions(+), 1 deletion(-)
src/openvpn/networking.h +21 -0
@@ -87,6 +87,27 @@ void net_ctx_reset(openvpn_net_ctx_t *ctx);*/ void net_ctx_free (openvpn_net_ctx_t *ctx); +/** +* Add a new interface +* +* @param ctx the implementation specific context +* @param iface interface to create +* @param type string describing interface type +* @param arg extra data required by the specific type +* @return int 0 on success, negative error code on error +*/ +int net_iface_new (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface, +const char *type,void *arg); + +/** +* Remove an interface +* +* @param ctx the implementation specific context +* @param iface interface to delete +* @return int 0 on success, negative error code on error +*/ +int net_iface_del (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface); +/** * Bring interface up or down. *
src/openvpn/networking_iproute2.c +28 -0
@@ -63,6 +63,34 @@ net_ctx_free(openvpn_net_ctx_t *ctx)gc_free (&ctx->gc); } +int +net_iface_new (openvpn_net_ctx_t *ctx,const char *iface,const char *type, +void *arg) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link add %s type %s" , iproute_path, iface, type); +argv_msg (M_INFO , &argv); +openvpn_execve_check (&argv, ctx->es,S_FATAL ,"Linux ip link add failed" ); + +argv_free (&argv); + +return 0 ; +} + +int +net_iface_del (openvpn_net_ctx_t *ctx,const char *iface) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link del %s" , iproute_path, iface); +openvpn_execve_check (&argv, ctx->es,0 ,"Linux ip link del failed" ); + +argv_free (&argv); + +return 0 ; +} +int net_iface_up (openvpn_net_ctx_t *ctx,const char *iface,bool up) {
src/openvpn/networking_sitnl.c +63 -0
81 lines not on this page · raw message
tests/unit_tests/openvpn/test_networking.c +21 -1
@@ -13,6 +13,20 @@ net__iface_up(bool up)return net_iface_up (NULL , iface, up); } +static int +net__iface_new (const char *name,const char *type) +{ +printf ("CMD: ip link add %s type %s\n" , name, type); +return net_iface_new (NULL , name, type,NULL ); +} + +static int +net__iface_del (const char *name) +{ +printf ("CMD: ip link del %s\n" , name); +return net_iface_del (NULL , name); +} +static int net__iface_mtu_set (int mtu) {
@@ -191,7 +205,7 @@ net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_str,static void usage (char *name) { -printf ("Usage: %s <0-7>\n" , name); +printf ("Usage: %s <0-9>\n" , name); }int
@@ -243,6 +257,12 @@ main(int argc, char *argv[])case 7 :return net__route_v6_add_gw ("2001:cafe:babe::" ,48 ,"2001::2" ,600 ); +case 8 : +return net__iface_new ("dummy0815" ,"dummy" ); + +case 9 : +return net__iface_del ("dummy0815" ); +default :printf ("invalid test: %d\n" , test);break ;
Signature · 1 line
2.35.1
[Openvpn-devel] [PATCH applied] Re: networking: implement net_iface_new and net_iface_del APIs
I like the new style much more - thanks (and it's actually quite a few less lines of code - good that we're not paid *cough* by LoC produced).
I have fixed one indent that uncrustify complained about - second line of the net_iface_new() function declaration in networking_iproute2.c (but not in networking_sitnl.c). Your editor fighting the whitespace dragon?
On the actual code change - this is not doing much yet, as t_net.sh isn't even calling it yet... - but calling "networking_testdriver" manually, I see that it creates an interface, and then removes it again, for SITNL builds. For IPROUTE2 builds, the testdriver is not built (and not trivial to do), so I did not test that one, but "it looks correct".
Your patch has been applied to the master branch.
commit c838a9f98fa2d8b6d7b2658e8399bc9d19ec60e0
Author: Antonio Quartulli Date: Thu Apr 7 11:41:46 2022 +0200
networking: implement net_iface_new and net_iface_del APIs
Signed-off-by: Arne Schwabe <[email protected]...>
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]/msg24088.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 4/7 ovpn-dco: introduce linux data-channel offload support
In reply to Antonio QuartulliImplement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.
--- Changes.rst | 7 + README.dco.md | 129 +++ configure.ac | 28 + doc/man-sections/advanced-options.rst | 13 + doc/man-sections/server-options.rst | 6 + src/openvpn/Makefile.am | 2 + src/openvpn/crypto.c | 1 + src/openvpn/dco.c | 607 ++++++++++++++ src/openvpn/dco.h | 305 +++++++ src/openvpn/dco_internal.h | 80 ++ src/openvpn/dco_linux.c | 882 +++++++++++++++++++++ src/openvpn/dco_linux.h | 62 ++ src/openvpn/errlevel.h | 2 + src/openvpn/event.h | 3 + src/openvpn/forward.c | 79 +- src/openvpn/init.c | 172 +++- src/openvpn/init.h | 2 +- src/openvpn/misc.h | 3 +- src/openvpn/mtcp.c | 61 +- src/openvpn/mudp.c | 13 + src/openvpn/multi.c | 227 +++++- src/openvpn/multi.h | 6 +- src/openvpn/networking_sitnl.c | 11 + src/openvpn/openvpn.vcxproj | 4 +- src/openvpn/openvpn.vcxproj.filters | 6 + src/openvpn/options.c | 29 + src/openvpn/options.h | 20 + src/openvpn/ovpn_dco_linux.h | 265 +++++++ src/openvpn/socket.h | 1 + src/openvpn/ssl.c | 80 +- src/openvpn/ssl.h | 7 +- src/openvpn/ssl_common.h | 23 + src/openvpn/ssl_ncp.c | 2 +- src/openvpn/tun.c | 129 ++- src/openvpn/tun.h | 6 +- tests/unit_tests/openvpn/test_networking.c | 3 + 36 files changed, 3116 insertions(+), 160 deletions(-) create mode 100644 README.dco.md create mode 100644 src/openvpn/dco.c create mode 100644 src/openvpn/dco.h create mode 100644 src/openvpn/dco_internal.h create mode 100644 src/openvpn/dco_linux.c create mode 100644 src/openvpn/dco_linux.h create mode 100644 src/openvpn/ovpn_dco_linux.h
Changes.rst +7 -0
@@ -69,6 +69,13 @@ Improved ``--mssfix`` and ``--fragment`` calculation account and the resulting size is specified as the total size of the VPN packets including IP and UDP headers. +Data channel offloading with ovpn-dco + 2.6.0+ implements support for data-channel offloading where the data packets + are directly processed and forwarded in kernel space thanks to the ovpn-dco + kernel module. The userspace openvpn program acts purely as a control plane + application. + + Deprecated features ------------------- ``inetd`` has been removed
README.dco.md new file +129 -0
129 lines not on this page · raw message
configure.ac +28 -0
@@ -142,6 +142,13 @@ AC_ARG_ENABLE( [enable_small="no"] ) +AC_ARG_ENABLE( + [dco], + [AS_HELP_STRING([--enable-dco], [enable data channel offload support using ovpn-dco kernel module @<:@default=no@:>@])], + , + [enable_dco="no"] +) + AC_ARG_ENABLE( [iproute2], [AS_HELP_STRING([--enable-iproute2], [enable support for iproute2 @<:@default=no@:>@])],
@@ -760,6 +767,26 @@ PKG_CHECK_MODULES( [] ) + + +if test "$enable_dco" = "yes"; then +dnl +dnl Include generic netlink library used to talk to ovpn-dco +dnl + + PKG_CHECK_MODULES([LIBNL_GENL], + [libnl-genl-3.0 >= 3.2.29], + [have_libnl="yes"], + [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] + ) + + CFLAGS="${CFLAGS} ${LIBNL_GENL_CFLAGS}" + LIBS="${LIBS} ${LIBNL_GENL_LIBS}" + + AC_DEFINE(ENABLE_DCO, 1, [Enable shared data channel offload]) + AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) +fi + if test "${with_crypto_library}" = "openssl"; then AC_ARG_VAR([OPENSSL_CFLAGS], [C compiler flags for OpenSSL]) AC_ARG_VAR([OPENSSL_LIBS], [linker flags for OpenSSL])
@@ -1196,6 +1223,7 @@ fi AM_CONDITIONAL([HAVE_SITNL], [false]) if test "${enable_iproute2}" = "yes"; then + test "${enable_dco}" = "yes" && AC_MSG_ERROR([iproute2 support cannot be enabled when using DCO]) test -z "${IPROUTE}" && AC_MSG_ERROR([ip utility is required but missing]) AC_DEFINE([ENABLE_IPROUTE], [1], [enable iproute2 support]) else if test "${have_sitnl}" = "yes"; then
doc/man-sections/advanced-options.rst +13 -0
@@ -91,3 +91,16 @@ used when debugging or testing out special usage scenarios. *(Linux only)* Set the TX queue length on the TUN/TAP interface. Currently defaults to operating system default. +--disable-dco + Disables the opportunistic use the data channel offloading if available. + Without this option, OpenVPN will opportunistically use DCO mode if + the config options and the running kernel supports using DCO. + + Data channel offload currently requires data-ciphers to only contain + AEAD ciphers (AES-GCM and Chacha20-Poly1305) and Linux with the + ovpn-dco module. + + Note that some options have no effect or not available when + DCO mode is enabled. + + A platforms that do not support DCO ``disable-dco`` has no effect.
doc/man-sections/server-options.rst +6 -0
@@ -321,6 +321,12 @@ fast hardware. SSL/TLS authentication must be used in this mode. from the kernel to OpenVPN. Once in OpenVPN, the ``--iroute`` directive routes to the specific client. + When using DCO, the extra ``--route`` directive is required only if the + expected behaviour is to route the traffic for a specific network to the VPN + interface also when the responsible client is not connected (traffic + will then be dropped). In the other cases the ``--iroute`` directive is + enough for DCO to fully configure the routing table. + This option must be specified either in a client instance config file using ``--client-config-dir`` or dynamically generated using a ``--client-connect`` script.
src/openvpn/Makefile.am +2 -0
@@ -53,6 +53,8 @@ openvpn_SOURCES = \ crypto.c crypto.h crypto_backend.h \ crypto_openssl.c crypto_openssl.h \ crypto_mbedtls.c crypto_mbedtls.h \ + dco.c dco.h dco_internal.h \ + dco_linux.c dco_linux.h \ dhcp.c dhcp.h \ dns.c dns.h \ env_set.c env_set.h \
src/openvpn/crypto.c +1 -0
@@ -845,6 +845,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, cipher_kt_iv_size(kt->cipher));warn_insecure_key_type (ciphername); } +if (md_defined (kt->digest)) { ctx->hmac =hmac_ctx_new ();
src/openvpn/dco.c new file +607 -0
607 lines not on this page · raw message
src/openvpn/dco.h new file +305 -0
305 lines not on this page · raw message
src/openvpn/dco_internal.h new file +80 -0
80 lines not on this page · raw message
src/openvpn/dco_linux.c new file +882 -0
882 lines not on this page · raw message
src/openvpn/dco_linux.h new file +62 -0
62 lines not on this page · raw message
src/openvpn/errlevel.h +2 -0
@@ -91,6 +91,7 @@#define D_OSBUF LOGLEV(3, 43, 0)/* show socket/tun/tap buffer sizes */ #define D_PS_PROXY LOGLEV(3, 44, 0)/* messages related to --port-share option */ #define D_IFCONFIG LOGLEV(3, 0, 0)/* show ifconfig info (don't mute) */ +#define D_DCO LOGLEV(3, 0, 0)/* show DCO related messages */ #define D_SHOW_PARMS LOGLEV(4, 50, 0)/* show all parameters on program initiation */ #define D_SHOW_OCC LOGLEV(4, 51, 0)/* show options compatibility string */
@@ -114,6 +115,7 @@#define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG)/* show TAP-Windows driver debug info */ #define D_CLIENT_NAT LOGLEV(6, 69, M_DEBUG)/* show client NAT debug info */ #define D_XKEY LOGLEV(6, 69, M_DEBUG)/* show xkey-provider debug info */ +#define D_DCO_DEBUG LOGLEV(6, 69, M_DEBUG)/* show DCO related lowlevel debug messages */ #define D_SHOW_KEYS LOGLEV(7, 70, M_DEBUG)/* show data channel encryption keys */ #define D_SHOW_KEY_SOURCE LOGLEV(7, 70, M_DEBUG)/* show data channel key source entropy */
src/openvpn/event.h +3 -0
@@ -72,6 +72,9 @@#define MANAGEMENT_WRITE (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT))#define FILE_SHIFT 8#define FILE_CLOSED (1 << (FILE_SHIFT + READ_SHIFT)) +#define DCO_SHIFT 10 +#define DCO_READ (1 << (DCO_SHIFT + READ_SHIFT)) +#define DCO_WRITE (1 << (DCO_SHIFT + WRITE_SHIFT))/* * Initialization flags passed to event_set_init
src/openvpn/forward.c +75 -4
131 lines not on this page · raw message
src/openvpn/init.c +136 -36
306 lines not on this page · raw message
src/openvpn/init.h +1 -1
@@ -30,7 +30,7 @@* Baseline maximum number of events * to wait for. */ -#define BASE_N_EVENTS 4 +#define BASE_N_EVENTS 5void context_clear (struct context *c);
src/openvpn/misc.h +2 -1
@@ -32,10 +32,11 @@#include "buffer.h" #include "platform.h" +#include <stddef.h> +/* forward declarations */ struct plugin_list ; -/* Set standard file descriptors to /dev/null */ void set_std_files_to_null (bool stdin_only);
src/openvpn/mtcp.c +47 -14
120 lines not on this page · raw message
src/openvpn/mudp.c +13 -0
@@ -227,6 +227,19 @@ multi_process_io_udp(struct multi_context *m)multi_process_file_closed (m, mpp_flags); }#endif +#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) + else if (status & DCO_READ) + { +if (!IS_SIG (&m->top)) + { +bool ret = true; +while (ret) + { + ret =multi_process_incoming_dco (m); + } + } + } +#endif }/*
src/openvpn/multi.c +184 -43
214 lines not on this page · raw message
src/openvpn/ovpn_dco_linux.h new file +265 -0
265 lines not on this page · raw message
src/openvpn/ssl.c +58 -22
80 lines not on this page · raw message
src/openvpn/tun.c +96 -33
129 lines not on this page · raw message
tests/unit_tests/openvpn/test_networking.c +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.35.1
Part of the diff is not shown here. View the raw message.
Re: [Openvpn-devel] [PATCH 4/7] ovpn-dco: introduce linux data-channel offload support
Documentation review:
Quoted 34 lines
Antonio Quartulli <[email protected]...> hat am 02.04.2022 09:08 geschrieben:
Changes.rst +7
-0@@ -69,6 +69,13 @@ Improved ``--mssfix`` and ``--fragment`` calculation account and the resulting size is specified as the total size of the VPN packets including IP and UDP headers. +Data channel offloading with ovpn-dco + 2.6.0+ implements support for data-channel offloading where the data packets + are directly processed and forwarded in kernel space thanks to the ovpn-dco + kernel module. The userspace openvpn program acts purely as a control plane + application. + + Deprecated features ------------------- ``inetd`` has been removedREADME.dco.md new file +9
-0@@ -0,0 +1,129 @@ +OpenVPN data channel offload +============================ +2.6.0+ implements support for data-channel offloading where the data packets +are directly processed and forwarded in kernel space thanks to the ovpn-dco +kernel module. The userspace openvpn program acts purely as a control plane +application. + + +Overview of current release
README.dco.md line 19
Quoted 10 lines
README.dco.md new file +10
-0+--------------------------- +- See the "Limitations by design" and "Current limitations" sections for + features that are not and/or will not be supported by OpenVPN + ovpn-dco + + +Getting started (Linux) +----------------------- + +- Use a recent Linux kernel. Ubuntu 20.04 (Linux 5.4.0) and Ubuntu 20.10 + (Linux 5.8.0) are known to work with ovpn-dco.
Remove Ubuntu 20.10 here or replaced by a more current release. It is just not relevant anymore.
[...]
README.dco.md line 68
Quoted 8 lines
README.dco.md new file +8
-0+DCO and P2P mode +---------------- +DCO is also available when running OpenVPN in P2P mode without --pull/--client option. +The P2P mode is useful for scenarios when the OpenVPN tunnel should not interfere with +overall routing and behave more like a "dumb" tunnel like GRE. + +However, DCO requires DATA_V2 to be enabled this requires P2P with NCP capability, which +is only available in OpenVPN 2.6 and later.
However, DCO requires DATA_V2 to be enabled. This requires P2P with NCP capability, which is only available in OpenVPN 2.6 and later.
[...]
README.dco.md line 84
Quoted 7 lines
README.dco.md new file +7
-0+Routing with ovpn-dco +--------------------- +The ovpn-dco kernel module implements a more transparent approach to +configuring routes to clients (aka 'iroutes') and consults the kernel +routing tables for forwarding decisions. + +- Each client has an IPv4 VPN IP and/or an IPv6 assigned to it.
- Each client has an IPv4 and/or an IPv6 VPN IP assigned to it.
README.dco.md line 94
Quoted 10 lines
README.dco.md new file +10
-0+- Additional IP ranges can be routed to a client by adding a route with + a client VPN IP as the gateway/nexthop (i.e. ip route add a.b.c.d/24 via $VPNIP). +- Due to the point above, there is no real need to add a companion --route for + each --iroute directive, unless you want to blackhole traffic when the specific + client is not connected. +- No internal routing is available. If you need truly internal routes, this can be + achieved either with filtering using `iptables` or using `ip rule`. +- client-to-client behaviour, as implemented in userspace, does not exist: packets + are always sent up to the tunnel interface and then back in to be routed to the + destination peer.
I have no idea what "back in" means in this sentence? Is this just me or is there something missing?
README.dco.md line 103
Quoted 7 lines
README.dco.md new file +7
-0+Limitations by design +---------------------- +- Layer 3 (dev tun only) +- only AEAD ciphers are supported and currently only + Chacha20-Poly1305 and AES-GCM-128/192/256 +- no support for compression or compression framing + - see also `--compress migrate` option to move to a setup with compression
"without compression"
README.dco.md line 104
Quoted 1 line
README.dco.md new file +1
-0+- various features not implemented since have better replacements
- various features are not implemented since they have better replacements
README.dco.md line 108
Quoted 4 lines
README.dco.md new file +4
-0+ - --shaper, use tc instead + - packet manipulation, use nftables/iptables instead +- OpenVPN 2.4.0 is the minimum peer version. + - older version are missing support for the AEAD ciphers
"versions"
README.dco.md line 111
Quoted 3 lines
README.dco.md new file +3
-0+- 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"
Quoted 4 lines
configure.ac +0
-0
[...]
Quoted 6 lines
configure.ac +2
-0@@ -760,6 +767,26 @@ PKG_CHECK_MODULES( [] ) + +
configure.ac PKG_CHECK_MODULES( · line 781
Quoted 10 lines
configure.ac +10
-0+if test "$enable_dco" = "yes"; then +dnl +dnl Include generic netlink library used to talk to ovpn-dco +dnl + + PKG_CHECK_MODULES([LIBNL_GENL], + [libnl-genl-3.0 >= 3.2.29], + [have_libnl="yes"], + [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] + )
3.2.29 or 3.4.0 ?
[...]
doc/man-sections/advanced-options.rst used when debugging or testing out special usage scenarios. · line 95
Quoted 10 lines
doc/man-sections/advanced-options.rst +2
-0@@ -91,3 +91,16 @@ used when debugging or testing out special usage scenarios. *(Linux only)* Set the TX queue length on the TUN/TAP interface. Currently defaults to operating system default. +--disable-dco + Disables the opportunistic use the data channel offloading if available.
"of the data channel offloading"
doc/man-sections/advanced-options.rst used when debugging or testing out special usage scenarios. · line 104
Quoted 9 lines
doc/man-sections/advanced-options.rst +9
-0+ Without this option, OpenVPN will opportunistically use DCO mode if + the config options and the running kernel supports using DCO. + + Data channel offload currently requires data-ciphers to only contain + AEAD ciphers (AES-GCM and Chacha20-Poly1305) and Linux with the + ovpn-dco module. + + Note that some options have no effect or not available when + DCO mode is enabled.
"are not available" ? Still not a great sentence but at least better grammatically.
doc/man-sections/advanced-options.rst used when debugging or testing out special usage scenarios. · line 106
Quoted 2 lines
doc/man-sections/advanced-options.rst +2
-0+ + A platforms that do not support DCO ``disable-dco`` has no effect.
"On platforms" ?
doc/man-sections/server-options.rst fast hardware. SSL/TLS authentication must be used in this mode. · line 328
Quoted 13 lines
doc/man-sections/server-options.rst +5
-0@@ -321,6 +321,12 @@ fast hardware. SSL/TLS authentication must be used in this mode. from the kernel to OpenVPN. Once in OpenVPN, the ``--iroute`` directive routes to the specific client. + When using DCO, the extra ``--route`` directive is required only if the + expected behaviour is to route the traffic for a specific network to the VPN + interface also when the responsible client is not connected (traffic + will then be dropped). In the other cases the ``--iroute`` directive is + enough for DCO to fully configure the routing table.
I think this works better if you reorder it:
However, when using DCO, the ``--iroute`` directive is usually enough for DCO to fully configure the routing table. The extra ``--route`` directive is required only if the expected behaviour is to route the traffic for a specific network to the VPN interface also when the responsible client is not connected (traffic will then be dropped).
This puts the important information first.
doc/man-sections/server-options.rst fast hardware. SSL/TLS authentication must be used in this mode.
Quoted 5 lines
doc/man-sections/server-options.rst +5
-0+#if defined(ENABLE_DCO) + +/** + * Check whether the options struct has any option that is not supported by + * our current dco implementation. If so it print a warning at warning level
remove "it"
Quoted 4 lines
+ * for the first conflicting option found and return true.
+ *
+ * @param msglevel the msg level to use to print the warnings
+ * @param o the optiions struct that hold the options
"options"
Quoted 3 lines
+ * @return true if a conflict was detected, false otherwise
+ */
+booldco_check_option_conflict(int msglevel, const struct options *o);
[...]
doc/man-sections/server-options.rst
Quoted 3 lines
doc/man-sections/server-options.rst +3
-0+ +/** + * Possibly swaps or wipes keys from DCO
"swap or wipe" (to be consistent with all other functions"
Quoted 6 lines
+ * @param dco DCO device context
+ * @param multi TLS multi instance
+ */doc/man-sections/server-options.rst +3
-0+void dco_update_keys(dco_context_t *dco, struct tls_multi *multi); + +/**
doc/man-sections/server-options.rst
Quoted 10 lines
doc/man-sections/server-options.rst +10
-0+ * Check whether ovpn-dco is available on this platform (i.e. kernel support is + * there) + * + * @param msglevel level to print messages to + * @return true if ovpn-dco is available, false otherwise + */ +bool dco_available(int msglevel); + +/** + * Installs a DCO in the main event loop
"Install"
[...]
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH 4/7] ovpn-dco: introduce linux data-channel offload support
Hi,
Quoted 1 line · Frank Lichtenheld
Documentation review:
Thanks for the feedback, will integrate it appropriately.
Regards,
Signature · 1 line
Antonio Quartulli
PATCH v2 4/7 ovpn-dco: introduce linux data-channel offload support
In reply to Antonio QuartulliImplement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.
---
Changes from v1:
* uncrustified code. Note that uncrustify wanted to change way more code in our repo, therefore I had to dig into the proposed changes and pick only those related to this patch. For this reason I may have missed something.
Changes.rst | 7 + README.dco.md | 123 +++ configure.ac | 28 + doc/man-sections/advanced-options.rst | 13 + doc/man-sections/server-options.rst | 6 + src/openvpn/Makefile.am | 2 + src/openvpn/crypto.c | 1 + src/openvpn/dco.c | 612 ++++++++++++++ src/openvpn/dco.h | 305 +++++++ src/openvpn/dco_internal.h | 83 ++ src/openvpn/dco_linux.c | 913 +++++++++++++++++++++ src/openvpn/dco_linux.h | 62 ++ src/openvpn/errlevel.h | 2 + src/openvpn/event.h | 3 + src/openvpn/forward.c | 79 +- src/openvpn/init.c | 173 +++- src/openvpn/init.h | 2 +- src/openvpn/misc.h | 3 +- src/openvpn/mtcp.c | 61 +- src/openvpn/mudp.c | 13 + src/openvpn/multi.c | 227 ++++- src/openvpn/multi.h | 6 +- src/openvpn/networking_sitnl.c | 11 + src/openvpn/openvpn.vcxproj | 4 +- src/openvpn/openvpn.vcxproj.filters | 6 + src/openvpn/options.c | 29 + src/openvpn/options.h | 20 + src/openvpn/ovpn_dco_linux.h | 265 ++++++ src/openvpn/socket.h | 1 + src/openvpn/ssl.c | 80 +- src/openvpn/ssl.h | 7 +- src/openvpn/ssl_common.h | 23 + src/openvpn/ssl_ncp.c | 2 +- src/openvpn/tun.c | 129 ++- src/openvpn/tun.h | 6 +- tests/unit_tests/openvpn/test_networking.c | 3 + 36 files changed, 3150 insertions(+), 160 deletions(-) create mode 100644 README.dco.md create mode 100644 src/openvpn/dco.c create mode 100644 src/openvpn/dco.h create mode 100644 src/openvpn/dco_internal.h create mode 100644 src/openvpn/dco_linux.c create mode 100644 src/openvpn/dco_linux.h create mode 100644 src/openvpn/ovpn_dco_linux.h
Changes.rst +7 -0
@@ -69,6 +69,13 @@ Improved ``--mssfix`` and ``--fragment`` calculation account and the resulting size is specified as the total size of the VPN packets including IP and UDP headers. +Data channel offloading with ovpn-dco + 2.6.0+ implements support for data-channel offloading where the data packets + are directly processed and forwarded in kernel space thanks to the ovpn-dco + kernel module. The userspace openvpn program acts purely as a control plane + application. + + Deprecated features ------------------- ``inetd`` has been removed
README.dco.md new file +123 -0
123 lines not on this page · raw message
configure.ac +28 -0
@@ -142,6 +142,13 @@ AC_ARG_ENABLE( [enable_small="no"] ) +AC_ARG_ENABLE( + [dco], + [AS_HELP_STRING([--enable-dco], [enable data channel offload support using ovpn-dco kernel module @<:@default=no@:>@])], + , + [enable_dco="no"] +) + AC_ARG_ENABLE( [iproute2], [AS_HELP_STRING([--enable-iproute2], [enable support for iproute2 @<:@default=no@:>@])],
@@ -760,6 +767,26 @@ PKG_CHECK_MODULES( [] ) + + +if test "$enable_dco" = "yes"; then +dnl +dnl Include generic netlink library used to talk to ovpn-dco +dnl + + PKG_CHECK_MODULES([LIBNL_GENL], + [libnl-genl-3.0 >= 3.4.0], + [have_libnl="yes"], + [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] + ) + + CFLAGS="${CFLAGS} ${LIBNL_GENL_CFLAGS}" + LIBS="${LIBS} ${LIBNL_GENL_LIBS}" + + AC_DEFINE(ENABLE_DCO, 1, [Enable shared data channel offload]) + AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) +fi + if test "${with_crypto_library}" = "openssl"; then AC_ARG_VAR([OPENSSL_CFLAGS], [C compiler flags for OpenSSL]) AC_ARG_VAR([OPENSSL_LIBS], [linker flags for OpenSSL])
@@ -1196,6 +1223,7 @@ fi AM_CONDITIONAL([HAVE_SITNL], [false]) if test "${enable_iproute2}" = "yes"; then + test "${enable_dco}" = "yes" && AC_MSG_ERROR([iproute2 support cannot be enabled when using DCO]) test -z "${IPROUTE}" && AC_MSG_ERROR([ip utility is required but missing]) AC_DEFINE([ENABLE_IPROUTE], [1], [enable iproute2 support]) else if test "${have_sitnl}" = "yes"; then
doc/man-sections/advanced-options.rst +13 -0
@@ -91,3 +91,16 @@ used when debugging or testing out special usage scenarios. *(Linux only)* Set the TX queue length on the TUN/TAP interface. Currently defaults to operating system default. +--disable-dco + Disables the opportunistic use of the data channel offloading if available. + Without this option, OpenVPN will opportunistically use DCO mode if + the config options and the running kernel supports using DCO. + + Data channel offload currently requires data-ciphers to only contain + AEAD ciphers (AES-GCM and Chacha20-Poly1305) and Linux with the + ovpn-dco module. + + Note that some options have no effect or cannot be used when DCO mode + is enabled. + + On platforms that do not support DCO ``disable-dco`` has no effect.
doc/man-sections/server-options.rst +6 -0
@@ -321,6 +321,12 @@ fast hardware. SSL/TLS authentication must be used in this mode. from the kernel to OpenVPN. Once in OpenVPN, the ``--iroute`` directive routes to the specific client. + However, when using DCO, the ``--iroute`` directive is usually enough + for DCO to fully configure the routing table. The extra ``--route`` + directive is required only if the expected behaviour is to route the + traffic for a specific network to the VPN interface also when the + responsible client is not connected (traffic will then be dropped). + This option must be specified either in a client instance config file using ``--client-config-dir`` or dynamically generated using a ``--client-connect`` script.
src/openvpn/Makefile.am +2 -0
@@ -53,6 +53,8 @@ openvpn_SOURCES = \ crypto.c crypto.h crypto_backend.h \ crypto_openssl.c crypto_openssl.h \ crypto_mbedtls.c crypto_mbedtls.h \ + dco.c dco.h dco_internal.h \ + dco_linux.c dco_linux.h \ dhcp.c dhcp.h \ dns.c dns.h \ env_set.c env_set.h \
src/openvpn/crypto.c +1 -0
@@ -845,6 +845,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, cipher_kt_iv_size(kt->cipher));warn_insecure_key_type (ciphername); } +if (md_defined (kt->digest)) { ctx->hmac =hmac_ctx_new ();
src/openvpn/dco.c new file +612 -0
612 lines not on this page · raw message
src/openvpn/dco.h new file +305 -0
305 lines not on this page · raw message
src/openvpn/dco_internal.h new file +83 -0
83 lines not on this page · raw message
src/openvpn/dco_linux.c new file +913 -0
913 lines not on this page · raw message
src/openvpn/dco_linux.h new file +62 -0
62 lines not on this page · raw message
src/openvpn/errlevel.h +2 -0
@@ -91,6 +91,7 @@#define D_OSBUF LOGLEV(3, 43, 0)/* show socket/tun/tap buffer sizes */ #define D_PS_PROXY LOGLEV(3, 44, 0)/* messages related to --port-share option */ #define D_IFCONFIG LOGLEV(3, 0, 0)/* show ifconfig info (don't mute) */ +#define D_DCO LOGLEV(3, 0, 0)/* show DCO related messages */ #define D_SHOW_PARMS LOGLEV(4, 50, 0)/* show all parameters on program initiation */ #define D_SHOW_OCC LOGLEV(4, 51, 0)/* show options compatibility string */
@@ -114,6 +115,7 @@#define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG)/* show TAP-Windows driver debug info */ #define D_CLIENT_NAT LOGLEV(6, 69, M_DEBUG)/* show client NAT debug info */ #define D_XKEY LOGLEV(6, 69, M_DEBUG)/* show xkey-provider debug info */ +#define D_DCO_DEBUG LOGLEV(6, 69, M_DEBUG)/* show DCO related lowlevel debug messages */ #define D_SHOW_KEYS LOGLEV(7, 70, M_DEBUG)/* show data channel encryption keys */ #define D_SHOW_KEY_SOURCE LOGLEV(7, 70, M_DEBUG)/* show data channel key source entropy */
src/openvpn/event.h +3 -0
@@ -72,6 +72,9 @@#define MANAGEMENT_WRITE (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT))#define FILE_SHIFT 8#define FILE_CLOSED (1 << (FILE_SHIFT + READ_SHIFT)) +#define DCO_SHIFT 10 +#define DCO_READ (1 << (DCO_SHIFT + READ_SHIFT)) +#define DCO_WRITE (1 << (DCO_SHIFT + WRITE_SHIFT))/* * Initialization flags passed to event_set_init
src/openvpn/forward.c +75 -4
131 lines not on this page · raw message
src/openvpn/init.c +137 -36
307 lines not on this page · raw message
src/openvpn/init.h +1 -1
@@ -30,7 +30,7 @@* Baseline maximum number of events * to wait for. */ -#define BASE_N_EVENTS 4 +#define BASE_N_EVENTS 5void context_clear (struct context *c);
src/openvpn/misc.h +2 -1
@@ -32,10 +32,11 @@#include "buffer.h" #include "platform.h" +#include <stddef.h> +/* forward declarations */ struct plugin_list ; -/* Set standard file descriptors to /dev/null */ void set_std_files_to_null (bool stdin_only);
src/openvpn/mtcp.c +47 -14
120 lines not on this page · raw message
src/openvpn/mudp.c +13 -0
@@ -227,6 +227,19 @@ multi_process_io_udp(struct multi_context *m)multi_process_file_closed (m, mpp_flags); }#endif +#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) + else if (status & DCO_READ) + { +if (!IS_SIG (&m->top)) + { +bool ret = true; +while (ret) + { + ret =multi_process_incoming_dco (m); + } + } + } +#endif }/*
src/openvpn/multi.c +184 -43
180 lines not on this page · raw message
src/openvpn/ovpn_dco_linux.h new file +265 -0
265 lines not on this page · raw message
src/openvpn/ssl.c +58 -22
80 lines not on this page · raw message
src/openvpn/tun.c +96 -33
129 lines not on this page · raw message
tests/unit_tests/openvpn/test_networking.c +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.35.1
Part of the diff is not shown here. View the raw message.
Re: [Openvpn-devel] [PATCH v2 4/7] ovpn-dco: introduce linux data-channel offload support
Honestly still not sure one would start reviewing the actual code but here are at least a few minor things I noticed while browsing through it:
Quoted 8 lines
Antonio Quartulli <[email protected]...> hat am 11.04.2022 15:35 geschrieben:
Implement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>
Quoted 7 lines
---
Changes from v1:
* uncrustified code. Note that uncrustify wanted to change way more code in our repo, therefore I had to dig into the proposed changes and pick only those related to this patch. For this reason I may have missed something.
You also incorporated my review suggestions.
[...]
README.dco.md
Quoted 5 lines
README.dco.md new file +0
-0
[...}
README.dco.md line 68
Quoted 8 lines
README.dco.md new file +8
-0+DCO and P2P mode +---------------- +DCO is also available when running OpenVPN in P2P mode without --pull/--client option. +The P2P mode is useful for scenarios when the OpenVPN tunnel should not interfere with +overall routing and behave more like a "dumb" tunnel like GRE. + +However, DCO requires DATA_V2 to be enabled. This requires P2P with NCP capability, which +is only available in OpenVPN 2.6 and later.
Changes.rst doesn't mention this change, should it? Should we mention here what "NCP" stands for?
Quoted 6 lines
README.dco.md new file +6
-0+OpenVPN prints a diagnostic message for the P2P NCP result when running in P2P mode: + + P2P mode NCP negotiation result: TLS_export=1, DATA_v2=1, peer-id 9484735, cipher=AES-256-GCM + +Double check that your have `DATA_v2=1` in your output and a supported AEAD cipher +(AES-XXX-GCM or CHACHA20POLY1305).
[...]
doc/man-sections/advanced-options.rst used when debugging or testing out special usage scenarios. · line 95
Quoted 10 lines
doc/man-sections/advanced-options.rst +2
-0@@ -91,3 +91,16 @@ used when debugging or testing out special usage scenarios. *(Linux only)* Set the TX queue length on the TUN/TAP interface. Currently defaults to operating system default. +--disable-dco + Disables the opportunistic use of the data channel offloading if available.
Nitpick: would remove "the" in "the data channel offloading".
[...]
src/openvpn/crypto.c init_key_ctx(struct key_ctx *ctx, const struct key *key, · line 848
Quoted 9 lines
src/openvpn/crypto.c +1
-0@@ -845,6 +845,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, cipher_kt_iv_size(kt->cipher));warn_insecure_key_type (ciphername); } +
Spurious uncrustify change?
Quoted 8 lines
src/openvpn/crypto.c +0
-0if (md_defined (kt->digest)) { ctx->hmac =hmac_ctx_new ();src/openvpn/dco.c new file +0
-0
[...]
Quoted 5 lines
+/**
+ * Find a usable key that is not the primary (i.e. the secondary key)
+ *
+ * @param multi The TLS struct to retrieve keys from
+ * @param primary The primary key that should be skipped doring the scan
"during"
[...]
Quoted 8 lines
src/openvpn/dco.c new file +8
-0+static bool +dco_check_option_conflict_ce (const struct connection_entry *ce,int msglevel) +{ +if (ce->fragment) + { +msg (msglevel,"Note: --fragment disables data channel offload." ); +return true; + }
src/openvpn/dco.c line 423
Quoted 10 lines
src/openvpn/dco.c new file +10
-0+ +if (ce->http_proxy_options) + { +msg (msglevel,"Note: --http-proxy disables data channel offload." ); +return true; + } + +if (ce->socks_proxy_server) + { +msg (msglevel,"Note --socks-proxy disable data channel offload." );
"Note: --socks-proxy disables data channel offload."
Missing ':' after "Note" and missing 's' in "disables".
Quoted 5 lines
src/openvpn/dco.c new file +5
-0+return true; + } + +return false; +}
[...]
Quoted 5 lines
src/openvpn/dco_linux.c new file +0
-0
[...]
Quoted 8 lines
+/**
+ * @brief resolves the netlink ID for ovpn-dco
+ *
+ * This function queries the kernel via a netlink socket
+ * whether the ovpn-dco netlink namespace is available
+ *
+ * This function can be used to determine if the kernel
+ * support DCO offloading.
"supports"
Quoted 5 lines
+ *
+ * @return ID on success, negative error code on error
+ */src/openvpn/dco_linux.c new file +2
-0+static int +resolve_ovpn_netlink_id (int msglevel)
[...]
Quoted 7 lines
+/**
+ * Send a preprared netlink message and registers cb as callback if non-null.
+ *
+ * The method will also freenl_msg+ * @param dco The dco context to use + * @param nl_msg the message to use + * @param cb An optional callback if the caller expects an answers\
"an answer", also spurious '\'
Quoted 7 lines
+ * @param prefix A prefix to report in the error message to give the user context
+ * @return status of sending the message
+ */src/openvpn/dco_linux.c new file +4
-0+static int +ovpn_nl_msg_send (dco_context_t *dco,struct nl_msg *nl_msg,ovpn_nl_cb cb, +const char *prefix) +{
src/openvpn/dco_linux.c line 186
Quoted 10 lines
src/openvpn/dco_linux.c new file +10
-0+ dco->status =1 ; + +if (cb) + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM , cb, dco); + } +else + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM ,NULL , dco); + }
Is there an actual difference to just writing
nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, cb, dco);
without the whole if/else?
Quoted 12 lines
src/openvpn/dco_linux.c new file +12
-0+nl_send_auto (dco->nl_sock, nl_msg); + +while (dco->status ==1 ) + { +ovpn_nl_recvmsgs (dco, prefix); + } + +if (dco->status <0 ) + { +msg (M_INFO ,"%s: failed to send netlink message: %s (%d)" , + prefix,strerror (-dco->status), dco->status); + }
src/openvpn/dco_linux.c line 209
Quoted 10 lines
src/openvpn/dco_linux.c new file +10
-0+ +return dco->status; +} + +struct sockaddr * +mapped_v4_to_v6 (struct sockaddr *sock,struct gc_arena *gc) +{ +struct sockaddr_in6 *sock6 = ((struct sockaddr_in6 *)sock); +if (sock->sa_family ==AF_INET6 + &&memcmp (&sock6->sin6_addr,"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" ,12 )==0 )
magic constant?
src/openvpn/dco_linux.c line 220
Quoted 11 lines
src/openvpn/dco_linux.c new file +11
-0+ { + +struct sockaddr_in *sock4; + ALLOC_OBJ_CLEAR_GC(sock4, struct sockaddr_in, gc); +memcpy (&sock4->sin_addr, sock6->sin6_addr.s6_addr +12 ,4 ); + sock4->sin_port = sock6->sin6_port; + sock4->sin_family =AF_INET ; +return (struct sockaddr *) sock4; + } +return sock; +}
[...]
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH v2 4/7] ovpn-dco: introduce linux data-channel offload support
Hi,
Quoted 2 lines · Frank Lichtenheld
Honestly still not sure one would start reviewing the actual code but here are at least a few minor things I noticed while browsing through it:
Well, now's the time for the code review - I have *tested* it in client and server scenarios, but not actually looked into the code much further than "uncrustify will not like this" :-)
Plan to do a more in-depth code review after next weekend.
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]...Re: [Openvpn-devel] [PATCH v2 4/7] ovpn-dco: introduce linux data-channel offload support
In reply to Frank LichtenheldHi,
reading through Frank's review bits, I found something...
Quoted 8 lines · Frank Lichtenheld
src/openvpn/dco_linux.c line 209
Quoted 6 lines
src/openvpn/dco_linux.c new file +6
-0+struct sockaddr * +mapped_v4_to_v6 (struct sockaddr *sock,struct gc_arena *gc) +{ +struct sockaddr_in6 *sock6 = ((struct sockaddr_in6 *)sock); +if (sock->sa_family ==AF_INET6 + &&memcmp (&sock6->sin6_addr,"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" ,12 )==0 )magic constant?
Yes. This should use IN6_IS_ADDR_V4MAPPED(), as we already do in other places (= we know that macro is universally available and works with our constructs).
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]...Re: [Openvpn-devel] [PATCH v2 4/7] ovpn-dco: introduce linux data-channel offload support
In reply to Frank LichtenheldHi,
Quoted 13 lines · Frank Lichtenheld
Honestly still not sure one would start reviewing the actual code but here are at least a few minor things I noticed while browsing through it:
Quoted 10 lines
Antonio Quartulli <[email protected]...> hat am 11.04.2022 15:35 geschrieben:
Implement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
Quoted 7 lines
Quoted 5 lines
Changes from v1:
* uncrustified code. Note that uncrustify wanted to change way more code in our repo, therefore I had to dig into the proposed changes and pick only those related to this patch. For this reason I may have missed something.You also incorporated my review suggestions.
Right - sorry!
Quoted 8 lines
[...]
README.dco.md
Quoted 5 lines
README.dco.md new file +0
-0[...}
Quoted 10 lines
README.dco.md line 68
Quoted 8 lines
README.dco.md new file +8
-0+DCO and P2P mode +---------------- +DCO is also available when running OpenVPN in P2P mode without --pull/--client option. +The P2P mode is useful for scenarios when the OpenVPN tunnel should not interfere with +overall routing and behave more like a "dumb" tunnel like GRE. + +However, DCO requires DATA_V2 to be enabled. This requires P2P with NCP capability, which +is only available in OpenVPN 2.6 and later.
Changes.rstdoesn't mention this change, should it?
how does this sound:
Note that DCO will use DATA_V2 packets in P2P mode, therefore, this implies that peers must be running 2.6.0+ in order to have P2P-NCP which brings DATA_V2 packet support.
Quoted 1 line
Should we mention here what "NCP" stands for?
to be honest I barely know what it stands for :-D I just know it is "cipher negotiation", but the actual definition I think is expected to be found elsewhere. no?
Quoted 16 lines
Quoted 7 lines
README.dco.md new file +6
-0+OpenVPN prints a diagnostic message for the P2P NCP result when running in P2P mode: + + P2P mode NCP negotiation result: TLS_export=1, DATA_v2=1, peer-id 9484735, cipher=AES-256-GCM + +Double check that your have `DATA_v2=1` in your output and a supported AEAD cipher +(AES-XXX-GCM or CHACHA20POLY1305).[...]
Quoted 8 lines
doc/man-sections/advanced-options.rst +0
-0@@ -91,3 +91,16 @@ used when debugging or testing out special usage scenarios. *(Linux only)* Set the TX queue length on the TUN/TAP interface. Currently defaults to operating system default.
Quoted 4 lines
doc/man-sections/advanced-options.rst used when debugging or testing out special usage scenarios. · line 95
Quoted 2 lines
doc/man-sections/advanced-options.rst +2
-0+--disable-dco + Disables the opportunistic use of the data channel offloading if available.Nitpick: would remove "the" in "the data channel offloading".
right
Quoted 13 lines
[...]
src/openvpn/crypto.c init_key_ctx(struct key_ctx *ctx, const struct key *key, · line 848
Quoted 9 lines
src/openvpn/crypto.c +1
-0@@ -845,6 +845,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, cipher_kt_iv_size(kt->cipher));warn_insecure_key_type (ciphername); } +Spurious uncrustify change?
removed
Quoted 10 lines
Quoted 9 lines
src/openvpn/crypto.c +0
-0if (md_defined (kt->digest)) { ctx->hmac =hmac_ctx_new ();src/openvpn/dco.c new file +0
-0[...]
Quoted 7 lines
Quoted 5 lines
+/**
+ * Find a usable key that is not the primary (i.e. the secondary key)
+ *
+ * @param multi The TLS struct to retrieve keys from
+ * @param primary The primary key that should be skipped doring the scan"during"
I almost managed to have Gert in the comment :-D
Quoted 14 lines
[...]
Quoted 12 lines
src/openvpn/dco.c new file +12
-0+static bool +dco_check_option_conflict_ce (const struct connection_entry *ce,int msglevel) +{ +if (ce->fragment) + { +msg (msglevel,"Note: --fragment disables data channel offload." ); +return true; + } + +if (ce->http_proxy_options) + { +msg (msglevel,"Note: --http-proxy disables data channel offload." );
Quoted 8 lines
src/openvpn/dco.c line 423
Quoted 6 lines
src/openvpn/dco.c new file +6
-0+return true; + } + +if (ce->socks_proxy_server) + { +msg (msglevel,"Note --socks-proxy disable data channel offload." );"Note: --socks-proxy disables data channel offload."
right
Quoted 2 lines
Missing ':' after "Note" and missing 's' in "disables".
yup, thanks!
Quoted 22 lines
Quoted 6 lines
src/openvpn/dco.c new file +5
-0+return true; + } + +return false; +}[...]
Quoted 5 lines
src/openvpn/dco_linux.c new file +0
-0[...]
Quoted 8 lines
+/**
+ * @brief resolves the netlink ID for ovpn-dco
+ *
+ * This function queries the kernel via a netlink socket
+ * whether the ovpn-dco netlink namespace is available
+ *
+ * This function can be used to determine if the kernel
+ * support DCO offloading.
Quoted 1 line
"supports"
thanks
Quoted 15 lines
Quoted 6 lines
+ *
+ * @return ID on success, negative error code on error
+ */src/openvpn/dco_linux.c new file +2
-0+static int +resolve_ovpn_netlink_id (int msglevel)[...]
Quoted 7 lines
+/**
+ * Send a preprared netlink message and registers cb as callback if non-null.
+ *
+ * The method will also freenl_msg+ * @param dco The dco context to use + * @param nl_msg the message to use + * @param cb An optional callback if the caller expects an answers\
Quoted 1 line
"an answer", also spurious '\'
thanks
Quoted 21 lines
Quoted 8 lines
+ * @param prefix A prefix to report in the error message to give the user context
+ * @return status of sending the message
+ */src/openvpn/dco_linux.c new file +4
-0+static int +ovpn_nl_msg_send (dco_context_t *dco,struct nl_msg *nl_msg,ovpn_nl_cb cb, +const char *prefix) +{src/openvpn/dco_linux.c line 186
Quoted 10 lines
src/openvpn/dco_linux.c new file +10
-0+ dco->status =1 ; + +if (cb) + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM , cb, dco); + } +else + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM ,NULL , dco); + }Is there an actual difference to just writing
Quoted 3 lines
nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, cb, dco);without the whole if/else?
yeah, this must be the result of older pruning, which left the leaves...but they can now be merged :-)
done!
Quoted 17 lines
Quoted 17 lines
src/openvpn/dco_linux.c new file +16
-0+nl_send_auto (dco->nl_sock, nl_msg); + +while (dco->status ==1 ) + { +ovpn_nl_recvmsgs (dco, prefix); + } + +if (dco->status <0 ) + { +msg (M_INFO ,"%s: failed to send netlink message: %s (%d)" , + prefix,strerror (-dco->status), dco->status); + } + +return dco->status; +} +
Quoted 8 lines
src/openvpn/dco_linux.c line 209
Quoted 6 lines
src/openvpn/dco_linux.c new file +6
-0+struct sockaddr * +mapped_v4_to_v6 (struct sockaddr *sock,struct gc_arena *gc) +{ +struct sockaddr_in6 *sock6 = ((struct sockaddr_in6 *)sock); +if (sock->sa_family ==AF_INET6 + &&memcmp (&sock6->sin6_addr,"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" ,12 )==0 )magic constant?
as Gert pointed out, there is a nice macro for this. using it now.
Quoted 14 lines
Quoted 12 lines
src/openvpn/dco_linux.c new file +11
-0+ { + +struct sockaddr_in *sock4; + ALLOC_OBJ_CLEAR_GC(sock4, struct sockaddr_in, gc); +memcpy (&sock4->sin_addr, sock6->sin6_addr.s6_addr +12 ,4 ); + sock4->sin_port = sock6->sin6_port; + sock4->sin_family =AF_INET ; +return (struct sockaddr *) sock4; + } +return sock; +}[...]
Quoted 1 line
Regards,
Thanks a lot for the review!
Regards,
Quoted 3 lines
--
Frank Lichtenheld
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v2 4/7] ovpn-dco: introduce linux data-channel offload support
Quoted 6 lines
Antonio Quartulli <[email protected]...> hat am 09.05.2022 20:06 geschrieben:
Quoted 4 lines · Frank Lichtenheld
Honestly still not sure one would start reviewing the actual code but here are at least a few minor things I noticed while browsing through it:
Quoted 1 line
Antonio Quartulli <[email protected]...> hat am 11.04.2022 15:35 geschrieben:
[...]
Quoted 18 lines
Quoted 7 lines
[...]
README.dco.md
Quoted 5 lines
README.dco.md new file +0
-0[...}
Quoted 10 lines
README.dco.md line 68
Quoted 8 lines
README.dco.md new file +8
-0+DCO and P2P mode +---------------- +DCO is also available when running OpenVPN in P2P mode without --pull/--client option. +The P2P mode is useful for scenarios when the OpenVPN tunnel should not interfere with +overall routing and behave more like a "dumb" tunnel like GRE. + +However, DCO requires DATA_V2 to be enabled. This requires P2P with NCP capability, which +is only available in OpenVPN 2.6 and later.
Changes.rstdoesn't mention this change, should it?
Quoted 5 lines
how does this sound:
Note that DCO will use
DATA_V2packets in P2P mode, therefore, this implies that peers must be running 2.6.0+ in order to have P2P-NCP which bringsDATA_V2packet support.
I think you misunderstood my point? I wasn't actually criticizing your text, I was wondering whether we should add an additional point in Changes.rst, because I see no mention of this new feature.
8c72d7981c32c43d1c7967a312bb439e13fc5b40 did add this feature without any changes to documentation or Changes.rst.
Quoted 5 lines
Quoted 1 line
Should we mention here what "NCP" stands for?
to be honest I barely know what it stands for :-D I just know it is "cipher negotiation", but the actual definition I think is expected to be found elsewhere. no?
FWIW, src/openvpn/options.h:#define OPT_P_NCP (1<<12) /**< Negotiable crypto parameters */
In general, I would think in this context using "cipher negotiation" as you already mentioned would be better than using an opaque acronym. Or at least use both so that users who are not intimately familiar with our nomenclature still know what you're talking about.
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH v2 4/7] ovpn-dco: introduce linux data-channel offload support
In reply to Antonio QuartulliHi,
Quoted 6 lines · Antonio Quartulli
Implement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
I've browsed through the code a bit to see if I can spot "unsafe" constructs (memory, pointers), or anything else noteworthy - since this is not the actual current code, it's hard to ACK.
We should move forward with "get this merged, and if the good folks testing this find new breakages, make this extra (smaller) patches on top, with proper credit"...
That said... a few things, in addition to the IN6_IS_ADDR_V4MAPPED() thing:
Quoted 7 lines
src/openvpn/dco.c new file +7
-0+int +dco_p2p_add_new_peer (struct context *c) +{ +if (!dco_enabled (&c->options)) + { +return 0 ; + }
[..]
src/openvpn/dco.c line 213
Quoted 3 lines
src/openvpn/dco.c new file +3
-0+ +if (dco_enabled (&c->options) && !c->c2.link_socket->info.dco_installed) + {
This second "dco_enabled()" check looks very unnecessary...
Not sure about the "if (!dco_installed)" check here - this seems to guard against double installment of this socket, but from the code flow I'm not sure how this could happen?
src/openvpn/dco.c line 244
Quoted 12 lines
src/openvpn/dco.c new file +12
-0+void +dco_remove_peer (struct context *c) +{ +if (!dco_enabled (&c->options)) + { +return ; + } +if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) + { + c->c2.tls_multi->dco_peer_added = false; +dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); + }
"traditional code ordering" would have the " = false" after the actual dco_del_peer() call... but that's of only aesthetic significance.
Quoted 4 lines
src/openvpn/dco.c new file +4
-0+void +dco_update_keys (dco_context_t *dco,struct tls_multi *multi) +{ +msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->peer_id);
[..]
src/openvpn/dco.c line 298
Quoted 9 lines
src/openvpn/dco.c new file +9
-0+ +struct key_state *primary =tls_select_encryption_key (multi); +ASSERT (!primary || primary->dco_status !=DCO_NOT_INSTALLED ); + +/* no primary key available -> no usable key exists, therefore we should +* tell DCO to simply wipe all keys +*/ +if (!primary) + {
"First, we ASSERT() if primary is NULL, and then, we do some action on primary being NULL"?
src/openvpn/dco.c line 308
Quoted 2 lines
src/openvpn/dco.c new file +2
-0+struct key_state *secondary =dco_get_secondary_key (multi, primary); +ASSERT (!secondary || secondary->dco_status !=DCO_NOT_INSTALLED );
Can you be sure that there always will be a valid and authorized secondary key when this fires?
Quoted 13 lines
src/openvpn/dco.c new file +13
-0+ +/* the current primary key was installed as secondary in DCO, this means +* that userspace has promoted it and we should tell DCO to swap keys +*/ +if (primary->dco_status ==DCO_INSTALLED_SECONDARY ) + { +msg (D_DCO_DEBUG ,"Swapping primary and secondary keys, now: id1=%d id2=%d" , + primary->key_id, secondary ? secondary->key_id :-1 ); + +dco_swap_keys (dco, multi->peer_id); + primary->dco_status =DCO_INSTALLED_PRIMARY ; +if (secondary) + {
src/openvpn/dco.c line 331
Quoted 10 lines
src/openvpn/dco.c new file +10
-0+ secondary->dco_status =DCO_INSTALLED_SECONDARY ; + } + } + +/* if we have no secondary key anymore, inform DCO about it */ +if (!secondary && multi->dco_keys_installed ==2 ) + { +dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); + multi->dco_keys_installed =1 ; + }
Since you ASSERT()ed on "!secondary", it is guaranteed to be not-NULL here...
Quoted 23 lines
src/openvpn/dco.c new file +23
-0+static int +dco_install_key (struct tls_multi *multi,struct key_state *ks, +const uint8_t *encrypt_key,const uint8_t *encrypt_iv, +const uint8_t *decrypt_key,const uint8_t *decrypt_iv, +const char *ciphername) + +{ +msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->peer_id, + ks->key_id); + +/* Install a key in the PRIMARY slot only when no other key exist. +* From that moment on, any new key will be installed in the SECONDARY +* slot and will be promoted to PRIMARY when userspace says so (a swap +* will be performed in that case) +*/ +dco_key_slot_t slot =OVPN_KEY_SLOT_PRIMARY ; +if (multi->dco_keys_installed >0 ) + { + slot =OVPN_KEY_SLOT_SECONDARY ; + } + + int ret = dco_new_key(multi->dco, multi->peer_id, ks->key_id, slot, + encrypt_key, encrypt_iv,
src/openvpn/dco.c line 376
Quoted 10 lines
src/openvpn/dco.c new file +10
-0+ decrypt_key, decrypt_iv, + ciphername); +if ((ret ==0 ) && (multi->dco_keys_installed <2 )) + { + multi->dco_keys_installed++; +switch (slot) + { +case OVPN_KEY_SLOT_PRIMARY : + ks->dco_status =DCO_INSTALLED_PRIMARY ; +break ;
I find this code slightly confusing. So when there are 2 keys installed and this function is called to install a new (upcoming secondary key), it will never set "ks->dco_status", then? Because the whole if() construct is not called...
Doing this in a switch seems overly complicated anyway, compared to
ks->dco_status = ( slot == OVPN_KEY_SLOT_PRIMARY )? DCO_INSTALLED_PRIMARY:
DCO_INSTALLED_SECONDARY;
Quoted 5 lines
src/openvpn/dco.c new file +5
-0+int +init_key_dco_bi (struct tls_multi *multi,struct key_state *ks, +const struct key2 *key2,int key_direction, +const char *ciphername,bool server) +{
src/openvpn/dco.c line 404
Quoted 10 lines
src/openvpn/dco.c new file +10
-0+struct key_direction_state kds; +key_direction_state_init (&kds, key_direction); + +return dco_install_key (multi, ks, + key2->keys[kds.out_key].cipher, + key2->keys[(int )server].hmac, + key2->keys[kds.in_key].cipher, + key2->keys[1 - (int )server].hmac, + ciphername); +}
This "_bi" stuff is "bidirectional data channel key", right?
(I tried to understand more, and the only easy-to-understand sections I found were related to "static openvpn key" reading, which we don't do in DCO mode...)
[..]
Quoted 13 lines
src/openvpn/dco.c new file +13
-0+ +/* These methods are currently Linux specific but likely to be used any +* platform that implements Server side DCO +*/ + +void +dco_install_iroute (struct multi_context *m,struct multi_instance *mi, +struct mroute_addr *addr) +{ +#if defined(TARGET_LINUX ) +if (!dco_enabled (&m->top.options)) + { +return ;
src/openvpn/dco.c line 540
Quoted 10 lines
src/openvpn/dco.c new file +10
-0+ } + +int addrtype = (addr->type &MR_ADDR_MASK ); + +/* If we do not have local IP addr to install, skip the route */ +if ((addrtype ==MR_ADDR_IPV6 && !mi->context.c2.push_ifconfig_ipv6_defined) + || (addrtype ==MR_ADDR_IPV4 && !mi->context.c2.push_ifconfig_defined)) + { +return ; + }
Should we have a warning here? "iroute requested but cannot be installed because no gateway/peer ip known"?
Otherwise we'll end up with a valid config that "silently does nothing".
(If we print that warning elsewhere, fine with me)
src/openvpn/dco.c line 551
Quoted 10 lines
src/openvpn/dco.c new file +10
-0+struct context *c = &mi->context; +const char *dev = c->c1.tuntap->actual_name; + +if (addrtype ==MR_ADDR_IPV6 ) + { +int netbits =128 ; +if (addr->type &MR_WITH_NETBITS ) + { + netbits = addr->netbits; + }
Side note: I wonder why we have that distinction anyway... a "MR WITHOUT NETBITS" would just be a "host route", so it could always set /128 in the iroute parsing code... but this is outside of *this* patch to clean up.
src/openvpn/dco.c line 563
Quoted 12 lines
src/openvpn/dco.c new file +12
-0+ +net_route_v6_add (&m->top.net_ctx, &addr->v6.addr, netbits, + &mi->context.c2.push_ifconfig_ipv6_local, dev,0 , +DCO_IROUTE_METRIC ); + } +else if (addrtype ==MR_ADDR_IPV4 ) + { +int netbits =32 ; +if (addr->type &MR_WITH_NETBITS ) + { + netbits = addr->netbits; + }
... and here for IPv4 host routes...
[..]
dco.h:
src/openvpn/dco.h line 48
Quoted 5 lines
src/openvpn/dco.h new file +5
-0+#if defined(TARGET_LINUX ) +#define DCO_DEFAULT_METRIC 200 +#else +#define DCO_DEFAULT_METRIC 0 +#endif
I find that define confusing, and I think the change to do_open_tun() / do_init_route_list() is not a good way to do it.
If we're having that conditional for the "default metric in route_option_list" anyway, it should just be "DCO_DEFAULT_METRIC" (not platform dependent), and set in do_init_route_list().
See below...
Quoted 1 line
src/openvpn/dco_internal.h +0
-0
[..]
Quoted 4 lines
+/**
+ * The following are the DCO APIs used to control the driver.
+ * They are implemented by eitherdco_linux.cordco_win.c
+ */
If this is the API, shouldn't it go to dco.h then? The other parts of dco_internal.h look more like "helper functions that multiple DCO implementations need"
src/openvpn/dco_linux.c
Quoted 1 line
src/openvpn/dco_linux.c +0
-0
[..]
I have not looked into detail into the netlink stuff (that would need to have a parallel look into the kernel module and a deeper understanding on what's going on)
Quoted 2 lines
+/**
+ * Send a preprared netlink message and registers cb as callback if non-null.
Typo "prep*r*ared"
Quoted 4 lines
src/openvpn/dco_linux.c +4
-0+static int +ovpn_nl_msg_send (dco_context_t *dco,struct nl_msg *nl_msg,ovpn_nl_cb cb, +const char *prefix) +{
src/openvpn/dco_linux.c line 186
Quoted 10 lines
src/openvpn/dco_linux.c +10
-0+ dco->status =1 ; + +if (cb) + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM , cb, dco); + } +else + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM ,NULL , dco); + }
As Frank already commented - if cb is NULL, you can just always pass on "cb", instead of having a second branch that spells out "NULL"...
src/openvpn/dco_linux.c line 210
Quoted 7 lines
src/openvpn/dco_linux.c +7
-0+struct sockaddr * +mapped_v4_to_v6 (struct sockaddr *sock,struct gc_arena *gc) +{ +struct sockaddr_in6 *sock6 = ((struct sockaddr_in6 *)sock); +if (sock->sa_family ==AF_INET6 + &&memcmp (&sock6->sin6_addr,"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" ,12 )==0 ) + {
See previous mail, IN6_IS_ADDR_V4MAPPED()
Quoted 6 lines
src/openvpn/dco_linux.c +6
-0+int +dco_new_peer (dco_context_t *dco,unsigned int peerid,int sd, +struct sockaddr *localaddr,struct sockaddr *remoteaddr, +struct in_addr *remote_in4,struct in6_addr *remote_in6) +{ +msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d" , __func__, peerid, sd);
[..]
src/openvpn/dco_linux.c line 274
Quoted 4 lines
src/openvpn/dco_linux.c +4
-0+nla_nest_end (nl_msg, attr); + + + ret =ovpn_nl_msg_send (dco, nl_msg,NULL , __func__);
double blank line here
Quoted 7 lines
src/openvpn/dco_linux.c +7
-0+static int +ovpn_nl_cb_error (struct sockaddr_nl (*nla) __attribute__ ((unused)), +struct nlmsgerr *err,void *arg) +{ +struct nlmsghdr *nlh = (struct nlmsghdr *)err -1 ; +struct nlattr *tb_msg[NLMSGERR_ATTR_MAX +1 ]; +int len = nlh->nlmsg_len;
src/openvpn/dco_linux.c line 307
Quoted 10 lines
src/openvpn/dco_linux.c +10
-0+struct nlattr *attrs; +int *ret = arg; +int ack_len =sizeof (*nlh) +sizeof (int ) +sizeof (*nlh); + + *ret = err->error; + +if (!(nlh->nlmsg_flags &NLM_F_ACK_TLVS )) + { +return NL_STOP ; + }
This is a bunch of magic with no explanation on what it does...
Maybe a comment before the function when this callback function is called, what sort of context it expects, and what it can do?
src/openvpn/dco_linux.c line 341
Quoted 8 lines
src/openvpn/dco_linux.c +8
-0+static void +ovpn_dco_init_netlink (dco_context_t *dco) +{ + dco->ovpn_dco_id =resolve_ovpn_netlink_id (M_ERR ); + + dco->nl_sock =nl_socket_alloc (); + +
double blank line
src/openvpn/dco_linux.c line 348
Quoted 7 lines
src/openvpn/dco_linux.c +7
-0+if (!dco->nl_sock) + { +msg (M_ERR ,"Cannot create netlink socket" ); + } + +/* TODO: Why are we setting this buffer size? */ +nl_socket_set_buffer_size (dco->nl_sock,8192 ,8192 );
This is a very good question :-)
src/openvpn/dco_linux.c line 409
Quoted 10 lines
src/openvpn/dco_linux.c +10
-0+static void +ovpn_dco_uninit_netlink (dco_context_t *dco) +{ +nl_socket_free (dco->nl_sock); + dco->nl_sock =NULL ; + +/* Decrease reference count */ +nl_cb_put (dco->nl_cb); + +memset (dco,0 ,sizeof (*dco));
CLEAR(dco);
Quoted 4 lines
src/openvpn/dco_linux.c +4
-0+static int +mcast_family_handler (struct nl_msg *msg,void *arg) +{ +dco_context_t *dco = arg;
src/openvpn/dco_linux.c line 657
Quoted 10 lines
src/openvpn/dco_linux.c +10
-0+struct nlattr *tb[CTRL_ATTR_MAX +1 ]; +struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); + +nla_parse (tb,CTRL_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +genlmsg_attrlen (gnlh,0 ),NULL ); + +if (!tb[CTRL_ATTR_MCAST_GROUPS ]) + { +return NL_SKIP ; + }
This, again, is a function full of magic, and desperately lacking a few comments on the why and how...
Quoted 4 lines
+/**
+ * Lookup the multicast id for OpenVPN. This method and its help method currently
+ * hardcode the lookup toOVPN_NL_NAMEandOVPN_NL_MULTICAST_GROUP_PEERSbut
+ * extended in the future if we need to lookup more than one mcast id.
Missing a "... 'can be' extended ..." here?
What is that multicast ID being used for? Why would one want more than one?
src/openvpn/dco_linux.c line 725
Quoted 8 lines
src/openvpn/dco_linux.c +8
-0+static int +ovpn_handle_msg (struct nl_msg *msg,void *arg) +{ +dco_context_t *dco = arg; + +struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); +struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlmsghdr *nlh =nlmsg_hdr (msg);
This seems to be the most magic of all the undocumented function here...? (Can you spot the pattern of my comments? ;-) )
src/openvpn/forward.c
Quoted 1 line
src/openvpn/forward.c +0
-0
[..]
I am skipping all the rest from here to init.c, due to "it's 4000 lines of patch review" - I want to get to the point about the metric, and will continue with forward.c later.
Quoted 4 lines
src/openvpn/init.c +0
-0
[..]
src/openvpn/init.c do_init_timers(struct context *c, bool deferred) · line 1308
Quoted 13 lines
src/openvpn/init.c +4
-3@@ -1299,15 +1300,23 @@ do_init_timers(struct context *c, bool deferred) }/* initialize pings */ - -if (c->options.ping_send_timeout) +if (dco_enabled (&c->options)) { -event_timeout_init (&c->c2.ping_send_interval, c->options.ping_send_timeout,0 ); +/* The DCO kernel module will send the pings instead of user space */ +event_timeout_clear (&c->c2.ping_rec_interval); +event_timeout_clear (&c->c2.ping_send_interval); }
Do we actually need to clear these, as opposed to "just do not call event_timeout_init()"?
src/openvpn/init.c do_alloc_route_list(struct context *c) · line 1390
Quoted 13 lines
src/openvpn/init.c +1
-1if (!deferred)@@ -1381,13 +1390,13 @@ do_alloc_route_list(struct context *c)static void do_init_route_list (const struct options *options,struct route_list *route_list, +int metric,const struct link_socket_info *link_socket_info,struct env_set *es,openvpn_net_ctx_t *ctx) {const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type); -int metric =0 ;
I find the addition of an extra parameter and the accompanying extra code in do_init_tun() to be a complicated way to get to the desired result. You have "options" here, so you can just do
int metric = 0;
if (dco_enabled(options))
{
metric = DCO_DEFAULT_METRIC;
}and get to the same result more easily.
src/openvpn/init.c do_init_route_list(const struct options *options, · line 1426
Quoted 13 lines
src/openvpn/init.c +1
-1if (dev ==DEV_TYPE_TUN && (options->topology ==TOP_NET30 || options->topology ==TOP_P2P )) {@@ -1418,12 +1427,12 @@ do_init_route_list(const struct options *options,static void do_init_route_ipv6_list (const struct options *options,struct route_ipv6_list *route_ipv6_list, +int metric,const struct link_socket_info *link_socket_info,struct env_set *es,openvpn_net_ctx_t *ctx) {const char *gw =NULL ; -int metric =-1 ;/* no metric set */
Same here...
Quoted 2 lines
src/openvpn/init.c +0
-0gw = options->ifconfig_ipv6_remote;/* default GW = remote end */ if (options->route_ipv6_default_gateway)
[..]
Quoted 17 lines
src/openvpn/init.c +7
-2@@ -1715,12 +1730,24 @@ do_open_tun(struct context *c)ASSERT (c->c2.link_socket);if (c->options.routes && c->c1.route_list) { -do_init_route_list (&c->options, c->c1.route_list, +int metric =0 ; +if (dco_enabled (&c->options)) + { + metric =DCO_DEFAULT_METRIC ; + } + +do_init_route_list (&c->options, c->c1.route_list, metric, &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,
src/openvpn/init.c do_open_tun(struct context *c) · line 1753
Quoted 10 lines
src/openvpn/init.c +7
-0+int metric =-1 ; +if (dco_enabled (&c->options)) + { + metric =DCO_DEFAULT_METRIC ; + } + +do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, metric, &c->c2.link_socket->info, c->c2.es, &c->net_ctx); }
... and with the suggested change to do_init_route*_list(), this change can totally go.
src/openvpn/init.c tun_abort(void) · line 2052
Quoted 8 lines
src/openvpn/init.c +1
-0@@ -2014,6 +2046,7 @@ tun_abort(void)* Handle delayed tun/tap interface bringup due to --up-delay or --pull */ +/** * Helper for do_up(). Take two option hashes and return true if they are not * equal, or either one is all-zeroes.
Spurious extra new line.
Quoted 38 lines
src/openvpn/init.c +10
-17@@ -2034,23 +2067,6 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) {reset_coarse_timers (c); -if (pulled_options) - { -if (!do_deferred_options (c, option_types_found)) - { -msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" ); -return false; - } - } -else if (c->mode ==MODE_POINT_TO_POINT ) - { -if (!do_deferred_p2p_ncp (c)) - { -msg (D_TLS_ERRORS ,"ERROR: Failed to apply P2P negotiated protocol options" ); -return false; - } - } -/* if --up-delay specified, open tun, do ifconfig, and run up script now */ if (c->options.up_delay ||PULL_DEFINED (&c->options)) {@@ -2076,6 +2092,23 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) } } +if (pulled_options) + { +if (!do_deferred_options (c, option_types_found)) + { +msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" ); +return false; + } + } +else if (c->mode ==MODE_POINT_TO_POINT ) + {
src/openvpn/init.c do_up(struct context *c, bool pulled_options, unsigned int option_types_found) · line 2114
Quoted 10 lines
src/openvpn/init.c +7
-0+if (!do_deferred_p2p_ncp (c)) + { +msg (D_TLS_ERRORS ,"ERROR: Failed to apply P2P negotiated protocol options" ); +return false; + } + } +if (c->c2.did_open_tun) { c->c1.pulled_options_digest_save = c->c2.pulled_options_digest;
On this, I can't see an obvious reason why the two blocks (what is show in the diff, and the "options_hash_changed_or_zero()" block) need to change order - can you help me understand?
Quoted 7 lines
/*
* Handle non-tun-related pulled options.
*/src/openvpn/init.c +0
-0@@ -2286,15 +2333,54 @@ do_deferred_options(struct context *c, const unsigned int found) }#endif
src/openvpn/init.c do_deferred_options(struct context *c, const unsigned int found) · line 2345
Quoted 10 lines
src/openvpn/init.c +10
-0+if (c->c2.did_open_tun) + { +/* If we are in DCO mode we need to set the new peer options now */ +int ret =dco_p2p_add_new_peer (c); +if (ret <0 ) + { +msg (D_DCO ,"Cannot add peer to DCO: %s" ,strerror (-ret)); +return false; + } + }
That comment reads as if we "set the new options for an existing peer", but the code reads as if this is creating the peer, with the new options.
If that interpretation is right, maybe
/* if we are in DCO mode, we now have all information needed and
* can proceed to create the peer
*/
or something?
Enough for today. More modules to come.
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]...Re: [Openvpn-devel] [PATCH v2 4/7] ovpn-dco: introduce linux data-channel offload support
Hi,
Quoted 14 lines · Gert Doering
Hi,
Quoted 6 lines · Antonio Quartulli
Implement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
I've browsed through the code a bit to see if I can spot "unsafe" constructs (memory, pointers), or anything else noteworthy - since this is not the actual current code, it's hard to ACK.
Quoted 5 lines
We should move forward with "get this merged, and if the good folks testing this find new breakages, make this extra (smaller) patches on top, with proper credit"...
That said... a few things, in addition to the
IN6_IS_ADDR_V4MAPPED()thing:
Thanks for pointing that out. I am switching to IN6_IS_ADDR_V4MAPPED()
Quoted 14 lines
Quoted 9 lines
src/openvpn/dco.c new file +7
-0+int +dco_p2p_add_new_peer (struct context *c) +{ +if (!dco_enabled (&c->options)) + { +return 0 ; + }[..]
src/openvpn/dco.c line 213
Quoted 3 lines
src/openvpn/dco.c new file +3
-0+ +if (dco_enabled (&c->options) && !c->c2.link_socket->info.dco_installed) + {
Quoted 5 lines
This second "
dco_enabled()" check looks very unnecessary...Not sure about the "if (!dco_installed)" check here - this seems to guard against double installment of this socket, but from the code flow I'm not sure how this could happen?
You are right - this is more a precondition.
I removed the if entirely (the dco_enabled() check is obviously uselss) and moved the !dco_installed condition as an assert at the top of the function.
Quoted 16 lines
src/openvpn/dco.c line 244
Quoted 13 lines
src/openvpn/dco.c new file +12
-0+void +dco_remove_peer (struct context *c) +{ +if (!dco_enabled (&c->options)) + { +return ; + } +if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) + { + c->c2.tls_multi->dco_peer_added = false; +dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); + }"traditional code ordering" would have the " = false" after the actual
dco_del_peer()call... but that's of only aesthetic significance.
well, makes sense. moved the assignment to the second line.
Quoted 6 lines
Quoted 5 lines
src/openvpn/dco.c new file +4
-0+void +dco_update_keys (dco_context_t *dco,struct tls_multi *multi) +{ +msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->peer_id);[..]
Quoted 12 lines
src/openvpn/dco.c line 298
Quoted 9 lines
src/openvpn/dco.c new file +9
-0+ +struct key_state *primary =tls_select_encryption_key (multi); +ASSERT (!primary || primary->dco_status !=DCO_NOT_INSTALLED ); + +/* no primary key available -> no usable key exists, therefore we should +* tell DCO to simply wipe all keys +*/ +if (!primary) + {"First, we
ASSERT()if primary is NULL, and then, we do some action on primary being NULL"?
hmm the ASSERT has two conditions in logic *or*:
"ASSERT(!primary || primary->dco_status != DCO_NOT_INSTALLED);"
Either primary is NULL or (if not-NULL) then its status must be NOT_INSTALLED.
This means that after the ASSERT we don't know yet if primary was NULL or not.
Quoted 7 lines
src/openvpn/dco.c line 308
Quoted 4 lines
src/openvpn/dco.c new file +2
-0+struct key_state *secondary =dco_get_secondary_key (multi, primary); +ASSERT (!secondary || secondary->dco_status !=DCO_NOT_INSTALLED );Can you be sure that there always will be a valid and authorized secondary key when this fires?
Same as above: secondary may either be NULL or NOT_INSTALLED.
Quoted 19 lines
Quoted 19 lines
src/openvpn/dco.c new file +18
-0+ +/* the current primary key was installed as secondary in DCO, this means +* that userspace has promoted it and we should tell DCO to swap keys +*/ +if (primary->dco_status ==DCO_INSTALLED_SECONDARY ) + { +msg (D_DCO_DEBUG ,"Swapping primary and secondary keys, now: id1=%d id2=%d" , + primary->key_id, secondary ? secondary->key_id :-1 ); + +dco_swap_keys (dco, multi->peer_id); + primary->dco_status =DCO_INSTALLED_PRIMARY ; +if (secondary) + { + secondary->dco_status =DCO_INSTALLED_SECONDARY ; + } + } + +/* if we have no secondary key anymore, inform DCO about it */
Quoted 8 lines
src/openvpn/dco.c line 331
Quoted 5 lines
src/openvpn/dco.c new file +5
-0+if (!secondary && multi->dco_keys_installed ==2 ) + { +dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); + multi->dco_keys_installed =1 ; + }Since you ASSERT()ed on "!secondary", it is guaranteed to be not-NULL here...
As per above.
Quoted 32 lines
Quoted 32 lines
src/openvpn/dco.c new file +30
-0+static int +dco_install_key (struct tls_multi *multi,struct key_state *ks, +const uint8_t *encrypt_key,const uint8_t *encrypt_iv, +const uint8_t *decrypt_key,const uint8_t *decrypt_iv, +const char *ciphername) + +{ +msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->peer_id, + ks->key_id); + +/* Install a key in the PRIMARY slot only when no other key exist. +* From that moment on, any new key will be installed in the SECONDARY +* slot and will be promoted to PRIMARY when userspace says so (a swap +* will be performed in that case) +*/ +dco_key_slot_t slot =OVPN_KEY_SLOT_PRIMARY ; +if (multi->dco_keys_installed >0 ) + { + slot =OVPN_KEY_SLOT_SECONDARY ; + } + +int ret =dco_new_key (multi->dco, multi->peer_id, ks->key_id, slot, + encrypt_key, encrypt_iv, + decrypt_key, decrypt_iv, + ciphername); +if ((ret ==0 ) && (multi->dco_keys_installed <2 )) + { + multi->dco_keys_installed++; +switch (slot) + {
Quoted 8 lines
src/openvpn/dco.c line 376
Quoted 3 lines
src/openvpn/dco.c new file +3
-0+case OVPN_KEY_SLOT_PRIMARY : + ks->dco_status =DCO_INSTALLED_PRIMARY ; +break ;I find this code slightly confusing. So when there are 2 keys installed and this function is called to install a new (upcoming secondary key), it will never set "
ks->dco_status", then? Because the wholeif()construct is not called...
Correct. This means we are at runtime, hence both keys are already INSTALLED, so no need to alter the status.
We could move the switch/case out and keep only the key_installed++ under the double condition. But it would be a useless assignment anyway.
Quoted 6 lines
Doing this in a switch seems overly complicated anyway, compared to
ks->dco_status = ( slot == OVPN_KEY_SLOT_PRIMARY )? DCO_INSTALLED_PRIMARY: DCO_INSTALLED_SECONDARY;
With enums I always prefer to use switch/case to properly enumerate all possible cases. Now here we have two values only, so we could skip the switch/case. I think it's just a matter of taste.
But your compact solution looks nice - I'll go with it!
Quoted 10 lines
Quoted 10 lines
src/openvpn/dco.c new file +9
-0+int +init_key_dco_bi (struct tls_multi *multi,struct key_state *ks, +const struct key2 *key2,int key_direction, +const char *ciphername,bool server) +{ +struct key_direction_state kds; +key_direction_state_init (&kds, key_direction); + + return dco_install_key(multi, ks,
Quoted 8 lines
src/openvpn/dco.c line 404
Quoted 6 lines
src/openvpn/dco.c new file +6
-0+ key2->keys[kds.out_key].cipher, + key2->keys[(int )server].hmac, + key2->keys[kds.in_key].cipher, + key2->keys[1 - (int )server].hmac, + ciphername); +}This "
_bi" stuff is "bidirectional data channel key", right?
yes..
Quoted 33 lines
(I tried to understand more, and the only easy-to-understand sections I found were related to "static openvpn key" reading, which we don't do in DCO mode...)
[..]
Quoted 13 lines
src/openvpn/dco.c new file +13
-0+ +/* These methods are currently Linux specific but likely to be used any +* platform that implements Server side DCO +*/ + +void +dco_install_iroute (struct multi_context *m,struct multi_instance *mi, +struct mroute_addr *addr) +{ +#if defined(TARGET_LINUX ) +if (!dco_enabled (&m->top.options)) + { +return ;src/openvpn/dco.c line 540
Quoted 10 lines
src/openvpn/dco.c new file +10
-0+ } + +int addrtype = (addr->type &MR_ADDR_MASK ); + +/* If we do not have local IP addr to install, skip the route */ +if ((addrtype ==MR_ADDR_IPV6 && !mi->context.c2.push_ifconfig_ipv6_defined) + || (addrtype ==MR_ADDR_IPV4 && !mi->context.c2.push_ifconfig_defined)) + { +return ; + }Should we have a warning here? "iroute requested but cannot be installed because no gateway/peer ip known"?
Quoted 3 lines
Otherwise we'll end up with a valid config that "silently does nothing".
(If we print that warning elsewhere, fine with me)
I am not even sure anything can work if the server does not know the client VPN IP. The latter is needed also for basic traffic (i.e. directed to the peer itself).
Quoted 13 lines
src/openvpn/dco.c line 551
Quoted 12 lines
src/openvpn/dco.c new file +10
-0+struct context *c = &mi->context; +const char *dev = c->c1.tuntap->actual_name; + +if (addrtype ==MR_ADDR_IPV6 ) + { +int netbits =128 ; +if (addr->type &MR_WITH_NETBITS ) + { + netbits = addr->netbits; + }
Quoted 4 lines
Side note: I wonder why we have that distinction anyway... a "MR WITHOUT NETBITS" would just be a "host route", so it could always set /128 in the iroute parsing code... but this is outside of *this* patch to clean up.
don't open the can..
Quoted 29 lines
src/openvpn/dco.c line 563
Quoted 13 lines
src/openvpn/dco.c new file +12
-0+ +net_route_v6_add (&m->top.net_ctx, &addr->v6.addr, netbits, + &mi->context.c2.push_ifconfig_ipv6_local, dev,0 , +DCO_IROUTE_METRIC ); + } +else if (addrtype ==MR_ADDR_IPV4 ) + { +int netbits =32 ; +if (addr->type &MR_WITH_NETBITS ) + { + netbits = addr->netbits; + }... and here for IPv4 host routes...
[..]
dco.h:src/openvpn/dco.h line 48
Quoted 5 lines
src/openvpn/dco.h new file +5
-0+#if defined(TARGET_LINUX ) +#define DCO_DEFAULT_METRIC 200 +#else +#define DCO_DEFAULT_METRIC 0 +#endif I find that define confusing, and I think the change to
do_open_tun()/do_init_route_list()is not a good way to do it.
Quoted 3 lines
If we're having that conditional for the "default metric in
route_option_list" anyway, it should just be "DCO_DEFAULT_METRIC" (not platform dependent), and set indo_init_route_list().
mh yeah, I am also not super happy about this.
Quoted 16 lines
See below...
Quoted 1 line
src/openvpn/dco_internal.h +0
-0[..]
Quoted 4 lines
+/**
+ * The following are the DCO APIs used to control the driver.
+ * They are implemented by eitherdco_linux.cordco_win.c
+ */If this is the API, shouldn't it go to
dco.hthen? The other parts ofdco_internal.hlook more like "helper functions that multiple DCO implementations need"
Quoted 6 lines
src/openvpn/dco_linux.c
Quoted 1 line
src/openvpn/dco_linux.c +0
-0[..]
I have not looked into detail into the netlink stuff (that would need to have a parallel look into the kernel module and a deeper understanding on what's going on)
or maybe by just looking at the API. I may need to add some more doc to make them more clear.
Quoted 5 lines
Quoted 3 lines
+/**
+ * Send a preprared netlink message and registers cb as callback if non-null.Typo "prep*r*ared"
fixed
Quoted 10 lines
Quoted 10 lines
src/openvpn/dco_linux.c +9
-0+static int +ovpn_nl_msg_send (dco_context_t *dco,struct nl_msg *nl_msg,ovpn_nl_cb cb, +const char *prefix) +{ + dco->status =1 ; + +if (cb) + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM , cb, dco);
Quoted 8 lines
src/openvpn/dco_linux.c line 186
Quoted 5 lines
src/openvpn/dco_linux.c +5
-0+ } +else + { +nl_cb_set (dco->nl_cb,NL_CB_VALID ,NL_CB_CUSTOM ,NULL , dco); + }As Frank already commented - if cb is NULL, you can just always pass on "cb", instead of having a second branch that spells out "NULL"...
fixed
Quoted 10 lines
src/openvpn/dco_linux.c line 210
Quoted 8 lines
src/openvpn/dco_linux.c +7
-0+struct sockaddr * +mapped_v4_to_v6 (struct sockaddr *sock,struct gc_arena *gc) +{ +struct sockaddr_in6 *sock6 = ((struct sockaddr_in6 *)sock); +if (sock->sa_family ==AF_INET6 + &&memcmp (&sock6->sin6_addr,"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" ,12 )==0 ) + {See previous mail,
IN6_IS_ADDR_V4MAPPED()
fixed
Quoted 8 lines
Quoted 7 lines
src/openvpn/dco_linux.c +6
-0+int +dco_new_peer (dco_context_t *dco,unsigned int peerid,int sd, +struct sockaddr *localaddr,struct sockaddr *remoteaddr, +struct in_addr *remote_in4,struct in6_addr *remote_in6) +{ +msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d" , __func__, peerid, sd);[..]
Quoted 6 lines
src/openvpn/dco_linux.c line 274
Quoted 4 lines
src/openvpn/dco_linux.c +4
-0+nla_nest_end (nl_msg, attr); + + + ret =ovpn_nl_msg_send (dco, nl_msg,NULL , __func__);double blank line here
fixed
Quoted 13 lines
Quoted 13 lines
src/openvpn/dco_linux.c +11
-0+static int +ovpn_nl_cb_error (struct sockaddr_nl (*nla) __attribute__ ((unused)), +struct nlmsgerr *err,void *arg) +{ +struct nlmsghdr *nlh = (struct nlmsghdr *)err -1 ; +struct nlattr *tb_msg[NLMSGERR_ATTR_MAX +1 ]; +int len = nlh->nlmsg_len; +struct nlattr *attrs; +int *ret = arg; +int ack_len =sizeof (*nlh) +sizeof (int ) +sizeof (*nlh); +
Quoted 8 lines
src/openvpn/dco_linux.c line 307
Quoted 6 lines
src/openvpn/dco_linux.c +6
-0+ *ret = err->error; + +if (!(nlh->nlmsg_flags &NLM_F_ACK_TLVS )) + { +return NL_STOP ; + }This is a bunch of magic with no explanation on what it does...
copied from other netlink programs :]
Quoted 4 lines
Maybe a comment before the function when this callback function is called, what sort of context it expects, and what it can do?
Sure will add a comment. To give an idea: it simply sets the error in the variable pointed by *arg, so that it can be retrieved from the code doing the netlink call.
The rest is just ugly blabla to parse the message and get a more verbose error message, if any was sent by the kernel.
Quoted 20 lines
src/openvpn/dco_linux.c line 341
Quoted 9 lines
src/openvpn/dco_linux.c +8
-0+static void +ovpn_dco_init_netlink (dco_context_t *dco) +{ + dco->ovpn_dco_id =resolve_ovpn_netlink_id (M_ERR ); + + dco->nl_sock =nl_socket_alloc (); + +double blank line
src/openvpn/dco_linux.c line 348
Quoted 7 lines
src/openvpn/dco_linux.c +7
-0+if (!dco->nl_sock) + { +msg (M_ERR ,"Cannot create netlink socket" ); + } + +/* TODO: Why are we setting this buffer size? */ +nl_socket_set_buffer_size (dco->nl_sock,8192 ,8192 );
Quoted 1 line
This is a very good question :-)
ideed. copied from iw.c :)
That's just a way to ensure that larger messages can happily fit the socket buffer and not fail.
Quoted 13 lines
src/openvpn/dco_linux.c line 409
Quoted 11 lines
src/openvpn/dco_linux.c +10
-0+static void +ovpn_dco_uninit_netlink (dco_context_t *dco) +{ +nl_socket_free (dco->nl_sock); + dco->nl_sock =NULL ; + +/* Decrease reference count */ +nl_cb_put (dco->nl_cb); + +memset (dco,0 ,sizeof (*dco));CLEAR(dco);
fixed
Quoted 11 lines
Quoted 11 lines
src/openvpn/dco_linux.c +9
-0+static int +mcast_family_handler (struct nl_msg *msg,void *arg) +{ +dco_context_t *dco = arg; +struct nlattr *tb[CTRL_ATTR_MAX +1 ]; +struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); + +nla_parse (tb,CTRL_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +genlmsg_attrlen (gnlh,0 ),NULL );
Quoted 8 lines
src/openvpn/dco_linux.c line 657
Quoted 5 lines
src/openvpn/dco_linux.c +5
-0+ +if (!tb[CTRL_ATTR_MCAST_GROUPS ]) + { +return NL_SKIP ; + }This, again, is a function full of magic, and desperately lacking a few comments on the why and how...
This is basically just parsing the reply to CTRL_CMD_GETFAMILY so that we can retrieve the multicast id of the DCO module.
To put it in other words: it is basically a callback for operations performed in ovpn_get_mcast_id() - there you have the higher level comment. But can add some more here if we want.
Quoted 7 lines
Quoted 5 lines
+/**
+ * Lookup the multicast id for OpenVPN. This method and its help method currently
+ * hardcode the lookup toOVPN_NL_NAMEandOVPN_NL_MULTICAST_GROUP_PEERSbut
+ * extended in the future if we need to lookup more than one mcast id.Missing a "... 'can be' extended ..." here?
yes
Quoted 3 lines
What is that multicast ID being used for? Why would one want more than one?
think of them as if they are multicast groups. You first get their addresses (IDs) and then register for messages sent to those groups.
The idea is that the main OVPN_NL_NAME group is for generic messages, while the OVPN_NL_MULTICAST_GROUP_PEERS group is for peer events.
We wanted to make this as flexible as possible so that also other programs running on the host could register to specific groups and get the events they are interested in.
There is no plan at the moment to create more groups.
Quoted 13 lines
src/openvpn/dco_linux.c line 725
Quoted 10 lines
src/openvpn/dco_linux.c +8
-0+static int +ovpn_handle_msg (struct nl_msg *msg,void *arg) +{ +dco_context_t *dco = arg; + +struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); +struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlmsghdr *nlh =nlmsg_hdr (msg);This seems to be the most magic of all the undocumented function here...? (Can you spot the pattern of my comments? ;-) )
hehe, because again this functon is just parsing a netlink reply. Can add some comments, but it is all mostly about check if attributes are there and if so retrieve thewir values.
Quoted 19 lines
src/openvpn/forward.c
Quoted 3 lines
src/openvpn/forward.c +0
-0[..]
I am skipping all the rest from here to
init.c, due to "it's 4000 lines of patch review" - I want to get to the point about the metric, and will continue withforward.clater.Quoted 4 lines
src/openvpn/init.c +0
-0[..]
Quoted 3 lines
src/openvpn/init.c +0
-0@@ -1299,15 +1300,23 @@ do_init_timers(struct context *c, bool deferred) }
Quoted 13 lines
src/openvpn/init.c do_init_timers(struct context *c, bool deferred) · line 1308
Quoted 10 lines
src/openvpn/init.c +4
-3/* initialize pings */ - -if (c->options.ping_send_timeout) +if (dco_enabled (&c->options)) { -event_timeout_init (&c->c2.ping_send_interval, c->options.ping_send_timeout,0 ); +/* The DCO kernel module will send the pings instead of user space */ +event_timeout_clear (&c->c2.ping_rec_interval); +event_timeout_clear (&c->c2.ping_send_interval); }Do we actually need to clear these, as opposed to "just do not call
event_timeout_init()"?
mumble mumble...we'd need to clear if init() was called before, but I don't think we can switch from non-DCO to DCO at runtime, so nobody should have ever init'd the timers...so probably you are right.
Quoted 19 lines
Quoted 4 lines
src/openvpn/init.c +0
-0if (!deferred)@@ -1381,13 +1390,13 @@ do_alloc_route_list(struct context *c) static voidsrc/openvpn/init.c do_alloc_route_list(struct context *c) · line 1390
Quoted 10 lines
src/openvpn/init.c +1
-1do_init_route_list(const struct options *options, struct route_list *route_list, + int metric, const struct link_socket_info *link_socket_info, struct env_set *es, openvpn_net_ctx_t *ctx) { const char *gw = NULL;int dev =dev_type_enum (options->dev, options->dev_type); -int metric =0 ;I find the addition of an extra parameter and the accompanying extra code in
do_init_tun()to be a complicated way to get to the desired result. You have "options" here, so you can just do
Quoted 7 lines
int metric = 0; if (dco_enabled(options)) { metric = DCO_DEFAULT_METRIC; }and get to the same result more easily.
true..
Quoted 44 lines
Quoted 5 lines
src/openvpn/init.c +0
-0if (dev ==DEV_TYPE_TUN && (options->topology ==TOP_NET30 || options->topology ==TOP_P2P )) {src/openvpn/init.c do_init_route_list(const struct options *options, · line 1426
Quoted 10 lines
src/openvpn/init.c +1
-1@@ -1418,12 +1427,12 @@ do_init_route_list(const struct options *options,static void do_init_route_ipv6_list (const struct options *options,struct route_ipv6_list *route_ipv6_list, +int metric,const struct link_socket_info *link_socket_info,struct env_set *es,openvpn_net_ctx_t *ctx) {const char *gw =NULL ; -int metric =-1 ;/* no metric set */ Same here...
Quoted 2 lines
src/openvpn/init.c +0
-0gw = options->ifconfig_ipv6_remote;/* default GW = remote end */ if (options->route_ipv6_default_gateway)[..]
Quoted 22 lines
src/openvpn/init.c +12
-2@@ -1715,12 +1730,24 @@ do_open_tun(struct context *c)ASSERT (c->c2.link_socket);if (c->options.routes && c->c1.route_list) { -do_init_route_list (&c->options, c->c1.route_list, +int metric =0 ; +if (dco_enabled (&c->options)) + { + metric =DCO_DEFAULT_METRIC ; + } + +do_init_route_list (&c->options, c->c1.route_list, metric, &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, +int metric =-1 ; +if (dco_enabled (&c->options)) + { + metric =DCO_DEFAULT_METRIC ; + }
Quoted 8 lines
src/openvpn/init.c do_open_tun(struct context *c) · line 1753
Quoted 5 lines
src/openvpn/init.c +2
-0+ +do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, metric, &c->c2.link_socket->info, c->c2.es, &c->net_ctx); }... and with the suggested change to do_init_route*_list(), this change can totally go.
yup, gone!
Quoted 59 lines
src/openvpn/init.c tun_abort(void) · line 2052
Quoted 10 lines
src/openvpn/init.c +1
-0@@ -2014,6 +2046,7 @@ tun_abort(void)* Handle delayed tun/tap interface bringup due to --up-delay or --pull */ +/** * Helper for do_up(). Take two option hashes and return true if they are not * equal, or either one is all-zeroes. Spurious extra new line.
Quoted 45 lines
src/openvpn/init.c +17
-17@@ -2034,23 +2067,6 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) {reset_coarse_timers (c); -if (pulled_options) - { -if (!do_deferred_options (c, option_types_found)) - { -msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" ); -return false; - } - } -else if (c->mode ==MODE_POINT_TO_POINT ) - { -if (!do_deferred_p2p_ncp (c)) - { -msg (D_TLS_ERRORS ,"ERROR: Failed to apply P2P negotiated protocol options" ); -return false; - } - } -/* if --up-delay specified, open tun, do ifconfig, and run up script now */ if (c->options.up_delay ||PULL_DEFINED (&c->options)) {@@ -2076,6 +2092,23 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) } } +if (pulled_options) + { +if (!do_deferred_options (c, option_types_found)) + { +msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" ); +return false; + } + } +else if (c->mode ==MODE_POINT_TO_POINT ) + { +if (!do_deferred_p2p_ncp (c)) + { +msg (D_TLS_ERRORS ,"ERROR: Failed to apply P2P negotiated protocol options" ); +return false; + } + } +
Quoted 9 lines
src/openvpn/init.c do_up(struct context *c, bool pulled_options, unsigned int option_types_found) · line 2114
Quoted 3 lines
src/openvpn/init.c +0
-0if (c->c2.did_open_tun) { c->c1.pulled_options_digest_save = c->c2.pulled_options_digest;On this, I can't see an obvious reason why the two blocks (what is show in the diff, and the "
options_hash_changed_or_zero()" block) need to change order - can you help me understand?
the reason was that the tun interface must be opened before we start parsing any option and start sending messages to the kernel (i.e. add peer or add key). So I moved the whole block earlier in do_up().
Note: tis function is still ongoing some restructuring because of the issues found by the netgate folks in P2P mode.
Quoted 22 lines
Quoted 8 lines
/*
* Handle non-tun-related pulled options.
*/src/openvpn/init.c +0
-0@@ -2286,15 +2333,54 @@ do_deferred_options(struct context *c, const unsigned int found) }#endif src/openvpn/init.c do_deferred_options(struct context *c, const unsigned int found) · line 2345
Quoted 10 lines
src/openvpn/init.c +10
-0+if (c->c2.did_open_tun) + { +/* If we are in DCO mode we need to set the new peer options now */ +int ret =dco_p2p_add_new_peer (c); +if (ret <0 ) + { +msg (D_DCO ,"Cannot add peer to DCO: %s" ,strerror (-ret)); +return false; + } + }That comment reads as if we "set the new options for an existing peer", but the code reads as if this is creating the peer, with the new options.
Quoted 7 lines
If that interpretation is right, maybe
/* if we are in DCO mode, we now have all information needed and * can proceed to create the peer */or something?
agreed - this was an older comment that was not changed after altering the code. fixing...
Quoted 3 lines
Enough for today. More modules to come.
Thanks a lot :)
will push everything in a bit.
Quoted 3 lines
gert
Signature · 1 line
Antonio Quartulli
PATCH 5/7 tun: extract close_tun_handle into its own fucntion and print correct type
In reply to Antonio QuartulliFrom: Arne Schwabe <[email protected]...>
This moves closing the tun handle into its own function and also prints the adapter type we are operating on, instead hardcoding it to tap-windows.
--- src/openvpn/tun.c | 75 ++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 34 deletions(-)
src/openvpn/tun.c +41 -34
@@ -6772,6 +6772,46 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gcargv_free (&argv); } +static +void close_tun_handle (struct tuntap * tt) +{ +const char * adaptertype =print_windows_driver (tt->windows_driver); +if (tt->hand !=NULL ) + { +dmsg (D_WIN32_IO_LOW ,"Attempting CancelIO on %s adapter" , adaptertype); +if (!CancelIo (tt->hand)) + { +msg (M_WARN |M_ERRNO ,"Warning: CancelIO failed on %s adapter" , adaptertype); + } + } + +dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped read event on %s adapter" , adaptertype); +overlapped_io_close (&tt->reads); + +dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped write event on %s adapter" , adaptertype); +overlapped_io_close (&tt->writes); + +if (tt->hand !=NULL ) + { +dmsg (D_WIN32_IO_LOW ,"Attempting CloseHandle on %s adapter" , adaptertype); +if (!CloseHandle (tt->hand)) + { +msg (M_WARN |M_ERRNO ,"Warning: CloseHandle failed on %s adapter" , adaptertype); + } + tt->hand =NULL ; + } + +if (tt->windows_driver ==WINDOWS_DRIVER_WINTUN ) + { +CloseHandle (tt->rw_handle.read); +CloseHandle (tt->rw_handle.write); +UnmapViewOfFile (tt->wintun_send_ring); +UnmapViewOfFile (tt->wintun_receive_ring); +CloseHandle (tt->wintun_send_ring_handle); +CloseHandle (tt->wintun_receive_ring_handle); + } +} +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx) {
@@ -6841,43 +6881,10 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)dhcp_release (tt); -if (tt->hand !=NULL ) - { -dmsg (D_WIN32_IO_LOW ,"Attempting CancelIO on TAP-Windows adapter" ); -if (!CancelIo (tt->hand)) - { -msg (M_WARN |M_ERRNO ,"Warning: CancelIO failed on TAP-Windows adapter" ); - } - } - -dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped read event on TAP-Windows adapter" ); -overlapped_io_close (&tt->reads); - -dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped write event on TAP-Windows adapter" ); -overlapped_io_close (&tt->writes); - -if (tt->hand !=NULL ) - { -dmsg (D_WIN32_IO_LOW ,"Attempting CloseHandle on TAP-Windows adapter" ); -if (!CloseHandle (tt->hand)) - { -msg (M_WARN |M_ERRNO ,"Warning: CloseHandle failed on TAP-Windows adapter" ); - } - } +close_tun_handle (tt);free (tt->actual_name); -if (tt->windows_driver ==WINDOWS_DRIVER_WINTUN ) - { -CloseHandle (tt->rw_handle.read); -CloseHandle (tt->rw_handle.write); -UnmapViewOfFile (tt->wintun_send_ring); -UnmapViewOfFile (tt->wintun_receive_ring); -CloseHandle (tt->wintun_send_ring_handle); -CloseHandle (tt->wintun_receive_ring_handle); - } - -clear_tuntap (tt);free (tt);gc_free (&gc);
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH 5/7] tun: extract close_tun_handle into its own fucntion and print correct type
Seems trivial.
Quoted 1 line
Antonio Quartulli <[email protected]...> hat am 02.04.2022 09:09 geschrieben:
[...]
src/openvpn/tun.c netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gc · line 6801
Quoted 8 lines
src/openvpn/tun.c +8
-0+if (tt->hand !=NULL ) + { +dmsg (D_WIN32_IO_LOW ,"Attempting CloseHandle on %s adapter" , adaptertype); +if (!CloseHandle (tt->hand)) + { +msg (M_WARN |M_ERRNO ,"Warning: CloseHandle failed on %s adapter" , adaptertype); + } + tt->hand =NULL ;
Setting hand to NULL is a slight behavior change, it wasn't there before. It might be nice to acknowledge it in the commit message just to confirm that it was a deliberate change.
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH 5/7] tun: extract close_tun_handle into its own fucntion and print correct type
Hi,
Quoted 15 lines · Frank Lichtenheld
Seems trivial.
Quoted 1 line
Antonio Quartulli <[email protected]...> hat am 02.04.2022 09:09 geschrieben:
[...]
src/openvpn/tun.c netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gc · line 6801
Quoted 8 lines
src/openvpn/tun.c +8
-0+if (tt->hand !=NULL ) + { +dmsg (D_WIN32_IO_LOW ,"Attempting CloseHandle on %s adapter" , adaptertype); +if (!CloseHandle (tt->hand)) + { +msg (M_WARN |M_ERRNO ,"Warning: CloseHandle failed on %s adapter" , adaptertype); + } + tt->hand =NULL ;
Quoted 3 lines
Setting hand to NULL is a slight behavior change, it wasn't there before. It might be nice to acknowledge it in the commit message just to confirm that it was a deliberate change.
Yes, it was a deliberate change.
This helper function will be invoked by (possibly) multiple places, so it's better to set a precondition and prevent a double close.
I agree we should add a sentence to the commit message about this.
Regards,
Signature · 1 line
Antonio Quartulli
PATCH 6/7 ovpn-dco-win: introduce windows data-channel offload support
In reply to Antonio QuartulliFrom: Arne Schwabe <[email protected]...>
Implement the data-channel offloading using the ovpn-dco-win kernel module. See README.dco.md for more details.
--- .github/workflows/build.yaml | 7 +- README.dco.md | 9 + config-msvc.h | 2 + configure.ac | 29 +- src/compat/Makefile.am | 3 +- src/compat/compat-dco_get_overlapped_result.c | 44 ++ src/compat/compat.h | 6 + src/compat/compat.vcxproj | 1 + src/compat/compat.vcxproj.filters | 3 + src/openvpn/Makefile.am | 3 +- src/openvpn/dco.c | 28 +- src/openvpn/dco.h | 5 + src/openvpn/dco_internal.h | 1 + src/openvpn/dco_linux.c | 6 + src/openvpn/dco_linux.h | 1 - src/openvpn/dco_win.c | 397 ++++++++++++++++++ src/openvpn/dco_win.h | 57 +++ src/openvpn/init.c | 34 +- src/openvpn/openvpn.vcxproj | 2 + src/openvpn/openvpn.vcxproj.filters | 9 + src/openvpn/options.c | 22 +- src/openvpn/options.h | 13 +- src/openvpn/ovpn-dco-win.h | 108 +++++ src/openvpn/socket.c | 105 ++++- src/openvpn/socket.h | 20 +- src/openvpn/tun.c | 43 +- src/openvpn/tun.h | 56 ++- 27 files changed, 938 insertions(+), 76 deletions(-) create mode 100644 src/compat/compat-dco_get_overlapped_result.c 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
.github/workflows/build.yaml +1 -6
@@ -27,11 +27,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:
@@ -119,7 +114,7 @@ jobs: run: cp ./tap-windows-9.23.3/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 --enable-dco working-directory: openvpn - name: build OpenVPN
README.dco.md +9 -0
@@ -58,6 +58,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/--client option.
@@ -109,6 +116,8 @@ Limitations by design - topology subnet is the only supported `--topology` for servers - iroute directives install routes on the host operating system, see also routing with ovpn-dco +- (ovpn-dco-win) client and p2p mode only +- (ovpn-dco-win) only AES-GCM-128/192/256 cipher support Current implementation limitations
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 +18 -11
@@ -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"
@@ -773,18 +774,24 @@ 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], + [libnl-genl-3.0 >= 3.2.29], + [have_libnl="yes"], + [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] + ) - PKG_CHECK_MODULES([LIBNL_GENL], - [libnl-genl-3.0 >= 3.2.29], - [have_libnl="yes"], - [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] - ) - - CFLAGS="${CFLAGS} ${LIBNL_GENL_CFLAGS}" - LIBS="${LIBS} ${LIBNL_GENL_LIBS}" + CFLAGS="${CFLAGS} ${LIBNL_GENL_CFLAGS}" + LIBS="${LIBS} ${LIBNL_GENL_LIBS}" + AC_DEFINE(ENABLE_DCO, 1, [Enable data channel offload for Linux]) + AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) + ;; - 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]) + ;; + esac fi if test "${with_crypto_library}" = "openssl"; then
src/compat/Makefile.am +2 -1
@@ -28,4 +28,5 @@ libcompat_la_SOURCES = \ compat-gettimeofday.c \ compat-daemon.c \ compat-strsep.c \ - compat-versionhelpers.h + compat-versionhelpers.h \ + compat-dco_get_overlapped_result.c
src/compat/compat-dco_get_overlapped_result.c new file +44 -0
44 lines not on this page · raw message
src/compat/compat.h +6 -0
@@ -62,4 +62,10 @@ char *strsep(char **stringp, const char *delim);#endif +#if defined(__MINGW32__) && !defined(__MINGW64__) +BOOL dco_get_overlapped_result (HANDLE handle,OVERLAPPED * ov,DWORD * transferred,DWORD delay_millisec,BOOL unused); +#else +#define dco_get_overlapped_result GetOverlappedResultEx +#endif +#endif /* COMPAT_H */
src/compat/compat.vcxproj +1 -0
@@ -159,6 +159,7 @@ </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="compat-basename.c" /> + <ClCompile Include="compat-dco_get_overlapped_result.c" /> <ClCompile Include="compat-dirname.c" /> <ClCompile Include="compat-gettimeofday.c" /> <ClCompile Include="compat-daemon.c" />
src/compat/compat.vcxproj.filters +3 -0
@@ -30,6 +30,9 @@ <ClCompile Include="compat-strsep.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="compat-dco_get_overlapped_result.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="compat.h">
src/openvpn/Makefile.am +2 -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 \
@@ -149,5 +150,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.c +26 -2
@@ -422,6 +422,25 @@ dco_check_option_conflict_ce(const struct connection_entry *ce, int msglevel)return false; } +static bool +dco_check_option_conflict_platform (int msglevel,const struct options *o) +{ +#if defined(_WIN32) +if (o->mode ==MODE_SERVER ) + { +msg (msglevel,"Only client and p2p data channel offload is supported " +"with ovpn-dco-win." ); +return true; + } +if (o->persist_tun) + { +msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +return true; + } +#endif +return false; +} +bool dco_check_option_conflict (int msglevel,const struct options *o) {
@@ -436,6 +455,11 @@ dco_check_option_conflict(int msglevel, const struct options *o)return true; } +if (dco_check_option_conflict_platform (msglevel, o)) + { +return true; + } +if (dev_type_enum (o->dev, o->dev_type) !=DEV_TYPE_TUN ) {msg (msglevel,"Note: dev-type not tun, disabling data channel offload." );
@@ -444,7 +468,7 @@ dco_check_option_conflict(int msglevel, const struct options *o)/* At this point the ciphers have already been normalised */ if (o->enable_ncp_fallback - && !tls_item_in_cipher_list (o->ciphername,DCO_SUPPORTED_CIPHERS )) + && !tls_item_in_cipher_list (o->ciphername,dco_get_supported_ciphers ())) {msg (msglevel,"Note: --data-cipher-fallback with cipher '%s' " "disables data channel offload." , o->ciphername);
@@ -498,7 +522,7 @@ dco_check_option_conflict(int msglevel, const struct options *o)const char *token;while ((token =strsep (&tmp_ciphers,":" ))) { -if (!tls_item_in_cipher_list (token,DCO_SUPPORTED_CIPHERS )) +if (!tls_item_in_cipher_list (token,dco_get_supported_ciphers ())) {msg (msglevel,"Note: cipher '%s' in --data-ciphers is not supported " "by ovpn-dco, disabling data channel offload." , token);
src/openvpn/dco.h +5 -0
@@ -180,6 +180,11 @@ void dco_update_keys(dco_context_t *dco, struct tls_multi *multi);*/ bool dco_available (int msglevel); +/** +* Returns list of colon-separated ciphers supported by platform +*/ +const char *dco_get_supported_ciphers (); +/** * Installs a DCO in the main event loop */
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_linux.c +6 -0
@@ -879,4 +879,10 @@ dco_event_set(dco_context_t *dco, struct event_set *es, void *arg) } } +const char * +dco_get_supported_ciphers () +{ +return "AES-128-GCM:AES-256-GCM:AES-192-GCM:CHACHA20-POLY1305" ; +} +#endif /* defined(ENABLE_DCO) && defined(TARGET_LINUX) */
src/openvpn/dco_linux.h +0 -1
@@ -36,7 +36,6 @@ typedef enum ovpn_cipher_alg dco_cipher_t;#define DCO_IROUTE_METRIC 100#define DCO_DEFAULT_METRIC 200 -#define DCO_SUPPORTED_CIPHERS "AES-128-GCM:AES-256-GCM:AES-192-GCM:CHACHA20-POLY1305" typedef struct {
src/openvpn/dco_win.c new file +397 -0
397 lines not on this page · raw message
src/openvpn/dco_win.h new file +57 -0
57 lines not on this page · raw message
src/openvpn/init.c +29 -5
@@ -1667,7 +1667,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;
@@ -1691,7 +1692,11 @@ do_open_tun(struct context *c)bool ret = false;#ifndef TARGET_ANDROID -if (!c->c1.tuntap) +if (!c->c1.tuntap +#ifdef _WIN32 + || (c->c1.tuntap && !c->c1.tuntap->dco.real_tun_init) +#endif + ) {#endif
@@ -1782,9 +1787,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 opend the device for the socket */ +if (!is_windco (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)
@@ -3514,6 +3522,22 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +#ifdef _WIN32 +if (c->c2.link_socket && c->c2.link_socket->info.dco_installed &&is_windco (c->c1.tuntap)) + { +ASSERT (c->c2.link_socket_owned); +ASSERT (c->c1.tuntap); + +/* We rely on the tun close to the handle if also setup +* routes etc, since they cannot be delete when the interface +* handle has been closed */ +if (true && !c->c1.tuntap->dco.real_tun_init) + { +do_close_tun_simple (c); + } + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +#endif if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/openvpn.vcxproj +2 -0
@@ -268,6 +268,7 @@ <ClCompile Include="crypto_openssl.c" /> <ClCompile Include="cryptoapi.c" /> <ClCompile Include="dco.c" /> + <ClCompile Include="dco_win.c" /> <ClCompile Include="dhcp.c" /> <ClCompile Include="dns.c" /> <ClCompile Include="env_set.c" />
@@ -354,6 +355,7 @@ <ClInclude Include="crypto_openssl.h" /> <ClInclude Include="cryptoapi.h" /> <ClInclude Include="dco.h" /> + <ClInclude Include="dco_win.h" /> <ClInclude Include="dhcp.h" /> <ClInclude Include="dns.h" /> <ClInclude Include="env_set.h" />
src/openvpn/openvpn.vcxproj.filters +9 -0
@@ -258,6 +258,9 @@ <ClCompile Include="xkey_provider.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="dco_win.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="base64.h">
@@ -386,6 +389,9 @@ <ClInclude Include="multi.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="networking_windco.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="ntlm.h"> <Filter>Header Files</Filter> </ClInclude>
@@ -536,6 +542,9 @@ <ClInclude Include="xkey_common.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="dco_win.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="openvpn_win32_resources.rc">
src/openvpn/options.c +18 -4
@@ -2338,6 +2338,11 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--windows-driver wintun requires --dev tun" ); } + +if (options->windows_driver ==WINDOWS_DRIVER_WINDCO ) + { +dco_check_option_conflict (M_USAGE , options); + }#endif /* ifdef _WIN32 */ /*
@@ -3108,8 +3113,8 @@ 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 +/* 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_WINDCO ) && (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 ;
@@ -3205,10 +3210,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" ;
@@ -4033,7 +4040,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4458,9 +4466,15 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco-win")) + { +return WINDOWS_DRIVER_WINDCO ; + } 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 ; } }
src/openvpn/options.h +4 -9
@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) -/** * 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_WINDCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} -#else - -static inline bool -dco_enabled (const struct options *o) -{return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/ovpn-dco-win.h new file +108 -0
108 lines not on this page · raw message
src/openvpn/socket.c +99 -6
153 lines not on this page · raw message
src/openvpn/socket.h +15 -5
@@ -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.
@@ -1048,6 +1049,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); }
@@ -1065,7 +1071,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 +1115,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 +1189,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 +34 -9
100 lines not on this page · raw message
src/openvpn/tun.h +40 -16
109 lines not on this page · raw message
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH 6/7] ovpn-dco-win: introduce windows data-channel offload support
Quoted 3 lines
Antonio Quartulli <[email protected]...> hat am 02.04.2022 09:09 geschrieben:
[...]
README.dco.md Limitations by design · line 120
Quoted 10 lines
README.dco.md +2
-0@@ -109,6 +116,8 @@ Limitations by design - topology subnet is the only supported `--topology` for servers - iroute directives install routes on the host operating system, see also routing with ovpn-dco +- (ovpn-dco-win) client and p2p mode only +- (ovpn-dco-win) only AES-GCM-128/192/256 cipher support
This seems to be out-of-sync with the code. The code seems to add CHACHA20-POLY1305 support on Windows 11.
As seen here:
Quoted 13 lines
README.dco.md +13
-0+ +const char * +dco_get_supported_ciphers() +{ + /* + * this API can be called either from user mode or kernel mode, + * which enables us to probe driver's chachapoly support + * (available starting from Windows 11) + */ + + BCRYPT_ALG_HANDLE h; + NTSTATUS status = BCryptOpenAlgorithmProvider(&h, L"CHACHA20_POLY1305", NULL, 0); + if (BCRYPT_SUCCESS(status))
README.dco.md Limitations by design
Quoted 10 lines
README.dco.md +10
-0+ { + BCryptCloseAlgorithmProvider(h, 0); + return "AES-128-GCM:AES-256-GCM:AES-192-GCM:CHACHA20-POLY1305"; + } + else + { + return "AES-128-GCM:AES-256-GCM:AES-192-GCM"; + } +} +
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH 6/7] ovpn-dco-win: introduce windows data-channel offload support
Hi,
Quoted 4 lines · Frank Lichtenheld
Quoted 3 lines
Antonio Quartulli <[email protected]...> hat am 02.04.2022 09:09 geschrieben:
[...]
Quoted 13 lines
README.dco.md Limitations by design · line 120
Quoted 10 lines
README.dco.md +2
-0@@ -109,6 +116,8 @@ Limitations by design - topology subnet is the only supported `--topology` for servers - iroute directives install routes on the host operating system, see also routing with ovpn-dco +- (ovpn-dco-win) client and p2p mode only +- (ovpn-dco-win) only AES-GCM-128/192/256 cipher supportThis seems to be out-of-sync with the code. The code seems to add CHACHA20-POLY1305 support on Windows 11.
You are correct - this should be changed.
Regards,
Signature · 1 line
Antonio Quartulli
PATCH 7/7 GitHub Actions: add Linux DCO build (on Ubuntu 20.04)
In reply to Antonio Quartulli--- .github/workflows/build.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
.github/workflows/build.yaml +8 -1
@@ -168,15 +168,22 @@ jobs: libname: OpenSSL 1.1.1 ssllib: openssl extraconf: "--disable-lzo --disable-lz4" + - os: ubuntu-20.04 + sslpkg: "libssl-dev" + libname: OpenSSL 1.1.1 + ssllib: openssl + extraconf: "--enable-dco" + nlpkg: "libnl-genl-3-dev" name: "gcc - ${{matrix.os}} - ${{matrix.libname}} ${{matrix.extraconf}}" env: SSLPKG: "${{matrix.sslpkg}}" + NLPKG: "${{matrix.nlpkg}}" runs-on: ${{matrix.os}} steps: - name: Install dependencies - run: sudo apt update && sudo apt install -y liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html libcmocka-dev python3-docutils libtool automake autoconf ${SSLPKG} + run: sudo apt update && sudo apt install -y liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html libcmocka-dev python3-docutils libtool automake autoconf ${SSLPKG} ${NLPKG} - name: Checkout OpenVPN uses: actions/[email protected]... - name: autoconf
Signature · 1 line
2.35.1