[tcp] send RST and clear send buffer on abort (#11269)

This commit corrects the timing of Transmission Control Block (TCB)
re-initialization to ensure proper RST packet sending during TCP
connection aborts and to prevent potential issues due to incomplete
TCB cleanup.
This commit is contained in:
Yaoxing Shan
2025-04-22 15:07:45 -07:00
committed by GitHub
parent 283edc0bd5
commit 424de28a2f
3 changed files with 18 additions and 9 deletions
+3 -7
View File
@@ -1089,13 +1089,9 @@ void tcplp_sys_connection_lost(struct tcpcb *aTcb, uint8_t aErrNum)
void tcplp_sys_on_state_change(struct tcpcb *aTcb, int aNewState) void tcplp_sys_on_state_change(struct tcpcb *aTcb, int aNewState)
{ {
if (aNewState == TCP6S_CLOSED) OT_UNUSED_VARIABLE(aTcb);
{ OT_UNUSED_VARIABLE(aNewState);
/* Re-initialize the TCB. */
cbuf_pop(&aTcb->recvbuf, cbuf_used_space(&aTcb->recvbuf));
aTcb->accepted_from = nullptr;
initialize_tcb(aTcb);
}
/* Any adaptive changes to the sleep interval would go here. */ /* Any adaptive changes to the sleep interval would go here. */
} }
+14 -1
View File
@@ -49,6 +49,8 @@
#include "tcp_const.h" #include "tcp_const.h"
static void reinitialize_tcb(struct tcpcb* tp);
/* /*
* samkumar: This is rewritten to have the host network stack to generate the * samkumar: This is rewritten to have the host network stack to generate the
* ISN with appropriate randomness. * ISN with appropriate randomness.
@@ -145,6 +147,15 @@ void initialize_tcb(struct tcpcb* tp) {
tcp_sack_init(tp); tcp_sack_init(tp);
} }
/* Re-initialize the TCB. */
static void reinitialize_tcb(struct tcpcb* tp)
{
uint32_t ntraversed;
lbuf_pop(&tp->sendbuf, lbuf_used_space(&tp->sendbuf), &ntraversed);
cbuf_pop(&tp->recvbuf, cbuf_used_space(&tp->recvbuf));
tp->accepted_from = NULL;
initialize_tcb(tp);
}
/* /*
* samkumar: Most of this function was no longer needed. It did things like * samkumar: Most of this function was no longer needed. It did things like
@@ -165,6 +176,8 @@ tcp_discardcb(struct tcpcb *tp)
CC_ALGO(tp)->cb_destroy(tp->ccv); CC_ALGO(tp)->cb_destroy(tp->ccv);
tcp_free_sackholes(tp); tcp_free_sackholes(tp);
reinitialize_tcb(tp);
} }
@@ -352,7 +365,7 @@ struct tcpcb *
tcp_drop(struct tcpcb *tp, int errnum) tcp_drop(struct tcpcb *tp, int errnum)
{ {
if (TCPS_HAVERCVDSYN(tp->t_state)) { if (TCPS_HAVERCVDSYN(tp->t_state)) {
tcp_state_change(tp, TCPS_CLOSED); tcp_state_change(tp, TCP6S_CLOSED);
(void) tcplp_output(tp); (void) tcplp_output(tp);
} }
if (errnum == ETIMEDOUT && tp->t_softerror) if (errnum == ETIMEDOUT && tp->t_softerror)
+1 -1
View File
@@ -522,7 +522,7 @@ tcp_usr_abort(struct tcpcb* tp)
if (tp->t_state != TCP6S_TIME_WAIT && if (tp->t_state != TCP6S_TIME_WAIT &&
tp->t_state != TCP6S_CLOSED) { tp->t_state != TCP6S_CLOSED) {
tcp_drop(tp, ECONNABORTED); tcp_drop(tp, ECONNABORTED);
} else if (tp->t_state == TCPS_TIME_WAIT) { // samkumar: I added this clause } else if (tp->t_state == TCP6S_TIME_WAIT) { // samkumar: I added this clause
tp = tcp_close_tcb(tp); tp = tcp_close_tcb(tp);
tcplp_sys_connection_lost(tp, CONN_LOST_NORMAL); tcplp_sys_connection_lost(tp, CONN_LOST_NORMAL);
} }