From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH] passt, tcp: Inline CALL_PROTO_HANDLER() and merge tcp_timer()
Date: Wed, 3 Jun 2026 12:37:29 +1000 [thread overview]
Message-ID: <ah-TadrcmlW_DtK1@zatzit> (raw)
In-Reply-To: <20260602131708.2726632-1-lvivier@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4070 bytes --]
On Tue, Jun 02, 2026 at 03:17:08PM +0200, Laurent Vivier wrote:
> 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 <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> 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
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2026-06-03 2:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 13:17 Laurent Vivier
2026-06-03 2:37 ` David Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ah-TadrcmlW_DtK1@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).