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 <zhzy0077@hotmail.com>
 in https://go.dev/cl/442375)

Co-authored-by: Zhiyuan Zheng <zhzy0077@hotmail.com>
GitHub-Last-Rev: db158625bb
GitHub-Pull-Request: golang/go#56161
Change-Id: I7becebc55c8ac612c670c533855f7e6ca397a496
Reviewed-on: https://go-review.googlesource.com/c/go/+/500375
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Zhiyuan Zheng 2022-10-13 03:28:10 +00:00 committed by Gopher Robot
parent 2e4fe8bbf0
commit c9faf3126e
1 changed files with 5 additions and 0 deletions

View File

@ -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