gateway: always select a new gateway when threshold != 0
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 31 Jan 2013 11:20:29 +0000 (12:20 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 31 Jan 2013 11:39:14 +0000 (12:39 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/gateway_default_handler.c

index aecf9cc..3957b3a 100644 (file)
@@ -377,12 +377,18 @@ static void gw_default_choosegw_handler(bool ipv4, bool ipv6) {
  * @param gw the gateway entry
  */
 static void gw_default_update_handler(struct gateway_entry *gw) {
-  bool v4changed = gw && (gw == olsr_get_inet_gateway(false))
-      && (!gw->ipv4 || (gw->ipv4nat && !olsr_cnf->smart_gw_allow_nat));
-  bool v6changed = gw && (gw == olsr_get_inet_gateway(true)) && !gw->ipv6;
+  if (olsr_cnf->smart_gw_thresh == 0) {
+    /* classical behaviour: stick with the chosen gateway unless it changes */
+    bool v4changed = gw && (gw == olsr_get_inet_gateway(false))
+        && (!gw->ipv4 || (gw->ipv4nat && !olsr_cnf->smart_gw_allow_nat));
+    bool v6changed = gw && (gw == olsr_get_inet_gateway(true)) && !gw->ipv6;
 
-  if (v4changed || v6changed) {
-    gw_default_lookup_gateway(v4changed, v6changed);
+    if (v4changed || v6changed) {
+      gw_default_lookup_gateway(v4changed, v6changed);
+    }
+  } else {
+    /* new behaviour: always pick a new gateway */
+    gw_default_lookup_gateway(true, true);
   }
 }