sgw: move add/remove of ifchange handler to better place
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 2 Oct 2014 09:41:34 +0000 (11:41 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 8 Oct 2014 08:31:37 +0000 (10:31 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/gateway.c

index 76501ca..900698c 100644 (file)
@@ -654,8 +654,6 @@ int olsr_init_gateways(void) {
     return 1;
   }
 
-  olsr_add_ifchange_handler(smartgw_tunnel_monitor);
-
   return 0;
 }
 
@@ -666,6 +664,7 @@ int olsr_startup_gateways(void) {
   bool ok = true;
 
   if (!multi_gateway_mode()) {
+    olsr_add_ifchange_handler(smartgw_tunnel_monitor);
     return 0;
   }
 
@@ -680,6 +679,8 @@ int olsr_startup_gateways(void) {
     return 1;
   }
 
+  olsr_add_ifchange_handler(smartgw_tunnel_monitor);
+
   if (olsr_cnf->smart_gw_takedown_percentage > 0) {
     /* start gateway takedown timer */
     olsr_set_timer(&gw_takedown_timer, olsr_cnf->smart_gw_period, 0, true, &gw_takedown_timer_callback, NULL, 0);
@@ -693,6 +694,7 @@ int olsr_startup_gateways(void) {
  */
 void olsr_shutdown_gateways(void) {
   if (!multi_gateway_mode()) {
+    olsr_remove_ifchange_handler(smartgw_tunnel_monitor);
     return;
   }
 
@@ -702,6 +704,8 @@ void olsr_shutdown_gateways(void) {
     gw_takedown_timer = NULL;
   }
 
+  olsr_remove_ifchange_handler(smartgw_tunnel_monitor);
+
   (void)multiGwRulesSgwTunnels(false);
   (void)multiGwRulesEgressInterfaces(false);
   (void)multiGwRulesOlsrInterfaces(false);
@@ -716,8 +720,6 @@ void olsr_cleanup_gateways(void) {
   struct gateway_entry * tree_gw;
   struct gw_container_entry * gw;
 
-  olsr_remove_ifchange_handler(smartgw_tunnel_monitor);
-
   /* remove all gateways in the gateway tree that are not the active gateway */
   OLSR_FOR_ALL_GATEWAY_ENTRIES(tree_gw) {
     if ((tree_gw != olsr_get_inet_gateway(false)) && (tree_gw != olsr_get_inet_gateway(true))) {