VirtioProxy: rely on wsldevicehost default MAC addresses and fix DNS tunneling assert (#40430)

* VirtioProxy: rely on wsldevicehost default MAC addresses and fix DNS tunneling assert Setting MAC addresses through the virtio-proxy guest connection options has proven problematic, so stop forwarding client_mac, gateway_mac, and gateway_mac_ipv6 from VirtioNetworking::RefreshGuestConnection() and let wsldevicehost fall back to its default values. Also extend the WI_ASSERT in WslCoreVm::IsDnsTunnelingSupported() to accept NetworkingMode::VirtioProxy. The VirtioProxy case was missed when the wslc feature branch was merged into main, causing the assert to fire in debug builds when DNS tunneling support is queried under that mode. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove dead NetworkSettings::GetBestGatewayMacAddress The previous commit dropped the only callers of GetBestGatewayMacAddress when virtio-proxy stopped pushing MAC addresses to wsldevicehost. Remove the now-unused declaration and definition. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * add unit test --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Ben Hillis committed May 6, 2026 at 20:31 UTC 6327f5abb186a109c97c26fe52a023638c604096
5 files changed +13 -48
src/windows/common/VirtioNetworking.cpp
-5
@@ -196,16 +196,11 @@ void VirtioNetworking::RefreshGuestConnection()
196 };
197
198 appendOption(L"client_ip", networkSettings->PreferredIpAddress.AddressString);
199 - appendOption(L"client_mac", networkSettings->MacAddress);
200 -
199 std::wstring default_route = networkSettings->GetBestGatewayAddressString();
200 appendOption(L"gateway_ip", default_route);
203 - appendOption(L"gateway_mac", networkSettings->GetBestGatewayMacAddress(AF_INET));
204 -
201 if (WI_IsFlagSet(m_flags, VirtioNetworkingFlags::Ipv6))
202 {
203 appendOption(L"client_ip_ipv6", networkSettings->PreferredIpv6Address.AddressString);
208 - appendOption(L"gateway_mac_ipv6", networkSettings->GetBestGatewayMacAddress(AF_INET6));
204 }
205
206 networking::DnsInfo currentDns{};
src/windows/common/WslCoreNetworkEndpointSettings.cpp
-40
@@ -136,43 +136,3 @@ std::shared_ptr<wsl::core::networking::NetworkSettings> wsl::core::networking::G
136 bestInterface->IfIndex,
137 bestInterface->IfType);
138 }
139 -
140 -std::wstring wsl::core::networking::NetworkSettings::GetBestGatewayMacAddress(ADDRESS_FAMILY addressFamily) const
141 -{
142 - auto gatewayAddress = GetBestGatewayAddress(addressFamily);
143 - if (gatewayAddress.si_family != addressFamily)
144 - {
145 - return {};
146 - }
147 -
148 - MIB_IPNET_ROW2 ipNetRow{};
149 - ipNetRow.Address = gatewayAddress;
150 - ipNetRow.InterfaceIndex = InterfaceIndex;
151 -
152 - const auto result = ResolveIpNetEntry2(&ipNetRow, nullptr);
153 - if (result != NO_ERROR)
154 - {
155 - LOG_HR_MSG(
156 - HRESULT_FROM_WIN32(result),
157 - "Failed to resolve gateway MAC address for: %ls, interface: %lu",
158 - windows::common::string::SockAddrInetToWstring(gatewayAddress).c_str(),
159 - InterfaceIndex);
160 -
161 - return {};
162 - }
163 -
164 - if (ipNetRow.PhysicalAddressLength != 6)
165 - {
166 - return {};
167 - }
168 -
169 - return wsl::shared::string::FormatMacAddress(
170 - wsl::shared::string::MacAddress{
171 - ipNetRow.PhysicalAddress[0],
172 - ipNetRow.PhysicalAddress[1],
173 - ipNetRow.PhysicalAddress[2],
174 - ipNetRow.PhysicalAddress[3],
175 - ipNetRow.PhysicalAddress[4],
176 - ipNetRow.PhysicalAddress[5]},
177 - L'-');
178 -}
src/windows/common/WslCoreNetworkEndpointSettings.h
-2
@@ -361,8 +361,6 @@ struct NetworkSettings
361 return {};
362 }
363
364 - std::wstring GetBestGatewayMacAddress(ADDRESS_FAMILY addressFamily) const;
365 -
364 std::wstring IpAddressesString() const
365 {
366 return std::accumulate(std::begin(IpAddresses), std::end(IpAddresses), std::wstring{}, [](const std::wstring& prev, const auto& addr) {
src/windows/service/exe/WslCoreVm.cpp
+3 -1
@@ -1904,7 +1904,9 @@ bool WslCoreVm::InitializeDrvFsLockHeld(_In_ HANDLE UserToken)
1904
1905 bool WslCoreVm::IsDnsTunnelingSupported() const
1906 {
1907 - WI_ASSERT(m_vmConfig.NetworkingMode == NetworkingMode::Nat || m_vmConfig.NetworkingMode == NetworkingMode::Mirrored);
1907 + WI_ASSERT(
1908 + m_vmConfig.NetworkingMode == NetworkingMode::Nat || m_vmConfig.NetworkingMode == NetworkingMode::Mirrored ||
1909 + m_vmConfig.NetworkingMode == NetworkingMode::VirtioProxy);
1910
1911 return SUCCEEDED_LOG(wsl::core::networking::DnsResolver::LoadDnsResolverMethods());
1912 }
test/windows/NetworkTests.cpp
+10
@@ -4815,6 +4815,16 @@ class VirtioProxyTests
4815 }
4816 }
4817
4818 + WSL2_TEST_METHOD(ValidateMacAddress)
4819 + {
4820 + VIRTIOPROXY_TEST_ONLY();
4821 +
4822 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4823 +
4824 + // eth0 should have wsldevicehost's default client MAC. Update if that default changes.
4825 + VERIFY_ARE_EQUAL(GetMacAddress(L"eth0"), std::wstring(L"00:00:00:00:01:00"));
4826 + }
4827 +
4828 WSL2_TEST_METHOD(GuestPortIsReleased)
4829 {
4830 VIRTIOPROXY_TEST_ONLY();