Repository navigation
feat(start-wrt): use USB Ethernet adapters as LAN ports - #4662
Conversation
A physical USB port becomes a LAN bridge port the first time an Ethernet-type USB network device is plugged into it. The daemon follows ip monitor link, records the port in startwrt (usb_port, keyed by the controller and the port chain on its USB 2 side, so USB 2 and USB 3 adapters in one port match), and joins the device to the port's br-usb_eth<N> bridge. A usb_eth<N> veth links that bridge to br-lan and carries the port's profile, so the mapping and profile persist while the port is empty, and plugging in needs no network reload. A hub's ports are physical ports of their own: the kernel cannot tell an onboard hub from a plugged-in one, so no port is treated as shared. A new port takes the lowest unused number. netifd takes a veth's peer for its parent and resets the peer (out of its bridge, IPv6 back on) whenever it claims the veth: at boot, on a network restart, and on reloads that touch the port. The watcher re-attaches the peer and disables its IPv6 on every peer event. The LAN guard drops DHCP replies and router advertisements forwarded between the ports of every bridge, including the router's own replies crossing a USB port's bridge from its veth. Frames entering from a usb_eth* link are the router's own or were checked on the bridge they left, so the guard accepts them. An r8152 adapter keeps link with its interface down, so a profile change de-authorizes and re-authorizes the adapter's USB device to make its clients lose link; Ethernet ports are still taken down and up. ethernet.get reports whether each USB port holds an adapter and has link; ethernet.set keeps a recorded USB port that a stale request omits and refuses one as WAN. ethernet.remove-usb-port forgets an empty port and reloads the network, since netifd would otherwise give a later port of the same name the removed port's VLAN. config.check reads usb_port sections for the Ethernet page. The image gains the Realtek, ASIX, CDC and RNDIS USB network drivers. kmod-usb-net-rtl8152 depends on kmod-crypto-sha256, whose module kernel 6.18 renamed from sha256_generic to sha256; openwrt-patches/0010 follows the rename.
Helix-Harness: pi Helix-Model: openai-codex/gpt-6.1-sol
helix-white
left a comment
There was a problem hiding this comment.
Requesting changes on 59d2b43 for two correctness issues.
[P1] Keep USB adapter ingress subject to the LAN guard — backend/nftables/ruleset-pre/10-startwrt-lan-dhcp-guard.nft:18 (paths relative to projects/start-wrt). The wildcard exemption trusts both ends of each veth. A client behind a USB adapter can send a DHCP reply or RA tagged with its assigned profile's VID. br-usb_eth<N> has VLAN filtering disabled, so that frame retains its tag there and does not match the guard's ether type ip/ip6 conditions. On br-lan, VLAN filtering removes the tag for an untagged destination, but iifname "usb_eth*" accept now exempts the packet before the guard can inspect it. This bypasses the DHCP-server and RA restrictions for other clients in the profile. Linux 6.18 reconstructs the VLAN header for the EtherType match and applies egress VLAN handling before the forward hook. The proposal scopes the exemption to ingress on br-usb_eth*, preserving router replies arriving through the peer while re-checking adapter traffic on br-lan. It records that boundary beside the rule. The reported untagged rogue-DHCP check does not cover this tagged path; adopted changes need packet-path regression coverage for tagged replies/advertisements and legitimate router traffic.
[P2] Finish the removal reload before the local CLI exits — backend/ctrl/src/ethernet.rs:162. remove-usb-port is registered as a local handler, without with_call_remote::<CliContext>(). Its spawned reload can therefore be cancelled when CliApp::run returns and drops the CLI context's runtime. The port has already been deleted from disk and the kernel, but netifd can retain the old VLAN for that name—the exact condition the reload is intended to prevent when the name is reused. The proposal awaits the reload, retaining configs-only behavior; the web caller already uses the restart/reconnect action flow.
Proposed changes: 59d2b43...proposal/4662
git merge-tree --write-tree origin/master <reviewed-head> was clean. Reviewed the USB lifecycle, VLAN/profile handling, guard, RPC/bindings, and Ethernet UI paths. No builds, tests, or VM runs were performed; the proposal is unverified and belongs to the author to verify. Available CI has no reported failure, but binary build, automated tests, formatting/lockfiles, and generated artifacts remain pending; the OpenWrt image job is skipped.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
…s dropped The daemon drops a handler's future when its client disconnects, which a bare await would let stop the reload between the network and Wi-Fi steps. Awaiting a spawned task keeps the CLI process alive until the reload ends and lets the daemon finish it regardless of the caller.
|
Both adopted in 59d2b43..99fe1ee.
|
helix-white
left a comment
There was a problem hiding this comment.
Approved on f3d6997. Both findings are resolved. Spawning and awaiting the removal reload is better than my bare-await proposal: the CLI waits for completion, while dropping an HTTP request detaches rather than cancels the reload. The narrowed guard retains checks for USB adapter traffic entering the LAN bridge. Merge-tree against current master is clean.
Brief
USB Ethernet adapters add persistent, individually profiled LAN ports on the Ethernet page. The profile belongs to the physical USB socket, including each hub socket, rather than the adapter. Empty sockets remain listed as “Not connected”; removal requires unplugging the adapter and confirms the network disruption. Removing a socket forgets its profile, and reconnecting creates a fresh Admin port. USB ports cannot become WAN ports.
Policy to note: a previously unseen socket starts in Admin, granting its attached client Admin-profile network access. Moving a hub changes its downstream socket identities; the resulting new ports also start in Admin.
Implementation diff: +1100 / −105 lines in 21 files (excludes lockfiles, tests, docs, release notes, and changelog). Localized contextual-help text counts as documentation; generated binding implementation is included.
Approach and ownership. Stable virtual Ethernet ports reuse the existing bridge-VLAN profile assignments rather than making adapter interface names the persistent identity. The daemon owns discovery and adapter attachment to a per-socket bridge. Its link-event watcher also repairs the peer attachment that OpenWrt's network manager resets. Shared VLAN lookup and network/firewall/Wi-Fi reload sequencing replace duplicated logic. Profile changes reset USB authorization because bringing an RTL8153 interface down does not drop its cable link. The image adds six adapter-driver packages and a kernel-6.18-specific SHA256 module-name correction needed by the Realtek driver.
Data model and compatibility. New UciUsbPort sections store the physical socket's path, keyed by its virtual port name; existing configurations need no migration. EthernetInfo retains the existing flattened Ethernet response and adds the required usb_ports map, whose UsbPortStatus values report adapter presence and cable-link activity. RemoveUsbPortRequest supplies a port to the new removal endpoint, which returns null. The existing set-request shape stays unchanged, but omitted recorded USB ports retain their profiles and USB WAN assignments are rejected. Rust contracts, generated bindings, and live/mock UI clients ship together.
Verification evidence. The author reports 911 + 37 Rust tests passing, plus web/i18n, bindings and formatting checks. Rust tests and formatting were rerun on 99fe1ee; the final merge adds only SDK documentation. Recorded K1/RTL8153 bench evidence covers discovery, separate sockets and hubs, profile changes, persistence across reboot, removal/name reuse, and signed UI calls. The review regression run reproduced tagged and priority-tagged DHCP/DHCPv6/RA leakage before the guard fix and blocked it afterward, while preserving control traffic, router DHCP replies and router advertisements. CLI removal now completes the whole reload sequence before returning.
I ran no tests or router operations. For the required screenshots only, I built the final-head mock UI and captured its Ethernet list and both removal dialogs; images follow in a screenshot-only comment. That build succeeded with bundle-size and CommonJS warnings.
Remaining evidence limits. Current binary-build, automated-test, formatting/lockfile and generated-artifact CI jobs are pending. The image job is skipped: the SHA256 packaging patch has not had a clean-workspace image build. Non-Realtek and USB 2 adapters, link loss on other chipsets, and a deliberately interrupted removal request remain unverified; the guard regression used Admin's VLAN. The author also records an unreproduced attachment miss during driverless-adapter experimentation.
The independent managed-switch PR, #4628, overlaps the Ethernet/VLAN implementation and UI; this approval covers this head against master, not a combined USB/trunk implementation.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
…dapter Packet steering ran at boot and on network reloads, so an adapter plugged in afterwards kept its packet work on one core until the next reload.
…link The kernel registers the adapter's network device before it creates the USB device's port link, so an adapter could be seen with no port and left unused. The hub's port node exists beforehand.
helix-white
left a comment
There was a problem hiding this comment.
Approved on bd1a927. I re-reviewed everything since my last approval (f3d6997): two usb_ports.rs fixes and a master merge that adds only a StartOS docs edit. A test merge against current master (00be0f5) is clean.
- Port identity without the
portlink (c1577bd).port_nodenow builds the hub's port path from the device name:<bus>-0:1.0/usb<bus>-port<n>under a root hub,<hub>:1.0/<hub>-port<n>under an external hub. That node already exists when the adapter's network device appears, so identity no longer depends on the device'sportsymlink, which the kernel creates later. The SuperSpeedpeerlookup reads the same node, so USB 2 and USB 3 sides still map to one socket. The test fixture stops creating theportsymlink, so the existing socket and hub tests now cover the path derivation instead of the link. - Packet steering on hot-plug (239b0fb). The
packet_steeringreload runs only after an adapter is newly attached to its port bridge; already-attached adapters return earlier, so repeated link events don't re-trigger it. A failure is logged and doesn't block attachment.
Brief
USB Ethernet adapters add persistent, individually profiled LAN ports on the Ethernet page. The profile belongs to the physical USB socket, including each hub socket, rather than the adapter. Empty sockets stay listed as "Not connected". Removal requires unplugging the adapter and confirms the network disruption. Removing a socket forgets its profile, and reconnecting creates a fresh Admin port. USB ports cannot become WAN ports.
Policy to note: a previously unseen socket starts in Admin, which gives its client Admin-profile network access. Moving a hub changes its downstream socket identities, so those new ports also start in Admin.
Approach and ownership. Stable virtual Ethernet ports reuse the existing bridge-VLAN profile assignments; adapter interface names are not the persistent identity. The daemon handles discovery and attaches each adapter to a per-socket bridge. Its link-event watcher repairs the peer attachment that OpenWrt's netifd resets, and reruns packet steering when a hot-plugged adapter is attached. Socket identity comes from the hub port node, which exists before the adapter's network device appears. The shared VLAN lookup and network/firewall/Wi-Fi reload sequence replace duplicated logic. Profile changes reset USB authorization, because bringing an RTL8153 interface down doesn't drop its cable link. The image adds six adapter-driver packages and a kernel-6.18 SHA256 module-name correction that the Realtek driver needs.
Data model and compatibility. New UciUsbPort sections store the physical socket's path, keyed by virtual port name. Existing configurations need no migration. EthernetInfo keeps the flattened Ethernet response and adds a required usb_ports map; each UsbPortStatus reports adapter presence and cable link. RemoveUsbPortRequest names a port for the new removal endpoint, which returns null. The set-request shape is unchanged, but recorded USB ports left out of a set request keep their profiles, and USB WAN assignments are rejected. Rust contracts, generated bindings and the live and mock UI clients ship together.
Verification evidence. The author reports make start-wrt-test (911 + 37 passed) on c1577bd; the final head is that commit with master merged, no conflicts. Earlier rounds also covered web/i18n, bindings and formatting checks. Recorded K1/RTL8153 bench evidence covers:
- discovery, separate sockets and hubs, profile changes, persistence across reboot, removal and name reuse, and signed UI calls;
- the DHCP/DHCPv6/RA guard regression from review round 1;
- CLI removal completing the full reload before returning;
- a second adapter that stayed unused on f3d6997 (no physical port found) and now joins its port: 6 of 6 hub-port reconnects plus 16
authorizedcycles with no warning, where theportlink was missing in 4 of 6 before the fix; - hot-plugged single-stream TCP rising from 761–764 / 491–496 Mbps to 941 / 795–799 Mbps up/down, matching an adapter plugged in at boot.
I ran no tests or router operations. The earlier mock-UI screenshots still show the final UI, since these commits change only daemon code.
Remaining evidence limits. On this head the riscv64 binary build, Changelog and Prettier CI jobs are pending. The image job is skipped, so the SHA256 packaging patch hasn't had a clean-workspace image build. Untested: non-Realtek and USB 2 adapters, link loss on other chipsets, a deliberately interrupted removal request, and a hub whose port interface isn't :1.0 (standard for hubs). The author also records a deadline has elapsed error at each daemon restart that wasn't compared against master.
The independent managed-switch PR, #4628, overlaps the Ethernet/VLAN implementation and UI. This approval covers this head against master, not a combined USB/trunk implementation.
Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
|
@Dominion5254 #4662 now conflicts with master ( To resolve: merge I'm this PR's cross-reviewer, so I haven't pushed to your branch. My approval was for |
…d in The trash icon on a USB port row was always clickable and answered a click on an in-use port with an "Adapter plugged in" dialog. It is now disabled while an adapter is in the port, with a hint saying to unplug it, so an enabled icon means the port can actually be removed. The dialog and the fresh ethernet.get behind it are gone; a click in the few seconds before the page's next poll is refused by the backend as before and shows its error toast.
# Conflicts: # projects/start-wrt/web/src/app/i18n/dictionaries/de.ts # projects/start-wrt/web/src/app/i18n/dictionaries/en.ts # projects/start-wrt/web/src/app/i18n/dictionaries/es.ts # projects/start-wrt/web/src/app/i18n/dictionaries/fr.ts # projects/start-wrt/web/src/app/i18n/dictionaries/pl.ts
helix-white
left a comment
There was a problem hiding this comment.
Approved on 93d792c. Since my last approval (bd1a927) there is one implementation commit and a master merge. A test merge against current master (246876d31) is clean.
- Disabled removal button (e99516f). The trash button is disabled while
usb_ports[port].presentis true, and its hint says to unplug the adapter. This matches the disabled-button-with-hint pattern used elsewhere in the StartWRT UI (profiles, outbound VPNs). The pre-clickethernet.get, the "Adapter plugged in" dialog and their strings are gone. The backend still refuses removal of an occupied port, so a click made before the next poll gets an error toast. No leftover imports or strings remain;TUI_CONFIRM,fillanddialogsare still used by the confirm and WAN-move dialogs. The docs page was updated to match. - Merge resolution (93d792c). Master's string keeps ID 633. This PR's five remaining strings are 634–638, consistently across
en,de,es,frandpl, with no gaps or duplicates.
Brief
USB Ethernet adapters add persistent, individually profiled LAN ports on the Ethernet page. The profile belongs to the physical USB socket, including each hub socket, rather than to the adapter. Empty sockets stay listed as "Not connected". The removal button is disabled while an adapter is plugged in, and removing an empty socket asks for confirmation of a brief network restart. Removing a socket forgets its profile, and reconnecting creates a fresh Admin port. USB ports cannot become WAN ports.
Policy to note: a previously unseen socket starts in Admin, which gives its client Admin-profile network access. Moving a hub changes its downstream socket identities, so those new ports also start in Admin.
Approach and ownership. Stable virtual Ethernet ports reuse the existing bridge-VLAN profile assignments; adapter interface names are not the persistent identity. The daemon handles discovery and attaches each adapter to a per-socket bridge. Its link-event watcher repairs the peer attachment that OpenWrt's netifd resets, and reruns packet steering when a hot-plugged adapter is attached. Socket identity comes from the hub port node, which exists before the adapter's network device appears. The shared VLAN lookup and network/firewall/Wi-Fi reload sequence replace duplicated logic. Profile changes reset USB authorization, because bringing an RTL8153 interface down doesn't drop its cable link. The image adds six adapter-driver packages and a kernel-6.18 SHA256 module-name correction that the Realtek driver needs.
Data model and compatibility. New UciUsbPort sections store the physical socket's path, keyed by virtual port name. Existing configurations need no migration. EthernetInfo keeps the flattened Ethernet response and adds a required usb_ports map; each UsbPortStatus reports adapter presence and cable link. RemoveUsbPortRequest names a port for the new removal endpoint, which returns null and refuses a port with an adapter present. The set-request shape is unchanged, but recorded USB ports left out of a set request keep their profiles, and USB WAN assignments are rejected. Rust contracts, generated bindings and the live and mock UI clients ship together.
Verification evidence. The author reports make start-wrt-test (911 + 37 passed) on c1577bd. On 93d792c (the final head), npm run check:wrt and npm run check:i18n:wrt (599 keys) passed. Recorded K1/RTL8153 bench evidence covers:
- discovery, separate sockets and hubs, profile changes, persistence across reboot, removal and name reuse, and signed UI calls;
- the DHCP/DHCPv6/RA guard regression from review round 1, and CLI removal completing the full reload before returning;
- adapters joining their port on every reconnect after the port-identity fix, and hot-plugged throughput matching boot-time after the packet-steering fix;
- in headless Chromium against the real UI on e99516f: occupied ports showed a disabled button with the hint, empty ports an enabled one. Disabled clicks sent no request, and the button followed unplug/replug within about 7 s. A removal confirmed after reconnecting behind the open dialog was refused with a toast naming the port.
I ran no tests or router operations. For the screenshots only, I built the final-head demo UI (npm run build:wrt:demo) and captured the Ethernet list, the disabled button's hint, and the removal confirmation. They follow in a screenshot-only comment and replace my earlier set, which showed the removed "Adapter plugged in" dialog.
Remaining evidence limits. On a phone a disabled button shows no hint, since it receives no tap; it is still greyed out. The image job is skipped, so the SHA256 packaging patch hasn't had a clean-workspace image build. Untested: non-Realtek and USB 2 adapters, link loss on other chipsets, a deliberately interrupted removal request, and a hub whose port interface isn't :1.0 (standard for hubs). The author also records a deadline has elapsed error at each daemon restart that wasn't compared against master. CI on this head was not complete when I reviewed.
The independent managed-switch PR, #4628, overlaps the Ethernet/VLAN implementation and UI. This approval covers this head against master, not a combined USB/trunk implementation.
Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
|
Final-head (93d792c) mock UI screenshots (sample data, not a live router). These replace my earlier set. |



