From 67e05dd8cd01a284e5766e6f64487ddcc60553f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 17 Sep 2019 19:11:31 +0200 Subject: networkd: use same order in _hash_func() and _compare_func() This makes it easier to see that the same data is handled in both cases. No functional change. --- src/network/networkd-route.c | 38 ++++++++++++++++++------------ src/network/networkd-routing-policy-rule.c | 26 ++++++++++---------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index bae7cd8f96..85df5d9395 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -157,11 +157,14 @@ static void route_hash_func(const Route *route, struct siphash *state) { switch (route->family) { case AF_INET: case AF_INET6: - siphash24_compress(&route->gw, FAMILY_ADDRESS_SIZE(route->family), state); - siphash24_compress(&route->dst, FAMILY_ADDRESS_SIZE(route->family), state); siphash24_compress(&route->dst_prefixlen, sizeof(route->dst_prefixlen), state); - siphash24_compress(&route->src, FAMILY_ADDRESS_SIZE(route->family), state); + siphash24_compress(&route->dst, FAMILY_ADDRESS_SIZE(route->family), state); + siphash24_compress(&route->src_prefixlen, sizeof(route->src_prefixlen), state); + siphash24_compress(&route->src, FAMILY_ADDRESS_SIZE(route->family), state); + + siphash24_compress(&route->gw, FAMILY_ADDRESS_SIZE(route->family), state); + siphash24_compress(&route->prefsrc, FAMILY_ADDRESS_SIZE(route->family), state); siphash24_compress(&route->tos, sizeof(route->tos), state); @@ -170,6 +173,7 @@ static void route_hash_func(const Route *route, struct siphash *state) { siphash24_compress(&route->protocol, sizeof(route->protocol), state); siphash24_compress(&route->scope, sizeof(route->scope), state); siphash24_compress(&route->type, sizeof(route->type), state); + siphash24_compress(&route->initcwnd, sizeof(route->initcwnd), state); siphash24_compress(&route->initrwnd, sizeof(route->initrwnd), state); @@ -194,55 +198,59 @@ static int route_compare_func(const Route *a, const Route *b) { if (r != 0) return r; + r = memcmp(&a->dst, &b->dst, FAMILY_ADDRESS_SIZE(a->family)); + if (r != 0) + return r; + r = CMP(a->src_prefixlen, b->src_prefixlen); if (r != 0) return r; - r = CMP(a->tos, b->tos); + r = memcmp(&a->src, &b->src, FAMILY_ADDRESS_SIZE(a->family)); if (r != 0) return r; - r = CMP(a->priority, b->priority); + r = memcmp(&a->gw, &b->gw, FAMILY_ADDRESS_SIZE(a->family)); if (r != 0) return r; - r = CMP(a->table, b->table); + r = memcmp(&a->prefsrc, &b->prefsrc, FAMILY_ADDRESS_SIZE(a->family)); if (r != 0) return r; - r = CMP(a->protocol, b->protocol); + r = CMP(a->tos, b->tos); if (r != 0) return r; - r = CMP(a->scope, b->scope); + r = CMP(a->priority, b->priority); if (r != 0) return r; - r = CMP(a->type, b->type); + r = CMP(a->table, b->table); if (r != 0) return r; - r = CMP(a->initcwnd, b->initcwnd); + r = CMP(a->protocol, b->protocol); if (r != 0) return r; - r = CMP(a->initrwnd, b->initrwnd); + r = CMP(a->scope, b->scope); if (r != 0) return r; - r = memcmp(&a->gw, &b->gw, FAMILY_ADDRESS_SIZE(a->family)); + r = CMP(a->type, b->type); if (r != 0) return r; - r = memcmp(&a->dst, &b->dst, FAMILY_ADDRESS_SIZE(a->family)); + r = CMP(a->initcwnd, b->initcwnd); if (r != 0) return r; - r = memcmp(&a->src, &b->src, FAMILY_ADDRESS_SIZE(a->family)); + r = CMP(a->initrwnd, b->initrwnd); if (r != 0) return r; - return memcmp(&a->prefsrc, &b->prefsrc, FAMILY_ADDRESS_SIZE(a->family)); + return 0; default: /* treat any other address family as AF_UNSPEC */ return 0; diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 9443db02fd..1c2c28b02a 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -105,7 +105,6 @@ static void routing_policy_rule_hash_func(const RoutingPolicyRule *rule, struct switch (rule->family) { case AF_INET: case AF_INET6: - siphash24_compress(&rule->from, FAMILY_ADDRESS_SIZE(rule->family), state); siphash24_compress(&rule->from_prefixlen, sizeof(rule->from_prefixlen), state); @@ -151,10 +150,18 @@ static int routing_policy_rule_compare_func(const RoutingPolicyRule *a, const Ro if (r != 0) return r; + r = memcmp(&a->from, &b->from, FAMILY_ADDRESS_SIZE(a->family)); + if (r != 0) + return r; + r = CMP(a->to_prefixlen, b->to_prefixlen); if (r != 0) return r; + r = memcmp(&a->to, &b->to, FAMILY_ADDRESS_SIZE(a->family)); + if (r != 0) + return r; + r = CMP(a->invert_rule, b->invert_rule); if (r != 0) return r; @@ -179,14 +186,6 @@ static int routing_policy_rule_compare_func(const RoutingPolicyRule *a, const Ro if (r != 0) return r; - r = strcmp_ptr(a->iif, b->iif); - if (!r) - return r; - - r = strcmp_ptr(a->oif, b->oif); - if (!r) - return r; - r = CMP(a->protocol, b->protocol); if (r != 0) return r; @@ -199,12 +198,15 @@ static int routing_policy_rule_compare_func(const RoutingPolicyRule *a, const Ro if (r != 0) return r; - r = memcmp(&a->from, &b->from, FAMILY_ADDRESS_SIZE(a->family)); - if (r != 0) + r = strcmp_ptr(a->iif, b->iif); + if (!r) return r; - return memcmp(&a->to, &b->to, FAMILY_ADDRESS_SIZE(a->family)); + r = strcmp_ptr(a->oif, b->oif); + if (!r) + return r; + return 0; default: /* treat any other address family as AF_UNSPEC */ return 0; -- cgit v1.2.1