return SACMP_CHILD;
if (n2min <= n1min && n1max <= n2max)
return SACMP_PARENT;
- if (n1max == n2min - 1)
+ if (n2min != 0 && n1max == n2min - 1)
return SACMP_ADJACENT_RIGHT;
if (n1max < n2min)
return SACMP_RIGHT;
- if (n2max == n1min - 1)
+ if (n1min != 0 && n2max == n1min - 1)
return SACMP_ADJACENT_LEFT;
if (n2max < n1min)
return SACMP_LEFT;
return SACMP_CHILD;
if (n2min <= n1min && n1max <= n2max)
return SACMP_PARENT;
+ if (n2min != 0 && n1max == n2min - 1)
+ return SACMP_ADJACENT_RIGHT;
if (n1max < n2min)
return SACMP_RIGHT;
+ if (n1min != 0 && n2max == n1min - 1)
+ return SACMP_ADJACENT_LEFT;
if (n2max < n1min)
return SACMP_LEFT;
+
return SACMP_INTERSECTION;
}
return sarray_add((struct sorted_array *) ips, &n);
}
-bool res4_empty(struct resources_ipv4 *ips)
+bool
+res4_empty(struct resources_ipv4 *ips)
{
return sarray_empty((struct sorted_array *) ips);
}
return addr_cmp(a, b) < 0;
}
+/* a + 1 == b? */
+static bool
+addr_is_successor(struct in6_addr const *a, struct in6_addr const *b)
+{
+ struct in6_addr a_plus_1;
+ unsigned int i;
+
+ memcpy(&a_plus_1, a, sizeof(a_plus_1));
+ for (i = 15; i >= 0; i--) {
+ if (a_plus_1.s6_addr[i] != UINT8_MAX) {
+ a_plus_1.s6_addr[i]++;
+ return memcmp(&a_plus_1, b, sizeof(a_plus_1)) == 0;
+ }
+ a_plus_1.s6_addr[i] = 0;
+ }
+
+ return false; /* b cannot be the successor of 0xFFFFF...FFF */
+}
+
static enum sarray_comparison
r6_cmp(void *arg1, void *arg2)
{
return SACMP_CHILD;
if (addr_le(a2min, a1min) && addr_le(a1max, a2max))
return SACMP_PARENT;
+ if (addr_is_successor(a1max, a2min))
+ return SACMP_ADJACENT_RIGHT;
if (addr_lt(a1max, a2min))
return SACMP_RIGHT;
+ if (addr_is_successor(a2max, a1min))
+ return SACMP_ADJACENT_LEFT;
if (addr_lt(a2max, a1min))
return SACMP_LEFT;
+
return SACMP_INTERSECTION;
}
continue;
case SACMP_RIGHT:
case SACMP_ADJACENT_RIGHT:
+ if (mid == sarray->count - 1)
+ return false;
left = mid + 1;
continue;
case SACMP_EQUAL:
case SACMP_CHILD:
return true;
case SACMP_PARENT:
- return false;
case SACMP_INTERSECTION:
- /* Fall through; it's not supposed to happen here. */
- break;
+ return false;
}
pr_crit("Unknown comparison value: %u", cmp);