zettio/weave#362 - use for fallback queries the same protocol clients have used for querying us.
This commit is contained in:
1 parent
9c7ffd9b81
commit
ef72d65aa4
1 file changed
+14
-11
+14
-11
@@ -61,10 +61,15 @@ func (s *DNSServer) Start() error {
|
||||
err = mdnsClient.Start(s.iface)
|
||||
checkFatal(err)
|
||||
|
||||
LocalServeMux := dns.NewServeMux()
|
||||
LocalServeMux.HandleFunc(LOCAL_DOMAIN, s.queryHandler([]Lookup{s.zone, mdnsClient}))
|
||||
LocalServeMux.HandleFunc(RDNS_DOMAIN, s.rdnsHandler([]Lookup{s.zone, mdnsClient}))
|
||||
LocalServeMux.HandleFunc(".", s.notUsHandler())
|
||||
// create two DNS request multiplexerers, depending on the protocol used by clients
|
||||
// (we use the same protocol for asking upstream servers)
|
||||
mux := func(client *dns.Client) *dns.ServeMux {
|
||||
m := dns.NewServeMux()
|
||||
m.HandleFunc(LOCAL_DOMAIN, s.queryHandler([]Lookup{s.zone, mdnsClient}))
|
||||
m.HandleFunc(RDNS_DOMAIN, s.rdnsHandler([]Lookup{s.zone, mdnsClient}, client))
|
||||
m.HandleFunc(".", s.notUsHandler(client))
|
||||
return m
|
||||
}
|
||||
|
||||
mdnsServer, err := NewMDNSServer(s.zone)
|
||||
checkFatal(err)
|
||||
@@ -73,8 +78,8 @@ func (s *DNSServer) Start() error {
|
||||
checkFatal(err)
|
||||
|
||||
address := fmt.Sprintf(":%d", s.port)
|
||||
s.udpSrv = &dns.Server{Addr: address, Net: "udp", Handler: LocalServeMux}
|
||||
s.tcpSrv = &dns.Server{Addr: address, Net: "tcp", Handler: LocalServeMux}
|
||||
s.udpSrv = &dns.Server{Addr: address, Net: "udp", Handler: mux(&dns.Client{Net: "udp", UDPSize: UDPBufSize})}
|
||||
s.tcpSrv = &dns.Server{Addr: address, Net: "tcp", Handler: mux(&dns.Client{Net: "tcp"})}
|
||||
|
||||
go func() {
|
||||
Info.Printf("Listening for DNS on %s (UDP)", address)
|
||||
@@ -121,8 +126,8 @@ func (s *DNSServer) queryHandler(lookups []Lookup) dns.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DNSServer) rdnsHandler(lookups []Lookup) dns.HandlerFunc {
|
||||
fallback := s.notUsHandler()
|
||||
func (s *DNSServer) rdnsHandler(lookups []Lookup, client *dns.Client) dns.HandlerFunc {
|
||||
fallback := s.notUsHandler(client)
|
||||
return func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
q := r.Question[0]
|
||||
Debug.Printf("Reverse query: %+v", q)
|
||||
@@ -144,9 +149,7 @@ func (s *DNSServer) rdnsHandler(lookups []Lookup) dns.HandlerFunc {
|
||||
|
||||
// When we receive a request for a name outside of our '.weave.local.'
|
||||
// domain, ask the configured DNS server as a fallback.
|
||||
func (s *DNSServer) notUsHandler() dns.HandlerFunc {
|
||||
dnsClient := new(dns.Client)
|
||||
dnsClient.UDPSize = UDPBufSize
|
||||
func (s *DNSServer) notUsHandler(dnsClient *dns.Client) dns.HandlerFunc {
|
||||
return func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
q := r.Question[0]
|
||||
Debug.Printf("[dns msgid %d] Fallback query: %+v", r.MsgHdr.Id, q)
|
||||
|
||||
Reference in new issue
Block a user