Skip to content

Commit 4fb8a24

Browse files
committed
Do not send TCP RST when packet handled by raw socket
1 parent c590a6a commit 4fb8a24

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/iface/interface/ipv4.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ impl InterfaceInner {
227227
}
228228

229229
#[cfg(feature = "socket-tcp")]
230-
IpProtocol::Tcp => self.process_tcp(sockets, ip_repr, ip_payload),
230+
IpProtocol::Tcp => {
231+
self.process_tcp(sockets, handled_by_raw_socket, ip_repr, ip_payload)
232+
}
231233

232234
_ if handled_by_raw_socket => None,
233235

src/iface/interface/ipv6.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ impl InterfaceInner {
342342
),
343343

344344
#[cfg(feature = "socket-tcp")]
345-
IpProtocol::Tcp => self.process_tcp(sockets, ipv6_repr.into(), ip_payload),
345+
IpProtocol::Tcp => {
346+
self.process_tcp(sockets, handled_by_raw_socket, ipv6_repr.into(), ip_payload)
347+
}
346348

347349
#[cfg(feature = "socket-raw")]
348350
_ if handled_by_raw_socket => None,

src/iface/interface/tcp.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ impl InterfaceInner {
66
pub(crate) fn process_tcp<'frame>(
77
&mut self,
88
sockets: &mut SocketSet,
9+
handled_by_raw_socket: bool,
910
ip_repr: IpRepr,
1011
ip_payload: &'frame [u8],
1112
) -> Option<Packet<'frame>> {
@@ -32,9 +33,11 @@ impl InterfaceInner {
3233
if tcp_repr.control == TcpControl::Rst
3334
|| ip_repr.dst_addr().is_unspecified()
3435
|| ip_repr.src_addr().is_unspecified()
36+
|| handled_by_raw_socket
3537
{
36-
// Never reply to a TCP RST packet with another TCP RST packet. We also never want to
37-
// send a TCP RST packet with unspecified addresses.
38+
// Never reply to a TCP RST packet with another TCP RST packet.
39+
// Never send a TCP RST packet with unspecified addresses.
40+
// Never send a TCP RST when packet has been handled by raw socket.
3841
None
3942
} else {
4043
// The packet wasn't handled by a socket, send a TCP RST packet.

src/iface/interface/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub fn tcp_not_accepted() {
187187
assert_eq!(
188188
iface.inner.process_tcp(
189189
&mut sockets,
190+
false,
190191
IpRepr::Ipv6(Ipv6Repr {
191192
src_addr: Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 2),
192193
dst_addr: Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1),
@@ -231,6 +232,7 @@ pub fn tcp_not_accepted() {
231232
assert_eq!(
232233
iface.inner.process_tcp(
233234
&mut sockets,
235+
false,
234236
IpRepr::Ipv6(Ipv6Repr {
235237
src_addr: Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 2),
236238
dst_addr: Ipv6Address::UNSPECIFIED,

0 commit comments

Comments
 (0)