]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: introduce multipath_route_dup()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 May 2021 19:45:02 +0000 (04:45 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 May 2021 01:39:12 +0000 (10:39 +0900)
The function will be used in later commits.

src/libsystemd/sd-netlink/netlink-util.c
src/libsystemd/sd-netlink/netlink-util.h

index 4ab3b1020c7371f479c881ee2d8936c8ea8e0c71..90a184319a9b4d2642bb044d9290b0b863661778 100644 (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;
index 394c821ffba051323d8075b72be0564b70410c6f..98bbfa451337949bbb752cb804bb2c2bd5815e68 100644 (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);