tcp_reset: Modify RST packet responses to comply with RFC 793.
Build Documentation / build-html (push) Has been cancelled

According to RFC793, the flags of TCP reply packet should be as follows:
1. `RST` if flags of request packet has `ACK`
2. `RST|ACK` if flags of request packet has no `ACK`, at the same time, the sequence should be set to zero.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
This commit is contained in:
wenquan1
2025-07-01 15:36:28 +08:00
committed by Xiang Xiao
parent 424a924f65
commit ee5009295c
+13 -5
View File
@@ -382,7 +382,6 @@ void tcp_send(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
void tcp_reset(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
{
FAR struct tcp_hdr_s *tcp;
uint32_t ackno;
uint16_t tmp16;
uint16_t acklen = 0;
uint8_t seqbyte;
@@ -437,7 +436,6 @@ void tcp_reset(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
acklen -= (tcp->tcpoffset >> 4) << 2;
tcp->flags = TCP_RST | TCP_ACK;
tcp->tcpoffset = 5 << 4;
/* Flip the seqno and ackno fields in the TCP header. */
@@ -463,9 +461,19 @@ void tcp_reset(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
* to propagate the carry to the other bytes as well.
*/
ackno = tcp_addsequence(tcp->ackno, acklen);
tcp_setsequence(tcp->ackno, ackno);
if ((tcp->flags & TCP_ACK) != 0)
{
tcp->flags = TCP_RST;
tcp_setsequence(tcp->ackno, 0);
}
else
{
uint32_t ackno;
tcp->flags = TCP_RST | TCP_ACK;
tcp_setsequence(tcp->seqno, 0);
ackno = tcp_addsequence(tcp->ackno, acklen);
tcp_setsequence(tcp->ackno, ackno);
}
/* Swap port numbers. */