]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Lib: Allow use of 240.0.0.0/4 as a private range
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 16 Mar 2022 18:50:16 +0000 (19:50 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 16 Mar 2022 19:01:18 +0000 (20:01 +0100)
There were several requests to allow use of 240.0.0.0/4 as a private
range, and Linux kernel already allows such routes, so perhaps we can
allow that too.

Thanks to Vincent Bernat and others for suggestion and patches.

lib/ip.c

index fcc72cafb4de5ee8e2c2c1fcafae24c1f6812399..4c5fa47fc8ff6cab9f643f5ee5320e28d39e062a 100644 (file)
--- a/lib/ip.c
+++ b/lib/ip.c
@@ -85,25 +85,29 @@ ip4_classify(ip4_addr ad)
   u32 a = _I(ad);
   u32 b = a >> 24U;
 
-  if (b && b <= 0xdf)
+  if (b < 0xe0)
   {
-    if (b == 0x7f)
+    if (b == 0x00)                             /* 0.0.0.0/8        This network */
+      return IADDR_INVALID;
+
+    if (b == 0x7f)                             /* 127.0.0.0/8      Loopback address */
       return IADDR_HOST | SCOPE_HOST;
-    else if ((b == 0x0a) ||
-            ((a & 0xffff0000) == 0xc0a80000) ||
-            ((a & 0xfff00000) == 0xac100000))
+
+    if ((b == 0x0a) ||                         /* 10.0.0.0/8       Private range */
+       ((a & 0xffff0000) == 0xc0a80000) ||     /* 192.168.0.0/16   Private range */
+       ((a & 0xfff00000) == 0xac100000))       /* 172.16.0.0/12    Private range */
       return IADDR_HOST | SCOPE_SITE;
-    else
-      return IADDR_HOST | SCOPE_UNIVERSE;
+
+    return IADDR_HOST | SCOPE_UNIVERSE;
   }
 
-  if (b >= 0xe0 && b <= 0xef)
+  if (b < 0xf0)                                        /* 224.0.0.0/4      Multicast address */
     return IADDR_MULTICAST | SCOPE_UNIVERSE;
 
-  if (a == 0xffffffff)
+  if (a == 0xffffffff)                         /* 255.255.255.255  Broadcast address */
     return IADDR_BROADCAST | SCOPE_LINK;
 
-  return IADDR_INVALID;
+  return IADDR_HOST | SCOPE_SITE;              /* 240.0.0.0/4      Reserved / private */
 }
 
 int