diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2007-12-18 01:45:28 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 17:59:11 -0500 |
commit | 7b21e09d1c17ef0296ec5a6df231a6c5c87b2fd7 (patch) | |
tree | 97df5c5e4b8a9cc6a76cc432b39b321542634f44 | |
parent | e2f82ac3fcffffca59751b65124544d11ed8be4a (diff) |
[NETFILTER]: xt_hashlimit: reduce overhead without IPv6
This patch generalizes the (CONFIG_IP6_NF_IPTABLES || CONFIG_IP6_NF_IPTABLES_MODULE)
test done in hashlimit_init_dst() to all the xt_hashlimit module.
This permits a size reduction of "struct dsthash_dst". This saves memory and
cpu for IPV4 only hosts.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/netfilter/xt_hashlimit.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index 651c1d26564a..c35d220a7ae2 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c | |||
@@ -20,8 +20,11 @@ | |||
20 | #include <linux/mm.h> | 20 | #include <linux/mm.h> |
21 | #include <linux/in.h> | 21 | #include <linux/in.h> |
22 | #include <linux/ip.h> | 22 | #include <linux/ip.h> |
23 | #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) | ||
23 | #include <linux/ipv6.h> | 24 | #include <linux/ipv6.h> |
24 | #include <net/ipv6.h> | 25 | #include <net/ipv6.h> |
26 | #endif | ||
27 | |||
25 | #include <net/net_namespace.h> | 28 | #include <net/net_namespace.h> |
26 | 29 | ||
27 | #include <linux/netfilter/x_tables.h> | 30 | #include <linux/netfilter/x_tables.h> |
@@ -48,10 +51,12 @@ struct dsthash_dst { | |||
48 | __be32 src; | 51 | __be32 src; |
49 | __be32 dst; | 52 | __be32 dst; |
50 | } ip; | 53 | } ip; |
54 | #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) | ||
51 | struct { | 55 | struct { |
52 | __be32 src[4]; | 56 | __be32 src[4]; |
53 | __be32 dst[4]; | 57 | __be32 dst[4]; |
54 | } ip6; | 58 | } ip6; |
59 | #endif | ||
55 | } addr; | 60 | } addr; |
56 | __be16 src_port; | 61 | __be16 src_port; |
57 | __be16 dst_port; | 62 | __be16 dst_port; |
@@ -599,6 +604,7 @@ static struct xt_match hashlimit_mt_reg[] __read_mostly = { | |||
599 | .destroy = hashlimit_mt_destroy, | 604 | .destroy = hashlimit_mt_destroy, |
600 | .me = THIS_MODULE | 605 | .me = THIS_MODULE |
601 | }, | 606 | }, |
607 | #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) | ||
602 | { | 608 | { |
603 | .name = "hashlimit", | 609 | .name = "hashlimit", |
604 | .family = AF_INET6, | 610 | .family = AF_INET6, |
@@ -613,6 +619,7 @@ static struct xt_match hashlimit_mt_reg[] __read_mostly = { | |||
613 | .destroy = hashlimit_mt_destroy, | 619 | .destroy = hashlimit_mt_destroy, |
614 | .me = THIS_MODULE | 620 | .me = THIS_MODULE |
615 | }, | 621 | }, |
622 | #endif | ||
616 | }; | 623 | }; |
617 | 624 | ||
618 | /* PROC stuff */ | 625 | /* PROC stuff */ |
@@ -675,6 +682,7 @@ static int dl_seq_real_show(struct dsthash_ent *ent, int family, | |||
675 | ntohs(ent->dst.dst_port), | 682 | ntohs(ent->dst.dst_port), |
676 | ent->rateinfo.credit, ent->rateinfo.credit_cap, | 683 | ent->rateinfo.credit, ent->rateinfo.credit_cap, |
677 | ent->rateinfo.cost); | 684 | ent->rateinfo.cost); |
685 | #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) | ||
678 | case AF_INET6: | 686 | case AF_INET6: |
679 | return seq_printf(s, "%ld " NIP6_FMT ":%u->" | 687 | return seq_printf(s, "%ld " NIP6_FMT ":%u->" |
680 | NIP6_FMT ":%u %u %u %u\n", | 688 | NIP6_FMT ":%u %u %u %u\n", |
@@ -685,6 +693,7 @@ static int dl_seq_real_show(struct dsthash_ent *ent, int family, | |||
685 | ntohs(ent->dst.dst_port), | 693 | ntohs(ent->dst.dst_port), |
686 | ent->rateinfo.credit, ent->rateinfo.credit_cap, | 694 | ent->rateinfo.credit, ent->rateinfo.credit_cap, |
687 | ent->rateinfo.cost); | 695 | ent->rateinfo.cost); |
696 | #endif | ||
688 | default: | 697 | default: |
689 | BUG(); | 698 | BUG(); |
690 | return 0; | 699 | return 0; |
@@ -756,14 +765,17 @@ static int __init hashlimit_mt_init(void) | |||
756 | "entry\n"); | 765 | "entry\n"); |
757 | goto err3; | 766 | goto err3; |
758 | } | 767 | } |
768 | err = 0; | ||
769 | #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) | ||
759 | hashlimit_procdir6 = proc_mkdir("ip6t_hashlimit", init_net.proc_net); | 770 | hashlimit_procdir6 = proc_mkdir("ip6t_hashlimit", init_net.proc_net); |
760 | if (!hashlimit_procdir6) { | 771 | if (!hashlimit_procdir6) { |
761 | printk(KERN_ERR "xt_hashlimit: unable to create proc dir " | 772 | printk(KERN_ERR "xt_hashlimit: unable to create proc dir " |
762 | "entry\n"); | 773 | "entry\n"); |
763 | goto err4; | 774 | err = -ENOMEM; |
764 | } | 775 | } |
765 | return 0; | 776 | #endif |
766 | err4: | 777 | if (!err) |
778 | return 0; | ||
767 | remove_proc_entry("ipt_hashlimit", init_net.proc_net); | 779 | remove_proc_entry("ipt_hashlimit", init_net.proc_net); |
768 | err3: | 780 | err3: |
769 | kmem_cache_destroy(hashlimit_cachep); | 781 | kmem_cache_destroy(hashlimit_cachep); |
@@ -777,7 +789,9 @@ err1: | |||
777 | static void __exit hashlimit_mt_exit(void) | 789 | static void __exit hashlimit_mt_exit(void) |
778 | { | 790 | { |
779 | remove_proc_entry("ipt_hashlimit", init_net.proc_net); | 791 | remove_proc_entry("ipt_hashlimit", init_net.proc_net); |
792 | #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) | ||
780 | remove_proc_entry("ip6t_hashlimit", init_net.proc_net); | 793 | remove_proc_entry("ip6t_hashlimit", init_net.proc_net); |
794 | #endif | ||
781 | kmem_cache_destroy(hashlimit_cachep); | 795 | kmem_cache_destroy(hashlimit_cachep); |
782 | xt_unregister_matches(hashlimit_mt_reg, ARRAY_SIZE(hashlimit_mt_reg)); | 796 | xt_unregister_matches(hashlimit_mt_reg, ARRAY_SIZE(hashlimit_mt_reg)); |
783 | } | 797 | } |