Skip to content

Commit 39d538e

Browse files
tcp: Avoid wrap in seq num check, reparse TS if missing
1 parent ebc56aa commit 39d538e

2 files changed

Lines changed: 11 additions & 22 deletions

File tree

src/net/tcp/connection.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,11 @@ void Connection::rtx_ack(const seq_t ack) {
666666

667667
void Connection::trigger_window_update(os::mem::Pmr_resource& res)
668668
{
669-
//printf("window freed up? %zu\n", res.allocatable());
670-
if(res.allocatable() >= (host_.max_bufsize() * Read_request::buffer_limit))
669+
const auto reserve = (host_.max_bufsize() * Read_request::buffer_limit);
670+
if(res.allocatable() >= reserve and cb.RCV.WND == 0) {
671+
//printf("allocatable=%zu cur_win=%u\n", res.allocatable(), cb.RCV.WND);
671672
send_window_update();
673+
}
672674
}
673675

674676
uint32_t Connection::calculate_rcv_wnd() const
@@ -799,7 +801,7 @@ void Connection::recv_data(const Packet_view& in)
799801
}
800802
}
801803
// Packet out of order
802-
else if((in.seq() - cb.RCV.NXT) < cb.RCV.WND)
804+
else if(( (in.seq() + in.tcp_data_length()) - cb.RCV.NXT) < cb.RCV.WND)
803805
{
804806
// only accept the data if we have a read request
805807
if(read_request != nullptr)

src/net/tcp/connection_states.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ using namespace std;
9494
bool Connection::State::check_seq(Connection& tcp, Packet_view& in)
9595
{
9696
auto& tcb = tcp.tcb();
97-
uint32_t packet_end = static_cast<uint32_t>(in.seq() + in.tcp_data_length()-1);
9897

9998
// RFC 7323
10099
static constexpr uint8_t HEADER_WITH_TS{sizeof(Header) + 12};
@@ -127,24 +126,9 @@ bool Connection::State::check_seq(Connection& tcp, Packet_view& in)
127126
goto unacceptable;
128127

129128
// #2 - Packet is ahead of what we expect to receive, but inside our window
130-
if( tcb.RCV.NXT <= in.seq() and in.seq() < tcb.RCV.NXT + tcb.RCV.WND ) {
129+
if( (in.seq() - tcb.RCV.NXT) < tcb.RCV.WND ) {
131130
goto acceptable;
132131
}
133-
// #3 (INVALID) - Packet is outside the right edge of the recv window
134-
else if( packet_end > tcb.RCV.NXT+tcb.RCV.WND ) {
135-
//printf("Outside right: %s NXT=%u WND=%u\n", in.to_string().c_str(), tcb.RCV.NXT, tcb.RCV.WND);
136-
goto unacceptable;
137-
}
138-
// #4 - Packet with payload is what we expect or bigger, but inside our window
139-
else if( tcb.RCV.NXT <= packet_end
140-
and packet_end < tcb.RCV.NXT+tcb.RCV.WND ) {
141-
goto acceptable;
142-
}
143-
else
144-
{
145-
//printf("Probably outside on left side %s end=%u NXT=%u WND=%u\n",
146-
// in.to_string().c_str(), packet_end, tcb.RCV.NXT, tcb.RCV.WND);
147-
}
148132
/*
149133
If an incoming segment is not acceptable, an acknowledgment
150134
should be sent in reply (unless the RST bit is set, if so drop
@@ -167,10 +151,13 @@ bool Connection::State::check_seq(Connection& tcp, Packet_view& in)
167151

168152
acceptable:
169153
const auto* ts = in.ts_option();
154+
if(tcb.SND.TS_OK)
155+
ts = in.parse_ts_option();
156+
170157
if(ts != nullptr and
171-
(ntohl(ts->val) >= tcb.TS_recent and in.seq() <= tcp.last_ack_sent_))
158+
(ts->get_val() >= tcb.TS_recent and in.seq() <= tcp.last_ack_sent_))
172159
{
173-
tcb.TS_recent = ntohl(ts->val);
160+
tcb.TS_recent = ts->get_val();
174161
}
175162
debug2("<Connection::State::check_seq> Acceptable SEQ: %u \n", in.seq());
176163
// is acceptable.

0 commit comments

Comments
 (0)