tcp: Never automatically add the ACK flag to RST packets

tcp_send_flag() will sometimes force on the ACK flag for all !SYN packets.
This doesn't make sense for RST packets, where plain RST and RST+ACK have
somewhat different meanings.  AIUI, RST+ACK indicates an abrupt end to
a connection, but acknowledges data already sent.  Plain RST indicates an
abort, when one end receives a packet that doesn't seem to make sense in
the context of what it knows about the connection.  All of the cases where
we send RSTs are the second, so we don't want an ACK flag, but we currently
could add one anyway.

Change that, so we won't add an ACK to an RST unless the caller explicitly
requests it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-03-26 16:42:23 +11:00 committed by Stefano Brivio
parent 16c2d8da0d
commit 5894a245b9

2
tcp.c
View file

@ -1674,7 +1674,7 @@ static int tcp_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags)
*data++ = OPT_WS; *data++ = OPT_WS;
*data++ = OPT_WS_LEN; *data++ = OPT_WS_LEN;
*data++ = conn->ws_to_tap; *data++ = conn->ws_to_tap;
} else { } else if (!(flags & RST)) {
if (conn->seq_ack_to_tap != prev_ack_to_tap || if (conn->seq_ack_to_tap != prev_ack_to_tap ||
!prev_wnd_to_tap) !prev_wnd_to_tap)
flags |= ACK; flags |= ACK;