diff options
author | Benjamin Poirier <bpoirier@suse.de> | 2012-05-24 07:32:38 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-06-09 11:33:03 -0400 |
commit | 570986003b9cd61b7ccf03beacb56f5f5f6f3409 (patch) | |
tree | e324b423b52a3c7819b23c603b7064ca7f505eff | |
parent | 09c073a87938a5031b396ad63c8acdfae86fc153 (diff) |
xfrm: take net hdr len into account for esp payload size calculation
[ 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>
-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, |