Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-drm-fsl-dcu.git] / net / ipv4 / netfilter / ipt_MASQUERADE.c
index ebd94f2abf0d49674d8ba6d74e34dff475eb7588..b5955f3a3f8f0866a429493264b5ecef276a0791 100644 (file)
@@ -2,7 +2,7 @@
    (depending on route). */
 
 /* (C) 1999-2001 Paul `Rusty' Russell
- * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
+ * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
 #include <net/checksum.h>
 #include <net/route.h>
 #include <linux/netfilter_ipv4.h>
+#ifdef CONFIG_NF_NAT_NEEDED
+#include <net/netfilter/nf_nat_rule.h>
+#else
 #include <linux/netfilter_ipv4/ip_nat_rule.h>
-#include <linux/netfilter_ipv4/ip_tables.h>
+#endif
+#include <linux/netfilter/x_tables.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -42,7 +46,6 @@ masquerade_check(const char *tablename,
                 const void *e,
                 const struct xt_target *target,
                 void *targinfo,
-                unsigned int targinfosize,
                 unsigned int hook_mask)
 {
        const struct ip_nat_multi_range_compat *mr = targinfo;
@@ -64,26 +67,35 @@ masquerade_target(struct sk_buff **pskb,
                  const struct net_device *out,
                  unsigned int hooknum,
                  const struct xt_target *target,
-                 const void *targinfo,
-                 void *userinfo)
+                 const void *targinfo)
 {
+#ifdef CONFIG_NF_NAT_NEEDED
+       struct nf_conn_nat *nat;
+#endif
        struct ip_conntrack *ct;
        enum ip_conntrack_info ctinfo;
-       const struct ip_nat_multi_range_compat *mr;
        struct ip_nat_range newrange;
+       const struct ip_nat_multi_range_compat *mr;
        struct rtable *rt;
-       u_int32_t newsrc;
+       __be32 newsrc;
 
        IP_NF_ASSERT(hooknum == NF_IP_POST_ROUTING);
 
        ct = ip_conntrack_get(*pskb, &ctinfo);
+#ifdef CONFIG_NF_NAT_NEEDED
+       nat = nfct_nat(ct);
+#endif
        IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED
-                           || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
+                           || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
 
        /* Source address is 0.0.0.0 - locally generated packet that is
         * probably not supposed to be masqueraded.
         */
+#ifdef CONFIG_NF_NAT_NEEDED
+       if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip == 0)
+#else
        if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip == 0)
+#endif
                return NF_ACCEPT;
 
        mr = targinfo;
@@ -95,7 +107,11 @@ masquerade_target(struct sk_buff **pskb,
        }
 
        write_lock_bh(&masq_lock);
+#ifdef CONFIG_NF_NAT_NEEDED
+       nat->masq_index = out->ifindex;
+#else
        ct->nat.masq_index = out->ifindex;
+#endif
        write_unlock_bh(&masq_lock);
 
        /* Transfer from original range. */
@@ -112,9 +128,19 @@ static inline int
 device_cmp(struct ip_conntrack *i, void *ifindex)
 {
        int ret;
+#ifdef CONFIG_NF_NAT_NEEDED
+       struct nf_conn_nat *nat = nfct_nat(i);
+
+       if (!nat)
+               return 0;
+#endif
 
        read_lock_bh(&masq_lock);
+#ifdef CONFIG_NF_NAT_NEEDED
+       ret = (nat->masq_index == (int)(long)ifindex);
+#else
        ret = (i->nat.masq_index == (int)(long)ifindex);
+#endif
        read_unlock_bh(&masq_lock);
 
        return ret;
@@ -164,8 +190,9 @@ static struct notifier_block masq_inet_notifier = {
        .notifier_call  = masq_inet_event,
 };
 
-static struct ipt_target masquerade = {
+static struct xt_target masquerade = {
        .name           = "MASQUERADE",
+       .family         = AF_INET,
        .target         = masquerade_target,
        .targetsize     = sizeof(struct ip_nat_multi_range_compat),
        .table          = "nat",
@@ -178,7 +205,7 @@ static int __init ipt_masquerade_init(void)
 {
        int ret;
 
-       ret = ipt_register_target(&masquerade);
+       ret = xt_register_target(&masquerade);
 
        if (ret == 0) {
                /* Register for device down reports */
@@ -192,9 +219,9 @@ static int __init ipt_masquerade_init(void)
 
 static void __exit ipt_masquerade_fini(void)
 {
-       ipt_unregister_target(&masquerade);
+       xt_unregister_target(&masquerade);
        unregister_netdevice_notifier(&masq_dev_notifier);
-       unregister_inetaddr_notifier(&masq_inet_notifier);      
+       unregister_inetaddr_notifier(&masq_inet_notifier);
 }
 
 module_init(ipt_masquerade_init);