[Olsr-dev] [PATCH v2 5/7] gateway: allow immediate removal of a gateway entry

Ferry Huberts (spam-protected)
Thu Oct 18 11:50:41 CEST 2012


From: Ferry Huberts <(spam-protected)>

This is going to be used by the cleanup function later on.

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/gateway.c | 17 ++++++++++++++---
 src/gateway.h |  2 +-
 src/hna_set.c |  2 +-
 src/tc_set.c  |  2 +-
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/gateway.c b/src/gateway.c
index 098847f..be55ef7 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -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);
diff --git a/src/gateway.h b/src/gateway.h
index 0ddaa6f..91e9170 100644
--- a/src/gateway.h
+++ b/src/gateway.h
@@ -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);
 
 /*
diff --git a/src/hna_set.c b/src/hna_set.c
index 33280fe..2ce3c7d 100644
--- a/src/hna_set.c
+++ b/src/hna_set.c
@@ -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__ */
 
diff --git a/src/tc_set.c b/src/tc_set.c
index 1f9da04..d32ec39 100644
--- a/src/tc_set.c
+++ b/src/tc_set.c
@@ -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.
-- 
1.7.11.7





More information about the Olsr-dev mailing list