From c0bd9eb1ed42cb0981f1c5a77c0f045bd326d350 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 7 May 2021 04:47:26 +0900 Subject: [PATCH] network: introduce route_dup() The function will be used in later commits. --- src/network/networkd-route.c | 38 ++++++++++++++++++++++++++++++++++++ src/network/networkd-route.h | 1 + 2 files changed, 39 insertions(+) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index e1dd93775f4..0ba1dcfe5cf 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -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; diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index 1ad5a1b9935..0cbeb44fcb2 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -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); -- 2.47.3