What the parser accepts is what the engine stores (#1281) #1282

Merged
jaylouisw merged 1 commit from fix/config-text-to-state into main 2026-11-09 22:04:03 +00:00
Owner

What the parser accepts is now what the engine stores.

Fixes #1281.

Three commands that stored something else

r1(config)#ip route 10.9.0.0 255.255.0.0 Gi0
Route added: 10.9.0.0/16 via Gi0            -> stored { gw: "Gi0", iface: null }

r1(config)#ip route 10.9.0.0 255.255.0.0 nonsense
Route added: 10.9.0.0/16 via nonsense       -> stored the same way: any word became a next hop

r1(config-if)#ip address 10.0.0.1/24
% Incomplete command                        -> no address, no hint what the form should be

r1(config-dhcp)#network 10.5.0.0/24
                                            -> stored network "10.5.0.0/24", which the pool validator
                                               rejects: the spelling the usage line advertises produced a
                                               pool that cannot serve

routeTo() reads r.gw as an address and r.iface as an egress. A port name in gw therefore produced a
route that is listed, installed, printed by show running-config — and then ARPs for an address called Gi0.
Measured on a two-router lab with the pc's LAN behind r2:

route on r1 ping to the pc
ip route 192.168.9.0 255.255.255.0 10.0.0.2 works
ip route 192.168.9.0 255.255.255.0 Gi0 fails: no ARP reply from 192.168.9.9

Fixed

The port-only form is legal and worth keeping — it is how you point at a segment — but it carries a packet only
when the far side proxies ARP for the destination, and nothing said so anywhere. It is now stored in the
egress field, and both surfaces say the rest:

r1(config)#ip route 192.168.9.0 255.255.255.0 Gi0
Route added: 192.168.9.0/24 out Gi0
  no next hop: this resolves by ARP on that segment, which needs proxy ARP on the far side

r1#show ip route
S  192.168.9.0    /24  [1/0] via -  Gi0  (no next hop: ARP for the destination on that segment)

Refusals, each naming the token and the route, none of them storing anything:

% 10.9.0.0/16: "nonsense" is neither a next-hop address nor an interface on r1
% 10.9.0.0/16: Gi0 is an interface, so it cannot also be followed by Gi0
% 10.9.0.0/16: no interface called "NoSuchPort"
% Invalid destination "not-an-address"

ip address <addr>/<len> says what is wrong and both accepted forms, and leaves the previous address alone:

% "10.0.0.77/24" is an address with a prefix length, not an address and a mask: use
  "ip address 10.0.0.77 255.255.255.0" or "ip address 10.0.0.77 24"

Inside a DHCP pool the /prefix spelling is split into network + mask with the one mask rule, so both
spellings produce identical state and identical printed config; /33 is refused quoting the value and
stores no half-network.

The route printer now emits three shapes rather than padding a missing gateway with an empty field, and all
three round-trip byte-identically.

Evidence

test/config-text-to-state.test.js — 34 checks, 23 of which fail with engine/cli.js reverted:

  • the port-only route stores {gw: null, iface: <port>}, warns at the console and is annotated in the table;
  • the lab: next-hop route carries the packet, port-only route does not, the failure names the address it
    could not resolve (no ARP reply from 192.168.9.9) and the table says why before the packet is sent;
  • four refusals, each leaving config.routes empty;
  • all three shapes save and restore byte-identically, with no empty field;
  • ip address …/24: quotes what was typed, shows both accepted forms, previous address untouched;
  • two DHCP spellings → identical state and identical config; /33 refused, nothing half-stored.

It drives CliSession directly rather than runCommands: runCommands interleaves prompt + command echoes,
and deciding which lines are echoes means guessing at prompt syntax — which broke on a refusal containing
<network> <mask>, where an angle bracket looked like a prompt.

Suite: 155 suites, 6,521 assertions, 0 failed.

What the parser accepts is now what the engine stores. Fixes #1281. ## Three commands that stored something else ``` r1(config)#ip route 10.9.0.0 255.255.0.0 Gi0 Route added: 10.9.0.0/16 via Gi0 -> stored { gw: "Gi0", iface: null } r1(config)#ip route 10.9.0.0 255.255.0.0 nonsense Route added: 10.9.0.0/16 via nonsense -> stored the same way: any word became a next hop r1(config-if)#ip address 10.0.0.1/24 % Incomplete command -> no address, no hint what the form should be r1(config-dhcp)#network 10.5.0.0/24 -> stored network "10.5.0.0/24", which the pool validator rejects: the spelling the usage line advertises produced a pool that cannot serve ``` `routeTo()` reads `r.gw` as an address and `r.iface` as an egress. A port name in `gw` therefore produced a route that is listed, installed, printed by `show running-config` — and then ARPs for an address called `Gi0`. Measured on a two-router lab with the pc's LAN behind r2: | route on r1 | ping to the pc | |---|---| | `ip route 192.168.9.0 255.255.255.0 10.0.0.2` | works | | `ip route 192.168.9.0 255.255.255.0 Gi0` | fails: `no ARP reply from 192.168.9.9` | ## Fixed The port-only form is legal and worth keeping — it is how you point at a segment — but it carries a packet only when the far side proxies ARP for the *destination*, and nothing said so anywhere. It is now stored in the egress field, and both surfaces say the rest: ``` r1(config)#ip route 192.168.9.0 255.255.255.0 Gi0 Route added: 192.168.9.0/24 out Gi0 no next hop: this resolves by ARP on that segment, which needs proxy ARP on the far side r1#show ip route S 192.168.9.0 /24 [1/0] via - Gi0 (no next hop: ARP for the destination on that segment) ``` Refusals, each naming the token and the route, none of them storing anything: ``` % 10.9.0.0/16: "nonsense" is neither a next-hop address nor an interface on r1 % 10.9.0.0/16: Gi0 is an interface, so it cannot also be followed by Gi0 % 10.9.0.0/16: no interface called "NoSuchPort" % Invalid destination "not-an-address" ``` `ip address <addr>/<len>` says what is wrong and both accepted forms, and leaves the previous address alone: ``` % "10.0.0.77/24" is an address with a prefix length, not an address and a mask: use "ip address 10.0.0.77 255.255.255.0" or "ip address 10.0.0.77 24" ``` Inside a DHCP pool the `/prefix` spelling is split into network + mask with the one mask rule, so both spellings produce **identical state and identical printed config**; `/33` is refused quoting the value and stores no half-network. The route printer now emits three shapes rather than padding a missing gateway with an empty field, and all three round-trip byte-identically. ## Evidence `test/config-text-to-state.test.js` — 34 checks, **23 of which fail with `engine/cli.js` reverted**: * the port-only route stores `{gw: null, iface: <port>}`, warns at the console and is annotated in the table; * the lab: next-hop route carries the packet, port-only route does not, the failure names the address it could not resolve (`no ARP reply from 192.168.9.9`) and the table says why **before** the packet is sent; * four refusals, each leaving `config.routes` empty; * all three shapes save and restore byte-identically, with no empty field; * `ip address …/24`: quotes what was typed, shows both accepted forms, previous address untouched; * two DHCP spellings → identical state and identical config; `/33` refused, nothing half-stored. It drives `CliSession` directly rather than `runCommands`: `runCommands` interleaves `prompt + command` echoes, and deciding which lines are echoes means guessing at prompt syntax — which broke on a refusal containing `<network> <mask>`, where an angle bracket looked like a prompt. Suite: 155 suites, 6,521 assertions, 0 failed.
What the parser accepts is what the engine stores (#1281)
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 15s
CI / Test (Node 20) (pull_request) Successful in 1m57s
CI / Test (Node 18) (pull_request) Successful in 2m3s
CI / Server smoke test (pull_request) Successful in 33s
CI / Docker build (pull_request) Successful in 41s
CI / Test (Node 22) (pull_request) Successful in 1m51s
cd5490777f
The census in #1279 proved state -> text. This is the other direction: a command that is accepted and stores
something other than what was typed, or nothing at all.

  ip route 10.9.0.0 255.255.0.0 Gi0       stored { gw: "Gi0", iface: null }
  ip route 10.9.0.0 255.255.0.0 nonsense  stored the same way - any word became a next hop
  ip address 10.0.0.1/24                  "% Incomplete command"
  ip dhcp pool / network 10.5.0.0/24      stored the string "10.5.0.0/24", which the pool validator
                                          rejects - the spelling the usage line advertises produced a pool
                                          that cannot serve

routeTo() reads r.gw as an address and r.iface as an egress, so a port name in gw produced a route that is
listed, installed, printed, and then ARPs for an address called "Gi0". Measured on a two-router lab with the
pc's LAN behind r2:

  ip route 192.168.9.0 255.255.255.0 10.0.0.2   ping works
  ip route 192.168.9.0 255.255.255.0 Gi0        ping fails: no ARP reply from 192.168.9.9

The port-only form is legal and worth keeping - it is how you point at a segment - but it carries a packet only
when the far side proxies ARP for the destination, and nothing said so anywhere:

  Route added: 192.168.9.0/24 out Gi0
    no next hop: this resolves by ARP on that segment, which needs proxy ARP on the far side

  S  192.168.9.0  /24  [1/0] via -  Gi0  (no next hop: ARP for the destination on that segment)

Refusals, each naming the token and the route, and storing nothing:
  "nonsense" is neither a next-hop address nor an interface on r1
  Gi0 is an interface, so it cannot also be followed by Gi0
  no interface called "NoSuchPort"
  Invalid destination "not-an-address"

ip address <addr>/<len> now says what is wrong and both accepted forms, instead of "Incomplete command", and
leaves the previous address alone. Inside a DHCP pool the /prefix spelling is split into network + mask with
the one mask rule, so both spellings produce identical state and identical printed config; an impossible
prefix (/33) is refused quoting the value and stores no half-network.

The route printer emits three shapes instead of padding a missing gateway with an empty field, and all three
round-trip byte-identically.

test/config-text-to-state.test.js (34 checks, 23 of which fail with engine/cli.js reverted). It drives
CliSession directly rather than runCommands: runCommands interleaves prompt+command echoes, and deciding which
lines are echoes means guessing at prompt syntax - which broke on a refusal containing <network> <mask>,
where an angle bracket looked like a prompt.

docs/CLI.md: static routes section with the three shapes, the note, and the four refusals; the ip address
refusal; the DHCP network spellings.

Suite: 155 suites, 6,521 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-09 22:03:59 +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!1282
No description provided.