From ebe3a5dac6ae7101cb7e9520903ce92a0d1ed32e Mon Sep 17 00:00:00 2001 From: NickVs2015 Date: Tue, 14 Apr 2026 06:10:41 +0300 Subject: [PATCH] fix: add linux reconnection (#2415) * fix: add linux reconnection * fix: Dbus error, fix race conditional * fix: improve reeconnection * fix: add dns load/unload * feat: catch state changed via check gateway * revert: restore linuxfirewall.cpp * fix: restore reconnect time * fix: add NM_STATE_DISABLED and check getGatewayAndIface more carefully * fix: reconnect * fix: revert wireguardutilslinux * fix: revert --- .../platforms/linux/daemon/linuxroutemonitor.cpp | 7 ++++++- client/platforms/linux/linuxnetworkwatcher.cpp | 3 +++ .../platforms/linux/linuxnetworkwatcherworker.cpp | 14 ++++++++------ client/platforms/linux/linuxnetworkwatcherworker.h | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/client/platforms/linux/daemon/linuxroutemonitor.cpp b/client/platforms/linux/daemon/linuxroutemonitor.cpp index 39926f232..eaf5bcd85 100644 --- a/client/platforms/linux/daemon/linuxroutemonitor.cpp +++ b/client/platforms/linux/daemon/linuxroutemonitor.cpp @@ -164,8 +164,13 @@ bool LinuxRouteMonitor::rtmSendRoute(int action, int flags, int type, } if (rtm->rtm_type == RTN_THROW) { + QString gateway = NetworkUtilities::getGatewayAndIface().first; + if (gateway.isEmpty()) { + logger.warning() << "No default gateway available, skipping exclusion route"; + return false; + } struct in_addr ip4; - inet_pton(AF_INET, NetworkUtilities::getGatewayAndIface().first.toUtf8(), &ip4); + inet_pton(AF_INET, gateway.toUtf8(), &ip4); nlmsg_append_attr(nlmsg, sizeof(buf), RTA_GATEWAY, &ip4, sizeof(ip4)); nlmsg_append_attr32(nlmsg, sizeof(buf), RTA_PRIORITY, 0); rtm->rtm_type = RTN_UNICAST; diff --git a/client/platforms/linux/linuxnetworkwatcher.cpp b/client/platforms/linux/linuxnetworkwatcher.cpp index 11b31fa5b..b27eae83f 100644 --- a/client/platforms/linux/linuxnetworkwatcher.cpp +++ b/client/platforms/linux/linuxnetworkwatcher.cpp @@ -44,6 +44,9 @@ void LinuxNetworkWatcher::initialize() { connect(m_worker, &LinuxNetworkWatcherWorker::wakeup, this, &NetworkWatcherImpl::wakeup); + connect(m_worker, &LinuxNetworkWatcherWorker::networkChanged, this, + [this]() { emit networkChanged(""); }); + // Let's wait a few seconds to allow the UI to be fully loaded and shown. // This is not strictly needed, but it's better for user experience because // it makes the UI faster to appear, plus it gives a bit of delay between the diff --git a/client/platforms/linux/linuxnetworkwatcherworker.cpp b/client/platforms/linux/linuxnetworkwatcherworker.cpp index f7cce6bb6..ca3f7c1b2 100644 --- a/client/platforms/linux/linuxnetworkwatcherworker.cpp +++ b/client/platforms/linux/linuxnetworkwatcherworker.cpp @@ -37,6 +37,7 @@ enum NMState { NM_STATE_UNKNOWN = 0, NM_STATE_ASLEEP = 10, + NM_STATE_DISABLED = 10, NM_STATE_DISCONNECTED = 20, NM_STATE_DISCONNECTING = 30, NM_STATE_CONNECTING = 40, @@ -199,10 +200,11 @@ void LinuxNetworkWatcherWorker::checkDevices() { void LinuxNetworkWatcherWorker::NMStateChanged(quint32 state) { - if (state == NM_STATE_ASLEEP) { - emit wakeup(); - } - - logger.debug() << "NMStateChanged " << state; -} + logger.debug() << "NMStateChanged " << state; + if (state == NM_STATE_ASLEEP || state == NM_STATE_DISABLED) { + emit wakeup(); + } else if (state == NM_STATE_CONNECTED_GLOBAL) { + emit networkChanged(); + } +} \ No newline at end of file diff --git a/client/platforms/linux/linuxnetworkwatcherworker.h b/client/platforms/linux/linuxnetworkwatcherworker.h index 7c5ae5407..8dead74d8 100644 --- a/client/platforms/linux/linuxnetworkwatcherworker.h +++ b/client/platforms/linux/linuxnetworkwatcherworker.h @@ -24,6 +24,7 @@ class LinuxNetworkWatcherWorker final : public QObject { signals: void unsecuredNetwork(const QString& networkName, const QString& networkId); void wakeup(); + void networkChanged(); public slots: void initialize();