From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=S3mHHgpC; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 69E0B5A0623 for ; Fri, 06 Feb 2026 07:17:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1770358661; bh=qPZfVT/SUNfC5yT3oWTcPDjgrjuJFc4U2/zGQYsKZSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S3mHHgpCtKCycNeiZ3eOKBNOFdRHR5tkNxa7KrxnwQOxlaVzOhJuw6tzFk2Zf02e/ T1OLOsYKPgKmBHk46GqwZtlzJK5rs2ov19ujMi6NhQdXD98YNsENSp/x/U6QappEKu 5h6KWEfVTF405EMzWm+fAucUlQnBgktO5ubZK2vRbnQN10PFVksTr6UzL8Rt6EFJrY R0ggNq2Ivbx3CWptp7BWYLC6jLOxbHDosRmt8Qd2mNcvGxTxEvMGFDwdacGZaCDWlp 40GA+4Kcgw9JgZM+xggIBlLqHcIwdxronpPRp/WJpxyuVbudlte+wox39FUNHMURbs NFPRczvYRq0Lg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4f6kQs2wsfz4w9k; Fri, 06 Feb 2026 17:17:41 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 3/4] tcp: Extend tcp_send_flag() to send TCP keepalive segments Date: Fri, 6 Feb 2026 17:17:38 +1100 Message-ID: <20260206061739.33648-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260206061739.33648-1-david@gibson.dropbear.id.au> References: <20260206061739.33648-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: XF3NHRDPI3XUYNFE3ST44CTEQ7345LQ5 X-Message-ID-Hash: XF3NHRDPI3XUYNFE3ST44CTEQ7345LQ5 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: TCP keepalives aren't technically a flag, but they are a zero-data segment so they can be generated with only a small modification to tcp_{buf,vu}_send_flag(). Implement this, using a new "pseudo-flag" value (similar to DUP_ACK), KEEPALIVE. Signed-off-by: David Gibson --- tcp_buf.c | 4 ++++ tcp_internal.h | 2 ++ tcp_vu.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/tcp_buf.c b/tcp_buf.c index d2925410..18bdce81 100644 --- a/tcp_buf.c +++ b/tcp_buf.c @@ -227,6 +227,10 @@ int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) tcp_frame_conns[tcp_payload_used++] = conn; l4len = optlen + sizeof(struct tcphdr); iov[TCP_IOV_PAYLOAD].iov_len = l4len; + + if (flags & KEEPALIVE) + seq--; + tcp_l2_buf_fill_headers(c, conn, iov, NULL, seq, false); tcp_l2_buf_pad(iov); diff --git a/tcp_internal.h b/tcp_internal.h index 5f8fb358..36f443b4 100644 --- a/tcp_internal.h +++ b/tcp_internal.h @@ -38,6 +38,8 @@ /* Flags for internal usage */ #define DUP_ACK (1 << 5) +#define KEEPALIVE (1 << 6) + #define OPT_EOL 0 #define OPT_NOP 1 #define OPT_MSS 2 diff --git a/tcp_vu.c b/tcp_vu.c index b9e9b55e..f2d38aa5 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -135,6 +135,9 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) flags_elem[0].in_sg[0].iov_len = hdrlen + optlen; payload = IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen); + if (flags & KEEPALIVE) + seq--; + tcp_fill_headers(c, conn, NULL, eh, ip4h, ip6h, th, &payload, NULL, seq, !*c->pcap); -- 2.53.0