tree-wide: Convert compare_func's to use CMP() macro wherever possible.
Looked for definitions of functions using the *_compare_func() suffix. Tested: - Unit tests passed (ninja -C build/ test) - Installed this build and booted with it.
This commit is contained in:
@@ -144,19 +144,18 @@ static void address_hash_func(const void *b, struct siphash *state) {
|
||||
|
||||
static int address_compare_func(const void *c1, const void *c2) {
|
||||
const Address *a1 = c1, *a2 = c2;
|
||||
int r;
|
||||
|
||||
if (a1->family < a2->family)
|
||||
return -1;
|
||||
if (a1->family > a2->family)
|
||||
return 1;
|
||||
r = CMP(a1->family, a2->family);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
switch (a1->family) {
|
||||
/* use the same notion of equality as the kernel does */
|
||||
case AF_INET:
|
||||
if (a1->prefixlen < a2->prefixlen)
|
||||
return -1;
|
||||
if (a1->prefixlen > a2->prefixlen)
|
||||
return 1;
|
||||
r = CMP(a1->prefixlen, a2->prefixlen);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
/* compare the peer prefixes */
|
||||
if (a1->prefixlen != 0) {
|
||||
@@ -174,10 +173,9 @@ static int address_compare_func(const void *c1, const void *c2) {
|
||||
else
|
||||
b2 = be32toh(a2->in_addr.in.s_addr) >> (32 - a1->prefixlen);
|
||||
|
||||
if (b1 < b2)
|
||||
return -1;
|
||||
if (b1 > b2)
|
||||
return 1;
|
||||
r = CMP(b1, b2);
|
||||
if (r != 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
_fallthrough_;
|
||||
|
||||
@@ -164,34 +164,30 @@ static void route_hash_func(const void *b, struct siphash *state) {
|
||||
|
||||
static int route_compare_func(const void *_a, const void *_b) {
|
||||
const Route *a = _a, *b = _b;
|
||||
int r;
|
||||
|
||||
if (a->family < b->family)
|
||||
return -1;
|
||||
if (a->family > b->family)
|
||||
return 1;
|
||||
r = CMP(a->family, b->family);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
switch (a->family) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
if (a->dst_prefixlen < b->dst_prefixlen)
|
||||
return -1;
|
||||
if (a->dst_prefixlen > b->dst_prefixlen)
|
||||
return 1;
|
||||
r = CMP(a->dst_prefixlen, b->dst_prefixlen);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->tos < b->tos)
|
||||
return -1;
|
||||
if (a->tos > b->tos)
|
||||
return 1;
|
||||
r = CMP(a->tos, b->tos);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->priority < b->priority)
|
||||
return -1;
|
||||
if (a->priority > b->priority)
|
||||
return 1;
|
||||
r = CMP(a->priority, b->priority);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->table < b->table)
|
||||
return -1;
|
||||
if (a->table > b->table)
|
||||
return 1;
|
||||
r = CMP(a->table, b->table);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
return memcmp(&a->dst, &b->dst, FAMILY_ADDRESS_SIZE(a->family));
|
||||
default:
|
||||
|
||||
@@ -92,38 +92,32 @@ static int routing_policy_rule_compare_func(const void *_a, const void *_b) {
|
||||
const RoutingPolicyRule *a = _a, *b = _b;
|
||||
int r;
|
||||
|
||||
if (a->family < b->family)
|
||||
return -1;
|
||||
if (a->family > b->family)
|
||||
return 1;
|
||||
r = CMP(a->family, b->family);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
switch (a->family) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
if (a->from_prefixlen < b->from_prefixlen)
|
||||
return -1;
|
||||
if (a->from_prefixlen > b->from_prefixlen)
|
||||
return 1;
|
||||
r = CMP(a->from_prefixlen, b->from_prefixlen);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->to_prefixlen < b->to_prefixlen)
|
||||
return -1;
|
||||
if (a->to_prefixlen > b->to_prefixlen)
|
||||
return 1;
|
||||
r = CMP(a->to_prefixlen, b->to_prefixlen);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->tos < b->tos)
|
||||
return -1;
|
||||
if (a->tos > b->tos)
|
||||
return 1;
|
||||
r = CMP(a->tos, b->tos);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->fwmask < b->fwmark)
|
||||
return -1;
|
||||
if (a->fwmask > b->fwmark)
|
||||
return 1;
|
||||
r = CMP(a->fwmask, b->fwmask);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->table < b->table)
|
||||
return -1;
|
||||
if (a->table > b->table)
|
||||
return 1;
|
||||
r = CMP(a->table, b->table);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
r = strcmp_ptr(a->iif, b->iif);
|
||||
if (!r)
|
||||
|
||||
Reference in New Issue
Block a user