fix: defaultNS not working in system dns

This commit is contained in:
wwqgtxx 2024-10-05 14:16:50 +08:00
parent 8f5a86410c
commit 9937ae1002

View File

@ -31,12 +31,12 @@ type systemClient struct {
func (c *systemClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
dnsClients, err := c.getDnsClients()
if err != nil {
if len(c.defaultNS) > 0 {
if len(dnsClients) == 0 && len(c.defaultNS) > 0 {
dnsClients = c.defaultNS
} else {
return
err = nil
}
if err != nil {
return
}
msg, _, err = batchExchange(ctx, dnsClients, m)
return
@ -45,11 +45,16 @@ func (c *systemClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Ms
// Address implements dnsClient
func (c *systemClient) Address() string {
dnsClients, _ := c.getDnsClients()
isDefault := ""
if len(dnsClients) == 0 && len(c.defaultNS) > 0 {
dnsClients = c.defaultNS
isDefault = "[defaultNS]"
}
addrs := make([]string, 0, len(dnsClients))
for _, c := range dnsClients {
addrs = append(addrs, c.Address())
}
return fmt.Sprintf("system(%s)", strings.Join(addrs, ","))
return fmt.Sprintf("system%s(%s)", isDefault, strings.Join(addrs, ","))
}
var _ dnsClient = (*systemClient)(nil)