@ -5,6 +5,7 @@ import (
"strings"
"sync"
"time"
"encoding/binary"
// "github.com/subgraph/go-nfnetlink"
"github.com/google/gopacket/layers"
@ -64,7 +65,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.NFQPacket) {
return
}
q := dns . question [ 0 ]
if q . Qtype == dnsTypeA {
if q . Qtype == dnsTypeA || q . Qtype == dnsTypeAAAA {
srcip , _ := getPacketIPAddrs ( pkt )
pinfo := getEmptyPInfo ( )
if ! isNSTrusted ( srcip ) {
@ -76,7 +77,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.NFQPacket) {
}
}
//log.Notice("XXX: PROCESS LOOKUP -> ", pinfo)
dc . processRecordA ( q . Name , dns . answer , pinfo . Pid )
dc . processRecordA ddress ( q . Name , dns . answer , pinfo . Pid )
return
}
log . Infof ( "Unhandled DNS message: %v" , dns )
@ -106,13 +107,29 @@ func procDeathCallback(pid int, param interface{}) {
}
}
func ( dc * dnsCache ) processRecordA ( name string , answers [ ] dnsRR , pid int ) {
func ( dc * dnsCache ) processRecordA ddress ( name string , answers [ ] dnsRR , pid int ) {
dc . lock . Lock ( )
defer dc . lock . Unlock ( )
for _ , rr := range answers {
var aBytes [ ] byte = nil
switch rec := rr . ( type ) {
case * dnsRR_A :
ip := net . IPv4 ( byte ( rec . A >> 24 ) , byte ( rec . A >> 16 ) , byte ( rec . A >> 8 ) , byte ( rec . A ) ) . String ( )
var ipA [ 4 ] byte
aBytes = ipA [ : ]
binary . BigEndian . PutUint32 ( aBytes , rec . A )
case * dnsRR_AAAA :
aBytes = rec . AAAA [ : ]
case * dnsRR_CNAME :
// Not that exotic; just ignore it
default :
log . Warningf ( "Unexpected RR type in answer section of A response: %v" , rec )
}
if aBytes == nil {
continue
}
ip := net . IP ( aBytes ) . String ( )
if strings . HasSuffix ( name , "." ) {
name = name [ : len ( name ) - 1 ]
}
@ -145,13 +162,6 @@ func (dc *dnsCache) processRecordA(name string, answers []dnsRR, pid int) {
if ! FirewallConfig . LogRedact {
log . Infof ( "Adding %s: %s" , name , ip )
}
case * dnsRR_AAAA :
log . Warning ( "AAAA record read from DNS; not supported." )
case * dnsRR_CNAME :
// Not that exotic; just ignore it
default :
log . Warningf ( "Unexpected RR type in answer section of A response: %v" , rec )
}
}
}