interface-ip: fix IPv4 route target masking
authorJo-Philipp Wich <jo@mein.io>
Tue, 14 Nov 2023 13:01:44 +0000 (14:01 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 14 Nov 2023 13:32:53 +0000 (14:32 +0100)
A previous commit supposed to mask out excess host bits in route targets
failed to correctly calculate the mask value, causing it to produce
improper results for certain mask lengths.

Fixes: #17
Fixes: 76eb342 ("interface-ip: mask out host bits in IPv4 route targets")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
interface-ip.c

index d2fe385f8aa5409cfaa854028334bc6d5e136665..28e7106e1bfc3c90ad909878ab8486c912293c58 100644 (file)
@@ -448,7 +448,7 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6)
 
                /* Mask out IPv4 host bits to avoid "Invalid prefix for given prefix length" */
                if (af == AF_INET && route->mask < 32)
-                       route->addr.in.s_addr &= ((1u << route->mask) - 1);
+                       clear_if_addr(&route->addr, route->mask);
        }
 
        if ((cur = tb[ROUTE_GATEWAY]) != NULL) {