mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +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.
(cherry picked from commit a39a9ac806
)
This commit is contained in:
parent
66fa6110ba
commit
7eefd2fbb7
@ -1316,68 +1316,24 @@ static int link_force_reconfigure_handler(sd_netlink *rtnl, sd_netlink_message *
|
|||||||
return link_reconfigure_handler_internal(rtnl, m, link, /* force = */ true);
|
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;
|
int r;
|
||||||
|
|
||||||
assert(link);
|
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
|
/* 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
|
* the function from being called multiple times simultaneously, refuse to reconfigure the
|
||||||
* interface in these cases. */
|
* interface in these cases. */
|
||||||
if (IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_INITIALIZED, LINK_STATE_LINGER))
|
if (IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_INITIALIZED, LINK_STATE_LINGER))
|
||||||
return 0; /* 0 means no-op. */
|
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)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return 1; /* 1 means the interface will be reconfigured. */
|
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) {
|
static int link_initialized_and_synced(Link *link) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -60,25 +60,9 @@
|
|||||||
/* use 128 MB for receive socket kernel queue. */
|
/* use 128 MB for receive socket kernel queue. */
|
||||||
#define RCVBUF_SIZE (128*1024*1024)
|
#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) {
|
static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
|
||||||
Manager *m = userdata;
|
Manager *m = userdata;
|
||||||
|
Link *link;
|
||||||
int b, r;
|
int b, r;
|
||||||
|
|
||||||
assert(message);
|
assert(message);
|
||||||
@ -93,9 +77,15 @@ static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_b
|
|||||||
if (b)
|
if (b)
|
||||||
return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user