From 343e6a50dfabe2a622ada5f1cfebd457b1e303d7 Mon Sep 17 00:00:00 2001 From: pokamest Date: Wed, 15 Dec 2021 14:53:07 +0300 Subject: [PATCH] resetIpStack added --- client/vpnconnection.cpp | 1 + ipc/ipc_interface.rep | 1 + ipc/ipcserver.cpp | 5 +++++ ipc/ipcserver.h | 1 + service/server/router.cpp | 11 +++++++++++ service/server/router.h | 1 + service/server/router_win.cpp | 21 +++++++++++++++++++++ service/server/router_win.h | 1 + 8 files changed, 42 insertions(+) diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 5837ce58b..85c9d5929 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -47,6 +47,7 @@ void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState sta { if (IpcClient::Interface()) { if (state == VpnProtocol::Connected){ + IpcClient::Interface()->resetIpStack(); IpcClient::Interface()->flushDns(); if (m_settings.routeMode() != Settings::VpnAllSites) { diff --git a/ipc/ipc_interface.rep b/ipc/ipc_interface.rep index b0e89fa3d..9cb991107 100644 --- a/ipc/ipc_interface.rep +++ b/ipc/ipc_interface.rep @@ -11,6 +11,7 @@ class IpcInterface SLOT( bool clearSavedRoutes() ); SLOT( bool routeDeleteList(const QString &gw, const QStringList &ip) ); SLOT( void flushDns() ); + SLOT( void resetIpStack() ); SLOT( bool checkAndInstallDriver() ); SLOT( QStringList getTapList() ); diff --git a/ipc/ipcserver.cpp b/ipc/ipcserver.cpp index 7db1ded90..c32e043a7 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -83,6 +83,11 @@ void IpcServer::flushDns() return Router::flushDns(); } +void IpcServer::resetIpStack() +{ + Router::resetIpStack(); +} + bool IpcServer::checkAndInstallDriver() { #ifdef Q_OS_WIN diff --git a/ipc/ipcserver.h b/ipc/ipcserver.h index 284cda21a..f01822816 100644 --- a/ipc/ipcserver.h +++ b/ipc/ipcserver.h @@ -20,6 +20,7 @@ class IpcServer : public IpcInterfaceSource virtual bool clearSavedRoutes() override; virtual bool routeDeleteList(const QString &gw, const QStringList &ips) override; virtual void flushDns() override; + virtual void resetIpStack() override; virtual bool checkAndInstallDriver() override; virtual QStringList getTapList() override; diff --git a/service/server/router.cpp b/service/server/router.cpp index 3890fcb3f..6b97e7957 100644 --- a/service/server/router.cpp +++ b/service/server/router.cpp @@ -53,3 +53,14 @@ void Router::flushDns() #endif } +void Router::resetIpStack() +{ +#ifdef Q_OS_WIN + RouterWin::Instance().resetIpStack(); +#elif defined (Q_OS_MAC) + // todo fixme +#elif defined Q_OS_LINUX + // todo fixme +#endif +} + diff --git a/service/server/router.h b/service/server/router.h index 59a25edef..c290f6640 100644 --- a/service/server/router.h +++ b/service/server/router.h @@ -19,6 +19,7 @@ class Router : public QObject static bool clearSavedRoutes(); static int routeDeleteList(const QString &gw, const QStringList &ips); static void flushDns(); + static void resetIpStack(); }; #endif // ROUTER_H diff --git a/service/server/router_win.cpp b/service/server/router_win.cpp index d242821ee..df4318054 100644 --- a/service/server/router_win.cpp +++ b/service/server/router_win.cpp @@ -289,6 +289,27 @@ void RouterWin::flushDns() //qDebug().noquote() << "OUTPUT ipconfig /flushdns: " + p.readAll(); } +void RouterWin::resetIpStack() +{ +// { +// QProcess p; +// QString command = QString("ipconfig /release"); +// p.start(command); +// } + { + QProcess p; + QString command = QString("netsh int ip reset"); + p.start(command); + p.waitForFinished(); + } + { + QProcess p; + QString command = QString("netsh winsock reset"); + p.start(command); + p.waitForFinished(); + } +} + void RouterWin::suspendWcmSvc(bool suspend) { if (suspend == m_suspended) return; diff --git a/service/server/router_win.h b/service/server/router_win.h index 4858a766d..bf23d2089 100644 --- a/service/server/router_win.h +++ b/service/server/router_win.h @@ -39,6 +39,7 @@ class RouterWin : public QObject bool clearSavedRoutes(); int routeDeleteList(const QString &gw, const QStringList &ips); void flushDns(); + void resetIpStack(); void suspendWcmSvc(bool suspend);