]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[IPSEC]: Move integrity stat collection into xfrm_input
authorHerbert Xu <herbert@gondor.apana.org.au>
Sun, 16 Dec 2007 23:55:02 +0000 (15:55 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 22:53:51 +0000 (14:53 -0800)
Similar to the moving out of the replay processing on the output, this
patch moves the integrity stat collectin from x->type->input into
xfrm_input.

This would eventually allow transforms such as AH/ESP to be lockless.

The error value EBADMSG (currently unused in the crypto layer) is used
to indicate a failed integrity check.  In future this error can be
directly returned by the crypto layer once we switch to aead
algorithms.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ah4.c
net/ipv4/esp4.c
net/ipv6/ah6.c
net/ipv6/esp6.c
net/xfrm/xfrm_input.c

index 5fc346d8b5665a344f80a8b82e6c2013b9dd549f..a989d29b44ead664be1a97148bd81515e474370c 100644 (file)
@@ -177,9 +177,8 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
                err = ah_mac_digest(ahp, skb, ah->auth_data);
                if (err)
                        goto out;
-               err = -EINVAL;
                if (memcmp(ahp->work_icv, auth_data, ahp->icv_trunc_len)) {
-                       x->stats.integrity_failed++;
+                       err = -EBADMSG;
                        goto out;
                }
        }
index 1738113268bc12f1e1a23e4a1ca14bb82a637ffa..3350a7d506699897811f0e76a45dd78ddedd2d41 100644 (file)
@@ -163,7 +163,7 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
        u8 nexthdr[2];
        struct scatterlist *sg;
        int padlen;
-       int err;
+       int err = -EINVAL;
 
        if (!pskb_may_pull(skb, sizeof(*esph)))
                goto out;
@@ -183,13 +183,14 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
                        BUG();
 
                if (unlikely(memcmp(esp->auth.work_icv, sum, alen))) {
-                       x->stats.integrity_failed++;
+                       err = -EBADMSG;
                        goto out;
                }
        }
 
-       if ((nfrags = skb_cow_data(skb, 0, &trailer)) < 0)
+       if ((err = skb_cow_data(skb, 0, &trailer)) < 0)
                goto out;
+       nfrags = err;
 
        skb->ip_summed = CHECKSUM_NONE;
 
@@ -202,6 +203,7 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
        sg = &esp->sgbuf[0];
 
        if (unlikely(nfrags > ESP_NUM_FAST_SG)) {
+               err = -ENOMEM;
                sg = kmalloc(sizeof(struct scatterlist)*nfrags, GFP_ATOMIC);
                if (!sg)
                        goto out;
@@ -214,11 +216,12 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
        if (unlikely(sg != &esp->sgbuf[0]))
                kfree(sg);
        if (unlikely(err))
-               return err;
+               goto out;
 
        if (skb_copy_bits(skb, skb->len-alen-2, nexthdr, 2))
                BUG();
 
+       err = -EINVAL;
        padlen = nexthdr[0];
        if (padlen+2 >= elen)
                goto out;
@@ -276,7 +279,7 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
        return nexthdr[1];
 
 out:
-       return -EINVAL;
+       return err;
 }
 
 static u32 esp4_get_mtu(struct xfrm_state *x, int mtu)
index 4eaf55072b1b05ff7c52537acb01eead7bd761f4..d4b59ecb0b57853b6ad03598c7f0768c0a0e9400 100644 (file)
@@ -379,10 +379,9 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
                err = ah_mac_digest(ahp, skb, ah->auth_data);
                if (err)
                        goto free_out;
-               err = -EINVAL;
                if (memcmp(ahp->work_icv, auth_data, ahp->icv_trunc_len)) {
                        LIMIT_NETDEBUG(KERN_WARNING "ipsec ah authentication error\n");
-                       x->stats.integrity_failed++;
+                       err = -EBADMSG;
                        goto free_out;
                }
        }
index 44405325467626a5ca473ef647872ec8cdb14753..096974ba642084c99360a15a27b5934e3c806b34 100644 (file)
@@ -177,8 +177,7 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
                        BUG();
 
                if (unlikely(memcmp(esp->auth.work_icv, sum, alen))) {
-                       x->stats.integrity_failed++;
-                       ret = -EINVAL;
+                       ret = -EBADMSG;
                        goto out;
                }
        }
index 587f3474ed3d13ce227c8c0dfca102710a322b7a..b7d68eb9434cdc663af43bc940f58eb49d0ba306 100644 (file)
@@ -147,8 +147,11 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
                        goto drop_unlock;
 
                nexthdr = x->type->input(x, skb);
-               if (nexthdr <= 0)
+               if (nexthdr <= 0) {
+                       if (nexthdr == -EBADMSG)
+                               x->stats.integrity_failed++;
                        goto drop_unlock;
+               }
 
                skb_network_header(skb)[nhoff] = nexthdr;