[PATCH v2] Lib: accept 240.0.0.0/4 as a valid range

Neil Jerram neil at tigera.io
Wed Mar 16 11:24:22 CET 2022


FYI, and in as much as it constitutes a form of support for this, we at
Project Calico made a similar change to our BIRD 1.6 fork with these
commits.  (Of which the first is rather embarrassing...)
https://github.com/projectcalico/bird/commit/5cc183424d9ffb898171ef16360c400414f91bf0
https://github.com/projectcalico/bird/commit/4c6f0ce840456cc04483a820007b433721706c07
https://github.com/projectcalico/bird/commit/49d883ed225d8eb0310009a5a79b1c9ee0afbca9

We went for SCOPE_SITE.

Best wishes,
    Neil


On Mon, Mar 14, 2022 at 9:35 AM Vincent Bernat <vincent at bernat.ch> wrote:

> 240.0.0.0/4 is marked as reserved and considered invalid by BIRD. At
> work, we are using this range internally since all RFC 1918 are full
> and 100.64.0.0/10 is already used too. BIRD complains loudly for each
> interface using this range.
>
> This change makes it possible to use this range. I have used scope
> "universe". But I would be happy with "site" too. While widely
> discussed, I don't think 240/4 will become routable on the Internet
> one day.
>
> As a bonus, I added some comments and unrolled a condition for each
> block. I also have added some hints for the compiler to avoid using
> jumps in the hotpath (tested on Godbolt, see
> https://godbolt.org/z/rGjz336K3).
> ---
>  lib/ip.c        | 28 +++++++++++-----------------
>  sysdep/config.h |  5 +++++
>  2 files changed, 16 insertions(+), 17 deletions(-)
>
> diff --git a/lib/ip.c b/lib/ip.c
> index fcc72cafb4de..4d0dff636e17 100644
> --- a/lib/ip.c
> +++ b/lib/ip.c
> @@ -85,25 +85,19 @@ ip4_classify(ip4_addr ad)
>    u32 a = _I(ad);
>    u32 b = a >> 24U;
>
> -  if (b && b <= 0xdf)
> -  {
> -    if (b == 0x7f)
> -      return IADDR_HOST | SCOPE_HOST;
> -    else if ((b == 0x0a) ||
> -            ((a & 0xffff0000) == 0xc0a80000) ||
> -            ((a & 0xfff00000) == 0xac100000))
> -      return IADDR_HOST | SCOPE_SITE;
> -    else
> -      return IADDR_HOST | SCOPE_UNIVERSE;
> -  }
> -
> -  if (b >= 0xe0 && b <= 0xef)
> +  if (unlikely(b == 0x00))
> +    return IADDR_INVALID;                   /* 0.0.0.0/8       This
> network */
> +  if (unlikely(b == 0x7f))                  /* 127.0.0.0/8     Loopback
> */
> +    return IADDR_HOST | SCOPE_HOST;
> +  if ((b == 0x0a) ||                        /* 10.0.0.0/8
> Private-use */
> +      ((a & 0xffff0000) == 0xc0a80000) ||   /* 192.168.0.0/16
> Private-use */
> +      ((a & 0xfff00000) == 0xac100000))     /* 172.16.0.0/12
>  Private-use */
> +    return IADDR_HOST | SCOPE_SITE;
> +  if (unlikely(b >= 0xe0 && b <= 0xef))     /* 224.0.0.0/4     Multicast
> */
>      return IADDR_MULTICAST | SCOPE_UNIVERSE;
> -
> -  if (a == 0xffffffff)
> +  if (unlikely(a == 0xffffffff))            /* 255.255.255.255 Limited
> broadcast */
>      return IADDR_BROADCAST | SCOPE_LINK;
> -
> -  return IADDR_INVALID;
> +  return IADDR_HOST | SCOPE_UNIVERSE;
>  }
>
>  int
> diff --git a/sysdep/config.h b/sysdep/config.h
> index b0531844af9f..4d73543c3894 100644
> --- a/sysdep/config.h
> +++ b/sysdep/config.h
> @@ -30,6 +30,11 @@
>   */
>  #include "sysdep/paths.h"
>
> +/* Likely/unlikely macros */
> +
> +#define likely(x)   __builtin_expect((x),1)
> +#define unlikely(x) __builtin_expect((x),0)
> +
>  /* Types */
>
>  #include <stdint.h>
> --
> 2.35.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20220316/15759b2a/attachment.htm>


More information about the Bird-users mailing list