ping takes a name, and DNS can be read back (#1375) #1376

Merged
jaylouisw merged 1 commit from feat/ping-name into main 2026-11-10 19:47:59 +00:00
Owner

ping takes a name, and DNS can be read back. Fixes #1375.

Simulator.ping() has accepted a hostname since #241: it resolves through the lab's DNS servers, emits a dns
event, and keeps NXDOMAIN, NODATA and SERVFAIL apart because they have different causes. The console refused
anything that was not an address before the engine saw it:

if (!ip || !net.isIp(ip)) return ['% Invalid ping target: ' + (ip || '(none)')];

so the first command anybody types could not use the resolver the product already has. The same audit found
dns zone / dns add with no way to read a zone back. Same family as show power inline (#1295), the STP election
(#1365), NAT (#1367), OSPF (#1371) and DHCP bindings (#1373).

ping <name>

h1> ping r1.lab
Type escape sequence to abort.
Translating "r1.lab"...domain server (10.0.0.1) [OK]
  r1.lab -> 10.0.0.1
Sending 4, 100-byte ICMP Echos to 10.0.0.1, timeout is 2 seconds:
!!!!
Success rate is 100 percent (4/4)
Reply from 10.0.0.1: bytes=100 time=0.002 ms

A name that does not resolve is refused before anything is sent, with the status the resolver reported and a
sentence that says what to fix:

h1> ping nope.lab
% Could not resolve "nope.lab": NXDOMAIN - no zone any server here hosts contains that name
% Nothing was sent. Check the zone on 10.0.0.1, or the name servers this device asks.
h1> ping only-txt.lab
% Could not resolve "only-txt.lab": NODATA - the name exists on 10.0.0.1 but has no A record
% Nothing was sent. Add an A record: dns add only-txt.lab A <address>

Two smaller defects found on the way

  • ping 10.0.0.999 passed net.isIp(), which only checks the shape (three dots, one to three digits) — the
    engine then threw Invalid IPv4 address at the first packet. The guard now asks whether every octet is in range,
    and digits-and-dots that are not an address are refused as an address rather than looked up as a name and
    answered NXDOMAIN.
  • resolveName() reported the answering server by device label ("ISR 4331 branch router-r1"), which is not
    what a real box prints where an address belongs. It now carries serverId and serverIp, and the console prints
    the address.

show ip dns

r1> show ip dns
Zone lab (default TTL 3600) - 4 record(s)
  r1.lab                             3600    IN A        10.0.0.1
  www.lab                            3600    IN A        10.0.0.50
  alias.lab                          3600    IN CNAME    www.lab
  only-txt.lab                       3600    IN TXT      hello

% No name servers configured (use "ip name-server <address>" in config mode)

show ip dns zone <name> narrows to one zone, an unknown name lists the zones that exist, a zone the server would
refuse to answer for prints NOT answered: <reason>, a device with no zones says it is not a DNS server and names
the command that would make it one, and with no resolver configured the report says lookups fall back to any
server in the lab — which is what resolveName() actually does.

Evidence

test/dns-console.test.js — 32 checks: the translation names the server by address and the address it resolved
to; a CNAME chain resolves to its target; an address is not translated; each of NXDOMAIN / NODATA / SERVFAIL gets
its own sentence and no echo is sent; a malformed address is refused as an address; the zone view prints A and
CNAME records in zone-file shape; every printed A record is checked against dns.resolve(), so the page is a
claim that is verified rather than a rendering; an unknown zone lists the zones present; and a zone with an
unusable record is marked NOT answered.

  • reverting engine/cli.js → 29 of 32 fail
  • reverting engine/simulator.js → 1 of 32 (the server address in the translation)

help gains both commands; docs/CLI.md gains "Pinging a name, and reading DNS"; docs/SIMULATION.md gains the
row that says DNS is reported and how each failure is named.

Suite: 191 suites, 7,384 assertions, 0 failed. Syntax: 259 files, OK.

`ping` takes a name, and DNS can be read back. Fixes #1375. `Simulator.ping()` has accepted a hostname since #241: it resolves through the lab's DNS servers, emits a `dns` event, and keeps NXDOMAIN, NODATA and SERVFAIL apart because they have different causes. The console refused anything that was not an address **before the engine saw it**: ```js if (!ip || !net.isIp(ip)) return ['% Invalid ping target: ' + (ip || '(none)')]; ``` so the first command anybody types could not use the resolver the product already has. The same audit found `dns zone` / `dns add` with no way to read a zone back. Same family as `show power inline` (#1295), the STP election (#1365), NAT (#1367), OSPF (#1371) and DHCP bindings (#1373). ## `ping <name>` ``` h1> ping r1.lab Type escape sequence to abort. Translating "r1.lab"...domain server (10.0.0.1) [OK] r1.lab -> 10.0.0.1 Sending 4, 100-byte ICMP Echos to 10.0.0.1, timeout is 2 seconds: !!!! Success rate is 100 percent (4/4) Reply from 10.0.0.1: bytes=100 time=0.002 ms ``` A name that does not resolve is refused before anything is sent, with the status the resolver reported and a sentence that says what to fix: ``` h1> ping nope.lab % Could not resolve "nope.lab": NXDOMAIN - no zone any server here hosts contains that name % Nothing was sent. Check the zone on 10.0.0.1, or the name servers this device asks. h1> ping only-txt.lab % Could not resolve "only-txt.lab": NODATA - the name exists on 10.0.0.1 but has no A record % Nothing was sent. Add an A record: dns add only-txt.lab A <address> ``` ## Two smaller defects found on the way * **`ping 10.0.0.999` passed `net.isIp()`**, which only checks the shape (three dots, one to three digits) — the engine then threw `Invalid IPv4 address` at the first packet. The guard now asks whether every octet is in range, and digits-and-dots that are not an address are refused as an address rather than looked up as a name and answered NXDOMAIN. * **`resolveName()` reported the answering server by device label** (`"ISR 4331 branch router-r1"`), which is not what a real box prints where an address belongs. It now carries `serverId` and `serverIp`, and the console prints the address. ## `show ip dns` ``` r1> show ip dns Zone lab (default TTL 3600) - 4 record(s) r1.lab 3600 IN A 10.0.0.1 www.lab 3600 IN A 10.0.0.50 alias.lab 3600 IN CNAME www.lab only-txt.lab 3600 IN TXT hello % No name servers configured (use "ip name-server <address>" in config mode) ``` `show ip dns zone <name>` narrows to one zone, an unknown name lists the zones that exist, a zone the server would refuse to answer for prints `NOT answered: <reason>`, a device with no zones says it is not a DNS server and names the command that would make it one, and with no resolver configured the report says lookups fall back to **any** server in the lab — which is what `resolveName()` actually does. ## Evidence `test/dns-console.test.js` — **32 checks**: the translation names the server by address and the address it resolved to; a CNAME chain resolves to its target; an address is not translated; each of NXDOMAIN / NODATA / SERVFAIL gets its own sentence and **no echo is sent**; a malformed address is refused as an address; the zone view prints A and CNAME records in zone-file shape; **every printed A record is checked against `dns.resolve()`**, so the page is a claim that is verified rather than a rendering; an unknown zone lists the zones present; and a zone with an unusable record is marked `NOT answered`. * reverting `engine/cli.js` → **29 of 32 fail** * reverting `engine/simulator.js` → 1 of 32 (the server address in the translation) `help` gains both commands; `docs/CLI.md` gains "Pinging a name, and reading DNS"; `docs/SIMULATION.md` gains the row that says DNS is reported and how each failure is named. Suite: **191 suites, 7,384 assertions, 0 failed**. Syntax: 259 files, OK.
ping takes a name, and DNS can be read back (#1375)
Some checks failed
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 15s
CI / Classify the change (pull_request) Successful in 19s
CI / Test (Node 18) (pull_request) Successful in 3m15s
CI / Test (Node 20) (pull_request) Successful in 2m56s
CI / Server smoke test (pull_request) Successful in 33s
CI / Docker build (pull_request) Successful in 1m19s
CI / Test (Node 22) (pull_request) Failing after 2m51s
9ead94a54d
Simulator.ping() has accepted a hostname since #241: it resolves through the lab's DNS servers, emits a dns
event, and keeps NXDOMAIN, NODATA and SERVFAIL apart because they have different causes. The console's
ping refused anything that was not an address BEFORE the engine saw it:

    if (!ip || !net.isIp(ip)) return ['% Invalid ping target: ...'];

so the first command anybody types could not use the resolver the product already has. The same audit
turned up dns zone / dns add with no way to read a zone back. Same family as show power inline (#1295), the
STP election (#1365), NAT (#1367), OSPF (#1371) and DHCP bindings (#1373).

ping <name> now resolves first and prints what a box prints:

    Translating "r1.lab"...domain server (10.0.0.1) [OK]
      r1.lab -> 10.0.0.1
    Sending 4, 100-byte ICMP Echos to 10.0.0.1, timeout is 2 seconds:
    !!!!
    Success rate is 100 percent (4/4)

A name that does not resolve is refused before anything is sent, with the status the resolver reported and
a sentence that says what to fix: NXDOMAIN (no hosted zone has the name), NODATA (the name exists, there is
no A record - with the 'dns add' line that would fix it), SERVFAIL (no device hosts a zone, or no listed
server answered).

Two smaller defects found on the way:
  - 'ping 10.0.0.999' passed net.isIp(), which only checks the shape (three dots, one to three digits), and
    the engine threw 'Invalid IPv4 address' at the first packet. The guard now asks whether every octet is
    in range, and digits-and-dots that are not an address are refused as an address rather than looked up
    as a name and answered NXDOMAIN.
  - resolveName() reported the answering server by device label ("ISR 4331 branch router-r1"), which is not
    what a real box prints where an address belongs. It now carries serverId and serverIp, and the console
    prints the address.

show ip dns [zone [<name>]] reads the zones back, record by record, with TTLs, in zone-file shape; a zone
the server would refuse to answer for prints 'NOT answered: <reason>'; a device with no zones says it is
not a DNS server and names the command that would make it one; and with no resolver configured the report
says lookups fall back to any server in the lab, which is what resolveName() actually does.

Evidence: test/dns-console.test.js, 32 checks - the translation names the server by address and the address
it resolved to, a CNAME chain resolves to its target, an address is not translated, each of NXDOMAIN /
NODATA / SERVFAIL is reported with its own sentence and no echo is sent, a malformed address is refused as
an address, the zone view prints A and CNAME records in zone-file shape, every printed A record is checked
against dns.resolve() so the page is a claim that is verified, an unknown zone lists the zones present, and
a zone with an unusable record is marked NOT answered. Reverting engine/cli.js fails 29 of 32; reverting
engine/simulator.js fails 1 (the server address in the translation).

help gains both commands; docs/CLI.md gains 'Pinging a name, and reading DNS'; docs/SIMULATION.md gains the
row that says DNS is reported and how each failure is named.

Suite: 191 suites, 7,384 assertions, 0 failed. Syntax: 259 files, OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-10 19:47:56 +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!1376
No description provided.