]> Cypherpunks repositories - gostls13.git/commitdiff
net: filter disabled interfaces in Windows DNS client
authorZhiyuan Zheng <zhzy0077@hotmail.com>
Thu, 13 Oct 2022 03:28:10 +0000 (03:28 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 2 Jun 2023 16:58:42 +0000 (16:58 +0000)
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: db158625bb46692cbbc09e3fe4dfa023c733f4e6
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>
src/net/dnsconfig_windows.go

index 5d640da1d740c9c8f5e01e24ff613d2d505f3e01..f3d242366ae2cd59f50672286277298bff8afd66 100644 (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