Added fix for stale routes in olsr_delete_routes_from_kernel
authorAndreas Tonnesen <andreto@olsr.org>
Mon, 23 May 2005 17:27:41 +0000 (17:27 +0000)
committerAndreas Tonnesen <andreto@olsr.org>
Mon, 23 May 2005 17:27:41 +0000 (17:27 +0000)
src/process_routes.c

index 7c6b7fb..b1d965b 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: process_routes.c,v 1.24 2005/02/28 14:42:57 tlopatic Exp $
+ * $Id: process_routes.c,v 1.25 2005/05/23 17:27:41 kattemat Exp $
  */
 
 
@@ -212,7 +212,7 @@ olsr_update_kernel_routes()
 {
   struct destination_n *delete_kernel_list = NULL;
   struct destination_n *add_kernel_list = NULL;
-  
+
   OLSR_PRINTF(3, "Updating kernel routes...\n")
   delete_kernel_list = olsr_build_update_list(old_routes, routingtable);
   add_kernel_list = olsr_build_update_list(routingtable, old_routes);
@@ -306,6 +306,7 @@ olsr_delete_routes_from_kernel(struct destination_n *delete_kernel_list)
       if(destination_ptr->destination->rt_metric > metric_counter)
        metric_counter = destination_ptr->destination->rt_metric;
     }
+
 #ifdef DEBUG
   OLSR_PRINTF(3, "%s highest metric %d\n",
              __func__, metric_counter)
@@ -321,42 +322,51 @@ olsr_delete_routes_from_kernel(struct destination_n *delete_kernel_list)
       for(destination_ptr = delete_kernel_list; destination_ptr != NULL; )
        {
 
-         if((destination_ptr->destination->rt_metric == metric_counter) &&
-            ((last_run || 
-              !COMP_IP(&destination_ptr->destination->rt_dst, 
-                        &destination_ptr->destination->rt_router))))
+         if(destination_ptr->destination->rt_metric == metric_counter)
            {
-             olsr_16_t error;
-#ifdef DEBUG
-             OLSR_PRINTF(3, "Deleting route to %s hopcount %d\n",
-                         olsr_ip_to_string(&destination_ptr->destination->rt_dst),
-                         destination_ptr->destination->rt_metric)
-#endif
-             
-             if(olsr_cnf->ip_version == AF_INET)
-               error = olsr_ioctl_del_route(destination_ptr->destination);
-             else
-               error = olsr_ioctl_del_route6(destination_ptr->destination);
-             
-             if(error < 0)
-               {
-                 OLSR_PRINTF(1, "Delete route(%s):%s\n", olsr_ip_to_string(&destination_ptr->destination->rt_dst), strerror(errno))
-                 olsr_syslog(OLSR_LOG_ERR, "Delete route:%m");
-               }
-             
-             /* Getting rid of this node and hooking up the broken point */
-             if(destination_ptr == delete_kernel_list) 
+             /* Make sure one-hop direct neighbors are deleted last */
+             if(metric_counter == 1 &&
+                (!last_run && 
+                 COMP_IP(&destination_ptr->destination->rt_dst, 
+                         &destination_ptr->destination->rt_router)))
                {
-                 destination_ptr = delete_kernel_list->next;
-                 free(delete_kernel_list);
-                 delete_kernel_list = destination_ptr;
-                 previous_node = delete_kernel_list;
+                 previous_node = destination_ptr;
+                 destination_ptr = destination_ptr->next;
                }
-             else 
+             else
                {
-                 previous_node->next = destination_ptr->next;
-                 free(destination_ptr);
-                 destination_ptr = previous_node->next;
+                 olsr_16_t error;                
+#ifdef DEBUG
+                 OLSR_PRINTF(3, "Deleting route to %s hopcount %d\n",
+                             olsr_ip_to_string(&destination_ptr->destination->rt_dst),
+                             destination_ptr->destination->rt_metric)
+#endif
+                   
+                   if(olsr_cnf->ip_version == AF_INET)
+                     error = olsr_ioctl_del_route(destination_ptr->destination);
+                   else
+                     error = olsr_ioctl_del_route6(destination_ptr->destination);
+                 
+                 if(error < 0)
+                   {
+                     OLSR_PRINTF(1, "Delete route(%s):%s\n", olsr_ip_to_string(&destination_ptr->destination->rt_dst), strerror(errno))
+                       olsr_syslog(OLSR_LOG_ERR, "Delete route:%m");
+                   }
+                 
+                 /* Getting rid of this node and hooking up the broken point */
+                 if(destination_ptr == delete_kernel_list) 
+                   {
+                     destination_ptr = delete_kernel_list->next;
+                     free(delete_kernel_list);
+                     delete_kernel_list = destination_ptr;
+                     previous_node = delete_kernel_list;
+                   }
+                 else 
+                   {
+                     previous_node->next = destination_ptr->next;
+                     free(destination_ptr);
+                     destination_ptr = previous_node->next;
+                   }
                }
            }
          else