aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/send.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-14 05:27:19 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-15 15:45:13 +0200
commita1525bfdccc7fabf35c6c538409e4de4c4812169 (patch)
tree81427f89c2bbf51aef4cde1e873c66a509851c28 /src/send.c
parentwg-quick: account for specified fwmark in auto routing mode (diff)
downloadwireguard-monolithic-historical-a1525bfdccc7fabf35c6c538409e4de4c4812169.tar.xz
wireguard-monolithic-historical-a1525bfdccc7fabf35c6c538409e4de4c4812169.zip
send: account for route-based MTU
It might be that a particular route has a different MTU than the interface, via `ip route add ... dev wg0 mtu 1281`, for example. In this case, it's important that we don't accidently pad beyond the end of the MTU. We accomplish that in this patch by carrying forward the MTU from the dst if it exists. We also add a unit test for this issue. Reported-by: Roman Mamedov <rm.wg@romanrm.net>
Diffstat (limited to 'src/send.c')
-rw-r--r--src/send.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/send.c b/src/send.c
index dddcc0b..9c9f694 100644
--- a/src/send.c
+++ b/src/send.c
@@ -116,11 +116,11 @@ static inline unsigned int skb_padding(struct sk_buff *skb)
* isn't strictly neccessary, but it's better to be cautious here, especially
* if that code ever changes.
*/
- unsigned int last_unit = skb->len % skb->dev->mtu;
+ unsigned int last_unit = skb->len % PACKET_CB(skb)->mtu;
unsigned int padded_size = (last_unit + MESSAGE_PADDING_MULTIPLE - 1) & ~(MESSAGE_PADDING_MULTIPLE - 1);
- if (padded_size > skb->dev->mtu)
- padded_size = skb->dev->mtu;
+ if (padded_size > PACKET_CB(skb)->mtu)
+ padded_size = PACKET_CB(skb)->mtu;
return padded_size - last_unit;
}
@@ -178,6 +178,7 @@ void packet_send_keepalive(struct wireguard_peer *peer)
return;
skb_reserve(skb, DATA_PACKET_HEAD_ROOM);
skb->dev = peer->device->dev;
+ PACKET_CB(skb)->mtu = skb->dev->mtu;
skb_queue_tail(&peer->staged_packet_queue, skb);
net_dbg_ratelimited("%s: Sending keepalive packet to peer %llu (%pISpfsc)\n", peer->device->dev->name, peer->internal_id, &peer->endpoint.addr);
}