Skip to contentSkip to conversation

Fix for NetBSD with subnet topology

Openvpn-devel Adam 4 participants 11 messages Jul 18, 2018 – Aug 9, 2018

lore
Share & tools
lore

Adam

author
#0 lore raw

Greetings,

It turns out, NetBSD needs similar handling of subnet topology for tun interfaces as OpenBSD does.

Here is a patch to fix the issue (against OpenVPN 2.4.6):

Kind regards,
Adam

#1 lore raw

Hello Adam,

thanks for your change.

could you please submit the patch in proper git format so that it can be easily applied?

You can create a patch like that by using the "git format-patch" command after you have commited your changes (you need to clone the git repository for that).

After creating the patch file, you can send it with either "git send-email" (preferred) or by attaching it to your email.

Please, don't forget the "Signed-off-by:" line at the end of your commit message.

On top of all this, is there a way to explain in a few words why this is now required (should go in the commit message)? Or "it just works this way"?

Thanks a lot.

Regards,

Quoted 26 lines · Adam

Greetings,

It turns out, NetBSD needs similar handling of subnet topology for tun interfaces as OpenBSD does.

Here is a patch to fix the issue (against OpenVPN 2.4.6):

Kind regards,
Adam

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
Antonio Quartulli
#2 lore raw
In reply to Adam

Hi,

Quoted 3 lines · Adam

It turns out, NetBSD needs similar handling of subnet topology for tun interfaces as OpenBSD does.

Here is a patch to fix the issue (against OpenVPN 2.4.6):

This comes as a bit of surprise - has something changed here on the NetBSD side? Which NetBSD version did you test this against, how does the problem manifest itself?

I do run CI tests on various NetBSD versions, and never had an issue with --topology subnet there...

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]...
#3 lore raw
Quoted 10 lines
Quoted 3 lines

It turns out, NetBSD needs similar handling of subnet topology for tun interfaces as OpenBSD does.

Here is a patch to fix the issue (against OpenVPN 2.4.6):

This comes as a bit of surprise - has something changed here on the NetBSD side? Which NetBSD version did you test this against, how does the problem manifest itself?

I do run CI tests on various NetBSD versions, and never had an issue with --topology subnet there...

I tried both NetBSD-7.1 and NetBSD-current (which is now at 8.99.21), and my OpenVPN setup does not work without the patch. On server side, I use a simple config like this (certificate sections omitted):

local 192.168.56.1
proto tcp-server
dev tun
topology subnet
persist-tun
persist-key

server 10.1.0.0 255.255.0.0
client-config-dir /dist/pkg/etc/openvpn/ccd

tls-server
tls-auth static.key 0

On client side (NetBSD) it looks like this:

remote 192.168.56.1 1194
proto tcp-client
dev tun
persist-tun
persist-key

tls-client
nobind
remote-cert-tls server
tls-auth static.key 1
auth-nocache
pull

tun0 interface and routing are configured as these:

% ifconfig tun0
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500

	inet 10.1.0.2 -> 10.1.0.2 netmask 0xffff0000
	inet6 fe80::a00:27ff:fef1:6df7%tun0 ->  prefixlen 64 scopeid 0x4

% route -n show | grep 10.1
10.1.0.2 10.1.0.2 UH - - - tun0

and the VPN network is unreachable (e.g. can't ping 10.1.0.1). However, with the patch applied, the network looks this:

% ifconfig tun0
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500

	inet 10.1.0.2 -> 10.1.0.1 netmask 0xffff0000
	inet6 fe80::a00:27ff:fef1:6df7%tun0 ->  prefixlen 64 scopeid 0x4
% route -n show | grep 10.1
10.1/16            10.1.0.1           UG          -        -      -  tun0
10.1.0.1           10.1.0.2           UH          -        -      -  tun0

and VPN works correctly.

Hoping that clarifies your concern. :)

Kind regards,
Adam

#4 lore raw

Hi,

Quoted 1 line · Adam

Hoping that clarifies your concern. :)

It leaves me a bit puzzled, to be honest... our buildbots *should* have caught it (NetBSD 5.1/amd64 and NetBSD 7.0.1/i386), as it runs a "topology subnet" test and tries to ping the remote IP and something "behind" it...

If I run the test by hand, it does indeed fail.

...
Mon Jul 23 17:28:43 2018 /sbin/ifconfig tun1 10.194.3.14 10.194.3.14 mtu 1500 netmask 255.255.255.0 up Mon Jul 23 17:28:43 2018 /sbin/route add -net 10.194.0.0 10.194.3.1 -netmask 255.255.255.0

nbsd70$ netstat -rn |grep 10.194

10.194.0/24        10.194.3.1         UGS         -        -      -  tun1
10.194.3.14        10.194.3.14        UH          -        -      -  tun1

nbsd70$ ping 10.194.3.1
PING 10.194.3.1 (10.194.3.1): 56 data bytes
^C
----10.194.3.1 PING Statistics----
5 packets transmitted, 0 packets received, 100.0% packet loss

Now, two actions on me...

