From c9faf3126e7521aadd45673961f9842abfc84926 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Thu, 13 Oct 2022 03:28:10 +0000 Subject: [PATCH] net: filter disabled interfaces in Windows DNS client The Go DNS resolver on Windows should filter disabled interfaces. Otherwise disabled TUN devices, VPNs will be also considered as valid nameservers and finally timedout. Fixes #56160 (Originally from Zhiyuan Zheng in https://go.dev/cl/442375) Co-authored-by: Zhiyuan Zheng GitHub-Last-Rev: db158625bb46692cbbc09e3fe4dfa023c733f4e6 GitHub-Pull-Request: golang/go#56161 Change-Id: I7becebc55c8ac612c670c533855f7e6ca397a496 Reviewed-on: https://go-review.googlesource.com/c/go/+/500375 TryBot-Result: Gopher Robot Run-TryBot: Brad Fitzpatrick Auto-Submit: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor Reviewed-by: Michael Knyszek --- src/net/dnsconfig_windows.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/net/dnsconfig_windows.go b/src/net/dnsconfig_windows.go index 5d640da1d7..f3d242366a 100644 --- a/src/net/dnsconfig_windows.go +++ b/src/net/dnsconfig_windows.go @@ -5,6 +5,7 @@ package net import ( + "internal/syscall/windows" "syscall" "time" ) @@ -30,6 +31,10 @@ func dnsReadConfig(ignoredFilename string) (conf *dnsConfig) { // In practice, however, it mostly works. for _, aa := range aas { for dns := aa.FirstDnsServerAddress; dns != nil; dns = dns.Next { + // Only take interfaces whose OperStatus is IfOperStatusUp(0x01) into DNS configs. + if aa.OperStatus != windows.IfOperStatusUp { + continue + } sa, err := dns.Address.Sockaddr.Sockaddr() if err != nil { continue -- 2.50.0