All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alessandro Vesely <vesely@tana.it>
To: Jan Engelhardt <jengelh@medozas.de>
Cc: netfilter@vger.kernel.org
Subject: Re: can we design a modified fail2ban ?
Date: Mon, 19 Apr 2010 17:18:12 +0200	[thread overview]
Message-ID: <4BCC7434.6020200@tana.it> (raw)
In-Reply-To: <alpine.LSU.2.01.1004181841450.9840@obet.zrqbmnf.qr>

On 18/Apr/10 18:44, Jan Engelhardt wrote:
> On Sunday 2010-04-18 15:46, Alessandro Vesely wrote:
>>  actionban = iptables -I fail2ban-<name>  1 -s<ip>  -j DROP
>>  actionunban = iptables -D fail2ban-<name>  -s<ip>  -j DROP
>>
>>  I don't know whether fail2ban uses some other storage to remember frequently banned IPs.
>
> If you are using iptables for actionban, it would not need to.

Right, but rather than deleting by number, it uses the same IP to 
issue the unban command. If the IP is remembered even after unbanning 
it, then it is possible to increase its next ban-period, in case it is 
caught again.

>>  How would you compare iptables and netfilter?
>
> Like you compare a tree with soil?

Yeah, my question was short, but not formally sound...

I heard about some not better characterized performance degradation 
that would occur when successively issuing a huge number of "iptables 
-I" commands. How huge is "huge"? Where is this topic expounded?

>>  I mean fail2ban actions versus looking up a b-tree file,
>
> Where does that btree file come from, and what should it be useful for?

A b-tree can be used to store IPs: One has to remember them, at least 
for some time, one way or another, if different IPs are to be treated 
differently. One can use an "at" command for unbanning, and avoid 
structured storage. Alternatively, one could use ipset, e.g. iptrees 
with timeouts. As yet another alternative, one can use netfilter and 
user-space storage. I mentioned b-trees because I use Berkeley DB with 
the my netfilter daemon. MySQL or anything similar offer similar 
functionality and performance.

When I started to use my daemon, I was afraid that accessing the disk 
on each packet would have been a bottleneck. So, I only filtered new 
connections. Later on, I added a rule to filter all packets, in order 
to also terminate existing connections. Two rules, actually: a 
netfilter rule to set a mark and another one to reject those packets, i.e.

   iptables -t raw -A OUTPUT -p tcp ! --syn -m multiport --sports $X \
      -j NFQUEUE --queue-num 4
   iptables -A OUTPUT -p tcp ! --syn -m mark --mark 4 \
      -j REJECT --reject-with tcp-reset

(For udp and --syn connections, a single netfilter rule is enough.)

The time taken for issuing verdicts used to be much less than that for 
parsing the log file. The former has jumped to about the double of the 
latter, after those additional two rules. Perhaps, I should have stuck 
to using netfilter for new connections only. Existing connections can 
be terminated with short-lived iptables rules, or by calling 
nids_killtcp() or "ngrep -K" directly. In hindsight, that looks fairly 
obvious. However, the above quoted fail2ban's actions don't seem to be 
concerned with such kind of optimizations. Thoughts?

  reply	other threads:[~2010-04-19 15:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-16  3:57 can we design a modified fail2ban ? J. Bakshi
2010-04-16  7:28 ` Jan Engelhardt
2010-04-17 16:01   ` Alessandro Vesely
2010-04-17 17:58     ` Jan Engelhardt
2010-04-18 13:46       ` Alessandro Vesely
2010-04-18 16:44         ` Jan Engelhardt
2010-04-19 15:18           ` Alessandro Vesely [this message]
2010-04-19  3:16     ` J. Bakshi
2010-04-16 15:29 ` Pascal Hambourg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BCC7434.6020200@tana.it \
    --to=vesely@tana.it \
    --cc=jengelh@medozas.de \
    --cc=netfilter@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.