From eef4e82903311c73a5da3030da7eee790ce783a5 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 5 Oct 2021 19:20:26 +0200 Subject: passt: Add handler for optional deferred tasks We'll need this for TCP ACK coalescing on tap/guest-side. For convenience, allow _handler() functions to be undefined, courtesy of __attribute__((weak)). Signed-off-by: Stefano Brivio --- passt.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'passt.c') diff --git a/passt.c b/passt.c index fa3d80a..1f5f60d 100644 --- a/passt.c +++ b/passt.c @@ -101,29 +101,35 @@ static void sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events, } /** - * timer_handler() - Run periodic tasks for L4 protocol handlers + * post_handler() - Run periodic and deferred tasks for L4 protocol handlers * @c: Execution context * @now: Current timestamp */ -static void timer_handler(struct ctx *c, struct timespec *now) +static void post_handler(struct ctx *c, struct timespec *now) { - if (!c->no_tcp && - timespec_diff_ms(now, &c->tcp.timer_run) >= TCP_TIMER_INTERVAL) { - tcp_timer(c, now); - c->tcp.timer_run = *now; - } - - if (!c->no_udp && - timespec_diff_ms(now, &c->udp.timer_run) >= UDP_TIMER_INTERVAL) { - udp_timer(c, now); - c->udp.timer_run = *now; - } - - if (!c->no_icmp && - timespec_diff_ms(now, &c->icmp.timer_run) >= ICMP_TIMER_INTERVAL) { - icmp_timer(c, now); - c->icmp.timer_run = *now; - } +#define CALL_PROTO_HANDLER(c, now, 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) + + CALL_PROTO_HANDLER(c, now, tcp, TCP); + CALL_PROTO_HANDLER(c, now, udp, UDP); + CALL_PROTO_HANDLER(c, now, icmp, ICMP); + +#undef CALL_PROTO_HANDLER } /** @@ -411,7 +417,7 @@ loop: sock_handler(&c, ref, events[i].events, &now); } - timer_handler(&c, &now); + post_handler(&c, &now); goto loop; -- cgit v1.2.3