Show figures of the routing table on the home page (closes #154)
check / check (push) Canceled after 0s

The home page gets cards for the newest and oldest kept route, the newest
and oldest updated AS, the AS with the most prefixes, the ASes with a
single prefix and fifteen well-known networks. Two more cards count the
bogon announcements and the prefixes with several origin ASes. They link
to the new pages /bogons and /multiple-origins, which list up to 1,000
entries each.

The new package internal/bogon tells reserved prefixes and AS numbers,
from the IANA special-purpose and address space registries. Table.Overview
walks the table and lets the read lock go every 10,000 prefixes. The
server works the cards out once a minute and serves that copy. A new index
on asns(last_seen) finds the newest and oldest updated AS.

Model: opus-5-5
This commit was merged in pull request #196.
This commit is contained in:
2026-10-27 18:27:01 +01:00
parent e68be8254a
commit 281d162e27
23 changed files with 2240 additions and 6 deletions
+95
View File
@@ -0,0 +1,95 @@
package bogon_test
import (
"net/netip"
"strconv"
"testing"
"git.eeqj.de/sneak/routewatch/internal/bogon"
)
func TestPrefix(t *testing.T) {
t.Parallel()
tests := []struct {
prefix string
// want is why the prefix is reserved, or "" when it is not.
want string
}{
{"10.1.2.0/24", "Private-Use (10.0.0.0/8)"},
{"10.0.0.0/8", "Private-Use (10.0.0.0/8)"},
{"192.0.2.0/24", "Documentation (TEST-NET-1) (192.0.2.0/24)"},
{"2001:db8:1::/48", "Documentation (2001:db8::/32)"},
{"fd00::/8", "Unique-Local (fc00::/7)"},
// Multicast space, from the IANA address space registries.
{"224.0.0.0/4", "Multicast (224.0.0.0/4)"},
{"239.255.0.0/16", "Multicast (224.0.0.0/4)"},
{"ff00::/8", "Multicast (ff00::/8)"},
{"ff02::/16", "Multicast (ff00::/8)"},
// The most specific block names the reason.
{"0.0.0.0/32", "This host on this network (0.0.0.0/32)"},
{"2001:2::/48", "Benchmarking (2001:2::/48)"},
// Blocks that may be announced, inside reserved blocks.
{"192.0.0.9/32", ""},
{"2001:4:112::/48", ""},
// Blocks that may be announced, inside no reserved block.
{"192.175.48.0/24", ""},
{"2002::/16", ""},
// A prefix that holds a reserved block is not inside it.
{"192.0.0.0/16", ""},
{"0.0.0.0/0", ""},
// Prefixes anyone may announce.
{"8.8.8.0/24", ""},
{"2001:4860::/32", ""},
}
for _, tc := range tests {
t.Run(tc.prefix, func(t *testing.T) {
t.Parallel()
reason, reserved := bogon.Prefix(netip.MustParsePrefix(tc.prefix))
if reason != tc.want || reserved != (tc.want != "") {
t.Errorf("Prefix(%s) = %q, %v; want %q", tc.prefix, reason,
reserved, tc.want)
}
})
}
}
func TestASN(t *testing.T) {
t.Parallel()
tests := []struct {
asn int
// want is why the AS number is reserved, or "" when it is not.
want string
}{
{23456, "AS_TRANS (AS23456)"},
{64496, "Documentation (AS64496-AS64511)"},
{64512, "Private-Use (AS64512-AS65534)"},
{65534, "Private-Use (AS64512-AS65534)"},
{65535, "Last 16-bit AS number (AS65535)"},
{65551, "Documentation (AS65536-AS65551)"},
{4200000000, "Private-Use (AS4200000000-AS4294967294)"},
{4294967295, "Last 32-bit AS number (AS4294967295)"},
// AS 0 means no known origin, and the AS112 project uses AS 112.
{0, ""},
{112, ""},
// Not handed out yet, which is not counted.
{65552, ""},
{15169, ""},
{64495, ""},
}
for _, tc := range tests {
t.Run(strconv.Itoa(tc.asn), func(t *testing.T) {
t.Parallel()
reason, reserved := bogon.ASN(tc.asn)
if reason != tc.want || reserved != (tc.want != "") {
t.Errorf("ASN(%d) = %q, %v; want %q", tc.asn, reason, reserved,
tc.want)
}
})
}
}