gw: simplify overlap checking code
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 18 Feb 2014 14:51:16 +0000 (15:51 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 18 Feb 2014 14:59:15 +0000 (15:59 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/cfgparser/olsrd_conf.c

index c1f6652..816ac0b 100644 (file)
@@ -655,11 +655,14 @@ olsrd_sanity_check_cnf(struct olsrd_config *cnf)
         return -1;
       }
 
+#define valueInRange(value, low, high) ((low <= value) && (value <= high))
+
+#define rangesOverlap(low1, high1, low2, high2) ( \
+                     valueInRange(low1 , low2, high2) || valueInRange(high1, low2, high2) || \
+                     valueInRange(low2,  low1, high1) || valueInRange(high2, low1, high1))
+
       /* check that the egress and tunnel marks ranges do not overlap */
-      overlap =            ((tunnelsLow <= egressLow)   && (egressLow   <= tunnelsHigh));
-      overlap = overlap || ((tunnelsLow <= egressHigh)  && (egressHigh  <= tunnelsHigh));
-      overlap = overlap || ((egressLow  <= tunnelsLow)  && (tunnelsLow  <= egressHigh));
-      overlap = overlap || ((egressLow  <= tunnelsHigh) && (tunnelsHigh <= egressHigh));
+      overlap = rangesOverlap(egressLow, egressHigh, tunnelsLow, tunnelsHigh);
       if (overlap) {
         fprintf(stderr, "Error, egress interface mark range [%u, %u] overlaps with tunnel interface mark range [%u, %u]\n",
             egressLow, egressHigh, tunnelsLow, tunnelsHigh);