X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnode.c;h=9d4d2f4393231556c7dba9376edaf22b219c2189;hb=f02d3ed3e135b5326003e7f69f8331ff6a3cc219;hp=351991611b2cd2a3d692213b6866cb50df7c4a25;hpb=af86a3226ea42375644b3f99c182c778d327de1e;p=tinc diff --git a/src/node.c b/src/node.c index 35199161..9d4d2f43 100644 --- a/src/node.c +++ b/src/node.c @@ -1,7 +1,7 @@ /* node.c -- node tree management - Copyright (C) 2001-2003 Guus Sliepen , - 2001-2003 Ivo Timmermans + Copyright (C) 2001-2006 Guus Sliepen , + 2001-2005 Ivo Timmermans This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: node.c,v 1.1.2.31 2003/12/22 11:04:16 guus Exp $ + $Id$ */ #include "system.h" @@ -35,13 +35,11 @@ avl_tree_t *node_udp_tree; /* Known nodes, sorted by address and port */ node_t *myself; -static int node_compare(const node_t *a, const node_t *b) -{ +static int node_compare(const node_t *a, const node_t *b) { return strcmp(a->name, b->name); } -static int node_udp_compare(const node_t *a, const node_t *b) -{ +static int node_udp_compare(const node_t *a, const node_t *b) { int result; cp(); @@ -54,24 +52,21 @@ static int node_udp_compare(const node_t *a, const node_t *b) return (a->name && b->name) ? strcmp(a->name, b->name) : 0; } -void init_nodes(void) -{ +void init_nodes(void) { cp(); node_tree = avl_alloc_tree((avl_compare_t) node_compare, (avl_action_t) free_node); node_udp_tree = avl_alloc_tree((avl_compare_t) node_udp_compare, NULL); } -void exit_nodes(void) -{ +void exit_nodes(void) { cp(); avl_delete_tree(node_udp_tree); avl_delete_tree(node_tree); } -node_t *new_node(void) -{ +node_t *new_node(void) { node_t *n = xmalloc_and_zero(sizeof(*n)); cp(); @@ -86,19 +81,12 @@ node_t *new_node(void) return n; } -void free_node(node_t *n) -{ +void free_node(node_t *n) { cp(); if(n->queue) list_delete_list(n->queue); - if(n->name) - free(n->name); - - if(n->hostname) - free(n->hostname); - if(n->key) free(n->key); @@ -112,22 +100,24 @@ void free_node(node_t *n) EVP_CIPHER_CTX_cleanup(&n->packet_ctx); - if(n->mtuevent) - event_del(n->mtuevent); + event_del(&n->mtuevent); + if(n->hostname) + free(n->hostname); + + if(n->name) + free(n->name); + free(n); } -void node_add(node_t *n) -{ +void node_add(node_t *n) { cp(); avl_insert(node_tree, n); - avl_insert(node_udp_tree, n); } -void node_del(node_t *n) -{ +void node_del(node_t *n) { avl_node_t *node, *next; edge_t *e; subnet_t *s; @@ -147,11 +137,9 @@ void node_del(node_t *n) } avl_delete(node_tree, n); - avl_delete(node_udp_tree, n); } -node_t *lookup_node(char *name) -{ +node_t *lookup_node(char *name) { node_t n = {0}; cp(); @@ -161,8 +149,7 @@ node_t *lookup_node(char *name) return avl_search(node_tree, &n); } -node_t *lookup_node_udp(const sockaddr_t *sa) -{ +node_t *lookup_node_udp(const sockaddr_t *sa) { node_t n = {0}; cp(); @@ -173,8 +160,7 @@ node_t *lookup_node_udp(const sockaddr_t *sa) return avl_search(node_udp_tree, &n); } -void dump_nodes(void) -{ +void dump_nodes(void) { avl_node_t *node; node_t *n;