X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsubnet.c;h=1ddf11e53b7e1bb8ea678a1944273ce745a5efe2;hb=b13e1a3c1f7252cda5ab95166d9f2d578983471f;hp=602177ffef3e146bccb71a49c42eba50112bb572;hpb=ac2a1722b71e98010324ed46235e96bfa6e672f5;p=tinc diff --git a/src/subnet.c b/src/subnet.c index 602177ff..1ddf11e5 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -1,6 +1,6 @@ /* subnet.c -- handle subnet lookups and lists - Copyright (C) 2000-2017 Guus Sliepen , + Copyright (C) 2000-2022 Guus Sliepen , 2000-2005 Ivo Timmermans This program is free software; you can redistribute it and/or modify @@ -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,7 @@ 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(); @@ -161,7 +162,7 @@ void subnet_cache_flush_tables(void) { hash_clear(mac_t, &mac_cache); } -void subnet_cache_flush(subnet_t *subnet) { +static void subnet_cache_flush(subnet_t *subnet) { switch(subnet->type) { case SUBNET_IPV4: if(subnet->net.ipv4.prefixlength == 32) { @@ -321,7 +322,7 @@ subnet_t *lookup_subnet_ipv6(const ipv6_t *address) { void subnet_update(node_t *owner, subnet_t *subnet, bool up) { char netstr[MAXNETSTR]; - char *name, *address, *port; + char *address, *port; char empty[] = ""; // Prepare environment variables to be passed to the script @@ -341,7 +342,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { int env_subnet = environment_add(&env, NULL); int env_weight = environment_add(&env, NULL); - name = up ? "subnet-up" : "subnet-down"; + const char *name = up ? "subnet-up" : "subnet-down"; if(!subnet) { for splay_each(subnet_t, subnet, &owner->subnet_tree) {