|
|
@ -5,6 +5,7 @@ import (
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
|
|
|
|
// "github.com/subgraph/go-nfnetlink"
|
|
|
|
// "github.com/subgraph/go-nfnetlink"
|
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
"github.com/google/gopacket/layers"
|
|
|
@ -64,7 +65,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.NFQPacket) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
q := dns.question[0]
|
|
|
|
q := dns.question[0]
|
|
|
|
if q.Qtype == dnsTypeA {
|
|
|
|
if q.Qtype == dnsTypeA || q.Qtype == dnsTypeAAAA {
|
|
|
|
srcip, _ := getPacketIPAddrs(pkt)
|
|
|
|
srcip, _ := getPacketIPAddrs(pkt)
|
|
|
|
pinfo := getEmptyPInfo()
|
|
|
|
pinfo := getEmptyPInfo()
|
|
|
|
if !isNSTrusted(srcip) {
|
|
|
|
if !isNSTrusted(srcip) {
|
|
|
@ -76,7 +77,7 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.NFQPacket) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//log.Notice("XXX: PROCESS LOOKUP -> ", pinfo)
|
|
|
|
//log.Notice("XXX: PROCESS LOOKUP -> ", pinfo)
|
|
|
|
dc.processRecordA(q.Name, dns.answer, pinfo.Pid)
|
|
|
|
dc.processRecordAddress(q.Name, dns.answer, pinfo.Pid)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Infof("Unhandled DNS message: %v", dns)
|
|
|
|
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) processRecordAddress(name string, answers []dnsRR, pid int) {
|
|
|
|
dc.lock.Lock()
|
|
|
|
dc.lock.Lock()
|
|
|
|
defer dc.lock.Unlock()
|
|
|
|
defer dc.lock.Unlock()
|
|
|
|
for _, rr := range answers {
|
|
|
|
for _, rr := range answers {
|
|
|
|
|
|
|
|
var aBytes []byte = nil
|
|
|
|
switch rec := rr.(type) {
|
|
|
|
switch rec := rr.(type) {
|
|
|
|
case *dnsRR_A:
|
|
|
|
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, ".") {
|
|
|
|
if strings.HasSuffix(name, ".") {
|
|
|
|
name = name[:len(name)-1]
|
|
|
|
name = name[:len(name)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,13 +162,6 @@ func (dc *dnsCache) processRecordA(name string, answers []dnsRR, pid int) {
|
|
|
|
if !FirewallConfig.LogRedact {
|
|
|
|
if !FirewallConfig.LogRedact {
|
|
|
|
log.Infof("Adding %s: %s", name, ip)
|
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|