2020-07-31 20:27:09 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"inet.af/netaddr"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the set of parameters that uniquely determine
|
|
|
|
// the state to which a manager should bring system DNS settings.
|
|
|
|
type Config struct {
|
|
|
|
// Nameservers are the IP addresses of the nameservers to use.
|
|
|
|
Nameservers []netaddr.IP
|
|
|
|
// Domains are the search domains to use.
|
|
|
|
Domains []string
|
2021-03-25 21:50:21 +00:00
|
|
|
// Proxied indicates whether DNS requests are proxied through a dns.Resolver.
|
2021-03-23 17:21:01 +00:00
|
|
|
// This enables MagicDNS.
|
2020-07-31 20:27:09 +00:00
|
|
|
Proxied bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Equal determines whether its argument and receiver
|
|
|
|
// represent equivalent DNS configurations (then DNS reconfig is a no-op).
|
|
|
|
func (lhs Config) Equal(rhs Config) bool {
|
2021-04-02 05:54:40 +00:00
|
|
|
if lhs.Proxied != rhs.Proxied {
|
2020-07-31 20:27:09 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(lhs.Nameservers) != len(rhs.Nameservers) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(lhs.Domains) != len(rhs.Domains) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// With how we perform resolution order shouldn't matter,
|
|
|
|
// but it is unlikely that we will encounter different orders.
|
|
|
|
for i, server := range lhs.Nameservers {
|
|
|
|
if rhs.Nameservers[i] != server {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The order of domains, on the other hand, is significant.
|
|
|
|
for i, domain := range lhs.Domains {
|
|
|
|
if rhs.Domains[i] != domain {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|