diff --git a/config.go b/config.go index 50a7a57..3e211db 100644 --- a/config.go +++ b/config.go @@ -41,6 +41,9 @@ type Config struct { // IncludeLoopback will include loopback interfaces to be eligble for queries and answers. IncludeLoopback bool + // DisableLinkLocal disables answering with the Link-Local Address + DisableLinkLocal bool + // Interfaces will override the interfaces used for queries and answers. Interfaces []net.Interface } diff --git a/conn.go b/conn.go index f25ac55..f73fb27 100644 --- a/conn.go +++ b/conn.go @@ -865,19 +865,20 @@ func (c *Conn) readLoop(name string, pktConn ipPacketConn, inboundBufferSize int var selectedIP net.IP for _, ip := range ifc.ips { ipCopy := ip + ipIsV6 := ipCopy.To4() == nil - // match up respective IP types based on question - if queryWantsV4 { - if ipv4 := ipCopy.To4(); ipv4 == nil { - continue - } - } else { // queryWantsV6 - if ipv6 := ipCopy.To16(); ipv6 == nil { - continue - } else if !isSupportedIPv6(ipv6, c.multicastPktConnV4 == nil) { - c.log.Debugf("interface %d address not a supported IPv6 address %s", ifIndex, ipCopy) - continue - } + // Query must match family (A for IPv4 and AAAA IPv6) + if queryWantsV4 == ipIsV6 { + continue + } + + if ipIsV6 && !isSupportedIPv6(ipCopy, c.multicastPktConnV4 == nil) { + c.log.Debugf("interface %d address not a supported IPv6 address %s", ifIndex, ipCopy) + continue + } + + if config.DisableLinkLocal && ipCopy.IsLinkLocalUnicast() { + continue } selectedIP = ipCopy