mirror of
https://github.com/espressif/openthread.git
synced 2026-09-06 09:10:04 +00:00
[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:
Vendored
+14
-1
@@ -49,6 +49,8 @@
|
||||
|
||||
#include "tcp_const.h"
|
||||
|
||||
static void reinitialize_tcb(struct tcpcb* tp);
|
||||
|
||||
/*
|
||||
* samkumar: This is rewritten to have the host network stack to generate the
|
||||
* ISN with appropriate randomness.
|
||||
@@ -145,6 +147,15 @@ void initialize_tcb(struct tcpcb* 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
|
||||
@@ -165,6 +176,8 @@ tcp_discardcb(struct tcpcb *tp)
|
||||
CC_ALGO(tp)->cb_destroy(tp->ccv);
|
||||
|
||||
tcp_free_sackholes(tp);
|
||||
|
||||
reinitialize_tcb(tp);
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +365,7 @@ struct tcpcb *
|
||||
tcp_drop(struct tcpcb *tp, int errnum)
|
||||
{
|
||||
if (TCPS_HAVERCVDSYN(tp->t_state)) {
|
||||
tcp_state_change(tp, TCPS_CLOSED);
|
||||
tcp_state_change(tp, TCP6S_CLOSED);
|
||||
(void) tcplp_output(tp);
|
||||
}
|
||||
if (errnum == ETIMEDOUT && tp->t_softerror)
|
||||
|
||||
+1
-1
@@ -522,7 +522,7 @@ tcp_usr_abort(struct tcpcb* tp)
|
||||
if (tp->t_state != TCP6S_TIME_WAIT &&
|
||||
tp->t_state != TCP6S_CLOSED) {
|
||||
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);
|
||||
tcplp_sys_connection_lost(tp, CONN_LOST_NORMAL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user