networkd: address - support for /31 IPv4 addresses (rfc3021) (#6938)
authorSusant Sahani <145210+ssahani@users.noreply.github.com>
Mon, 20 Nov 2017 18:16:01 +0000 (23:46 +0530)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Nov 2017 18:16:01 +0000 (19:16 +0100)
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

index 1ed6288..2f8edea 100644 (file)
@@ -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");
+                        }
                 }
         }