Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes unused MTU settings at TcpSocket dispatch #384

Merged
merged 2 commits into from
Oct 25, 2020

Conversation

mustermeiszer
Copy link

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.

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.
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is correct. MTU is IP packet size (IP header + TCP header + payload). size here is only payload size.

You have to subtract the IP and TCP header sizes, as in here :

let mut max_segment_size = caps.max_transmission_unit;

Copy link
Author

@mustermeiszer mustermeiszer Oct 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so much for a quick fix on my part. Haha.

Is this fine?

let size = cmp::min(cmp::min(self.remote_win_len, self.remote_mss),
                     caps.max_transmission_unit - ip_repr.buffer_len() - repr.mss_header_len());
repr.payload = self.tx_buffer.get_allocated(offset, size);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

The MTU consists of TCP header, IP header and the payload.
In the former fix, this was not taken into account.
@whitequark whitequark merged commit f25a531 into smoltcp-rs:master Oct 25, 2020
@whitequark
Copy link
Contributor

Thanks @mustermeiszer for the fix and @Dirbaio for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants