Skip to content

Commit

Permalink
OpenBSD: repair --show-gateway
Browse files Browse the repository at this point in the history
OpenBSD route sockets do not want to be passed RTA_IFP on RTM_GET
- if we do this, we get back EINVAL.

On other platforms, if we do not request RTA_IFP, we will not get
back interface information for queried routes - on OpenBSD, RTA_IFP
comes back always...

So we need to #ifdef this, RTA_IFP on all platforms except OpenBSD.

(Found this fix in OpenBSD's ports tree, in their patches for OpenVPN
2.6.8 - but they just remove RTA_IFP, no #ifdef, so we can't just apply
their patch)

While at it, add M_ERRNO to the "write to routing socket" error message.

Signed-off-by: Gert Doering <[email protected]>
Acked-by: Arne Schwabe <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg27892.html
Signed-off-by: Gert Doering <[email protected]>
(cherry picked from commit acf6f33)
  • Loading branch information
cron2 committed Jan 1, 2024
1 parent 5380fe0 commit 77376fc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/openvpn/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -3513,7 +3513,11 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)
/* setup data to send to routing socket */
pid = getpid();
seq = 0;
#ifdef TARGET_OPENBSD
rtm_addrs = RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IFP */
#else
rtm_addrs = RTA_DST | RTA_NETMASK | RTA_IFP;
#endif

bzero(&m_rtmsg, sizeof(m_rtmsg));
bzero(&so_dst, sizeof(so_dst));
Expand Down Expand Up @@ -3551,7 +3555,7 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)
}
if (write(sockfd, (char *)&m_rtmsg, l) < 0)
{
msg(M_WARN, "GDG: problem writing to routing socket");
msg(M_WARN|M_ERRNO, "GDG: problem writing to routing socket");
goto done;
}
do
Expand Down Expand Up @@ -3764,7 +3768,11 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6,
/* setup data to send to routing socket */
pid = getpid();
seq = 0;
#ifdef TARGET_OPENBSD
rtm_addrs = RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IFP */
#else
rtm_addrs = RTA_DST | RTA_NETMASK | RTA_IFP;
#endif

bzero(&m_rtmsg, sizeof(m_rtmsg));
bzero(&so_dst, sizeof(so_dst));
Expand Down

0 comments on commit 77376fc

Please sign in to comment.