@@ -365,12 +365,13 @@ static size_t tcp_data_len(struct net_pkt *pkt)
365365 return len > 0 ? (size_t )len : 0 ;
366366}
367367
368- static const char * tcp_th (struct net_pkt * pkt )
368+ static const char * tcp_th (struct net_pkt * pkt , uint32_t * seq_ptr , uint32_t * ack_ptr )
369369{
370370#define BUF_SIZE 80
371371 static char buf [BUF_SIZE ];
372372 int len = 0 ;
373373 struct tcphdr * th = th_get (pkt );
374+ uint32_t seq , ack ;
374375
375376 buf [0 ] = '\0' ;
376377
@@ -380,12 +381,28 @@ static const char *tcp_th(struct net_pkt *pkt)
380381 goto end ;
381382 }
382383
384+ seq = th_seq (th );
385+
383386 len += snprintk (buf + len , BUF_SIZE - len ,
384- "%s Seq=%u" , tcp_flags (th_flags (th )), th_seq (th ));
387+ "%s Seq=%u{%u}" , tcp_flags (th_flags (th )),
388+ ack_ptr != NULL ? (uint32_t )(seq - * ack_ptr ) : 0U ,
389+ seq );
385390
386391 if (th_flags (th ) & ACK ) {
392+ ack = th_ack (th );
393+
387394 len += snprintk (buf + len , BUF_SIZE - len ,
388- " Ack=%u" , th_ack (th ));
395+ " Ack=%u{%u}" ,
396+ seq_ptr != NULL ? (uint32_t )(ack - * seq_ptr ) : 0U ,
397+ ack );
398+
399+ if (seq_ptr != NULL ) {
400+ * seq_ptr = ack ;
401+ }
402+ }
403+
404+ if (ack_ptr != NULL ) {
405+ * ack_ptr = seq ;
389406 }
390407
391408 len += snprintk (buf + len , BUF_SIZE - len ,
@@ -1047,10 +1064,13 @@ static const char *tcp_conn_state(struct tcp *conn, struct net_pkt *pkt)
10471064{
10481065#define BUF_SIZE 160
10491066 static char buf [BUF_SIZE ];
1067+ uint32_t seq = conn -> isn , ack = conn -> isn_peer ;
10501068
1051- snprintk (buf , BUF_SIZE , "%s [%s Seq=%u Ack=%u]" , pkt ? tcp_th (pkt ) : "" ,
1052- tcp_state_to_str (conn -> state , false),
1053- conn -> seq , conn -> ack );
1069+ snprintk (buf , BUF_SIZE , "%s [%s Seq=%u{%u} Ack=%u{%u}]" ,
1070+ pkt ? tcp_th (pkt , & seq , & ack ) : "" ,
1071+ tcp_state_to_str (conn -> state , false),
1072+ conn -> seq - seq , conn -> seq ,
1073+ conn -> ack - ack , conn -> ack );
10541074#undef BUF_SIZE
10551075 return buf ;
10561076}
@@ -1523,7 +1543,7 @@ void net_tcp_reply_rst(struct net_pkt *pkt)
15231543 goto err ;
15241544 }
15251545
1526- NET_DBG ("%s" , tcp_th (rst ));
1546+ NET_DBG ("%s" , tcp_th (rst , NULL , NULL ));
15271547
15281548 tcp_send (rst );
15291549
@@ -2520,6 +2540,8 @@ static struct tcp *tcp_conn_new(struct net_pkt *pkt)
25202540 conn -> seq = tcp_init_isn (& local_addr , & context -> remote );
25212541 }
25222542
2543+ conn -> isn = conn -> seq ;
2544+
25232545 NET_DBG ("[%p] local: %s, remote: %s" , conn ,
25242546 net_sprint_addr (local_addr .sa_family ,
25252547 (const void * )& net_sin (& local_addr )-> sin_addr ),
@@ -3071,6 +3093,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
30713093
30723094 /* Make sure our MSS is also sent in the ACK */
30733095 conn -> send_options .mss_found = true;
3096+ conn -> isn_peer = th_seq (th );
30743097 conn_ack (conn , th_seq (th ) + 1 ); /* capture peer's isn */
30753098 tcp_out (conn , SYN | ACK );
30763099 conn -> send_options .mss_found = false;
@@ -3183,6 +3206,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
31833206 */
31843207 if (FL (& fl , & , SYN | ACK , th && th_ack (th ) == conn -> seq )) {
31853208 k_work_cancel_delayable (& conn -> send_data_timer );
3209+ conn -> isn_peer = th_seq (th );
31863210 conn_ack (conn , th_seq (th ) + 1 );
31873211 if (len ) {
31883212 verdict = tcp_data_get (conn , pkt , & len );
@@ -4026,6 +4050,8 @@ int net_tcp_connect(struct net_context *context,
40264050 */
40274051 conn -> in_connect = !IS_ENABLED (CONFIG_NET_TEST_PROTOCOL );
40284052
4053+ conn -> isn = conn -> seq ;
4054+
40294055 ret = tcp_start_handshake (conn );
40304056 if (ret < 0 ) {
40314057 goto out ;
0 commit comments