]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce route_dup()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 May 2021 19:47:26 +0000 (04:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 May 2021 02:22:24 +0000 (11:22 +0900)
The function will be used in later commits.

src/network/networkd-route.c
src/network/networkd-route.h

index e1dd93775f4164d6485b1284f91152d4b6708b31..0ba1dcfe5cf6f990455537f00396b1e49a517296 100644 (file)
@@ -510,6 +510,44 @@ static void route_copy(Route *dest, const Route *src, const MultipathRoute *m, c
         }
 }
 
+int route_dup(const Route *src, Route **ret) {
+        _cleanup_(route_freep) Route *dest = NULL;
+        MultipathRoute *m;
+        int r;
+
+        assert(src);
+        assert(ret);
+
+        dest = newdup(Route, src, 1);
+        if (!dest)
+                return -ENOMEM;
+
+        /* Unset all pointers */
+        dest->network = NULL;
+        dest->section = NULL;
+        dest->link = NULL;
+        dest->manager = NULL;
+        dest->multipath_routes = NULL;
+        dest->expire = NULL;
+
+        ORDERED_SET_FOREACH(m, src->multipath_routes) {
+                _cleanup_(multipath_route_freep) MultipathRoute *n = NULL;
+
+                r = multipath_route_dup(m, &n);
+                if (r < 0)
+                        return r;
+
+                r = ordered_set_ensure_put(&dest->multipath_routes, NULL, n);
+                if (r < 0)
+                        return r;
+
+                TAKE_PTR(n);
+        }
+
+        *ret = TAKE_PTR(dest);
+        return 0;
+}
+
 static int route_add_internal(Manager *manager, Link *link, Set **routes, const Route *in, Route **ret) {
         _cleanup_(route_freep) Route *route = NULL;
         int r;
index 1ad5a1b9935a4aa7216f963a2b2c3d45bfa75cba..0cbeb44fcb20c26aa2dc1017093c4bf3d4be888c 100644 (file)
@@ -71,6 +71,7 @@ extern const struct hash_ops route_hash_ops;
 int route_new(Route **ret);
 Route *route_free(Route *route);
 DEFINE_NETWORK_SECTION_FUNCTIONS(Route, route_free);
+int route_dup(const Route *src, Route **ret);
 
 int route_configure(const Route *route, Link *link, link_netlink_message_handler_t callback, Route **ret);
 int route_remove(const Route *route, Manager *manager, Link *link, link_netlink_message_handler_t callback);