Skip to content

Commit 7684d50

Browse files
committedSep 22, 2017
Fix an issue where TCP packets would have zero IP payload length.
1 parent 64d3063 commit 7684d50

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
 

Diff for: ‎src/socket/tcp.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,10 @@ impl<'a> TcpSocket<'a> {
756756
(ip_reply_repr, reply_repr)
757757
}
758758

759-
pub(crate) fn ack_reply(&self, ip_repr: &IpRepr, repr: &TcpRepr) ->
760-
(IpRepr, TcpRepr<'static>) {
759+
fn ack_reply(&self, ip_repr: &IpRepr, repr: &TcpRepr) -> (IpRepr, TcpRepr<'static>) {
761760
let (ip_reply_repr, mut reply_repr) = Self::reply(ip_repr, repr);
762761

763-
// From RFC793:
762+
// From RFC 793:
764763
// [...] an empty acknowledgment segment containing the current send-sequence number
765764
// and an acknowledgment indicating the next sequence number expected
766765
// to be received.
@@ -1338,6 +1337,7 @@ impl<'a> TcpSocket<'a> {
13381337
repr.max_seg_size = Some(max_segment_size as u16);
13391338
}
13401339

1340+
ip_repr.set_payload_len(repr.buffer_len());
13411341
emit((ip_repr, repr))?;
13421342

13431343
// We've sent something, whether useful data or a keep-alive packet, so rewind
@@ -1481,6 +1481,7 @@ mod test {
14811481
assert_eq!(ip_repr.protocol(), IpProtocol::Tcp);
14821482
assert_eq!(ip_repr.src_addr(), LOCAL_IP);
14831483
assert_eq!(ip_repr.dst_addr(), REMOTE_IP);
1484+
assert_eq!(ip_repr.payload_len(), tcp_repr.buffer_len());
14841485

14851486
trace!("recv: {}", tcp_repr);
14861487
Ok(f(Ok(tcp_repr)))

Diff for: ‎src/wire/ip.rs

+11
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ impl IpRepr {
237237
}
238238
}
239239

240+
/// Set the payload length.
241+
pub fn set_payload_len(&mut self, length: usize) {
242+
match self {
243+
&mut IpRepr::Unspecified { ref mut payload_len, .. } =>
244+
*payload_len = length,
245+
&mut IpRepr::Ipv4(Ipv4Repr { ref mut payload_len, .. }) =>
246+
*payload_len = length,
247+
&mut IpRepr::__Nonexhaustive => unreachable!()
248+
}
249+
}
250+
240251
/// Convert an unspecified representation into a concrete one, or return
241252
/// `Err(Error::Unaddressable)` if not possible.
242253
///

0 commit comments

Comments
 (0)
Please sign in to comment.