Eric Dumazet wrote: > Le samedi 27 février 2010 à 20:38 -0700, Tim Gardner a écrit : >> From 03b1a0171cd3b7eb680ec738ddcc21c59688f6fe Mon Sep 17 00:00:00 2001 >> From: Tim Gardner >> Date: Sat, 27 Feb 2010 20:22:07 -0700 >> Subject: [PATCH] netfilter: xt_recent: Add an entry reaper >> >> One of the problems with the way xt_recent is implemented is that >> there is no efficient way to remove expired entries. Of course, >> one can write a rule '-m recent --remove', but you have to know >> beforehand which entry to delete. This commit adds reaper >> logic which checks one entry on the LRU list each time a rule >> is invoked that has a '--seconds' value. If an entry ceases >> to accumulate time stamps, then eventually the reaper will >> encounter it in the LRU list and remove it. >> > > Might I ask why do you want to remove expired entries like this, using > cpu cycles in the fast path ? I dont understand why you need this reaper > pointer given we already have lru_list to give us the oldest entry. > > 1) They are normally removed in recent_entry_init(), when a new entry is > about to be added. > > 2) All entries are flushed when > echo clear > /proc/net/xt_recent/ > > 3) You could eventually implement a purge operation to remove all > expired entries at will > > echo purge > /proc/net/xt_recent/ > > > I realize there are manual methods for removing entries, but I argue that manual methods are insufficient in a dynamic environment. Let me explain one of my use cases. One of the companies that I work for is an ISP. Our primary bridge/firewall uses iptables as a first line of defense. One of the methods to detect attackers is by using a port scan detection filter (PSD), which is a bit memory and CPU intensive. Once PSD identifies an attacker, then that source IP is added to a 'recent' filter instance with an X second timeout, and the PSD entry flushes after some timeout. 'recent' continues to block _all_ traffic from that source IP until it stops sending packets for at least X seconds, at which time I would like 'recent' to release the entry. Here is a rule snippet that implements this behavior: IRAW="iptables -t raw" $IRAW -N DROPIP $IRAW -A PREROUTING -m recent --name psd --update --seconds 3600 -j DROP $IRAW -A PREROUTING -m psd --update --seconds 600 -J DROPIP $IRAW -A DROPIP -m recent --name psd --set -j DROP As long as '-m recent --name psd --update --seconds 3600' drops entries older then 3600 seconds, then nothing external is required to recover those entries. As for your fast path comment, how about scaling the frequency with which the reaper is run using a module parameter ? See attached patch. rtg -- Tim Gardner timg@tpi.com www.tpi.com OR 503-601-0234 x102 MT 406-443-5357