Skip to content

support for newer kernels / Ubuntu 20.04 #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ clean:
$(MAKE) -C src -f Makefile.xtables clean;
$(MAKE) -C test clean;

install:
install: all
$(MAKE) -C src modules_install;
$(MAKE) -C src -f Makefile.xtables install;
depmod -a

3 changes: 2 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- Makefile -*-
MODULES_DIR := /lib/modules/$(shell uname -r)
KVER := $(shell uname -r)
MODULES_DIR := /lib/modules/${KVER}
KERNEL_DIR := ${MODULES_DIR}/build

obj-m += xt_ts3init.o
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.xtables
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:
fi

lib%.so: lib%.o
gcc -shared -fPIC -o $@ $^;
gcc -shared -fPIC -o $@ $^ -lxtables;

lib%.o: lib%.c
gcc ${CFLAGS} -D_INIT=lib$*_init -fPIC -c -o $@ $<;
Expand Down
19 changes: 9 additions & 10 deletions src/ts3init_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
struct ts3init_cache_t
{
unsigned long saved_jiffies;
time_t unix_time;
ktime_t unix_time;
struct xt_ts3init_cookie_cache cookie_cache;
};

Expand All @@ -35,22 +35,21 @@ DEFINE_PER_CPU(struct ts3init_cache_t, ts3init_cache);
static inline void update_cache_time(unsigned long jifs,
struct ts3init_cache_t* cache)
{
if (((long)jifs - (long)cache->saved_jiffies) >= HZ)
{
struct timespec64 now;
if (unlikely(((long)jifs - (long)cache->saved_jiffies) >= HZ)){
/* it's been 1 second sinds last time update.
* Get the new unix time and cache it*/
struct timeval tv;
cache->saved_jiffies = jifs;
do_gettimeofday(&tv);
cache->unix_time = tv.tv_sec;
ktime_get_real_ts64(&now);
cache->unix_time = now.tv_sec;
}
}

time_t ts3init_get_cached_unix_time(void)
ktime_t ts3init_get_cached_unix_time(void)
{
struct ts3init_cache_t* cache;
unsigned long jifs;
time_t current_unix_time;
ktime_t current_unix_time;

jifs = jiffies;

Expand All @@ -70,7 +69,7 @@ bool ts3init_get_cookie_seed_for_packet_index(u8 packet_index, const u8* random_
struct ts3init_cache_t* cache;
u64* result;
unsigned long jifs;
time_t current_unix_time;
ktime_t current_unix_time;

jifs = jiffies;
cache = &get_cpu_var(ts3init_cache);
Expand All @@ -96,7 +95,7 @@ bool ts3init_get_current_cookie_seed(const u8* random_seed, u64 (*cookie)[2], u8
struct ts3init_cache_t* cache;
u64* result;
unsigned long jifs;
time_t current_unix_time;
ktime_t current_unix_time;

jifs = jiffies;
cache = &get_cpu_var(ts3init_cache);
Expand Down
2 changes: 1 addition & 1 deletion src/ts3init_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*
* Returns the current unix_time from cache, updated once every second.
*/
time_t ts3init_get_cached_unix_time(void);
ktime_t ts3init_get_cached_unix_time(void);


/*
Expand Down
11 changes: 5 additions & 6 deletions src/ts3init_cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
static struct crypto_shash *sha512_tfm;


static void check_update_seed_cache(time_t time, __u8 index,
static void check_update_seed_cache(ktime_t time, __u8 index,
struct xt_ts3init_cookie_cache* cache,
const __u8* random_seed)
{
Expand All @@ -58,7 +58,6 @@ static void check_update_seed_cache(time_t time, __u8 index,
{
SHASH_DESC_ON_STACK(shash, sha512_tfm);
shash->tfm = sha512_tfm;
shash->flags = 0;

ret = crypto_shash_init(shash);
if (ret != 0)
Expand Down Expand Up @@ -86,23 +85,23 @@ static void check_update_seed_cache(time_t time, __u8 index,
}
}

__u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index,
__u64* ts3init_get_cookie_seed(ktime_t current_time, __u8 packet_index,
struct xt_ts3init_cookie_cache* cache,
const __u8* random_seed)
{

__u8 current_cache_index;
__u8 packet_cache_index;
time_t current_cache_time;
time_t packet_cache_time;
ktime_t current_cache_time;
ktime_t packet_cache_time;

if (packet_index >= 8) return NULL;

current_cache_index = (current_time % 8) / 4;
packet_cache_index = packet_index / 4;

/* get cache time of packet */
current_cache_time = current_time & ~((time_t)3);
current_cache_time = current_time & ~((ktime_t)3);
packet_cache_time = current_cache_time
- ((current_cache_index ^ packet_cache_index)*4);

Expand Down
4 changes: 2 additions & 2 deletions src/ts3init_cookie.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum

struct xt_ts3init_cookie_cache
{
time_t time[2];
ktime_t time[2];
union
{
__u8 seed8[SHA512_SIZE*2];
Expand All @@ -22,7 +22,7 @@ struct xt_ts3init_cookie_cache
* If the cookie seed is missing in cache it will be generated using
* random_seed and current_time
*/
__u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index,
__u64* ts3init_get_cookie_seed(ktime_t current_time, __u8 packet_index,
struct xt_ts3init_cookie_cache* cache,
const __u8* random_seed);

Expand Down
2 changes: 1 addition & 1 deletion src/ts3init_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ts3init_get_cookie_mt(const struct sk_buff *skb, struct xt_action_param *par)
if (info->specific_options & CHK_GET_COOKIE_CHECK_TIMESTAMP)
{
__u8 *payload, payload_buf[ts3init_payload_sizes[COMMAND_GET_COOKIE]];
time_t current_unix_time, packet_unix_time;
ktime_t current_unix_time, packet_unix_time;

payload = get_payload(skb, par, &header_data, payload_buf, sizeof(payload_buf));
if (!payload)
Expand Down
Loading