Skip to contentSkip to conversation

Fix gateway detection with OpenBSD routing domains

PATCH In review Steven McDonald 2 participants 2 messages Apr 13, 2017 – May 18, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix gateway detection with OpenBSD routing domains

When OpenVPN is started using a non-default routing table on OpenBSD (e.g., with 'route -T10 exec openvpn ...'), it hangs forever trying to read its default gateway from a PF_ROUTE socket. This is because rtm_tableid is not being initialised after bzeroing the rt_msghdr we write to the socket, so we end up asking the kernel for the default route in routing table 0.

By default, the OpenBSD kernel will not respond to requests for routing table 0 from a process running in a different routing table, and even if it did, it would give us the wrong default gateway.

The solution here is to set rtm_tableid to the value returned by getrtable(2), which always succeeds and returns the calling process's current routing table.

This patch makes the test suite (without a t_client.rc) pass when run in a non-default routing table, where it would fail previously. It has also been successfully tested in client mode against both git master and OpenVPN 2.4.1 from ports on an OpenBSD -current system.

---
 src/openvpn/route.c | 6 ++++++
 1 file changed, 6 insertions(+)
src/openvpn/route.c +6 -0
index 08998d5f..33cdc0b0 100644
@@ -3597,6 +3597,9 @@ get_default_gateway(struct route_gateway_info *rgi)
     rtm.rtm_flags = RTF_UP | RTF_GATEWAY;
     rtm.rtm_version = RTM_VERSION;
     rtm.rtm_seq = ++seq;
+#ifdef TARGET_OPENBSD
+    rtm.rtm_tableid = getrtable();
+#endif
     rtm.rtm_addrs = rtm_addrs;
 
     so_dst.sa_family = AF_INET;
@@ -3812,6 +3815,9 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6,
     rtm.rtm_flags = RTF_UP;
     rtm.rtm_version = RTM_VERSION;
     rtm.rtm_seq = ++seq;
+#ifdef TARGET_OPENBSD
+    rtm.rtm_tableid = getrtable();
+#endif
 
     so_dst.sin6_family = AF_INET6;
     so_mask.sin6_family = AF_INET6;
Signature · 1 line
2.12.2
#1 lore raw

ACK, thanks. Sorry that it took so long, wanted to verify things and then it got lost. Since it's openbsd specific, I only did cursory checks ("the code looks sane and getrtable() is documented to do what you say"), but did not set up a system with non-0 routing tables.

Your patch has been applied to the master and release/2.4 branch, and adapted to release/2.3 ("IPv4 only").

commit 3dd30bfe5fdf9f34afe7f847b4e30156982d9ff0 (master) commit 212e24ddc7b60fc2d2303ccf5893054e952232bb (release/2.4) commit 50ba481c21a0e868491b02efe7a1d9c5664d8f58 (release/2.3)

Author: Steven McDonald
Date:   Fri Apr 14 03:31:29 2017 +1000
     Fix gateway detection with OpenBSD routing domains

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

--
kind regards,

Gert Doering