An address is an address (#1411) #1412

Merged
jaylouisw merged 1 commit from fix/one-address-rule into main 2026-11-11 01:53:24 +00:00
Owner

An address is an address. Fixes #1411.

Found by asking one question of every door that takes an address: what happens if I type one that cannot exist?

r1(config)#ip name-server 300.1.1.1        → Name server 300.1.1.1
r1(config)#ip default-gateway 300.1.1.1    → Default gateway: 300.1.1.1
r1(config)#ip route 300.1.1.0 255.255.255.0 10.1.1.9
                                           → Route added: 300.1.1.0/24 via 10.1.1.9
r1(config)#ip route 192.0.2.0 255.255.255.0 300.1.1.9
                                           → Route added: 192.0.2.0/24 via 300.1.1.9
r1(config)#ip nat pool NP 300.1.1.1 300.1.1.9 netmask 255.255.255.0
                                           → NAT pool "NP" 300.1.1.1 - 300.1.1.9 netmask 255.255.255.0
r1(config-router)#neighbor 300.1.1.1 remote-as 65002
                                           → BGP neighbor 300.1.1.1 remote-as 65002

Eight doors took it, because net.isIp() asked the wrong question: four dotted groups of one to three digits, so
300.1.1.1 and 10.0.0.999 were addresses as far as every caller was concerned. ipToInt() has always checked
the octets — that is why ip address, vrrp 1 ip and ping refused the same value — and ping had already
worked around this by writing a private strict helper beside the weak predicate instead of fixing it (#1379).

What changed

  • net.isIp() asks the parser (ipToInt), so every caller that already used it — the DHCP pool validator, the OSPF
    interface checks, the console doors — gets the right answer at once, and the six hand-written copies of the shape
    regex in engine/cli.js plus two in engine/bgp.js are gone. Each door quotes the value it refused, and the NAT
    and BGP doors name the offending address rather than falling back to a usage line.
  • A mask is a mask. ip route "validated" its mask by calling maskToInt() and throwing the result away, and
    maskToInt() turns a non-contiguous mask into an integer rather than refusing it — so
    ip route 192.0.2.0 255.0.255.0 10.1.1.9 answered Route added: 192.0.2.0/8 and installed a prefix nobody asked
    for. It now applies the contiguity rule and the sentence ip address has always used, and a NAT pool netmask is
    asked the same question.
  • A route with nowhere to go is not installed. ip route <dest> <mask> with neither a next hop nor an
    interface was accepted as on-link, and the table then described it with "no next hop: ARP for the destination on
    that segment" — naming a segment the command never mentioned. It is now an incomplete command. The
    interface-only form is still legal and still carries its caveat.
  • access-list 10 permit 300.1.1.0 0.0.0.255 answered % [object Object]: the refusal printed the error object
    instead of its message.

Evidence

test/address-rule.test.js — 26 checks. The predicate refuses 300.1.1.1, 10.0.0.999, 9999.1.1.1, 1.2.3,
1.2.3.4.5, '', a word and a missing value, and still accepts the whole legal range; eight doors refuse with the
value quoted and never reach a config; the BGP neighbour names the address; the ACL refusal is a sentence; a
non-contiguous mask is refused in both directions while /24 as a prefix length and a real /25 still work; a route
with no next hop is refused and never appears in the table or the config while the interface-only form still works
and still warns; a 50-case matrix (five impossible addresses × ten doors) leaves nothing in a show running-config
or a show ip route; the seven legal forms are all still accepted (no over-refusal); and a sweep over every model
that can route (700+) stores none of them.

Reverting engine/net.js fails 6 of the 26, engine/cli.js 11.

test/nat-cli.test.js: its "bad address gets the usage line" assertion pinned the old ambiguous answer; it now
asserts the address is named, and that a missing operand still gets the usage line.

docs/CLI.md: "An address is an address", with the mask and no-next-hop rules beside it.

Suite: 207 suites, 7,965 assertions, 0 failed. Syntax: 275 files, OK.

An address is an address. Fixes #1411. Found by asking one question of every door that takes an address: what happens if I type one that cannot exist? ``` r1(config)#ip name-server 300.1.1.1 → Name server 300.1.1.1 r1(config)#ip default-gateway 300.1.1.1 → Default gateway: 300.1.1.1 r1(config)#ip route 300.1.1.0 255.255.255.0 10.1.1.9 → Route added: 300.1.1.0/24 via 10.1.1.9 r1(config)#ip route 192.0.2.0 255.255.255.0 300.1.1.9 → Route added: 192.0.2.0/24 via 300.1.1.9 r1(config)#ip nat pool NP 300.1.1.1 300.1.1.9 netmask 255.255.255.0 → NAT pool "NP" 300.1.1.1 - 300.1.1.9 netmask 255.255.255.0 r1(config-router)#neighbor 300.1.1.1 remote-as 65002 → BGP neighbor 300.1.1.1 remote-as 65002 ``` Eight doors took it, because `net.isIp()` asked the wrong question: four dotted groups of one to three digits, so `300.1.1.1` and `10.0.0.999` were addresses as far as every caller was concerned. `ipToInt()` has always checked the octets — that is why `ip address`, `vrrp 1 ip` and `ping` refused the same value — and `ping` had already worked around this by writing a private strict helper beside the weak predicate instead of fixing it (#1379). ## What changed * `net.isIp()` asks the parser (`ipToInt`), so every caller that already used it — the DHCP pool validator, the OSPF interface checks, the console doors — gets the right answer at once, and the six hand-written copies of the shape regex in `engine/cli.js` plus two in `engine/bgp.js` are gone. Each door quotes the value it refused, and the NAT and BGP doors name the offending address rather than falling back to a usage line. * **A mask is a mask.** `ip route` "validated" its mask by calling `maskToInt()` and throwing the result away, and `maskToInt()` turns a non-contiguous mask into an integer rather than refusing it — so `ip route 192.0.2.0 255.0.255.0 10.1.1.9` answered `Route added: 192.0.2.0/8` and installed a prefix nobody asked for. It now applies the contiguity rule and the sentence `ip address` has always used, and a NAT pool netmask is asked the same question. * **A route with nowhere to go is not installed.** `ip route <dest> <mask>` with neither a next hop nor an interface was accepted as `on-link`, and the table then described it with "no next hop: ARP for the destination on that segment" — naming a segment the command never mentioned. It is now an incomplete command. The interface-only form is still legal and still carries its caveat. * `access-list 10 permit 300.1.1.0 0.0.0.255` answered `% [object Object]`: the refusal printed the error object instead of its message. ## Evidence `test/address-rule.test.js` — **26 checks**. The predicate refuses `300.1.1.1`, `10.0.0.999`, `9999.1.1.1`, `1.2.3`, `1.2.3.4.5`, `''`, a word and a missing value, and still accepts the whole legal range; eight doors refuse with the value quoted and never reach a config; the BGP neighbour names the address; the ACL refusal is a sentence; a non-contiguous mask is refused in both directions while `/24` as a prefix length and a real `/25` still work; a route with no next hop is refused and never appears in the table or the config while the interface-only form still works and still warns; a 50-case matrix (five impossible addresses × ten doors) leaves nothing in a `show running-config` or a `show ip route`; the seven legal forms are all still accepted (no over-refusal); and a sweep over every model that can route (700+) stores none of them. Reverting `engine/net.js` fails **6 of the 26**, `engine/cli.js` **11**. `test/nat-cli.test.js`: its "bad address gets the usage line" assertion pinned the old ambiguous answer; it now asserts the address is named, and that a missing operand still gets the usage line. `docs/CLI.md`: "An address is an address", with the mask and no-next-hop rules beside it. Suite: **207 suites, 7,965 assertions, 0 failed**. Syntax: 275 files, OK.
An address is an address (#1411)
All checks were successful
CI / Classify the change (pull_request) Successful in 10s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 12s
CI / Test (Node 20) (pull_request) Successful in 2m50s
CI / Test (Node 18) (pull_request) Successful in 3m0s
CI / Server smoke test (pull_request) Successful in 29s
CI / Docker build (pull_request) Successful in 37s
CI / Test (Node 22) (pull_request) Successful in 2m28s
90c2e00b0a
Found by asking one question of every door that takes an address: what happens if I type one that cannot exist?

    r1(config)#ip name-server 300.1.1.1        → Name server 300.1.1.1
    r1(config)#ip default-gateway 300.1.1.1    → Default gateway: 300.1.1.1
    r1(config)#ip route 300.1.1.0 255.255.255.0 10.1.1.9
                                               → Route added: 300.1.1.0/24 via 10.1.1.9
    r1(config)#ip route 192.0.2.0 255.255.255.0 300.1.1.9
                                               → Route added: 192.0.2.0/24 via 300.1.1.9
    r1(config)#ip nat pool NP 300.1.1.1 300.1.1.9 netmask 255.255.255.0
                                               → NAT pool "NP" 300.1.1.1 - 300.1.1.9 netmask 255.255.255.0
    r1(config-router)#neighbor 300.1.1.1 remote-as 65002
                                               → BGP neighbor 300.1.1.1 remote-as 65002

Eight doors took it, because `net.isIp()` asked the wrong question: four dotted groups of one to three digits, so
`300.1.1.1` and `10.0.0.999` were addresses. `ipToInt()` has always checked the octets - that is why `ip address`,
`vrrp 1 ip` and `ping` refused the same value - and `ping` had already worked around this by writing a private
strict helper beside the weak predicate instead of fixing it (#1379).

Fixed: `net.isIp()` asks the parser (`ipToInt`), so every caller that already used it - the DHCP pool validator, the
OSPF interface checks, the console doors - gets the right answer at once, and the six hand-written copies of the
shape regex in `engine/cli.js` plus two in `engine/bgp.js` are gone. Each door quotes the value it refused, and the
NAT and BGP doors name the offending address instead of falling back to a usage line.

Two neighbours of the same mistake, found in the same sweep:

* **A mask is a mask.** `ip route` "validated" its mask by calling `maskToInt()` and throwing the result away, and
  `maskToInt()` turns a non-contiguous mask into an integer rather than refusing it - so
  `ip route 192.0.2.0 255.0.255.0 10.1.1.9` answered `Route added: 192.0.2.0/8` and installed a prefix nobody asked
  for. It now applies the contiguity rule and the sentence `ip address` has always used, and a NAT pool netmask is
  asked the same question.
* **A route with nowhere to go is not installed.** `ip route <dest> <mask>` with neither a next hop nor an
  interface was accepted as `on-link`, and the table then described it with "no next hop: ARP for the destination
  on that segment" - naming a segment the command never mentioned. It is now an incomplete command. The
  interface-only form is still legal and still carries its caveat.
* `access-list 10 permit 300.1.1.0 0.0.0.255` answered `% [object Object]`: the refusal printed the error object
  instead of its message.

Evidence: `test/address-rule.test.js`, 26 checks. The predicate refuses `300.1.1.1`, `10.0.0.999`, `9999.1.1.1`,
`1.2.3`, `1.2.3.4.5`, `''`, a word and a missing value, and still accepts the whole legal range; eight doors refuse
with the value quoted and never reach a config; the BGP neighbour names the address; the ACL refusal is a sentence;
a non-contiguous mask is refused in both directions while `/24` as a prefix length and a real `/25` still work; a
route with no next hop is refused and never appears in the table or the config while the interface-only form still
works and still warns; a 50-case matrix (five impossible addresses × ten doors) leaves nothing in a
`show running-config` or a `show ip route`; the seven legal forms are all still accepted (no over-refusal); and a
sweep over every model that can route (700+) stores none of them.

Reverting `engine/net.js` fails 6 of the 26, `engine/cli.js` 11.

`test/nat-cli.test.js`: its "bad address gets the usage line" assertion pinned the old ambiguous answer; it now
asserts the address is named, and that a missing operand still gets the usage line.

docs/CLI.md: "An address is an address", with the mask and no-next-hop rules beside it.

Suite: 207 suites, 7,965 assertions, 0 failed. Syntax: 275 files, OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-11 01:53:22 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1412
No description provided.