]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv4/ipcomp.c
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/linville/wireles...
[linux-2.6-omap-h63xx.git] / net / ipv4 / ipcomp.c
index e787044a85148ebceaafdbb964c7dd15c2e99daa..58b60b2fb01175fb4c02fb72598619dfb38df716 100644 (file)
@@ -14,9 +14,9 @@
  *   - 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 +74,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 +84,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;
@@ -98,15 +102,17 @@ out:
 static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
 {
        struct ipcomp_data *ipcd = x->data;
-       const int ihlen = ip_hdrlen(skb);
-       const int plen = skb->len - ihlen;
+       const int plen = skb->len;
        int dlen = IPCOMP_SCRATCH_SIZE;
-       u8 *start = skb->data + ihlen;
+       u8 *start = skb->data;
        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;
 
@@ -118,7 +124,7 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
        memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
        put_cpu();
 
-       pskb_trim(skb, ihlen + dlen + sizeof(struct ip_comp_hdr));
+       pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
        return 0;
 
 out:
@@ -131,12 +137,8 @@ static int ipcomp_output(struct xfrm_state *x, struct sk_buff *skb)
        int err;
        struct ip_comp_hdr *ipch;
        struct ipcomp_data *ipcd = x->data;
-       int hdr_len = 0;
-       struct iphdr *iph = ip_hdr(skb);
 
-       iph->tot_len = htons(skb->len);
-       hdr_len = iph->ihl * 4;
-       if ((skb->len - hdr_len) < ipcd->threshold) {
+       if (skb->len < ipcd->threshold) {
                /* Don't bother compressing */
                goto out_ok;
        }
@@ -145,25 +147,19 @@ static int ipcomp_output(struct xfrm_state *x, struct sk_buff *skb)
                goto out_ok;
 
        err = ipcomp_compress(x, skb);
-       iph = ip_hdr(skb);
 
        if (err) {
                goto out_ok;
        }
 
        /* Install ipcomp header, convert into ipcomp datagram. */
-       iph->tot_len = htons(skb->len);
-       ipch = (struct ip_comp_hdr *)((char *)iph + iph->ihl * 4);
-       ipch->nexthdr = iph->protocol;
+       ipch = ip_comp_hdr(skb);
+       ipch->nexthdr = *skb_mac_header(skb);
        ipch->flags = 0;
        ipch->cpi = htons((u16 )ntohl(x->id.spi));
-       iph->protocol = IPPROTO_COMP;
-       ip_send_check(iph);
-       return 0;
-
+       *skb_mac_header(skb) = IPPROTO_COMP;
 out_ok:
-       if (x->props.mode == XFRM_MODE_TUNNEL)
-               ip_send_check(iph);
+       skb_push(skb, -skb_network_offset(skb));
        return 0;
 }
 
@@ -192,7 +188,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)
@@ -203,9 +198,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;
 
@@ -355,7 +348,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;
        }
@@ -399,15 +392,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;
@@ -440,7 +440,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,