X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fconnection.c;h=7f48697d77188dccf9053706541767f72ba632a1;hp=46d82d2ce8e1648c4649cbf4eaf6df8da6c67291;hb=cf49b2c0647554613874cce495e4a7937a9f7863;hpb=1857b3c97c261dda9978a67d07b315bb3ca68841 diff --git a/src/connection.c b/src/connection.c index 46d82d2c..7f48697d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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: connection.c,v 1.1.2.2 2000/11/20 19:41:10 guus Exp $ + $Id: connection.c,v 1.1.2.6 2000/11/24 23:13:01 guus Exp $ */ #include "config.h" @@ -40,11 +40,23 @@ /* Root of the connection list */ rbltree_t *connection_tree; +rbltree_t *id_tree; + connection_t *myself = NULL; /* Initialization and callbacks */ int connection_compare(connection_t *a, connection_t *b) +{ + ipv4_t result; + result = a->address - b->address; + if(result) + return result; + else + return a->port - b->port; +} + +int id_compare(connection_t *a, connection_t *b) { return strcmp(a->name, b->name); } @@ -52,17 +64,15 @@ int connection_compare(connection_t *a, connection_t *b) void init_connections(void) { connection_tree = new_rbltree((rbl_compare_t)connection_compare, (rbl_action_t)free_connection); + id_tree = new_rbltree((rbl_compare_t)id_compare, NULL); } /* Creation and deletion of connection elements */ connection_t *new_connection(void) { - connection_t *p = (connection_t *)xmalloc(sizeof(*p)); + connection_t *p = (connection_t *)xmalloc_and_zero(sizeof(*p)); cp - /* initialise all those stupid pointers at once */ - memset(p, '\0', sizeof(*p)); - p->subnet_tree = new_rbltree((rbl_compare_t)subnet_compare, NULL); cp return p; @@ -114,6 +124,7 @@ cp void destroy_connection_tree(void) { cp + rbl_delete_rbltree(id_tree); rbl_delete_rbltree(connection_tree); cp } @@ -127,22 +138,43 @@ cp cp } +void id_add(connection_t *cl) +{ +cp + rbl_insert(id_tree, cl); +cp +} + void connection_del(connection_t *cl) { cp + rbl_delete(id_tree, cl); rbl_delete(connection_tree, cl); cp } /* Lookup functions */ -connection_t *lookup_id(char *name) +connection_t *lookup_connection(ipv4_t address, short unsigned int port) { connection_t cl; cp - cl.name = name; + cl.address = address; + cl.port = port; + return rbl_search(connection_tree, &cl); +} + +connection_t *lookup_id(char *name) +{ + connection_t cl, *p; cp + cl.name = name; + p = rbl_search(id_tree, &cl); + if(p && p->status.active) + return p; + else + return NULL; } /* Debugging */