: nf_conntrack: use hash for expectations
Subsystems (2)
[NETFILTER]: nf_conntrack: use hash for expectations
Use a hashtable for expectations to avoid searching a single global list for every new connection. The default hash size is 1/256 of the conntrack hash table size, this can be overriden using a module parameter.
Signed-off-by Patrick McHardy <[email protected]>
---
commit 7246b74f7501fcddd2876408ee3e88f8988cf957
tree ab55cdc97f8c6049b00dc0508fbb4be8e4a92011
parent 873139d6b6e37954fd70dab4fe9362490da3f00b
author Patrick McHardy <[email protected]> Tue, 26 Jun 2007 15:57:32 +0200 committer Patrick McHardy <[email protected]> Tue, 26 Jun 2007 15:57:32 +0200
include/net/netfilter/nf_conntrack_expect.h | 6 + net/netfilter/nf_conntrack_core.c | 9 ++ net/netfilter/nf_conntrack_expect.c | 119 +++++++++++++++++++++++++++ net/netfilter/nf_conntrack_standalone.c | 11 -- 4 files changed, 132 insertions(+), 13 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +5 -1
@@ -8,7 +8,6 @@extern struct list_head nf_conntrack_expect_list;extern struct kmem_cache *nf_conntrack_expect_cachep; -extern const struct file_operations exp_file_ops;struct nf_conntrack_expect_mask {
@@ -21,6 +20,9 @@ struct nf_conntrack_expect/* Internal linked list (global expectation list) */ struct list_head list; +/* Hash member */ +struct hlist_node hlist; +/* We expect this tuple, with the following mask */ struct nf_conntrack_tuple tuple;struct nf_conntrack_expect_mask mask;
@@ -59,6 +61,8 @@ struct nf_conntrack_expect#define NF_CT_EXPECT_PERMANENT 0x1 +int nf_ct_expect_init (void ); +void nf_ct_expect_fini (void );struct nf_conntrack_expect *__nf_conntrack_expect_find (const struct nf_conntrack_tuple *tuple);
net/netfilter/nf_conntrack_core.c +8 -1
@@ -963,6 +963,7 @@ void nf_conntrack_cleanup(void)nf_conntrack_proto_fini ();nf_conntrack_helper_fini (); +nf_ct_expect_fini (); }static struct list_head *alloc_hashtable (int *sizep,int *vmalloced)
@@ -1088,10 +1089,14 @@ int __init nf_conntrack_init(void)if (ret <0 ) goto out_free_expect_slab; - ret =nf_conntrack_helper_init (); + ret =nf_ct_expect_init ();if (ret <0 ) goto out_fini_proto; + ret =nf_conntrack_helper_init (); +if (ret <0 ) + goto out_fini_expect; +/* For use by REJECT target */ rcu_assign_pointer (ip_ct_attach, __nf_conntrack_attach);rcu_assign_pointer (nf_ct_destroy, destroy_conntrack);
@@ -1104,6 +1109,8 @@ int __init nf_conntrack_init(void)return ret; +out_fini_expect: +nf_ct_expect_fini (); out_fini_proto:nf_conntrack_proto_fini (); out_free_expect_slab:
net/netfilter/nf_conntrack_expect.c +117 -2
169 lines not on this page · raw message
net/netfilter/nf_conntrack_standalone.c +2 -9
@@ -410,7 +410,7 @@ EXPORT_SYMBOL_GPL(nf_ct_log_invalid);static int __init nf_conntrack_standalone_init (void ) {#ifdef CONFIG_PROC_FS -struct proc_dir_entry *proc, *proc_exp, *proc_stat; +struct proc_dir_entry *proc, *proc_stat;#endif int ret =0 ;
@@ -422,13 +422,9 @@ static int __init nf_conntrack_standalone_init(void) proc =proc_net_fops_create ("nf_conntrack" ,0440 , &ct_file_ops);if (!proc) goto cleanup_init; - proc_exp =proc_net_fops_create ("nf_conntrack_expect" ,0440 , - &exp_file_ops); -if (!proc_exp) goto cleanup_proc; - proc_stat =create_proc_entry ("nf_conntrack" ,S_IRUGO , proc_net_stat);if (!proc_stat) - goto cleanup_proc_exp; + goto cleanup_proc; proc_stat->proc_fops = &ct_cpu_seq_fops; proc_stat->owner =THIS_MODULE ;
@@ -448,8 +444,6 @@ static int __init nf_conntrack_standalone_init(void)#endif #ifdef CONFIG_PROC_FS remove_proc_entry ("nf_conntrack" , proc_net_stat); - cleanup_proc_exp: -proc_net_remove ("nf_conntrack_expect" ); cleanup_proc:proc_net_remove ("nf_conntrack" ); cleanup_init:
@@ -465,7 +459,6 @@ static void __exit nf_conntrack_standalone_fini(void)#endif #ifdef CONFIG_PROC_FS remove_proc_entry ("nf_conntrack" , proc_net_stat); -proc_net_remove ("nf_conntrack_expect" );proc_net_remove ("nf_conntrack" );#endif /* CNFIG_PROC_FS */ nf_conntrack_cleanup ();