gateway: allow immediate removal of a gateway entry
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 18 Oct 2012 09:09:02 +0000 (11:09 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 24 Oct 2012 12:17:49 +0000 (14:17 +0200)
This is going to be used by the cleanup function later on.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/gateway.c
src/gateway.h
src/hna_set.c
src/tc_set.c

index 098847f..be55ef7 100644 (file)
@@ -386,8 +386,10 @@ void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_add
  *
  * @param originator
  * @param prefixlen
+ * @param immediate when set to true then the gateway is removed from the
+ * gateway tree immediately, else it is removed on a delayed schedule.
  */
-void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen) {
+void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen, bool immediate) {
   struct gateway_entry *gw = node2gateway(avl_find(&gateway_tree, originator));
   bool change = false;
 
@@ -395,6 +397,11 @@ void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen
     return;
   }
 
+  if (immediate && gw->cleanup_timer) {
+    /* stop timer if we have to remove immediately */
+    olsr_set_timer(&gw->cleanup_timer, 0, 0, false, NULL, NULL, NULL);
+  }
+
   if (gw->cleanup_timer == NULL || gw->ipv4 || gw->ipv6) {
     /* found a gw and it wasn't deleted yet */
 
@@ -437,8 +444,12 @@ void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen
         v6gw_tunnel = NULL;
       }
 
-      /* remove gateway entry on a delayed schedule */
-      olsr_set_timer(&gw->cleanup_timer, GW_CLEANUP_INTERVAL, 0, false, cleanup_gateway_handler, gw, NULL);
+      if (!immediate) {
+        /* remove gateway entry on a delayed schedule */
+        olsr_set_timer(&gw->cleanup_timer, GW_CLEANUP_INTERVAL, 0, false, cleanup_gateway_handler, gw, NULL);
+      } else {
+        cleanup_gateway_handler(gw);
+      }
     } else if (change) {
       assert(gw_handler);
       gw_handler->update(gw);
index 0ddaa6f..91e9170 100644 (file)
@@ -152,7 +152,7 @@ void refresh_smartgw_netmask(void);
 
 bool olsr_is_smart_gateway(struct olsr_ip_prefix *prefix, union olsr_ip_addr *net);
 void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_addr *mask, int prefixlen, uint16_t seqno);
-void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen);
+void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen, bool immediate);
 void olsr_trigger_gatewayloss_check(void);
 
 /*
index 33280fe..2ce3c7d 100644 (file)
@@ -216,7 +216,7 @@ olsr_delete_hna_net_entry(struct hna_net *net_to_delete) {
 #ifdef __linux__
   if (is_prefix_inetgw(&net_to_delete->hna_prefix)) {
     /* modify smart gateway entry if necessary */
-    olsr_delete_gateway_entry(&net_to_delete->hna_gw->A_gateway_addr, net_to_delete->hna_prefix.prefix_len);
+    olsr_delete_gateway_entry(&net_to_delete->hna_gw->A_gateway_addr, net_to_delete->hna_prefix.prefix_len, false);
   }
 #endif /* __linux__ */
 
index 3fbb98a..99a8f08 100644 (file)
@@ -283,7 +283,7 @@ olsr_delete_tc_entry(struct tc_entry *tc)
 
   /* delete gateway if available */
 #ifdef __linux__
-  olsr_delete_gateway_entry(&tc->addr, FORCE_DELETE_GW_ENTRY);
+  olsr_delete_gateway_entry(&tc->addr, FORCE_DELETE_GW_ENTRY, false);
 #endif /* __linux__ */
   /*
    * Delete the rt_path for ourselves.