]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: make nexthop_configure() take callback
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 26 Apr 2021 07:05:04 +0000 (16:05 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 May 2021 01:30:45 +0000 (10:30 +0900)
src/network/networkd-nexthop.c

index f3dbd98ed12b0b0b60f4ff155309c9813f2984df..b0759cac9019590cad13f51b829cc1aac8f94621 100644 (file)
@@ -406,37 +406,12 @@ static int nexthop_remove(const NextHop *nexthop, Manager *manager, Link *link)
         return 0;
 }
 
-static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
-        int r;
-
-        assert(link);
-        assert(link->nexthop_messages > 0);
+static int nexthop_configure(
+                const NextHop *nexthop,
+                Link *link,
+                link_netlink_message_handler_t callback,
+                NextHop **ret) {
 
-        link->nexthop_messages--;
-
-        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
-                return 1;
-
-        r = sd_netlink_message_get_errno(m);
-        if (r < 0 && r != -EEXIST) {
-                log_link_message_warning_errno(link, m, r, "Could not set nexthop");
-                link_enter_failed(link);
-                return 1;
-        }
-
-        if (link->nexthop_messages == 0) {
-                log_link_debug(link, "Nexthops set");
-                link->static_nexthops_configured = true;
-                /* Now all nexthops are configured. Let's configure remaining routes. */
-                r = link_set_routes_with_gateway(link);
-                if (r < 0)
-                        link_enter_failed(link);
-        }
-
-        return 1;
-}
-
-static int nexthop_configure(const NextHop *nexthop, Link *link) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
         int r;
 
@@ -445,6 +420,7 @@ static int nexthop_configure(const NextHop *nexthop, Link *link) {
         assert(link->manager->rtnl);
         assert(link->ifindex > 0);
         assert(IN_SET(nexthop->family, AF_INET, AF_INET6));
+        assert(callback);
 
         log_nexthop_debug(nexthop, nexthop->id, "Configuring", link);
 
@@ -482,20 +458,50 @@ static int nexthop_configure(const NextHop *nexthop, Link *link) {
                 }
         }
 
-        r = netlink_call_async(link->manager->rtnl, NULL, req, nexthop_handler,
+        r = netlink_call_async(link->manager->rtnl, NULL, req, callback,
                                link_netlink_destroy_callback, link);
         if (r < 0)
                 return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
 
         link_ref(link);
 
-        r = nexthop_add(link, nexthop, NULL);
+        r = nexthop_add(link, nexthop, ret);
         if (r < 0)
                 return log_link_error_errno(link, r, "Could not add nexthop: %m");
 
         return r;
 }
 
+static int static_nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+        int r;
+
+        assert(link);
+        assert(link->nexthop_messages > 0);
+
+        link->nexthop_messages--;
+
+        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+                return 1;
+
+        r = sd_netlink_message_get_errno(m);
+        if (r < 0 && r != -EEXIST) {
+                log_link_message_warning_errno(link, m, r, "Could not set nexthop");
+                link_enter_failed(link);
+                return 1;
+        }
+
+        if (link->nexthop_messages == 0) {
+                log_link_debug(link, "Nexthops set");
+                link->static_nexthops_configured = true;
+                /* Now all nexthops are configured. Let's configure remaining routes. */
+                r = link_set_routes_with_gateway(link);
+                if (r < 0)
+                        link_enter_failed(link);
+        }
+
+        return 1;
+}
+
 int link_set_nexthops(Link *link) {
         enum {
                 PHASE_ID,         /* First phase: Nexthops with ID */
@@ -520,7 +526,7 @@ int link_set_nexthops(Link *link) {
                         if ((nh->id > 0) != (phase == PHASE_ID))
                                 continue;
 
-                        r = nexthop_configure(nh, link);
+                        r = nexthop_configure(nh, link, static_nexthop_handler, NULL);
                         if (r < 0)
                                 return log_link_warning_errno(link, r, "Could not set nexthop: %m");