]> err.no Git - linux-2.6/blobdiff - net/ipv4/ipcomp.c
Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-backlight
[linux-2.6] / net / ipv4 / ipcomp.c
index 32b02deca2ecbe7ac921b81087f1cdd173754a84..a75807b971b3e1b452d6b272ab3b8077afebd4d1 100644 (file)
@@ -14,9 +14,8 @@
  *   - Adaptive compression.
  */
 #include <linux/module.h>
-#include <asm/scatterlist.h>
-#include <asm/semaphore.h>
 #include <linux/crypto.h>
+#include <linux/err.h>
 #include <linux/pfkeyv2.h>
 #include <linux/percpu.h>
 #include <linux/smp.h>
@@ -74,8 +73,8 @@ out:
 
 static int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)
 {
+       int nexthdr;
        int err = -ENOMEM;
-       struct iphdr *iph;
        struct ip_comp_hdr *ipch;
 
        if (skb_linearize_cow(skb))
@@ -84,12 +83,16 @@ static int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)
        skb->ip_summed = CHECKSUM_NONE;
 
        /* Remove ipcomp header and decompress original payload */
-       iph = ip_hdr(skb);
        ipch = (void *)skb->data;
-       iph->protocol = ipch->nexthdr;
+       nexthdr = ipch->nexthdr;
+
        skb->transport_header = skb->network_header + sizeof(*ipch);
        __skb_pull(skb, sizeof(*ipch));
        err = ipcomp_decompress(x, skb);
+       if (err)
+               goto out;
+
+       err = nexthdr;
 
 out:
        return err;
@@ -104,8 +107,11 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
        const int cpu = get_cpu();
        u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
        struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
-       int err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
+       int err;
 
+       local_bh_disable();
+       err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
+       local_bh_enable();
        if (err)
                goto out;
 
@@ -172,7 +178,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
                              spi, IPPROTO_COMP, AF_INET);
        if (!x)
                return;
-       NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%u.%u.%u.%u\n",
+       NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/" NIPQUAD_FMT "\n",
                 spi, NIPQUAD(iph->daddr));
        xfrm_state_put(x);
 }
@@ -181,7 +187,6 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
 static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
 {
        struct xfrm_state *t;
-       u8 mode = XFRM_MODE_TUNNEL;
 
        t = xfrm_state_alloc();
        if (t == NULL)
@@ -192,9 +197,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
        t->id.daddr.a4 = x->id.daddr.a4;
        memcpy(&t->sel, &x->sel, sizeof(t->sel));
        t->props.family = AF_INET;
-       if (x->props.mode == XFRM_MODE_BEET)
-               mode = x->props.mode;
-       t->props.mode = mode;
+       t->props.mode = x->props.mode;
        t->props.saddr.a4 = x->props.saddr.a4;
        t->props.flags = x->props.flags;
 
@@ -344,7 +347,7 @@ static struct crypto_comp **ipcomp_alloc_tfms(const char *alg_name)
        for_each_possible_cpu(cpu) {
                struct crypto_comp *tfm = crypto_alloc_comp(alg_name, 0,
                                                            CRYPTO_ALG_ASYNC);
-               if (!tfm)
+               if (IS_ERR(tfm))
                        goto error;
                *per_cpu_ptr(tfms, cpu) = tfm;
        }
@@ -388,15 +391,22 @@ static int ipcomp_init_state(struct xfrm_state *x)
        if (x->encap)
                goto out;
 
+       x->props.header_len = 0;
+       switch (x->props.mode) {
+       case XFRM_MODE_TRANSPORT:
+               break;
+       case XFRM_MODE_TUNNEL:
+               x->props.header_len += sizeof(struct iphdr);
+               break;
+       default:
+               goto out;
+       }
+
        err = -ENOMEM;
        ipcd = kzalloc(sizeof(*ipcd), GFP_KERNEL);
        if (!ipcd)
                goto out;
 
-       x->props.header_len = 0;
-       if (x->props.mode == XFRM_MODE_TUNNEL)
-               x->props.header_len += sizeof(struct iphdr);
-
        mutex_lock(&ipcomp_resource_mutex);
        if (!ipcomp_alloc_scratches())
                goto error;
@@ -429,7 +439,7 @@ error:
        goto out;
 }
 
-static struct xfrm_type ipcomp_type = {
+static const struct xfrm_type ipcomp_type = {
        .description    = "IPCOMP4",
        .owner          = THIS_MODULE,
        .proto          = IPPROTO_COMP,