summaryrefslogtreecommitdiff
path: root/lib/ip.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-08-02 17:58:14 +0200
committerMaria Matejka <mq@ucw.cz>2022-08-02 17:58:14 +0200
commit0072d11f3431165240656edf6ade473554b8747e (patch)
tree6c53bbbf0d3a4a3ad70846aae50995dc184cc5a5 /lib/ip.c
parent2e95d269d6bd42372d3273264e14775242b0744d (diff)
parentdb9153e216b6f1847ac9cdf170b1d14c04552e41 (diff)
Merge branch 'ballygarvan' into HEAD
Replacing the old 3.0-alpha0 cork mechanism with another one inside the routing table. This version should be simpler and also quite clear what it does, why and when.
Diffstat (limited to 'lib/ip.c')
-rw-r--r--lib/ip.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/ip.c b/lib/ip.c
index fcc72caf..4c5fa47f 100644
--- 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