chore(connlib): discard packets from smoltcp if > MTU (#7262)

This should really never happen but is a defense in depth measure to
ensure we never attempt to send packets through the tunnel that are
larger than our interface MTU.

Raising a warning will alert us through Sentry in case this does happen.

---------

Signed-off-by: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
Thomas Eizinger
2024-11-05 15:18:14 +11:00
committed by GitHub
parent 271c480357
commit 9782c7689f

View File

@@ -61,6 +61,15 @@ impl<'a> smoltcp::phy::TxToken for SmolTxToken<'a> {
where
F: FnOnce(&mut [u8]) -> R,
{
let max_len = ip_packet::PACKET_SIZE;
if len > max_len {
tracing::warn!("Packets larger than {max_len} are not supported; len={len}");
let mut buf = Vec::with_capacity(len);
return f(&mut buf);
}
let mut ip_packet_buf = IpPacketBuf::new();
let result = f(ip_packet_buf.buf());