1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

network: forcibly reconfigure all interfaces after sleep

Previously, interfaces are partially reconfigured in a spurious way.
Let's use the same way as `networkctl reconfigure`.

Hopefully fixes #14987 and #24997.
This commit is contained in:
Yu Watanabe 2022-11-01 13:36:52 +09:00 committed by Luca Boccassi
parent 3e2f7c46da
commit a39a9ac806
2 changed files with 11 additions and 65 deletions

View File

@ -1293,68 +1293,24 @@ 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 link_reconfigure(Link *link, bool force) {
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 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
* interface in these cases. */
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;

View File

@ -64,25 +64,9 @@
/* 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;
}