]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: use same order in _hash_func() and _compare_func()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 17 Sep 2019 17:11:31 +0000 (19:11 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 17 Sep 2019 17:11:50 +0000 (19:11 +0200)
This makes it easier to see that the same data is handled in both cases.
No functional change.

src/network/networkd-route.c
src/network/networkd-routing-policy-rule.c

index bae7cd8f96038e25d9d2032c16f51941446478f7..85df5d9395f4e2d56fa8400fe944f237a48c5ed7 100644 (file)
@@ -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;
index 9443db02fd6c2a9fce1a892270a7eef574fd045c..1c2c28b02ac646ba136df161487d5a18922e2aeb 100644 (file)
@@ -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;