Ignore routes shorter than /8 or /16 in the IP lookup #59

Merged
clawbot merged 1 commits from issue-57-ip-lookup-min-mask-length into next 2026-10-14 17:23:52 +02:00
Collaborator

Fixes #57.

The IP lookup (/ip/... and /api/v1/ip/...) tried every mask length down to /0, so a default route or a very short route such as 2000::/3 was reported as the owner of any address it covered until a more specific route had been seen.

The lookup now stops at /8 for IPv4 and /16 for IPv6, two named constants next to the other address constants in internal/database/database.go. An address covered only by shorter routes gets the existing "no route found" answer.

Worth knowing:

  • A /8 or /16 route itself is still used; only shorter ones are skipped.
  • The live tables still store the short routes; only the lookup skips them.
  • The new test TestGetIPInfoIgnoresShortRoutes fails on next without the fix. It writes its prefixes out (a /7 and a /8 for IPv4, a /15 and a /16 for IPv6), so a limit one bit off either way fails it.
  • README "IP Lookup" says routes shorter than those lengths are not used, and its lookup counts now read at most 25 (IPv4) and 113 (IPv6).
  • TODO.md is unchanged: its line for this fix is added by #72.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/routewatch/issues/57. The IP lookup (`/ip/...` and `/api/v1/ip/...`) tried every mask length down to /0, so a default route or a very short route such as `2000::/3` was reported as the owner of any address it covered until a more specific route had been seen. The lookup now stops at /8 for IPv4 and /16 for IPv6, two named constants next to the other address constants in `internal/database/database.go`. An address covered only by shorter routes gets the existing "no route found" answer. Worth knowing: - A /8 or /16 route itself is still used; only shorter ones are skipped. - The live tables still store the short routes; only the lookup skips them. - The new test `TestGetIPInfoIgnoresShortRoutes` fails on `next` without the fix. It writes its prefixes out (a /7 and a /8 for IPv4, a /15 and a /16 for IPv6), so a limit one bit off either way fails it. - README "IP Lookup" says routes shorter than those lengths are not used, and its lookup counts now read at most 25 (IPv4) and 113 (IPv6). - `TODO.md` is unchanged: its line for this fix is added by https://git.eeqj.de/sneak/routewatch/issues/72. Model: opus-5-5
clawbot added the needs-review label 2026-10-14 14:46:15 +02:00
clawbot self-assigned this 2026-10-14 14:46:15 +02:00
Author
Collaborator
  1. TODO.md has no Completed Steps line for this fix. The repo's TODO.md workflow puts the TODO.md change in the same commit as the work, and every earlier issue PR added a dated line there. Acceptable: a 2026-10-14 line at the top of Completed Steps saying the IP lookup no longer uses routes shorter than /8 for IPv4 or /16 for IPv6, so an address covered only by such routes gets "no route found", ending in (closes #57).
  2. internal/database/database_test.go, TestGetIPInfoIgnoresShortRoutes: neither limit is tested at its exact value. Nothing checks that a /16 IPv6 route is used, or that a route one bit shorter than a limit (a /15 IPv6 or a /7 IPv4 route) is not. So a wrong value in minLookupMaskLengthV4 or minLookupMaskLengthV6 would go unnoticed, for example 32 for IPv6, which would ignore every IPv6 route from /17 to /31. The PR body's "A /8 or /16 route itself is still used" is not tested for /16. Acceptable: the test also checks that a /16 IPv6 route is used and that a /15 IPv6 route and a /7 IPv4 route are not.

Model: opus-5-5

1. `TODO.md` has no Completed Steps line for this fix. The repo's `TODO.md` workflow puts the `TODO.md` change in the same commit as the work, and every earlier issue PR added a dated line there. Acceptable: a 2026-10-14 line at the top of Completed Steps saying the IP lookup no longer uses routes shorter than /8 for IPv4 or /16 for IPv6, so an address covered only by such routes gets "no route found", ending in `(closes #57)`. 2. `internal/database/database_test.go`, `TestGetIPInfoIgnoresShortRoutes`: neither limit is tested at its exact value. Nothing checks that a /16 IPv6 route is used, or that a route one bit shorter than a limit (a /15 IPv6 or a /7 IPv4 route) is not. So a wrong value in `minLookupMaskLengthV4` or `minLookupMaskLengthV6` would go unnoticed, for example 32 for IPv6, which would ignore every IPv6 route from /17 to /31. The PR body's "A /8 or /16 route itself is still used" is not tested for /16. Acceptable: the test also checks that a /16 IPv6 route is used and that a /15 IPv6 route and a /7 IPv4 route are not. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-14 15:12:22 +02:00
clawbot added 1 commit 2026-10-14 15:29:24 +02:00
The IP lookup tried every mask length down to /0, so a default route or
a very short route such as 2000::/3 was reported as the owner of any
address it covered until a more specific route was seen. Such a route
only says where a peer sends traffic it has no better route for.

The lookup now stops at /8 for IPv4 and /16 for IPv6; an address covered
only by shorter routes gets "no route found". The live tables still
store those routes. README states the limit.

Model: opus-5-5
clawbot force-pushed issue-57-ip-lookup-min-mask-length from 4c9802b46c to 78b58a9188 2026-10-14 15:29:24 +02:00 Compare
clawbot added needs-review and removed needs-rework labels 2026-10-14 15:56:29 +02:00
Author
Collaborator
  1. TODO.md left unchanged: its line for this fix is added by the plan at #72 (comment).
  2. TestGetIPInfoIgnoresShortRoutes now also checks that a /15 IPv6 and a /7 IPv4 route are not used and that a /16 IPv6 route is; it also checks a /8 IPv4 route is used, so both limits are tested at their exact value in one place.

Model: opus-5-5

1. `TODO.md` left unchanged: its line for this fix is added by the plan at https://git.eeqj.de/sneak/routewatch/issues/72#issuecomment-139587. 2. `TestGetIPInfoIgnoresShortRoutes` now also checks that a /15 IPv6 and a /7 IPv4 route are not used and that a /16 IPv6 route is; it also checks a /8 IPv4 route is used, so both limits are tested at their exact value in one place. Model: opus-5-5
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 521c632087 into next 2026-10-14 17:23:52 +02:00
clawbot deleted branch issue-57-ip-lookup-min-mask-length 2026-10-14 17:23:53 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/routewatch#59