]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: forcibly reconfigure all interfaces after sleep
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Nov 2022 04:36:52 +0000 (13:36 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 1 Nov 2022 10:47:33 +0000 (11:47 +0100)
Previously, interfaces are partially reconfigured in a spurious way.
Let's use the same way as `networkctl reconfigure`.

Hopefully fixes #14987 and #24997.

src/network/networkd-link.c
src/network/networkd-manager.c

index 151346f19859b24995a25361c5b26ddfb42a454c..b3dccb7b093235064f8ec72dc4b378e606afdf64 100644 (file)
@@ -1293,46 +1293,10 @@ static int link_force_reconfigure_handler(sd_netlink *rtnl, sd_netlink_message *
         return link_reconfigure_handler_internal(rtnl, m, link, /* force = */ true);
 }
 
-static int link_reconfigure_after_sleep_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
-        int r;
-
-        assert(link);
-
-        r = link_reconfigure_handler_internal(rtnl, m, link, /* force = */ false);
-        if (r != 0)
-                return r;
-
-        /* r == 0 means an error occurs, the link is unmanaged, or the matching network file is unchanged. */
-        if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
-                return 0;
-
-        /* re-request static configs, and restart engines. */
-        r = link_stop_engines(link, false);
-        if (r < 0) {
-                link_enter_failed(link);
-                return 0;
-        }
-
-        r = link_acquire_dynamic_conf(link);
-        if (r < 0) {
-                link_enter_failed(link);
-                return 0;
-        }
-
-        r = link_request_static_configs(link);
-        if (r < 0) {
-                link_enter_failed(link);
-                return 0;
-        }
-
-        return 0;
-}
-
-static int link_reconfigure_internal(Link *link, link_netlink_message_handler_t callback) {
+int link_reconfigure(Link *link, bool force) {
         int r;
 
         assert(link);
-        assert(callback);
 
         /* When link in pending or initialized state, then link_configure() will be called. To prevent
          * the function from being called multiple times simultaneously, refuse to reconfigure the
@@ -1340,21 +1304,13 @@ static int link_reconfigure_internal(Link *link, link_netlink_message_handler_t
         if (IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_INITIALIZED, LINK_STATE_LINGER))
                 return 0; /* 0 means no-op. */
 
-        r = link_call_getlink(link, callback);
+        r = link_call_getlink(link, force ? link_force_reconfigure_handler : link_reconfigure_handler);
         if (r < 0)
                 return r;
 
         return 1; /* 1 means the interface will be reconfigured. */
 }
 
-int link_reconfigure(Link *link, bool force) {
-        return link_reconfigure_internal(link, force ? link_force_reconfigure_handler : link_reconfigure_handler);
-}
-
-int link_reconfigure_after_sleep(Link *link) {
-        return link_reconfigure_internal(link, link_reconfigure_after_sleep_handler);
-}
-
 static int link_initialized_and_synced(Link *link) {
         int r;
 
index cdfd29bc0ec3713fc8c386cfbe682263667299c8..684d635d363b4584a738a6b466e56b47d624ecc7 100644 (file)
 /* use 128 MB for receive socket kernel queue. */
 #define RCVBUF_SIZE    (128*1024*1024)
 
-static int manager_reset_all(Manager *m) {
-        Link *link;
-        int r;
-
-        assert(m);
-
-        HASHMAP_FOREACH(link, m->links_by_index) {
-                r = link_reconfigure_after_sleep(link);
-                if (r < 0) {
-                        log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
-                        link_enter_failed(link);
-                }
-        }
-
-        return 0;
-}
-
 static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
         Manager *m = ASSERT_PTR(userdata);
+        Link *link;
         int b, r;
 
         assert(message);
@@ -96,9 +80,15 @@ static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_b
         if (b)
                 return 0;
 
-        log_debug("Coming back from suspend, resetting all connections...");
+        log_debug("Coming back from suspend, reconfiguring all connections...");
 
-        (void) manager_reset_all(m);
+        HASHMAP_FOREACH(link, m->links_by_index) {
+                r = link_reconfigure(link, /* force = */ true);
+                if (r < 0) {
+                        log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
+                        link_enter_failed(link);
+                }
+        }
 
         return 0;
 }