Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/windows/common/VirtioNetworking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,11 @@ void VirtioNetworking::RefreshGuestConnection()
};

appendOption(L"client_ip", networkSettings->PreferredIpAddress.AddressString);
appendOption(L"client_mac", networkSettings->MacAddress);

std::wstring default_route = networkSettings->GetBestGatewayAddressString();
appendOption(L"gateway_ip", default_route);
appendOption(L"gateway_mac", networkSettings->GetBestGatewayMacAddress(AF_INET));

if (WI_IsFlagSet(m_flags, VirtioNetworkingFlags::Ipv6))
{
appendOption(L"client_ip_ipv6", networkSettings->PreferredIpv6Address.AddressString);
appendOption(L"gateway_mac_ipv6", networkSettings->GetBestGatewayMacAddress(AF_INET6));
}
Comment thread
benhillis marked this conversation as resolved.

networking::DnsInfo currentDns{};
Expand Down
40 changes: 0 additions & 40 deletions src/windows/common/WslCoreNetworkEndpointSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,43 +136,3 @@ std::shared_ptr<wsl::core::networking::NetworkSettings> wsl::core::networking::G
bestInterface->IfIndex,
bestInterface->IfType);
}

std::wstring wsl::core::networking::NetworkSettings::GetBestGatewayMacAddress(ADDRESS_FAMILY addressFamily) const
{
auto gatewayAddress = GetBestGatewayAddress(addressFamily);
if (gatewayAddress.si_family != addressFamily)
{
return {};
}

MIB_IPNET_ROW2 ipNetRow{};
ipNetRow.Address = gatewayAddress;
ipNetRow.InterfaceIndex = InterfaceIndex;

const auto result = ResolveIpNetEntry2(&ipNetRow, nullptr);
if (result != NO_ERROR)
{
LOG_HR_MSG(
HRESULT_FROM_WIN32(result),
"Failed to resolve gateway MAC address for: %ls, interface: %lu",
windows::common::string::SockAddrInetToWstring(gatewayAddress).c_str(),
InterfaceIndex);

return {};
}

if (ipNetRow.PhysicalAddressLength != 6)
{
return {};
}

return wsl::shared::string::FormatMacAddress(
wsl::shared::string::MacAddress{
ipNetRow.PhysicalAddress[0],
ipNetRow.PhysicalAddress[1],
ipNetRow.PhysicalAddress[2],
ipNetRow.PhysicalAddress[3],
ipNetRow.PhysicalAddress[4],
ipNetRow.PhysicalAddress[5]},
L'-');
}
2 changes: 0 additions & 2 deletions src/windows/common/WslCoreNetworkEndpointSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ struct NetworkSettings
return {};
}

std::wstring GetBestGatewayMacAddress(ADDRESS_FAMILY addressFamily) const;

std::wstring IpAddressesString() const
{
return std::accumulate(std::begin(IpAddresses), std::end(IpAddresses), std::wstring{}, [](const std::wstring& prev, const auto& addr) {
Expand Down
4 changes: 3 additions & 1 deletion src/windows/service/exe/WslCoreVm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,9 @@ bool WslCoreVm::InitializeDrvFsLockHeld(_In_ HANDLE UserToken)

bool WslCoreVm::IsDnsTunnelingSupported() const
{
WI_ASSERT(m_vmConfig.NetworkingMode == NetworkingMode::Nat || m_vmConfig.NetworkingMode == NetworkingMode::Mirrored);
WI_ASSERT(
m_vmConfig.NetworkingMode == NetworkingMode::Nat || m_vmConfig.NetworkingMode == NetworkingMode::Mirrored ||
m_vmConfig.NetworkingMode == NetworkingMode::VirtioProxy);

Comment thread
benhillis marked this conversation as resolved.
return SUCCEEDED_LOG(wsl::core::networking::DnsResolver::LoadDnsResolverMethods());
}
Expand Down
10 changes: 10 additions & 0 deletions test/windows/NetworkTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4815,6 +4815,16 @@ class VirtioProxyTests
}
}

WSL2_TEST_METHOD(ValidateMacAddress)
{
VIRTIOPROXY_TEST_ONLY();

m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));

// eth0 should have wsldevicehost's default client MAC. Update if that default changes.
VERIFY_ARE_EQUAL(GetMacAddress(L"eth0"), std::wstring(L"00:00:00:00:01:00"));
}

WSL2_TEST_METHOD(GuestPortIsReleased)
{
VIRTIOPROXY_TEST_ONLY();
Expand Down