Various fixes, tinc is now somewhat capable of actually working again.
[tinc] / src / subnet.c
index fff384f..1b7bc38 100644 (file)
@@ -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: subnet.c,v 1.1.2.26 2001/10/27 13:13:35 guus Exp $
+    $Id: subnet.c,v 1.1.2.28 2001/10/30 12:59:12 guus Exp $
 */
 
 #include "config.h"
 
 avl_tree_t *subnet_tree;
 
-void init_subnets(void)
-{
-cp
-  subnet_tree = avl_alloc_tree((avl_compare_t)subnet_compare, (avl_action_t)free_subnet);
-cp
-}
-
 /* Subnet comparison */
 
 int subnet_compare_mac(subnet_t *a, subnet_t *b)
 {
-  int result;
 cp
-  result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(mac_t));
-  
-  if(result)
-    return result;
-
-  return strcmp(a->owner->name, b->owner->name);
+  return memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(mac_t));
 }
 
 int subnet_compare_ipv4(subnet_t *a, subnet_t *b)
@@ -76,7 +63,7 @@ cp
   else if(a->net.ipv4.mask > b->net.ipv4.mask)
     return 1;
 
-  return strcmp(a->owner->name, b->owner->name);
+  return 0;
 }
 
 int subnet_compare_ipv6(subnet_t *a, subnet_t *b)
@@ -95,7 +82,7 @@ cp
   if(result)
     return result;
 
-  return strcmp(a->owner->name, b->owner->name);
+  return 0;
 }
 
 int subnet_compare(subnet_t *a, subnet_t *b)
@@ -121,6 +108,36 @@ cp
     }
 }
 
+/* Initialising trees */
+
+void init_subnets(void)
+{
+cp
+  subnet_tree = avl_alloc_tree((avl_compare_t)subnet_compare, (avl_action_t)free_subnet);
+cp
+}
+
+void exit_subnets(void)
+{
+cp
+  avl_delete_tree(subnet_tree);
+cp
+}
+
+avl_tree_t *new_subnet_tree(void)
+{
+cp
+  return avl_alloc_tree((avl_compare_t)subnet_compare, NULL);
+cp
+}
+
+void free_subnet_tree(avl_tree_t *subnet_tree)
+{
+cp
+  avl_delete_tree(subnet_tree);
+cp
+}
+
 /* Allocating and freeing space for subnets */
 
 subnet_t *new_subnet(void)
@@ -135,7 +152,7 @@ cp
   free(subnet);
 }
 
-/* Linked list management */
+/* Adding and removing subnets */
 
 void subnet_add(node_t *n, subnet_t *subnet)
 {