mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
fix: keep DNS and routing during seamless Xray switch on Linux
This commit is contained in:
@@ -20,6 +20,16 @@ int Router::routeAddList(const QString &gw, const QStringList &ips)
|
||||
#endif
|
||||
}
|
||||
|
||||
int Router::routeAddListVia(const QString &ifname, const QString &gw, const QStringList &ips)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
return RouterLinux::Instance().routeAddListVia(ifname, gw, ips);
|
||||
#else
|
||||
Q_UNUSED(ifname)
|
||||
return routeAddList(gw, ips);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Router::clearSavedRoutes()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
@@ -17,6 +17,7 @@ class Router : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
static int routeAddList(const QString &gw, const QStringList &ips);
|
||||
static int routeAddListVia(const QString &ifname, const QString &gw, const QStringList &ips);
|
||||
static bool clearSavedRoutes();
|
||||
static int routeDeleteList(const QString &gw, const QStringList &ips);
|
||||
static bool flushDns();
|
||||
|
||||
@@ -87,6 +87,34 @@ int RouterLinux::routeAddList(const QString &gw, const QStringList &ips)
|
||||
return cnt;
|
||||
}
|
||||
|
||||
int RouterLinux::routeAddListVia(const QString &ifname, const QString &gw, const QStringList &ips)
|
||||
{
|
||||
if (ifname.isEmpty()) {
|
||||
qWarning() << "routeAddListVia: empty ifname";
|
||||
return 0;
|
||||
}
|
||||
int cnt = 0;
|
||||
for (const QString &ip : ips) {
|
||||
QStringList args;
|
||||
args << "route" << "replace" << ip;
|
||||
if (!gw.isEmpty()) {
|
||||
args << "via" << gw;
|
||||
}
|
||||
args << "dev" << ifname << "scope" << "link";
|
||||
|
||||
QProcess p;
|
||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
p.start("ip", args);
|
||||
if (p.waitForFinished(2000) && p.exitCode() == 0) {
|
||||
cnt++;
|
||||
} else {
|
||||
qWarning().noquote() << "routeAddListVia failed:" << ip << "via" << gw << "dev" << ifname
|
||||
<< "rc=" << p.exitCode() << "out=" << p.readAll();
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
bool RouterLinux::clearSavedRoutes()
|
||||
{
|
||||
int temp_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
|
||||
bool routeAdd(const QString &ip, const QString &gw, const int &sock);
|
||||
int routeAddList(const QString &gw, const QStringList &ips);
|
||||
int routeAddListVia(const QString &ifname, const QString &gw, const QStringList &ips);
|
||||
bool clearSavedRoutes();
|
||||
bool routeDelete(const QString &ip, const QString &gw, const int &sock);
|
||||
bool routeDeleteList(const QString &gw, const QStringList &ips);
|
||||
|
||||
Reference in New Issue
Block a user