fix(usb): stable gadget MAC so the host NIC keeps one MAC across reboots#828
Open
BeaconCat wants to merge 1 commit into
Open
fix(usb): stable gadget MAC so the host NIC keeps one MAC across reboots#828BeaconCat wants to merge 1 commit into
BeaconCat wants to merge 1 commit into
Conversation
The USB network gadget (rndis.usb0 / ncm.usb0) is created without dev_addr or host_addr, so the kernel picks a random MAC for both the device side and the host side on every bind. S10uuid later pins the device-side usb0 via 'ip link set', but the host_addr -- the MAC the attached PC's RNDIS/NCM adapter uses -- stays random and changes on every re-enumeration/reboot. The host then registers a brand-new network adapter each time, piling up stale adapters/MACs (e.g. ~10 after a few reboots) and breaking anything that keys off the MAC. Derive both MACs from the chip UID (same scheme S10uuid already uses for eth0 and usb0), before binding the gadget: dev_addr = 48:da:35:6e:<uid> host_addr = 48:da:35:6d:<uid> Verified on a NanoKVM Cube: host_addr went from random a6:3f:5d:8a:7d:52 to a stable 48:da:35:6d:26:62, identical across two reboots. Fixes sipeed#740
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Plugging one NanoKVM (Cube) into a PC over USB ends up creating many network adapters / MAC addresses on the host — ~10 after a few reboots.
Root cause: the USB network gadget
rndis.usb0/ncm.usb0is created inS03usbdevwithout settingdev_addrorhost_addr, so the kernel assigns a random MAC to both the device side and the host side on every bind.S10uuidlater pins the device-sideusb0withip link set, but thehost_addr— the MAC the attached PC's RNDIS/NCM adapter uses — stays random and changes on every re-enumeration/reboot. Windows then registers a brand-new adapter each time, piling up stale adapters/MACs and breaking anything that keys off the MAC (DHCP reservations, WoL, firewall rules…).Fix
Derive both MACs deterministically from the chip UID (the same
sha512sum /sys/class/cvi-base/base_uidschemeS10uuidalready uses foreth0/usb0), set before binding the gadget:Guarded on a non-empty UID; falls back to the old random behaviour if
base_uidis unavailable. Applies to both thencmandrndispaths.Verified on hardware (NanoKVM Cube)
a6:3f:5d:8a:7d:52(random, changes every boot)48:da:35:6d:26:6248:da:35:6d:26:62(stable)Fixes #740