]> err.no Git - linux-2.6/blobdiff - net/ipv4/netfilter/ipt_MASQUERADE.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6] / net / ipv4 / netfilter / ipt_MASQUERADE.c
index 57e9f6cf1c36d5eac1574351a96a9768cea82b2c..27860510ca6dacb4464f65352b5f4e9c917c9921 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/config.h>
 #include <linux/types.h>
+#include <linux/inetdevice.h>
 #include <linux/ip.h>
 #include <linux/timer.h>
 #include <linux/module.h>
@@ -18,6 +19,7 @@
 #include <net/protocol.h>
 #include <net/ip.h>
 #include <net/checksum.h>
+#include <net/route.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv4/ip_nat_rule.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
@@ -33,7 +35,7 @@ MODULE_DESCRIPTION("iptables MASQUERADE target module");
 #endif
 
 /* Lock protects masq region inside conntrack */
-static DECLARE_RWLOCK(masq_lock);
+static DEFINE_RWLOCK(masq_lock);
 
 /* FIXME: Multiple targets. --RR */
 static int
@@ -86,15 +88,16 @@ masquerade_target(struct sk_buff **pskb,
 
        IP_NF_ASSERT(hooknum == NF_IP_POST_ROUTING);
 
-       /* FIXME: For the moment, don't do local packets, breaks
-          testsuite for 2.3.49 --RR */
-       if ((*pskb)->sk)
-               return NF_ACCEPT;
-
        ct = ip_conntrack_get(*pskb, &ctinfo);
        IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED
                            || 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.
+        */
+       if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip == 0)
+               return NF_ACCEPT;
+
        mr = targinfo;
        rt = (struct rtable *)(*pskb)->dst;
        newsrc = inet_select_addr(out, rt->rt_gateway, RT_SCOPE_UNIVERSE);
@@ -103,9 +106,9 @@ masquerade_target(struct sk_buff **pskb,
                return NF_DROP;
        }
 
-       WRITE_LOCK(&masq_lock);
+       write_lock_bh(&masq_lock);
        ct->nat.masq_index = out->ifindex;
-       WRITE_UNLOCK(&masq_lock);
+       write_unlock_bh(&masq_lock);
 
        /* Transfer from original range. */
        newrange = ((struct ip_nat_range)
@@ -122,9 +125,9 @@ device_cmp(struct ip_conntrack *i, void *ifindex)
 {
        int ret;
 
-       READ_LOCK(&masq_lock);
+       read_lock_bh(&masq_lock);
        ret = (i->nat.masq_index == (int)(long)ifindex);
-       READ_UNLOCK(&masq_lock);
+       read_unlock_bh(&masq_lock);
 
        return ret;
 }