|
|
@@ -24,29 +24,31 @@ import (
|
|
|
// ClassicNameServer implemented traditional UDP DNS.
|
|
|
type ClassicNameServer struct {
|
|
|
sync.RWMutex
|
|
|
- name string
|
|
|
- address *net.Destination
|
|
|
- ips map[string]*record
|
|
|
- requests map[uint16]*dnsRequest
|
|
|
- pub *pubsub.Service
|
|
|
- udpServer *udp.Dispatcher
|
|
|
- cleanup *task.Periodic
|
|
|
- reqID uint32
|
|
|
+ name string
|
|
|
+ address *net.Destination
|
|
|
+ ips map[string]*record
|
|
|
+ requests map[uint16]*dnsRequest
|
|
|
+ pub *pubsub.Service
|
|
|
+ udpServer *udp.Dispatcher
|
|
|
+ cleanup *task.Periodic
|
|
|
+ reqID uint32
|
|
|
+ queryStrategy QueryStrategy
|
|
|
}
|
|
|
|
|
|
// NewClassicNameServer creates udp server object for remote resolving.
|
|
|
-func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher) *ClassicNameServer {
|
|
|
+func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher, queryStrategy QueryStrategy) *ClassicNameServer {
|
|
|
// default to 53 if unspecific
|
|
|
if address.Port == 0 {
|
|
|
address.Port = net.Port(53)
|
|
|
}
|
|
|
|
|
|
s := &ClassicNameServer{
|
|
|
- address: &address,
|
|
|
- ips: make(map[string]*record),
|
|
|
- requests: make(map[uint16]*dnsRequest),
|
|
|
- pub: pubsub.NewService(),
|
|
|
- name: strings.ToUpper(address.String()),
|
|
|
+ address: &address,
|
|
|
+ ips: make(map[string]*record),
|
|
|
+ requests: make(map[uint16]*dnsRequest),
|
|
|
+ pub: pubsub.NewService(),
|
|
|
+ name: strings.ToUpper(address.String()),
|
|
|
+ queryStrategy: queryStrategy,
|
|
|
}
|
|
|
s.cleanup = &task.Periodic{
|
|
|
Interval: time.Minute,
|
|
|
@@ -239,6 +241,10 @@ func (s *ClassicNameServer) findIPsForDomain(domain string, option dns_feature.I
|
|
|
// QueryIP implements Server.
|
|
|
func (s *ClassicNameServer) QueryIP(ctx context.Context, domain string, clientIP net.IP, option dns_feature.IPOption, disableCache bool) ([]net.IP, error) {
|
|
|
fqdn := Fqdn(domain)
|
|
|
+ option = ResolveIpOptionOverride(s.queryStrategy, option)
|
|
|
+ if !option.IPv4Enable && !option.IPv6Enable {
|
|
|
+ return nil, dns_feature.ErrEmptyResponse
|
|
|
+ }
|
|
|
|
|
|
if disableCache {
|
|
|
errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name)
|