@@ -365,12 +365,13 @@ static size_t tcp_data_len(struct net_pkt *pkt)
365
365
return len > 0 ? (size_t )len : 0 ;
366
366
}
367
367
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 )
369
369
{
370
370
#define BUF_SIZE 80
371
371
static char buf [BUF_SIZE ];
372
372
int len = 0 ;
373
373
struct tcphdr * th = th_get (pkt );
374
+ uint32_t seq , ack ;
374
375
375
376
buf [0 ] = '\0' ;
376
377
@@ -380,12 +381,28 @@ static const char *tcp_th(struct net_pkt *pkt)
380
381
goto end ;
381
382
}
382
383
384
+ seq = th_seq (th );
385
+
383
386
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 );
385
390
386
391
if (th_flags (th ) & ACK ) {
392
+ ack = th_ack (th );
393
+
387
394
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 ;
389
406
}
390
407
391
408
len += snprintk (buf + len , BUF_SIZE - len ,
@@ -1047,10 +1064,13 @@ static const char *tcp_conn_state(struct tcp *conn, struct net_pkt *pkt)
1047
1064
{
1048
1065
#define BUF_SIZE 160
1049
1066
static char buf [BUF_SIZE ];
1067
+ uint32_t seq = conn -> isn , ack = conn -> isn_peer ;
1050
1068
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 );
1054
1074
#undef BUF_SIZE
1055
1075
return buf ;
1056
1076
}
@@ -1523,7 +1543,7 @@ void net_tcp_reply_rst(struct net_pkt *pkt)
1523
1543
goto err ;
1524
1544
}
1525
1545
1526
- NET_DBG ("%s" , tcp_th (rst ));
1546
+ NET_DBG ("%s" , tcp_th (rst , NULL , NULL ));
1527
1547
1528
1548
tcp_send (rst );
1529
1549
@@ -2520,6 +2540,8 @@ static struct tcp *tcp_conn_new(struct net_pkt *pkt)
2520
2540
conn -> seq = tcp_init_isn (& local_addr , & context -> remote );
2521
2541
}
2522
2542
2543
+ conn -> isn = conn -> seq ;
2544
+
2523
2545
NET_DBG ("[%p] local: %s, remote: %s" , conn ,
2524
2546
net_sprint_addr (local_addr .sa_family ,
2525
2547
(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)
3071
3093
3072
3094
/* Make sure our MSS is also sent in the ACK */
3073
3095
conn -> send_options .mss_found = true;
3096
+ conn -> isn_peer = th_seq (th );
3074
3097
conn_ack (conn , th_seq (th ) + 1 ); /* capture peer's isn */
3075
3098
tcp_out (conn , SYN | ACK );
3076
3099
conn -> send_options .mss_found = false;
@@ -3183,6 +3206,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
3183
3206
*/
3184
3207
if (FL (& fl , & , SYN | ACK , th && th_ack (th ) == conn -> seq )) {
3185
3208
k_work_cancel_delayable (& conn -> send_data_timer );
3209
+ conn -> isn_peer = th_seq (th );
3186
3210
conn_ack (conn , th_seq (th ) + 1 );
3187
3211
if (len ) {
3188
3212
verdict = tcp_data_get (conn , pkt , & len );
@@ -4026,6 +4050,8 @@ int net_tcp_connect(struct net_context *context,
4026
4050
*/
4027
4051
conn -> in_connect = !IS_ENABLED (CONFIG_NET_TEST_PROTOCOL );
4028
4052
4053
+ conn -> isn = conn -> seq ;
4054
+
4029
4055
ret = tcp_start_handshake (conn );
4030
4056
if (ret < 0 ) {
4031
4057
goto out ;
0 commit comments