[NETFILTER]: x_tables: remove unused size argument to check/destroy functions
[linux-2.6.22.y-op.git] / net / ipv4 / netfilter / ipt_REDIRECT.c
blobf03d43671c6d1e5278bcd263971aac630abef9bf
1 /* Redirect. Simple mapping which alters dst to a local IP address. */
2 /* (C) 1999-2001 Paul `Rusty' Russell
3 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
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 */
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_ipv4/ip_nat_rule.h>
23 MODULE_LICENSE("GPL");
24 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
25 MODULE_DESCRIPTION("iptables REDIRECT target module");
27 #if 0
28 #define DEBUGP printk
29 #else
30 #define DEBUGP(format, args...)
31 #endif
33 /* FIXME: Take multiple ranges --RR */
34 static int
35 redirect_check(const char *tablename,
36 const void *e,
37 const struct xt_target *target,
38 void *targinfo,
39 unsigned int hook_mask)
41 const struct ip_nat_multi_range_compat *mr = targinfo;
43 if (mr->range[0].flags & IP_NAT_RANGE_MAP_IPS) {
44 DEBUGP("redirect_check: bad MAP_IPS.\n");
45 return 0;
47 if (mr->rangesize != 1) {
48 DEBUGP("redirect_check: bad rangesize %u.\n", mr->rangesize);
49 return 0;
51 return 1;
54 static unsigned int
55 redirect_target(struct sk_buff **pskb,
56 const struct net_device *in,
57 const struct net_device *out,
58 unsigned int hooknum,
59 const struct xt_target *target,
60 const void *targinfo)
62 struct ip_conntrack *ct;
63 enum ip_conntrack_info ctinfo;
64 u_int32_t newdst;
65 const struct ip_nat_multi_range_compat *mr = targinfo;
66 struct ip_nat_range newrange;
68 IP_NF_ASSERT(hooknum == NF_IP_PRE_ROUTING
69 || hooknum == NF_IP_LOCAL_OUT);
71 ct = ip_conntrack_get(*pskb, &ctinfo);
72 IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED));
74 /* Local packets: make them go to loopback */
75 if (hooknum == NF_IP_LOCAL_OUT)
76 newdst = htonl(0x7F000001);
77 else {
78 struct in_device *indev;
79 struct in_ifaddr *ifa;
81 newdst = 0;
83 rcu_read_lock();
84 indev = __in_dev_get_rcu((*pskb)->dev);
85 if (indev && (ifa = indev->ifa_list))
86 newdst = ifa->ifa_local;
87 rcu_read_unlock();
89 if (!newdst)
90 return NF_DROP;
93 /* Transfer from original range. */
94 newrange = ((struct ip_nat_range)
95 { mr->range[0].flags | IP_NAT_RANGE_MAP_IPS,
96 newdst, newdst,
97 mr->range[0].min, mr->range[0].max });
99 /* Hand modified range to generic setup. */
100 return ip_nat_setup_info(ct, &newrange, hooknum);
103 static struct ipt_target redirect_reg = {
104 .name = "REDIRECT",
105 .target = redirect_target,
106 .targetsize = sizeof(struct ip_nat_multi_range_compat),
107 .table = "nat",
108 .hooks = (1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT),
109 .checkentry = redirect_check,
110 .me = THIS_MODULE,
113 static int __init ipt_redirect_init(void)
115 return ipt_register_target(&redirect_reg);
118 static void __exit ipt_redirect_fini(void)
120 ipt_unregister_target(&redirect_reg);
123 module_init(ipt_redirect_init);
124 module_exit(ipt_redirect_fini);