Skip to content

Commit 353e5c9

Browse files
klassertdavem330
authored andcommitted
ipv4: Fix IPsec slowpath fragmentation problem
ip_append_data() builds packets based on the mtu from dst_mtu(rt->dst.path). On IPsec the effective mtu is lower because we need to add the protocol headers and trailers later when we do the IPsec transformations. So after the IPsec transformations the packet might be too big, which leads to a slowpath fragmentation then. This patch fixes this by building the packets based on the lower IPsec mtu from dst_mtu(&rt->dst) and adapts the exthdr handling to this. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 33f99dc commit 353e5c9

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎net/ipv4/ip_output.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,6 @@ static int __ip_append_data(struct sock *sk,
802802
skb = skb_peek_tail(queue);
803803

804804
exthdrlen = !skb ? rt->dst.header_len : 0;
805-
length += exthdrlen;
806-
transhdrlen += exthdrlen;
807805
mtu = cork->fragsize;
808806

809807
hh_len = LL_RESERVED_SPACE(rt->dst.dev);
@@ -883,6 +881,8 @@ static int __ip_append_data(struct sock *sk,
883881
else
884882
alloclen = fraglen;
885883

884+
alloclen += exthdrlen;
885+
886886
/* The last fragment gets additional space at tail.
887887
* Note, with MSG_MORE we overallocate on fragments,
888888
* because we have no idea what fragment will be
@@ -923,11 +923,11 @@ static int __ip_append_data(struct sock *sk,
923923
/*
924924
* Find where to start putting bytes.
925925
*/
926-
data = skb_put(skb, fraglen);
926+
data = skb_put(skb, fraglen + exthdrlen);
927927
skb_set_network_header(skb, exthdrlen);
928928
skb->transport_header = (skb->network_header +
929929
fragheaderlen);
930-
data += fragheaderlen;
930+
data += fragheaderlen + exthdrlen;
931931

932932
if (fraggap) {
933933
skb->csum = skb_copy_and_csum_bits(
@@ -1061,7 +1061,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
10611061
*/
10621062
*rtp = NULL;
10631063
cork->fragsize = inet->pmtudisc == IP_PMTUDISC_PROBE ?
1064-
rt->dst.dev->mtu : dst_mtu(rt->dst.path);
1064+
rt->dst.dev->mtu : dst_mtu(&rt->dst);
10651065
cork->dst = &rt->dst;
10661066
cork->length = 0;
10671067
cork->tx_flags = ipc->tx_flags;

0 commit comments

Comments
 (0)