mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
fix: app freeze on quit (#1804)
* fix: app freeze on quit
* fix: typo in VpnConnection destructor
* add trace info
* add more trace info
* set timelimit for flushDns
* Refactor IpcClient::Interface access logic
* cleanup unused variable
* cleanup trace info
* fix: remove second disconnect from VPN on app close
* this object will be deleted at app close
* Don't terminate VPN thread on Linux
* Revert "Don't terminate VPN thread on Linux"
This reverts commit 20e4ea2d4a.
* disconnect all signals from vpnconnection on exit
* add interruption request on vpnConnectionThread
* use checktimer only for iOS
* disconnect all signals from vpnconnection on exit
* disconnect signals on exit before VPN disconnect
* add disconnectSlots method
* fix: add allow traffic rules on killswitch disable
* wait for response from service before object destroy
* change disconnect from vpn order
* add delay for connection close
* change disconnect method order
* use stop method for protocol disconnecect
* change disconnect method order
* allow dns traffic after app close
* delete tun on disconnect
---------
Co-authored-by: vkamn <vk@amnezia.org>
This commit is contained in:
@@ -98,6 +98,17 @@ bool KillSwitch::disableKillSwitch() {
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("320.allowDNS"), false);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("400.allowPIA"), false);
|
||||
} else {
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("000.allowLoopback"), true);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("100.blockAll"), false);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("110.allowNets"), false);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("120.blockNets"), false);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("200.allowVPN"), false);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv6, QStringLiteral("250.blockIPv6"), false);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("290.allowDHCP"), true);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("300.allowLAN"), true);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("310.blockDNS"), false);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("320.allowDNS"), true);
|
||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("400.allowPIA"), false);
|
||||
LinuxFirewall::uninstall();
|
||||
}
|
||||
#endif
|
||||
|
||||
+12
-12
@@ -42,14 +42,14 @@ int Router::routeDeleteList(const QString &gw, const QStringList &ips)
|
||||
#endif
|
||||
}
|
||||
|
||||
void Router::flushDns()
|
||||
bool Router::flushDns()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
RouterWin::Instance().flushDns();
|
||||
return RouterWin::Instance().flushDns();
|
||||
#elif defined (Q_OS_MAC)
|
||||
RouterMac::Instance().flushDns();
|
||||
return RouterMac::Instance().flushDns();
|
||||
#elif defined Q_OS_LINUX
|
||||
RouterLinux::Instance().flushDns();
|
||||
return RouterLinux::Instance().flushDns();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -111,25 +111,25 @@ bool Router::restoreResolvers() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Router::StopRoutingIpv6()
|
||||
bool Router::StopRoutingIpv6()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
RouterWin::Instance().StopRoutingIpv6();
|
||||
return RouterWin::Instance().StopRoutingIpv6();
|
||||
#elif defined (Q_OS_MAC)
|
||||
// todo fixme
|
||||
return true;// todo fixme
|
||||
#elif defined Q_OS_LINUX
|
||||
RouterLinux::Instance().StopRoutingIpv6();
|
||||
return RouterLinux::Instance().StopRoutingIpv6();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Router::StartRoutingIpv6()
|
||||
bool Router::StartRoutingIpv6()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
RouterWin::Instance().StartRoutingIpv6();
|
||||
return RouterWin::Instance().StartRoutingIpv6();
|
||||
#elif defined (Q_OS_MAC)
|
||||
// todo fixme
|
||||
return true;// todo fixme
|
||||
#elif defined Q_OS_LINUX
|
||||
RouterLinux::Instance().StartRoutingIpv6();
|
||||
return RouterLinux::Instance().StartRoutingIpv6();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ public:
|
||||
static int routeAddList(const QString &gw, const QStringList &ips);
|
||||
static bool clearSavedRoutes();
|
||||
static int routeDeleteList(const QString &gw, const QStringList &ips);
|
||||
static void flushDns();
|
||||
static bool flushDns();
|
||||
static void resetIpStack();
|
||||
static bool createTun(const QString &dev, const QString &subnet);
|
||||
static bool deleteTun(const QString &dev);
|
||||
static void StartRoutingIpv6();
|
||||
static void StopRoutingIpv6();
|
||||
static bool StartRoutingIpv6();
|
||||
static bool StopRoutingIpv6();
|
||||
static bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers);
|
||||
static bool restoreResolvers();
|
||||
};
|
||||
|
||||
@@ -160,7 +160,7 @@ bool RouterLinux::isServiceActive(const QString &serviceName) {
|
||||
return process.exitCode() == 0;
|
||||
}
|
||||
|
||||
void RouterLinux::flushDns()
|
||||
bool RouterLinux::flushDns()
|
||||
{
|
||||
QProcess p;
|
||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
@@ -174,7 +174,7 @@ void RouterLinux::flushDns()
|
||||
p.start("systemctl", { "restart", "systemd-resolved" });
|
||||
} else {
|
||||
qDebug() << "No suitable DNS manager found.";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
p.waitForFinished();
|
||||
@@ -183,6 +183,8 @@ void RouterLinux::flushDns()
|
||||
qDebug().noquote() << "Flush dns completed";
|
||||
else
|
||||
qDebug().noquote() << "OUTPUT systemctl restart nscd/systemd-resolved: " + output;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RouterLinux::createTun(const QString &dev, const QString &subnet) {
|
||||
@@ -283,7 +285,7 @@ bool RouterLinux::restoreResolvers() {
|
||||
return m_dnsUtil->restoreResolvers();
|
||||
}
|
||||
|
||||
void RouterLinux::StartRoutingIpv6()
|
||||
bool RouterLinux::StartRoutingIpv6()
|
||||
{
|
||||
QProcess process;
|
||||
QStringList commands;
|
||||
@@ -293,12 +295,12 @@ void RouterLinux::StartRoutingIpv6()
|
||||
if (!process.waitForStarted(1000))
|
||||
{
|
||||
qDebug().noquote() << "Could not start activate ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
else if (!process.waitForFinished(2000))
|
||||
{
|
||||
qDebug().noquote() << "Could not activate ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
commands.clear();
|
||||
|
||||
@@ -307,19 +309,20 @@ void RouterLinux::StartRoutingIpv6()
|
||||
if (!process.waitForStarted(1000))
|
||||
{
|
||||
qDebug().noquote() << "Could not start activate ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
else if (!process.waitForFinished(2000))
|
||||
{
|
||||
qDebug().noquote() << "Could not activate ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
commands.clear();
|
||||
|
||||
qDebug().noquote() << "StartRoutingIpv6 OK";
|
||||
return true;
|
||||
}
|
||||
|
||||
void RouterLinux::StopRoutingIpv6()
|
||||
bool RouterLinux::StopRoutingIpv6()
|
||||
{
|
||||
QProcess process;
|
||||
QStringList commands;
|
||||
@@ -329,12 +332,12 @@ void RouterLinux::StopRoutingIpv6()
|
||||
if (!process.waitForStarted(1000))
|
||||
{
|
||||
qDebug().noquote() << "Could not start disable ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
else if (!process.waitForFinished(2000))
|
||||
{
|
||||
qDebug().noquote() << "Could not disable ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
commands.clear();
|
||||
|
||||
@@ -343,14 +346,15 @@ void RouterLinux::StopRoutingIpv6()
|
||||
if (!process.waitForStarted(1000))
|
||||
{
|
||||
qDebug().noquote() << "Could not start disable ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
else if (!process.waitForFinished(2000))
|
||||
{
|
||||
qDebug().noquote() << "Could not disable ipv6\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
commands.clear();
|
||||
|
||||
qDebug().noquote() << "StopRoutingIpv6 OK";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ public:
|
||||
bool routeDelete(const QString &ip, const QString &gw, const int &sock);
|
||||
bool routeDeleteList(const QString &gw, const QStringList &ips);
|
||||
QString getgatewayandiface();
|
||||
void flushDns();
|
||||
bool flushDns();
|
||||
bool createTun(const QString &dev, const QString &subnet);
|
||||
bool deleteTun(const QString &dev);
|
||||
void StartRoutingIpv6();
|
||||
void StopRoutingIpv6();
|
||||
bool StartRoutingIpv6();
|
||||
bool StopRoutingIpv6();
|
||||
bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers);
|
||||
bool restoreResolvers();
|
||||
public slots:
|
||||
|
||||
@@ -169,7 +169,7 @@ bool RouterMac::deleteTun(const QString &dev)
|
||||
return true;
|
||||
}
|
||||
|
||||
void RouterMac::flushDns()
|
||||
bool RouterMac::flushDns()
|
||||
{
|
||||
// sudo killall -HUP mDNSResponder
|
||||
QProcess p;
|
||||
@@ -177,5 +177,7 @@ void RouterMac::flushDns()
|
||||
|
||||
p.start("killall", QStringList() << "-HUP" << "mDNSResponder");
|
||||
p.waitForFinished();
|
||||
|
||||
qDebug().noquote() << "OUTPUT killall -HUP mDNSResponder: " + p.readAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
bool clearSavedRoutes();
|
||||
bool routeDelete(const QString &ip, const QString &gw);
|
||||
bool routeDeleteList(const QString &gw, const QStringList &ips);
|
||||
void flushDns();
|
||||
bool flushDns();
|
||||
bool createTun(const QString &dev, const QString &subnet);
|
||||
bool deleteTun(const QString &dev);
|
||||
bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers);
|
||||
|
||||
@@ -273,7 +273,7 @@ int RouterWin::routeDeleteList(const QString &gw, const QStringList &ips)
|
||||
return success_count;
|
||||
}
|
||||
|
||||
void RouterWin::flushDns()
|
||||
bool RouterWin::flushDns()
|
||||
{
|
||||
QProcess p;
|
||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
@@ -281,6 +281,7 @@ void RouterWin::flushDns()
|
||||
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
return true;
|
||||
//qDebug().noquote() << "OUTPUT ipconfig /flushdns: " + p.readAll();
|
||||
}
|
||||
|
||||
@@ -447,7 +448,7 @@ bool RouterWin::restoreResolvers() {
|
||||
return m_dnsUtil->restoreResolvers();
|
||||
}
|
||||
|
||||
void RouterWin::StopRoutingIpv6()
|
||||
bool RouterWin::StopRoutingIpv6()
|
||||
{
|
||||
{
|
||||
QProcess p;
|
||||
@@ -467,9 +468,10 @@ void RouterWin::StopRoutingIpv6()
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RouterWin::StartRoutingIpv6()
|
||||
bool RouterWin::StartRoutingIpv6()
|
||||
{
|
||||
{
|
||||
QProcess p;
|
||||
@@ -489,5 +491,6 @@ void RouterWin::StartRoutingIpv6()
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ public:
|
||||
int routeAddList(const QString &gw, const QStringList &ips);
|
||||
bool clearSavedRoutes();
|
||||
int routeDeleteList(const QString &gw, const QStringList &ips);
|
||||
void flushDns();
|
||||
bool flushDns();
|
||||
void resetIpStack();
|
||||
|
||||
void StartRoutingIpv6();
|
||||
void StopRoutingIpv6();
|
||||
bool StartRoutingIpv6();
|
||||
bool StopRoutingIpv6();
|
||||
|
||||
void suspendWcmSvc(bool suspend);
|
||||
bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers);
|
||||
|
||||
Reference in New Issue
Block a user