Don't panic on TCP sequence number wrapping in debug mode.

This commit is contained in:
Kai Lüke 2017-11-13 17:45:07 +09:00 committed by whitequark
parent 1e809daf7a
commit 2a52234d53
2 changed files with 18 additions and 2 deletions

View File

@ -1482,6 +1482,7 @@ impl<'a> fmt::Write for TcpSocket<'a> {
#[cfg(test)]
mod test {
use core::i32;
use wire::{IpAddress, IpRepr};
use wire::{Ipv4Address, IpCidr, Ipv4Repr};
use super::*;
@ -2128,6 +2129,21 @@ mod test {
}]);
}
#[test]
fn test_established_send_wrap() {
let mut s = socket_established();
let local_seq_start = TcpSeqNumber(i32::MAX - 1);
s.local_seq_no = local_seq_start + 1;
s.remote_last_seq = local_seq_start + 1;
s.send_slice(b"abc").unwrap();
recv!(s, time 1000, Ok(TcpRepr {
seq_number: local_seq_start + 1,
ack_number: Some(REMOTE_SEQ + 1),
payload: &b"abc"[..],
..RECV_TEMPL
}));
}
#[test]
fn test_established_no_ack() {
let mut s = socket_established();

View File

@ -51,13 +51,13 @@ impl ops::Sub for SeqNumber {
type Output = usize;
fn sub(self, rhs: SeqNumber) -> usize {
(self.0 - rhs.0) as usize
self.0.wrapping_sub(rhs.0) as usize
}
}
impl cmp::PartialOrd for SeqNumber {
fn partial_cmp(&self, other: &SeqNumber) -> Option<cmp::Ordering> {
(self.0 - other.0).partial_cmp(&0)
self.0.wrapping_sub(other.0).partial_cmp(&0)
}
}