I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit b65b53b0 authored by zzz's avatar zzz
Browse files

Transport: Add missing bogons to IP validity check

192.0.0.2 seen out there (RFC 6333)
parent 49e1e1c8
No related branches found
No related tags found
No related merge requests found
...@@ -102,6 +102,8 @@ public abstract class TransportUtil { ...@@ -102,6 +102,8 @@ public abstract class TransportUtil {
} }
/** /**
* Ref: RFC 5735
*
* @param addr non-null * @param addr non-null
* @since IPv6 * @since IPv6
*/ */
...@@ -110,22 +112,40 @@ public abstract class TransportUtil { ...@@ -110,22 +112,40 @@ public abstract class TransportUtil {
if (!allowIPv4) if (!allowIPv4)
return false; return false;
int a0 = addr[0] & 0xFF; int a0 = addr[0] & 0xFF;
if (a0 == 127) return false; // please keep sorted by IP
if (a0 == 10) return false;
int a1 = addr[1] & 0xFF;
if (a0 == 172 && a1 >= 16 && a1 <= 31) return false;
if (a0 == 192 && a1 == 168) return false;
if (a0 >= 224) return false; // no multicast
if (a0 == 0) return false; if (a0 == 0) return false;
if (a0 == 169 && a1 == 254) return false; if (a0 == 10) return false;
// 5/8 allocated to RIPE (30 November 2010) // 5/8 allocated to RIPE (30 November 2010)
//if ((addr[0]&0xFF) == 5) return false; // Hamachi //if ((addr[0]&0xFF) == 5) return false; // Hamachi
// Hamachi moved to 25/8 Nov. 2012 // Hamachi moved to 25/8 Nov. 2012
// Assigned to UK Ministry of Defence // Assigned to UK Ministry of Defence
// http://blog.logmein.com/products/changes-to-hamachi-on-november-19th // http://blog.logmein.com/products/changes-to-hamachi-on-november-19th
if (a0 == 25) return false; if (a0 == 25) return false;
if (a0 == 127) return false;
int a1 = addr[1] & 0xFF;
// Carrier Grade NAT RFC 6598 // Carrier Grade NAT RFC 6598
if (a0 == 100 && a1 >= 64 && a1 <= 127) return false; if (a0 == 100 && a1 >= 64 && a1 <= 127) return false;
if (a0 == 169 && a1 == 254) return false;
if (a0 == 172 && a1 >= 16 && a1 <= 31) return false;
if (a0 == 192) {
if (a1 == 168) return false;
if (a1 == 0) {
int a2 = addr[2] & 0xFF;
// protocol assignment, documentation
// 192.0.0.2 seen in the wild, RFC 6333 "Dual-Stack Lite Broadband Deployments Following IPv4 Exhaustion"
if (a2 == 0 || a2 == 2) return false;
}
// 6to4 anycast
if (a1 == 88 && (addr[2] & 0xff) == 99) return false;
}
if (a0 == 198) {
// tests
if (a1 == 18 || a1 == 19) return false;
if (a1 == 51 && (addr[2] & 0xff) == 100) return false;
}
// test
if (a0 == 203 && a1 == 0 && (addr[2] & 0xff) == 113) return false;
if (a0 >= 224) return false; // no multicast
return true; // or at least possible to be true return true; // or at least possible to be true
} else if (addr.length == 16) { } else if (addr.length == 16) {
if (allowIPv6) { if (allowIPv6) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment