A VLAN parameter is not a mode change, and a port has one method (#1285) #1286

Merged
jaylouisw merged 1 commit from fix/switchport-mode-and-one-method into main 2026-11-09 22:27:22 +00:00
Owner

A VLAN parameter is not a mode change, and a port has one method.

Fixes #1285.

1. switchport trunk native vlan on an access port made it a trunk

sw1(config-if)#switchport trunk native vlan 20
Trunk native VLAN 20 on Fa0/1
sw1(config-if)#end
sw1#show running-config
interface Fa0/1                       <- and nothing else: the value is not in the backup either

vlan.mode was access before the command and trunk after. The same for switchport trunk allowed vlan 10,20, and in the other direction switchport access vlan 30 on a trunk turned the trunk into an access
port.

  • the data plane follows the mode, so a port that was carrying VLAN 1 started emitting trunks for VLAN
    20 — a change in a column nobody typed into;
  • staging a trunk before the cable is patched is what the command is for, and what real gear accepts: the
    value is stored, the mode is left alone;
  • because the printer emitted trunk parameters only in trunk mode, the stored value then vanished from the
    backup and never came back on restore.

2. A port held a static address and a DHCP client at once

R1(config-if)#ip address 10.0.0.1 255.255.255.0
R1(config-if)#ip address dhcp
Interface Gi0/0 set to DHCP

state afterwards: { ip: "10.0.0.1", dhcp: true }.

  • it held an address it did not own, and routeTo() would route for it;
  • show ip interface brief reported Method DHCP beside that address;
  • show running-config printed only the static line, so restoring the backup lost the DHCP intent.

The reverse direction already cleared the flag, but silently. no ip address answered "IP address removed
from Gi0/0" whether or not there was an address and whether or not the port was a DHCP client.

3. Found while testing (2): the backup baked in a leased address

A DHCP host that had leased 10.0.0.100 printed ip address 10.0.0.100 255.255.255.0. Restored on another
network, that host claims a stale address and never asks for a new one.

After

sw1(config-if)#switchport trunk native vlan 20
Trunk native VLAN 20 on Fa0/1 (stored; the port is in access mode - set "switchport mode trunk" to use it)

sw1(config-if)#switchport mode trunk                 <- and now, silently, it is in use

R1(config-if)#ip address dhcp
Interface Gi0/0 set to DHCP (static address 10.0.0.1/24 removed)

R1(config-if)#no ip address
% No IP address on Gi0/0
  • only switchport mode changes the mode; the three parameter commands store and say when the value is not
    yet in use, and say nothing when it is;
  • the mode and the parameters print independently, so a staged trunk survives a backup in either mode;
  • one method per port, in both directions, with the displaced method named;
  • no ip address names what it removed, or refuses when there is nothing;
  • show running-config prints ip address dhcp for a leased host, never the leased address.

Evidence

test/switchport-mode.test.js — 32 checks. test/interface-method.test.js — 26 checks. With engine/cli.js
reverted, the two suites report 17 and 13 failures respectively.

  • staging leaves the mode alone in both directions, says what it stored and what would use it, and a value
    used immediately gets no note;
  • the data plane follows the mode: a staged trunk carries VLAN 1 and drops 20, and after switchport mode trunk carries 20 while still dropping what the allowed list omits;
  • show vlan lists the port under the VLAN it carries, not the one it is staged for;
  • all four settings print under an access port, and the backup replays byte for byte into the same mode and
    the same parameters; the default trunk and access cases print exactly what they printed before (the existing
    45-check round-trip suite still passes unchanged);
  • a static address does not survive ip address dhcp and the displaced address is named; a DHCP client does
    not survive a static address;
  • no ip address distinguishes nothing / static / dhcp;
  • fifteen port histories leave exactly one method, and never an address without a mask;
  • a host moved from a static address to DHCP gets a real lease from a real pool — an address the pool hands
    out, not the one it used to have — pings successfully, and prints ip address dhcp in its backup.

docs/CLI.md: the interface and VLAN sections now state the one-method rule, that the backup prints the method
rather than a leased address, and that a VLAN parameter is not a mode change.

Suite: 158 suites, 6,629 assertions, 0 failed.

A VLAN parameter is not a mode change, and a port has one method. Fixes #1285. ## 1. `switchport trunk native vlan` on an access port made it a trunk ``` sw1(config-if)#switchport trunk native vlan 20 Trunk native VLAN 20 on Fa0/1 sw1(config-if)#end sw1#show running-config interface Fa0/1 <- and nothing else: the value is not in the backup either ``` `vlan.mode` was `access` before the command and `trunk` after. The same for `switchport trunk allowed vlan 10,20`, and in the other direction `switchport access vlan 30` on a trunk turned the trunk into an access port. * **the data plane follows the mode**, so a port that was carrying VLAN 1 started emitting trunks for VLAN 20 — a change in a column nobody typed into; * staging a trunk before the cable is patched is what the command is *for*, and what real gear accepts: the value is stored, the mode is left alone; * because the printer emitted trunk parameters only in trunk mode, the stored value then vanished from the backup and never came back on restore. ## 2. A port held a static address and a DHCP client at once ``` R1(config-if)#ip address 10.0.0.1 255.255.255.0 R1(config-if)#ip address dhcp Interface Gi0/0 set to DHCP ``` state afterwards: `{ ip: "10.0.0.1", dhcp: true }`. * it held an address it did not own, and `routeTo()` would route for it; * `show ip interface brief` reported Method `DHCP` beside that address; * `show running-config` printed only the static line, so restoring the backup lost the DHCP intent. The reverse direction already cleared the flag, but silently. `no ip address` answered "IP address removed from Gi0/0" whether or not there was an address and whether or not the port was a DHCP client. ## 3. Found while testing (2): the backup baked in a leased address A DHCP host that had leased `10.0.0.100` printed `ip address 10.0.0.100 255.255.255.0`. Restored on another network, that host claims a stale address and never asks for a new one. ## After ``` sw1(config-if)#switchport trunk native vlan 20 Trunk native VLAN 20 on Fa0/1 (stored; the port is in access mode - set "switchport mode trunk" to use it) sw1(config-if)#switchport mode trunk <- and now, silently, it is in use R1(config-if)#ip address dhcp Interface Gi0/0 set to DHCP (static address 10.0.0.1/24 removed) R1(config-if)#no ip address % No IP address on Gi0/0 ``` * only `switchport mode` changes the mode; the three parameter commands store and say when the value is not yet in use, and say nothing when it is; * the mode and the parameters print independently, so a staged trunk survives a backup in either mode; * one method per port, in both directions, with the displaced method named; * `no ip address` names what it removed, or refuses when there is nothing; * `show running-config` prints `ip address dhcp` for a leased host, never the leased address. ## Evidence `test/switchport-mode.test.js` — 32 checks. `test/interface-method.test.js` — 26 checks. With `engine/cli.js` reverted, the two suites report **17** and **13** failures respectively. * staging leaves the mode alone in both directions, says what it stored and what would use it, and a value used immediately gets no note; * the data plane follows the mode: a staged trunk carries VLAN 1 and drops 20, and after `switchport mode trunk` carries 20 while still dropping what the allowed list omits; * `show vlan` lists the port under the VLAN it carries, not the one it is staged for; * all four settings print under an access port, and the backup replays **byte for byte** into the same mode and the same parameters; the default trunk and access cases print exactly what they printed before (the existing 45-check round-trip suite still passes unchanged); * a static address does not survive `ip address dhcp` and the displaced address is named; a DHCP client does not survive a static address; * `no ip address` distinguishes nothing / static / dhcp; * fifteen port histories leave exactly one method, and never an address without a mask; * a host moved from a static address to DHCP gets a real lease from a real pool — an address the pool hands out, not the one it used to have — pings successfully, and prints `ip address dhcp` in its backup. `docs/CLI.md`: the interface and VLAN sections now state the one-method rule, that the backup prints the method rather than a leased address, and that a VLAN parameter is not a mode change. Suite: 158 suites, 6,629 assertions, 0 failed.
A VLAN parameter is not a mode change, and a port has one method (#1285)
Some checks failed
CI / Classify the change (pull_request) Successful in 13s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 16s
CI / Test (Node 20) (pull_request) Successful in 2m16s
CI / Test (Node 18) (pull_request) Failing after 2m19s
CI / Server smoke test (pull_request) Successful in 38s
CI / Docker build (pull_request) Successful in 43s
CI / Test (Node 22) (pull_request) Successful in 2m4s
d8ac2ea746
Two commands were changing something the operator did not ask about.

1. switchport trunk native vlan, switchport trunk allowed vlan and switchport access vlan each set the port's
   `mode` as a side effect, so staging a trunk on an access port - which is what the command is for, and what
   real gear accepts, so the trunk can be built before the cable is patched - silently turned the port into a
   trunk: a different command, in a different column of the table, changed what the port forwards. Measured on
   a plain access port: vlan.mode was `access` before the command and `trunk` after, and frames for VLAN 20
   started leaving a port that carries VLAN 1. In the other direction, `switchport access vlan 30` on a trunk
   turned the trunk into an access port.

   Worse, the parameter was then lost: the printer emitted trunk parameters only in trunk mode, so
   `show running-config` printed `interface Fa0/1` and nothing else, and a restore brought the port back
   without the value it had been staged with.

   Now the parameters are stored and the mode is left alone; only `switchport mode` changes the mode. When the
   value cannot be used yet the console says so and names the command that would use it:

     Trunk native VLAN 20 on Fa0/1 (stored; the port is in access mode - set "switchport mode trunk" to use it)

   and says nothing when the value is already in use. The mode and the VLAN parameters are printed
   independently, so a staged trunk survives a backup in either mode, byte-identically.

2. `ip address dhcp` set the DHCP flag and left the static address on the interface, so one port held two
   methods at once: it kept an address it did not own (`routeTo()` would route for it), `show ip interface
   brief` reported Method DHCP beside that address, and `show running-config` printed only the static line, so
   restoring the backup lost the DHCP intent. The reverse direction already cleared the flag, but silently.

   Both directions now displace the other method and say which:

     Interface Gi0/0 set to DHCP (static address 10.0.0.1/24 removed)
     IP address set on Gi0/0: 10.0.0.1/24 (DHCP client removed)

   `no ip address` names what it removed ("IP address 10.0.0.9/24 removed", "DHCP client removed") or refuses
   when there is nothing to remove, instead of claiming to remove an address that was never there.

3. Found while testing (2): the printer preferred the address over the method, so a DHCP host that had leased
   10.0.0.100 printed `ip address 10.0.0.100 255.255.255.0`. Restored on another network that host claims a
   stale address and never asks for a new one. `show running-config` now prints `ip address dhcp`, because a
   backup describes what was configured, not what the last exchange produced.

test/switchport-mode.test.js: 32 checks - staging leaves the mode alone in both directions and says what it
stored and what would use it; a value used immediately gets no note; the data plane follows the mode, so a
staged trunk carries VLAN 1 and drops 20 until `switchport mode trunk`, then carries 20 and still drops what the
allowed list omits; `show vlan` lists the port under the VLAN it carries, not the one it is staged for; all
four settings print under an access port and the backup replays byte-for-byte into the same mode and the same
parameters; the default trunk and access cases still print exactly what they printed before.

test/interface-method.test.js: 26 checks - a static address does not survive `ip address dhcp` and the
displaced address is named; a DHCP client does not survive a static address; `no ip address` distinguishes
nothing/static/dhcp; fifteen port histories leave exactly one method and never an address without a mask; and a
host moved from a static address to DHCP gets a real lease from a real pool (an address the pool hands out, not
the one it used to have), pings successfully, and prints `ip address dhcp` in its backup.

With engine/cli.js reverted: switchport-mode 17 failures, interface-method 13 failures.

docs/CLI.md: the interface and VLAN sections now state the one-method rule, that the backup prints the method
rather than a leased address, and that a VLAN parameter is not a mode change.

Suite: 158 suites, 6,629 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-09 22:27: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!1286
No description provided.