contrib: Count entry differences in asmap-tool diff summary
What changed, and why it matters
This is a small cleanup change to a helper script used for comparing internet routing maps (asmap files). It only changes how the tool reports summary statistics: it now counts the number of changed entries separately from the number of affected IP addresses, and uses a built-in library function instead of a manual calculation. There is no security relevance.
No security action needed. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies contrib/asmap/asmap-tool.py’s diff subcommand. It adds counters for the number of changed prefix entries (ipv4_entries_changed, ipv6_entries_changed) and replaces manual bit-shift address counting (1 << (32 - prefixlen) and 1 << (128 - prefixlen)) with ipaddress network objects’ num_addresses property. The output format is adjusted to a multi-line summary. This is a pure refactoring/reporting improvement in an offline analysis tool.
Changed components
contrib/asmap/asmap-tool.pyInspect captured patch +9 / −4
diff --git a/contrib/asmap/asmap-tool.py b/contrib/asmap/asmap-tool.py
index 33a380a2..c679ab15 100755
--- a/contrib/asmap/asmap-tool.py
+++ b/contrib/asmap/asmap-tool.py
@@ -140,15 +140,19 @@ def main():
state1 = load_file(args.infile1)
state2 = load_file(args.infile2)
ipv4_changed = 0
+ ipv4_entries_changed = 0
ipv6_changed = 0
+ ipv6_entries_changed = 0
for prefix, old_asn, new_asn in state1.diff(state2):
if args.ignore_unassigned and old_asn == 0:
continue
net = asmap.prefix_to_net(prefix)
if isinstance(net, ipaddress.IPv4Network):
- ipv4_changed += 1 << (32 - net.prefixlen)
+ ipv4_changed += net.num_addresses
+ ipv4_entries_changed += 1
elif isinstance(net, ipaddress.IPv6Network):
- ipv6_changed += 1 << (128 - net.prefixlen)
+ ipv6_changed += net.num_addresses
+ ipv6_entries_changed += 1
if new_asn == 0:
print(f"# {net} was AS{old_asn}")
elif old_asn == 0:
@@ -159,8 +163,9 @@ def main():
ipv6_change_str = "" if ipv6_changed == 0 else f" (2^{math.log2(ipv6_changed):.2f})"
print(
- f"# {ipv4_changed}{ipv4_change_str} IPv4 addresses changed; "
- f"{ipv6_changed}{ipv6_change_str} IPv6 addresses changed"
+f"""# Summary
+IPv4: {ipv4_entries_changed} entries with {ipv4_changed}{ipv4_change_str} addresses changed
+IPv6: {ipv6_entries_changed} entries with {ipv6_changed}{ipv6_change_str} addresses changed"""
)
elif args.subcommand == "diff_addrs":
state1 = load_file(args.infile1)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.