@@ -94,7 +94,6 @@ using namespace std;
9494bool 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
168152acceptable:
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