From 776ec50c54099300aa0ddb5dd44a5830ebc42c4f Mon Sep 17 00:00:00 2001 From: Mykola Baibuz Date: Thu, 19 Sep 2024 22:17:14 +0300 Subject: [PATCH] Some updates for DNS name resolving --- client/protocols/openvpnprotocol.cpp | 2 ++ client/protocols/xrayprotocol.cpp | 8 ++++++-- ipc/ipcserver.cpp | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/client/protocols/openvpnprotocol.cpp b/client/protocols/openvpnprotocol.cpp index ba3bf64e..4c2feb52 100644 --- a/client/protocols/openvpnprotocol.cpp +++ b/client/protocols/openvpnprotocol.cpp @@ -352,6 +352,8 @@ void OpenVpnProtocol::updateVpnGateway(const QString &line) #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) // killSwitch toggle if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) { + m_configData.insert("vpnServer", + NetworkUtilities::getIPAddress(m_configData.value(amnezia::config_key::hostName).toString())); IpcClient::Interface()->enableKillSwitch(m_configData, 0); } #endif diff --git a/client/protocols/xrayprotocol.cpp b/client/protocols/xrayprotocol.cpp index 9795ac91..33599006 100755 --- a/client/protocols/xrayprotocol.cpp +++ b/client/protocols/xrayprotocol.cpp @@ -44,7 +44,9 @@ ErrorCode XrayProtocol::start() m_xrayCfgFile.setAutoRemove(false); #endif m_xrayCfgFile.open(); - m_xrayCfgFile.write(QJsonDocument(m_xrayConfig).toJson()); + QString config = QJsonDocument(m_xrayConfig).toJson(); + config.replace(m_remoteHost, m_remoteAddress); + m_xrayCfgFile.write(config.toUtf8()); m_xrayCfgFile.close(); QStringList args = QStringList() << "-c" << m_xrayCfgFile.fileName() << "-format=json"; @@ -124,6 +126,7 @@ ErrorCode XrayProtocol::startTun2Sock() #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) // killSwitch toggle if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) { + m_configData.insert("vpnServer", m_remoteAddress); IpcClient::Interface()->enableKillSwitch(m_configData, 0); } #endif @@ -202,7 +205,8 @@ void XrayProtocol::readXrayConfiguration(const QJsonObject &configuration) } m_xrayConfig = xrayConfiguration; m_localPort = QString(amnezia::protocols::xray::defaultLocalProxyPort).toInt(); - m_remoteAddress = NetworkUtilities::getIPAddress(configuration.value(amnezia::config_key::hostName).toString()); + m_remoteHost = configuration.value(amnezia::config_key::hostName).toString(); + m_remoteAddress = NetworkUtilities::getIPAddress(m_remoteHost); m_routeMode = configuration.value(amnezia::config_key::splitTunnelType).toInt(); m_primaryDNS = configuration.value(amnezia::config_key::dns1).toString(); m_secondaryDNS = configuration.value(amnezia::config_key::dns2).toString(); diff --git a/ipc/ipcserver.cpp b/ipc/ipcserver.cpp index af074ed5..bb8a4182 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -210,7 +210,7 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd if (splitTunnelType == 0) { blockAll = true; allowNets = true; - allownets.append(NetworkUtilities::getIPAddress(configStr.value(amnezia::config_key::hostName).toString())); + allownets.append(configStr.value("vpnServer").toString()); } else if (splitTunnelType == 1) { blockNets = true; for (auto v : splitTunnelSites) { @@ -219,7 +219,7 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd } else if (splitTunnelType == 2) { blockAll = true; allowNets = true; - allownets.append(NetworkUtilities::getIPAddress(configStr.value(amnezia::config_key::hostName).toString())); + allownets.append(configStr.value("vpnServer").toString()); for (auto v : splitTunnelSites) { allownets.append(v.toString()); } @@ -330,7 +330,7 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr) } } - config.m_excludedAddresses.append(NetworkUtilities::getIPAddress(configStr.value(amnezia::config_key::hostName).toString())); + config.m_excludedAddresses.append(configStr.value("vpnServer").toString()); if (splitTunnelType == 2) { for (auto v : splitTunnelSites) { QString ipRange = v.toString();