[Olsr-dev] [PATCH v1 3/5] gateway: add helper function gw_default_calc_threshold
Ferry Huberts
(spam-protected)
Mon Jul 30 15:13:15 CEST 2012
From: Ferry Huberts <(spam-protected)>
Signed-off-by: Ferry Huberts <(spam-protected)>
---
src/gateway_default_handler.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/gateway_default_handler.c b/src/gateway_default_handler.c
index d0ee880..d8a5adb 100644
--- a/src/gateway_default_handler.c
+++ b/src/gateway_default_handler.c
@@ -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;
--
1.7.11.2
More information about the Olsr-dev
mailing list