<div dir="ltr">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...)<div><a href="https://github.com/projectcalico/bird/commit/5cc183424d9ffb898171ef16360c400414f91bf0">https://github.com/projectcalico/bird/commit/5cc183424d9ffb898171ef16360c400414f91bf0</a><br><a href="https://github.com/projectcalico/bird/commit/4c6f0ce840456cc04483a820007b433721706c07">https://github.com/projectcalico/bird/commit/4c6f0ce840456cc04483a820007b433721706c07</a><br></div><div><a href="https://github.com/projectcalico/bird/commit/49d883ed225d8eb0310009a5a79b1c9ee0afbca9">https://github.com/projectcalico/bird/commit/49d883ed225d8eb0310009a5a79b1c9ee0afbca9</a><br></div><div><br></div><div>We went for SCOPE_SITE.</div><div><br></div><div>Best wishes,</div><div> Neil</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 14, 2022 at 9:35 AM Vincent Bernat <<a href="mailto:vincent@bernat.ch">vincent@bernat.ch</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><a href="http://240.0.0.0/4" rel="noreferrer" target="_blank">240.0.0.0/4</a> is marked as reserved and considered invalid by BIRD. At<br>
work, we are using this range internally since all RFC 1918 are full<br>
and <a href="http://100.64.0.0/10" rel="noreferrer" target="_blank">100.64.0.0/10</a> is already used too. BIRD complains loudly for each<br>
interface using this range.<br>
<br>
This change makes it possible to use this range. I have used scope<br>
"universe". But I would be happy with "site" too. While widely<br>
discussed, I don't think 240/4 will become routable on the Internet<br>
one day.<br>
<br>
As a bonus, I added some comments and unrolled a condition for each<br>
block. I also have added some hints for the compiler to avoid using<br>
jumps in the hotpath (tested on Godbolt, see<br>
<a href="https://godbolt.org/z/rGjz336K3" rel="noreferrer" target="_blank">https://godbolt.org/z/rGjz336K3</a>).<br>
---<br>
lib/ip.c | 28 +++++++++++-----------------<br>
sysdep/config.h | 5 +++++<br>
2 files changed, 16 insertions(+), 17 deletions(-)<br>
<br>
diff --git a/lib/ip.c b/lib/ip.c<br>
index fcc72cafb4de..4d0dff636e17 100644<br>
--- a/lib/ip.c<br>
+++ b/lib/ip.c<br>
@@ -85,25 +85,19 @@ ip4_classify(ip4_addr ad)<br>
u32 a = _I(ad);<br>
u32 b = a >> 24U;<br>
<br>
- if (b && b <= 0xdf)<br>
- {<br>
- if (b == 0x7f)<br>
- return IADDR_HOST | SCOPE_HOST;<br>
- else if ((b == 0x0a) ||<br>
- ((a & 0xffff0000) == 0xc0a80000) ||<br>
- ((a & 0xfff00000) == 0xac100000))<br>
- return IADDR_HOST | SCOPE_SITE;<br>
- else<br>
- return IADDR_HOST | SCOPE_UNIVERSE;<br>
- }<br>
-<br>
- if (b >= 0xe0 && b <= 0xef)<br>
+ if (unlikely(b == 0x00))<br>
+ return IADDR_INVALID; /* <a href="http://0.0.0.0/8" rel="noreferrer" target="_blank">0.0.0.0/8</a> This network */<br>
+ if (unlikely(b == 0x7f)) /* <a href="http://127.0.0.0/8" rel="noreferrer" target="_blank">127.0.0.0/8</a> Loopback */<br>
+ return IADDR_HOST | SCOPE_HOST;<br>
+ if ((b == 0x0a) || /* <a href="http://10.0.0.0/8" rel="noreferrer" target="_blank">10.0.0.0/8</a> Private-use */<br>
+ ((a & 0xffff0000) == 0xc0a80000) || /* <a href="http://192.168.0.0/16" rel="noreferrer" target="_blank">192.168.0.0/16</a> Private-use */<br>
+ ((a & 0xfff00000) == 0xac100000)) /* <a href="http://172.16.0.0/12" rel="noreferrer" target="_blank">172.16.0.0/12</a> Private-use */<br>
+ return IADDR_HOST | SCOPE_SITE;<br>
+ if (unlikely(b >= 0xe0 && b <= 0xef)) /* <a href="http://224.0.0.0/4" rel="noreferrer" target="_blank">224.0.0.0/4</a> Multicast */<br>
return IADDR_MULTICAST | SCOPE_UNIVERSE;<br>
-<br>
- if (a == 0xffffffff)<br>
+ if (unlikely(a == 0xffffffff)) /* 255.255.255.255 Limited broadcast */<br>
return IADDR_BROADCAST | SCOPE_LINK;<br>
-<br>
- return IADDR_INVALID;<br>
+ return IADDR_HOST | SCOPE_UNIVERSE;<br>
}<br>
<br>
int<br>
diff --git a/sysdep/config.h b/sysdep/config.h<br>
index b0531844af9f..4d73543c3894 100644<br>
--- a/sysdep/config.h<br>
+++ b/sysdep/config.h<br>
@@ -30,6 +30,11 @@<br>
*/<br>
#include "sysdep/paths.h"<br>
<br>
+/* Likely/unlikely macros */<br>
+<br>
+#define likely(x) __builtin_expect((x),1)<br>
+#define unlikely(x) __builtin_expect((x),0)<br>
+<br>
/* Types */<br>
<br>
#include <stdint.h><br>
-- <br>
2.35.1<br>
<br>
</blockquote></div>