network: introduce LINK_RECONFIGURE_CLEANLY flag
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Nov 2024 02:41:31 +0000 (11:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Nov 2024 17:05:00 +0000 (02:05 +0900)
And use it when explicit reconfiguration is requested by Reconfigure() DBus method
or networkd certainly detects that connected network is changed.
Otherwise do not use the flag especially when we come back from sleep mode.

src/network/networkd-link-bus.c
src/network/networkd-link.c
src/network/networkd-link.h

index 654aea36a2796bd0c9192e1ed664b1f5c066fd9c..27ee855181e9d86c369c9ed60da002167ae0cbb0 100644 (file)
@@ -665,7 +665,7 @@ int bus_link_method_reconfigure(sd_bus_message *message, void *userdata, sd_bus_
         if (r == 0)
                 return 1; /* Polkit will call us back */
 
-        r = link_reconfigure_full(l, LINK_RECONFIGURE_UNCONDITIONALLY, message, /* counter = */ NULL);
+        r = link_reconfigure_full(l, LINK_RECONFIGURE_UNCONDITIONALLY | LINK_RECONFIGURE_CLEANLY, message, /* counter = */ NULL);
         if (r != 0)
                 return r; /* Will reply later when r > 0. */
 
index 8f925f895eea4b4101192f36370bf5aaf43eec5b..080e6beff3b04920b533547f33544e6d0539d067 100644 (file)
@@ -1387,7 +1387,7 @@ int link_reconfigure_impl(Link *link, LinkReconfigurationFlag flags) {
 
         /* Dropping old .network file */
 
-        if (FLAGS_SET(flags, LINK_RECONFIGURE_UNCONDITIONALLY)) {
+        if (FLAGS_SET(flags, LINK_RECONFIGURE_CLEANLY)) {
                 /* Remove all static configurations. Note, dynamic configurations are dropped by
                  * link_stop_engines(), and foreign configurations will be removed later by
                  * link_configure() -> link_drop_unmanaged_config(). */
@@ -1741,7 +1741,7 @@ static int link_carrier_gained(Link *link) {
          * For non-wireless interfaces, we have no way to detect the connected network change. So,
          * we do not set any flags here. Note, both ssid and previous_ssid are NULL in that case. */
         if (link->previous_ssid && !streq_ptr(link->previous_ssid, link->ssid))
-                flags |= LINK_RECONFIGURE_UNCONDITIONALLY;
+                flags |= LINK_RECONFIGURE_UNCONDITIONALLY | LINK_RECONFIGURE_CLEANLY;
         link->previous_ssid = mfree(link->previous_ssid);
 
         /* AP and P2P-GO interfaces may have a new SSID - update the link properties in case a new .network
index 9ae7e1c8da4f7750c8cc27aa485fef99ae908206..ad8bac7ad6100e8dbea2b4eab0b248b731d30b83 100644 (file)
@@ -44,6 +44,7 @@ typedef enum LinkState {
 
 typedef enum LinkReconfigurationFlag {
         LINK_RECONFIGURE_UNCONDITIONALLY = 1 << 0, /* Reconfigure an interface even if .network file is unchanged. */
+        LINK_RECONFIGURE_CLEANLY         = 1 << 1, /* Drop all existing configs before reconfiguring. Otherwise, reuse existing configs as possible as we can. */
 } LinkReconfigurationFlag;
 
 typedef struct Manager Manager;