Skip to content

Commit aa5237a

Browse files
author
Safing
committed
Fixed cleanup acutally not removing any elements
1 parent 96e9abd commit aa5237a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

firewall/inspection/portscan/detect.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ func (d *Detector) Inspect(conn *network.Connection, pkt packet.Packet) (pktVerd
9797
log.Tracer(ctx).Debugf("Conn: %v, Entity: %#v, Protocol: %v, LocalIP: %s, LocalPort: %d, inMap: %v, entry: %+v", conn, conn.Entity, conn.IPProtocol, conn.LocalIP.String(), conn.LocalPort, inMap, entry)
9898

9999
if inMap {
100-
entry.updateScoreIgnoreBlockPrevOffender(ipString)
100+
inMap = entry.updateScoreIgnoreBlockPrevOffender(ipString)
101+
}
102+
103+
if inMap {
101104
entry.lastSeen = time.Now()
102105

103106
if entry.ignore {
@@ -200,7 +203,9 @@ func handleMaliciousPacket(ctx context.Context, inMap bool, conn *network.Connec
200203

201204
//updateScoreIgnoreBlockPrevOffender updates this 4 Values of the Struct
202205
//ipString needs to correspond to the key of the entry in the map ips
203-
func (d *ipData) updateScoreIgnoreBlockPrevOffender(ipString string) {
206+
//WARNING: This function maybe deletes the entry ipString from the Map ips. (look at the returncode)
207+
//return: still in map? (bool)
208+
func (d *ipData) updateScoreIgnoreBlockPrevOffender(ipString string) bool {
204209
d.score -= intMin(int(time.Since(d.lastUpdated)/decreaseInterval), d.score)
205210

206211
if d.ignore {
@@ -220,7 +225,13 @@ func (d *ipData) updateScoreIgnoreBlockPrevOffender(ipString string) {
220225
status.DeleteThreat(threadPrefix + ipString)
221226
}
222227

228+
if !d.blocked && !d.ignore && !d.previousOffender && d.score == 0 {
229+
delete(ips, ipString)
230+
return false
231+
}
232+
223233
d.lastUpdated = time.Now()
234+
return true
224235
}
225236

226237
// Destroy implements the destroy interface.
@@ -254,8 +265,11 @@ func updateWholeList() {
254265
runOnlyOne.Lock()
255266
defer runOnlyOne.Unlock()
256267

257-
entry.updateScoreIgnoreBlockPrevOffender(ip)
258-
log.Debugf("%s: %v", ip, entry)
268+
if entry.updateScoreIgnoreBlockPrevOffender(ip) {
269+
log.Debugf("%s: %v", ip, entry)
270+
} else {
271+
log.Debugf("Removed %s from the list", ip)
272+
}
259273
}
260274
log.Debugf("Portscan detection: finished update list&cleanup")
261275

0 commit comments

Comments
 (0)