author Ferry Huberts Mon, 30 Jul 2012 11:07:52 +0000 (13:07 +0200) committer Ferry Huberts Wed, 1 Aug 2012 09:38:42 +0000 (11:38 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>

@@ -38,6 +38,24 @@ static struct olsr_gw_handler gw_def_handler = {
* Helper functions
*/

+/**
+ * Calculate the threshold path cost.
+ *
+ * @param path_cost the path cost
+ * @return the threshold path cost
+ */
+
+  if (olsr_cnf->smart_gw_thresh == 0) {
+    path_cost_times_threshold = path_cost;
+  } else {
+    path_cost_times_threshold = ((long long) path_cost * (long long) olsr_cnf->smart_gw_thresh + 50LL) / 100LL;
+  }
+
+  return path_cost_times_threshold;
+}
+
/**
* Look through the gateway list and select the best gateway
* depending on the distance to this router
@@ -70,11 +88,7 @@ static void gw_default_choose_gateway(void) {
}

/* determine the path costs threshold */
-    if (olsr_cnf->smart_gw_thresh == 0) {
-      path_cost_times_threshold = tc->path_cost;
-    } else {
-      path_cost_times_threshold = ((long long)tc->path_cost * (long long)olsr_cnf->smart_gw_thresh + 50LL) / 100LL;
-    }
+    path_cost_times_threshold = gw_default_calc_threshold(tc->path_cost);

if (!gw_def_finished_ipv4 && gw->ipv4 && gw->ipv4nat == olsr_cnf->smart_gw_allow_nat && path_cost_times_threshold < cost_ipv4) {
inet_ipv4 = gw;