diff options
author | Jan Engelhardt <jengelh@inai.de> | 2012-09-21 05:41:34 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-09-21 06:12:05 -0400 |
commit | 2cbc78a29e76a2e92c172651204f3117491877d2 (patch) | |
tree | f61c52236d72a68a746fa09def3052d712e7b0d0 /net/ipv4 | |
parent | b3d54b3e406b5d6ac391590bf7524e887e8e13c3 (diff) |
netfilter: combine ipt_REDIRECT and ip6t_REDIRECT
Combine more modules since the actual code is so small anyway that the
kmod metadata and the module in its loaded state totally outweighs the
combined actual code size.
IP_NF_TARGET_REDIRECT becomes a compat option; IP6_NF_TARGET_REDIRECT
is completely eliminated since it has not see a release yet.
Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Acked-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/netfilter/Kconfig | 12 | ||||
-rw-r--r-- | net/ipv4/netfilter/Makefile | 1 | ||||
-rw-r--r-- | net/ipv4/netfilter/ipt_REDIRECT.c | 113 |
3 files changed, 5 insertions, 121 deletions
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig index 6f140084004f..d8d6f2a5bf12 100644 --- a/net/ipv4/netfilter/Kconfig +++ b/net/ipv4/netfilter/Kconfig | |||
@@ -181,13 +181,11 @@ config IP_NF_TARGET_NETMAP | |||
181 | config IP_NF_TARGET_REDIRECT | 181 | config IP_NF_TARGET_REDIRECT |
182 | tristate "REDIRECT target support" | 182 | tristate "REDIRECT target support" |
183 | depends on NETFILTER_ADVANCED | 183 | depends on NETFILTER_ADVANCED |
184 | help | 184 | select NETFILTER_XT_TARGET_REDIRECT |
185 | REDIRECT is a special case of NAT: all incoming connections are | 185 | ---help--- |
186 | mapped onto the incoming interface's address, causing the packets to | 186 | This is a backwards-compat option for the user's convenience |
187 | come to the local machine instead of passing through. This is | 187 | (e.g. when running oldconfig). It selects |
188 | useful for transparent proxies. | 188 | CONFIG_NETFILTER_XT_TARGET_REDIRECT. |
189 | |||
190 | To compile it as a module, choose M here. If unsure, say N. | ||
191 | 189 | ||
192 | endif | 190 | endif |
193 | 191 | ||
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile index f4446c5d6595..007b128eecc9 100644 --- a/net/ipv4/netfilter/Makefile +++ b/net/ipv4/netfilter/Makefile | |||
@@ -45,7 +45,6 @@ obj-$(CONFIG_IP_NF_MATCH_RPFILTER) += ipt_rpfilter.o | |||
45 | obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o | 45 | obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o |
46 | obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o | 46 | obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o |
47 | obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o | 47 | obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o |
48 | obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o | ||
49 | obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o | 48 | obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o |
50 | obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o | 49 | obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o |
51 | 50 | ||
diff --git a/net/ipv4/netfilter/ipt_REDIRECT.c b/net/ipv4/netfilter/ipt_REDIRECT.c deleted file mode 100644 index 11407d7d2472..000000000000 --- a/net/ipv4/netfilter/ipt_REDIRECT.c +++ /dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | /* Redirect. Simple mapping which alters dst to a local IP address. */ | ||
2 | /* (C) 1999-2001 Paul `Rusty' Russell | ||
3 | * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | */ | ||
9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
10 | #include <linux/types.h> | ||
11 | #include <linux/ip.h> | ||
12 | #include <linux/timer.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/netfilter.h> | ||
15 | #include <linux/netdevice.h> | ||
16 | #include <linux/if.h> | ||
17 | #include <linux/inetdevice.h> | ||
18 | #include <net/protocol.h> | ||
19 | #include <net/checksum.h> | ||
20 | #include <linux/netfilter_ipv4.h> | ||
21 | #include <linux/netfilter/x_tables.h> | ||
22 | #include <net/netfilter/nf_nat.h> | ||
23 | |||
24 | MODULE_LICENSE("GPL"); | ||
25 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | ||
26 | MODULE_DESCRIPTION("Xtables: Connection redirection to localhost"); | ||
27 | |||
28 | /* FIXME: Take multiple ranges --RR */ | ||
29 | static int redirect_tg_check(const struct xt_tgchk_param *par) | ||
30 | { | ||
31 | const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo; | ||
32 | |||
33 | if (mr->range[0].flags & NF_NAT_RANGE_MAP_IPS) { | ||
34 | pr_debug("bad MAP_IPS.\n"); | ||
35 | return -EINVAL; | ||
36 | } | ||
37 | if (mr->rangesize != 1) { | ||
38 | pr_debug("bad rangesize %u.\n", mr->rangesize); | ||
39 | return -EINVAL; | ||
40 | } | ||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | static unsigned int | ||
45 | redirect_tg(struct sk_buff *skb, const struct xt_action_param *par) | ||
46 | { | ||
47 | struct nf_conn *ct; | ||
48 | enum ip_conntrack_info ctinfo; | ||
49 | __be32 newdst; | ||
50 | const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo; | ||
51 | struct nf_nat_range newrange; | ||
52 | |||
53 | NF_CT_ASSERT(par->hooknum == NF_INET_PRE_ROUTING || | ||
54 | par->hooknum == NF_INET_LOCAL_OUT); | ||
55 | |||
56 | ct = nf_ct_get(skb, &ctinfo); | ||
57 | NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED)); | ||
58 | |||
59 | /* Local packets: make them go to loopback */ | ||
60 | if (par->hooknum == NF_INET_LOCAL_OUT) | ||
61 | newdst = htonl(0x7F000001); | ||
62 | else { | ||
63 | struct in_device *indev; | ||
64 | struct in_ifaddr *ifa; | ||
65 | |||
66 | newdst = 0; | ||
67 | |||
68 | rcu_read_lock(); | ||
69 | indev = __in_dev_get_rcu(skb->dev); | ||
70 | if (indev && (ifa = indev->ifa_list)) | ||
71 | newdst = ifa->ifa_local; | ||
72 | rcu_read_unlock(); | ||
73 | |||
74 | if (!newdst) | ||
75 | return NF_DROP; | ||
76 | } | ||
77 | |||
78 | /* Transfer from original range. */ | ||
79 | memset(&newrange.min_addr, 0, sizeof(newrange.min_addr)); | ||
80 | memset(&newrange.max_addr, 0, sizeof(newrange.max_addr)); | ||
81 | newrange.flags = mr->range[0].flags | NF_NAT_RANGE_MAP_IPS; | ||
82 | newrange.min_addr.ip = newdst; | ||
83 | newrange.max_addr.ip = newdst; | ||
84 | newrange.min_proto = mr->range[0].min; | ||
85 | newrange.max_proto = mr->range[0].max; | ||
86 | |||
87 | /* Hand modified range to generic setup. */ | ||
88 | return nf_nat_setup_info(ct, &newrange, NF_NAT_MANIP_DST); | ||
89 | } | ||
90 | |||
91 | static struct xt_target redirect_tg_reg __read_mostly = { | ||
92 | .name = "REDIRECT", | ||
93 | .family = NFPROTO_IPV4, | ||
94 | .target = redirect_tg, | ||
95 | .targetsize = sizeof(struct nf_nat_ipv4_multi_range_compat), | ||
96 | .table = "nat", | ||
97 | .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT), | ||
98 | .checkentry = redirect_tg_check, | ||
99 | .me = THIS_MODULE, | ||
100 | }; | ||
101 | |||
102 | static int __init redirect_tg_init(void) | ||
103 | { | ||
104 | return xt_register_target(&redirect_tg_reg); | ||
105 | } | ||
106 | |||
107 | static void __exit redirect_tg_exit(void) | ||
108 | { | ||
109 | xt_unregister_target(&redirect_tg_reg); | ||
110 | } | ||
111 | |||
112 | module_init(redirect_tg_init); | ||
113 | module_exit(redirect_tg_exit); | ||