]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Bugfix: Set broadcast address on interface.
authorSebastian Marsching <sebastian-git-2016@marsching.com>
Mon, 15 Sep 2025 11:05:07 +0000 (13:05 +0200)
committerGert Doering <gert@greenie.muc.de>
Sun, 21 Sep 2025 16:07:04 +0000 (18:07 +0200)
This fixes a problem that was introduced in OpenVPN 2.5. Previously,
the ifconfig utility was used for adding the local address to an
interface. This utility automatically sets the correct broadcast address
based on the given unicast address and netmask.

Due to switching to iproute and Netlink, this does not happen
automatically any longer, which means that applications that rely on
broadcasts do not work correctly.

This patch fixes this issue both when using iproute (by telling iproute
to set the broadcast address based on the local address and prefix) and
when using Netlink (by calculating the correct broadcast address and
setting it).

Signed-off-by: Sebastian Marsching <sebastian-git-2016@marsching.com>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20250915110507.20557-1-sebastian-git-2016@marsching.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33131.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 0df0edc49ce4acb96c8e16bdf0fcee1eedfd91f0)

src/openvpn/networking_iproute2.c
src/openvpn/networking_sitnl.c

index 975282ca1bd04224acd3c3ef74be3694c81a02d1..74ddc241566c30ea956559b3f1dffb83cc16e44f 100644 (file)
@@ -159,7 +159,7 @@ net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface,
 
     const char *addr_str = print_in_addr_t(*addr, 0, &ctx->gc);
 
-    argv_printf(&argv, "%s addr add dev %s %s/%d", iproute_path, iface,
+    argv_printf(&argv, "%s addr add dev %s %s/%d broadcast +", iproute_path, iface,
                 addr_str, prefixlen);
     argv_msg(M_INFO, &argv);
     openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip addr add failed");
index f53f5ee9ebf43525cfaac7cf7126717e153ea7a4..10c3825629343d36d4b1563b19ac61c8c33b12f6 100644 (file)
@@ -32,6 +32,7 @@
 #include "misc.h"
 #include "networking.h"
 #include "proto.h"
+#include "route.h"
 
 #include <errno.h>
 #include <string.h>
@@ -800,6 +801,13 @@ sitnl_addr_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family,
         SITNL_ADDATTR(&req.n, sizeof(req), IFA_LOCAL, local, size);
     }
 
+    if (af_family == AF_INET && local && !remote && prefixlen <= 30)
+    {
+        inet_address_t broadcast = *local;
+        broadcast.ipv4 |= htonl(~netbits_to_netmask(prefixlen));
+        SITNL_ADDATTR(&req.n, sizeof(req), IFA_BROADCAST, &broadcast, size);
+    }
+
     ret = sitnl_send(&req.n, 0, 0, NULL, NULL);
     if (ret == -EEXIST)
     {