Skip to content

Commit

Permalink
Add support for kernel 4.15
Browse files Browse the repository at this point in the history
Fixes #260
  • Loading branch information
ydahhrk committed Mar 8, 2018
1 parent 9dfaf22 commit 8f42b91
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion 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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 8f42b91

Please sign in to comment.