diff options
-rw-r--r-- | include/net/netfilter/nf_nat.h | 2 | ||||
-rw-r--r-- | net/ipv4/netfilter/nf_nat_core.c | 21 |
2 files changed, 12 insertions, 11 deletions
diff --git a/include/net/netfilter/nf_nat.h b/include/net/netfilter/nf_nat.h index d0e5e436dc1b..6ae52f7c9f55 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. */ |
67 | struct nf_conn_nat | 67 | struct 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 04691edf50c2..f242ac61b3eb 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 */ |
46 | static unsigned int nf_nat_htable_size; | 45 | static unsigned int nf_nat_htable_size; |
46 | static int nf_nat_vmalloced; | ||
47 | 47 | ||
48 | static struct list_head *bysource; | 48 | static struct hlist_head *bysource; |
49 | 49 | ||
50 | #define MAX_IP_NAT_PROTO 256 | 50 | #define MAX_IP_NAT_PROTO 256 |
51 | static struct nf_nat_protocol *nf_nat_protos[MAX_IP_NAT_PROTO]; | 51 | static 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 | } |