Skip to content

Commit ddd86cf

Browse files
committed
Use powershell Resolve-DnsName -Name <name> to verify DNS on Windows.
The `nslookup` used before this commit, does not use the DNS information provided by the OS, and hence is not a good choice for validating that our local DNS server is functional. Signed-off-by: Thomas Hallgren <[email protected]>
1 parent e66fa64 commit ddd86cf

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

pkg/client/userd/trafficmgr/intercept.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,12 @@ func (s *session) InterceptEpilog(context.Context, *rpc.CreateInterceptRequest,
732732
}
733733

734734
func waitForDNS(c context.Context, host string) bool {
735-
c, cancel := context.WithTimeout(c, 5*time.Second)
735+
c, cancel := context.WithTimeout(c, 12*time.Second)
736736
defer cancel()
737737
for c.Err() == nil {
738738
dtime.SleepWithContext(c, 200*time.Millisecond)
739739
dlog.Debugf(c, "Attempting to resolve DNS for %s", host)
740-
ips := dnsproxy.TimedExternalLookup(c, host, 3*time.Second)
740+
ips := dnsproxy.TimedExternalLookup(c, host, 5*time.Second)
741741
if len(ips) > 0 {
742742
dlog.Debugf(c, "Attempt succeeded, DNS for %s is %v", host, ips)
743743
return true

pkg/dnsproxy/lookup_windows.go

+4-25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"bytes"
66
"context"
7+
"fmt"
78
"strings"
89
"time"
910

@@ -14,39 +15,17 @@ import (
1415
func externalLookup(ctx context.Context, host string, timeout time.Duration) iputil.IPs {
1516
ctx, cancel := context.WithTimeout(ctx, timeout)
1617
defer cancel()
17-
cmd := proc.CommandContext(ctx, "nslookup", host)
18+
cmd := proc.CommandContext(ctx, "powershell.exe", "-NoProfile", "-NonInteractive", fmt.Sprintf("(Resolve-DnsName -Name %s -Type A_AAAA -DnsOnly).IPAddress", host))
1819
cmd.DisableLogging = true
1920
out, err := cmd.Output()
2021
if err != nil {
2122
return nil
2223
}
23-
24-
// Look for the adjacent lines
25-
// Name: <host> [possibly extended with search path]
26-
// Address: <ip>
2724
var ips iputil.IPs
2825
sc := bufio.NewScanner(bytes.NewReader(out))
2926
for sc.Scan() {
30-
s := sc.Text()
31-
if a := strings.TrimPrefix(s, "Name:"); a != s && strings.HasPrefix(strings.TrimSpace(a), host) && sc.Scan() {
32-
s = sc.Text()
33-
if a := strings.TrimPrefix(s, "Address:"); a != s {
34-
if ip := iputil.Parse(strings.TrimSpace(a)); ip != nil {
35-
ips = append(ips, ip)
36-
}
37-
} else if a := strings.TrimPrefix(s, "Addresses:"); a != s {
38-
for {
39-
if ip := iputil.Parse(strings.TrimSpace(a)); ip != nil {
40-
ips = append(ips, ip)
41-
} else {
42-
break
43-
}
44-
if !sc.Scan() {
45-
break
46-
}
47-
a = sc.Text()
48-
}
49-
}
27+
if ip := iputil.Parse(strings.TrimSpace(sc.Text())); ip != nil {
28+
ips = append(ips, ip)
5029
}
5130
}
5231
return ips

pkg/vif/device_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func getGlobalSearchList() ([]string, error) {
237237
}
238238

239239
func setGlobalSearchList(ctx context.Context, gss []string) error {
240-
cmd := proc.CommandContext(ctx, "powershell.exe", "Set-DnsClientGlobalSetting", "-SuffixSearchList", psList(gss))
240+
cmd := proc.CommandContext(ctx, "powershell.exe", "-NoProfile", "-NonInteractive", "Set-DnsClientGlobalSetting", "-SuffixSearchList", psList(gss))
241241
_, err := proc.CaptureErr(ctx, cmd)
242242
return err
243243
}

0 commit comments

Comments
 (0)