From e87e2b78f70dba836355ceb0fdb07d1334ea8648 Mon Sep 17 00:00:00 2001 From: Susant Sahani <145210+ssahani@users.noreply.github.com> Date: Mon, 20 Nov 2017 23:46:01 +0530 Subject: [PATCH] networkd: address - support for /31 IPv4 addresses (rfc3021) (#6938) When configuring a network address with /31 using networkd, a /31 without a broadcast specified should be present. A /31 which has neither a network nor a broadcast address. See https://tools.ietf.org/html/rfc3021 Fixes #4038 --- src/network/networkd-address.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 1ed6288ec06..2f8edea8557 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -514,7 +514,10 @@ static int address_acquire(Link *link, Address *original, Address **ret) { in_addr.in.s_addr = in_addr.in.s_addr | htobe32(1); /* .. and use last as broadcast address */ - broadcast.s_addr = in_addr.in.s_addr | htobe32(0xFFFFFFFFUL >> original->prefixlen); + if (original->prefixlen > 30) + broadcast.s_addr = 0; + else + broadcast.s_addr = in_addr.in.s_addr | htobe32(0xFFFFFFFFUL >> original->prefixlen); } else if (original->family == AF_INET6) in_addr.in6.s6_addr[15] |= 1; @@ -629,9 +632,11 @@ int address_configure( return log_error_errno(r, "Could not append IFA_ADDRESS attribute: %m"); } else { if (address->family == AF_INET) { - r = sd_netlink_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast); - if (r < 0) - return log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m"); + if (address->prefixlen <= 30) { + r = sd_netlink_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast); + if (r < 0) + return log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m"); + } } }