mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-04 10:05:42 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user