From b933bc361fb5dc4590871d11382b06c238660c9f Mon Sep 17 00:00:00 2001 From: mustermeiszer Date: Fri, 23 Oct 2020 14:12:20 +0200 Subject: [PATCH 1/2] Fixes unused MTU settings at TcpSocket dispatch This commit fixes a small bug, where the TcpSocket computed the maximum size per payload in a tx_buffer without taking into account the MTU defined by the underlying network device. --- src/socket/tcp.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 8cdbf2123..b6f6bef0c 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -1558,7 +1558,8 @@ impl<'a> TcpSocket<'a> { // Extract as much data as the remote side can receive in this packet // from the transmit buffer. let offset = self.remote_last_seq - self.local_seq_no; - let size = cmp::min(self.remote_win_len, self.remote_mss); + let size = cmp::min(cmp::min(self.remote_win_len, self.remote_mss), + caps.max_transmission_unit); repr.payload = self.tx_buffer.get_allocated(offset, size); // If we've sent everything we had in the buffer, follow it with the PSH or FIN // flags, depending on whether the transmit half of the connection is open. From b7678619980d0179fd8cc5de92ab4d2ff868bd9c Mon Sep 17 00:00:00 2001 From: mustermeiszer Date: Fri, 23 Oct 2020 15:13:18 +0200 Subject: [PATCH 2/2] Taking into account TCP and IP header The MTU consists of TCP header, IP header and the payload. In the former fix, this was not taken into account. --- src/socket/tcp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index b6f6bef0c..b4a5f6692 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -1559,7 +1559,7 @@ impl<'a> TcpSocket<'a> { // from the transmit buffer. let offset = self.remote_last_seq - self.local_seq_no; let size = cmp::min(cmp::min(self.remote_win_len, self.remote_mss), - caps.max_transmission_unit); + caps.max_transmission_unit - ip_repr.buffer_len() - repr.mss_header_len()); repr.payload = self.tx_buffer.get_allocated(offset, size); // If we've sent everything we had in the buffer, follow it with the PSH or FIN // flags, depending on whether the transmit half of the connection is open.