naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
2aacef
From ff7e9a0e3bf9229b2ea55ac0e832358fe13b97b4 Mon Sep 17 00:00:00 2001
2aacef
From: Yu Watanabe <watanabe.yu+github@gmail.com>
2aacef
Date: Tue, 22 Nov 2022 14:24:32 +0900
2aacef
Subject: [PATCH] network: wifi: try to reconfigure when connected
2aacef
2aacef
Sometimes, RTM_NEWLINK message with carrier is received earlier than
2aacef
NL80211_CMD_CONNECT. To make SSID= or other WiFi related settings in
2aacef
[Match] section work, let's try to reconfigure the interface.
2aacef
2aacef
Fixes a bug introduced by 96f5f9ef9a1ba5146d3357c1548fb675d3bd5b68.
2aacef
2aacef
Fixes #25384.
2aacef
2aacef
(cherry picked from commit 8a4ad01a72481a6a7c0309064dd2dbd814818c94)
2aacef
2aacef
Related: #2138081
2aacef
---
2aacef
 src/network/networkd-link.c |  2 +-
2aacef
 src/network/networkd-link.h |  1 +
2aacef
 src/network/networkd-wifi.c | 12 ++++++++++++
2aacef
 3 files changed, 14 insertions(+), 1 deletion(-)
2aacef
2aacef
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
2aacef
index 00e4e451ef..788c7957d3 100644
2aacef
--- a/src/network/networkd-link.c
2aacef
+++ b/src/network/networkd-link.c
2aacef
@@ -1178,7 +1178,7 @@ static int link_get_network(Link *link, Network **ret) {
2aacef
         return -ENOENT;
2aacef
 }
2aacef
 
2aacef
-static int link_reconfigure_impl(Link *link, bool force) {
2aacef
+int link_reconfigure_impl(Link *link, bool force) {
2aacef
         Network *network = NULL;
2aacef
         NetDev *netdev = NULL;
2aacef
         int r;
2aacef
diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h
2aacef
index 9f1cdca312..65b0164106 100644
2aacef
--- a/src/network/networkd-link.h
2aacef
+++ b/src/network/networkd-link.h
2aacef
@@ -234,6 +234,7 @@ int link_stop_engines(Link *link, bool may_keep_dhcp);
2aacef
 const char* link_state_to_string(LinkState s) _const_;
2aacef
 LinkState link_state_from_string(const char *s) _pure_;
2aacef
 
2aacef
+int link_reconfigure_impl(Link *link, bool force);
2aacef
 int link_reconfigure(Link *link, bool force);
2aacef
 int link_reconfigure_after_sleep(Link *link);
2aacef
 
2aacef
diff --git a/src/network/networkd-wifi.c b/src/network/networkd-wifi.c
2aacef
index 4bf798a9eb..62cbca0cf9 100644
2aacef
--- a/src/network/networkd-wifi.c
2aacef
+++ b/src/network/networkd-wifi.c
2aacef
@@ -269,6 +269,18 @@ int manager_genl_process_nl80211_mlme(sd_netlink *genl, sd_netlink_message *mess
2aacef
                 if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid)
2aacef
                         log_link_info(link, "Connected WiFi access point: %s (%s)",
2aacef
                                       link->ssid, ETHER_ADDR_TO_STR(&link->bssid));
2aacef
+
2aacef
+                /* Sometimes, RTM_NEWLINK message with carrier is received earlier than NL80211_CMD_CONNECT.
2aacef
+                 * To make SSID= or other WiFi related settings in [Match] section work, let's try to
2aacef
+                 * reconfigure the interface. */
2aacef
+                if (link->ssid && link_has_carrier(link)) {
2aacef
+                        r = link_reconfigure_impl(link, /* force = */ false);
2aacef
+                        if (r < 0) {
2aacef
+                                log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
2aacef
+                                link_enter_failed(link);
2aacef
+                                return 0;
2aacef
+                        }
2aacef
+                }
2aacef
                 break;
2aacef
         }
2aacef
         case NL80211_CMD_DISCONNECT: