X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsubnet.c;h=fe7d23efb980f4f93daff30c8f5d26a1e3aecb2f;hb=e32d4f3db3f1ed3eebe2e11d57512b60a6c02fa6;hp=ffc82a6980b54e57cff5b029b5126ee81cd57a66;hpb=8c8dfd6686a3d4cc11c20a09c8dfbc8321b07cdb;p=tinc diff --git a/src/subnet.c b/src/subnet.c index ffc82a69..fe7d23ef 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -22,6 +22,7 @@ #include "splay_tree.h" #include "control_common.h" +#include "crypto.h" #include "hash.h" #include "logger.h" #include "net.h" @@ -83,7 +84,7 @@ static uint32_t hash_function_ipv6_t(const ipv6_t *p) { uint32_t hash = hash_seed; for(int i = 0; i < 4; i++) { - hash += fullwidth[i]; + hash = wrapping_add32(hash, fullwidth[i]); hash = wrapping_mul32(hash, 0x9e370001U); } @@ -95,7 +96,7 @@ static uint32_t hash_function_mac_t(const mac_t *p) { uint32_t hash = hash_seed; for(int i = 0; i < 3; i++) { - hash += halfwidth[i]; + hash = wrapping_add32(hash, halfwidth[i]); hash = wrapping_mul32(hash, 0x9e370001U); } @@ -128,7 +129,10 @@ void subnet_cache_flush_table(subnet_type_t stype) { /* Initialising trees */ void init_subnets(void) { - hash_seed = (uint32_t)rand(); + hash_seed = prng(UINT32_MAX); + + // tables need to be cleared on startup + subnet_cache_flush_tables(); } void exit_subnets(void) {