NAT from the console, and a ping that is actually translated (#1366) #1367
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!1367
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/nat-console"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
NAT from the console, and a ping that is actually translated. Fixes #1366.
engine/nat.jsmodels static, dynamic and PAT translation with a live table and ageing, and the flow path callsit on the way out and back in, emitting
nat-dropwhen a rule cannot translate. Nothing in the product everwrote
config.nat— not the CLI, not the UI, not the server, not a catalogue spec — so_isNat()was alwaysfalse and
docs/SIMULATION.mdcarried an "Absent in the CLI" row next to it.Worse, the one test anybody runs was wrong even with rules in the file. Both hooks began:
An ICMP echo has no
l4— the engine keeps it inframe.icmp— so a ping crossed a NAT router untouched. Thedocs recorded that too, as "Absent — important".
The console
Every rule is validated by
nat.js's ownvalidateRule(), so the console and the data path cannot disagree aboutwhat a rule means. Refusals name the reason and what would work:
The reports
show ip nat translationsdistinguishes nothing has crossed (No translations: no packet needing NAT has crossed this device) from traffic crossed and nothing needed translating — the same distinctionshow interfacesmakes for its counters.ICMP
The packet view now comes from
frame.icmpwhen there is nol4; only the address is rewritten (an echo isidentified by its id, not a port), and the events report
proto icmpwith a null port instead of dereferencingan
l4that is not there. Measured on an inside host at192.168.10.50behind a PAT pool:Survives a save
Serialized only when non-empty, restored on load, and printed by
show running-configpools before the rulesthat name them, so a restore replays.
test/config-completeness.test.jsgains the print declaration the suitedemands for a new config key (56 checks).
Evidence
test/nat-cli.test.js— 38 checks: pool and rule creation, seven kinds of refusal, a real ping translatedthrough PAT with the inside local and inside global in the table, the three report views, a lab with no rules that
still pings and says so, static port forwarding, save/reload, and the
noforms.engine/cli.js→ 21 of 38 failengine/simulator.js→ 7 of 38 fail (every translation check)docs/CLI.mdgains the command table, the refusals and the three show views;docs/SIMULATION.md's two "Absent"rows for NAT become "Modelled";
docs/ROADMAP.md's NAT item is ticked.npm run syntax— 254 files, all OK.npm test— 186 suites, 7,211 assertions, 0 failed.engine/nat.js models static, dynamic and PAT translation with a live table and ageing, and the flow path calls it on the way out and back in, emitting nat-drop when a rule cannot translate. Nothing in the product ever wrote config.nat: not the CLI, not the UI, not the server, not a catalogue spec. So Simulator._isNat() was always false, the whole mechanism was unreachable, and docs/SIMULATION.md carried 'Absent in the CLI' next to it. Worse, the one test anybody runs was wrong even with rules in the file. _natOutbound/_natInbound began if (!frame || !frame.l4 || !this._isNat(dev)) return 'pass'; and an ICMP echo has no l4 - the engine keeps it in frame.icmp. A ping therefore crossed a NAT router untouched, and the same docs section recorded it as 'Absent - important'. Now: - ip nat pool <name> <start> <end> netmask <mask> - ip nat inside source static <local> <global> [tcp|udp <port>] - ip nat inside source list <spec> pool <name> [overload] - ip nat inside source list <spec> interface <if> [overload] - no ip nat inside source | no ip nat pool <name> Every rule is validated by nat.js's own validateRule(), so the console and the data path cannot disagree about what a rule means. Refusals name the reason and what would work: overload on a multi-address pool, an ACL number where this model takes an address spec, an interface with no address, a pool that ends before it starts, a duplicate pool name, a pool still in use. show ip nat rules prints each rule as the command that would create it; show ip nat translations prints the engine's live table with its header; show ip nat statistics counts rules by type, pools and active translations. 'Nothing has crossed' and 'traffic crossed and nothing needed translating' are different answers and the report gives both. ICMP now reaches NAT: the packet view comes from frame.icmp when there is no l4, only the address is rewritten (an echo is identified by its id, not a port), and the events report proto icmp with a null port rather than dereferencing an l4 that is not there. The config survives a save (serialized only when non-empty, restored on load) and show running-config prints pools before the rules that name them, so a restore replays. test/nat-cli.test.js: 38 checks - pool and rule creation, seven kinds of refusal, a real ping translated through PAT with the inside local and inside global in the table, the report's three views, a lab with no rules that still pings and says so, static port forwarding, save/reload, and the no-forms. Reverting engine/cli.js fails 21 of 38; reverting engine/simulator.js fails 7 (every translation check). test/config-completeness.test.js gains the print declaration for the new config key (56 checks). docs: CLI.md gains the command table, the refusals and the three show views; SIMULATION.md's two 'Absent' rows for NAT become 'Modelled'; ROADMAP's NAT item is ticked. Suite: 186 suites, 7,211 assertions, 0 failed. Syntax: 254 files, all OK.