Every duplicate ACK unconditionally triggered a fast retransmit,
even when the ACK sequence hadn't advanced.
Add a dup_acks counter (as a union with retries) to
tcp_tap_conn and tcp_tap_transfer that gets incremented on the
first fast retransmit and cleared when the ACK sequence
advances.
This is a quick fix to stop the amplification storm. Full
compliance with RFC 5681 Section 3.2 (three duplicate ACKs)
is left to a later patch.
Link: https://bugs.passt.top/show_bug.cgi?id=224
Signed-off-by: Anshu Kumari
---
v2:
- added union for retries and dup_acks.
- removed retransmitting flag.
---
tcp.c | 12 ++++++++----
tcp_conn.h | 16 ++++++++++++----
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/tcp.c b/tcp.c
index 95f4f3e1..d205cd41 100644
--- a/tcp.c
+++ b/tcp.c
@@ -242,7 +242,7 @@
* - consume buffer by difference between new ack_seq and @seq_ack_from_tap
* - update @seq_ack_from_tap from ack_seq in header
* - on two duplicated ACKs, reset @seq_to_tap to @seq_ack_from_tap, and
- * resend with steps listed above
+ * resend with steps listed above, once per loss event
*
* - from tap/guest to socket:
* - on packet from tap/guest:
@@ -1263,7 +1263,7 @@ static void tcp_update_seqack_from_tap(const struct ctx *c,
if (SEQ_LT(seq, conn->seq_to_tap))
conn_flag(c, conn, ACK_FROM_TAP_DUE, now);
- conn->retries = 0;
+ conn->dup_acks = 0;
conn->seq_ack_from_tap = seq;
}
}
@@ -2082,7 +2082,9 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn,
tcp_tap_window_update(c, conn, max_ack_seq_wnd, now);
- if (retr) {
+ if (retr && !conn->dup_acks) {
+ conn->dup_acks++;
+
flow_trace(conn,
"fast re-transmit, ACK: %u, previous sequence: %u",
conn->seq_ack_from_tap, conn->seq_to_tap);
@@ -2443,7 +2445,9 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
tcp_update_seqack_from_tap(c, conn, ntohl(th->ack_seq),
now);
- if (retr) {
+ if (retr && !conn->dup_acks) {
+ conn->dup_acks++;
+
flow_trace(conn,
"fast re-transmit, ACK: %u, previous sequence: %u",
ntohl(th->ack_seq), conn->seq_to_tap);
diff --git a/tcp_conn.h b/tcp_conn.h
index 3173ddb9..ba175a3e 100644
--- a/tcp_conn.h
+++ b/tcp_conn.h
@@ -16,7 +16,8 @@
/**
* struct tcp_tap_conn - Descriptor for a TCP connection (not spliced)
* @f: Generic flow information
- * @retries: Number of retries occurred due to timeouts
+ * @retries: Number of retries due to timeouts
+ * @dup_acks: Number of duplicate ACKs (union with @retries)
* @ws_from_tap: Window scaling factor advertised from tap/guest
* @ws_to_tap: Window scaling factor advertised to tap/guest
* @tap_mss: MSS advertised by tap/guest, rounded to 2 ^ TCP_MSS_BITS
@@ -41,7 +42,10 @@ struct tcp_tap_conn {
struct flow_common f;
#define TCP_RETRIES_BITS 3
- unsigned int retries :TCP_RETRIES_BITS;
+ union {
+ unsigned int retries :TCP_RETRIES_BITS;
+ unsigned int dup_acks :TCP_RETRIES_BITS;
+ };
#define TCP_MAX_RETRIES MAX_FROM_BITS(TCP_RETRIES_BITS)
#define TCP_WS_BITS 4 /* RFC 7323 */
@@ -122,7 +126,8 @@ struct tcp_tap_conn {
* struct tcp_tap_transfer - Migrated TCP data, flow table part, network order
* @pif: Interfaces for each side of the flow
* @side: Addresses and ports for each side of the flow
- * @retries: Number of retries occurred due to timeouts
+ * @retries: Number of retries due to timeouts
+ * @dup_acks: Number of duplicate ACKs (union with @retries)
* @ws_from_tap: Window scaling factor advertised from tap/guest
* @ws_to_tap: Window scaling factor advertised to tap/guest
* @events: Connection events, implying connection states
@@ -142,7 +147,10 @@ struct tcp_tap_transfer {
uint8_t pif[SIDES];
struct flowside side[SIDES];
- uint8_t retries;
+ union {
+ uint8_t retries;
+ uint8_t dup_acks;
+ };
uint8_t ws_from_tap;
uint8_t ws_to_tap;
uint8_t events;
--
2.55.0