fix(faketcp): harden packet parsing against malformed frames (#2103)

Discard malformed fake TCP frames instead of panicking so OpenWrt
nodes can survive unexpected or truncated packets.

Also emit the correct IPv6 ethertype and cover the parser with
round-trip and truncation regression tests.
This commit is contained in:
fanyang
2026-04-12 13:02:23 +08:00
committed by GitHub
parent 8311b11713
commit 51befdbf87
2 changed files with 153 additions and 24 deletions
+11 -4
View File
@@ -223,8 +223,12 @@ impl Socket {
return None;
};
let (src_mac, dst_mac, _v4_packet, tcp_packet) =
parse_ip_packet(&raw_buf).unwrap();
let Some((src_mac, dst_mac, _v4_packet, tcp_packet)) =
parse_ip_packet(&raw_buf)
else {
trace!("Dropping malformed fake tcp packet for established socket");
continue;
};
tracing::trace!(
"Socket received TCP packet from {}({:?}) to {}({:?}): {:?}",
@@ -307,8 +311,11 @@ impl Socket {
info!("Waiting for client SYN + ACK timed out");
return None;
};
let (src_mac, _dst_mac, _v4_packet, tcp_packet) =
parse_ip_packet(&buf).unwrap();
let Some((src_mac, _dst_mac, _v4_packet, tcp_packet)) = parse_ip_packet(&buf)
else {
trace!("Dropping malformed fake tcp packet during handshake");
continue;
};
if (tcp_packet.get_flags() & tcp::TcpFlags::RST) != 0 {
tracing::trace!("Connection {} reset by peer", self);