Wire DHCP into the data path: the library had no caller #1055
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!1055
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/dhcp-wired-1051"
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?
engine/dhcp.jsmodelled DHCPv4 completely — pool normalisation, validation, DISCOVER/OFFER,REQUEST/ACK-NAK, renewals, reservations, exclusions, lease expiry — and nothing called it:
A host configured with
ip address dhcpset a flag, printed a confirmation, and stayed unaddressedfor the life of the lab. Every ping it sent then failed silently, so the lab read as a broken
configuration rather than a missing feature.
The caller
Simulator.computeDhcp()runs before the first packet of a run — when a real host would have doneit — and
engine/segment.jswalks the broadcast domain instead of assuming one:(which is what the convergence work in #1050 made meaningful);
The lease lands on the interface — address, mask, gateway, DNS, lease time — the default gateway
comes from the pool when the host had none, and the exchange is a timeline event, so a lab can read
the ACK and the pool it came from.
The bug that cost a debugging round
The first version asked
ipInPool(pool, serverIface.ip)to decide whether a server should answer.That function answers "can this address be handed out" — and a router's own interface address is
deliberately not allocatable, so every correctly configured server was rejected as "no pool in
this subnet". The right question is subnet membership. The comment now says so where the mistake
was made, because it is an easy one to make twice.
Four failures, not one
no-serverno-poolpool-exhaustednakReporting "no reply" for all four would have been the same bug in a different costume.
CLI
The pool is validated once, when the sub-mode is left.
networkbeforerangeis the secondkeystroke, not an error, and a CLI that scolds you mid-typing is a CLI people stop using. The
message is the library's own (
E_DHCP_BAD_RANGE: … both rangeStart and rangeEnd are required) —not a second opinion that can drift from the model.
Pools are serialised only when non-empty. A server that forgets its pools on save is broken, but
a device with none should not grow an empty array in every saved topology — the
examples-idempotentguard caught the first version of that, which is exactly why it exists.Test
test/dhcp-in-path.test.js— 51 assertions: a lease in the events and on the interface, two hostswith no collision, all four failure modes, exclusions and reservations from the CLI, the walk across
a switch and its refusal across a router, STP and VLAN boundaries, an early run that reports
converginginstead of failing, and a save/load round trip.Nine failed on the first run — one engine bug (
leaseSecondsis internal; the lease came out as thelibrary default 86400 instead of the configured 43200) and eight of my own test mistakes, mostly
hosts cabled to separate router ports and therefore in different subnets. Fixed in the test where
the test was wrong.
Docs
docs/SIMULATION.md§5.1 used to read "absent from the data path … the largest gap between what therepo looks like and what it does." It now documents what is modelled and, precisely, what is not:
no relay, so a central server cannot serve a remote subnet — by design rather than by accident —
plus no snooping, no Option 82, no DHCPv6, and leases that are computed at run start rather than
aged.
98 suites, 4791 assertions, all passing.
Closes #1051.