sgw: preserve sgw tunnel ordering in iptables rules
authorFerry Huberts <ferry.huberts@pelagic.nl>
Sat, 28 May 2016 21:16:52 +0000 (23:16 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Sat, 28 May 2016 21:37:13 +0000 (23:37 +0200)
Run the script on the reversed list of sgw tunnels so that the script
can simply insert rules at the head of the tables to preserve ordering.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/gateway.c

index fed87b0..847593a 100644 (file)
@@ -529,17 +529,16 @@ static bool multiGwRulesEgressInterfaces(bool add) {
 static bool multiGwRulesSgwTunnels(bool add) {
   bool ok = true;
   unsigned int i = 0;
+  uint8_t count = olsr_cnf->smart_gw_use_count;
 
-  while (i < olsr_cnf->smart_gw_use_count) {
-    struct interfaceName * ifn = (olsr_cnf->ip_version == AF_INET) ? &sgwTunnel4InterfaceNames[i] : &sgwTunnel6InterfaceNames[i];
+  while (++i <= count) {
+    struct interfaceName * ifn = (olsr_cnf->ip_version == AF_INET) ? &sgwTunnel4InterfaceNames[count - i] : &sgwTunnel6InterfaceNames[count - i];
     if (!multiGwRunScript(SCRIPT_MODE_SGWTUN, add, ifn->name, ifn->tableNr, ifn->ruleNr, ifn->bypassRuleNr)) {
       ok = false;
       if (add) {
         return ok;
       }
     }
-
-    i++;
   }
 
   return ok;