[OpenWrt-Devel] [PATCH v2 netifd] interface-ip: Fix broadcast address when using /31 or /32 IPv4 addressing

Baptiste Jonglez baptiste at bitsofnetworks.org
Sat Sep 26 06:17:22 EDT 2015


nbd, did you have time to look at this new version of the patch?

Thanks,
Baptiste

On Mon, Sep 14, 2015 at 12:25:33PM +0200, Baptiste Jonglez wrote:
> From: Baptiste Jonglez <git at bitsofnetworks.org>
> 
> A /31-addressed interface requires a broadcast address of 255.255.255.255,
> 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.
> 
> For consistency with the Linux kernel, /32-addressed interfaces are
> treated in the same way.
> 
> Signed-off-by: Baptiste Jonglez <git at bitsofnetworks.org>
> ---
>  interface-ip.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/interface-ip.c b/interface-ip.c
> index 8eb2ff3..0c72e46 100644
> --- a/interface-ip.c
> +++ b/interface-ip.c
> @@ -473,11 +473,17 @@ 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 and /32 addressing need 255.255.255.255
> +			 * as broadcast address. */
> +			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);
> +			}
>  		}
>  	}
>  
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20150926/ac751605/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list