X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsubnet.c;h=04254957c2e4461e371b6106fb4ccbd0ba4761dc;hb=914d1be411229c28e6e8e4a0df99afa076a8b448;hp=13c4603018b74070fd7887fae502c2f8fb2da66c;hpb=1545909dcb3ac618754486f4ccd4d8f237d64bb7;p=tinc diff --git a/src/subnet.c b/src/subnet.c index 13c46030..04254957 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -33,7 +33,10 @@ /* lists type of subnet */ -splay_tree_t *subnet_tree; +splay_tree_t subnet_tree = { + .compare = (splay_compare_t) subnet_compare, + .delete = (splay_action_t) free_subnet, +}; /* Subnet lookup cache */ @@ -50,27 +53,22 @@ void subnet_cache_flush(void) { /* Initialising trees */ void init_subnets(void) { - subnet_tree = splay_alloc_tree((splay_compare_t) subnet_compare, (splay_action_t) free_subnet); - ipv4_cache = hash_alloc(0x100, sizeof(ipv4_t)); ipv6_cache = hash_alloc(0x100, sizeof(ipv6_t)); mac_cache = hash_alloc(0x100, sizeof(mac_t)); } void exit_subnets(void) { - splay_delete_tree(subnet_tree); + splay_empty_tree(&subnet_tree); hash_free(ipv4_cache); hash_free(ipv6_cache); hash_free(mac_cache); } -splay_tree_t *new_subnet_tree(void) { - return splay_alloc_tree((splay_compare_t) subnet_compare, NULL); -} - -void free_subnet_tree(splay_tree_t *subnet_tree) { - splay_delete_tree(subnet_tree); +void init_subnet_tree(splay_tree_t *tree) { + memset(tree, 0, sizeof(*tree)); + tree->compare = (splay_compare_t) subnet_compare; } /* Allocating and freeing space for subnets */ @@ -88,10 +86,10 @@ void free_subnet(subnet_t *subnet) { void subnet_add(node_t *n, subnet_t *subnet) { subnet->owner = n; - splay_insert(subnet_tree, subnet); + splay_insert(&subnet_tree, subnet); if(n) { - splay_insert(n->subnet_tree, subnet); + splay_insert(&n->subnet_tree, subnet); } subnet_cache_flush(); @@ -99,18 +97,18 @@ void subnet_add(node_t *n, subnet_t *subnet) { void subnet_del(node_t *n, subnet_t *subnet) { if(n) { - splay_delete(n->subnet_tree, subnet); + splay_delete(&n->subnet_tree, subnet); } - splay_delete(subnet_tree, subnet); + splay_delete(&subnet_tree, subnet); subnet_cache_flush(); } /* Subnet lookup routines */ -subnet_t *lookup_subnet(const node_t *owner, const subnet_t *subnet) { - return splay_search(owner->subnet_tree, subnet); +subnet_t *lookup_subnet(node_t *owner, const subnet_t *subnet) { + return splay_search(&owner->subnet_tree, subnet); } subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) { @@ -124,7 +122,7 @@ subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) { // Search all subnets for a matching one - for splay_each(subnet_t, p, owner ? owner->subnet_tree : subnet_tree) { + for splay_each(subnet_t, p, owner ? &owner->subnet_tree : &subnet_tree) { if(!p || p->type != SUBNET_MAC) { continue; } @@ -158,7 +156,7 @@ subnet_t *lookup_subnet_ipv4(const ipv4_t *address) { // Search all subnets for a matching one - for splay_each(subnet_t, p, subnet_tree) { + for splay_each(subnet_t, p, &subnet_tree) { if(!p || p->type != SUBNET_IPV4) { continue; } @@ -192,7 +190,7 @@ subnet_t *lookup_subnet_ipv6(const ipv6_t *address) { // Search all subnets for a matching one - for splay_each(subnet_t, p, subnet_tree) { + for splay_each(subnet_t, p, &subnet_tree) { if(!p || p->type != SUBNET_IPV6) { continue; } @@ -240,7 +238,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { name = up ? "subnet-up" : "subnet-down"; if(!subnet) { - for splay_each(subnet_t, subnet, owner->subnet_tree) { + for splay_each(subnet_t, subnet, &owner->subnet_tree) { if(!net2str(netstr, sizeof(netstr), subnet)) { continue; } @@ -283,7 +281,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { } bool dump_subnets(connection_t *c) { - for splay_each(subnet_t, subnet, subnet_tree) { + for splay_each(subnet_t, subnet, &subnet_tree) { char netstr[MAXNETSTR]; if(!net2str(netstr, sizeof(netstr), subnet)) {