Skip to contentSkip to conversation

How many individual rules before performance tanks?

netfilter-core Harald Welte 1 participant 1 message Nov 26, 2003 1 message not in the archive netfilter

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · Apollyon

I have a very specialised project in which I need to have potentially hundreds of thousands of single-ip# packet deny/accept rules which need to be individually added/removed on demand [can be throttled so that changes are batched to occur every minute].

please allow me to Cc' my reply to the netfilter mailinglist. this way other people can benefit from the answers I give.

Quoted 5 lines

1) Normal packet flow from one interface to another, traversing all of the rules. The configuration will be a default accept, with thousands
of razor-sharp deny rules. With about 200,000 deny rules, for example, would there be an appreciable loss in performance for packets which do NOT trigger a DENY rule? Obviously, I don't care about the performance of the DENY rule hits.

you certainly don't want to use iptables (or ipchains/ipfwadm) for a configuration like this. Inherent through it's architecture, it will not scale to 200,000 unordered rules flat in one chain.

Quoted 3 lines

2) Assuming a very busy network with constantly high traffic [40-60 Mbps], would ruleset insertion/removals take a great deal of time to execute in such an environment? [Locking issues???]

again, this is not feasible with iptables. all your rules would be sent from kernel to userspace, where the single change would be done, and the whole ruleset be sent back to the kernel. there is no support for incremental ruleset changes inside the kernel.

Quoted 3 lines

3) What is the upper bound of the number of rules? The BSD OSs seem to have a limit of 65535 uniquely-specifiable rules. Are there inherent limitations in Netfilter?

there is no limitation in iptables. But they are linearly traversed. The only optimization you can do is manually organizing them in trees of user-defined chains.

Quoted 5 lines

4) If netfilter as it exists cannot perform well in this (admittedly strange) environment, I am willing and able to implement an O(n) packet filter system which will handle 20 million rules as quickly as 20 using a two-level segmented bitmapping strategy. Mapping the entire IPv4 space would require at most 512MB with this strategy, allocated in 8K [/16] hunks.

please try your luck with nf-hipac. (www.hipac.org). They should scale quite well, especially for applications like yours - with exactly the same semantics like iptables.

Quoted 2 lines

Robert Seretny

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie