diff mbox

[OpenWrt-Devel,netifd] interface-ip: Fix broadcast address when using /31 IPv4 addressing

Message ID 1442221874-30604-1-git-send-email-baptiste@bitsofnetworks.org
State Superseded
Headers show

Commit Message

Baptiste Jonglez Sept. 14, 2015, 9:11 a.m. UTC
A /31-addressed interface requires a 255.255.255.255 broadcast, because
there is no room for a proper broadcast address.  Without this, any packet
destinated to the other end of the link is sent as broadcast, which is
incorrect.

Signed-off-by: Baptiste Jonglez <git@bitsofnetworks.org>
---
 interface-ip.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/interface-ip.c b/interface-ip.c
index 8eb2ff3..439b8af 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -473,11 +473,16 @@  interface_update_proto_addr(struct vlist_tree *tree,
 		if ((a_new->flags & DEVADDR_FAMILY) == DEVADDR_INET4 &&
 		    !a_new->broadcast) {
 
-			uint32_t mask = ~0;
-			uint32_t *a = (uint32_t *) &a_new->addr;
-
-			mask >>= a_new->mask;
-			a_new->broadcast = *a | htonl(mask);
+			/* /31 addressing needs 255.255.255.255 broadcast */
+			if (a_new->mask == 31) {
+				a_new->broadcast = (uint32_t) ~0;
+			} else {
+				uint32_t mask = ~0;
+				uint32_t *a = (uint32_t *) &a_new->addr;
+
+				mask >>= a_new->mask;
+				a_new->broadcast = *a | htonl(mask);
+			}
 		}
 	}