xfrm: Assign the inner mode output function to the dst entry
[linux-2.6.git] / net / xfrm / xfrm_output.c
index 867484a..47bacd8 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/netdevice.h>
 #include <linux/netfilter.h>
 #include <linux/skbuff.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <net/dst.h>
 #include <net/xfrm.h>
@@ -22,43 +23,54 @@ static int xfrm_output2(struct sk_buff *skb);
 
 static int xfrm_state_check_space(struct xfrm_state *x, struct sk_buff *skb)
 {
-       struct dst_entry *dst = skb->dst;
+       struct dst_entry *dst = skb_dst(skb);
        int nhead = dst->header_len + LL_RESERVED_SPACE(dst->dev)
                - skb_headroom(skb);
+       int ntail = dst->dev->needed_tailroom - skb_tailroom(skb);
 
-       if (nhead > 0)
-               return pskb_expand_head(skb, nhead, 0, GFP_ATOMIC);
+       if (nhead <= 0) {
+               if (ntail <= 0)
+                       return 0;
+               nhead = 0;
+       } else if (ntail < 0)
+               ntail = 0;
 
-       /* Check tail too... */
-       return 0;
+       return pskb_expand_head(skb, nhead, ntail, GFP_ATOMIC);
 }
 
 static int xfrm_output_one(struct sk_buff *skb, int err)
 {
-       struct dst_entry *dst = skb->dst;
+       struct dst_entry *dst = skb_dst(skb);
        struct xfrm_state *x = dst->xfrm;
+       struct net *net = xs_net(x);
 
        if (err <= 0)
                goto resume;
 
        do {
                err = xfrm_state_check_space(x, skb);
-               if (err)
+               if (err) {
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
                        goto error_nolock;
+               }
 
                err = x->outer_mode->output(x, skb);
-               if (err)
+               if (err) {
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR);
                        goto error_nolock;
+               }
 
                spin_lock_bh(&x->lock);
                err = xfrm_state_check_expire(x);
-               if (err)
+               if (err) {
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEEXPIRED);
                        goto error;
+               }
 
-               if (x->type->flags & XFRM_TYPE_REPLAY_PROT) {
-                       XFRM_SKB_CB(skb)->seq = ++x->replay.oseq;
-                       if (xfrm_aevent_is_on())
-                               xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
+               err = x->repl->overflow(x, skb);
+               if (err) {
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATESEQERROR);
+                       goto error;
                }
 
                x->curlft.bytes += skb->len;
@@ -66,20 +78,25 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
 
                spin_unlock_bh(&x->lock);
 
+               skb_dst_force(skb);
+
                err = x->type->output(x, skb);
+               if (err == -EINPROGRESS)
+                       goto out_exit;
 
 resume:
                if (err) {
-                       XFRM_INC_STATS(LINUX_MIB_XFRMOUTSTATEPROTOERROR);
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEPROTOERROR);
                        goto error_nolock;
                }
 
-               if (!(skb->dst = dst_pop(dst))) {
-                       XFRM_INC_STATS(LINUX_MIB_XFRMOUTERROR);
+               dst = skb_dst_pop(skb);
+               if (!dst) {
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
                        err = -EHOSTUNREACH;
                        goto error_nolock;
                }
-               dst = skb->dst;
+               skb_dst_set(skb, dst);
                x = dst->xfrm;
        } while (x && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL));
 
@@ -97,21 +114,18 @@ error_nolock:
 int xfrm_output_resume(struct sk_buff *skb, int err)
 {
        while (likely((err = xfrm_output_one(skb, err)) == 0)) {
-               struct xfrm_state *x;
-
                nf_reset(skb);
 
-               err = skb->dst->ops->local_out(skb);
+               err = skb_dst(skb)->ops->local_out(skb);
                if (unlikely(err != 1))
                        goto out;
 
-               x = skb->dst->xfrm;
-               if (!x)
+               if (!skb_dst(skb)->xfrm)
                        return dst_output(skb);
 
-               err = nf_hook(x->inner_mode->afinfo->family,
+               err = nf_hook(skb_dst(skb)->ops->family,
                              NF_INET_POST_ROUTING, skb,
-                             NULL, skb->dst->dev, xfrm_output2);
+                             NULL, skb_dst(skb)->dev, xfrm_output2);
                if (unlikely(err != 1))
                        goto out;
        }
@@ -135,7 +149,7 @@ static int xfrm_output_gso(struct sk_buff *skb)
 
        segs = skb_gso_segment(skb, 0);
        kfree_skb(skb);
-       if (unlikely(IS_ERR(segs)))
+       if (IS_ERR(segs))
                return PTR_ERR(segs);
 
        do {
@@ -162,6 +176,7 @@ static int xfrm_output_gso(struct sk_buff *skb)
 
 int xfrm_output(struct sk_buff *skb)
 {
+       struct net *net = dev_net(skb_dst(skb)->dev);
        int err;
 
        if (skb_is_gso(skb))
@@ -170,7 +185,7 @@ int xfrm_output(struct sk_buff *skb)
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
                err = skb_checksum_help(skb);
                if (err) {
-                       XFRM_INC_STATS(LINUX_MIB_XFRMOUTERROR);
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
                        kfree_skb(skb);
                        return err;
                }
@@ -178,4 +193,20 @@ int xfrm_output(struct sk_buff *skb)
 
        return xfrm_output2(skb);
 }
+
+int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)
+{
+       struct xfrm_mode *inner_mode;
+       if (x->sel.family == AF_UNSPEC)
+               inner_mode = xfrm_ip2inner_mode(x,
+                               xfrm_af2proto(skb_dst(skb)->ops->family));
+       else
+               inner_mode = x->inner_mode;
+
+       if (inner_mode == NULL)
+               return -EAFNOSUPPORT;
+       return inner_mode->afinfo->extract_output(x, skb);
+}
+
 EXPORT_SYMBOL_GPL(xfrm_output);
+EXPORT_SYMBOL_GPL(xfrm_inner_extract_output);