提交 eb758c88 编写于 作者: S Steffen Klassert

esp: Introduce a helper to setup the trailer

We need to setup the trailer in two different cases,
so add a helper to avoid code duplication.
Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
上级 03e2a30f
...@@ -182,6 +182,22 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err) ...@@ -182,6 +182,22 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err)
esp_output_done(base, err); esp_output_done(base, err);
} }
static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
{
/* Fill padding... */
if (tfclen) {
memset(tail, 0, tfclen);
tail += tfclen;
}
do {
int i;
for (i = 0; i < plen - 2; i++)
tail[i] = i + 1;
} while (0);
tail[plen - 2] = plen - 2;
tail[plen - 1] = proto;
}
static int esp_output(struct xfrm_state *x, struct sk_buff *skb) static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
{ {
struct esp_output_extra *extra; struct esp_output_extra *extra;
...@@ -304,18 +320,7 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -304,18 +320,7 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
tail = vaddr + pfrag->offset; tail = vaddr + pfrag->offset;
/* Fill padding... */ esp_output_fill_trailer(tail, tfclen, plen, proto);
if (tfclen) {
memset(tail, 0, tfclen);
tail += tfclen;
}
do {
int i;
for (i = 0; i < plen - 2; i++)
tail[i] = i + 1;
} while (0);
tail[plen - 2] = plen - 2;
tail[plen - 1] = proto;
kunmap_atomic(vaddr); kunmap_atomic(vaddr);
...@@ -395,20 +400,9 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -395,20 +400,9 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
esph = ip_esp_hdr(skb); esph = ip_esp_hdr(skb);
skip_cow: skip_cow:
/* Fill padding... */ esp_output_fill_trailer(tail, tfclen, plen, proto);
if (tfclen) {
memset(tail, 0, tfclen);
tail += tfclen;
}
do {
int i;
for (i = 0; i < plen - 2; i++)
tail[i] = i + 1;
} while (0);
tail[plen - 2] = plen - 2;
tail[plen - 1] = proto;
pskb_put(skb, trailer, clen - skb->len + alen);
pskb_put(skb, trailer, clen - skb->len + alen);
skb_push(skb, -skb_network_offset(skb)); skb_push(skb, -skb_network_offset(skb));
esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low); esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low);
esph->spi = x->id.spi; esph->spi = x->id.spi;
......
...@@ -198,6 +198,22 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err) ...@@ -198,6 +198,22 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err)
esp_output_done(base, err); esp_output_done(base, err);
} }
static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
{
/* Fill padding... */
if (tfclen) {
memset(tail, 0, tfclen);
tail += tfclen;
}
do {
int i;
for (i = 0; i < plen - 2; i++)
tail[i] = i + 1;
} while (0);
tail[plen - 2] = plen - 2;
tail[plen - 1] = proto;
}
static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
{ {
int err; int err;
...@@ -284,18 +300,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -284,18 +300,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
tail = vaddr + pfrag->offset; tail = vaddr + pfrag->offset;
/* Fill padding... */ esp_output_fill_trailer(tail, tfclen, plen, proto);
if (tfclen) {
memset(tail, 0, tfclen);
tail += tfclen;
}
do {
int i;
for (i = 0; i < plen - 2; i++)
tail[i] = i + 1;
} while (0);
tail[plen - 2] = plen - 2;
tail[plen - 1] = proto;
kunmap_atomic(vaddr); kunmap_atomic(vaddr);
...@@ -375,20 +380,9 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -375,20 +380,9 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
esph = ip_esp_hdr(skb); esph = ip_esp_hdr(skb);
skip_cow: skip_cow:
/* Fill padding... */ esp_output_fill_trailer(tail, tfclen, plen, proto);
if (tfclen) {
memset(tail, 0, tfclen);
tail += tfclen;
}
do {
int i;
for (i = 0; i < plen - 2; i++)
tail[i] = i + 1;
} while (0);
tail[plen - 2] = plen - 2;
tail[plen - 1] = proto;
pskb_put(skb, trailer, clen - skb->len + alen);
pskb_put(skb, trailer, clen - skb->len + alen);
skb_push(skb, -skb_network_offset(skb)); skb_push(skb, -skb_network_offset(skb));
esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low); esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册