... figure out why the NetBSD buildslaves did not detect the problem in the first place (most likely "not running the remote client test suite due to mistakes in setting up things")

... test your patch and get it in :-)

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]...
#5 lore raw
In reply to Adam

Hi,

Quoted 3 lines · Adam

It turns out, NetBSD needs similar handling of subnet topology for tun interfaces as OpenBSD does.

Here is a patch to fix the issue (against OpenVPN 2.4.6):

So, the patch looks good, and it works nicely on my buildslave.

There's two catches here - one is that with this patch format, I do not get proper git attribution in place, so we really really prefer patches that come out of "git commit -s ..." -> "git send-email".

The other catch is that this patch is for 2.4 only, and does not apply to git master anymore (since Antonio has wrecked tun.c all over :-) ).

So what I'd really love to see is two patches, one for 2.4 and one for git master, both coming out of "git commit -s" -> "git send-email" - because that would speed up the flow tremendously (I can ACK and commit the patches right away, but if I adapt your patch to "git master", someone else needs to do the review and the credits who did the fixing are all wrong)

thanks :)

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]...
#6 lore raw
Quoted 20 lines · Adam
Quoted 3 lines

It turns out, NetBSD needs similar handling of subnet topology for tun interfaces as OpenBSD does.

Here is a patch to fix the issue (against OpenVPN 2.4.6):

So, the patch looks good, and it works nicely on my buildslave.

There's two catches here - one is that with this patch format, I do not get proper git attribution in place, so we really really prefer patches that come out of "git commit -s ..." -> "git send-email".

The other catch is that this patch is for 2.4 only, and does not apply to git master anymore (since Antonio has wrecked tun.c all over :-) ).

So what I'd really love to see is two patches, one for 2.4 and one for git master, both coming out of "git commit -s" -> "git send-email" - because that would speed up the flow tremendously (I can ACK and commit the patches right away, but if I adapt your patch to "git master", someone else needs to do the review and the credits who did the fixing are all wrong)

Quoted 3 lines

thanks :)

gert

Here it is, against the current master branch.

