Skip to content

Commit 9937ae1

Browse files
committed
fix: defaultNS not working in system dns
1 parent 8f5a864 commit 9937ae1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

dns/system.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ type systemClient struct {
3131

3232
func (c *systemClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
3333
dnsClients, err := c.getDnsClients()
34+
if len(dnsClients) == 0 && len(c.defaultNS) > 0 {
35+
dnsClients = c.defaultNS
36+
err = nil
37+
}
3438
if err != nil {
35-
if len(c.defaultNS) > 0 {
36-
dnsClients = c.defaultNS
37-
} else {
38-
return
39-
}
39+
return
4040
}
4141
msg, _, err = batchExchange(ctx, dnsClients, m)
4242
return
@@ -45,11 +45,16 @@ func (c *systemClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Ms
4545
// Address implements dnsClient
4646
func (c *systemClient) Address() string {
4747
dnsClients, _ := c.getDnsClients()
48+
isDefault := ""
49+
if len(dnsClients) == 0 && len(c.defaultNS) > 0 {
50+
dnsClients = c.defaultNS
51+
isDefault = "[defaultNS]"
52+
}
4853
addrs := make([]string, 0, len(dnsClients))
4954
for _, c := range dnsClients {
5055
addrs = append(addrs, c.Address())
5156
}
52-
return fmt.Sprintf("system(%s)", strings.Join(addrs, ","))
57+
return fmt.Sprintf("system%s(%s)", isDefault, strings.Join(addrs, ","))
5358
}
5459

5560
var _ dnsClient = (*systemClient)(nil)

0 commit comments

Comments
 (0)