diff --git a/dns/main.go b/dns/main.go index 9f1c00ea..a1ee520c 100644 --- a/dns/main.go +++ b/dns/main.go @@ -26,7 +26,6 @@ var mdnsClient *weavedns.MDNSClient func handleMDNS(w dns.ResponseWriter, r *dns.Msg) { // Here we have to handle both requests incoming, responses to queries // we sent out, and responses to queries that other nodes sent - // And we also get to see our own queries! if len(r.Answer) > 0 { mdnsClient.HandleResponse(r) } else if len(r.Question) > 0 { @@ -35,6 +34,10 @@ func handleMDNS(w dns.ResponseWriter, r *dns.Msg) { if err == nil { m := makeDNSReply(r, q.Name, net.ParseIP(ip)) mdnsClient.SendResponse(m) + } else if mdnsClient.IsInflightQuery(r) { + // ignore this - it's our own query received via multicast + } else { + log.Printf("Failed MDNS lookup for %s", q.Name) } } } diff --git a/mdns_client.go b/mdns_client.go index c9ee138f..f8d8b479 100644 --- a/mdns_client.go +++ b/mdns_client.go @@ -73,7 +73,7 @@ func (c *MDNSClient) SendQuery(name string, querytype uint16, responseCh chan<- c.Lock() query, found := c.inflight[name] if !found { - query = &inflightQuery{name: name} + query = &inflightQuery{name: name, Id: m.Id} c.inflight[name] = query } info := &responseInfo{ch: responseCh} @@ -97,6 +97,22 @@ func (c *MDNSClient) SendResponse(m *dns.Msg) error { return err } +func (c *MDNSClient) IsInflightQuery(m *dns.Msg) bool { + if len(m.Question) == 1 { + q := m.Question[0] + if q.Qtype == dns.TypeA { + c.Lock() + defer c.Unlock() + if query, found := c.inflight[q.Name]; found { + if query.Id == m.Id { + return true + } + } + } + } + return false +} + func (c *MDNSClient) HandleResponse(r *dns.Msg) { for _, answer := range r.Answer { switch rr := answer.(type) {