Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / net / ipv4 / xfrm4_output.c
index 21832df..4ef8efa 100644 (file)
@@ -8,8 +8,10 @@
  * 2 of the License, or (at your option) any later version.
  */
 
+#include <linux/compiler.h>
 #include <linux/skbuff.h>
 #include <linux/spinlock.h>
+#include <linux/netfilter_ipv4.h>
 #include <net/inet_ecn.h>
 #include <net/ip.h>
 #include <net/xfrm.h>
@@ -33,6 +35,7 @@ static void xfrm4_encap(struct sk_buff *skb)
        struct dst_entry *dst = skb->dst;
        struct xfrm_state *x = dst->xfrm;
        struct iphdr *iph, *top_iph;
+       int flags;
 
        iph = skb->nh.iph;
        skb->h.ipiph = iph;
@@ -51,14 +54,17 @@ static void xfrm4_encap(struct sk_buff *skb)
 
        /* DS disclosed */
        top_iph->tos = INET_ECN_encapsulate(iph->tos, iph->tos);
-       if (x->props.flags & XFRM_STATE_NOECN)
+
+       flags = x->props.flags;
+       if (flags & XFRM_STATE_NOECN)
                IP_ECN_clear(top_iph);
 
-       top_iph->frag_off = iph->frag_off & htons(IP_DF);
+       top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
+               0 : (iph->frag_off & htons(IP_DF));
        if (!top_iph->frag_off)
-               __ip_select_ident(top_iph, dst, 0);
+               __ip_select_ident(top_iph, dst->child, 0);
 
-       top_iph->ttl = dst_path_metric(dst, RTAX_HOPLIMIT);
+       top_iph->ttl = dst_metric(dst->child, RTAX_HOPLIMIT);
 
        top_iph->saddr = x->props.saddr.a4;
        top_iph->daddr = x->id.daddr.a4;
@@ -78,11 +84,11 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb)
 
        IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
        
-       if (!(iph->frag_off & htons(IP_DF)))
+       if (!(iph->frag_off & htons(IP_DF)) || skb->local_df)
                goto out;
 
        dst = skb->dst;
-       mtu = dst_pmtu(dst) - dst->header_len - dst->trailer_len;
+       mtu = dst_mtu(dst);
        if (skb->len > mtu) {
                icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
                ret = -EMSGSIZE;
@@ -91,47 +97,51 @@ out:
        return ret;
 }
 
-int xfrm4_output(struct sk_buff **pskb)
+static int xfrm4_output_one(struct sk_buff *skb)
 {
-       struct sk_buff *skb = *pskb;
        struct dst_entry *dst = skb->dst;
        struct xfrm_state *x = dst->xfrm;
        int err;
        
        if (skb->ip_summed == CHECKSUM_HW) {
-               err = skb_checksum_help(pskb, 0);
-               skb = *pskb;
+               err = skb_checksum_help(skb, 0);
                if (err)
                        goto error_nolock;
        }
 
-       spin_lock_bh(&x->lock);
-       err = xfrm_state_check(x, skb);
-       if (err)
-               goto error;
-
        if (x->props.mode) {
                err = xfrm4_tunnel_check_size(skb);
                if (err)
-                       goto error;
+                       goto error_nolock;
        }
 
-       xfrm4_encap(skb);
+       do {
+               spin_lock_bh(&x->lock);
+               err = xfrm_state_check(x, skb);
+               if (err)
+                       goto error;
 
-       err = x->type->output(skb);
-       if (err)
-               goto error;
+               xfrm4_encap(skb);
 
-       x->curlft.bytes += skb->len;
-       x->curlft.packets++;
+               err = x->type->output(x, skb);
+               if (err)
+                       goto error;
 
-       spin_unlock_bh(&x->lock);
+               x->curlft.bytes += skb->len;
+               x->curlft.packets++;
+
+               spin_unlock_bh(&x->lock);
        
-       if (!(skb->dst = dst_pop(dst))) {
-               err = -EHOSTUNREACH;
-               goto error_nolock;
-       }
-       err = NET_XMIT_BYPASS;
+               if (!(skb->dst = dst_pop(dst))) {
+                       err = -EHOSTUNREACH;
+                       goto error_nolock;
+               }
+               dst = skb->dst;
+               x = dst->xfrm;
+       } while (x && !x->props.mode);
+
+       IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
+       err = 0;
 
 out_exit:
        return err;
@@ -141,3 +151,40 @@ error_nolock:
        kfree_skb(skb);
        goto out_exit;
 }
+
+static int xfrm4_output_finish(struct sk_buff *skb)
+{
+       int err;
+
+#ifdef CONFIG_NETFILTER
+       if (!skb->dst->xfrm) {
+               IPCB(skb)->flags |= IPSKB_REROUTED;
+               return dst_output(skb);
+       }
+#endif
+       while (likely((err = xfrm4_output_one(skb)) == 0)) {
+               nf_reset(skb);
+
+               err = nf_hook(PF_INET, NF_IP_LOCAL_OUT, &skb, NULL,
+                             skb->dst->dev, dst_output);
+               if (unlikely(err != 1))
+                       break;
+
+               if (!skb->dst->xfrm)
+                       return dst_output(skb);
+
+               err = nf_hook(PF_INET, NF_IP_POST_ROUTING, &skb, NULL,
+                             skb->dst->dev, xfrm4_output_finish);
+               if (unlikely(err != 1))
+                       break;
+       }
+
+       return err;
+}
+
+int xfrm4_output(struct sk_buff *skb)
+{
+       return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, skb->dst->dev,
+                           xfrm4_output_finish,
+                           !(IPCB(skb)->flags & IPSKB_REROUTED));
+}