aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-10-05 19:20:26 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-10-05 19:20:26 +0200
commiteef4e82903311c73a5da3030da7eee790ce783a5 (patch)
tree0b2b591aa5ef51784be2f9a139b0fdcf1c016d4f
parent529b245d2be1963c29c5688bca6bf14e5f3e2a66 (diff)
downloadpasst-eef4e82903311c73a5da3030da7eee790ce783a5.tar
passt-eef4e82903311c73a5da3030da7eee790ce783a5.tar.gz
passt-eef4e82903311c73a5da3030da7eee790ce783a5.tar.bz2
passt-eef4e82903311c73a5da3030da7eee790ce783a5.tar.lz
passt-eef4e82903311c73a5da3030da7eee790ce783a5.tar.xz
passt-eef4e82903311c73a5da3030da7eee790ce783a5.tar.zst
passt-eef4e82903311c73a5da3030da7eee790ce783a5.zip
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>
-rw-r--r--passt.c46
1 files changed, 26 insertions, 20 deletions
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;