introduce networking API and add netlink support for Linux
v3 cover introduce networking API and add netlink support for Linux
From a high level description of this patchset, please refer to "[PATCH 0/4] add netlink support for Linux" sent to the mailing list on Apr, 20th 2018.
Changes from v2:
- addressed some of Arne's comments sent to the mailing list
- renamed networking_ip.* to networking_iproute2.*
- fixed minor bugs discovered during the integration with OVPN3
Changes from v1:
- introduced opaque context object containing implementation specific state;
- fixed env passed to ip command (thanks to opaque context);
- rebased on to pof latest master (00d78cd5)
Regards,
Antonio Quartulli (7):
implement networking API for iproute2
introduce sitnl: Simplified Interface To NetLink tun.c: use new networking API to handle tun interface on Linux route.c: use new networking API to handle routing table on Linux route.c: use sitnl to implement get_default_gateway_ipv6() unit tests: implement test for sitnl
travis.yml: add test for iproute2 net implementation
.travis.yml | 3 + configure.ac | 15 +- src/openvpn/Makefile.am | 2 + src/openvpn/errlevel.h | 1 + src/openvpn/forward.c | 2 +- src/openvpn/init.c | 55 +- src/openvpn/init.h | 5 +- src/openvpn/networking.h | 8 +- src/openvpn/networking_iproute2.c | 385 ++++++ src/openvpn/networking_iproute2.h | 36 + src/openvpn/networking_sitnl.c | 1228 ++++++++++++++++++++ src/openvpn/networking_sitnl.h | 28 + src/openvpn/openvpn.c | 4 +- src/openvpn/openvpn.h | 2 + src/openvpn/options.c | 10 +- src/openvpn/options.h | 1 + src/openvpn/route.c | 497 +++----- src/openvpn/route.h | 26 +- src/openvpn/sitnl.h | 217 ++++ src/openvpn/ssl.c | 2 +- src/openvpn/ssl_common.h | 1 + src/openvpn/tun.c | 233 ++-- src/openvpn/tun.h | 14 +- tests/Makefile.am | 3 +- tests/t_net.sh | 180 +++ tests/unit_tests/openvpn/Makefile.am | 30 +- tests/unit_tests/openvpn/test_networking.c | 229 ++++ 27 files changed, 2707 insertions(+), 510 deletions(-) create mode 100644 src/openvpn/networking_iproute2.c create mode 100644 src/openvpn/networking_iproute2.h create mode 100644 src/openvpn/networking_sitnl.c create mode 100644 src/openvpn/networking_sitnl.h create mode 100644 src/openvpn/sitnl.h create mode 100755 tests/t_net.sh create mode 100644 tests/unit_tests/openvpn/test_networking.c
Signature · 1 line
2.19.2
PATCH v3 1/7 implement networking API for iproute2
iproute2 is the first user of the new networking API and its one of the two currently supported functionalities on Linux (the other being net-tools).
This patch simply copies the current code from tun.c/route.c to networking_ip.c without introducing any funcional change to the code.
--- src/openvpn/Makefile.am | 2 +- src/openvpn/networking.h | 2 +- src/openvpn/networking_iproute2.c | 386 ++++++++++++++++++++++++++++++ src/openvpn/networking_iproute2.h | 36 +++ 4 files changed, 424 insertions(+), 2 deletions(-) create mode 100644 src/openvpn/networking_iproute2.c create mode 100644 src/openvpn/networking_iproute2.h
src/openvpn/Makefile.am +1 -1
@@ -80,7 +80,7 @@ openvpn_SOURCES = \ mtu.c mtu.h \ mudp.c mudp.h \ multi.c multi.h \ - networking.h \ + networking_iproute2.c networking_iproute2.h networking.h \ ntlm.c ntlm.h \ occ.c occ.h \ openssl_compat.h \
src/openvpn/networking.h +1 -1
@@ -34,7 +34,7 @@ struct context;#ifdef ENABLE_SITNL #include "networking_sitnl.h" #elif ENABLE_IPROUTE -#include "networking_ip.h" +#include "networking_iproute2.h" #else /* define mock types to ensure code builds on any platform */ typedef void *openvpn_net_ctx_t ;
src/openvpn/networking_iproute2.c new file +386 -0
386 lines not on this page · raw message
src/openvpn/networking_iproute2.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Generic interface to platform specific networking code +* +* Copyright (C) 2016-2018 Antonio Quartulli <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see the file COPYING included with this +* distribution); if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef NETWORKING_IP_H_ +#define NETWORKING_IP_H_ + +#include "env_set.h" + +typedef char openvpn_net_iface_t ; + +struct openvpn_net_ctx +{ +struct env_set *es; +}; + +typedef struct openvpn_net_ctx openvpn_net_ctx_t ; + +#endif /* NETWORKING_IP_H_ */
Signature · 1 line
2.19.2
Re: [Openvpn-devel] [PATCH v3 1/7] implement networking API for iproute2
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 7 lines
iproute2 is the first user of the new networking API and its one of the two currently supported functionalities on Linux (the other being net-tools).
This patch simply copies the current code from
tun.c/route.ctonetworking_ip.cwithout introducing any funcional change to the code.
Should be networking_iproute2.c in the commit message too.
Otherise:
Re: [Openvpn-devel] [PATCH v3 1/7] implement networking API for iproute2
In reply to Antonio QuartulliHi,
Quoted 4 lines · Antonio Quartulli
iproute2 is the first user of the new networking API and its one of the two currently supported functionalities on Linux (the other being net-tools).
Quoted 8 lines
This patch simply copies the current code from
tun.c/route.ctonetworking_ip.cwithout introducing any funcional change to the code.Signed-off-by Antonio Quartulli <[email protected]...>--- src/openvpn/Makefile.am | 2 +- src/openvpn/networking.h | 2 +-
"something is missing". It is nice that Arne ACKed this, but this patch does not apply to master, because we do not have a networking.h that it could modify...
I have quickly checked my inbox for other patch sets that would introduce "networking.h" but the only place I can see this mentioned is this patch set - so could you please send a "-1/7" that makes this patchset apply?
Or rebase on a clean "master", re-test, and re-send as v4?
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]...[Openvpn-devel] [PATCH applied] Re: implement networking API for iproute2
In reply to Antonio QuartulliYour patch has been applied to the master branch.
I'm not really happy with this patch - it adds lots of code which is not used yet. It claims that this is "the code from route.c / tun.c", but as it is not moved over but just copied, "git diff --color-moved=zebra" won't help in actually verifying that it is, indeed, the same code - and it cannot be tested because it is never called... so this is not a good patch granularity. But since Arne has already ACKed the whole series, I'm not holding this up, just grumbling a bit, hoping for a slightly more convincing (= there is a way to actually test the code changes every single commit brings) granularity in future series.
Oh, and as a side note - can we please stop configuring broadcast addresses? This was silly 15 years ago already... the machine knows quite well what the broadcast address is.
+ char *brd_str = (char *)print_in_addr_t(*broadcast, 0, NULL);
+
+ argv_printf(&argv, "%s addr add dev %s %s/%d broadcast %s", iproute_path,
+ iface, addr_str, prefixlen, brd_str);
.. and as yet another side note - this code introduces string allocations using (implicit) malloc() and free()... so this is very much *different* code than "what we have in route.c/tun.c" - and it questions the design of this API if every single backend *except* sitnl will have to start doing local memory management. ** This needs to be fixed **.
commit 678111936ffb33992684dd3b96dc5b21693dfa58
Author: Antonio Quartulli Date: Wed Dec 19 15:01:12 2018 +1000
implement networking API for iproute2
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18031.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 2/7 introduce sitnl: Simplified Interface To NetLink
In reply to Antonio QuartulliThis patch introduces a tiny netlink interface, optimized for the openvpn use case.
It basically exposes all those operations that are currently handled by directly calling the /sbin/ip command (or even ifconfig/route, if configured).
By using netlink, openvpn won't need to spawn new processes when configuring the tun interface or routes.
This new approach will also allow openvpn to be granted CAP_NET_ADMIN and be able to properly work even though it dropped the root privileges (currently handled via workarounds).
By moving this logic into the sitnl module, tun.c and route.c also benefit from some code simplification
--- configure.ac | 13 +- src/openvpn/Makefile.am | 4 +- src/openvpn/errlevel.h | 1 + src/openvpn/networking_sitnl.c | 1228 ++++++++++++++++++++++++++++++++ src/openvpn/networking_sitnl.h | 28 + src/openvpn/sitnl.h | 217 ++++++ 6 files changed, 1485 insertions(+), 6 deletions(-) create mode 100644 src/openvpn/networking_sitnl.c create mode 100644 src/openvpn/networking_sitnl.h create mode 100644 src/openvpn/sitnl.h
configure.ac +8 -5
@@ -298,6 +298,7 @@ case "$host" in *-*-linux*) AC_DEFINE([TARGET_LINUX], [1], [Are we running on Linux?]) AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["L"], [Target prefix]) + have_sitnl="yes" ;; *-*-solaris*) AC_DEFINE([TARGET_SOLARIS], [1], [Are we running on Solaris?])
@@ -1226,11 +1227,13 @@ fi if test "${enable_iproute2}" = "yes"; then test -z "${IPROUTE}" && AC_MSG_ERROR([ip utility is required but missing]) AC_DEFINE([ENABLE_IPROUTE], [1], [enable iproute2 support]) -else - if test "${WIN32}" != "yes"; then - test -z "${ROUTE}" && AC_MSG_ERROR([route utility is required but missing]) - test -z "${IFCONFIG}" && AC_MSG_ERROR([ifconfig utility is required but missing]) - fi +else if test "${have_sitnl}" = "yes"; then + AC_DEFINE([ENABLE_SITNL], [1], [enable sitnl support]) +else if test "${WIN32}" != "yes" -a "${have_sitnl}" != "yes"; then + test -z "${ROUTE}" && AC_MSG_ERROR([route utility is required but missing]) + test -z "${IFCONFIG}" && AC_MSG_ERROR([ifconfig utility is required but missing]) +fi +fi fi if test "${enable_selinux}" = "yes"; then
src/openvpn/Makefile.am +3 -1
@@ -80,7 +80,9 @@ openvpn_SOURCES = \ mtu.c mtu.h \ mudp.c mudp.h \ multi.c multi.h \ - networking_iproute2.c networking_iproute2.h networking.h \ + networking_iproute2.c networking_iproute2.h \ + networking_sitnl.c networking_sitnl.h \ + networking.h \ ntlm.c ntlm.h \ occ.c occ.h \ openssl_compat.h \
src/openvpn/errlevel.h +1 -0
@@ -109,6 +109,7 @@#define D_LOG_RW LOGLEV(5, 0, 0)/* Print 'R' or 'W' to stdout for read/write */ +#define D_RTNL LOGLEV(6, 68, M_DEBUG)/* show RTNL low level operations */ #define D_LINK_RW LOGLEV(6, 69, M_DEBUG)/* show TCP/UDP reads/writes (terse) */ #define D_TUN_RW LOGLEV(6, 69, M_DEBUG)/* show TUN/TAP reads/writes */ #define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG)/* show TAP-Windows driver debug info */
src/openvpn/networking_sitnl.c new file +1228 -0
1,228 lines not on this page · raw message
src/openvpn/networking_sitnl.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Generic interface to platform specific networking code +* +* Copyright (C) 2016-2018 Antonio Quartulli <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see the file COPYING included with this +* distribution); if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef NETWORKING_SITNL_H_ +#define NETWORKING_SITNL_H_ + +typedef char openvpn_net_iface_t ; +typedef void *openvpn_net_ctx_t ; + +#endif /* NETWORKING_SITNL_H_ */
src/openvpn/sitnl.h new file +217 -0
217 lines not on this page · raw message
Signature · 1 line
2.19.2
Re: [Openvpn-devel] [PATCH v3 2/7] introduce sitnl: Simplified Interface To NetLink
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 7 lines
This patch introduces a tiny netlink interface, optimized for the openvpn use case.
It basically exposes all those operations that are currently handled by directly calling the
/sbin/ipcommand (or even ifconfig/route, if configured).
Quoted 9 lines
By using netlink, openvpn won't need to spawn new processes when configuring the tun interface or routes.
This new approach will also allow openvpn to be grantedCAP_NET_ADMINand be able to properly work even though it dropped the root privileges (currently handled via workarounds).By moving this logic into the sitnl module,
tun.candroute.calso benefit from some code simplification
[Openvpn-devel] [PATCH applied] Re: introduce sitnl: Simplified Interface To NetLink
In reply to Antonio QuartulliYour patch has been applied to the master branch.
I'm (sorry) again not totally happy with it - it introduces the configure changes for sitnl, namely, breaking the "do route and ifconfig command exist?" check on all Linux systems (have_sitnl=yes is unconditionally set for Linux, and that will then always skip the check), without actually providing calls to sitnl yet. A better granularity would have introduced the configure checks only at the very end, when the actual HAVE_SITNL code is not only "it is there and compiles" but also functional, and route/ifconfig are kicked out.
Additonally, it introduces "sitnl.h" which is not included in openvpn_SOURCES and not referenced from anywhere... which is also an extra burden on me (will this disappear in a future patch? will it be included? will it appear in openvpn_SOURCES eventually?).
The code in networking_sitnl.* looks mostly reasonable, though I wonder if it wasn't more elegant to do the sitnl_socket() dance only once in the init, and store the file descriptor in the context afterwards... right now, you're doing the whole open/bind/../close for every function called.
The upcoming networking_we_are_done() function doing the gc_free() calls for non-linux implementations could then do the close() for sitnl...
Besides this, there are a few warts...
+ if (up)
+ req.i.ifi_flags |= IFF_UP;
+ else
+ req.i.ifi_flags &= ~IFF_UP;
..
+ ifindex = if_nametoindex(iface);
+ if (ifindex == 0) {
.. which you might want to run through uncrustify eventually...
commit c6542257019ba66a98b817d3b851621dd553f80a
Author: Antonio Quartulli Date: Wed Dec 19 15:01:13 2018 +1000
introduce sitnl: Simplified Interface To NetLink
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18030.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 3/7 tun.c: use new networking API to handle tun interface on Linux
In reply to Antonio QuartulliBy switching to the networking API (for Linux) openvpn will now use any of the available implementations to handle the tun interface.
At the moment only iproute2 and sitnl (NetLink) is implemented.
--- src/openvpn/init.c | 22 ++-- src/openvpn/init.h | 2 +- src/openvpn/networking.h | 6 -- src/openvpn/openvpn.c | 4 +- src/openvpn/openvpn.h | 2 + src/openvpn/options.c | 4 +- src/openvpn/options.h | 1 + src/openvpn/tun.c | 215 +++++++++++++++++++++------------------ src/openvpn/tun.h | 12 ++- 9 files changed, 147 insertions(+), 121 deletions(-)
src/openvpn/init.c +14 -8
@@ -1105,7 +1105,7 @@ do_genkey(const struct options *options)* Persistent TUN/TAP device management mode? */ bool -do_persist_tuntap (const struct options *options) +do_persist_tuntap (const struct options *options,openvpn_net_ctx_t *ctx) {if (options->persist_config) {
@@ -1123,7 +1123,8 @@ do_persist_tuntap(const struct options *options)#ifdef ENABLE_FEATURE_TUN_PERSIST tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, - options->username, options->groupname, &options->tuntap_options); + options->username, options->groupname, &options->tuntap_options, + ctx);if (options->persist_mode && options->lladdr) {set_lladdr (options->dev, options->lladdr,NULL );
@@ -1694,7 +1695,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.bind_local, c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, - c->c2.es); + c->c2.es, + &c->net_ctx); init_tun_post(c->c1.tuntap, &c->c2.frame,
@@ -1766,7 +1768,8 @@ do_open_tun(struct context *c) c->options.dev_type, c->options.dev_node, &gc); -do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es); +do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es, + &c->net_ctx); }/* possibly add routes */
@@ -1794,7 +1797,8 @@ do_open_tun(struct context *c)if (!c->options.ifconfig_noexec &&ifconfig_order () ==IFCONFIG_AFTER_TUN_OPEN ) { -do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name,TUN_MTU_SIZE (&c->c2.frame), c->c2.es); +do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, +TUN_MTU_SIZE (&c->c2.frame), c->c2.es, &c->net_ctx); }/* run the up script */
@@ -1902,7 +1906,7 @@ do_close_tun_simple(struct context *c)msg (D_CLOSE ,"Closing TUN/TAP interface" );if (c->c1.tuntap) { -close_tun (c->c1.tuntap); +close_tun (c->c1.tuntap, &c->net_ctx); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
@@ -3380,9 +3384,11 @@ do_compute_occ_strings(struct context *c)struct gc_arena gc =gc_new (); c->c2.options_string_local = -options_string (&c->options, &c->c2.frame, c->c1.tuntap, false, &gc); +options_string (&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ctx, + false, &gc); c->c2.options_string_remote = -options_string (&c->options, &c->c2.frame, c->c1.tuntap, true, &gc); +options_string (&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ctx, + true, &gc); msg(D_SHOW_OCC, "Local Options String (VER=%s): '%s'", options_string_version(c->c2.options_string_local, &gc),
src/openvpn/init.h +1 -1
@@ -56,7 +56,7 @@ bool print_openssl_info(const struct options *options);bool do_genkey (const struct options *options); -bool do_persist_tuntap (const struct options *options); +bool do_persist_tuntap (const struct options *options,openvpn_net_ctx_t *ctx);bool possibly_become_daemon (const struct options *options);
src/openvpn/networking.h +0 -6
@@ -21,12 +21,6 @@#ifndef NETWORKING_H_ #define NETWORKING_H_ -#ifdef HAVE_CONFIG_H -#include "config.h" -#elif defined(_MSC_VER) -#include "config-msvc.h" -#endif -#include "syshead.h" struct context ;
src/openvpn/openvpn.c +3 -1
@@ -215,6 +215,8 @@ openvpn_main(int argc, char *argv[])open_plugins (&c, true,OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE );#endif +net_ctx_init (&c, &c.net_ctx); +/* init verbosity and mute levels */ init_verb_mute (&c,IVM_LEVEL_1 );
@@ -234,7 +236,7 @@ openvpn_main(int argc, char *argv[]) }/* tun/tap persist command? */ -if (do_persist_tuntap (&c.options)) +if (do_persist_tuntap (&c.options, &c.net_ctx)) {break ; }
src/openvpn/openvpn.h +2 -0
@@ -522,6 +522,8 @@ struct contextstruct env_set *es;/**< Set of environment variables. */ +openvpn_net_ctx_t net_ctx;/**< Networking API opaque context */ +struct signal_info *sig;/**< Internal error signaling object. */ struct plugin_list *plugins;/**< List of plug-ins. */
src/openvpn/options.c +3 -1
@@ -3548,6 +3548,7 @@ char * options_string(const struct options *o, const struct frame *frame, struct tuntap *tt, + openvpn_net_ctx_t *ctx, bool remote, struct gc_arena *gc) {
@@ -3590,7 +3591,8 @@ options_string(const struct options *o,NULL ,NULL , false, - NULL); +NULL , + ctx);if (tt) { tt_local = true;
src/openvpn/options.h +1 -0
@@ -744,6 +744,7 @@ const char *options_string_version(const char *s, struct gc_arena *gc);char *options_string (const struct options *o,const struct frame *frame,struct tuntap *tt, +openvpn_net_ctx_t *ctx,bool remote,struct gc_arena *gc);
src/openvpn/tun.c +115 -100
431 lines not on this page · raw message
src/openvpn/tun.h +8 -4
@@ -36,6 +36,7 @@#include "event.h" #include "proto.h" #include "misc.h" +#include "networking.h" #if defined(_WIN32) || defined(TARGET_ANDROID )
@@ -211,7 +212,7 @@ tuntap_defined(const struct tuntap *tt)void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt); -void close_tun (struct tuntap *tt); +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx);int write_tun (struct tuntap *tt,uint8_t *buf,int len);
@@ -219,7 +220,8 @@ int read_tun(struct tuntap *tt, uint8_t *buf, int len);void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username, -const char *groupname,const struct tuntap_options *options); +const char *groupname,const struct tuntap_options *options, +openvpn_net_ctx_t *ctx); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -237,7 +239,8 @@ struct tuntap *init_tun(const char *dev, /* --dev option */struct addrinfo *local_public, struct addrinfo *remote_public, const bool strict_warn, - struct env_set *es); + struct env_set *es, + openvpn_net_ctx_t *ctx); void init_tun_post(struct tuntap *tt, const struct frame *frame,
@@ -253,9 +256,10 @@ void do_ifconfig_setenv(const struct tuntap *tt,* @param ifname the human readable interface name * @param mtu the MTU value to set the interface to * @param es the environment to be used when executing the commands +* @param ctx the networking API opaque context */ void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu, -const struct env_set *es); +const struct env_set *es,openvpn_net_ctx_t *ctx);bool is_dev_type (const char *dev,const char *dev_type,const char *match_type);
Signature · 1 line
2.19.2
Re: [Openvpn-devel] [PATCH v3 3/7] tun.c: use new networking API to handle tun interface on Linux
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 6 lines
By switching to the networking API (for Linux) openvpn will now use any of the available implementations to handle the tun interface.
At the moment only iproute2 and sitnl (NetLink) is implemented.
Arne
[Openvpn-devel] [PATCH applied] Re: tun.c: use new networking API to handle tun interface on Linux
In reply to Antonio QuartulliYour patch has been applied to the master branch.
The change to options_string() surprised me a bit, then I found that it's calling init_tun() under the hood (sometimes) and now I do not want to know anymore... or maybe I want to have someone tell me "oh, with Heiko's windows change of ordering, we do not need this anymore *anyway*, we can rip it out". Or maybe Android needs it... I'm tempted to put an ASSERT(tt) in there and test a few platforms...
Anyway. This patch is now finally something I could actually *test* :-) - so, I ran the t_client tests with an --enable-iproute2 build and an "no options" build (which should give me netlink).
OpenVPN output showed suitably nice differences...
Sun Jun 2 20:50:35 2019 net_iface_mtu_set: mtu 1500 for tun0 Sun Jun 2 20:50:35 2019 net_iface_up: set tun0 up Sun Jun 2 20:50:35 2019 net_addr_v4_add: x.x.x.74/29 brd 255.255.255.248 dev tun0 Sun Jun 2 20:50:35 2019 net_iface_mtu_set: mtu 1500 for tun0 Sun Jun 2 20:50:35 2019 net_iface_up: set tun0 up Sun Jun 2 20:50:35 2019 net_addr_v6_add: 2001:x:x:x::1000/64 dev tun0
vs.
Sun Jun 2 20:55:57 2019 /bin/ip link set dev tun0 up mtu 1500 Sun Jun 2 20:55:57 2019 /bin/ip link set dev tun0 up Sun Jun 2 20:55:57 2019 /bin/ip addr add dev tun0 x.x.x.74/29 broadcast 255.255.255.248 Sun Jun 2 20:55:57 2019 /bin/ip link set dev tun0 up mtu 1500 Sun Jun 2 20:55:57 2019 /bin/ip link set dev tun0 up Sun Jun 2 20:55:57 2019 /bin/ip -6 addr add 2001:x.x.x::1000/64 dev tun0
and manual "ip addr show" reflected the correctness while OpenVPN was up. Great :-)
commit dc7fcd714188989966ac2bd9315485603813fe0f
Author: Antonio Quartulli Date: Wed Dec 19 15:01:14 2018 +1000
tun.c: use new networking API to handle tun interface on Linux
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18028.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 4/7 route.c: use new networking API to handle routing table on Linux
In reply to Antonio QuartulliBy switching to the networking API (for Linux) openvpn will now use any of the available implementations to handle the routing table.
At the moment only iproute2 is implemented.
--- src/openvpn/forward.c | 2 +- src/openvpn/init.c | 24 ++- src/openvpn/init.h | 3 +- src/openvpn/networking_iproute2.c | 1 - src/openvpn/options.c | 4 +- src/openvpn/route.c | 336 ++++++++++++------------------ src/openvpn/route.h | 19 +- src/openvpn/ssl.c | 2 +- src/openvpn/ssl_common.h | 1 + src/openvpn/tun.c | 18 +- src/openvpn/tun.h | 2 +- 11 files changed, 184 insertions(+), 228 deletions(-)
src/openvpn/forward.c +1 -1
@@ -508,7 +508,7 @@ static void check_add_routes_action(struct context *c, const bool errors) { do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx);update_time ();event_timeout_clear (&c->c2.route_wakeup);event_timeout_clear (&c->c2.route_wakeup_expire);
src/openvpn/init.c +15 -9
@@ -1426,7 +1426,8 @@ static void do_init_route_list(const struct options *options, struct route_list *route_list, const struct link_socket_info *link_socket_info, - struct env_set *es) + struct env_set *es, + openvpn_net_ctx_t *ctx) { const char *gw = NULL;int dev =dev_type_enum (options->dev, options->dev_type);
@@ -1450,7 +1451,8 @@ do_init_route_list(const struct options *options, gw, metric,link_socket_current_remote (link_socket_info ), - es)) + es, + ctx)) {/* copy routes to environment */ setenv_routes (es ,route_list );
@@ -1633,11 +1635,13 @@ do_route(const struct options *options,struct route_ipv6_list *route_ipv6_list, const struct tuntap *tt, const struct plugin_list *plugins, - struct env_set *es) + struct env_set *es, + openvpn_net_ctx_t *ctx) { if (!options->route_noexec && ( route_list || route_ipv6_list ) ) { -add_routes (route_list ,route_ipv6_list ,tt ,ROUTE_OPTION_FLAGS (options ),es ); +add_routes (route_list ,route_ipv6_list ,tt ,ROUTE_OPTION_FLAGS (options ), +es ,ctx );setenv_int (es,"redirect_gateway" ,route_did_redirect_default_gateway (route_list)); }#ifdef ENABLE_MANAGEMENT
@@ -1750,7 +1754,7 @@ do_open_tun(struct context *c)if (c->options.routes && c->c1.route_list) {do_init_route_list (&c->options, c->c1.route_list, - &c->c2.link_socket->info, c->c2.es); + &c->c2.link_socket->info, c->c2.es, &c->net_ctx); }if (c->options.routes_ipv6 && c->c1.route_ipv6_list) {
@@ -1777,7 +1781,7 @@ do_open_tun(struct context *c) {/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); }#ifdef TARGET_ANDROID /* Store the old fd inside the fd so open_tun can use it */
@@ -1834,7 +1838,7 @@ do_open_tun(struct context *c)if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) {do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es); + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); }/*
@@ -1963,7 +1967,8 @@ do_close_tun(struct context *c, bool force) c->c2.es);delete_routes (c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), c->c2.es); + c->c1.tuntap,ROUTE_OPTION_FLAGS (&c->options), + c->c2.es, &c->net_ctx); }/* actually close tun/tap device based on --down-pre flag */
@@ -2820,6 +2825,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.x509_username_field =X509_USERNAME_FIELD_DEFAULT ;#endif to.es = c->c2.es; + to.net_ctx = &c->net_ctx;#ifdef ENABLE_DEBUG to.gremlin = c->options.gremlin;
@@ -3182,7 +3188,7 @@ do_option_warnings(struct context *c)if (o->tls_server) { -warn_on_use_of_common_subnets (); +warn_on_use_of_common_subnets (&c->net_ctx); }if (o->tls_client && !o->tls_verify
src/openvpn/init.h +2 -1
@@ -76,7 +76,8 @@ void do_route(const struct options *options,struct route_ipv6_list *route_ipv6_list, const struct tuntap *tt, const struct plugin_list *plugins, - struct env_set *es); + struct env_set *es, + openvpn_net_ctx_t *ctx);void close_instance (struct context *c);
src/openvpn/networking_iproute2.c +0 -1
@@ -29,7 +29,6 @@#include "syshead.h" #include "networking.h" -#include "networking_iproute2.h" #include "misc.h" #include "openvpn.h" #include "run_command.h"
src/openvpn/options.c +3 -1
@@ -5006,12 +5006,14 @@ add_option(struct options *options,struct route_gateway_info rgi;struct route_ipv6_gateway_info rgi6;struct in6_addr remote =IN6ADDR_ANY_INIT ; +openvpn_net_ctx_t net_ctx;VERIFY_PERMISSION (OPT_P_GENERAL );if (p[1 ]) {get_ipv6_addr (p[1 ], &remote,NULL ,M_WARN ); } -get_default_gateway (&rgi); +net_ctx_init (NULL , &net_ctx); +get_default_gateway (&rgi, &net_ctx);get_default_gateway_ipv6 (&rgi6, &remote);print_default_gateway (M_INFO , &rgi, &rgi6);openvpn_exit (OPENVPN_EXIT_STATUS_GOOD );/* exit point */
src/openvpn/route.c +139 -197
699 lines not on this page · raw message
src/openvpn/route.h +12 -7
@@ -256,15 +256,16 @@ void copy_route_ipv6_option_list(struct route_ipv6_option_list *dest,void route_ipv6_clear_host_bits (struct route_ipv6 *r6 ); -void add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es); +void add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx); -void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es); +void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es,openvpn_net_ctx_t *ctx);void add_route (struct route_ipv4 *r,const struct tuntap *tt,unsigned int flags,const struct route_gateway_info *rgi, -const struct env_set *es); +const struct env_set *es, +openvpn_net_ctx_t *ctx); void add_route_to_option_list(struct route_option_list *l, const char *network,
@@ -282,7 +283,8 @@ bool init_route_list(struct route_list *rl,const char *remote_endpoint, int default_metric, in_addr_t remote_host, - struct env_set *es); + struct env_set *es, + openvpn_net_ctx_t *ctx); bool init_route_ipv6_list(struct route_ipv6_list *rl6, const struct route_ipv6_option_list *opt6,
@@ -299,13 +301,15 @@ void add_routes(struct route_list *rl,struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, - const struct env_set *es); + const struct env_set *es, + openvpn_net_ctx_t *ctx);void delete_routes (struct route_list *rl,struct route_ipv6_list *rl6,const struct tuntap *tt,unsigned int flags, -const struct env_set *es); +const struct env_set *es, +openvpn_net_ctx_t *ctx);void setenv_routes (struct env_set *es,const struct route_list *rl);
@@ -315,7 +319,8 @@ void setenv_routes_ipv6(struct env_set *es, const struct route_ipv6_list *rl6);bool is_special_addr (const char *addr_str); -void get_default_gateway (struct route_gateway_info *rgi); +void get_default_gateway (struct route_gateway_info *rgi, +openvpn_net_ctx_t *ctx);void get_default_gateway_ipv6 (struct route_ipv6_gateway_info *rgi,const struct in6_addr *dest);
src/openvpn/ssl.c +1 -1
@@ -2324,7 +2324,7 @@ push_peer_info(struct buffer *buf, struct tls_session *session) {/* push mac addr */ struct route_gateway_info rgi; -get_default_gateway (&rgi); +get_default_gateway (&rgi, session->opt->net_ctx);if (rgi.flags &RGI_HWADDR_DEFINED ) {buf_printf (&out,"IV_HWADDR=%s\n" ,format_hex_ex (rgi.hwaddr,6 ,0 ,1 ,":" , &gc));
src/openvpn/ssl_common.h +1 -0
@@ -315,6 +315,7 @@ struct tls_options/* instance-wide environment variable set */ struct env_set *es; +openvpn_net_ctx_t *net_ctx;const struct plugin_list *plugins;/* compression parms */
src/openvpn/tun.c +9 -9
@@ -453,13 +453,13 @@ check_subnet_conflict(const in_addr_t ip, }void -warn_on_use_of_common_subnets (void ) +warn_on_use_of_common_subnets (openvpn_net_ctx_t *ctx) {struct gc_arena gc =gc_new ();struct route_gateway_info rgi;const int needed = (RGI_ADDR_DEFINED |RGI_NETMASK_DEFINED ); -get_default_gateway (&rgi); +get_default_gateway (&rgi, ctx);if ((rgi.flags & needed) == needed) {const in_addr_t lan_network = rgi.gateway.addr & rgi.gateway.netmask;
@@ -818,7 +818,7 @@ add_route_connected_v6_net(struct tuntap *tt, r6.gateway = tt->local_ipv6; r6.metric =0 ;/* connected route */ r6.flags =RT_DEFINED |RT_METRIC_DEFINED ; -add_route_ipv6 (&r6, tt,0 , es); +add_route_ipv6 (&r6, tt,0 , es,NULL ); }void
@@ -834,7 +834,7 @@ delete_route_connected_v6_net(struct tuntap *tt, r6.metric =0 ;/* connected route */ r6.flags =RT_DEFINED |RT_ADDED |RT_METRIC_DEFINED ;route_ipv6_clear_host_bits (&r6); - delete_route_ipv6(&r6, tt, 0, es); + delete_route_ipv6(&r6, tt, 0, es, NULL); }#endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) */
@@ -1170,7 +1170,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, r.netmask = tt->remote_netmask; r.gateway = tt->local; r.metric =0 ; - add_route(&r, tt, 0, NULL, es); + add_route(&r, tt, 0, NULL, es, NULL); }#elif defined(TARGET_OPENBSD)
@@ -1217,7 +1217,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, r.network = tt->local & tt->remote_netmask; r.netmask = tt->remote_netmask; r.gateway = remote_end; - add_route(&r, tt, 0, NULL, es); + add_route(&r, tt, 0, NULL, es, NULL); }#elif defined(TARGET_NETBSD)
@@ -1259,7 +1259,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, r.network = tt->local & tt->remote_netmask; r.netmask = tt->remote_netmask; r.gateway = remote_end; - add_route(&r, tt, 0, NULL, es); + add_route(&r, tt, 0, NULL, es, NULL); }#elif defined(TARGET_DARWIN)
@@ -1309,7 +1309,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, r.network = tt->local & tt->remote_netmask; r.netmask = tt->remote_netmask; r.gateway = tt->local; - add_route(&r, tt, 0, NULL, es); + add_route(&r, tt, 0, NULL, es, NULL); }#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
@@ -1348,7 +1348,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, r.network = tt->local & tt->remote_netmask; r.netmask = tt->remote_netmask; r.gateway = remote_end; - add_route(&r, tt, 0, NULL, es); + add_route(&r, tt, 0, NULL, es, NULL); }#elif defined(TARGET_AIX)
src/openvpn/tun.h +1 -1
@@ -275,7 +275,7 @@ void check_subnet_conflict(const in_addr_t ip,const in_addr_t netmask, const char *prefix); -void warn_on_use_of_common_subnets (void ); +void warn_on_use_of_common_subnets (openvpn_net_ctx_t *ctx);/* * Inline functions
Signature · 1 line
2.19.2
Re: [Openvpn-devel] [PATCH v3 4/7] route.c: use new networking API to handle routing table on Linux
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 4 lines
By switching to the networking API (for Linux) openvpn will now use any of the available implementations to handle the routing table.
[Openvpn-devel] [PATCH applied] Re: route.c: use new networking API to handle routing table on Linux
In reply to Antonio QuartulliYour patch has been applied to the master branch.
Tested with t_client test, one binary with --enable-iproute2, one without.
"Route add"-Diffs look nicely different, including the /128 bypass...
Wed Jun 5 11:09:02 2019 /bin/ip route add 194.97.144.0/24 via x.x.x.73 Wed Jun 5 11:09:02 2019 add_route_ipv6(2001:x:x:x::f000:11/128 -> fe80::250:43ff:fe01:dc37 metric 1) dev enp0s25 Wed Jun 5 11:09:02 2019 /bin/ip -6 route add 2001:x:x:x::f000:11/128 dev enp0s25 via fe80::250:43ff:fe01:dc37 metric 1 Wed Jun 5 11:09:02 2019 add_route_ipv6(2001:608::/32 -> 2001:x:x:x::1 metric -1) dev tun0 Wed Jun 5 11:09:02 2019 /bin/ip -6 route add 2001:608::/32 dev tun0
Wed Jun 5 11:09:21 2019 net_route_v4_add: 194.97.144.0/24 via x.x.x.73 dev [NULL] table 0 metric -1 Wed Jun 5 11:09:21 2019 add_route_ipv6(2001:x:x:x::f000:11/128 -> fe80::250:43ff:fe01:dc37 metric 1) dev enp0s25 Wed Jun 5 11:09:21 2019 net_route_v6_add: 2001:x:x:x::f000:11/128 via fe80::250:43ff:fe01:dc37 dev enp0s25 table 0 metric 1 Wed Jun 5 11:09:21 2019 add_route_ipv6(2001:608::/32 -> 2001:x:x:x::1 metric -1) dev tun0 Wed Jun 5 11:09:21 2019 net_route_v6_add: 2001:608::/32 via :: dev tun0 table 0 metric -1
.. but the resulting output of "ip route" + "ip -6 route" is exactly the same. Well done :-)
OTOH... :-) - looking at all the changes needed to transport &c->net_ctx, I wonder why you didn't just hide it in c->c1.tuntap, as we did for the windows socket... (tt->options.msg_channel). Almost everything related to "routing and ifconfig" needs to have the tt pointer available already today...
Warts:
+#else
+ const char *iface;
+ int metric;
+#endif
.. I think this really should be inside the #ifdef TARGET_LINUX block, not outside in an #else for an #if !defined(TARGET_LINUX)... so the code further down would then become
#if defined(TARGET_LINUX)
const char *ifcace = NULL;
if (is_on_link(...)).. having declaration and initialization in one place, and "where it belongs". Same thing for add_route_ipv6()...
+#if defined(TARGET_LINUX)
+ int metric;
+#endif
.. this is adding an extra #ifdef and taking 3 extra lines instead of just having "int metric = -1;" down where it's initialized.
delete_route() sports this beauty...
+#if !defined(TARGET_LINUX)
const char *network;
#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX)
const char *netmask;
#endif
#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
const char *gateway;+#endif
.. so you have two linux-specific defines (ENABLE_IPROUTE and TARGET_LINUX) *inside* an "#if !defined(TARGET_LINUX)"... plus the "metric" thing...
commit aec4a3d1b6a9e4d9e584b368126da061c15b174b
Author: Antonio Quartulli Date: Wed Dec 19 15:01:15 2018 +1000
route.c: use new networking API to handle routing table on Linux
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18029.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 5/7 route.c: use sitnl to implement get_default_gateway_ipv6()
In reply to Antonio Quartulliget_default_gateway_ipv6() has always been implemented using netlink, however, now that we have sitnl, we can re-use the latter and get rid of the netlink code from route.c.
--- src/openvpn/init.c | 9 +- src/openvpn/networking_iproute2.c | 2 +- src/openvpn/options.c | 2 +- src/openvpn/route.c | 161 ++++-------------------------- src/openvpn/route.h | 7 +- 5 files changed, 30 insertions(+), 151 deletions(-)
src/openvpn/init.c +6 -3
@@ -1463,7 +1463,8 @@ static void do_init_route_ipv6_list(const struct options *options, struct route_ipv6_list *route_ipv6_list, const struct link_socket_info *link_socket_info, - struct env_set *es) + struct env_set *es, + openvpn_net_ctx_t *ctx) { const char *gw = NULL;int metric =-1 ;/* no metric set */
@@ -1499,7 +1500,8 @@ do_init_route_ipv6_list(const struct options *options, gw, metric,link_socket_current_remote_ipv6 (link_socket_info ), - es)) + es, + ctx)) {/* copy routes to environment */ setenv_routes_ipv6 (es ,route_ipv6_list );
@@ -1759,7 +1761,8 @@ do_open_tun(struct context *c)if (c->options.routes_ipv6 && c->c1.route_ipv6_list) {do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, - &c->c2.link_socket->info, c->c2.es); + &c->c2.link_socket->info, c->c2.es, + &c->net_ctx); }/* do ifconfig */
src/openvpn/networking_iproute2.c +1 -1
@@ -375,7 +375,7 @@ net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,/* * The following function is not implemented in the iproute backend as it -* already uses netlink in route.c. +* uses the sitnl implementation from networking_sitnl.c. * * int * net_route_v6_best_gw(const struct in6_addr *dst, int prefixlen,
src/openvpn/options.c +1 -1
@@ -5014,7 +5014,7 @@ add_option(struct options *options, }net_ctx_init (NULL , &net_ctx);get_default_gateway (&rgi, &net_ctx); -get_default_gateway_ipv6 (&rgi6, &remote); +get_default_gateway_ipv6 (&rgi6, &remote, &net_ctx);print_default_gateway (M_INFO , &rgi, &rgi6);openvpn_exit (OPENVPN_EXIT_STATUS_GOOD );/* exit point */ }
src/openvpn/route.c +17 -144
209 lines not on this page · raw message
src/openvpn/route.h +5 -2
@@ -31,6 +31,7 @@#include "basic.h" #include "tun.h" #include "misc.h" +#include "networking.h" #ifdef _WIN32/*
@@ -291,7 +292,8 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,const char *remote_endpoint, int default_metric, const struct in6_addr *remote_host, - struct env_set *es); + struct env_set *es, + openvpn_net_ctx_t *ctx); void route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es,
@@ -323,7 +325,8 @@ void get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx);void get_default_gateway_ipv6 (struct route_ipv6_gateway_info *rgi, -const struct in6_addr *dest); +const struct in6_addr *dest, +openvpn_net_ctx_t *ctx); void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
Signature · 1 line
2.19.2
Re: [Openvpn-devel] [PATCH v3 5/7] route.c: use sitnl to implement get_default_gateway_ipv6()
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 4 lines
get_default_gateway_ipv6()has always been implemented using netlink, however, now that we have sitnl, we can re-use the latter and get rid of the netlink code fromroute.c.
[Openvpn-devel] [NAK] Re: route.c: use sitnl to implement get_default_gateway_ipv6()
In reply to Antonio QuartulliUnfortunately, I need to NAK this, because this will break some people's use of OpenVPN in an IPv6 context (namely, where the OpenVPN server is sitting in the same LAN as the client - think "EduRoam WiFi").
I did the same thing as before - built an iproute2 binary and a sitnl binary, and tested t_client plus some manual commands.
Under some conditions, the output is *differen*, and this is very bad.
Here's the output of "openvpn --show-gateway" for my local network...
iproute2 build:
Wed Jun 5 12:04:53 2019 ROUTE6_GATEWAY fe80::250:43ff:fe01:dc37 IFACE=enp0s25
sitnl build:
Wed Jun 5 12:04:56 2019 ROUTE6_GATEWAY fe80::250:43ff:fe01:dc37 ON_LINK IFACE=enp0s25
which I find surprising, since they should both use the same backend now...? "Older binaries" print the gateway without ON_LINK.
It gets weirder... if I ask for something which actually *is* on-link (another address out of my on-link subnet), I get the same thing:
$ src/openvpn/openvpn --show-gateway 2001:608:4::1
iproute2 build:
Wed Jun 5 12:19:37 2019 ROUTE6_GATEWAY :: IFACE=enp0s25
sitnl build:
Wed Jun 5 12:18:20 2019 ROUTE6_GATEWAY :: ON_LINK IFACE=enp0s25 HWADDR=00:00:00:00:54:57
and *sometimes*
Wed Jun 5 12:19:56 2019 ROUTE6_GATEWAY :: IFACE=enp0s25
while my old code alwyays prints
Wed Jun 5 12:24:51 2019 ROUTE6_GATEWAY 2001:608:4::1 ON_LINK IFACE=enp0s25
("what you are looking for is on this link and it is the gateway").
This is a regression and needs to be fixed -> so, NAK.
On-Link targets always need to have ON_LINK set for both builds, off-link targets (if there exists a default-gateway) must never have it set, and the gateway address should.
I have no idea what is going wrong here, because both implementations should behave exactly the same, since they use the same backend - but this smells like "something is not correct, and it depends on build or run-time factors". Maybe something isn't properly initialized when rewriting this... the bug is not in code that is introduced by this patch (it's hiding in networking_sitnl.c, I assume) but this patch is what activates the code path,
A few comments on the actual code changes :-) - the introduction of *ctx here cannot be avoided.
This strikes me as a bit funky, though...
+ struct in_addr gw;
+ CLEAR(gw);
.. and then "gw" is not used at all?
The introduction of a "flags" temporary variable can be certainly be argued about (I find it less readable for a one-shot comparison), but if you do, why not define it where it's used (C99)?
While at it, please kick out the definition of "struct rtreq" in route.c, right above the TARGET_LINUX get_default_gateway_ipv6() - no longer needed since we do not do the netlink stuff here anymore.
thanks,
gert
--
kind regards,
Gert Doering
PATCH v4 1/1 route.c: use sitnl to implement get_default_gateway_ipv6()
From: Antonio Quartulli <[email protected]...>
get_default_gateway_ipv6() has always been implemented using netlink, however, now that we have sitnl, we can re-use the latter and get rid of the netlink code from route.c.
---
Changes from v1:
- use IN6_IS_ADDR_UNSPECIFIED to check if GW address is specified. This fixes the issue of never setting the ON_LINK flag for IPv6 routes
src/openvpn/init.c | 9 +- src/openvpn/networking_iproute2.c | 2 +- src/openvpn/options.c | 2 +- src/openvpn/route.c | 163 ++++-------------------------- src/openvpn/route.h | 7 +- 5 files changed, 31 insertions(+), 152 deletions(-)
src/openvpn/init.c +6 -3
@@ -1486,7 +1486,8 @@ static void do_init_route_ipv6_list(const struct options *options, struct route_ipv6_list *route_ipv6_list, const struct link_socket_info *link_socket_info, - struct env_set *es) + struct env_set *es, + openvpn_net_ctx_t *ctx) { const char *gw = NULL;int metric =-1 ;/* no metric set */
@@ -1522,7 +1523,8 @@ do_init_route_ipv6_list(const struct options *options, gw, metric,link_socket_current_remote_ipv6 (link_socket_info ), - es)) + es, + ctx)) {/* copy routes to environment */ setenv_routes_ipv6 (es ,route_ipv6_list );
@@ -1782,7 +1784,8 @@ do_open_tun(struct context *c)if (c->options.routes_ipv6 && c->c1.route_ipv6_list) {do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, - &c->c2.link_socket->info, c->c2.es); + &c->c2.link_socket->info, c->c2.es, + &c->net_ctx); }/* do ifconfig */
src/openvpn/networking_iproute2.c +1 -1
@@ -375,7 +375,7 @@ net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,/* * The following function is not implemented in the iproute backend as it -* already uses netlink in route.c. +* uses the sitnl implementation from networking_sitnl.c. * * int * net_route_v6_best_gw(const struct in6_addr *dst, int prefixlen,
src/openvpn/options.c +1 -1
@@ -5012,7 +5012,7 @@ add_option(struct options *options, }net_ctx_init (NULL , &net_ctx);get_default_gateway (&rgi, &net_ctx); -get_default_gateway_ipv6 (&rgi6, &remote); +get_default_gateway_ipv6 (&rgi6, &remote, &net_ctx);print_default_gateway (M_INFO , &rgi, &rgi6);openvpn_exit (OPENVPN_EXIT_STATUS_GOOD );/* exit point */ }
src/openvpn/route.c +18 -145
217 lines not on this page · raw message
src/openvpn/route.h +5 -2
@@ -31,6 +31,7 @@#include "basic.h" #include "tun.h" #include "misc.h" +#include "networking.h" #ifdef _WIN32/*
@@ -291,7 +292,8 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,const char *remote_endpoint, int default_metric, const struct in6_addr *remote_host, - struct env_set *es); + struct env_set *es, + openvpn_net_ctx_t *ctx); void route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es,
@@ -323,7 +325,8 @@ void get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx);void get_default_gateway_ipv6 (struct route_ipv6_gateway_info *rgi, -const struct in6_addr *dest); +const struct in6_addr *dest, +openvpn_net_ctx_t *ctx); void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
Signature · 1 line
2.22.0
Re: [Openvpn-devel] [PATCH v4] route.c: use sitnl to implement get_default_gateway_ipv6()
Hi,
Quoted 4 lines · Antonio Quartulli
Changes from v1:
- useIN6_IS_ADDR_UNSPECIFIEDto check if GW address is specified. This fixes the issue of never setting theON_LINKflag for IPv6 routes
Something is still not working correctly.
It *must not* set the ON_LINK flag for routes that are behind a gatway ("route to gateway" vs. "route to interface"), but it still does.
Here's what I tested:
- my home network has 2001:608:4:0::/64 on link
- I have set up a route fd00:eeee:200::/48 -> tun0 (no gateway)
- default gateway is either statically configured (FreeBSD) or learned from RA (linux)
- I asked openvpn the following question:
openvpn --show-gateway
openvpn --show-gateway 2001:608::2
openvpn --show-gateway 2001:608:4::123
openvpn --show-gateway fd00:eeee:200::1
the first is "find me the way to reach ::", which is via default gateway (and the target is not ON_LINK), the second is "find me the way to this particular IPv6 address" - which is also via default gateway (here), and not ON_LINK.
The third is "find me the way to reach 2001:608:4::123", which is another host on the LAN, so packets for this IPv6 address must be sent "towards the LAN" not "to a gateway" -> this is ON_LINK.
The fourth is something of an oddball, point to point interfaces do not have neighbour discovery - so all routes to a gateway *behind* a p2p interface are also "ON_LINK", as there is no gateway we could put into a route.
Now, this is what OpenVPN 2.4.7 prints here (or master "with no patch") (leaving off IPv4):
$ openvpn247 --show-gateway Sun Jul 14 21:51:09 2019 ROUTE6_GATEWAY fe80::250:43ff:fe01:dc37 IFACE=enp0s25 $ openvpn247 --show-gateway 2001:608::2 Sun Jul 14 21:51:22 2019 ROUTE6_GATEWAY fe80::250:43ff:fe01:dc37 IFACE=enp0s25 $ openvpn247 --show-gateway 2001:608:4::123 Sun Jul 14 21:51:33 2019 ROUTE6_GATEWAY 2001:608:4::123 ON_LINK IFACE=enp0s25 $ openvpn247 --show-gateway fd00:eeee:200::1 Sun Jul 14 21:52:14 2019 ROUTE6_GATEWAY fd00:eeee:200::1 ON_LINK IFACE=tun0
and this is what OpenVPN master + your patch prints
$ src/openvpn/openvpn --show-gateway Sun Jul 14 21:42:25 2019 ROUTE6_GATEWAY fe80::250:43ff:fe01:dc37 ON_LINK IFACE=enp0s25 HWADDR=00:00:00:00:54:97 $ src/openvpn/openvpn --show-gateway 2001:608::2 Sun Jul 14 21:46:02 2019 ROUTE6_GATEWAY fe80::250:43ff:fe01:dc37 ON_LINK IFACE=enp0s25 HWADDR=00:00:00:00:54:b7 $ src/openvpn/openvpn --show-gateway 2001:608:4::123 Sun Jul 14 21:42:51 2019 ROUTE6_GATEWAY 2001:608:4::123 ON_LINK IFACE=enp0s25 $ src/openvpn/openvpn --show-gateway fd00:eeee:200::1 Sun Jul 14 21:42:59 2019 ROUTE6_GATEWAY fd00:eeee:200::1 ON_LINK IFACE=tun0 HWADDR=00:00:00:00:54:87
as you can see, it now insists on "everything is ON_LINK".
Now... I think the issue might be just that you removed the
- CLEAR(*rgi6);
bit, so "there is cruft in that structure, and it is flagged as 'the ON_LINK bit is set'" - but it's too late for me to do a full code review, so can't say for sure. If I just add it back, it behaves correctly, but it would be good to give this function another long and hard stare...
However - as it is today, I need to NAK this. Sorry. (And I should have been much quicker)
gert
(PS: FreeBSD is, as expected, showing the same things before/after, with ON_LINK only for test 3+4 - but that's a totally different code path, so no surprises here)
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 v4] route.c: use sitnl to implement get_default_gateway_ipv6()
Hi,
Quoted 3 lines · Gert Doering
It *must not* set the
ON_LINKflag for routes that are behind a gatway ("route to gateway" vs. "route to interface"), but it still does.
[SKIP SKIP]
Quoted 3 lines
as you can see, it now insists on "everything is
ON_LINK".
interesting to note that on my test machine I don't see this behaviour. ON_LINK is returned only when appropriate.
Quoted 11 lines
Now... I think the issue might be just that you removed the
-
CLEAR(*rgi6);bit, so "there is cruft in that structure, and it is flagged as 'the
ON_LINKbit is set'" - but it's too late for me to do a full code review, so can't say for sure. If I just add it back, it behaves correctly, but it would be good to give this function another long and hard stare...
This makes a lot of sense: that CLEAR() statement has been removed by accident.
And honestly this missing initialization is somewhat compatible with not always seeing the problem (initialization of stack variables may differ on different platforms based on compiler version, kernel options, etc..).
Actually I also realized that the 'gw' variable introduced next to this line was not used, so I have got rid of it.
Quoted 2 lines
However - as it is today, I need to NAK this. Sorry. (And I should have been much quicker)
No worries. v5 incoming!!
Cheers,
Quoted 7 lines
gert
(PS: FreeBSD is, as expected, showing the same things before/after, with
ON_LINKonly for test 3+4 - but that's a totally different code path, so no surprises here)
Signature · 1 line
Antonio Quartulli
PATCH v5 1/1 route.c: use sitnl to implement get_default_gateway_ipv6()
In reply to Gert DoeringFrom: Antonio Quartulli <[email protected]...>
get_default_gateway_ipv6() has always been implemented using netlink, however, now that we have sitnl, we can re-use the latter and get rid of the netlink code from route.c.
---
Changes from v1:
- use IN6_IS_ADDR_UNSPECIFIED to check if GW address is specified. This fixes the issue of never setting the ON_LINK flag for IPv6 routes
Changes from v4:
- get_default_gateway_ipv6(): get rid of unused 'gw' variable
- get_default_gateway_ipv6(): CLEAR rgi6 object before usage
src/openvpn/init.c | 9 +- src/openvpn/networking_iproute2.c | 2 +- src/openvpn/options.c | 2 +- src/openvpn/route.c | 160 +++--------------------------- src/openvpn/route.h | 7 +- 5 files changed, 29 insertions(+), 151 deletions(-)
src/openvpn/init.c +6 -3
@@ -1486,7 +1486,8 @@ static void do_init_route_ipv6_list(const struct options *options, struct route_ipv6_list *route_ipv6_list, const struct link_socket_info *link_socket_info, - struct env_set *es) + struct env_set *es, + openvpn_net_ctx_t *ctx) { const char *gw = NULL;int metric =-1 ;/* no metric set */
@@ -1522,7 +1523,8 @@ do_init_route_ipv6_list(const struct options *options, gw, metric,link_socket_current_remote_ipv6 (link_socket_info ), - es)) + es, + ctx)) {/* copy routes to environment */ setenv_routes_ipv6 (es ,route_ipv6_list );
@@ -1782,7 +1784,8 @@ do_open_tun(struct context *c)if (c->options.routes_ipv6 && c->c1.route_ipv6_list) {do_init_route_ipv6_list (&c->options, c->c1.route_ipv6_list, - &c->c2.link_socket->info, c->c2.es); + &c->c2.link_socket->info, c->c2.es, + &c->net_ctx); }/* do ifconfig */
src/openvpn/networking_iproute2.c +1 -1
@@ -375,7 +375,7 @@ net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,/* * The following function is not implemented in the iproute backend as it -* already uses netlink in route.c. +* uses the sitnl implementation from networking_sitnl.c. * * int * net_route_v6_best_gw(const struct in6_addr *dst, int prefixlen,
src/openvpn/options.c +1 -1
@@ -5012,7 +5012,7 @@ add_option(struct options *options, }net_ctx_init (NULL , &net_ctx);get_default_gateway (&rgi, &net_ctx); -get_default_gateway_ipv6 (&rgi6, &remote); +get_default_gateway_ipv6 (&rgi6, &remote, &net_ctx);print_default_gateway (M_INFO , &rgi, &rgi6);openvpn_exit (OPENVPN_EXIT_STATUS_GOOD );/* exit point */ }
src/openvpn/route.c +16 -144
215 lines not on this page · raw message
src/openvpn/route.h +5 -2
@@ -31,6 +31,7 @@#include "basic.h" #include "tun.h" #include "misc.h" +#include "networking.h" #ifdef _WIN32/*
@@ -291,7 +292,8 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,const char *remote_endpoint, int default_metric, const struct in6_addr *remote_host, - struct env_set *es); + struct env_set *es, + openvpn_net_ctx_t *ctx); void route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es,
@@ -323,7 +325,8 @@ void get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx);void get_default_gateway_ipv6 (struct route_ipv6_gateway_info *rgi, -const struct in6_addr *dest); +const struct in6_addr *dest, +openvpn_net_ctx_t *ctx); void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
Signature · 1 line
2.22.0
[Openvpn-devel] [PATCH applied] Re: route.c: use sitnl to implement get_default_gateway_ipv6()
Passes the manual "--show-gateway <thing>" test now, and survived staring-at-the-code. Though that one turned up things elsewhere that I do not like very much (but which have already been merged) - see next mail.
I said before I'm not a big fan of having an "int flags" declaration at the beginning of a function for a single-use helper variable further down - C99 permits "int flags = ..." right where the thing is needed, and I find that much more readable (I wouldn't introduce "flags" at all, but if you do, having to look in two places "what is this? is this used anywhere else?" is more review effort). But you ignored that comment, and I'm not disliking this enough for a NAK.
Your patch has been applied to the master branch.
commit c454b21e7ce458ce6f5bcaf6c313ab3ba3dd5baf
Author: Antonio Quartulli Date: Mon Jul 15 16:46:09 2019 +0200
route.c: use sitnl to implement get_default_gateway_ipv6()
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18667.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v5] route.c: use sitnl to implement get_default_gateway_ipv6()
In reply to Antonio QuartulliHi,
Quoted 7 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]...>
get_default_gateway_ipv6()has always been implemented using netlink, however, now that we have sitnl, we can re-use the latter and get rid of the netlink code fromroute.c.Signed-off-by Antonio Quartulli <[email protected]...>
Yeah, thanks.
This particular patch is ok now, but it is calling functions that are no save to call. So, fixing needed. (I considered on whether to NAK this again, but since it is safe *today*, this is more for the work queue of cleanup to do).
Down in networking_sitnl.c, in sitnl_route_best_gw(), you do
strcpy(best_iface, res.iface);
which *today* is safe, because best_iface is "char[16]" and res.iface is "char[IFNAMSIZ]", which happens to be 16 on linux *today*. Now what if folks decide "we need longer names, because docker? or anything?" - bam. This needs to be a strncpy(). Or "struct route_ipv6_gateway_info" -> iface needs to be [IFNAMSIZ] with an preceding "#ifndef IFNAMSIZ, #define IFNAMSIZ 16" for platforms that do not have said define...
Or something else to guarantee that you never overflow *best_iface.
Then, I'm a bit sad that your sitnl_route_best_gw() code pretty much lacks all documentation about what it *does*. My code in route.c that talks to netlink had quite a bit of explanations on "why a certain value is set in a certain way"...
rtreq.nh.nlmsg_type = RTM_GETROUTE;
rtreq.nh.nlmsg_flags = NLM_F_REQUEST; /* best match only */
rtreq.rtm.rtm_family = AF_INET6;
rtreq.rtm.rtm_src_len = 0; /* not source dependent */
rtreq.rtm.rtm_dst_len = 128; /* exact dst */
rtreq.rtm.rtm_table = RT_TABLE_MAIN;
rtreq.rtm.rtm_protocol = RTPROT_UNSPEC;while your code leaves off initialization for "anything that is default anyway" and just magically copies in values for the rest - including "0" for "rtm_dst_len" (both callers pass in "0" for prefixlen, which doesn't match the documentation I've read, back then, that says you must pass in a full prefix length for an exact route match - and if you pass in 0 anyway, why carry a prefixlen argument at all??).
The rtm_dst_len puzzles me, to be honest... either I misread the documentation, or this is ignored by the kernel... the way I understood this, it's the number of bits that is matched in the address, so "0" would pretty much mean "match any route" - but what it returns is correct, so it's not doing "match any". *scratch head*.
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 v3 6/7 unit tests: implement test for sitnl
In reply to Antonio QuartulliThis patch introduces a new unit test that is not executed by the cmocka framework, but rather used by a new t_net.sh bash script.
The idea behind this test is to ensure that invoking sitnl functions or running iproute commands leads to the same networking (interface and routing table) state.
To achieve this, the t_net.sh script first runs a binary implemented invoking sitnl functions and then takes a "screenshot" of the state. Subsequently a series of iproute commands, expected to mimic exactly the same behaviour as the sitnl functions invoked before, are executed. The final state is then compared with the screenshot previously taken.
If no mismatching is found, the test is passed.
The current unit_test, however, does not cover all the sitnl functionalities and it is expected to be extended in the future.
--- configure.ac | 2 + tests/Makefile.am | 3 +- tests/t_net.sh | 180 ++++++++++++++++ tests/unit_tests/openvpn/Makefile.am | 30 ++- tests/unit_tests/openvpn/test_networking.c | 229 +++++++++++++++++++++ 5 files changed, 438 insertions(+), 6 deletions(-) create mode 100755 tests/t_net.sh create mode 100644 tests/unit_tests/openvpn/test_networking.c
configure.ac +2 -0
@@ -294,9 +294,11 @@ else fi AC_DEFINE_UNQUOTED([TARGET_ALIAS], ["${host}"], [A string representing our host]) +AM_CONDITIONAL([TARGET_LINUX], [false]) case "$host" in *-*-linux*) AC_DEFINE([TARGET_LINUX], [1], [Are we running on Linux?]) + AM_CONDITIONAL([TARGET_LINUX], [true]) AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["L"], [Target prefix]) have_sitnl="yes" ;;
tests/Makefile.am +2 -1
@@ -14,7 +14,8 @@ MAINTAINERCLEANFILES = \ SUBDIRS = unit_tests -test_scripts = t_client.sh +test_scripts = t_net.sh +test_scripts += t_client.sh test_scripts += t_lpback.sh t_cltsrv.sh TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)"
tests/t_net.sh new file +180 -0
180 lines not on this page · raw message
tests/unit_tests/openvpn/Makefile.am +25 -5
@@ -1,17 +1,22 @@ AUTOMAKE_OPTIONS = foreign -check_PROGRAMS= +test_binaries= if HAVE_LD_WRAP_SUPPORT -check_PROGRAMS += argv_testdriver buffer_testdriver +test_binaries += argv_testdriver buffer_testdriver endif -check_PROGRAMS += crypto_testdriver packet_id_testdriver +test_binaries += crypto_testdriver packet_id_testdriver if HAVE_LD_WRAP_SUPPORT -check_PROGRAMS += tls_crypt_testdriver +test_binaries += tls_crypt_testdriver endif -TESTS = $(check_PROGRAMS) +TESTS = $(test_binaries) +check_PROGRAMS = $(test_binaries) + +if TARGET_LINUX +check_PROGRAMS += networking_testdriver +endif openvpn_includedir = $(top_srcdir)/include openvpn_srcdir = $(top_srcdir)/src/openvpn
@@ -68,3 +73,18 @@ tls_crypt_testdriver_SOURCES = test_tls_crypt.c mock_msg.c \ $(openvpn_srcdir)/packet_id.c \ $(openvpn_srcdir)/platform.c \ $(openvpn_srcdir)/run_command.c + +networking_testdriver_CFLAGS = @TEST_CFLAGS@ \ + -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \ + $(OPTIONAL_CRYPTO_CFLAGS) +networking_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(openvpn_srcdir) \ + $(OPTIONAL_CRYPTO_LIBS) +networking_testdriver_SOURCES = test_networking.c mock_msg.c \ + $(openvpn_srcdir)/networking_sitnl.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/crypto.c \ + $(openvpn_srcdir)/crypto_mbedtls.c \ + $(openvpn_srcdir)/crypto_openssl.c \ + $(openvpn_srcdir)/otime.c \ + $(openvpn_srcdir)/packet_id.c \ + $(openvpn_srcdir)/platform.c
tests/unit_tests/openvpn/test_networking.c new file +229 -0
229 lines not on this page · raw message
Signature · 1 line
2.19.2
Re: [Openvpn-devel] [PATCH v3 6/7] unit tests: implement test for sitnl
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 16 lines
This patch introduces a new unit test that is not executed by the cmocka framework, but rather used by a new
t_net.shbash script.The idea behind this test is to ensure that invoking sitnl functions or running iproute commands leads to the same networking (interface and routing table) state.
To achieve this, the
t_net.shscript first runs a binary implemented invoking sitnl functions and then takes a "screenshot" of the state. Subsequently a series of iproute commands, expected to mimic exactly the same behaviour as the sitnl functions invoked before, are executed. The final state is then compared with the screenshot previously taken.
Quoted 6 lines
If no mismatching is found, the test is passed.
The current
unit_test, however, does not cover all the sitnl functionalities and it is expected to be extended in the future.
I first wanted to make a remark about the usage of seq but trying to run the test on OpenBSD is pointless anyway, so:
[Openvpn-devel] [PATCH applied] Re: unit tests: implement test for sitnl
In reply to Antonio QuartulliYour patch has been applied to the master branch.
Since this is not depending on 5/7, no reason to stall - so, here we are.
Comments...
- it's sourcing t_client.rc, but only for the SUDO definition - this is a bit confusing, and might warrant a comment in the script
- maybe make this a bit more verbose what it does?
make check-TESTS
make[4]: Entering directory '/rhome/gert/src/openvpn-maint/test-build-master-ossl111/tests'
PASS: t_net.sh
(all our other tests print "test this, ok, test that, ok", which I find good feedback)
- maybe feed the list of things to test from a "t_net.rc" file, so you can more easily extend the test set (when developing)? Right now, the test is hardcoded in the C source, but the script needs to know how many tests there are to call them in sequence...
- "make check" in an --enable-iproute2 build fails like this:
./../openvpn/tests/t_net.sh: eval: line 150: syntax error near unexpected token ;' ./../openvpn/tests/t_net.sh: eval: line 150: ;'
FAIL: t_net.sh
I expected it to fail in some interesting way, but this looks like it at least needs more sanity checking on setting of $OUT and $CMD (or maybe fail more explicitly for non-sitnl builds).
- code wise:
t_scripts = t_client.sh
+test_scripts = t_net.sh
+test_scripts += t_client.sh
test_scripts += t_lpback.sh t_cltsrv.sh
... why are we having two lines that add one script each and one line that adds two scripts here? Why not just "one line for all"?
- if you want bash, ask for bash...
+#!/bin/sh
..
+# Note: statements in the rest of the script may not even pass syntax check on +# solaris/bsd. It uses /bin/bash
/bin/sh on Linux will not always be bash (dash on Debian, for example), so either do not use bash features, or ask for /bin/bash.
- comments taken over verbatim from t_client.sh are more confusing than useful here:
+# make sure we have permissions to run ifconfig/route from OpenVPN +# can't use "id -u" here - doesn't work on Solaris
- all the KILL_EXEC stuff should be removed from t_net.sh - you never run "sudo kill <something>", so don't carry over that code (we need to explicitely test this in t_client.sh because otherwise we might end up with openvpn binaries that we have started in the background and cannot kill anymore - "sudo openvpn" allowed, but "sudo kill" not allowed)
- in the tests: good practice is to always use 2001:db8::/32 for "demo and testing", not addresses that might be assigned to someone else one day. But also use an ULA network (fdxx:xxxx:xxxx::/48, with "xx" selected by rolling a dice) in case "something" handles these differently - ULA is the new RFC1918 stuff, globally unique but still not routed.
commit c4d5bcd7c90abbab2378ac865e326933b0ff1e1c
Author: Antonio Quartulli Date: Wed Dec 19 15:01:17 2018 +1000
unit tests: implement test for sitnl
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18027.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: unit tests: implement test for sitnl
Hi,
t_net.sh definitely needs more polishing... I see quite a bit of buildbot explosions after this last commit. Some of these look like "why...?"
./t_net.sh: sudo /usr/bin/kill -0 succeeded, good.
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified unit-test 0 errored out:
FAIL: t_net.sh
... so it really shouldn't check whether "kill" works, but whether the "sudo $mytestprogram" works... (and the buildslaves need to be adjusted to permit this extra path) - and if not, make this a SKIP, not a FAIL.
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 v3 7/7 travis.yml: add test for iproute2 net implementation
In reply to Antonio Quartulli--- .travis.yml | 3 +++ 1 file changed, 3 insertions(+)
.travis.yml +3 -0
@@ -33,6 +33,9 @@ matrix: - env: SSLLIB="openssl" OPENSSL_VERSION="1.1.0h" os: linux compiler: gcc + - env: SSLLIB="openssl" EXTRA_CONFIG="--enable-iproute2" + os: linux + compiler: gcc - env: SSLLIB="openssl" CFLAGS="-fsanitize=address" os: linux compiler: clang
Signature · 1 line
2.19.2
Re: [Openvpn-devel] [PATCH v3 7/7] travis.yml: add test for iproute2 net implementation
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 11 lines
Signed-off-by Antonio Quartulli <[email protected]...>--- .travis.yml | 3 +++ 1 file changed, 3 insertions(+).travis.yml +0
-0
.travis.yml matrix: · line 41
Quoted 9 lines
.travis.yml +3
-0@@ -33,6 +33,9 @@ matrix: - env: SSLLIB="openssl" OPENSSL_VERSION="1.1.0h" os: linux compiler: gcc + - env: SSLLIB="openssl" EXTRA_CONFIG="--enable-iproute2" + os: linux + compiler: gcc - env: SSLLIB="openssl" CFLAGS="-fsanitize=address" os: linux compiler: clang
[Openvpn-devel] [PATCH applied] Re: travis.yml: add test for iproute2 net implementation
In reply to Antonio QuartulliYour patch has been applied to the master branch.
Sufficiently trivial and independent of piece 4+5+6 that I applied this in between. Failed, of course, because the context of .travis.yml got modified in between... we really need to focus our development on "one large thing at a time"...
commit d595562d946aec4811ac0deffff0770fb9c32a21
Author: Antonio Quartulli Date: Wed Dec 19 15:01:18 2018 +1000
travis.yml: add test for iproute2 net implementation
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18032.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Am 19.12.18 um 06:01 schrieb Antonio Quartulli:
Quoted 4 lines
From a high level description of this patchset, please refer to "[PATCH 0/4] add netlink support for Linux" sent to the mailing list on Apr, 20th 2018.
This patch set seem to be missing the commit
implement platform generic networking API
from the v1 of the patch set, so I will review the v1 instead again as it looks it is still identical in your git tree.
Arne
PATCH v3 1/1 implement platform generic networking API
In reply to Antonio Quartullitun.c and route.c contain all the code used by openvpn to manage the tun interface and the routing table on all the supported platforms.
Across the years, this resulted in a longer functions and series of ifdefs.
This patch introduces a new "networking API" which aims at creating a simple abstraction between the tun/route logic and the platform dependent code.
The is API expected to be implemented outside of tun.c/route.c by using platform specific functionalities.
--- src/openvpn/Makefile.am | 1 + src/openvpn/networking.h | 278 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 src/openvpn/networking.h
src/openvpn/Makefile.am +1 -0
@@ -80,6 +80,7 @@ openvpn_SOURCES = \ mtu.c mtu.h \ mudp.c mudp.h \ multi.c multi.h \ + networking.h \ ntlm.c ntlm.h \ occ.c occ.h \ openssl_compat.h \
src/openvpn/networking.h new file +278 -0
278 lines not on this page · raw message
Signature · 1 line
2.21.0
Gert Doering
NAKRe: [Openvpn-devel] [PATCH v3 -1/7] implement platform generic networking API
Hi,
src/openvpn/networking.h line 38
Quoted 5 lines · Antonio Quartulli
src/openvpn/networking.h new file +5
-0+#ifdef ENABLE_SITNL +#include "networking_sitnl.h" +#elif ENABLE_IPROUTE +#include "networking_ip.h" +#else
NAK, this patch breaks compilation - there is no "networking_ip.h" in our tree, and this patch isn't introducing it either.
If we need this together with 1/7 of the v3 series, maybe we really need to make this into a joint "1/7 v4"... but every single patch needs to compile (on mainstream platforms).
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]...Gert Doering
Acked-byRe: [Openvpn-devel] [PATCH v3 -1/7] implement platform generic networking API
Hi,
Quoted 9 lines · Gert Doering
src/openvpn/networking.h line 38
Quoted 5 lines · Antonio Quartulli
src/openvpn/networking.h new file +5
-0+#ifdef ENABLE_SITNL +#include "networking_sitnl.h" +#elif ENABLE_IPROUTE +#include "networking_ip.h" +#else NAK, this patch breaks compilation - there is no "
networking_ip.h" in our tree, and this patch isn't introducing it either.
Oh well. It doesn't break compilation, as networking.h is not yet included anywhere. And "1/7 v3" fixes the include.
So while this is a slightly confusing commit, it won't *break* anything and I'll merge it ASAP.
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]...[Openvpn-devel] [PATCH applied] Re: implement platform generic networking API
In reply to Antonio QuartulliThis patch does not actually *do* anything - it just brings in a new file (networking.h) with the new API. The file wouldn't compile because it references not-yet-existing other .h files, so the patch is a bit confusing - but since the rest of the series has ACKs and needs this prequel, here we go.
Your patch has been applied to the master branch.
Note: I think "networking.h" and "networking_iproute2.h" are very long file names (and are hurting my sense for aesthetics) so I suggest we rename those to "net.h" and "net_<method>.h" afterwards - not the most elegant approach but I do not want to hold up the series any longer.
Note2: when this is in, I want us to drop support for ifconfig/route on Linux, and get rid of --enable-iproute2 (this would become the fallback if --enable-sitnl is not set). Two options are enough.
commit 3d26593736982852fcf277b541da38b4c3cc7fc8
Author: Antonio Quartulli Date: Tue May 14 10:11:59 2019 +0200
implement platform generic networking API
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]/msg18458.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering