Skip to content

Commit 424de28

Browse files
authored
[tcp] send RST and clear send buffer on abort (openthread#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.
1 parent 283edc0 commit 424de28

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/core/net/tcp6.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,13 +1089,9 @@ void tcplp_sys_connection_lost(struct tcpcb *aTcb, uint8_t aErrNum)
10891089

10901090
void tcplp_sys_on_state_change(struct tcpcb *aTcb, int aNewState)
10911091
{
1092-
if (aNewState == TCP6S_CLOSED)
1093-
{
1094-
/* Re-initialize the TCB. */
1095-
cbuf_pop(&aTcb->recvbuf, cbuf_used_space(&aTcb->recvbuf));
1096-
aTcb->accepted_from = nullptr;
1097-
initialize_tcb(aTcb);
1098-
}
1092+
OT_UNUSED_VARIABLE(aTcb);
1093+
OT_UNUSED_VARIABLE(aNewState);
1094+
10991095
/* Any adaptive changes to the sleep interval would go here. */
11001096
}
11011097

third_party/tcplp/bsdtcp/tcp_subr.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949

5050
#include "tcp_const.h"
5151

52+
static void reinitialize_tcb(struct tcpcb* tp);
53+
5254
/*
5355
* samkumar: This is rewritten to have the host network stack to generate the
5456
* ISN with appropriate randomness.
@@ -145,6 +147,15 @@ void initialize_tcb(struct tcpcb* tp) {
145147
tcp_sack_init(tp);
146148
}
147149

150+
/* Re-initialize the TCB. */
151+
static void reinitialize_tcb(struct tcpcb* tp)
152+
{
153+
uint32_t ntraversed;
154+
lbuf_pop(&tp->sendbuf, lbuf_used_space(&tp->sendbuf), &ntraversed);
155+
cbuf_pop(&tp->recvbuf, cbuf_used_space(&tp->recvbuf));
156+
tp->accepted_from = NULL;
157+
initialize_tcb(tp);
158+
}
148159

149160
/*
150161
* samkumar: Most of this function was no longer needed. It did things like
@@ -165,6 +176,8 @@ tcp_discardcb(struct tcpcb *tp)
165176
CC_ALGO(tp)->cb_destroy(tp->ccv);
166177

167178
tcp_free_sackholes(tp);
179+
180+
reinitialize_tcb(tp);
168181
}
169182

170183

@@ -352,7 +365,7 @@ struct tcpcb *
352365
tcp_drop(struct tcpcb *tp, int errnum)
353366
{
354367
if (TCPS_HAVERCVDSYN(tp->t_state)) {
355-
tcp_state_change(tp, TCPS_CLOSED);
368+
tcp_state_change(tp, TCP6S_CLOSED);
356369
(void) tcplp_output(tp);
357370
}
358371
if (errnum == ETIMEDOUT && tp->t_softerror)

third_party/tcplp/bsdtcp/tcp_usrreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ tcp_usr_abort(struct tcpcb* tp)
522522
if (tp->t_state != TCP6S_TIME_WAIT &&
523523
tp->t_state != TCP6S_CLOSED) {
524524
tcp_drop(tp, ECONNABORTED);
525-
} else if (tp->t_state == TCPS_TIME_WAIT) { // samkumar: I added this clause
525+
} else if (tp->t_state == TCP6S_TIME_WAIT) { // samkumar: I added this clause
526526
tp = tcp_close_tcb(tp);
527527
tcplp_sys_connection_lost(tp, CONN_LOST_NORMAL);
528528
}

0 commit comments

Comments
 (0)