Skip to content

Remove DnsTunnelingSocket flag from VirtioNetworking#40443

Merged
benhillis merged 4 commits intomasterfrom
user/benhill/dns_tunneling
May 7, 2026
Merged

Remove DnsTunnelingSocket flag from VirtioNetworking#40443
benhillis merged 4 commits intomasterfrom
user/benhill/dns_tunneling

Conversation

@benhillis
Copy link
Copy Markdown
Member

@benhillis benhillis commented May 6, 2026

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.

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>
Copilot AI review requested due to automatic review settings May 6, 2026 19:38
@benhillis benhillis requested a review from a team as a code owner May 6, 2026 19:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 VirtioNetworking by dropping the DnsTunnelingSocket flag, 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 DnsTunneling virtio flag when requested.
  • Adds/updates tests to validate that virtio proxy + DNS tunneling configures /etc/resolv.conf to 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.

Comment thread src/windows/service/exe/HcsVirtualMachine.cpp Outdated
Comment thread src/windows/common/VirtioNetworking.h
Comment thread src/windows/common/VirtioNetworking.cpp
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/windows/common/VirtioNetworking.h
Comment thread src/windows/common/VirtioNetworking.cpp
Comment thread src/windows/service/exe/WslCoreVm.cpp
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>
Copilot AI review requested due to automatic review settings May 7, 2026 00:56
@benhillis benhillis force-pushed the user/benhill/dns_tunneling branch from d1ad373 to 55b9a5c Compare May 7, 2026 00:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/exe/HcsVirtualMachine.cpp
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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: definitely room for cleanup and if/else consolidation for FeatureEnabled(WslcFeatureFlagsDnsTunneling), NAT mode, DnsSocket != nullptr conditions below

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, can adjust tests in a follow-up.

@benhillis benhillis merged commit 5f71bf7 into master May 7, 2026
11 checks passed
@benhillis benhillis deleted the user/benhill/dns_tunneling branch May 7, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants