Skip to content

Commit 13f249d

Browse files
authored
Merge pull request #707 from SquidDev/backport-0.8
Backport several fixes to 0.8
2 parents 72b9021 + e51e750 commit 13f249d

File tree

2 files changed

+115
-5
lines changed

2 files changed

+115
-5
lines changed

src/socket/dhcpv4.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,6 @@ mod test {
635635
macro_rules! send {
636636
($socket:ident, $repr:expr) =>
637637
(send!($socket, time 0, $repr));
638-
($socket:ident, $repr:expr, $result:expr) =>
639-
(send!($socket, time 0, $repr, $result));
640638
($socket:ident, time $time:expr, $repr:expr) =>
641639
(send!($socket, time $time, $repr, Ok(( ))));
642640
($socket:ident, time $time:expr, $repr:expr, $result:expr) =>

src/socket/tcp.rs

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ impl<'a> TcpSocket<'a> {
14931493
// from the sequence space.
14941494
let mut ack_len = 0;
14951495
let mut ack_of_fin = false;
1496+
let mut ack_all = false;
14961497
if repr.control != TcpControl::Rst {
14971498
if let Some(ack_number) = repr.ack_number {
14981499
// Sequence number corresponding to the first byte in `tx_buffer`.
@@ -1514,6 +1515,8 @@ impl<'a> TcpSocket<'a> {
15141515
);
15151516
ack_of_fin = true;
15161517
}
1518+
1519+
ack_all = self.remote_last_seq == ack_number
15171520
}
15181521

15191522
self.rtte.on_ack(cx.now(), ack_number);
@@ -1643,7 +1646,7 @@ impl<'a> TcpSocket<'a> {
16431646
// ACK packets in ESTABLISHED state reset the retransmit timer,
16441647
// except for duplicate ACK packets which preserve it.
16451648
(State::Established, TcpControl::None) => {
1646-
if !self.timer.is_retransmit() || ack_len != 0 {
1649+
if !self.timer.is_retransmit() || ack_all {
16471650
self.timer.set_for_idle(cx.now(), self.keep_alive);
16481651
}
16491652
}
@@ -1662,7 +1665,9 @@ impl<'a> TcpSocket<'a> {
16621665
if ack_of_fin {
16631666
self.set_state(State::FinWait2);
16641667
}
1665-
self.timer.set_for_idle(cx.now(), self.keep_alive);
1668+
if ack_all {
1669+
self.timer.set_for_idle(cx.now(), self.keep_alive);
1670+
}
16661671
}
16671672

16681673
// FIN packets in FIN-WAIT-1 state change it to CLOSING, or to TIME-WAIT
@@ -1997,7 +2002,12 @@ impl<'a> TcpSocket<'a> {
19972002
_ => false,
19982003
};
19992004

2000-
if self.nagle && data_in_flight && !can_send_full {
2005+
// If we're applying the Nagle algorithm we don't want to send more
2006+
// until one of:
2007+
// * There's no data in flight
2008+
// * We can send a full packet
2009+
// * We have all the data we'll ever send (we're closing send)
2010+
if self.nagle && data_in_flight && !can_send_full && !want_fin {
20012011
can_send = false;
20022012
}
20032013

@@ -5137,6 +5147,85 @@ mod test {
51375147
recv!(s, time 1550, Err(Error::Exhausted));
51385148
}
51395149

5150+
#[test]
5151+
fn test_data_retransmit_bursts_half_ack() {
5152+
let mut s = socket_established();
5153+
s.remote_mss = 6;
5154+
s.send_slice(b"abcdef012345").unwrap();
5155+
5156+
recv!(s, time 0, Ok(TcpRepr {
5157+
control: TcpControl::None,
5158+
seq_number: LOCAL_SEQ + 1,
5159+
ack_number: Some(REMOTE_SEQ + 1),
5160+
payload: &b"abcdef"[..],
5161+
..RECV_TEMPL
5162+
}), exact);
5163+
recv!(s, time 0, Ok(TcpRepr {
5164+
control: TcpControl::Psh,
5165+
seq_number: LOCAL_SEQ + 1 + 6,
5166+
ack_number: Some(REMOTE_SEQ + 1),
5167+
payload: &b"012345"[..],
5168+
..RECV_TEMPL
5169+
}), exact);
5170+
// Acknowledge the first packet
5171+
send!(s, time 5, TcpRepr {
5172+
seq_number: REMOTE_SEQ + 1,
5173+
ack_number: Some(LOCAL_SEQ + 1 + 6),
5174+
window_len: 6,
5175+
..SEND_TEMPL
5176+
});
5177+
// The second packet should be re-sent.
5178+
recv!(s, time 1500, Ok(TcpRepr {
5179+
control: TcpControl::Psh,
5180+
seq_number: LOCAL_SEQ + 1 + 6,
5181+
ack_number: Some(REMOTE_SEQ + 1),
5182+
payload: &b"012345"[..],
5183+
..RECV_TEMPL
5184+
}), exact);
5185+
5186+
recv!(s, time 1550, Err(Error::Exhausted));
5187+
}
5188+
5189+
#[test]
5190+
fn test_data_retransmit_bursts_half_ack_close() {
5191+
let mut s = socket_established();
5192+
s.remote_mss = 6;
5193+
s.send_slice(b"abcdef012345").unwrap();
5194+
s.close();
5195+
5196+
recv!(s, time 0, Ok(TcpRepr {
5197+
control: TcpControl::None,
5198+
seq_number: LOCAL_SEQ + 1,
5199+
ack_number: Some(REMOTE_SEQ + 1),
5200+
payload: &b"abcdef"[..],
5201+
..RECV_TEMPL
5202+
}), exact);
5203+
recv!(s, time 0, Ok(TcpRepr {
5204+
control: TcpControl::Fin,
5205+
seq_number: LOCAL_SEQ + 1 + 6,
5206+
ack_number: Some(REMOTE_SEQ + 1),
5207+
payload: &b"012345"[..],
5208+
..RECV_TEMPL
5209+
}), exact);
5210+
// Acknowledge the first packet
5211+
send!(s, time 5, TcpRepr {
5212+
seq_number: REMOTE_SEQ + 1,
5213+
ack_number: Some(LOCAL_SEQ + 1 + 6),
5214+
window_len: 6,
5215+
..SEND_TEMPL
5216+
});
5217+
// The second packet should be re-sent.
5218+
recv!(s, time 1500, Ok(TcpRepr {
5219+
control: TcpControl::Fin,
5220+
seq_number: LOCAL_SEQ + 1 + 6,
5221+
ack_number: Some(REMOTE_SEQ + 1),
5222+
payload: &b"012345"[..],
5223+
..RECV_TEMPL
5224+
}), exact);
5225+
5226+
recv!(s, time 1550, Err(Error::Exhausted));
5227+
}
5228+
51405229
#[test]
51415230
fn test_send_data_after_syn_ack_retransmit() {
51425231
let mut s = socket_syn_received();
@@ -6916,6 +7005,29 @@ mod test {
69167005
);
69177006
}
69187007

7008+
#[test]
7009+
fn test_final_packet_in_stream_doesnt_wait_for_nagle() {
7010+
let mut s = socket_established();
7011+
s.remote_mss = 6;
7012+
s.send_slice(b"abcdef0").unwrap();
7013+
s.socket.close();
7014+
7015+
recv!(s, time 0, Ok(TcpRepr {
7016+
control: TcpControl::None,
7017+
seq_number: LOCAL_SEQ + 1,
7018+
ack_number: Some(REMOTE_SEQ + 1),
7019+
payload: &b"abcdef"[..],
7020+
..RECV_TEMPL
7021+
}), exact);
7022+
recv!(s, time 0, Ok(TcpRepr {
7023+
control: TcpControl::Fin,
7024+
seq_number: LOCAL_SEQ + 1 + 6,
7025+
ack_number: Some(REMOTE_SEQ + 1),
7026+
payload: &b"0"[..],
7027+
..RECV_TEMPL
7028+
}), exact);
7029+
}
7030+
69197031
// =========================================================================================//
69207032
// Tests for packet filtering.
69217033
// =========================================================================================//

0 commit comments

Comments
 (0)