From 28bb42c5a2c5e13a59eeb6cb242eba38a3475bbc Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Tue, 19 Mar 2024 22:48:38 -0400 Subject: [PATCH] Properly filter family by Query Type Only emit A records for IPv4 and AAAA records for IPv6 Queries --- conn.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/conn.go b/conn.go index f25ac55..e8aa392 100644 --- a/conn.go +++ b/conn.go @@ -865,19 +865,16 @@ 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 } selectedIP = ipCopy