aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2007-07-08 01:30:27 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-07-11 01:17:43 -0400
commit53aba5979e1d964c0234816eda2316f1c2e7946d (patch)
tree042b0528b82f119d2a452c0e2a448f1d4d04fb14
parentac565e5fc104fe1842a87f2206fcfb7b6dda903d (diff)
[NETFILTER]: nf_nat: use hlists for bysource hash
Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/netfilter/nf_nat.h2
-rw-r--r--net/ipv4/netfilter/nf_nat_core.c21
2 files changed, 12 insertions, 11 deletions
diff --git a/include/net/netfilter/nf_nat.h b/include/net/netfilter/nf_nat.h
index d0e5e436dc1..6ae52f7c9f5 100644
--- a/include/net/netfilter/nf_nat.h
+++ b/include/net/netfilter/nf_nat.h
@@ -66,7 +66,7 @@ struct nf_conn;
66/* The structure embedded in the conntrack structure. */ 66/* The structure embedded in the conntrack structure. */
67struct nf_conn_nat 67struct nf_conn_nat
68{ 68{
69 struct list_head bysource; 69 struct hlist_node bysource;
70 struct nf_nat_seq seq[IP_CT_DIR_MAX]; 70 struct nf_nat_seq seq[IP_CT_DIR_MAX];
71 struct nf_conn *ct; 71 struct nf_conn *ct;
72 union nf_conntrack_nat_help help; 72 union nf_conntrack_nat_help help;
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index 04691edf50c..f242ac61b3e 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -12,7 +12,6 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/timer.h> 13#include <linux/timer.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/vmalloc.h>
16#include <net/checksum.h> 15#include <net/checksum.h>
17#include <net/icmp.h> 16#include <net/icmp.h>
18#include <net/ip.h> 17#include <net/ip.h>
@@ -44,8 +43,9 @@ static struct nf_conntrack_l3proto *l3proto = NULL;
44 43
45/* Calculated at init based on memory size */ 44/* Calculated at init based on memory size */
46static unsigned int nf_nat_htable_size; 45static unsigned int nf_nat_htable_size;
46static int nf_nat_vmalloced;
47 47
48static struct list_head *bysource; 48static struct hlist_head *bysource;
49 49
50#define MAX_IP_NAT_PROTO 256 50#define MAX_IP_NAT_PROTO 256
51static struct nf_nat_protocol *nf_nat_protos[MAX_IP_NAT_PROTO]; 51static struct nf_nat_protocol *nf_nat_protos[MAX_IP_NAT_PROTO];
@@ -153,9 +153,10 @@ find_appropriate_src(const struct nf_conntrack_tuple *tuple,
153 unsigned int h = hash_by_src(tuple); 153 unsigned int h = hash_by_src(tuple);
154 struct nf_conn_nat *nat; 154 struct nf_conn_nat *nat;
155 struct nf_conn *ct; 155 struct nf_conn *ct;
156 struct hlist_node *n;
156 157
157 read_lock_bh(&nf_nat_lock); 158 read_lock_bh(&nf_nat_lock);
158 list_for_each_entry(nat, &bysource[h], bysource) { 159 hlist_for_each_entry(nat, n, &bysource[h], bysource) {
159 ct = nat->ct; 160 ct = nat->ct;
160 if (same_src(ct, tuple)) { 161 if (same_src(ct, tuple)) {
161 /* Copy source part from reply tuple. */ 162 /* Copy source part from reply tuple. */
@@ -336,7 +337,7 @@ nf_nat_setup_info(struct nf_conn *ct,
336 /* nf_conntrack_alter_reply might re-allocate exntension aera */ 337 /* nf_conntrack_alter_reply might re-allocate exntension aera */
337 nat = nfct_nat(ct); 338 nat = nfct_nat(ct);
338 nat->ct = ct; 339 nat->ct = ct;
339 list_add(&nat->bysource, &bysource[srchash]); 340 hlist_add_head(&nat->bysource, &bysource[srchash]);
340 write_unlock_bh(&nf_nat_lock); 341 write_unlock_bh(&nf_nat_lock);
341 } 342 }
342 343
@@ -600,7 +601,7 @@ static void nf_nat_cleanup_conntrack(struct nf_conn *ct)
600 NF_CT_ASSERT(nat->ct->status & IPS_NAT_DONE_MASK); 601 NF_CT_ASSERT(nat->ct->status & IPS_NAT_DONE_MASK);
601 602
602 write_lock_bh(&nf_nat_lock); 603 write_lock_bh(&nf_nat_lock);
603 list_del(&nat->bysource); 604 hlist_del(&nat->bysource);
604 nat->ct = NULL; 605 nat->ct = NULL;
605 write_unlock_bh(&nf_nat_lock); 606 write_unlock_bh(&nf_nat_lock);
606} 607}
@@ -618,7 +619,7 @@ static void nf_nat_move_storage(struct nf_conn *conntrack, void *old)
618 srchash = hash_by_src(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); 619 srchash = hash_by_src(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
619 620
620 write_lock_bh(&nf_nat_lock); 621 write_lock_bh(&nf_nat_lock);
621 list_replace(&old_nat->bysource, &new_nat->bysource); 622 hlist_replace_rcu(&old_nat->bysource, &new_nat->bysource);
622 new_nat->ct = ct; 623 new_nat->ct = ct;
623 write_unlock_bh(&nf_nat_lock); 624 write_unlock_bh(&nf_nat_lock);
624} 625}
@@ -646,8 +647,8 @@ static int __init nf_nat_init(void)
646 /* Leave them the same for the moment. */ 647 /* Leave them the same for the moment. */
647 nf_nat_htable_size = nf_conntrack_htable_size; 648 nf_nat_htable_size = nf_conntrack_htable_size;
648 649
649 /* One vmalloc for both hash tables */ 650 bysource = nf_ct_alloc_hashtable(&nf_nat_htable_size,
650 bysource = vmalloc(sizeof(struct list_head) * nf_nat_htable_size); 651 &nf_nat_vmalloced);
651 if (!bysource) { 652 if (!bysource) {
652 ret = -ENOMEM; 653 ret = -ENOMEM;
653 goto cleanup_extend; 654 goto cleanup_extend;
@@ -663,7 +664,7 @@ static int __init nf_nat_init(void)
663 write_unlock_bh(&nf_nat_lock); 664 write_unlock_bh(&nf_nat_lock);
664 665
665 for (i = 0; i < nf_nat_htable_size; i++) { 666 for (i = 0; i < nf_nat_htable_size; i++) {
666 INIT_LIST_HEAD(&bysource[i]); 667 INIT_HLIST_HEAD(&bysource[i]);
667 } 668 }
668 669
669 /* Initialize fake conntrack so that NAT will skip it */ 670 /* Initialize fake conntrack so that NAT will skip it */
@@ -693,7 +694,7 @@ static void __exit nf_nat_cleanup(void)
693{ 694{
694 nf_ct_iterate_cleanup(&clean_nat, NULL); 695 nf_ct_iterate_cleanup(&clean_nat, NULL);
695 synchronize_rcu(); 696 synchronize_rcu();
696 vfree(bysource); 697 nf_ct_free_hashtable(bysource, nf_nat_vmalloced, nf_nat_htable_size);
697 nf_ct_l3proto_put(l3proto); 698 nf_ct_l3proto_put(l3proto);
698 nf_ct_extend_unregister(&nat_extend); 699 nf_ct_extend_unregister(&nat_extend);
699} 700}