From: Joel Newkirk <netfilter@newkirk.us>
To: Gerald Galster <Gerry@gerry.de>, netfilter@lists.netfilter.org
Subject: Re: IP Accounting and performance
Date: Mon, 9 Dec 2002 10:21:44 -0500 [thread overview]
Message-ID: <200212091021.44030.netfilter@newkirk.us> (raw)
In-Reply-To: <AB18D92A-0AF2-11D7-96A2-00039376F59E@gerry.de>
On Sunday 08 December 2002 04:18 pm, Gerald Galster wrote:
> Hi all,
>
> Perhaps you can give me some hints on a performance problem that I'm
> currently experiencing with iptables.
>
> The situation is as follows:
>
> I have a firewall currently running kernel 2.4.20, Celeron 1 GHz and
> 512 MB of RAM
> that should do traffic accounting based on single IP addresses. I
> thought it would be more
> efficient to use iptables than writing a standalone application using
> pcap or the like.
You will probably get your best speed (and usability of the resulting
data) if you just use one of the accounting daemons that can be paired
with the ULOG target, and use the two rules below. Google/linux search
on "Netfilter ULOG accounting"
http://www.google.com/linux?num=100&restrict=linux&hl=en&lr=&ie=ISO-8859-1&q=netfilter+ULOG+accounting&btnG=Google+Search
turns up some useful links... That said, if you still want to do it
directly in your ruleset, read on! :^)
> I need to add filtering rules like
>
> /sbin/iptables -A FORWARD -o eth0 -s ip_address/32
> /sbin/iptables -A FORWARD -i eth0 -d ip_address/32
Is this the complete rule? If you don't have a target it will count and
pass to the next rule. Since all you said you are doing is counting
that may seem OK, but it means that each packet is tested against each
and every rule...
If you can use a -j ACCEPT target for them it will count, and prevent
testing against following rules. This will seriously speed up testing
for IP's that appear early in the list, but won't help later ones at
all. Best is to break the address range down into smaller chunks.
Something expanded from the following might work well:
/sbin/iptables -N ip01to31in
/sbin/iptables -N ip32to63out
/sbin/iptables -A ip01to31in -d 10.11.12.13 -j RETURN
/sbin/iptables -A FORWARD -i eth0 -d 10.11.12.0/27 -j ip01to31in
/sbin/iptables -A ip32to63out -s 10.11.12.33 -j RETURN
/sbin/iptables -A FORWARD -o eth0 -s 10.11.12.32/27 -j ip32to63out
This creates a user-defined chain (two in this sample fragment) to test a
range of addresses, which can be broken down in whatever fashion gives
you either an even distribution of rules among the userdef chains, or
simply two chains and two FORWARD rules for each subnet. (Obviously the
breakdown must occur in some fashion that is easy to test, IE based on
masking the IPs) The latter would allow you to use the FORWARD chain
counts to see overall numbers for each subnet, but if one subnet is 5
machines and another is 1000 this will obviously be seriously
unbalanced. You can also further break down from a user defined chain
to several more sub-chains using the same technique if this is useful.
> for about six class-C networks (this means about 3000 iptables rules).
Your end result can be twelve user-defined chains, one in/one out for
each subnet, and twelve rules in FORWARD.
Using the RETURN target in the user-defined chains simply passes the
packet back to the originating chain (IE, FORWARD) and skips testing
against the remaining rules in the chain. You can substitute ACCEPT (or
DROP or REJECT) with no problem here as well. RETURN shouldn't incur
much more processing time, since the packet should only match and be
passed to ONE userdef chain, and the main FORWARD chain should be fairly
short this way, so it will only test against a few more rules after it
RETURNS to FORWARD. Using RETURN in a sub-chain will also allow you to
perform 'real' FORWARD filtering after the counting has taken place.
Also, as someone else suggested, you can have a script that creates the
rules in a loop, or perhaps six (one per subnet). Fanciest and most
efficient traversal-wise would be a balanced tree of rules, (which could
bring you down to a max of 2-3 dozen tests for each packet, instead of
thousands right now) the construction of which is beyond the scope of
this reply... :^P
Whatever you do, if you handle this with iptables rules make sure you use
the most restrictive rules possible for your situation at the upper
levels (IE in FORWARD itself) to prevent traffic being tested that
doesn't need to be. If all you're interested in is HTTP to the
internet, for example, test that in the FORWARD rules before reaching
the subchains.
j
> The average throughput is around 3 Mbits / second.
>
> After I've added those rules, the latency in ping times to a machine
> behind
> the firewall increases from 30 ms to over 200 ms ...
>
> Now my question is if I can speed those things up ... do you have any
> ideas?
>
> Thanks in advance.
>
> Regards,
> Gerald
next prev parent reply other threads:[~2002-12-09 15:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-08 21:18 IP Accounting and performance Gerald Galster
2002-12-09 0:13 ` Michael
2002-12-09 10:53 ` Leonardo Rodrigues ( listas )
2002-12-09 15:21 ` Joel Newkirk [this message]
2002-12-10 14:18 ` Gerald Galster
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=200212091021.44030.netfilter@newkirk.us \
--to=netfilter@newkirk.us \
--cc=Gerry@gerry.de \
--cc=netfilter@lists.netfilter.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox