Minor fixes/refinements

This commit is contained in:
Alfonso Acosta
2016-09-16 13:50:53 +00:00
parent 028ed32b6f
commit f5ad6a8e97
2 changed files with 7 additions and 5 deletions

View File

@@ -98,7 +98,9 @@ func newPcapHandle() (*pcap.Handle, error) {
// obtained while snooping A-record queries
func (s *DNSSnooper) CachedNamesForIP(ip string) []string {
result := []string{}
if s == nil {
return result
}
domains, err := s.reverseDNSCache.Get(ip)
if err != nil {
return result
@@ -201,14 +203,14 @@ func (s *DNSSnooper) processDNSMessage(dns *layers.DNS) {
}
}
log.Debugf("DNSSnooper: caught DNS lookup: %s -> %v", string(domainQueried), ips)
// Update cache
// TODO: Be smarter about the expiration of IPs with multiple reverse-domains
newDomain := string(domainQueried)
log.Debugf("DNSSnooper: caught DNS lookup: %s -> %v", newDomain, ips)
for ip := range ips {
if existingDomains, err := s.reverseDNSCache.Get(ip); err != nil {
s.reverseDNSCache.Set(ip, map[string]struct{}{newDomain: {}})
} else {
// TODO: Be smarter about the expiration of entries with pre-existing associated domains
existingDomains.(map[string]struct{})[newDomain] = struct{}{}
}
}

View File

@@ -69,7 +69,7 @@ func TestSpyNoProcesses(t *testing.T) {
)
scanner := procspy.FixedScanner(fixConnections)
reporter := endpoint.NewReporter(nodeID, nodeName, false, false, false, "", scanner)
reporter := endpoint.NewReporter(nodeID, nodeName, false, false, false, "", scanner, nil)
r, _ := reporter.Report()
//buf, _ := json.MarshalIndent(r, "", " ")
//t.Logf("\n%s\n", buf)
@@ -86,7 +86,7 @@ func TestSpyWithProcesses(t *testing.T) {
)
scanner := procspy.FixedScanner(fixConnectionsWithProcesses)
reporter := endpoint.NewReporter(nodeID, nodeName, true, false, true, "", scanner)
reporter := endpoint.NewReporter(nodeID, nodeName, true, false, true, "", scanner, nil)
r, _ := reporter.Report()
// buf, _ := json.MarshalIndent(r, "", " ") ; t.Logf("\n%s\n", buf)