network: introduce route_dup()

The function will be used in later commits.
This commit is contained in:
Yu Watanabe
2021-05-12 11:22:24 +09:00
parent 4867b9d711
commit c0bd9eb1ed
2 changed files with 39 additions and 0 deletions
+38
View 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;
+1
View 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);