[hyperv] permanent_ipv4_neighbor picks stray zone-network ICS leases for Default Switch instances
Describe the bug
With the hyperv driver, the daemon can pick the wrong management IP for an instance and SSH times out.
Right now, HyperVVirtualMachine::management_ipv4() uses permanent_ipv4_neighbor(mac), which returns the first
permanent neighbour entry with the instance's MAC on any interface. The problem is that the hyperv_api zone
networks (Multipass vNetwork (zoneN)) also hand out DHCP leases to instances that are only on Default Switch, so
there are multiple permanent entries for the same MAC. Whichever comes first wins.
The zone networks and Default Switch share the same vSwitch (same SwitchGuid in hnsdiag). The zone networks
are only separated by VLAN isolation (1/2/3) and Default Switch has none. So the instance's DHCP broadcasts end up
at the zone networks' ICS DHCP servers too.
To Reproduce
- Make sure the zone networks exist on the host. They're created once the
hyperv_apibackend is initialised (e.g.multipass set local.driver=hyperv_api, or the Hyper-V -> HCS migration). multipass set local.driver=hypervmultipass launch --name brtest- Check the neighbour table for the instance MAC:
Get-NetNeighbor -AddressFamily IPv4 -LinkLayerAddress <mac> | Select-Object InterfaceAlias, IPAddress, State vEthernet (Multipass vNetwork (zone3)) 10.97.2.221 52-54-00-04-FF-51 Permanent vEthernet (Multipass vNetwork (zone3)) 10.97.2.23 52-54-00-04-FF-51 Permanent vEthernet (Multipass vNetwork (zone2)) 10.97.1.243 52-54-00-04-FF-51 Permanent vEthernet (Multipass vNetwork (zone2)) 10.97.1.92 52-54-00-04-FF-51 Permanent vEthernet (Default Switch) 172.22.89.161 52-54-00-04-FF-51 Permanent vEthernet (Multipass vNetwork (zone1)) 10.97.0.223 52-54-00-04-FF-51 Permanent vEthernet (Multipass vNetwork (zone1)) 10.97.0.134 52-54-00-04-FF-51 Permanent Only the Default Switch one is real. - multipass shell brtest times out when a zone entry gets picked.
Removing the stray entries doesn't help for long; they come back with the next DHCP exchange.
Expected behavior The management IP should only come from the network the management NIC is on (Default Switch for hyperv, the zone network for hyperv_api). Also, instances that aren't on a zone network shouldn't be getting leases from it.
Logs
[trace] [brtest] management_ipv4() > IP address is 10.97.0.117
[trace] [brtest] ssh connection failed: 'Timeout connecting to 10.97.0.117'
[trace] [brtest] Dispatching through exec (reason: foreign thread)
[debug] [powershell.exe] [9172] started: powershell.exe -NoProfile -NonInteractive -Command Get-VM -Name brtest |
Select-Object -ExpandProperty State
[trace] [brtest] [9172] Output:
Running
[trace] [brtest] management_ipv4() > IP address is 10.97.0.117
Additional info
- OS: Windows 11 Pro 10.0.26200 (KVM guest, nested virt)
- CPU architecture or model: x86_64
- multipass version:
- multipass info:
- multipass get local.driver: hyperv
Additional context This is on main too, since 08cdffa02 ("[hyperv] Use permanent_ipv4_neighbor for ipv4"). It only shows up once the zone networks exist, which is always the case after a Hyper-V -> HCS migration. That means the retained hyperv originals are affected when they're started to validate or delete them.
hyperv_api has the same weakness in its fallback path. HCSVirtualMachine::management_ipv4() falls back to permanent_ipv4_neighbor when the endpoint has no IPv4. A migrated copy keeps the original's MAC, so it can pick up the original's Default Switch entry.
Source: canonical/multipass