From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 435995A0619; Thu, 04 Dec 2025 22:25:30 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] tcp: Enable SO_KEEPALIVE if we see keep-alive segments from container / guest Date: Thu, 4 Dec 2025 22:25:30 +0100 Message-ID: <20251204212530.2237432-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NBXTODGVJY72GERARYBC5TKVGEAY2BOO X-Message-ID-Hash: NBXTODGVJY72GERARYBC5TKVGEAY2BOO X-MailFrom: sbrivio@passt.top 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: Dominic Kohls 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: This is an approximation, as enabling SO_KEEPALIVE doesn't mean that a keep-alive segment will be sent right away, rather that keep-alive segments will start being sent if the connection is idle. On the other hand, we don't have direct control over the host-side TCP, so this is probably the best approximation we can get. By default, namespaces inherit keep-alive parameters from their parent namespace, so we can assume that, in case of a container, we'll wait for the same interval it took for the container to start sending us keep-alives, effectively doubling that interval. To keep this simple, set SO_KEEPALIVE whenever we see a keep-alive segment, instead of tracking its state. Keep-alive segments are relatively infrequent, so we don't expect any substantial cost from doing that. Reported-by: Dominic Kohls Signed-off-by: Stefano Brivio --- tcp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tcp.c b/tcp.c index 8357c0e..c5486bc 100644 --- a/tcp.c +++ b/tcp.c @@ -1838,6 +1838,9 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, tcp_send_flag(c, conn, ACK); tcp_timer_ctl(c, conn); + setsockopt(conn->sock, SOL_SOCKET, SO_KEEPALIVE, + &((int){ 1 }), sizeof(int)); + if (p->count == 1) { tcp_tap_window_update(c, conn, ntohs(th->window)); -- 2.43.0