diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-05-07 04:45:02 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-05-12 10:39:12 +0900 |
commit | 4867b9d711d036c12d5fa4310c9aef52342ca863 (patch) | |
tree | 760f4abdcf74490ac1e442bd83e3e88ee5caffa5 /src/libsystemd | |
parent | d94e8ba02193a2739d3ed8f7df293384b16a98c3 (diff) | |
download | systemd-4867b9d711d036c12d5fa4310c9aef52342ca863.tar.gz |
sd-netlink: introduce multipath_route_dup()
The function will be used in later commits.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-util.c | 29 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-util.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c index 4ab3b1020c..90a184319a 100644 --- a/src/libsystemd/sd-netlink/netlink-util.c +++ b/src/libsystemd/sd-netlink/netlink-util.c @@ -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; diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h index 394c821ffb..98bbfa4513 100644 --- a/src/libsystemd/sd-netlink/netlink-util.h +++ b/src/libsystemd/sd-netlink/netlink-util.h @@ -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); |