]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: route: shorten code a bit
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 22 Feb 2021 17:21:31 +0000 (02:21 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 22 Feb 2021 17:21:31 +0000 (02:21 +0900)
src/network/networkd-route.c

index 882b71f9d953748eaf2c3f404b3dc32eab80b383..a74541a6c95e8d56ce63cab98963b74054ef427c 100644 (file)
@@ -451,34 +451,18 @@ static int route_get(const Manager *manager, const Link *link, const Route *in,
         assert(manager || link);
         assert(in);
 
-        if (link) {
-                existing = set_get(link->routes, in);
-                if (existing) {
-                        if (ret)
-                                *ret = existing;
-                        return 1;
-                }
-
-                existing = set_get(link->routes_foreign, in);
-                if (existing) {
-                        if (ret)
-                                *ret = existing;
-                        return 0;
-                }
-        } else {
-                existing = set_get(manager->routes, in);
-                if (existing) {
-                        if (ret)
-                                *ret = existing;
-                        return 1;
-                }
+        existing = set_get(link ? link->routes : manager->routes, in);
+        if (existing) {
+                if (ret)
+                        *ret = existing;
+                return 1;
+        }
 
-                existing = set_get(manager->routes_foreign, in);
-                if (existing) {
-                        if (ret)
-                                *ret = existing;
-                        return 0;
-                }
+        existing = set_get(link ? link->routes_foreign : manager->routes_foreign, in);
+        if (existing) {
+                if (ret)
+                        *ret = existing;
+                return 0;
         }
 
         return -ENOENT;
@@ -488,6 +472,8 @@ static void route_copy(Route *dest, const Route *src, const MultipathRoute *m, c
         assert(dest);
         assert(src);
 
+        /* This only copies entries used by the above hash and compare functions. */
+
         dest->family = src->family;
         dest->src = src->src;
         dest->src_prefixlen = src->src_prefixlen;
@@ -596,19 +582,11 @@ static int route_add(Manager *manager, Link *link, const Route *in, const Multip
                 is_new = true;
         } else if (r == 0) {
                 /* Take over a foreign route */
-                if (link) {
-                        r = set_ensure_put(&link->routes, &route_hash_ops, route);
-                        if (r < 0)
-                                return r;
-
-                        set_remove(link->routes_foreign, route);
-                } else {
-                        r = set_ensure_put(&manager->routes, &route_hash_ops, route);
-                        if (r < 0)
-                                return r;
+                r = set_ensure_put(link ? &link->routes : &manager->routes, &route_hash_ops, route);
+                if (r < 0)
+                        return r;
 
-                        set_remove(manager->routes_foreign, route);
-                }
+                set_remove(link ? link->routes_foreign : manager->routes_foreign, route);
         } else if (r == 1) {
                 /* Route exists, do nothing */
                 ;