diff options
| author | Benjamin Poirier <bpoirier@suse.de> | 2012-05-24 07:32:38 -0400 |
|---|---|---|
| committer | Luis Henriques <luis.henriques@canonical.com> | 2012-07-03 11:29:04 -0400 |
| commit | 29c11f715b98262eda3cfd73e502c59dbb3c3429 (patch) | |
| tree | 66a66b7f0cb6d2de38ead4de39d0cf9d7d9b7e83 | |
| parent | 4d8a92cfcca611cd321531cbee3b3d850d794097 (diff) | |
xfrm: take net hdr len into account for esp payload size calculation
BugLink: http://bugs.launchpad.net/bugs/1013748
[ Upstream commit 91657eafb64b4cb53ec3a2fbc4afc3497f735788 ]
Corrects the function that determines the esp payload size. The calculations
done in esp{4,6}_get_mtu() lead to overlength frames in transport mode for
certain mtu values and suboptimal frames for others.
According to what is done, mainly in esp{,6}_output() and tcp_mtu_to_mss(),
net_header_len must be taken into account before doing the alignment
calculation.
Signed-off-by: Benjamin Poirier <bpoirier@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Herton Ronaldo Krzesinski <herton.krzesinski@canonical.com>
| -rw-r--r-- | net/ipv4/esp4.c | 24 | ||||
| -rw-r--r-- | net/ipv6/esp6.c | 18 |
2 files changed, 16 insertions, 26 deletions
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index a5b413416da..530787bc199 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c | |||
| @@ -457,28 +457,22 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu) | |||
| 457 | struct esp_data *esp = x->data; | 457 | struct esp_data *esp = x->data; |
| 458 | u32 blksize = ALIGN(crypto_aead_blocksize(esp->aead), 4); | 458 | u32 blksize = ALIGN(crypto_aead_blocksize(esp->aead), 4); |
| 459 | u32 align = max_t(u32, blksize, esp->padlen); | 459 | u32 align = max_t(u32, blksize, esp->padlen); |
| 460 | u32 rem; | 460 | unsigned int net_adj; |
| 461 | |||
| 462 | mtu -= x->props.header_len + crypto_aead_authsize(esp->aead); | ||
| 463 | rem = mtu & (align - 1); | ||
| 464 | mtu &= ~(align - 1); | ||
| 465 | 461 | ||
| 466 | switch (x->props.mode) { | 462 | switch (x->props.mode) { |
| 467 | case XFRM_MODE_TUNNEL: | ||
| 468 | break; | ||
| 469 | default: | ||
| 470 | case XFRM_MODE_TRANSPORT: | 463 | case XFRM_MODE_TRANSPORT: |
| 471 | /* The worst case */ | ||
| 472 | mtu -= blksize - 4; | ||
| 473 | mtu += min_t(u32, blksize - 4, rem); | ||
| 474 | break; | ||
| 475 | case XFRM_MODE_BEET: | 464 | case XFRM_MODE_BEET: |
| 476 | /* The worst case. */ | 465 | net_adj = sizeof(struct iphdr); |
| 477 | mtu += min_t(u32, IPV4_BEET_PHMAXLEN, rem); | ||
| 478 | break; | 466 | break; |
| 467 | case XFRM_MODE_TUNNEL: | ||
| 468 | net_adj = 0; | ||
| 469 | break; | ||
| 470 | default: | ||
| 471 | BUG(); | ||
| 479 | } | 472 | } |
| 480 | 473 | ||
| 481 | return mtu - 2; | 474 | return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) - |
| 475 | net_adj) & ~(align - 1)) + (net_adj - 2); | ||
| 482 | } | 476 | } |
| 483 | 477 | ||
| 484 | static void esp4_err(struct sk_buff *skb, u32 info) | 478 | static void esp4_err(struct sk_buff *skb, u32 info) |
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 1ac7938dd9e..65dd5433f08 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c | |||
| @@ -411,19 +411,15 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu) | |||
| 411 | struct esp_data *esp = x->data; | 411 | struct esp_data *esp = x->data; |
| 412 | u32 blksize = ALIGN(crypto_aead_blocksize(esp->aead), 4); | 412 | u32 blksize = ALIGN(crypto_aead_blocksize(esp->aead), 4); |
| 413 | u32 align = max_t(u32, blksize, esp->padlen); | 413 | u32 align = max_t(u32, blksize, esp->padlen); |
| 414 | u32 rem; | 414 | unsigned int net_adj; |
| 415 | 415 | ||
| 416 | mtu -= x->props.header_len + crypto_aead_authsize(esp->aead); | 416 | if (x->props.mode != XFRM_MODE_TUNNEL) |
| 417 | rem = mtu & (align - 1); | 417 | net_adj = sizeof(struct ipv6hdr); |
| 418 | mtu &= ~(align - 1); | 418 | else |
| 419 | 419 | net_adj = 0; | |
| 420 | if (x->props.mode != XFRM_MODE_TUNNEL) { | ||
| 421 | u32 padsize = ((blksize - 1) & 7) + 1; | ||
| 422 | mtu -= blksize - padsize; | ||
| 423 | mtu += min_t(u32, blksize - padsize, rem); | ||
| 424 | } | ||
| 425 | 420 | ||
| 426 | return mtu - 2; | 421 | return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) - |
| 422 | net_adj) & ~(align - 1)) + (net_adj - 2); | ||
| 427 | } | 423 | } |
| 428 | 424 | ||
| 429 | static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | 425 | static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, |
