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=h3zEAssR; 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 DF2815A0262 for ; Tue, 02 Jun 2026 15:17:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780406232; 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; bh=3YUMwtRar2MofkxR70vCPU+yUSKRnZCpSWk/7rajSdo=; b=h3zEAssRxxtsn2r3tStAU5oaSuQ8rc/k0WsMbB4S5eB7H1rjQRTe57ifmtGqLWCkzmY7Ix lH6E0U19HtvXtRJrUXdD1SfPVTwZRVfmveTTGgFHMmfyxCHZNP7y5QS/ChFrG+7Dkr4duA EClppcsLHrpyO+x3uCcI4qnosJ+pzV4= Received: from mx-prod-mc-03.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-639-WpTeUWYDOuWRkeWASPpFlw-1; Tue, 02 Jun 2026 09:17:11 -0400 X-MC-Unique: WpTeUWYDOuWRkeWASPpFlw-1 X-Mimecast-MFC-AGG-ID: WpTeUWYDOuWRkeWASPpFlw_1780406230 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 55C7F1955DE4 for ; Tue, 2 Jun 2026 13:17:10 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7780C30001A2; Tue, 2 Jun 2026 13:17:09 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH] passt, tcp: Inline CALL_PROTO_HANDLER() and merge tcp_timer() Date: Tue, 2 Jun 2026 15:17:08 +0200 Message-ID: <20260602131708.2726632-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PoqNhrPymSxjRwarNVzPZ5aIvf6marvS2OJpYVr9uLc_1780406230 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: K4DPH4UJQB7BPNMEYWJDCBOAKUTWNUOF X-Message-ID-Hash: K4DPH4UJQB7BPNMEYWJDCBOAKUTWNUOF 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: Since 260075bde769 ("tcp, udp, fwd: Run all port scanning from a single timer"), CALL_PROTO_HANDLER() has only one user (tcp), so inline it at the call site and remove the macro. Merge tcp_timer() into tcp_defer_handler(), moving the timer interval check there, matching the pattern used by flow_defer_handler() and fwd_scan_ports_timer(). The weak declaration and null check for tcp_defer_handler are also dropped as the function is always defined. Signed-off-by: Laurent Vivier --- passt.c | 23 ++--------------------- tcp.c | 22 ++++++++++------------ tcp.h | 3 +-- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/passt.c b/passt.c index b6fc12d4ed81..b3f806b9a15e 100644 --- a/passt.c +++ b/passt.c @@ -101,27 +101,8 @@ struct passt_stats { */ static void post_handler(struct ctx *c, const struct timespec *now) { -#define CALL_PROTO_HANDLER(lc, uc) \ - do { \ - extern void \ - lc ## _defer_handler (struct ctx *c) \ - __attribute__ ((weak)); \ - \ - if (!c->no_ ## lc) { \ - if (lc ## _defer_handler) \ - lc ## _defer_handler(c); \ - \ - if (timespec_diff_ms((now), &c->lc.timer_run) \ - >= uc ## _TIMER_INTERVAL) { \ - lc ## _timer(c, now); \ - c->lc.timer_run = *now; \ - } \ - } \ - } while (0) - - /* NOLINTNEXTLINE(bugprone-branch-clone): intervals can be the same */ - CALL_PROTO_HANDLER(tcp, TCP); -#undef CALL_PROTO_HANDLER + if (!c->no_tcp) + tcp_defer_handler(c, now); flow_defer_handler(c, now); fwd_scan_ports_timer(c, now); diff --git a/tcp.c b/tcp.c index 0fb8da05cb65..c400075440c9 100644 --- a/tcp.c +++ b/tcp.c @@ -895,16 +895,6 @@ bool tcp_flow_defer(const struct tcp_tap_conn *conn) return true; } -/** - * tcp_defer_handler() - Handler for TCP deferred tasks - * @c: Execution context - */ -/* cppcheck-suppress [constParameterPointer, unmatchedSuppression] */ -void tcp_defer_handler(struct ctx *c) -{ - tcp_payload_flush(c); -} - /** * tcp_fill_header() - Fill the TCP header fields for a given TCP segment. * @@ -3005,12 +2995,20 @@ static void tcp_inactivity(struct ctx *c, const struct timespec *now) } /** - * tcp_timer() - Periodic tasks: port detection, closed connections, pool refill + * tcp_defer_handler() - Handler for TCP deferred tasks * @c: Execution context * @now: Current timestamp */ -void tcp_timer(struct ctx *c, const struct timespec *now) +/* cppcheck-suppress [constParameterPointer, unmatchedSuppression] */ +void tcp_defer_handler(struct ctx *c, const struct timespec *now) { + tcp_payload_flush(c); + + if (timespec_diff_ms(now, &c->tcp.timer_run) < TCP_TIMER_INTERVAL) + return; + + c->tcp.timer_run = *now; + tcp_sock_refill_init(c); if (c->mode == MODE_PASTA) tcp_splice_refill(c); diff --git a/tcp.h b/tcp.h index 8a0eb930b54b..3262a807e5d4 100644 --- a/tcp.h +++ b/tcp.h @@ -29,8 +29,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, int tcp_listen(const struct ctx *c, uint8_t pif, unsigned rule, const union inany_addr *addr, const char *ifname, in_port_t port); int tcp_init(struct ctx *c); -void tcp_timer(struct ctx *c, const struct timespec *now); -void tcp_defer_handler(struct ctx *c); +void tcp_defer_handler(struct ctx *c, const struct timespec *now); void tcp_update_l2_buf(const unsigned char *eth_d); -- 2.54.0