* Equivalent to RCV.WND in RFC 793 terminology.
*/
uint32_t rcv_win;
- /** Most recent received timestamp
+ /** Received timestamp value
+ *
+ * Updated when a packet is received; copied to ts_recent when
+ * the window is advanced.
+ */
+ uint32_t ts_val;
+ /** Most recent received timestamp that advanced the window
*
* Equivalent to TS.Recent in RFC 1323 terminology.
*/
* @v seq_len Sequence space length to consume
*/
static void tcp_rx_seq ( struct tcp_connection *tcp, uint32_t seq_len ) {
+
+ /* Sanity check */
+ assert ( seq_len > 0 );
+
+ /* Update acknowledgement number */
tcp->rcv_ack += seq_len;
+
+ /* Update window */
if ( tcp->rcv_win > seq_len ) {
tcp->rcv_win -= seq_len;
} else {
tcp->rcv_win = 0;
}
+
+ /* Update timestamp */
+ tcp->ts_recent = tcp->ts_val;
+
+ /* Mark ACK as pending */
tcp->flags |= TCP_ACK_PENDING;
}
struct tcp_options options;
size_t hlen;
uint16_t csum;
- uint32_t start_seq;
uint32_t seq;
uint32_t ack;
uint32_t win;
/* Parse parameters from header and strip header */
tcp = tcp_demux ( ntohs ( tcphdr->dest ) );
- seq = start_seq = ntohl ( tcphdr->seq );
+ seq = ntohl ( tcphdr->seq );
ack = ntohl ( tcphdr->ack );
win = ntohs ( tcphdr->win );
flags = tcphdr->flags;
tcp_rx_opts ( tcp, ( ( ( void * ) tcphdr ) + sizeof ( *tcphdr ) ),
( hlen - sizeof ( *tcphdr ) ), &options );
+ if ( options.tsopt )
+ tcp->ts_val = ntohl ( options.tsopt->tsval );
iob_pull ( iobuf, hlen );
len = iob_len ( iobuf );
seq_len = ( len + ( ( flags & TCP_SYN ) ? 1 : 0 ) +
goto discard;
}
- /* Update timestamp, if applicable */
- if ( options.tsopt &&
- tcp_in_window ( tcp->rcv_ack, start_seq, seq_len ) ) {
- tcp->ts_recent = ntohl ( options.tsopt->tsval );
- }
-
/* Enqueue received data */
tcp_rx_enqueue ( tcp, seq, flags, iob_disown ( iobuf ) );