]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: move link_request_set_nexthop() to networkd-nexthop.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Sep 2020 08:18:55 +0000 (17:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 6 Oct 2020 17:39:51 +0000 (02:39 +0900)
src/network/networkd-link.c
src/network/networkd-nexthop.c
src/network/networkd-nexthop.h

index 685cbd34cfe43c35c115c26847d50475d9b430e3..dca9b1550cc13d7eba02052f2935717e1b1d6f5a 100644 (file)
@@ -925,60 +925,6 @@ static void link_enter_configured(Link *link) {
         link_dirty(link);
 }
 
-static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
-        int r;
-
-        assert(link);
-        assert(link->nexthop_messages > 0);
-        assert(IN_SET(link->state, LINK_STATE_CONFIGURING,
-                      LINK_STATE_FAILED, LINK_STATE_LINGER));
-
-        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, "Nexthop set");
-                link->static_nexthops_configured = true;
-                link_check_ready(link);
-        }
-
-        return 1;
-}
-
-static int link_request_set_nexthop(Link *link) {
-        NextHop *nh;
-        int r;
-
-        link->static_nexthops_configured = false;
-
-        LIST_FOREACH(nexthops, nh, link->network->static_nexthops) {
-                r = nexthop_configure(nh, link, nexthop_handler);
-                if (r < 0)
-                        return log_link_warning_errno(link, r, "Could not set nexthop: %m");
-                if (r > 0)
-                        link->nexthop_messages++;
-        }
-
-        if (link->nexthop_messages == 0) {
-                link->static_nexthops_configured = true;
-                link_check_ready(link);
-        } else {
-                log_link_debug(link, "Setting nexthop");
-                link_set_state(link, LINK_STATE_CONFIGURING);
-        }
-
-        return 1;
-}
-
 static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
         int r;
 
@@ -1002,7 +948,7 @@ static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
         if (link->route_messages == 0) {
                 log_link_debug(link, "Routes set");
                 link->static_routes_configured = true;
-                link_request_set_nexthop(link);
+                link_set_nexthop(link);
         }
 
         return 1;
@@ -1053,7 +999,7 @@ int link_request_set_routes(Link *link) {
 
         if (link->route_messages == 0) {
                 link->static_routes_configured = true;
-                link_request_set_nexthop(link);
+                link_set_nexthop(link);
         } else {
                 log_link_debug(link, "Setting routes");
                 link_set_state(link, LINK_STATE_CONFIGURING);
index 6d89be1a25d55a48f48d682959289b9a9c26967d..6b16c0f00afed70cd4ccec72b7196f6d4fa01437 100644 (file)
@@ -319,10 +319,34 @@ int nexthop_remove(NextHop *nexthop, Link *link,
         return 0;
 }
 
-int nexthop_configure(
-                NextHop *nexthop,
-                Link *link,
-                link_netlink_message_handler_t callback) {
+static int 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, "Nexthop set");
+                link->static_nexthops_configured = true;
+                link_check_ready(link);
+        }
+
+        return 1;
+}
+
+static int nexthop_configure(NextHop *nexthop, Link *link) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
         int r;
 
@@ -331,7 +355,6 @@ int nexthop_configure(
         assert(link->manager->rtnl);
         assert(link->ifindex > 0);
         assert(IN_SET(nexthop->family, AF_INET, AF_INET6));
-        assert(callback);
 
         if (DEBUG_LOGGING) {
                 _cleanup_free_ char *gw = NULL;
@@ -366,7 +389,7 @@ int nexthop_configure(
                         return log_link_error_errno(link, r, "Could not set nexthop family: %m");
         }
 
-        r = netlink_call_async(link->manager->rtnl, NULL, req, callback,
+        r = netlink_call_async(link->manager->rtnl, NULL, req, nexthop_handler,
                                link_netlink_destroy_callback, link);
         if (r < 0)
                 return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -380,6 +403,34 @@ int nexthop_configure(
         return 1;
 }
 
+int link_set_nexthop(Link *link) {
+        NextHop *nh;
+        int r;
+
+        assert(link);
+        assert(link->network);
+
+        link->static_nexthops_configured = false;
+
+        LIST_FOREACH(nexthops, nh, link->network->static_nexthops) {
+                r = nexthop_configure(nh, link);
+                if (r < 0)
+                        return log_link_warning_errno(link, r, "Could not set nexthop: %m");
+                if (r > 0)
+                        link->nexthop_messages++;
+        }
+
+        if (link->nexthop_messages == 0) {
+                link->static_nexthops_configured = true;
+                link_check_ready(link);
+        } else {
+                log_link_debug(link, "Setting nexthop");
+                link_set_state(link, LINK_STATE_CONFIGURING);
+        }
+
+        return 1;
+}
+
 int nexthop_section_verify(NextHop *nh) {
         if (section_is_invalid(nh->section))
                 return -EINVAL;
index 28cbdad738e770e42c56b31914932a3407f325f9..cd9958824c98a564cb3d0f9faa20ba3795f3db33 100644 (file)
@@ -34,9 +34,10 @@ extern const struct hash_ops nexthop_hash_ops;
 
 int nexthop_new(NextHop **ret);
 void nexthop_free(NextHop *nexthop);
-int nexthop_configure(NextHop *nexthop, Link *link, link_netlink_message_handler_t callback);
 int nexthop_remove(NextHop *nexthop, Link *link, link_netlink_message_handler_t callback);
 
+int link_set_nexthop(Link *link);
+
 int nexthop_get(Link *link, NextHop *in, NextHop **ret);
 int nexthop_add(Link *link, NextHop *in, NextHop **ret);
 int nexthop_add_foreign(Link *link, NextHop *in, NextHop **ret);