sd-netlink: introduce multipath_route_dup()

The function will be used in later commits.
This commit is contained in:
Yu Watanabe
2021-05-12 10:39:12 +09:00
parent d94e8ba021
commit 4867b9d711
2 changed files with 31 additions and 0 deletions
+29
View File
@@ -418,6 +418,35 @@ MultipathRoute *multipath_route_free(MultipathRoute *m) {
return mfree(m);
}
int multipath_route_dup(const MultipathRoute *m, MultipathRoute **ret) {
_cleanup_(multipath_route_freep) MultipathRoute *n = NULL;
_cleanup_free_ char *ifname = NULL;
assert(m);
assert(ret);
if (m->ifname) {
ifname = strdup(m->ifname);
if (!ifname)
return -ENOMEM;
}
n = new(MultipathRoute, 1);
if (!n)
return -ENOMEM;
*n = (MultipathRoute) {
.gateway = m->gateway,
.weight = m->weight,
.ifindex = m->ifindex,
.ifname = TAKE_PTR(ifname),
};
*ret = TAKE_PTR(n);
return 0;
}
int rtattr_read_nexthop(const struct rtnexthop *rtnh, size_t size, int family, OrderedSet **ret) {
_cleanup_ordered_set_free_free_ OrderedSet *set = NULL;
int r;
+2
View File
@@ -27,6 +27,8 @@ typedef struct MultipathRoute {
MultipathRoute *multipath_route_free(MultipathRoute *m);
DEFINE_TRIVIAL_CLEANUP_FUNC(MultipathRoute*, multipath_route_free);
int multipath_route_dup(const MultipathRoute *m, MultipathRoute **ret);
int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret);
uint32_t rtnl_message_get_serial(sd_netlink_message *m);
void rtnl_message_seal(sd_netlink_message *m);