Browse Source

make sure all symbols that show up in the kernel are prefixed with ts3init_

pull/1/head
Niels Werensteijn 8 years ago
parent
commit
2bf9af83b9
  1. 8
      src/siphash24.c
  2. 1
      src/siphash24.h
  3. 45
      src/ts3init_match.c
  4. 14
      src/ts3init_target.c

8
src/siphash24.c

@ -25,12 +25,12 @@ enum
ts3init_dROUNDS = 4 ts3init_dROUNDS = 4
}; };
inline u64 ts3init_ROTL(u64 x, int b) static inline u64 ts3init_ROTL(u64 x, int b)
{ {
return (x << b) | (x >> (64 - b)); return (x << b) | (x >> (64 - b));
} }
inline u64 ts3init_U8TO64_LE(const u8* p) static inline u64 ts3init_U8TO64_LE(const u8* p)
{ {
return (((u64)(p[0])) | ((u64)(p[1]) << 8) | return (((u64)(p[0])) | ((u64)(p[1]) << 8) |
((u64)(p[2]) << 16) | ((u64)(p[3]) << 24) | ((u64)(p[2]) << 16) | ((u64)(p[3]) << 24) |
@ -38,7 +38,7 @@ inline u64 ts3init_U8TO64_LE(const u8* p)
((u64)(p[6]) << 48) | ((u64)(p[7]) << 56)); ((u64)(p[6]) << 48) | ((u64)(p[7]) << 56));
} }
inline void ts3init_SIPROUND(u64* v0, u64* v1, u64* v2, u64* v3) static inline void ts3init_SIPROUND(u64* v0, u64* v1, u64* v2, u64* v3)
{ {
*v0 += *v1; *v0 += *v1;
*v1 = ts3init_ROTL(*v1, 13); *v1 = ts3init_ROTL(*v1, 13);
@ -57,7 +57,7 @@ inline void ts3init_SIPROUND(u64* v0, u64* v1, u64* v2, u64* v3)
} }
inline void ts3init_TRACE(u64 v0, u64 v1, u64 v2, u64 v3, size_t inlen) static inline void ts3init_TRACE(u64 v0, u64 v1, u64 v2, u64 v3, size_t inlen)
{ {
#ifdef DEBUG #ifdef DEBUG
printk("(%d) v0 %x %x\n", (int)inlen, (u32)(v0 >> 32), (u32)v0); printk("(%d) v0 %x %x\n", (int)inlen, (u32)(v0 >> 32), (u32)v0);

1
src/siphash24.h

@ -26,7 +26,6 @@
#define printk printf #define printk printf
#define le64_to_cpu(x) x #define le64_to_cpu(x) x
#define cpu_to_le64(x) x #define cpu_to_le64(x) x
#define inline static inline
#else #else
#include <linux/kernel.h> #include <linux/kernel.h>
#endif #endif

45
src/ts3init_match.c

@ -34,18 +34,18 @@ static const struct ts3_init_header_tag ts3init_header_tag_signature =
{ .tag8 = {'T', 'S', '3', 'I', 'N', 'I', 'T', '1'} }; { .tag8 = {'T', 'S', '3', 'I', 'N', 'I', 'T', '1'} };
static const int header_size = 18; static const int header_size = 18;
static int payload_sizes[] = { 16, 20, 20, 244, -1, 1 }; static int ts3init_payload_sizes[] = { 16, 20, 20, 244, -1, 1 };
DEFINE_PER_CPU(struct ts3init_cache_t, ts3init_cache); DEFINE_PER_CPU(struct ts3init_cache_t, ts3init_cache);
bool check_header(const struct sk_buff *skb, const struct xt_action_param *par, static bool check_header(const struct sk_buff *skb, const struct xt_action_param *par,
struct ts3_init_checked_header_data* header_data) struct ts3_init_checked_header_data* header_data)
{ {
unsigned int data_len; unsigned int data_len;
struct udphdr *udp; struct udphdr *udp;
struct ts3_init_header* ts3_header; struct ts3_init_header* ts3_header;
int expected_payload_size; int expected_payload_size;
udp = skb_header_pointer(skb, par->thoff, sizeof(*udp), &header_data->udp_buf); udp = skb_header_pointer(skb, par->thoff, sizeof(*udp), &header_data->udp_buf);
data_len = be16_to_cpu(udp->len) - sizeof(*udp); data_len = be16_to_cpu(udp->len) - sizeof(*udp);
@ -64,9 +64,9 @@ bool check_header(const struct sk_buff *skb, const struct xt_action_param *par,
if (ts3_header->command >= COMMAND_MAX) return false; if (ts3_header->command >= COMMAND_MAX) return false;
/* TODO: check min_client_version if needed */ /* TODO: check min_client_version if needed */
/* TODO: add payload size check for COMMAND_SOLVE_PUZZLE */ /* TODO: add payload size check for COMMAND_SOLVE_PUZZLE */
expected_payload_size = payload_sizes[ts3_header->command]; expected_payload_size = ts3init_payload_sizes[ts3_header->command];
if (data_len != header_size + expected_payload_size) return false; if (data_len != header_size + expected_payload_size) return false;
header_data->udp = udp; header_data->udp = udp;
@ -93,12 +93,12 @@ ts3init_get_cookie_mt(const struct sk_buff *skb, struct xt_action_param *par)
{ {
const struct xt_ts3init_get_cookie_mtinfo *info = par->matchinfo; const struct xt_ts3init_get_cookie_mtinfo *info = par->matchinfo;
struct ts3_init_checked_header_data header_data; struct ts3_init_checked_header_data header_data;
if (!check_header(skb, par, &header_data)) if (!check_header(skb, par, &header_data))
return false; return false;
if (header_data.ts3_header->command != COMMAND_GET_COOKIE) return false; if (header_data.ts3_header->command != COMMAND_GET_COOKIE) return false;
if (info->specific_options & CHK_GET_COOKIE_CHECK_TIMESTAMP) if (info->specific_options & CHK_GET_COOKIE_CHECK_TIMESTAMP)
{ {
struct ts3init_cache_t* cache; struct ts3init_cache_t* cache;
@ -106,13 +106,13 @@ ts3init_get_cookie_mt(const struct sk_buff *skb, struct xt_action_param *par)
time_t current_unix_time, packet_unix_time; time_t current_unix_time, packet_unix_time;
jifs = jiffies; jifs = jiffies;
cache = &get_cpu_var(ts3init_cache); cache = &get_cpu_var(ts3init_cache);
update_cache_time(jifs, cache); update_cache_time(jifs, cache);
current_unix_time = cache->unix_time; current_unix_time = cache->unix_time;
put_cpu_var(ts3init_cache); put_cpu_var(ts3init_cache);
packet_unix_time = packet_unix_time =
@ -148,9 +148,9 @@ static int ts3init_get_cookie_mt_check(const struct xt_mtchk_param *par)
printk(KERN_INFO KBUILD_MODNAME ": invalid (specific) options for get_cookie\n"); printk(KERN_INFO KBUILD_MODNAME ": invalid (specific) options for get_cookie\n");
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }
static bool static bool
ts3init_get_puzzle_mt(const struct sk_buff *skb, struct xt_action_param *par) ts3init_get_puzzle_mt(const struct sk_buff *skb, struct xt_action_param *par)
@ -202,12 +202,12 @@ ts3init_get_puzzle_mt(const struct sk_buff *skb, struct xt_action_param *par)
/* compare cookie with payload bytes 0-7. if equal, cookie /* compare cookie with payload bytes 0-7. if equal, cookie
* is valid */ * is valid */
packet_cookie = (((u64)((ts3_header->payload)[0])) | ((u64)((ts3_header->payload)[1]) << 8) | packet_cookie = (((u64)((ts3_header->payload)[0])) | ((u64)((ts3_header->payload)[1]) << 8) |
((u64)((ts3_header->payload)[2]) << 16) | ((u64)((ts3_header->payload)[3]) << 24) | ((u64)((ts3_header->payload)[2]) << 16) | ((u64)((ts3_header->payload)[3]) << 24) |
((u64)((ts3_header->payload)[4]) << 32) | ((u64)((ts3_header->payload)[5]) << 40) | ((u64)((ts3_header->payload)[4]) << 32) | ((u64)((ts3_header->payload)[5]) << 40) |
((u64)((ts3_header->payload)[6]) << 48) | ((u64)((ts3_header->payload)[7]) << 56)); ((u64)((ts3_header->payload)[6]) << 48) | ((u64)((ts3_header->payload)[7]) << 56));
if (packet_cookie != cookie) return false; if (packet_cookie != cookie) return false;
} }
return true; return true;
@ -216,7 +216,7 @@ ts3init_get_puzzle_mt(const struct sk_buff *skb, struct xt_action_param *par)
static int ts3init_get_puzzle_mt_check(const struct xt_mtchk_param *par) static int ts3init_get_puzzle_mt_check(const struct xt_mtchk_param *par)
{ {
struct xt_ts3init_get_puzzle_mtinfo *info = par->matchinfo; struct xt_ts3init_get_puzzle_mtinfo *info = par->matchinfo;
if (! (par->family == NFPROTO_IPV4 || par->family == NFPROTO_IPV6)) if (! (par->family == NFPROTO_IPV4 || par->family == NFPROTO_IPV6))
{ {
printk(KERN_INFO KBUILD_MODNAME ": invalid protocol (only ipv4 and ipv6) for get_puzzle\n"); printk(KERN_INFO KBUILD_MODNAME ": invalid protocol (only ipv4 and ipv6) for get_puzzle\n");
@ -234,12 +234,13 @@ static int ts3init_get_puzzle_mt_check(const struct xt_mtchk_param *par)
printk(KERN_INFO KBUILD_MODNAME ": invalid (specific) options for get_cookie\n"); printk(KERN_INFO KBUILD_MODNAME ": invalid (specific) options for get_cookie\n");
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }
static struct xt_match ts3init_mt_reg[] __read_mostly = { static struct xt_match ts3init_mt_reg[] __read_mostly =
{
{ {
.name = "ts3init_get_cookie", .name = "ts3init_get_cookie",
.revision = 0, .revision = 0,
@ -282,12 +283,12 @@ static struct xt_match ts3init_mt_reg[] __read_mostly = {
}, },
}; };
int __init ts3init_match_init(void) int ts3init_match_init(void)
{ {
return xt_register_matches(ts3init_mt_reg, ARRAY_SIZE(ts3init_mt_reg)); return xt_register_matches(ts3init_mt_reg, ARRAY_SIZE(ts3init_mt_reg));
} }
void __exit ts3init_match_exit(void) void ts3init_match_exit(void)
{ {
xt_unregister_matches(ts3init_mt_reg, ARRAY_SIZE(ts3init_mt_reg)); xt_unregister_matches(ts3init_mt_reg, ARRAY_SIZE(ts3init_mt_reg));
} }

14
src/ts3init_target.c

@ -31,7 +31,7 @@
bool bool
send_ipv6(const struct sk_buff *oldskb, const struct xt_action_param *par, u8 command, const void *payload, const size_t payload_size) ts3init_send_ipv6(const struct sk_buff *oldskb, const struct xt_action_param *par, u8 command, const void *payload, const size_t payload_size)
{ {
const struct udphdr *oldudp; const struct udphdr *oldudp;
const struct ipv6hdr *oldip; const struct ipv6hdr *oldip;
@ -113,7 +113,7 @@ send_ipv6(const struct sk_buff *oldskb, const struct xt_action_param *par, u8 co
} }
bool bool
send_ipv4(const struct sk_buff *oldskb, const struct xt_action_param *par, u8 command, const void *payload, const size_t payload_size) ts3init_send_ipv4(const struct sk_buff *oldskb, const struct xt_action_param *par, u8 command, const void *payload, const size_t payload_size)
{ {
const struct udphdr *oldudp; const struct udphdr *oldudp;
const struct iphdr *oldip; const struct iphdr *oldip;
@ -185,7 +185,7 @@ send_ipv4(const struct sk_buff *oldskb, const struct xt_action_param *par, u8 co
return false; return false;
} }
static const char reset_package[] = {'T', 'S', '3', 'I', 'N', 'I', 'T', '1', 0x65, 0, 0x88, COMMAND_RESET_PUZZLE, 0 }; static const char ts3init_reset_package[] = {'T', 'S', '3', 'I', 'N', 'I', 'T', '1', 0x65, 0, 0x88, COMMAND_RESET_PUZZLE, 0 };
static unsigned int static unsigned int
ts3init_reset_tg(struct sk_buff *skb, const struct xt_action_param *par) ts3init_reset_tg(struct sk_buff *skb, const struct xt_action_param *par)
@ -193,11 +193,11 @@ ts3init_reset_tg(struct sk_buff *skb, const struct xt_action_param *par)
switch (par->family) switch (par->family)
{ {
case NFPROTO_IPV4: case NFPROTO_IPV4:
send_ipv4(skb, par, COMMAND_RESET_PUZZLE, reset_package, sizeof(reset_package)); ts3init_send_ipv4(skb, par, COMMAND_RESET_PUZZLE, ts3init_reset_package, sizeof(ts3init_reset_package));
break; break;
case NFPROTO_IPV6: case NFPROTO_IPV6:
send_ipv6(skb, par, COMMAND_RESET_PUZZLE, reset_package, sizeof(reset_package)); ts3init_send_ipv6(skb, par, COMMAND_RESET_PUZZLE, ts3init_reset_package, sizeof(ts3init_reset_package));
break; break;
} }
return NF_DROP; return NF_DROP;
@ -223,12 +223,12 @@ static struct xt_target ts3init_tg_reg[] __read_mostly =
}, },
}; };
int __init ts3init_target_init(void) int ts3init_target_init(void)
{ {
return xt_register_targets(ts3init_tg_reg, ARRAY_SIZE(ts3init_tg_reg)); return xt_register_targets(ts3init_tg_reg, ARRAY_SIZE(ts3init_tg_reg));
} }
void __exit ts3init_target_exit(void) void ts3init_target_exit(void)
{ {
xt_unregister_targets(ts3init_tg_reg, ARRAY_SIZE(ts3init_tg_reg)); xt_unregister_targets(ts3init_tg_reg, ARRAY_SIZE(ts3init_tg_reg));
} }

Loading…
Cancel
Save