gateway: add helper function gw_default_calc_threshold
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 30 Jul 2012 11:07:52 +0000 (13:07 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 1 Aug 2012 09:38:42 +0000 (11:38 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/gateway_default_handler.c

index d0ee880..d8a5adb 100644 (file)
@@ -39,6 +39,24 @@ static struct olsr_gw_handler gw_def_handler = {
  */
 
 /**
+ * Calculate the threshold path cost.
+ *
+ * @param path_cost the path cost
+ * @return the threshold path cost
+ */
+static inline olsr_linkcost gw_default_calc_threshold(olsr_linkcost path_cost) {
+  olsr_linkcost path_cost_times_threshold;
+
+  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;