A USB Ethernet adapter in one of the router's USB-A ports becomes a LAN port with its own Security Profile.
What it does
startwrt(config usb_port, keyed by controller and port chain on the socket's USB 2 side) and adds ausb_eth<N>port to the LAN bridge in the Admin profile. The profile belongs to the socket, not the adapter, and persists while the socket is empty. Each socket of a hub is a port of its own: the kernel reportsremovableandconnect_typeas unknown, so an onboard hub cannot be told from a plugged-in one, and no socket is treated as shared.usb_eth<N>is a veth onbr-lancarrying the port's VLAN; its peer joinsbr-usb_eth<N>, which the adapter joins. Plugging in needs no network reload. The watcher followsip monitor linkand re-attaches the veth peer whenever netifd resets it (netifd treats a veth's peer as its parent).portlink: on a fresh enumeration the adapter's network device can register before that link exists, which left the adapter unused with no later event to retry on./etc/init.d/packet_steering reloadwhen an adapter joins its port. Steering otherwise runs at boot and on network reloads, so a hot-plugged adapter kept all its packet work on one core.10-startwrt-lan-dhcp-guard.nftaccepts frames entering a USB port's bridge from itsusb_eth<N>-uplink: they are the router's own or were checked onbr-lan. Without it the guard dropped the router's own DHCP replies and RAs crossing a USB port's bridge. Frames a USB port sends intobr-lanare checked there, which is where a VLAN-tagged frame from behind an adapter loses its tag.ethernet.remove-usb-port(trash button on the Ethernet page) forgets a port with no adapter plugged in. While an adapter is plugged in, the button is disabled and its hint says to unplug the adapter; the handler refuses as well, which covers a click before the page next polls. Removal reloads the network before it returns, because netifd would otherwise give a later port of the same name the removed port's VLAN; the reload runs as its own task, so it finishes when the caller disconnects. A new port takes the lowest unused number.ethernet.getaddsusb_ports(present,active);ethernet.setkeeps a recorded USB port a stale request omits and refuses one as WAN.config.checkreadsusb_portsections for the Ethernet page.kmod-usb-net-{rtl8152,asix,asix-ax88179,cdc-ether,cdc-ncm,rndis}.kmod-usb-net-rtl8152depends onkmod-crypto-sha256, whose module kernel 6.18 renamed;openwrt-patches/0010follows the rename (same shape as0003). Without it the image does not build.Docs, help text, changelog fragment and translations are included.
Verification
The disabled trash button (e99516f) was checked and benched on e99516f. 93d792c is that commit with master 246876d merged; the merge conflicted only in the five dictionaries, where master had taken string ID 633, so this PR's strings moved to 634–638, and
npm run check:i18n:wrt(599 keys) andnpm run check:wrtpassed on 93d792c.Earlier checks ran on 1ee09422b; 59d2b43 is that commit rebased onto master ed6bc4b without conflicts, with the commit message rewritten.
make start-wrt-testandmake start-wrt-format-checkran again on 99fe1ee (review round 1).make start-wrt-test: 911 + 37 passednpm run check:wrt,npm run check:i18n:wrt(599 keys),make start-wrt-rpc-bindings-check,make start-wrt-format-check,prettier --check: cleannode scripts/changelog.mjs check-version projects/start-wrt: passes on 59d2b43Live bench (K1, RTL8153 adapters, a real wired client behind each):
usbnetloaded at boot, r8152 firmware present, guard rule shipped, an adapter plugged in at boot recorded asusb_eth0witheth0/eth1unchanged, client leased in Admin, followed a move to Guest in about 17 s, profile and lease survived a reboot,bench.sh smokepassed.usb_eth1; moved into a hub it becameusb_eth2at its own port chain; movingusb_eth2to Guest moved its client whileusb_eth0stayed in Admin; removing the emptyusb_eth1left the others intact.ethernet.getandconfig.check(no findings) through the UI's signed login; headless Chromium on the real UI showed the rows and the remove confirm on an empty port; smoke passed.usb_ethrename of the rule).br-lanand a client on a second USB port's bridge counted what arrived. With the rule as first pushed (iifname "usb_eth*" accept) the untagged frames were dropped and all six tagged ones of each kind reached both clients. With the narrowed rule none arrived and the guard's drop counters rose, while a control datagram on other ports sent the same three ways arrived every time. Under the narrowed rulefw4loaded its ruleset, the client on the second USB port's bridge leased from the router and took an address from its router advertisement, and a real wired client behind an RTL8153 adapter re-leased after the adapter was bounced.startwrt-clion 59d2b43 returned within a second and the Wi-Fi restart that ends the reload never ran; on 99fe1ee it returned after about 3 s with the whole reload logged. Through the daemon the call returned after the reload. An adapter plugged in after its port was removed came up as a freshusb_eth0in Admin and its client leased.bench.sh smokepassed.make start-wrt-test911 + 37 passed on c1577bd.Single TCP stream, 15 s, between a gigabit client behind an RTL8153 adapter and a host on the WAN side, flow offloading unset on the bench:
threaded0,rps_cpus00)Download stays near 800 Mbps: one core runs at about 92% wherever the xHCI interrupt lands, and pinning that interrupt to other cores gave 751–814 Mbps.
A 986 Mbps UDP stream from the client on one adapter to a client on a second adapter left the second adapter at 984 Mbps. The same stream routed to the WAN forwarded 435 Mbps with flow offloading unset and 985 Mbps with it on (the shipped default).
Detection: a second adapter physically plugged in on f3d6997 logged
no physical portand stayed unused. Disconnecting and reconnecting an adapter at its hub port (disable1, then 0) showed the device'sportlink absent when its network device appeared in 4 of 6 cycles; on c1577bd the adapter joined its port in all 6, and in 16 furtherauthorizedcycles, with no warning logged. Theauthorizedbounce does not recreate the race, since the USB device persists.bench.sh smokepassed after a reboot. Before it, smoke reported onedeadline has elapsederror logged at each daemon restart; whether master logs it too was not checked.npm run check:wrtandnpm run check:i18n:wrtpassed): headless Chromium on the real UI. Ports with an adapter plugged in showed a disabled button and the hint on hover; empty ports showed an enabled button and no hint. Clicking a disabled button opened nothing and sent no request. Disconnecting an adapter at its hub port enabled its button without a reload, and reconnecting it disabled the button again within about 7 s. A removal confirmed after the adapter was reconnected behind the open dialog was refused, the error toast named the port, and the port stayed recorded. In phone emulation a tap on a disabled button shows no hint, since a disabled button receives no click; the button is still greyed out.bench.sh smokepassed.Not verified:
openwrt-patches/0010has had no clean-workspace build.deadline has elapsedon a daemon restart.