aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/esp6.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-10-09 16:33:35 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:55:03 -0400
commitb7c6538cd84f8072fad43bfce530f5bf695edbba (patch)
treee0ba79ffe7b79355985a45de9961b17a0462764f /net/ipv6/esp6.c
parent050f009e16f908932070313c1745d09dc69fd62b (diff)
[IPSEC]: Move state lock into x->type->output
This patch releases the lock on the state before calling x->type->output. It also adds the lock to the spots where they're currently needed. Most of those places (all except mip6) are expected to disappear with async crypto. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/esp6.c')
-rw-r--r--net/ipv6/esp6.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 9fc19400b851..7355bb0345e2 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -34,6 +34,7 @@
34#include <linux/kernel.h> 34#include <linux/kernel.h>
35#include <linux/pfkeyv2.h> 35#include <linux/pfkeyv2.h>
36#include <linux/random.h> 36#include <linux/random.h>
37#include <linux/spinlock.h>
37#include <net/icmp.h> 38#include <net/icmp.h>
38#include <net/ipv6.h> 39#include <net/ipv6.h>
39#include <net/protocol.h> 40#include <net/protocol.h>
@@ -98,6 +99,8 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
98 esph->spi = x->id.spi; 99 esph->spi = x->id.spi;
99 esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq); 100 esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq);
100 101
102 spin_lock_bh(&x->lock);
103
101 if (esp->conf.ivlen) { 104 if (esp->conf.ivlen) {
102 if (unlikely(!esp->conf.ivinitted)) { 105 if (unlikely(!esp->conf.ivinitted)) {
103 get_random_bytes(esp->conf.ivec, esp->conf.ivlen); 106 get_random_bytes(esp->conf.ivec, esp->conf.ivlen);
@@ -112,7 +115,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
112 if (unlikely(nfrags > ESP_NUM_FAST_SG)) { 115 if (unlikely(nfrags > ESP_NUM_FAST_SG)) {
113 sg = kmalloc(sizeof(struct scatterlist)*nfrags, GFP_ATOMIC); 116 sg = kmalloc(sizeof(struct scatterlist)*nfrags, GFP_ATOMIC);
114 if (!sg) 117 if (!sg)
115 goto error; 118 goto unlock;
116 } 119 }
117 skb_to_sgvec(skb, sg, esph->enc_data+esp->conf.ivlen-skb->data, clen); 120 skb_to_sgvec(skb, sg, esph->enc_data+esp->conf.ivlen-skb->data, clen);
118 err = crypto_blkcipher_encrypt(&desc, sg, sg, clen); 121 err = crypto_blkcipher_encrypt(&desc, sg, sg, clen);
@@ -121,7 +124,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
121 } while (0); 124 } while (0);
122 125
123 if (unlikely(err)) 126 if (unlikely(err))
124 goto error; 127 goto unlock;
125 128
126 if (esp->conf.ivlen) { 129 if (esp->conf.ivlen) {
127 memcpy(esph->enc_data, esp->conf.ivec, esp->conf.ivlen); 130 memcpy(esph->enc_data, esp->conf.ivec, esp->conf.ivlen);
@@ -134,6 +137,9 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
134 memcpy(pskb_put(skb, trailer, alen), esp->auth.work_icv, alen); 137 memcpy(pskb_put(skb, trailer, alen), esp->auth.work_icv, alen);
135 } 138 }
136 139
140unlock:
141 spin_unlock_bh(&x->lock);
142
137error: 143error:
138 return err; 144 return err;
139} 145}