I have a TCP server demo running on a STM32H7 Nucleo board. It seems to be working correctly for the most part: I can flood ping and there is no packet loss, I see ARP working correctly, and so on. But for some reason, when I try to connect to the stack over TCP, it takes a long and variable time to reply with SYN ACK—anywhere from a few SYN packets ignored to perhaps ten of them, before the stack suddenly ACKs and the connection is open. Once the TCP connection is established, everything seems fine again. Here is a packet trace using tcpdump; 192.168.15.1 is a Linux PC and 192.168.15.2 is the Nucleo board running FreeRTOS+TCP:
09:52:03.380033 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 192.168.15.2 tell 192.168.15.2, length 46
09:52:10.363374 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 192.168.15.2 tell 192.168.15.1, length 28
09:52:10.363685 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.15.2 is-at 00:11:22:33:44:55, length 50
09:52:10.363696 IP (tos 0x0, ttl 64, id 46606, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xe57b), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797594838 ecr 0,nop,wscale 7], length 0
09:52:11.365802 IP (tos 0x0, ttl 64, id 46607, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xe190), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797595841 ecr 0,nop,wscale 7], length 0
09:52:12.389672 IP (tos 0x0, ttl 64, id 46608, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xdd90), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797596865 ecr 0,nop,wscale 7], length 0
09:52:13.413779 IP (tos 0x0, ttl 64, id 46609, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xd990), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797597889 ecr 0,nop,wscale 7], length 0
09:52:14.437746 IP (tos 0x0, ttl 64, id 46610, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xd590), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797598913 ecr 0,nop,wscale 7], length 0
09:52:15.462046 IP (tos 0x0, ttl 64, id 46611, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xd190), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797599937 ecr 0,nop,wscale 7], length 0
09:52:17.511420 IP (tos 0x0, ttl 64, id 46612, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xc98e), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797601987 ecr 0,nop,wscale 7], length 0
09:52:21.541423 IP (tos 0x0, ttl 64, id 46613, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xb9d0), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797606017 ecr 0,nop,wscale 7], length 0
09:52:29.989755 IP (tos 0x0, ttl 64, id 46614, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0x98d0), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797614465 ecr 0,nop,wscale 7], length 0
09:52:33.218868 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 192.168.15.2 tell 192.168.15.2, length 46
09:52:35.109489 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 192.168.15.2 tell 192.168.15.1, length 28
09:52:35.109871 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.15.2 is-at 00:11:22:33:44:55, length 50
09:52:46.373435 IP (tos 0x0, ttl 64, id 46615, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0x58d0), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797630849 ecr 0,nop,wscale 7], length 0
09:53:03.060471 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 192.168.15.2 tell 192.168.15.2, length 46
09:53:18.629464 IP (tos 0x0, ttl 64, id 46616, offset 0, flags [DF], proto TCP (6), length 60)
192.168.15.1.37436 > 192.168.15.2.23: Flags [S], cksum 0x9f82 (incorrect -> 0xdacf), seq 2741833246, win 64240, options [mss 1460,sackOK,TS val 797663105 ecr 0,nop,wscale 7], length 0
09:53:18.630286 IP (tos 0x0, ttl 128, id 0, offset 0, flags [none], proto TCP (6), length 52)
192.168.15.2.23 > 192.168.15.1.37436: Flags [S.], cksum 0x238c (correct), seq 536886496, ack 2741833247, win 2920, options [mss 1460,nop,wscale 0,nop,nop,sackOK], length 0
09:53:18.630400 IP (tos 0x0, ttl 64, id 46617, offset 0, flags [DF], proto TCP (6), length 40)
192.168.15.1.37436 > 192.168.15.2.23: Flags [.], cksum 0x6dc9 (correct), seq 1, ack 1, win 502, length 0
and here is the debugging output from the stack, on my serial terminal:
FreeRTOS_AddEndPoint: MAC: 44-55 IPv4: c0a80f02ip
main: starting scheduler
prvIPTask started
PHY ID 7C130
TCP listen: in task func
TCP listen: socket created
TCP listen: sockopts set
xPhyReset: phyBMCR_RESET 0 ready
+TCP: advertise: 01E1 config 3100
Autonego ready: 00000004: full duplex 100 mbit high status
TCP listen: socket bound
TCP listen: in loop
pxEasyFit: ARP c0a80f01ip -> c0a80f02ip
ipARP_REQUEST from c0a80f01ip to c0a80f02ip end-point c0a80f02ip
pxEasyFit: ARP c0a80f01ip -> c0a80f02ip
ipARP_REQUEST from c0a80f01ip to c0a80f02ip end-point c0a80f02ip
Gain: Socket 23 now has 1 / 20 child me: 20004ad0 parent: 20003fb8 peer: 20004ad0
prvSocketSetMSS: 1460 bytes for c0a80f01ip port 37436
prvWinScaleFactor: uxRxWinSize 2 MSS 1460 Factor 0
TCP: passive 23 => 1.15.168.192 port 37436 set ESTAB (scaling 1)
prvAcceptWaitClient: client 20004ad0 parent 20003fb8
TCP listen: accepted! creating task
(The lines starting with “TCP listen:” are ones I added.) There is a minute-long delay between the ARP messages and the “Gain: Socket 23 now has 1 / 20 child”, during which time the stack is ignoring TCP SYN packets from timestamp 09:52:10.4 until 09:53:18.6, when it finally ACKs and the connection is suddenly established. From that time on there is basically zero latency and everything is perfectly snappy.
Any idea what might be going on, and how to debug it? Thanks.