A netmask is a run of ones, and one rule says so (#1249) #1250

Merged
jaylouisw merged 1 commit from fix/mask-rule into main 2026-11-09 18:45:22 +00:00
Owner

A netmask is a run of ones, and one rule says so

Fixes #1249.

R1(config-if)#ip address 10.9.9.9 255.0.255.0
IP address set on Gi0: 10.9.9.9/8              <- accepted, and the panel calls it /16

255.0.255.0 is a valid IPv4 address and not a netmask — it has no prefix length. Four places answered
the question "what prefix is this mask" four different ways:

mask net.prefixOf() dhcp.maskContiguous() ospf.maskPrefix() app.maskBits()
255.0.255.0 8 false null 16
255.255.255.253 30 false null 31
255.255.0.255 16 false null 24

So the router accepted it, routed on the raw mask, and the inspector summarised it as a number that
describes nothing — in the one panel you open to find out why a link behaves oddly.

Second half, quieter: ip address 10.0.0.1 24 stored the string "24". Anything parsing a dotted mask
— the front panel included — reads that as 0.0.0.24 and prints /2.

Third: ip address 10.9.9.9 garbage printed % Error: Invalid IPv4 address: garbage — the wrong
argument, because mask parsing was left to throw through the address path.

Now

  • engine/net.js owns the rule: isContiguousMask(), maskFromPrefix(), prefixOfInt(). maskToInt()
    keeps its contract — a bare number is still a prefix length — so no caller changes meaning.
  • the console refuses a non-contiguous mask, naming the mask and the rule, and leaves the previous address
    untouched; a bad address is still reported as an address.
  • the mask is stored in one spelling (dotted), whichever way it was typed, so nothing downstream has to
    guess.
  • the DHCP pool validator and the OSPF interface cost call the shared predicate instead of carrying their
    own copies; their contracts (a validation error, a null prefix) are unchanged.
  • the front panel applies the same rule: ? for a mask with no prefix length, and a bare number read as a
    prefix length.

Evidence

test/mask-rule.test.js — 31 checks:

  • all 33 prefix lengths agree across prefixOf, prefixOfInt, the panel, and the short spelling;
  • five non-contiguous masks: the engine calls none of them contiguous, and the panel returns ? for each
    rather than a plausible number;
  • the refusal, its message, and the previous address surviving it; a junk mask reported as a mask, a bad
    address still reported as an address, an out-of-range prefix length as a mask error;
  • /24 stored dotted, printed dotted by show running-config, and replayed to the same address and mask;
  • DHCP and OSPF still refuse what they refused, and agree with the shared predicate on every prefix length;
  • a lab carrying a bad mask still renders and still admits it cannot say.

Reverting engine/cli.js fails 11 of the 31.

docs/CLI.md documents the rule and the stored form under "Interface-mode commands".

Suite: 138 suites, 5,964 assertions, 0 failed.

A netmask is a run of ones, and one rule says so Fixes #1249. ``` R1(config-if)#ip address 10.9.9.9 255.0.255.0 IP address set on Gi0: 10.9.9.9/8 <- accepted, and the panel calls it /16 ``` `255.0.255.0` is a valid IPv4 *address* and not a netmask — it has no prefix length. Four places answered the question "what prefix is this mask" four different ways: | mask | `net.prefixOf()` | `dhcp.maskContiguous()` | `ospf.maskPrefix()` | `app.maskBits()` | |---|---|---|---|---| | `255.0.255.0` | 8 | false | null | **16** | | `255.255.255.253` | 30 | false | null | **31** | | `255.255.0.255` | 16 | false | null | **24** | So the router accepted it, routed on the raw mask, and the inspector summarised it as a number that describes nothing — in the one panel you open to find out why a link behaves oddly. **Second half, quieter:** `ip address 10.0.0.1 24` stored the string `"24"`. Anything parsing a dotted mask — the front panel included — reads that as `0.0.0.24` and prints `/2`. **Third:** `ip address 10.9.9.9 garbage` printed `% Error: Invalid IPv4 address: garbage` — the wrong argument, because mask parsing was left to throw through the address path. ## Now * `engine/net.js` owns the rule: `isContiguousMask()`, `maskFromPrefix()`, `prefixOfInt()`. `maskToInt()` keeps its contract — a bare number is still a prefix length — so no caller changes meaning. * the console refuses a non-contiguous mask, naming the mask and the rule, and leaves the previous address untouched; a bad address is still reported as an address. * the mask is stored in **one** spelling (dotted), whichever way it was typed, so nothing downstream has to guess. * the DHCP pool validator and the OSPF interface cost call the shared predicate instead of carrying their own copies; their contracts (a validation error, a `null` prefix) are unchanged. * the front panel applies the same rule: `?` for a mask with no prefix length, and a bare number read as a prefix length. ## Evidence `test/mask-rule.test.js` — 31 checks: * all **33 prefix lengths** agree across `prefixOf`, `prefixOfInt`, the panel, and the short spelling; * five non-contiguous masks: the engine calls none of them contiguous, and the panel returns `?` for each rather than a plausible number; * the refusal, its message, and the previous address surviving it; a junk mask reported as a mask, a bad address still reported as an address, an out-of-range prefix length as a mask error; * `/24` stored dotted, printed dotted by `show running-config`, and replayed to the same address and mask; * DHCP and OSPF still refuse what they refused, and agree with the shared predicate on every prefix length; * a lab carrying a bad mask still renders and still admits it cannot say. Reverting `engine/cli.js` fails 11 of the 31. `docs/CLI.md` documents the rule and the stored form under "Interface-mode commands". Suite: 138 suites, 5,964 assertions, 0 failed.
A netmask is a run of ones, and one rule says so (#1249)
All checks were successful
CI / Classify the change (pull_request) Successful in 11s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 13s
CI / Test (Node 20) (pull_request) Successful in 1m57s
CI / Test (Node 18) (pull_request) Successful in 2m0s
CI / Server smoke test (pull_request) Successful in 34s
CI / Docker build (pull_request) Successful in 38s
CI / Test (Node 22) (pull_request) Successful in 1m42s
046713060e
`ip address 10.9.9.9 255.0.255.0` was accepted. 255.0.255.0 is a valid IPv4 address and not a netmask - it
has no prefix length - and four places answered "what prefix is this mask" four different ways:

  engine/net.js    leading ones          255.0.255.0 -> 8
  engine/dhcp.js   a bit trick           refused
  engine/ospf.js   rebuilt and compared  null
  web/app.js       counted set bits      255.0.255.0 -> 16

So the router accepted it, routed on the raw mask, and the inspector summarised it as /16: a number that
describes nothing, in the panel you open to find out why a link behaves oddly.

Second half, quieter: `ip address 10.0.0.1 24` stored the string "24". Anything that parses a dotted mask -
the front panel included - reads that as 0.0.0.24 and prints /2.

Third: `ip address 10.9.9.9 garbage` said "% Error: Invalid IPv4 address: garbage" - the wrong argument.

Now:
* engine/net.js owns the rule: isContiguousMask(), maskFromPrefix(), prefixOfInt(), and maskToInt() keeps
  its existing contract (a bare number is still a prefix length).
* the console refuses a non-contiguous mask, naming the mask and the rule, and leaves the previous address
  untouched; a bad address is still reported as an address.
* the mask is stored in one spelling - the dotted form - whichever way it was typed, so nothing downstream
  guesses.
* the DHCP pool validator and the OSPF interface cost call the shared predicate instead of carrying their
  own; their contracts (a validation error, a null prefix) are unchanged.
* the front panel applies the same rule and shows "?" for a mask with no prefix length, and reads a bare
  number as a prefix length.

test/mask-rule.test.js (31 checks): all 33 prefix lengths agree across prefixOf, prefixOfInt, the panel and
the short spelling; none of five non-contiguous masks is called contiguous by the engine, and the panel says
"?" for each instead of a number; the refusal and its message; the previous address surviving it; a junk
mask reported as a mask; /24 stored dotted, printed dotted, and replayed to the same mask; a DHCP pool and
an OSPF interface still refusing what they refused; and a lab carrying a bad mask that still renders while
admitting it cannot say. Reverting engine/cli.js fails 11 of the 31.

Suite: 138 suites, 5,964 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-09 18:45:19 +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!1250
No description provided.