From: Yu Watanabe Date: Thu, 6 May 2021 19:45:02 +0000 (+0900) Subject: sd-netlink: introduce multipath_route_dup() X-Git-Tag: v249-rc1~240^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4867b9d711d036c12d5fa4310c9aef52342ca863;p=thirdparty%2Fsystemd.git sd-netlink: introduce multipath_route_dup() The function will be used in later commits. --- diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c index 4ab3b1020c7..90a184319a9 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 394c821ffba..98bbfa45133 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);