using a hash table for netfilter tables?
Subsystems (2)
Quoted 9 lines · Andre Uratsuka Manoel
Hi all,
I need to replace the current list-based netfilter code for something using hashtables. The reason is that I have hundreds of tables in a project, but set up times are killing me. I took a peek at the code and it looked easy to do, since the current list-based code already takes care of locking, that's a huge problem I don't have to care about.
Is there something I should know abot? Any tips? Is this stupid?
Hi Andre,
If, as Patrick Schaaf suggested, you are already using iptables-restore, then it could be that you are having the same problems as us. Would you be willing to try Robert Olsson's kernel patch, to see if it makes a difference to your ruleset loading time? Our cleaned-up version of the patch is attached, or we can give you the original if you prefer.
(I posted this patch to netfilter-devel on Tuesday, but it doesn't seem to have made the list yet.)
Cheers, Chris.
Signature · 4 lines
___ __ _ / __// / ,__(_)_ | Chris Wilson -- UNIX Firewall Lead Developer | / (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk | \ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |
This is my updated version of Robert Olsson's patch, against 2.4.20 with patch-o-matic-20030107.
<[email protected]> 17/04/03
net/ipv4/netfilter/ip_tables.c +16 -1
@@ -8,4 +8,9 @@* - increase module usage count as soon as we have rules inside * a table +* +* 6 Mar 2002 Robert Olsson <[email protected]> +* 17 Apr 2003 Chris Wilson <[email protected]> +* - mark_source_chains speedup for complex chains +* */ #include <linux/config.h>
@@ -503,4 +508,7 @@unsigned int hook; +/* keep track of where we have been: */ +unsigned char *been =vmalloc (newinfo->size); +/* No recursion; use packet counter to save back ptrs (reset to 0 as we leave), and comefrom to save source hook bitmask */
@@ -515,4 +523,5 @@/* Set initial back pointer. */ e->counters.pcnt = pos; +memset (been,0 , newinfo->size);for (;;) {
@@ -523,4 +532,5 @@printk ("iptables: loop hook %u pos %u %08X.\n" , hook, pos, e->comefrom); +vfree (been);return 0 ; }
@@ -570,8 +580,12 @@int newpos = t->verdict; -if (strcmp (t->target.u.user.name, +if ( (pos <0 || pos >= newinfo->size + || !been[pos]) + &&strcmp (t->target.u.user.name,IPT_STANDARD_TARGET ) ==0 && newpos >=0 ) {/* This a jump; chase it. */ +if (pos >=0 && pos < newinfo->size) + been[pos]++;duprintf ("Jump rule %u -> %u\n" , pos, newpos);
@@ -589,4 +603,5 @@duprintf ("Finished chain %u\n" , hook); } +vfree (been);return 1 ; }
Quoted 6 lines · Chris Wilson
Quoted 6 lines
I need to replace the current list-based netfilter code for something using hashtables. The reason is that I have hundreds of tables in a project, but set up times are killing me. I took a peek at the code and it looked easy to do, since the current list-based code already takes care of locking, that's a huge problem I don't have to care about.
Quoted 7 lines
Quoted 1 line
Is there something I should know abot? Any tips? Is this stupid?
If, as Patrick Schaaf suggested, you are already using iptables-restore, then it could be that you are having the same problems as us. Would you be willing to try Robert Olsson's kernel patch, to see if it makes a difference to your ruleset loading time? Our cleaned-up version of the patch is attached, or we can give you the original if you prefer.
I wasn't using iptables-restore, but I gave it a try and it takes
about 2 minutes to load 600 chains. The time seems to be inside iptables-restore, and not in the kernel.
I will try the patch, but that will have to wait a few days, since
I have to take care of some other business before that. I took a quick peek at it, and didn't understand it yet...
Later, though, I will have to deal with changing rules and those
still require linear-time searches...
Thank you for your help.
Andre