gateway: minor speed improvement in gw_default_choose_gateway
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 16 Jan 2013 20:24:46 +0000 (21:24 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 17 Jan 2013 09:02:00 +0000 (10:02 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/gateway_default_handler.c

index cbde3e2..dd28e4f 100644 (file)
@@ -185,29 +185,31 @@ static void gw_default_choose_gateway(void) {
   }
 
   OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
   }
 
   OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
-    bool gw_eligible_v4;
-    bool gw_eligible_v6;
     uint64_t path_cost = gw_default_getcosts(gw);
 
     if (path_cost == UINT64_MAX) {
       continue;
     }
 
     uint64_t path_cost = gw_default_getcosts(gw);
 
     if (path_cost == UINT64_MAX) {
       continue;
     }
 
-    gw_eligible_v4 = gw->ipv4
-        /* && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit) */
-        && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat);
-    if (!gw_def_finished_ipv4 && gw_eligible_v4 && path_cost < cost_ipv4
-        && (!eval_cost_ipv4_threshold || (path_cost < cost_ipv4_threshold))) {
-      inet_ipv4 = gw;
-      cost_ipv4 = path_cost;
+    if (!gw_def_finished_ipv4) {
+      bool gw_eligible_v4 = gw->ipv4
+          /* && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit) */
+          && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat);
+      if (gw_eligible_v4 && path_cost < cost_ipv4
+          && (!eval_cost_ipv4_threshold || (path_cost < cost_ipv4_threshold))) {
+        inet_ipv4 = gw;
+        cost_ipv4 = path_cost;
+      }
     }
 
     }
 
-    gw_eligible_v6 = gw->ipv6
-        /* && olsr_cnf->ip_version == AF_INET6 */;
-    if (!gw_def_finished_ipv6 && gw_eligible_v6 && path_cost < cost_ipv6
-        && (!eval_cost_ipv6_threshold || (path_cost < cost_ipv6_threshold))) {
-      inet_ipv6 = gw;
-      cost_ipv6 = path_cost;
+    if (!gw_def_finished_ipv6) {
+      bool gw_eligible_v6 = gw->ipv6
+          /* && olsr_cnf->ip_version == AF_INET6 */;
+      if (gw_eligible_v6 && path_cost < cost_ipv6
+          && (!eval_cost_ipv6_threshold || (path_cost < cost_ipv6_threshold))) {
+        inet_ipv6 = gw;
+        cost_ipv6 = path_cost;
+      }
     }
   } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
 
     }
   } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)