|
@@ -187,12 +187,30 @@ ip_nat_out(unsigned int hooknum,
|
|
|
const struct net_device *out,
|
|
|
int (*okfn)(struct sk_buff *))
|
|
|
{
|
|
|
+ struct ip_conntrack *ct;
|
|
|
+ enum ip_conntrack_info ctinfo;
|
|
|
+ unsigned int ret;
|
|
|
+
|
|
|
/* root is playing with raw sockets. */
|
|
|
if ((*pskb)->len < sizeof(struct iphdr)
|
|
|
|| (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
|
|
|
return NF_ACCEPT;
|
|
|
|
|
|
- return ip_nat_fn(hooknum, pskb, in, out, okfn);
|
|
|
+ ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
|
|
|
+ if (ret != NF_DROP && ret != NF_STOLEN
|
|
|
+ && (ct = ip_conntrack_get(*pskb, &ctinfo)) != NULL) {
|
|
|
+ enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
|
|
|
+
|
|
|
+ if (ct->tuplehash[dir].tuple.src.ip !=
|
|
|
+ ct->tuplehash[!dir].tuple.dst.ip
|
|
|
+#ifdef CONFIG_XFRM
|
|
|
+ || ct->tuplehash[dir].tuple.src.u.all !=
|
|
|
+ ct->tuplehash[!dir].tuple.dst.u.all
|
|
|
+#endif
|
|
|
+ )
|
|
|
+ return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
static unsigned int
|
|
@@ -217,7 +235,12 @@ ip_nat_local_fn(unsigned int hooknum,
|
|
|
enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
|
|
|
|
|
|
if (ct->tuplehash[dir].tuple.dst.ip !=
|
|
|
- ct->tuplehash[!dir].tuple.src.ip)
|
|
|
+ ct->tuplehash[!dir].tuple.src.ip
|
|
|
+#ifdef CONFIG_XFRM
|
|
|
+ || ct->tuplehash[dir].tuple.dst.u.all !=
|
|
|
+ ct->tuplehash[dir].tuple.src.u.all
|
|
|
+#endif
|
|
|
+ )
|
|
|
return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
|
|
|
}
|
|
|
return ret;
|