fix: allow secondary DNS usage when AmneziaDNS is disabled (#1583)
* Allow secondary DNS usage when AmneziaDNS is disabled * Don't setup secondary DNS for OpenVPN with AmneziaDNS --------- Co-authored-by: vladimir.kuznetsov <nethiuswork@gmail.com>
This commit is contained in:
parent
127f8ed3bb
commit
b341934863
10 changed files with 116 additions and 32 deletions
|
@ -118,6 +118,12 @@ QString OpenVpnConfigurator::processConfigWithLocalSettings(const QPair<QString,
|
||||||
QRegularExpression regex("redirect-gateway.*");
|
QRegularExpression regex("redirect-gateway.*");
|
||||||
config.replace(regex, "");
|
config.replace(regex, "");
|
||||||
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (dns.first.contains(protocols::dns::amneziaDnsIp)) {
|
||||||
|
QRegularExpression dnsRegex("dhcp-option DNS " + dns.second);
|
||||||
|
config.replace(dnsRegex, "");
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_settings->isSitesSplitTunnelingEnabled()) {
|
if (!m_settings->isSitesSplitTunnelingEnabled()) {
|
||||||
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
||||||
config.append("block-ipv6\n");
|
config.append("block-ipv6\n");
|
||||||
|
@ -161,6 +167,12 @@ QString OpenVpnConfigurator::processConfigWithExportSettings(const QPair<QString
|
||||||
QRegularExpression regex("redirect-gateway.*");
|
QRegularExpression regex("redirect-gateway.*");
|
||||||
config.replace(regex, "");
|
config.replace(regex, "");
|
||||||
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (dns.first.contains(protocols::dns::amneziaDnsIp)) {
|
||||||
|
QRegularExpression dnsRegex("dhcp-option DNS " + dns.second);
|
||||||
|
config.replace(dnsRegex, "");
|
||||||
|
}
|
||||||
|
|
||||||
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
||||||
|
|
||||||
// Prevent ipv6 leak
|
// Prevent ipv6 leak
|
||||||
|
|
|
@ -169,11 +169,14 @@ bool Daemon::maybeUpdateResolvers(const InterfaceConfig& config) {
|
||||||
if ((config.m_hopType == InterfaceConfig::MultiHopExit) ||
|
if ((config.m_hopType == InterfaceConfig::MultiHopExit) ||
|
||||||
(config.m_hopType == InterfaceConfig::SingleHop)) {
|
(config.m_hopType == InterfaceConfig::SingleHop)) {
|
||||||
QList<QHostAddress> resolvers;
|
QList<QHostAddress> resolvers;
|
||||||
resolvers.append(QHostAddress(config.m_dnsServer));
|
resolvers.append(QHostAddress(config.m_primaryDnsServer));
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
resolvers.append(QHostAddress(config.m_secondaryDnsServer));
|
||||||
|
}
|
||||||
|
|
||||||
// If the DNS is not the Gateway, it's a user defined DNS
|
// If the DNS is not the Gateway, it's a user defined DNS
|
||||||
// thus, not add any other :)
|
// thus, not add any other :)
|
||||||
if (config.m_dnsServer == config.m_serverIpv4Gateway) {
|
if (config.m_primaryDnsServer == config.m_serverIpv4Gateway) {
|
||||||
resolvers.append(QHostAddress(config.m_serverIpv6Gateway));
|
resolvers.append(QHostAddress(config.m_serverIpv6Gateway));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,15 +282,26 @@ bool Daemon::parseConfig(const QJsonObject& obj, InterfaceConfig& config) {
|
||||||
config.m_serverIpv4Gateway = obj.value("serverIpv4Gateway").toString();
|
config.m_serverIpv4Gateway = obj.value("serverIpv4Gateway").toString();
|
||||||
config.m_serverIpv6Gateway = obj.value("serverIpv6Gateway").toString();
|
config.m_serverIpv6Gateway = obj.value("serverIpv6Gateway").toString();
|
||||||
|
|
||||||
if (!obj.contains("dnsServer")) {
|
if (!obj.contains("primaryDnsServer")) {
|
||||||
config.m_dnsServer = QString();
|
config.m_primaryDnsServer = QString();
|
||||||
} else {
|
} else {
|
||||||
QJsonValue value = obj.value("dnsServer");
|
QJsonValue value = obj.value("primaryDnsServer");
|
||||||
if (!value.isString()) {
|
if (!value.isString()) {
|
||||||
logger.error() << "dnsServer is not a string";
|
logger.error() << "dnsServer is not a string";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
config.m_dnsServer = value.toString();
|
config.m_primaryDnsServer = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!obj.contains("secondaryDnsServer")) {
|
||||||
|
config.m_secondaryDnsServer = QString();
|
||||||
|
} else {
|
||||||
|
QJsonValue value = obj.value("secondaryDnsServer");
|
||||||
|
if (!value.isString()) {
|
||||||
|
logger.error() << "dnsServer is not a string";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
config.m_secondaryDnsServer = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!obj.contains("hopType")) {
|
if (!obj.contains("hopType")) {
|
||||||
|
|
|
@ -28,7 +28,8 @@ QJsonObject InterfaceConfig::toJson() const {
|
||||||
(m_hopType == InterfaceConfig::SingleHop)) {
|
(m_hopType == InterfaceConfig::SingleHop)) {
|
||||||
json.insert("serverIpv4Gateway", QJsonValue(m_serverIpv4Gateway));
|
json.insert("serverIpv4Gateway", QJsonValue(m_serverIpv4Gateway));
|
||||||
json.insert("serverIpv6Gateway", QJsonValue(m_serverIpv6Gateway));
|
json.insert("serverIpv6Gateway", QJsonValue(m_serverIpv6Gateway));
|
||||||
json.insert("dnsServer", QJsonValue(m_dnsServer));
|
json.insert("primaryDnsServer", QJsonValue(m_primaryDnsServer));
|
||||||
|
json.insert("secondaryDnsServer", QJsonValue(m_secondaryDnsServer));
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray allowedIPAddesses;
|
QJsonArray allowedIPAddesses;
|
||||||
|
@ -100,11 +101,15 @@ QString InterfaceConfig::toWgConf(const QMap<QString, QString>& extra) const {
|
||||||
out << "MTU = " << m_deviceMTU << "\n";
|
out << "MTU = " << m_deviceMTU << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_dnsServer.isNull()) {
|
if (!m_primaryDnsServer.isNull()) {
|
||||||
QStringList dnsServers(m_dnsServer);
|
QStringList dnsServers;
|
||||||
|
dnsServers.append(m_primaryDnsServer);
|
||||||
|
if (!m_secondaryDnsServer.isNull()) {
|
||||||
|
dnsServers.append(m_secondaryDnsServer);
|
||||||
|
}
|
||||||
// If the DNS is not the Gateway, it's a user defined DNS
|
// If the DNS is not the Gateway, it's a user defined DNS
|
||||||
// thus, not add any other :)
|
// thus, not add any other :)
|
||||||
if (m_dnsServer == m_serverIpv4Gateway) {
|
if (m_primaryDnsServer == m_serverIpv4Gateway) {
|
||||||
dnsServers.append(m_serverIpv6Gateway);
|
dnsServers.append(m_serverIpv6Gateway);
|
||||||
}
|
}
|
||||||
out << "DNS = " << dnsServers.join(", ") << "\n";
|
out << "DNS = " << dnsServers.join(", ") << "\n";
|
||||||
|
|
|
@ -32,7 +32,8 @@ class InterfaceConfig {
|
||||||
QString m_serverIpv4AddrIn;
|
QString m_serverIpv4AddrIn;
|
||||||
QString m_serverPskKey;
|
QString m_serverPskKey;
|
||||||
QString m_serverIpv6AddrIn;
|
QString m_serverIpv6AddrIn;
|
||||||
QString m_dnsServer;
|
QString m_primaryDnsServer;
|
||||||
|
QString m_secondaryDnsServer;
|
||||||
int m_serverPort = 0;
|
int m_serverPort = 0;
|
||||||
int m_deviceMTU = 1420;
|
int m_deviceMTU = 1420;
|
||||||
QList<IPAddress> m_allowedIPAddressRanges;
|
QList<IPAddress> m_allowedIPAddressRanges;
|
||||||
|
|
|
@ -149,7 +149,14 @@ void LocalSocketController::activate(const QJsonObject &rawConfig) {
|
||||||
json.insert("serverPort", wgConfig.value(amnezia::config_key::port).toInt());
|
json.insert("serverPort", wgConfig.value(amnezia::config_key::port).toInt());
|
||||||
json.insert("serverIpv4Gateway", wgConfig.value(amnezia::config_key::hostName));
|
json.insert("serverIpv4Gateway", wgConfig.value(amnezia::config_key::hostName));
|
||||||
// json.insert("serverIpv6Gateway", QJsonValue(hop.m_server.ipv6Gateway()));
|
// json.insert("serverIpv6Gateway", QJsonValue(hop.m_server.ipv6Gateway()));
|
||||||
json.insert("dnsServer", rawConfig.value(amnezia::config_key::dns1));
|
|
||||||
|
json.insert("primaryDnsServer", rawConfig.value(amnezia::config_key::dns1));
|
||||||
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (!rawConfig.value(amnezia::config_key::dns1).toString().
|
||||||
|
contains(amnezia::protocols::dns::amneziaDnsIp)) {
|
||||||
|
json.insert("secondaryDnsServer", rawConfig.value(amnezia::config_key::dns2));
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray jsAllowedIPAddesses;
|
QJsonArray jsAllowedIPAddesses;
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,10 @@ bool WireguardUtilsLinux::addInterface(const InterfaceConfig& config) {
|
||||||
} else {
|
} else {
|
||||||
if (config.m_killSwitchEnabled) {
|
if (config.m_killSwitchEnabled) {
|
||||||
FirewallParams params { };
|
FirewallParams params { };
|
||||||
params.dnsServers.append(config.m_dnsServer);
|
params.dnsServers.append(config.m_primaryDnsServer);
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
params.dnsServers.append(config.m_secondaryDnsServer);
|
||||||
|
}
|
||||||
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
||||||
params.blockAll = true;
|
params.blockAll = true;
|
||||||
if (config.m_excludedAddresses.size()) {
|
if (config.m_excludedAddresses.size()) {
|
||||||
|
|
|
@ -136,26 +136,29 @@ bool WireguardUtilsMacos::addInterface(const InterfaceConfig& config) {
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
logger.error() << "Interface configuration failed:" << strerror(err);
|
logger.error() << "Interface configuration failed:" << strerror(err);
|
||||||
} else {
|
} else {
|
||||||
if (config.m_killSwitchEnabled) {
|
if (config.m_killSwitchEnabled) {
|
||||||
FirewallParams params { };
|
FirewallParams params { };
|
||||||
params.dnsServers.append(config.m_dnsServer);
|
params.dnsServers.append(config.m_primaryDnsServer);
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
params.dnsServers.append(config.m_secondaryDnsServer);
|
||||||
|
}
|
||||||
|
|
||||||
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
||||||
params.blockAll = true;
|
params.blockAll = true;
|
||||||
if (config.m_excludedAddresses.size()) {
|
if (config.m_excludedAddresses.size()) {
|
||||||
params.allowNets = true;
|
params.allowNets = true;
|
||||||
foreach (auto net, config.m_excludedAddresses) {
|
foreach (auto net, config.m_excludedAddresses) {
|
||||||
params.allowAddrs.append(net.toUtf8());
|
params.allowAddrs.append(net.toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
params.blockNets = true;
|
params.blockNets = true;
|
||||||
foreach (auto net, config.m_allowedIPAddressRanges) {
|
foreach (auto net, config.m_allowedIPAddressRanges) {
|
||||||
params.blockAddrs.append(net.toString());
|
params.blockAddrs.append(net.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
applyFirewallRules(params);
|
|
||||||
}
|
}
|
||||||
|
applyFirewallRules(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (err == 0);
|
return (err == 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,15 +291,32 @@ bool WindowsFirewall::enablePeerTraffic(const InterfaceConfig& config) {
|
||||||
"Block Internet", config.m_serverPublicKey)) {
|
"Block Internet", config.m_serverPublicKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!config.m_dnsServer.isEmpty()) {
|
if (!config.m_primaryDnsServer.isEmpty()) {
|
||||||
if (!allowTrafficTo(QHostAddress(config.m_dnsServer), 53, HIGH_WEIGHT,
|
if (!allowTrafficTo(QHostAddress(config.m_primaryDnsServer), 53, HIGH_WEIGHT,
|
||||||
"Allow DNS-Server", config.m_serverPublicKey)) {
|
"Allow DNS-Server", config.m_serverPublicKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// In some cases, we might configure a 2nd DNS server for IPv6, however
|
// In some cases, we might configure a 2nd DNS server for IPv6, however
|
||||||
// this should probably be cleaned up by converting m_dnsServer into
|
// this should probably be cleaned up by converting m_dnsServer into
|
||||||
// a QStringList instead.
|
// a QStringList instead.
|
||||||
if (config.m_dnsServer == config.m_serverIpv4Gateway) {
|
if (config.m_primaryDnsServer == config.m_serverIpv4Gateway) {
|
||||||
|
if (!allowTrafficTo(QHostAddress(config.m_serverIpv6Gateway), 53,
|
||||||
|
HIGH_WEIGHT, "Allow extra IPv6 DNS-Server",
|
||||||
|
config.m_serverPublicKey)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
if (!allowTrafficTo(QHostAddress(config.m_secondaryDnsServer), 53, HIGH_WEIGHT,
|
||||||
|
"Allow DNS-Server", config.m_serverPublicKey)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// In some cases, we might configure a 2nd DNS server for IPv6, however
|
||||||
|
// this should probably be cleaned up by converting m_dnsServer into
|
||||||
|
// a QStringList instead.
|
||||||
|
if (config.m_secondaryDnsServer == config.m_serverIpv4Gateway) {
|
||||||
if (!allowTrafficTo(QHostAddress(config.m_serverIpv6Gateway), 53,
|
if (!allowTrafficTo(QHostAddress(config.m_serverIpv6Gateway), 53,
|
||||||
HIGH_WEIGHT, "Allow extra IPv6 DNS-Server",
|
HIGH_WEIGHT, "Allow extra IPv6 DNS-Server",
|
||||||
config.m_serverPublicKey)) {
|
config.m_serverPublicKey)) {
|
||||||
|
|
|
@ -98,8 +98,13 @@ ErrorCode XrayProtocol::startTun2Sock()
|
||||||
if (vpnState == Vpn::ConnectionState::Connected) {
|
if (vpnState == Vpn::ConnectionState::Connected) {
|
||||||
setConnectionState(Vpn::ConnectionState::Connecting);
|
setConnectionState(Vpn::ConnectionState::Connecting);
|
||||||
QList<QHostAddress> dnsAddr;
|
QList<QHostAddress> dnsAddr;
|
||||||
|
|
||||||
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns1).toString()));
|
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns1).toString()));
|
||||||
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns2).toString()));
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (!m_configData.value(amnezia::config_key::dns1).toString().
|
||||||
|
contains(amnezia::protocols::dns::amneziaDnsIp)) {
|
||||||
|
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns2).toString()));
|
||||||
|
}
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QThread::msleep(8000);
|
QThread::msleep(8000);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -192,7 +192,14 @@ bool KillSwitch::addAllowedRange(const QStringList &ranges) {
|
||||||
bool KillSwitch::enablePeerTraffic(const QJsonObject &configStr) {
|
bool KillSwitch::enablePeerTraffic(const QJsonObject &configStr) {
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
InterfaceConfig config;
|
InterfaceConfig config;
|
||||||
config.m_dnsServer = configStr.value(amnezia::config_key::dns1).toString();
|
|
||||||
|
config.m_primaryDnsServer = configStr.value(amnezia::config_key::dns1).toString();
|
||||||
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (!config.m_primaryDnsServer.contains(amnezia::protocols::dns::amneziaDnsIp)) {
|
||||||
|
config.m_secondaryDnsServer = configStr.value(amnezia::config_key::dns2).toString();
|
||||||
|
}
|
||||||
|
|
||||||
config.m_serverPublicKey = "openvpn";
|
config.m_serverPublicKey = "openvpn";
|
||||||
config.m_serverIpv4Gateway = configStr.value("vpnGateway").toString();
|
config.m_serverIpv4Gateway = configStr.value("vpnGateway").toString();
|
||||||
config.m_serverIpv4AddrIn = configStr.value("vpnServer").toString();
|
config.m_serverIpv4AddrIn = configStr.value("vpnServer").toString();
|
||||||
|
@ -307,8 +314,14 @@ bool KillSwitch::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterIn
|
||||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("300.allowLAN"), true);
|
LinuxFirewall::setAnchorEnabled(LinuxFirewall::Both, QStringLiteral("300.allowLAN"), true);
|
||||||
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("310.blockDNS"), true);
|
LinuxFirewall::setAnchorEnabled(LinuxFirewall::IPv4, QStringLiteral("310.blockDNS"), true);
|
||||||
QStringList dnsServers;
|
QStringList dnsServers;
|
||||||
|
|
||||||
dnsServers.append(configStr.value(amnezia::config_key::dns1).toString());
|
dnsServers.append(configStr.value(amnezia::config_key::dns1).toString());
|
||||||
dnsServers.append(configStr.value(amnezia::config_key::dns2).toString());
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (!configStr.value(amnezia::config_key::dns1).toString().contains(amnezia::protocols::dns::amneziaDnsIp)) {
|
||||||
|
dnsServers.append(configStr.value(amnezia::config_key::dns2).toString());
|
||||||
|
}
|
||||||
|
|
||||||
dnsServers.append("127.0.0.1");
|
dnsServers.append("127.0.0.1");
|
||||||
dnsServers.append("127.0.0.53");
|
dnsServers.append("127.0.0.53");
|
||||||
|
|
||||||
|
@ -345,7 +358,11 @@ bool KillSwitch::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterIn
|
||||||
|
|
||||||
QStringList dnsServers;
|
QStringList dnsServers;
|
||||||
dnsServers.append(configStr.value(amnezia::config_key::dns1).toString());
|
dnsServers.append(configStr.value(amnezia::config_key::dns1).toString());
|
||||||
dnsServers.append(configStr.value(amnezia::config_key::dns2).toString());
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (!configStr.value(amnezia::config_key::dns1).toString().contains(amnezia::protocols::dns::amneziaDnsIp)) {
|
||||||
|
dnsServers.append(configStr.value(amnezia::config_key::dns2).toString());
|
||||||
|
}
|
||||||
|
|
||||||
for (auto dns : configStr.value(amnezia::config_key::allowedDnsServers).toArray()) {
|
for (auto dns : configStr.value(amnezia::config_key::allowedDnsServers).toArray()) {
|
||||||
if (!dns.isString()) {
|
if (!dns.isString()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue