From 6e0c9b7dac87d7b5712ad7eb17a5dfe5353931d0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 5 Nov 2024 11:41:31 +0900 Subject: [PATCH] network: introduce LINK_RECONFIGURE_CLEANLY flag 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 | 2 +- src/network/networkd-link.c | 4 ++-- src/network/networkd-link.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/network/networkd-link-bus.c b/src/network/networkd-link-bus.c index 654aea36a27..27ee855181e 100644 --- a/src/network/networkd-link-bus.c +++ b/src/network/networkd-link-bus.c @@ -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. */ diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 8f925f895ee..080e6beff3b 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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 diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index 9ae7e1c8da4..ad8bac7ad61 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -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; -- 2.47.3