Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 224969
b: refs/heads/master
c: d979e20
h: refs/heads/master
i:
  224967: 7fc4e82
v: v3
  • Loading branch information
Martin Willi authored and David S. Miller committed Dec 10, 2010
1 parent 9d13a26 commit 1ed71e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 35d2856b4693e8de5d616307b56cef296b839157
refs/heads/master: d979e20f2b9f8a50c8d5f889e0b5d78580440d1f
32 changes: 24 additions & 8 deletions trunk/net/ipv4/esp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct esp_skb_cb {

#define ESP_SKB_CB(__skb) ((struct esp_skb_cb *)&((__skb)->cb[0]))

static u32 esp4_get_mtu(struct xfrm_state *x, int mtu);

/*
* Allocate an AEAD request structure with extra space for SG and IV.
*
Expand Down Expand Up @@ -117,25 +119,35 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
int blksize;
int clen;
int alen;
int plen;
int tfclen;
int nfrags;

/* skb is pure payload to encrypt */

err = -ENOMEM;

/* Round to block size */
clen = skb->len;

esp = x->data;
aead = esp->aead;
alen = crypto_aead_authsize(aead);

tfclen = 0;
if (x->tfcpad) {
struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst(skb);
u32 padto;

padto = min(x->tfcpad, esp4_get_mtu(x, dst->child_mtu_cached));
if (skb->len < padto)
tfclen = padto - skb->len;
}
blksize = ALIGN(crypto_aead_blocksize(aead), 4);
clen = ALIGN(clen + 2, blksize);
clen = ALIGN(skb->len + 2 + tfclen, blksize);
if (esp->padlen)
clen = ALIGN(clen, esp->padlen);
plen = clen - skb->len - tfclen;

if ((err = skb_cow_data(skb, clen - skb->len + alen, &trailer)) < 0)
err = skb_cow_data(skb, tfclen + plen + alen, &trailer);
if (err < 0)
goto error;
nfrags = err;

Expand All @@ -150,13 +162,17 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)

/* Fill padding... */
tail = skb_tail_pointer(trailer);
if (tfclen) {
memset(tail, 0, tfclen);
tail += tfclen;
}
do {
int i;
for (i=0; i<clen-skb->len - 2; i++)
for (i = 0; i < plen - 2; i++)
tail[i] = i + 1;
} while (0);
tail[clen - skb->len - 2] = (clen - skb->len) - 2;
tail[clen - skb->len - 1] = *skb_mac_header(skb);
tail[plen - 2] = plen - 2;
tail[plen - 1] = *skb_mac_header(skb);
pskb_put(skb, trailer, clen - skb->len + alen);

skb_push(skb, -skb_network_offset(skb));
Expand Down

0 comments on commit 1ed71e5

Please sign in to comment.