1
0
mirror of https://passt.top/passt synced 2024-10-02 03:55:48 +00:00

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 <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-10-05 19:20:26 +02:00
parent 529b245d2b
commit eef4e82903

42
passt.c
View File

@ -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 * @c: Execution context
* @now: Current timestamp * @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 && #define CALL_PROTO_HANDLER(c, now, lc, uc) \
timespec_diff_ms(now, &c->tcp.timer_run) >= TCP_TIMER_INTERVAL) { do { \
tcp_timer(c, now); extern void \
c->tcp.timer_run = *now; 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)
if (!c->no_udp && CALL_PROTO_HANDLER(c, now, tcp, TCP);
timespec_diff_ms(now, &c->udp.timer_run) >= UDP_TIMER_INTERVAL) { CALL_PROTO_HANDLER(c, now, udp, UDP);
udp_timer(c, now); CALL_PROTO_HANDLER(c, now, icmp, ICMP);
c->udp.timer_run = *now;
}
if (!c->no_icmp && #undef CALL_PROTO_HANDLER
timespec_diff_ms(now, &c->icmp.timer_run) >= ICMP_TIMER_INTERVAL) {
icmp_timer(c, now);
c->icmp.timer_run = *now;
}
} }
/** /**
@ -411,7 +417,7 @@ loop:
sock_handler(&c, ref, events[i].events, &now); sock_handler(&c, ref, events[i].events, &now);
} }
timer_handler(&c, &now); post_handler(&c, &now);
goto loop; goto loop;