Fixups to IANA IP special purpose registry

Fix the IPv4 block mask. IPv4 masks are numerical masks
and not mask bit sizes.

Fix a typo. Print IPv4 addresses in hex.
This commit is contained in:
João Valverde 2023-10-25 00:02:28 +01:00
parent 799ae75010
commit ea5f48aa93
2 changed files with 45 additions and 29 deletions

View File

@ -7,30 +7,30 @@
#include "iana-ip.h"
_U_ static const struct ws_ipv4_special_block __ipv4_special_block[] = {
{ { 0, 8 }, "\"This network\"", 1, 0, 0, 0, 1 },
{ { 0, 32 }, "\"This host on this network\"", 1, 0, 0, 0, 1 },
{ { 167772160, 8 }, "Private-Use", 1, 1, 1, 0, 0 },
{ { 1681915904, 10 }, "Shared Address Space", 1, 1, 1, 0, 0 },
{ { 2130706432, 8 }, "Loopback", -1, -1, -1, -1, 1 },
{ { 2851995648, 16 }, "Link Local", 1, 1, 0, 0, 1 },
{ { 2886729728, 12 }, "Private-Use", 1, 1, 1, 0, 0 },
{ { 3221225472, 24 }, "IETF Protocol Assignments", 0, 0, 0, 0, 0 },
{ { 3221225472, 29 }, "IPv4 Service Continuity Prefix", 1, 1, 1, 0, 0 },
{ { 3221225480, 32 }, "IPv4 dummy address", 1, 0, 0, 0, 0 },
{ { 3221225481, 32 }, "Port Control Protocol Anycast", 1, 1, 1, 1, 0 },
{ { 3221225482, 32 }, "Traversal Using Relays around NAT Anycast", 1, 1, 1, 1, 0 },
{ { 3221225642, 32 }, "NAT64/DNS64 Discovery", 0, 0, 0, 0, 1 },
{ { 3221225643, 32 }, "NAT64/DNS64 Discovery", 0, 0, 0, 0, 1 },
{ { 3221225984, 24 }, "Documentation (TEST-NET-1)", 0, 0, 0, 0, 0 },
{ { 3223307264, 24 }, "AS112-v4", 1, 1, 1, 1, 0 },
{ { 3224682752, 24 }, "AMT", 1, 1, 1, 1, 0 },
{ { 3232235520, 16 }, "Private-Use", 1, 1, 1, 0, 0 },
{ { 3232706560, 24 }, "Direct Delegation AS112 Service", 1, 1, 1, 1, 0 },
{ { 3323068416, 15 }, "Benchmarking", 1, 1, 1, 0, 0 },
{ { 3325256704, 24 }, "Documentation (TEST-NET-2)", 0, 0, 0, 0, 0 },
{ { 3405803776, 24 }, "Documentation (TEST-NET-3)", 0, 0, 0, 0, 0 },
{ { 4026531840, 4 }, "Reserved", 0, 0, 0, 0, 1 },
{ { 4294967295, 32 }, "Limited Broadcast", 0, 1, 0, 0, 1 },
{ { 0x00000000, 0xff000000 }, "\"This network\"", 1, 0, 0, 0, 1 },
{ { 0x00000000, 0xffffffff }, "\"This host on this network\"", 1, 0, 0, 0, 1 },
{ { 0x0a000000, 0xff000000 }, "Private-Use", 1, 1, 1, 0, 0 },
{ { 0x64400000, 0xffc00000 }, "Shared Address Space", 1, 1, 1, 0, 0 },
{ { 0x7f000000, 0xff000000 }, "Loopback", -1, -1, -1, -1, 1 },
{ { 0xa9fe0000, 0xffff0000 }, "Link Local", 1, 1, 0, 0, 1 },
{ { 0xac100000, 0xfff00000 }, "Private-Use", 1, 1, 1, 0, 0 },
{ { 0xc0000000, 0xffffff00 }, "IETF Protocol Assignments", 0, 0, 0, 0, 0 },
{ { 0xc0000000, 0xfffffff8 }, "IPv4 Service Continuity Prefix", 1, 1, 1, 0, 0 },
{ { 0xc0000008, 0xffffffff }, "IPv4 dummy address", 1, 0, 0, 0, 0 },
{ { 0xc0000009, 0xffffffff }, "Port Control Protocol Anycast", 1, 1, 1, 1, 0 },
{ { 0xc000000a, 0xffffffff }, "Traversal Using Relays around NAT Anycast", 1, 1, 1, 1, 0 },
{ { 0xc00000aa, 0xffffffff }, "NAT64/DNS64 Discovery", 0, 0, 0, 0, 1 },
{ { 0xc00000ab, 0xffffffff }, "NAT64/DNS64 Discovery", 0, 0, 0, 0, 1 },
{ { 0xc0000200, 0xffffff00 }, "Documentation (TEST-NET-1)", 0, 0, 0, 0, 0 },
{ { 0xc01fc400, 0xffffff00 }, "AS112-v4", 1, 1, 1, 1, 0 },
{ { 0xc034c100, 0xffffff00 }, "AMT", 1, 1, 1, 1, 0 },
{ { 0xc0a80000, 0xffff0000 }, "Private-Use", 1, 1, 1, 0, 0 },
{ { 0xc0af3000, 0xffffff00 }, "Direct Delegation AS112 Service", 1, 1, 1, 1, 0 },
{ { 0xc6120000, 0xfffe0000 }, "Benchmarking", 1, 1, 1, 0, 0 },
{ { 0xc6336400, 0xffffff00 }, "Documentation (TEST-NET-2)", 0, 0, 0, 0, 0 },
{ { 0xcb007100, 0xffffff00 }, "Documentation (TEST-NET-3)", 0, 0, 0, 0, 0 },
{ { 0xf0000000, 0xf0000000 }, "Reserved", 0, 0, 0, 0, 1 },
{ { 0xffffffff, 0xffffffff }, "Limited Broadcast", 0, 1, 0, 0, 1 },
};
// GCC bug?

