From 75c9fd8642d5a1e81de6b30da7dfd9a57e093ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20M=C3=BCnchow?= Date: Fri, 14 Oct 2016 12:39:47 +0200 Subject: [PATCH] renamed variables, parameters, constants, fields and files that contain or are about the user supplied seed to random_seeed. --- src/libxt_TS3INIT_MORPH_TO_GET_COOKIE.c | 2 +- src/libxt_TS3INIT_RESET.c | 2 +- src/libxt_TS3INIT_SET_COOKIE.c | 68 +++++++++---------- src/libxt_ts3init_get_cookie.c | 2 +- src/libxt_ts3init_get_puzzle.c | 60 ++++++++-------- src/ts3init_cache.c | 8 +-- src/ts3init_cache.h | 8 +-- src/ts3init_cookie.c | 12 ++-- src/ts3init_cookie.h | 4 +- src/ts3init_match.c | 4 +- src/ts3init_match.h | 12 ++-- ...it_cookie_seed.h => ts3init_random_seed.h} | 18 ++--- src/ts3init_target.c | 6 +- src/ts3init_target.h | 12 ++-- 14 files changed, 109 insertions(+), 109 deletions(-) rename src/{ts3init_cookie_seed.h => ts3init_random_seed.h} (77%) diff --git a/src/libxt_TS3INIT_MORPH_TO_GET_COOKIE.c b/src/libxt_TS3INIT_MORPH_TO_GET_COOKIE.c index fbdb9f5..dde709e 100644 --- a/src/libxt_TS3INIT_MORPH_TO_GET_COOKIE.c +++ b/src/libxt_TS3INIT_MORPH_TO_GET_COOKIE.c @@ -17,7 +17,7 @@ #include #include #include -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_target.h" static void ts3init_morph_to_get_cookie_help(void) diff --git a/src/libxt_TS3INIT_RESET.c b/src/libxt_TS3INIT_RESET.c index 9283520..415ce6e 100644 --- a/src/libxt_TS3INIT_RESET.c +++ b/src/libxt_TS3INIT_RESET.c @@ -17,7 +17,7 @@ #include #include #include -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_target.h" static void ts3init_reset_help(void) diff --git a/src/libxt_TS3INIT_SET_COOKIE.c b/src/libxt_TS3INIT_SET_COOKIE.c index a1480ab..451f8b0 100644 --- a/src/libxt_TS3INIT_SET_COOKIE.c +++ b/src/libxt_TS3INIT_SET_COOKIE.c @@ -17,7 +17,7 @@ #include #include #include -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_target.h" #define param_act(t, s, f) xtables_param_act((t), "ts3init_set_cookie", (s), (f)) @@ -27,20 +27,20 @@ static void ts3init_set_cookie_tg_help(void) printf( "TS3INIT_SET_COOKIE target options:\n" " --zero-random-sequence Always return 0 as random sequence.\n" - " --seed Seed is a %i byte lowercase hex number in.\n" + " --random-seed Seed is a %i byte lowercase hex number in.\n" " A source could be /dev/random.\n" - " --seed-file Read the seed from a file.\n", - COOKIE_SEED_LEN); + " --random-seed-file Read the seed from a file.\n", + RANDOM_SEED_LEN); } static const struct option ts3init_set_cookie_tg_opts[] = { {.name = "zero-random-sequence", .has_arg = false, .val = '1'}, - {.name = "seed", .has_arg = true, .val = '2'}, - {.name = "seed-file", .has_arg = true, .val = '3'}, + {.name = "random-seed", .has_arg = true, .val = '2'}, + {.name = "random-seed-file", .has_arg = true, .val = '3'}, {NULL}, }; -static int ts3init_set_cookie_tg_parse(int c, char **argv, +static int ts3init_set_cookie_tg_parse(int c, char **argv, int invert, unsigned int *flags, const void *entry, struct xt_entry_target **target) { @@ -52,26 +52,26 @@ static int ts3init_set_cookie_tg_parse(int c, char **argv, info->specific_options |= TARGET_SET_COOKIE_ZERO_RANDOM_SEQUENCE; return true; case '2': - param_act(XTF_ONLY_ONCE, "--seed", *flags & TARGET_SET_COOKIE_SEED_FROM_ARGUMENT); - param_act(XTF_NO_INVERT, "--seed", invert); - if (strlen(optarg) != (COOKIE_SEED_LEN * 2)) + param_act(XTF_ONLY_ONCE, "--random-seed", *flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT); + param_act(XTF_NO_INVERT, "--random-seed", invert); + if (strlen(optarg) != (RANDOM_SEED_LEN * 2)) xtables_error(PARAMETER_PROBLEM, - "TS3INIT_SET_COOKIE: invalid seed length"); - if (!hex2int_seed(optarg, info->cookie_seed)) + "TS3INIT_SET_COOKIE: invalid random seed length"); + if (!parse_random_seed(optarg, info->random_seed)) xtables_error(PARAMETER_PROBLEM, - "TS3INIT_SET_COOKIE: invalid seed. (not lowercase hex)"); - info->specific_options |= TARGET_SET_COOKIE_SEED_FROM_ARGUMENT; - *flags |= TARGET_SET_COOKIE_SEED_FROM_ARGUMENT; + "TS3INIT_SET_COOKIE: invalid random seed. (not lowercase hex)"); + info->specific_options |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT; + *flags |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT; return true; case '3': - param_act(XTF_ONLY_ONCE, "--seed-file", *flags & TARGET_SET_COOKIE_SEED_FROM_FILE); - param_act(XTF_NO_INVERT, "--seed-file", invert); + param_act(XTF_ONLY_ONCE, "--random-seed-file", *flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE); + param_act(XTF_NO_INVERT, "--random-seed-file", invert); - if (read_cookie_seed_from_file("TS3INIT_SET_COOKIE", optarg, info->cookie_seed)) - memcpy(info->cookie_seed_path, optarg, strlen(optarg) + 1); - info->specific_options |= TARGET_SET_COOKIE_SEED_FROM_FILE; - *flags |= TARGET_SET_COOKIE_SEED_FROM_FILE; + if (read_random_seed_from_file("TS3INIT_SET_COOKIE", optarg, info->random_seed)) + memcpy(info->random_seed_path, optarg, strlen(optarg) + 1); + info->specific_options |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE; + *flags |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE; return true; default: @@ -86,18 +86,18 @@ static void ts3init_set_cookie_tg_save(const void *ip, const struct xt_entry_tar { printf("--zero-random-sequence "); } - if (info->specific_options & TARGET_SET_COOKIE_SEED_FROM_ARGUMENT) + if (info->specific_options & TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT) { - printf("--seed "); - for (int i = 0; i < COOKIE_SEED_LEN; i++) + printf("--random-seed "); + for (int i = 0; i < RANDOM_SEED_LEN; i++) { - printf("%02X", info->cookie_seed[i]); + printf("%02X", info->random_seed[i]); } printf(" "); } - if (info->specific_options & TARGET_SET_COOKIE_SEED_FROM_FILE) + if (info->specific_options & TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE) { - printf("--seed-file \"%s\" ", info->cookie_seed_path); + printf("--random-seed-file \"%s\" ", info->random_seed_path); } } @@ -110,18 +110,18 @@ static void ts3init_set_cookie_tg_print(const void *ip, const struct xt_entry_ta static void ts3init_set_cookie_tg_check(unsigned int flags) { - bool seed_from_argument = flags & TARGET_SET_COOKIE_SEED_FROM_ARGUMENT; - bool seed_from_file = flags & TARGET_SET_COOKIE_SEED_FROM_FILE; - if (seed_from_argument && seed_from_file) + bool random_seed_from_argument = flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT; + bool random_seed_from_file = flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE; + if (random_seed_from_argument && random_seed_from_file) { xtables_error(PARAMETER_PROBLEM, - "TS3INIT_SET_COOKIE: --seed and --seed-file " - "can not be specified at the same time"); + "TS3INIT_SET_COOKIE: --random-seed and --random-seed-file " + "can not be specified at the same time"); } - if (!seed_from_argument && !seed_from_file) + if (!random_seed_from_argument && !random_seed_from_file) { xtables_error(PARAMETER_PROBLEM, - "TS3INIT_SET_COOKIE: either --seed or --seed-file " + "TS3INIT_SET_COOKIE: either --random-seed or --random-seed-file " "must be specified"); } } diff --git a/src/libxt_ts3init_get_cookie.c b/src/libxt_ts3init_get_cookie.c index 0f5089b..95eaa58 100644 --- a/src/libxt_ts3init_get_cookie.c +++ b/src/libxt_ts3init_get_cookie.c @@ -17,7 +17,7 @@ #include #include #include -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_match.h" #define param_act(t, s, f) xtables_param_act((t), "ts3init_get_cookie", (s), (f)) diff --git a/src/libxt_ts3init_get_puzzle.c b/src/libxt_ts3init_get_puzzle.c index 2fc3b48..9d63ed6 100644 --- a/src/libxt_ts3init_get_puzzle.c +++ b/src/libxt_ts3init_get_puzzle.c @@ -17,7 +17,7 @@ #include #include #include -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_match.h" #define param_act(t, s, f) xtables_param_act((t), "ts3init_get_puzzle", (s), (f)) @@ -29,18 +29,18 @@ static void ts3init_get_puzzle_help(void) "ts3init_get_puzzle match options:\n" " --min-client n The sending client needs to be at least version.\n" " --check-cookie Check that the cookie was generated by same seed.\n" - " --seed Seed is a %i byte lowercase hex number in.\n" + " --random-seed Seed is a %i byte lowercase hex number in.\n" " A source could be /dev/random.\n" - " --seed-file Read the seed from a file.\n", - COOKIE_SEED_LEN + " --random-seed-file Read the seed from a file.\n", + RANDOM_SEED_LEN ); } static const struct option ts3init_get_puzzle_opts[] = { {.name = "min-client", .has_arg = true, .val = '1'}, {.name = "check-cookie", .has_arg = false, .val = '2'}, - {.name = "seed", .has_arg = true, .val = '3'}, - {.name = "seed-file", .has_arg = true, .val = '4'}, + {.name = "random-seed", .has_arg = true, .val = '3'}, + {.name = "random-seed-file", .has_arg = true, .val = '4'}, {NULL}, }; @@ -70,26 +70,26 @@ static int ts3init_get_puzzle_parse(int c, char **argv, int invert, unsigned int return true; case '3': - param_act(XTF_ONLY_ONCE, "--seed", info->specific_options & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT); - param_act(XTF_NO_INVERT, "--seed", invert); - if (strlen(optarg) != (COOKIE_SEED_LEN * 2)) + param_act(XTF_ONLY_ONCE, "--random-seed", info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT); + param_act(XTF_NO_INVERT, "--random-seed", invert); + if (strlen(optarg) != (RANDOM_SEED_LEN * 2)) xtables_error(PARAMETER_PROBLEM, - "ts3init_get_puzzle: invalid seed length"); - if (!hex2int_seed(optarg, info->cookie_seed)) + "ts3init_get_puzzle: invalid random seed length"); + if (!parse_random_seed(optarg, info->random_seed)) xtables_error(PARAMETER_PROBLEM, - "ts3init_get_puzzle: invalid seed. (not lowercase hex)"); - info->specific_options |= CHK_GET_PUZZLE_SEED_FROM_ARGUMENT; - *flags |= CHK_GET_PUZZLE_SEED_FROM_ARGUMENT; + "ts3init_get_puzzle: invalid random seed. (not lowercase hex)"); + info->specific_options |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT; + *flags |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT; return true; case '4': - param_act(XTF_ONLY_ONCE, "--seed-file", info->specific_options & CHK_GET_PUZZLE_SEED_FROM_FILE); - param_act(XTF_NO_INVERT, "--seed-file", invert); + param_act(XTF_ONLY_ONCE, "--random-seed-file", info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE); + param_act(XTF_NO_INVERT, "--random-seed-file", invert); - if (read_cookie_seed_from_file("ts3init_get_puzzle", optarg, info->cookie_seed)) - memcpy(info->cookie_seed_path, optarg, strlen(optarg) + 1); - info->specific_options |= CHK_GET_PUZZLE_SEED_FROM_FILE; - *flags |= CHK_GET_PUZZLE_SEED_FROM_FILE; + if (read_random_seed_from_file("ts3init_get_puzzle", optarg, info->random_seed)) + memcpy(info->random_seed_path, optarg, strlen(optarg) + 1); + info->specific_options |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE; + *flags |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE; return true; default: @@ -108,18 +108,18 @@ static void ts3init_get_puzzle_save(const void *ip, const struct xt_entry_match { printf("--check-cookie "); } - if (info->specific_options & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT) + if (info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT) { - printf("--seed "); - for (int i = 0; i < COOKIE_SEED_LEN; i++) + printf("--random-seed "); + for (int i = 0; i < RANDOM_SEED_LEN; i++) { - printf("%02X", info->cookie_seed[i]); + printf("%02X", info->random_seed[i]); } printf(" "); } - if (info->specific_options & CHK_GET_PUZZLE_SEED_FROM_FILE) + if (info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE) { - printf("--seed-file \"%s\" ", info->cookie_seed_path); + printf("--random-seed-file \"%s\" ", info->random_seed_path); } } @@ -132,12 +132,12 @@ static void ts3init_get_puzzle_print(const void *ip, const struct xt_entry_match static void ts3init_get_puzzle_check(unsigned int flags) { - bool seed_from_argument = flags & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT; - bool seed_from_file = flags & CHK_GET_PUZZLE_SEED_FROM_FILE; + bool seed_from_argument = flags & CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT; + bool seed_from_file = flags & CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE; if (seed_from_argument && seed_from_file) { xtables_error(PARAMETER_PROBLEM, - "ts3init_get_puzzle: --seed and --seed-file " + "ts3init_get_puzzle: --random-seed and --random-seed-file " "can not be specified at the same time"); } if (flags & CHK_GET_PUZZLE_CHECK_COOKIE) @@ -146,7 +146,7 @@ static void ts3init_get_puzzle_check(unsigned int flags) { xtables_error(PARAMETER_PROBLEM, "ts3init_get_puzzle: --check-cookie requires either " - "--seed or --seed-file"); + "--random-seed or --random-seed-file"); } } } diff --git a/src/ts3init_cache.c b/src/ts3init_cache.c index bb8ed7f..1356ac2 100644 --- a/src/ts3init_cache.c +++ b/src/ts3init_cache.c @@ -65,7 +65,7 @@ time_t ts3init_get_cached_unix_time(void) return current_unix_time; } -bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (*cookie)[2]) +bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* random_seed, u64 (*cookie)[2]) { struct ts3init_cache_t* cache; u64* result; @@ -80,7 +80,7 @@ bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (* current_unix_time = cache->unix_time; result = ts3init_get_cookie_seed(current_unix_time, - packet_index, &cache->cookie_cache, seed); + packet_index, &cache->cookie_cache, random_seed); if (result) { @@ -91,7 +91,7 @@ bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (* return result; } -bool ts3init_get_current_cookie(const u8* seed, u64 (*cookie)[2], u8 *packet_index) +bool ts3init_get_current_cookie(const u8* random_seed, u64 (*cookie)[2], u8 *packet_index) { struct ts3init_cache_t* cache; u64* result; @@ -108,7 +108,7 @@ bool ts3init_get_current_cookie(const u8* seed, u64 (*cookie)[2], u8 *packet_ind *packet_index = current_unix_time % 8; result = ts3init_get_cookie_seed(current_unix_time, - *packet_index, &cache->cookie_cache, seed); + *packet_index, &cache->cookie_cache, random_seed); if (result) { diff --git a/src/ts3init_cache.h b/src/ts3init_cache.h index ee63620..31eb894 100644 --- a/src/ts3init_cache.h +++ b/src/ts3init_cache.h @@ -9,14 +9,14 @@ time_t ts3init_get_cached_unix_time(void); /* * Returns the cookie for a packet_index. - * If the cookie is not in the cache, it will be generated using the seed. + * If the cookie is not in the cache, it will be generated using the random seed. */ -bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (*cookie)[2]); +bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* random_seed, u64 (*cookie)[2]); /* * Returns the current cookie and packet_index. - * If the cookie is not in the cache, it will be generated using the seed. + * If the cookie is not in the cache, it will be generated using the random seed. */ -bool ts3init_get_current_cookie(const u8* seed, u64 (*cookie)[2], u8 *packet_index); +bool ts3init_get_current_cookie(const u8* random_seed, u64 (*cookie)[2], u8 *packet_index); #endif /* _TS3INIT_CACHE_H */ diff --git a/src/ts3init_cookie.c b/src/ts3init_cookie.c index 4e88367..38d86c6 100644 --- a/src/ts3init_cookie.c +++ b/src/ts3init_cookie.c @@ -21,12 +21,12 @@ #include #include #include "siphash24.h" -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_cookie.h" static void check_update_seed_cache(time_t time, __u8 index, struct xt_ts3init_cookie_cache* cache, - const __u8* cookie_seed) + const __u8* random_seed) { struct hash_desc desc; struct scatterlist sg[2]; @@ -36,10 +36,10 @@ static void check_update_seed_cache(time_t time, __u8 index, if (time == cache->time[index]) return; /* We need to update the cache. */ - /* seed = sha512(cookie_seed[COOKIE_SEED_LEN] + __le32 time) */ + /* seed = sha512(random_seed[RANDOM_SEED_LEN] + __le32 time) */ seed_hash_time = cpu_to_le32( (__u32)time); sg_init_table(sg, ARRAY_SIZE(sg)); - sg_set_buf(&sg[0], cookie_seed, COOKIE_SEED_LEN); + sg_set_buf(&sg[0], random_seed, RANDOM_SEED_LEN); sg_set_buf(&sg[1], &seed_hash_time, 4); desc.tfm = crypto_alloc_hash("sha512", 0, 0); @@ -70,7 +70,7 @@ static void check_update_seed_cache(time_t time, __u8 index, __u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index, struct xt_ts3init_cookie_cache* cache, - const __u8* cookie_seed) + const __u8* random_seed) { __u8 current_cache_index; @@ -90,7 +90,7 @@ __u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index, /* make sure the cache is up-to-date */ check_update_seed_cache(packet_cache_time, packet_cache_index, cache, - cookie_seed); + random_seed); /* return the proper seed */ return cache->seed64 + ((SIP_KEY_SIZE/sizeof(__u64)) * packet_index ); diff --git a/src/ts3init_cookie.h b/src/ts3init_cookie.h index 3831ad9..ef441f4 100644 --- a/src/ts3init_cookie.h +++ b/src/ts3init_cookie.h @@ -19,11 +19,11 @@ struct xt_ts3init_cookie_cache /* * Returns the cookie that fits current_time and packet_index. * If the cookie is missing in cache it will be generated using - * cookie_seed and current_time + * random_seed and current_time */ __u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index, struct xt_ts3init_cookie_cache* cache, - const __u8* cookie_seed); + const __u8* random_seed); /* * Returns the hash of cookie and source/destination address/port. diff --git a/src/ts3init_match.c b/src/ts3init_match.c index 6a4b394..b229c9b 100644 --- a/src/ts3init_match.c +++ b/src/ts3init_match.c @@ -20,7 +20,7 @@ #include #include #include -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_cookie.h" #include "ts3init_match.h" #include "ts3init_header.h" @@ -217,7 +217,7 @@ static bool ts3init_get_puzzle_mt(const struct sk_buff *skb, struct xt_action_pa __u64 cookie_seed[2]; __u64 cookie, packet_cookie; - if (ts3init_get_cookie_for_packet_index(ts3_header->payload[8], info->cookie_seed, &cookie_seed) == false) + if (ts3init_get_cookie_for_packet_index(ts3_header->payload[8], info->random_seed, &cookie_seed) == false) return false; /* use cookie_seed and ipaddress and port to create a hash diff --git a/src/ts3init_match.h b/src/ts3init_match.h index 2984147..b991d66 100644 --- a/src/ts3init_match.h +++ b/src/ts3init_match.h @@ -30,10 +30,10 @@ struct xt_ts3init_get_cookie_mtinfo /* Enums and structs for get_puzzle */ enum { - CHK_GET_PUZZLE_CHECK_COOKIE = 1 << 0, - CHK_GET_PUZZLE_SEED_FROM_ARGUMENT = 1 << 1, - CHK_GET_PUZZLE_SEED_FROM_FILE = 1 << 2, - CHK_GET_PUZZLE_VALID_MASK = (1 << 3) - 1, + CHK_GET_PUZZLE_CHECK_COOKIE = 1 << 0, + CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT = 1 << 1, + CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE = 1 << 2, + CHK_GET_PUZZLE_VALID_MASK = (1 << 3) - 1, }; struct xt_ts3init_get_puzzle_mtinfo @@ -42,8 +42,8 @@ struct xt_ts3init_get_puzzle_mtinfo __u8 specific_options; __u16 reserved1; __u32 min_client_version; - __u8 cookie_seed[COOKIE_SEED_LEN]; - char cookie_seed_path[COOKIE_PATH_MAX]; + __u8 random_seed[RANDOM_SEED_LEN]; + char random_seed_path[RANDOM_SEED_PATH_MAX]; }; #endif /* _TS3INIT_MATCH_H */ diff --git a/src/ts3init_cookie_seed.h b/src/ts3init_random_seed.h similarity index 77% rename from src/ts3init_cookie_seed.h rename to src/ts3init_random_seed.h index d9fc21c..63b5610 100644 --- a/src/ts3init_cookie_seed.h +++ b/src/ts3init_random_seed.h @@ -2,18 +2,18 @@ #define _TS3INIT_COOKIE_SEED_H enum { - COOKIE_SEED_LEN = 60, - COOKIE_PATH_MAX = 256, + RANDOM_SEED_LEN = 60, + RANDOM_SEED_PATH_MAX = 256, }; /* * Parses a hexstring into dest. - * It is assumed that COOKIE_SEED_LEN bytes are to be parsed. + * It is assumed that RANDOM_SEED_LEN bytes are to be parsed. */ -static inline bool hex2int_seed(const char *src, __u8* dst) +static inline bool parse_random_seed(const char *src, __u8* dst) { int i, j; - for (i = 0; i < COOKIE_SEED_LEN; ++i) + for (i = 0; i < RANDOM_SEED_LEN; ++i) { int v = 0; for ( j = 0; j < 2; ++j) @@ -35,11 +35,11 @@ static inline bool hex2int_seed(const char *src, __u8* dst) /* * Reads a cookie seed from a file. */ -static inline bool read_cookie_seed_from_file(const char *module_name, const char *path, __u8* dst) +static inline bool read_random_seed_from_file(const char *module_name, const char *path, __u8* dst) { int n, fd; - char text[COOKIE_SEED_LEN * 2], error_message[256]; - if (strlen(path) > COOKIE_PATH_MAX) + char text[RANDOM_SEED_LEN * 2], error_message[256]; + if (strlen(path) > RANDOM_SEED_PATH_MAX) { xtables_error(PARAMETER_PROBLEM, "%s: path is too long.", module_name); return false; @@ -56,7 +56,7 @@ static inline bool read_cookie_seed_from_file(const char *module_name, const cha n = read(fd, text, sizeof(text)); if (n == -1) goto io_error; - else if (n != sizeof(text) || hex2int_seed(text, dst) == false) + else if (n != sizeof(text) || parse_random_seed(text, dst) == false) { xtables_error(PARAMETER_PROBLEM, "%s: %s must contain exactly %lu lowercase hex characters", module_name, path, sizeof(text)); return false; diff --git a/src/ts3init_target.c b/src/ts3init_target.c index df16d4c..1856922 100644 --- a/src/ts3init_target.c +++ b/src/ts3init_target.c @@ -26,7 +26,7 @@ #include #include #include "compat_xtables.h" -#include "ts3init_cookie_seed.h" +#include "ts3init_random_seed.h" #include "ts3init_cookie.h" #include "ts3init_target.h" #include "ts3init_header.h" @@ -231,7 +231,7 @@ ts3init_generate_cookie_ipv4(const struct xt_action_param *par, const struct xt_ts3init_set_cookie_tginfo *info = par->targinfo; __u64 cookie[2]; - if (ts3init_get_current_cookie(info->cookie_seed, &cookie, packet_index) == false) + if (ts3init_get_current_cookie(info->random_seed, &cookie, packet_index) == false) return false; if (ts3init_calculate_cookie_ipv4(ip, udp, cookie[0], cookie[1], cookie_hash)) return false; @@ -250,7 +250,7 @@ ts3init_generate_cookie_ipv6(const struct xt_action_param *par, const struct xt_ts3init_set_cookie_tginfo *info = par->targinfo; __u64 cookie[2]; - if (ts3init_get_current_cookie(info->cookie_seed, &cookie, packet_index) == false) + if (ts3init_get_current_cookie(info->random_seed, &cookie, packet_index) == false) return false; if (ts3init_calculate_cookie_ipv6(ip, udp, cookie[0], cookie[1], cookie_hash)) return false; diff --git a/src/ts3init_target.h b/src/ts3init_target.h index dc7b4ca..b749bc8 100644 --- a/src/ts3init_target.h +++ b/src/ts3init_target.h @@ -10,10 +10,10 @@ enum /* Enums and structs for set_cookie */ enum { - TARGET_SET_COOKIE_ZERO_RANDOM_SEQUENCE = 1 << 0, - TARGET_SET_COOKIE_SEED_FROM_ARGUMENT = 1 << 1, - TARGET_SET_COOKIE_SEED_FROM_FILE = 1 << 2, - TARGET_SET_COOKIE_VALID_MASK = (1 << 3) - 1 + TARGET_SET_COOKIE_ZERO_RANDOM_SEQUENCE = 1 << 0, + TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT = 1 << 1, + TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE = 1 << 2, + TARGET_SET_COOKIE_VALID_MASK = (1 << 3) - 1 }; @@ -22,8 +22,8 @@ struct xt_ts3init_set_cookie_tginfo __u8 common_options; __u8 specific_options; __u16 reserved1; - __u8 cookie_seed[COOKIE_SEED_LEN]; - char cookie_seed_path[COOKIE_PATH_MAX]; + __u8 random_seed[RANDOM_SEED_LEN]; + char random_seed_path[RANDOM_SEED_PATH_MAX]; }; #endif /* _TS3INIT_TARGET_H */