Remove DnsTunnelingSocket flag from VirtioNetworking#40443
Conversation
Drops the DnsTunnelingSocket virtio networking flag (and the dedicated DNS hvsocket plumbing it carried) in favor of the in-built DnsTunneling path. In virtio proxy mode, DNS queries are now always forwarded by the host virtio proxy itself: Linux's /etc/resolv.conf points at the eth0 gateway IP rather than the listener IP, no DNS hvsocket is opened, and the Linux init does not start a DnsTunnelingManager. Changes: - VirtioNetworking: remove DnsTunnelingSocket enum value, dnsHvsocket constructor parameter, m_dnsTunnelingResolver field, and the DnsResolver.h include. RefreshGuestConnection now uses only the in-built DnsTunneling path. - WslCoreVm: virtio proxy branch unconditionally sets the DnsTunneling flag when DNS tunneling is enabled. message->EnableDnsTunneling is suppressed for virtio proxy mode so Linux init won't open the DNS hvsocket. The pre-accepted dnsTunnelingSocket is dropped on the NAT->VirtioProxy fallback path. - HcsVirtualMachine: WSLC virtio proxy branch likewise switches to the DnsTunneling flag and discards the unused dnsSocketHandle. - Tests: add VirtioProxyTests::DnsTunnelingResolvConfUsesGateway which asserts resolv.conf contains the gateway IP and not the legacy listener IP, confirming the in-built path is in use. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR removes the legacy DnsTunnelingSocket virtio networking flag and its dedicated DNS hvsocket plumbing, standardizing virtio proxy DNS forwarding on the built-in DNS tunneling path (Linux /etc/resolv.conf points at the gateway IP, and Linux init no longer opens/uses a DNS hvsocket in virtio proxy mode).
Changes:
- Simplifies
VirtioNetworkingby dropping theDnsTunnelingSocketflag, the DNS hvsocket constructor parameter, and the resolver member; DNS config refresh now uses only the built-in DNS tunneling path. - Updates WSL/WSLC VM setup to suppress the DNS hvsocket for virtio proxy while still enabling the
DnsTunnelingvirtio flag when requested. - Adds/updates tests to validate that virtio proxy + DNS tunneling configures
/etc/resolv.confto use the eth0 gateway IP (not the legacy listener IP).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Updates WSLC networking validation to assert virtio proxy uses gateway nameserver when DNS tunneling is enabled. |
| test/windows/NetworkTests.cpp | Adds a virtio proxy test ensuring /etc/resolv.conf uses the gateway IP and not the legacy DNS listener IP. |
| src/windows/wslcsession/WSLCVirtualMachine.cpp | Stops allocating/passing the DNS channel to Linux init for WSLC virtio proxy mode. |
| src/windows/WslcSDK/wslcsdk.cpp | Enables the WSLC DNS tunneling feature flag for SDK-created sessions. |
| src/windows/service/exe/WslCoreVm.cpp | Switches virtio proxy to the DnsTunneling virtio flag and suppresses EnableDnsTunneling for virtio proxy init (no DNS hvsocket). |
| src/windows/service/exe/HcsVirtualMachine.cpp | Updates WSLC networking configuration to only expect a DNS hvsocket for NAT and switches virtio proxy to DnsTunneling. |
| src/windows/common/VirtioNetworking.h | Removes DnsTunnelingSocket from flags and drops DNS hvsocket plumbing from the public constructor. |
| src/windows/common/VirtioNetworking.cpp | Removes DNS hvsocket initialization/validation and legacy DNS-tunneling-socket refresh path. |
Reorder ConfigureNetworking so the caller-provided DnsSocket is validated against the requested feature flag before the LoadDnsResolverMethods call may clear it. Avoids E_INVALIDARG in NAT mode when the support check fails. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wrap the constructor declaration/definition parameter list per the repo's BinPackParameters: false / 130-column style. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d1ad373 to
55b9a5c
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| wil::unique_socket dnsSocketHandle; | ||
|
|
||
| // The DNS hvsocket is only allocated for NAT mode. | ||
| THROW_HR_IF(E_INVALIDARG, (FeatureEnabled(WslcFeatureFlagsDnsTunneling) && m_networkingMode == WSLCNetworkingModeNAT) != (DnsSocket != nullptr)); |
There was a problem hiding this comment.
nit: definitely room for cleanup and if/else consolidation for FeatureEnabled(WslcFeatureFlagsDnsTunneling), NAT mode, DnsSocket != nullptr conditions below
There was a problem hiding this comment.
I thought this was pretty clean, what were you thinking? I can address this in a follow-up.
| const auto state = NetworkTests::GetInterfaceState(L"eth0"); | ||
| VERIFY_IS_TRUE(state.Gateway.has_value()); | ||
|
|
||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"cat /etc/resolv.conf | grep nameserver | grep -F " + state.Gateway.value()), static_cast<DWORD>(0)); |
There was a problem hiding this comment.
nit: doesn't matter with the generated resolv.conf, but I do like the tightened awk version in WSLCTests. 'grep -F' here would do substring matches so maybe grep -w is better. Also like the ^nameserver in the WSLCTests better than the 'grep nameserver' below that could match comments etc.
There was a problem hiding this comment.
Fair, can adjust tests in a follow-up.
Drops the
DnsTunnelingSocketvirtio networking flag (and the dedicated DNS hvsocket plumbing it carried) in favor of the in-builtDnsTunnelingpath. In virtio proxy mode, DNS queries are now always forwarded by the host virtio proxy itself: Linux's/etc/resolv.confpoints at the eth0 gateway IP rather than the listener IP, no DNS hvsocket is opened, and the Linux init does not start aDnsTunnelingManager.Changes:
VirtioNetworking: removeDnsTunnelingSocketenum value,dnsHvsocketconstructor parameter,m_dnsTunnelingResolverfield, and theDnsResolver.hinclude.RefreshGuestConnectionnow uses only the in-builtDnsTunnelingpath.WslCoreVm: virtio proxy branch unconditionally sets theDnsTunnelingflag when DNS tunneling is enabled.message->EnableDnsTunnelingis suppressed for virtio proxy mode so Linux init won't open the DNS hvsocket. The pre-accepteddnsTunnelingSocketis dropped on the NAT->VirtioProxy fallback path.HcsVirtualMachine: WSLC virtio proxy branch likewise switches to theDnsTunnelingflag and discards the unuseddnsSocketHandle.VirtioProxyTests::DnsTunnelingResolvConfUsesGatewaywhich assertsresolv.confcontains the gateway IP and not the legacy listener IP, confirming the in-built path is in use.