Skip to content

Commit 0df0edc

Browse files
smarschingcron2
authored andcommitted
Bugfix: Set broadcast address on interface.
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 <[email protected]> Acked-by: Antonio Quartulli <[email protected]> Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg33131.html Signed-off-by: Gert Doering <[email protected]>
1 parent a69aac4 commit 0df0edc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/openvpn/networking_iproute2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr
150150

151151
const char *addr_str = print_in_addr_t(*addr, 0, &ctx->gc);
152152

153-
argv_printf(&argv, "%s addr add dev %s %s/%d", iproute_path, iface, addr_str, prefixlen);
153+
argv_printf(&argv, "%s addr add dev %s %s/%d broadcast +", iproute_path, iface, addr_str, prefixlen);
154154
argv_msg(M_INFO, &argv);
155155
openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip addr add failed");
156156

src/openvpn/networking_sitnl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "misc.h"
3232
#include "networking.h"
3333
#include "proto.h"
34+
#include "route.h"
3435

3536
#include <errno.h>
3637
#include <string.h>
@@ -803,6 +804,13 @@ sitnl_addr_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family,
803804
SITNL_ADDATTR(&req.n, sizeof(req), IFA_LOCAL, local, size);
804805
}
805806

807+
if (af_family == AF_INET && local && !remote && prefixlen <= 30)
808+
{
809+
inet_address_t broadcast = *local;
810+
broadcast.ipv4 |= htonl(~netbits_to_netmask(prefixlen));
811+
SITNL_ADDATTR(&req.n, sizeof(req), IFA_BROADCAST, &broadcast, size);
812+
}
813+
806814
ret = sitnl_send(&req.n, 0, 0, NULL, NULL);
807815
if (ret == -EEXIST)
808816
{

0 commit comments

Comments
 (0)