From 1ac7931b5afa6b3c521d23f1847476ab6384eb10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adam=20Ciarcin=CC=81ski?= <[email protected]...>
Date: Thu, 2 Aug 2018 16:17:56 +0200
Subject: [PATCH] Fix subnet topology on NetBSD.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/openvpn/tun.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
src/openvpn/tun.c +16 -3
index 1c7e51d9..7fe4a062 100644
@@ -845,7 +845,7 @@ delete_route_connected_v6_net(struct tuntap *tt,
 #endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) */
 
 #if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)  \
-    || defined(TARGET_OPENBSD)
+    || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD)
 /* we can't use true subnet mode on tun on all platforms, as that
  * conflicts with IPv6 (wants to use ND then, which we don't do),
  * but the OSes want "a remote address that is different from ours"
@@ -1233,6 +1233,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
     }
 
 #elif defined(TARGET_NETBSD)
+    in_addr_t remote_end;           /* for "virtual" subnet topology */
 
     if (tun)
     {
@@ -1243,8 +1244,8 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
     else if (tt->topology == TOP_SUBNET)
     {
         argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PATH,
-                    ifname, ifconfig_local, ifconfig_local, tun_mtu,
-                    ifconfig_remote_netmask);
+                    ifname, ifconfig_local, print_in_addr_t(remote_end, 0, &gc),
+                    tun_mtu, ifconfig_remote_netmask);
     }
     else
     {
@@ -1260,6 +1261,18 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
     argv_msg(M_INFO, &argv);
     openvpn_execve_check(&argv, es, S_FATAL, "NetBSD ifconfig failed");
 
+    /* Add a network route for the local tun interface */
+    if (!tun && tt->topology == TOP_SUBNET)
+    {
+        struct route_ipv4 r;
+        CLEAR(r);
+        r.flags = RT_DEFINED;
+        r.network = tt->local & tt->remote_netmask;
+        r.netmask = tt->remote_netmask;
+        r.gateway = remote_end;
+        add_route(&r, tt, 0, NULL, es);
+    }
+
 #elif defined(TARGET_DARWIN)
     /*
      * Darwin (i.e. Mac OS X) seems to exhibit similar behaviour to OpenBSD...
Signature · 1 line
2.18.0

Kind regards,
Adam

#7 lore raw

Hi,

Quoted 1 line · Adam

Here it is, against the current master branch.

Thanks for re-sending. Unfortunately, it's not complete - it adds "remote_end", but never initializes it in the TARGET_FREEBSD branch.

So it sort of works because it happens to puts 0.0.0.0 (or even random stack data) into "remote_end" which is then used as gateway address...

Sun Aug 5 21:01:38 2018 /sbin/ifconfig tun1 10.194.3.14 0.0.0.0 mtu 1500 netmask 255.255.255.0 up Sun Aug 5 21:01:38 2018 /sbin/route add -net 10.194.3.0 0.0.0.0 -netmask 255.255.255.0 add net 10.194.3.0: gateway 0.0.0.0

(Actually, it looks like it could work, but pinging 10.194.3.1 is subsequently failing)

All other platforms have a

  remote_end = create_arbitrary_remote( tt );

in there, to make it look less... accidential. I assume this just got lost on rebasing (blame it on Antonio :-) ).

Could you send us a v2? thanks :)

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]...
#8 lore raw
Quoted 18 lines
Quoted 1 line

Here it is, against the current master branch.

Thanks for re-sending. Unfortunately, it's not complete - it adds "remote_end", but never initializes it in the TARGET_FREEBSD branch.

So it sort of works because it happens to puts 0.0.0.0 (or even random stack data) into "remote_end" which is then used as gateway address...

Sun Aug 5 21:01:38 2018 /sbin/ifconfig tun1 10.194.3.14 0.0.0.0 mtu 1500 netmask 255.255.255.0 up Sun Aug 5 21:01:38 2018 /sbin/route add -net 10.194.3.0 0.0.0.0 -netmask 255.255.255.0 add net 10.194.3.0: gateway 0.0.0.0

(Actually, it looks like it could work, but pinging 10.194.3.1 is subsequently failing)

All other platforms have a

Quoted 8 lines

remote_end = create_arbitrary_remote( tt );

in there, to make it look less... accidential. I assume this just got lost on rebasing (blame it on Antonio :-) ).

Could you send us a v2? thanks :)

gert

Sorry about that. I'm on holiday, and doing it with only one eye opened. ;)

Here it is once more...

Cheers,
Adam

From b24aed8efb5adec5d3dcab25ecf456fbd8e4415a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adam=20Ciarcin=CC=81ski?= <[email protected]...>
Date: Thu, 2 Aug 2018 16:17:56 +0200
Subject: [PATCH] Fix subnet topology on NetBSD.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/openvpn/tun.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
src/openvpn/tun.c +17 -3
index 1c7e51d9..50f158cb 100644
@@ -845,7 +845,7 @@ delete_route_connected_v6_net(struct tuntap *tt,
 #endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) */
 
 #if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)  \
-    || defined(TARGET_OPENBSD)
+    || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD)
 /* we can't use true subnet mode on tun on all platforms, as that
  * conflicts with IPv6 (wants to use ND then, which we don't do),
  * but the OSes want "a remote address that is different from ours"
@@ -1233,6 +1233,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
     }
 
 #elif defined(TARGET_NETBSD)
+    in_addr_t remote_end;           /* for "virtual" subnet topology */
 
     if (tun)
     {
@@ -1242,9 +1243,10 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
     }
     else if (tt->topology == TOP_SUBNET)
     {
+        remote_end = create_arbitrary_remote(tt);
         argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PATH,
-                    ifname, ifconfig_local, ifconfig_local, tun_mtu,
-                    ifconfig_remote_netmask);
+                    ifname, ifconfig_local, print_in_addr_t(remote_end, 0, &gc),
+                    tun_mtu, ifconfig_remote_netmask);
     }
     else
     {
@@ -1260,6 +1262,18 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
     argv_msg(M_INFO, &argv);
     openvpn_execve_check(&argv, es, S_FATAL, "NetBSD ifconfig failed");
 
+    /* Add a network route for the local tun interface */
+    if (!tun && tt->topology == TOP_SUBNET)
+    {
+        struct route_ipv4 r;
+        CLEAR(r);
+        r.flags = RT_DEFINED;
+        r.network = tt->local & tt->remote_netmask;
+        r.netmask = tt->remote_netmask;
+        r.gateway = remote_end;
+        add_route(&r, tt, 0, NULL, es);
+    }
+
 #elif defined(TARGET_DARWIN)
     /*
      * Darwin (i.e. Mac OS X) seems to exhibit similar behaviour to OpenBSD...
Signature · 1 line
2.18.0
#9 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix subnet topology on NetBSD.

ACK, thanks. And a good vacation to you :-)

Tested on NetBSD 7.0.1, and passes all my tests.

(Given that the changes are all #ifdef TARGET_NETBSD, I do not expect surprises on other platforms).

Your patch has been applied to the master and release/2.4 branch (well, *this* patch was applied to "master", and the previous patch was applied to release/2.4, since "git cherrypick" refused to play nicely - so there will be two "patch applied" mails).

commit 98e1d917fceb4c003fda0b43270325091768484f (master) commit de4c7767b6b30ebd8f05cffb0fabe7e68bdc5e38 (release/2.4)

Author: Adam Ciarcin?ski
Date:   Thu Aug 2 16:17:56 2018 +0200
     Fix subnet topology on NetBSD.

     Signed-off-by: Adam Ciarcin?ski <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg17399.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#10 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix subnet topology on NetBSD.

In reply to Adam

Your patch has been applied to the release/2.4 branch.

commit de4c7767b6b30ebd8f05cffb0fabe7e68bdc5e38

Author: Adam Ciarcin?ski
Date:   Thu Aug 2 16:17:56 2018 +0200
     Fix subnet topology on NetBSD.

     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg17268.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering