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=Ldzm+qOz; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id AD7AE5A026D for ; Fri, 31 Jul 2026 18:23:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785515022; 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=lnkcvt/AxZCgQk/LXHY2RWrTEYsgh1AvXGJ7/+ipVnc=; b=Ldzm+qOzy8aE5Z+rb1mcu+PIeTObMnc2NtOQASvLY0KmB6vHcrweg4Uwwr0pwU8JE8RSD1 5DdbTkUtNA0QHVUNLE9nCyhDVehuClWBTZLyTgVShJUqZgFnP7C88zMhs/wvrYdrNDn90e K2RvXUYqmIJKRdHQyenjS0bqqhiLLfE= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-OkdrlQA4PAGO9lrMErTAUw-1; Fri, 31 Jul 2026 12:23:41 -0400 X-MC-Unique: OkdrlQA4PAGO9lrMErTAUw-1 X-Mimecast-MFC-AGG-ID: OkdrlQA4PAGO9lrMErTAUw_1785515020 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 32C5319560AE for ; Fri, 31 Jul 2026 16:23:40 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 580561956044; Fri, 31 Jul 2026 16:23:39 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2 08/10] tcp: Extract tcp_timer_epoll_add() helper Date: Fri, 31 Jul 2026 18:23:27 +0200 Message-ID: <20260731162329.3552800-9-lvivier@redhat.com> In-Reply-To: <20260731162329.3552800-1-lvivier@redhat.com> References: <20260731162329.3552800-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: lnYO7hA3vLO8yS51D4LJBCNebIk7OHh7PPkgqPhFB6A_1785515020 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 3ZKW52DLW563OV323BKKOCCJ5IN7L5UP X-Message-ID-Hash: 3ZKW52DLW563OV323BKKOCCJ5IN7L5UP 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: Factor out the epoll registration of TCP timers from tcp_timer_ctl() into a separate tcp_timer_epoll_add() helper. Signed-off-by: Laurent Vivier --- tcp.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tcp.c b/tcp.c index aef689faf031..88caf5d8968b 100644 --- a/tcp.c +++ b/tcp.c @@ -545,6 +545,22 @@ static int tcp_epoll_ctl(struct tcp_tap_conn *conn) return 0; } +static int tcp_timer_epoll_add(struct tcp_tap_conn *conn, int fd, + const struct timespec *now) +{ + union epoll_ref ref; + + 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_perror_ratelimit(conn, now, "failed to add timer"); + return -1; + } + + return 0; +} + /** * tcp_timer_ctl() - Set timerfd based on flags/events, create timerfd if needed * @c: Execution context @@ -562,7 +578,6 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn, return; if (conn->timer == -1) { - union epoll_ref ref; int fd; fd = timerfd_create(CLOCK_MONOTONIC, 0); @@ -578,12 +593,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn, return; } - 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_perror_ratelimit(conn, now, "failed to add timer"); + if (tcp_timer_epoll_add(conn, fd, now) < 0) { close(fd); return; } -- 2.54.0