From 8f42b91b4d61f6a059d4c054d1535f2600feaf8a Mon Sep 17 00:00:00 2001 From: Alberto Leiva Popper Date: Thu, 8 Mar 2018 12:35:20 -0600 Subject: [PATCH] Add support for kernel 4.15 Fixes #260 --- mod/stateful/timer.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/mod/stateful/timer.c b/mod/stateful/timer.c index 51b6cd244..25e087c7c 100644 --- a/mod/stateful/timer.c +++ b/mod/stateful/timer.c @@ -1,10 +1,24 @@ #include "nat64/mod/stateful/timer.h" +#include "nat64/mod/common/linux_version.h" #include "nat64/mod/common/xlator.h" #include "nat64/mod/stateful/fragment_db.h" #include "nat64/mod/stateful/joold.h" #include "nat64/mod/stateful/bib/db.h" +/* + * TODO We don't cancel the timer much at all; it seems like we should be using + * a hrtimer instead. + * + * the kernel has two core timer mechanisms. One of those — the + * high-resolution timer (or "hrtimer") — subsystem, is focused on + * near-term events where the timer is expected to run to completion. The + * other subsystem is just called "kernel timers"; it offers less precision + * but is more efficient in situations where the timer will probably be + * canceled before it fires. + * (Jonathan Corbet, 2017) + */ + #define TIMER_PERIOD msecs_to_jiffies(2000) static struct timer_list timer; @@ -17,7 +31,13 @@ static int clean_state(struct xlator *jool, void *args) return 0; } -static void timer_function(unsigned long arg) +static void timer_function( +#if LINUX_VERSION_AT_LEAST(4, 15, 0, 9999, 0) + struct timer_list *arg +#else + unsigned long arg +#endif + ) { xlator_foreach(clean_state, NULL); mod_timer(&timer, jiffies + TIMER_PERIOD); @@ -28,10 +48,14 @@ static void timer_function(unsigned long arg) */ int timer_init(void) { +#if LINUX_VERSION_AT_LEAST(4, 15, 0, 9999, 0) + timer_setup(&timer, timer_function, 0); +#else init_timer(&timer); timer.function = timer_function; timer.expires = 0; timer.data = 0; +#endif mod_timer(&timer, jiffies + TIMER_PERIOD); return 0; }