Skip to content

Commit 661ca2d

Browse files
committed
issue: 4398221 Fix connection closure on SYN_RCVD
When closing a connection in SYN_RCVD state, we should transition directly to CLOSED without sending FIN or RST packets, as specified in the RFC. This patch properly handles this case by immediately changing the state to CLOSED instead of going through the normal shutdown procedure. This prevents unnecessary control packets when a connection receives a SYN and is immediately closed without exchanging data. Signed-off-by: Tomer Cabouly <[email protected]>
1 parent 0d8f272 commit 661ca2d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/core/lwip/tcp.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,15 @@ err_t tcp_close(struct tcp_pcb *pcb)
258258
/* Set a flag not to receive any more data... */
259259
pcb->flags |= TF_RXCLOSED;
260260
}
261-
/* ... and close */
262-
return tcp_close_shutdown(pcb, 1);
261+
262+
if (get_tcp_state(pcb) == SYN_RCVD) {
263+
// according to the RFC, in case we get a SYN and no more data
264+
// we should just close w/o FIN or RST
265+
set_tcp_state(pcb, CLOSED);
266+
return ERR_OK;
267+
} else {
268+
return tcp_close_shutdown(pcb, 1);
269+
}
263270
}
264271

265272
/**

0 commit comments

Comments
 (0)