View File

@ -52,10 +52,26 @@ def open_url(url):
return body
class IPv4SpecialBlock(ipaddress.IPv4Network):
@staticmethod
def ip_get_subnet_mask(bits):
masks = (
0x00000000,
0x80000000, 0xc0000000, 0xe0000000, 0xf0000000,
0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
0xff800000, 0xffc00000, 0xffe00000, 0xfff00000,
0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000,
0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000,
0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00,
0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0,
0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff)
if bits > 32:
ValueError("Expected bit mask less or equal to 32")
return masks[bits]
def __str__(self):
addr = int(self.network_address)
addr = self.network_address
mask = self.prefixlen
line = '{{ {:d}, {:d} }}'.format(addr, mask)
line = '{{ {:#x}, {:#010x} }}'.format(addr, self.ip_get_subnet_mask(mask))
return line
class IPv6SpecialBlock(ipaddress.IPv6Network):
@ -72,7 +88,7 @@ class IPv6SpecialBlock(ipaddress.IPv6Network):
line = '{{ {}, {} }}'.format(self.addr_c_array(addr), mask)
return line
class IPRegisty(list):
class IPRegistry(list):
@staticmethod
def true_or_false(val):
if val == 'True':
@ -96,7 +112,7 @@ class IPRegisty(list):
reserved = self.true_or_false(reserved)
super().append([ip, name, source, destination, forward, glob, reserved])
class IPv4Registry(IPRegisty):
class IPv4Registry(IPRegistry):
@staticmethod
def ipv4_addr_and_mask(s):
ip = IPv4SpecialBlock(s)
@ -118,7 +134,7 @@ class IPv4Registry(IPRegisty):
fd.write(line)
fd.write('};\n')
class IPv6Registry(IPRegisty):
class IPv6Registry(IPRegistry):
@staticmethod
def ipv6_addr_and_mask(s):
ip_str = s.split()[0]