Save blocked DNS queries

This commit is contained in:
Daniel
2020-04-08 14:07:59 +02:00
parent 249261a3da
commit 7da9e64c27
3 changed files with 12 additions and 9 deletions

View File

@@ -71,7 +71,6 @@ func NewConnectionFromDNSRequest(ctx context.Context, fqdn string, ip net.IP, po
Started: timestamp,
Ended: timestamp,
}
saveOpenDNSRequest(dnsConn)
return dnsConn
}
@@ -218,8 +217,8 @@ func (conn *Connection) SaveWhenFinished() {
conn.saveWhenFinished = true
}
// save saves the link object in the storage and propagates the change.
func (conn *Connection) save() {
// Save saves the connection in the storage and propagates the change through the database system.
func (conn *Connection) Save() {
if conn.ID == "" {
// dns request
@@ -336,7 +335,7 @@ func (conn *Connection) packetHandler() {
// must not be locked, will deadlock with cleaner functions
if conn.saveWhenFinished {
conn.saveWhenFinished = false
conn.save()
conn.Save()
}
// submit trace logs
log.Tracer(pkt.Ctx()).Submit()

View File

@@ -26,7 +26,8 @@ func removeOpenDNSRequest(pid int, fqdn string) {
delete(openDNSRequests, key)
}
func saveOpenDNSRequest(conn *Connection) {
// SaveOpenDNSRequest saves a dns request connection that was allowed to proceed.
func SaveOpenDNSRequest(conn *Connection) {
openDNSRequestsLock.Lock()
defer openDNSRequestsLock.Unlock()
@@ -65,7 +66,7 @@ func writeOpenDNSRequestsToDB() {
for id, conn := range openDNSRequests {
conn.Lock()
if conn.Ended < threshold {
conn.save()
conn.Save()
delete(openDNSRequests, id)
}
conn.Unlock()