From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=F6xd/MGt; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 7415E5A0624 for ; Fri, 09 Jan 2026 17:54:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767977687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sS+q/W+1yL6ni0QeGuoXbrn1bO38qsfoFW5N5YVFGKc=; b=F6xd/MGtvYzkH5WzRLqnYG6kRdKbrUdUfjEFLfuYEHlwJJ+1EW2oX62jcJaWOmHOuRd9p8 DQmqBaKF0NTbM2UaMcjCYOUtAV2PfGmKmU2EUs3s234ovHloN1GCNpgJfwB8UYGEEHKSko ACbhZ7QHEw76a5PoRV1aWs7x9ss27Z0= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-t672rwloPOykp-mNBaTaqw-1; Fri, 09 Jan 2026 11:54:45 -0500 X-MC-Unique: t672rwloPOykp-mNBaTaqw-1 X-Mimecast-MFC-AGG-ID: t672rwloPOykp-mNBaTaqw_1767977685 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 04EFE18005BA for ; Fri, 9 Jan 2026 16:54:45 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.149]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EA13C1955F66; Fri, 9 Jan 2026 16:54:43 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v3 2/6] tcp: cleanup timer creation Date: Fri, 9 Jan 2026 17:54:34 +0100 Message-ID: <20260109165438.2492285-3-lvivier@redhat.com> In-Reply-To: <20260109165438.2492285-1-lvivier@redhat.com> References: <20260109165438.2492285-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vQsw_HeskBQ35i9iT7xSSmnLncLU1N_yLn0O4xuPbkc_1767977685 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 2J7BS5G2JJLOJUV4FXGGRC2XFU7QLZK3 X-Message-ID-Hash: 2J7BS5G2JJLOJUV4FXGGRC2XFU7QLZK3 X-MailFrom: lvivier@redhat.com 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: Laurent Vivier 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: Refactor tcp_timer_ctl() to use the epoll_add() helper instead of manually constructing epoll_event and calling epoll_ctl() directly. Also separate the error handling for timerfd_create() failure (-1) from fd overflow (> FD_REF_MAX) to provide more specific debug messages. The overflow case now logs the actual fd value, using flow_dbg_perror() in this case was not correct (no errno set). Delay setting conn->timer until epoll_add() succeeds, removing redundant conn->timer = -1 assignments in error paths since the timer is already -1 when we enter this block. Signed-off-by: Laurent Vivier --- tcp.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tcp.c b/tcp.c index 5141cdc7e839..4b746b4ca16c 100644 --- a/tcp.c +++ b/tcp.c @@ -569,30 +569,32 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn) return; if (conn->timer == -1) { - union epoll_ref ref = { .type = EPOLL_TYPE_TCP_TIMER, - .flow = FLOW_IDX(conn) }; - struct epoll_event ev = { .data.u64 = ref.u64, - .events = EPOLLIN | EPOLLET }; - int epollfd = flow_epollfd(&conn->f); + union epoll_ref ref; int fd; fd = timerfd_create(CLOCK_MONOTONIC, 0); - if (fd == -1 || fd > FD_REF_MAX) { + if (fd == -1) { flow_dbg_perror(conn, "failed to get timer"); - if (fd > -1) - close(fd); - conn->timer = -1; return; } - conn->timer = fd; - ref.fd = conn->timer; + if (fd > FD_REF_MAX) { + flow_dbg(conn, "timer fd overflow (%d > %d)", + fd, FD_REF_MAX); + close(fd); + return; + } - if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn->timer, &ev)) { - flow_dbg_perror(conn, "failed to add timer"); - close(conn->timer); - conn->timer = -1; + ref.type = EPOLL_TYPE_TCP_TIMER; + ref.flow = FLOW_IDX(conn); + ref.fd = fd; + if (epoll_add(flow_epollfd(&conn->f), EPOLLIN | EPOLLET, + ref) < 0) { + flow_dbg(conn, "failed to add timer"); + close(fd); return; } + + conn->timer = fd; } if (conn->flags & ACK_TO_TAP_DUE) { -- 2.52.0