From: Yu Watanabe Date: Thu, 6 May 2021 19:47:26 +0000 (+0900) Subject: network: introduce route_dup() X-Git-Tag: v249-rc1~240^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0bd9eb1ed42cb0981f1c5a77c0f045bd326d350;p=thirdparty%2Fsystemd.git network: introduce route_dup() The function will be used in later commits. --- 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);