]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv4/netfilter/nf_nat_standalone.c
[IP]: Introduce ip_hdrlen()
[net-next-2.6.git] / net / ipv4 / netfilter / nf_nat_standalone.c
index 5a964a167c134ff8a8ed133c26bf762f35c0a574..61ca272165a1326e27e901a96ecf738715cd36a2 100644 (file)
@@ -96,13 +96,12 @@ nf_nat_fn(unsigned int hooknum,
           protocol. 8) --RR */
        if (!ct) {
                /* Exception: ICMP redirect to new connection (not in
-                   hash table yet).  We must not let this through, in
-                   case we're doing NAT to the same network. */
+                  hash table yet).  We must not let this through, in
+                  case we're doing NAT to the same network. */
                if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) {
                        struct icmphdr _hdr, *hp;
 
-                       hp = skb_header_pointer(*pskb,
-                                               (*pskb)->nh.iph->ihl*4,
+                       hp = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                                sizeof(_hdr), &_hdr);
                        if (hp != NULL &&
                            hp->type == ICMP_REDIRECT)
@@ -141,7 +140,7 @@ nf_nat_fn(unsigned int hooknum,
                        if (unlikely(nf_ct_is_confirmed(ct)))
                                /* NAT module was loaded late */
                                ret = alloc_null_binding_confirmed(ct, info,
-                                                                  hooknum);
+                                                                  hooknum);
                        else if (hooknum == NF_IP_LOCAL_IN)
                                /* LOCAL_IN hook doesn't have a chain!  */
                                ret = alloc_null_binding(ct, info, hooknum);
@@ -171,10 +170,10 @@ nf_nat_fn(unsigned int hooknum,
 
 static unsigned int
 nf_nat_in(unsigned int hooknum,
-          struct sk_buff **pskb,
-          const struct net_device *in,
-          const struct net_device *out,
-          int (*okfn)(struct sk_buff *))
+         struct sk_buff **pskb,
+         const struct net_device *in,
+         const struct net_device *out,
+         int (*okfn)(struct sk_buff *))
 {
        unsigned int ret;
        __be32 daddr = (*pskb)->nh.iph->daddr;
@@ -203,7 +202,7 @@ nf_nat_out(unsigned int hooknum,
 
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr) ||
-           (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
+           ip_hdrlen(*pskb) < sizeof(struct iphdr))
                return NF_ACCEPT;
 
        ret = nf_nat_fn(hooknum, pskb, in, out, okfn);
@@ -236,7 +235,7 @@ nf_nat_local_fn(unsigned int hooknum,
 
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr) ||
-           (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
+           ip_hdrlen(*pskb) < sizeof(struct iphdr))
                return NF_ACCEPT;
 
        ret = nf_nat_fn(hooknum, pskb, in, out, okfn);
@@ -245,14 +244,16 @@ nf_nat_local_fn(unsigned int hooknum,
                enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
 
                if (ct->tuplehash[dir].tuple.dst.u3.ip !=
-                   ct->tuplehash[!dir].tuple.src.u3.ip
-#ifdef CONFIG_XFRM
-                   || ct->tuplehash[dir].tuple.dst.u.all !=
-                      ct->tuplehash[!dir].tuple.src.u.all
-#endif
-                   )
+                   ct->tuplehash[!dir].tuple.src.u3.ip) {
                        if (ip_route_me_harder(pskb, RTN_UNSPEC))
                                ret = NF_DROP;
+               }
+#ifdef CONFIG_XFRM
+               else if (ct->tuplehash[dir].tuple.dst.u.all !=
+                        ct->tuplehash[!dir].tuple.src.u.all)
+                       if (ip_xfrm_me_harder(pskb))
+                               ret = NF_DROP;
+#endif
        }
        return ret;
 }
@@ -269,9 +270,9 @@ nf_nat_adjust(unsigned int hooknum,
 
        ct = nf_ct_get(*pskb, &ctinfo);
        if (ct && test_bit(IPS_SEQ_ADJUST_BIT, &ct->status)) {
-               DEBUGP("nf_nat_standalone: adjusting sequence number\n");
-               if (!nf_nat_seq_adjust(pskb, ct, ctinfo))
-                       return NF_DROP;
+               DEBUGP("nf_nat_standalone: adjusting sequence number\n");
+               if (!nf_nat_seq_adjust(pskb, ct, ctinfo))
+                       return NF_DROP;
        }
        return NF_ACCEPT;
 }