-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FXVPN-377 Fix DNS Inclusion (#10257)
* Fix the DNS handling in StateOnPartial wip fix dns Add test code FIX test code remove unsued tests cleanup * cleanup * Fix compile thingy
- Loading branch information
Showing
10 changed files
with
270 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "controller_p.h" | ||
|
||
#include <QHostAddress> | ||
|
||
#include "dnshelper.h" | ||
#include "ipaddress.h" | ||
#include "models/server.h" | ||
#include "rfc/rfc1918.h" | ||
#include "rfc/rfc4193.h" | ||
|
||
namespace ControllerPrivate { | ||
|
||
QList<IPAddress> getExtensionProxyAddressRanges( | ||
const Server& exitServer, std::optional<const dnsData> dnsServer) { | ||
QList<IPAddress> ranges = { | ||
IPAddress(QHostAddress(exitServer.ipv4Gateway()), 32), | ||
IPAddress(QHostAddress{MULLVAD_PROXY_RANGE}, MULLVAD_PROXY_RANGE_LENGTH)}; | ||
if (!exitServer.ipv6Gateway().isEmpty()) { | ||
ranges.append(IPAddress(QHostAddress(exitServer.ipv6Gateway()), 128)); | ||
} | ||
|
||
const dnsData dns = [&dnsServer, &exitServer]() { | ||
if (dnsServer.has_value()) { | ||
return dnsServer.value(); | ||
} | ||
return DNSHelper::getDNSDetails(exitServer.ipv4Gateway()); | ||
}(); | ||
|
||
if (dns.dnsType == "Default") { | ||
// The DNS Adress is already Resolved. | ||
return ranges; | ||
} | ||
if (dns.dnsType != "Custom") { | ||
// It's a vpn-internal DNS, always add it | ||
ranges.append(IPAddress(QHostAddress(dns.ipAddress), 32)); | ||
return ranges; | ||
} | ||
Q_ASSERT(dns.dnsType == "Custom"); | ||
const QHostAddress addr{dns.ipAddress}; | ||
// If it is a custom dns only add it to the tunnel if it is **NOT** | ||
// a "lan" adress | ||
if (!RFC1918::contains(addr) && !RFC4193::contains(addr) && | ||
!addr.isLoopback()) { | ||
ranges.append(IPAddress(QHostAddress(dns.ipAddress), 32)); | ||
} | ||
return ranges; | ||
} | ||
|
||
} // namespace ControllerPrivate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#pragma once | ||
|
||
#include <QHostAddress> | ||
#include <QList> | ||
|
||
#include "dnshelper.h" | ||
|
||
class IPAddress; | ||
class Server; | ||
|
||
/** | ||
* Controller.cpp is currently mock'ed out of the unit tests | ||
* stopping us from testing it. This namespace should contain | ||
* pure functions so that we can start writing unit-tests for that code. | ||
* | ||
*/ | ||
namespace ControllerPrivate { | ||
|
||
// The Mullvad proxy services are located at internal IPv4 addresses in the | ||
// 10.124.0.0/20 address range, which is a subset of the 10.0.0.0/8 Class-A | ||
// private address range. | ||
constexpr const char* MULLVAD_PROXY_RANGE = "10.124.0.0"; | ||
constexpr const int MULLVAD_PROXY_RANGE_LENGTH = 20; | ||
|
||
QList<IPAddress> getExtensionProxyAddressRanges( | ||
const Server& exitServer, | ||
std::optional<const dnsData> dnsServer = std::nullopt); | ||
|
||
} // namespace ControllerPrivate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "testcontroller_p.h" | ||
|
||
#include <QHostAddress> | ||
#include <QJsonArray> | ||
#include <QJsonObject> | ||
|
||
#include "controller_p.h" | ||
#include "dnshelper.h" | ||
#include "ipaddress.h" | ||
#include "models/server.h" | ||
namespace { | ||
|
||
Server createServer(QString ipv4Gateway) { | ||
QJsonObject args; | ||
args["hostname"] = "test"; | ||
args["ipv4_addr_in"] = "test"; | ||
args["ipv4_gateway"] = ipv4Gateway; | ||
args["ipv6_addr_in"] = "2001:db8::1"; | ||
args["ipv6_gateway"] = "2001:db8::1"; | ||
args["public_key"] = "test"; | ||
args["weight"] = 0.0; | ||
args["port_ranges"] = QJsonArray{}; | ||
Server out{}; | ||
bool ok = out.fromJson(args); | ||
Q_UNUSED(ok); | ||
return out; | ||
} | ||
|
||
bool includesAddress(QHostAddress addr, const QList<IPAddress>& l) { | ||
for (auto const& laddr : l) { | ||
if (laddr.contains(addr)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
}; // namespace | ||
|
||
void TestControllerPrivate::getExtensionProxyAddressRanges() { | ||
auto const testIsDNSIncluded = [](dnsData dns, QString exitGateway) { | ||
auto const res = ControllerPrivate::getExtensionProxyAddressRanges( | ||
createServer(exitGateway), dns); | ||
return includesAddress(QHostAddress{dns.ipAddress}, res); | ||
}; | ||
|
||
// A Custom DNS that is not in the localhost network | ||
// should be in the ProxyAdressRange (so it will be tunneled in the vpn) | ||
QCOMPARE(testIsDNSIncluded( | ||
{ | ||
.ipAddress = "99.99.99.99", | ||
.dnsType = "Custom", | ||
}, | ||
"1.2.3.5"), | ||
true); | ||
|
||
// Opposite: a LAN ip should not appear on this list. | ||
QCOMPARE(testIsDNSIncluded( | ||
{ | ||
.ipAddress = "192.168.0.1", | ||
.dnsType = "Custom", | ||
}, | ||
"1.2.3.5"), | ||
false); | ||
|
||
// If you run your dns on localhost. also not. | ||
QCOMPARE(testIsDNSIncluded( | ||
{ | ||
.ipAddress = "127.0.0.1", | ||
.dnsType = "Custom", | ||
}, | ||
"1.2.3.5"), | ||
false); | ||
|
||
// The default is the Exit node, so that should be tunneled | ||
QCOMPARE(testIsDNSIncluded( | ||
{ | ||
.ipAddress = "1.2.3.5", | ||
.dnsType = "Default", | ||
}, | ||
"1.2.3.5"), | ||
true); | ||
|
||
// If we add a filtering dns, that MUST always go through the tunnel. | ||
QCOMPARE(testIsDNSIncluded( | ||
{ | ||
.ipAddress = "99.99.99.99", | ||
.dnsType = "BlockMalwareAndTrackers", | ||
}, | ||
"1.2.3.5"), | ||
true); | ||
} | ||
|
||
static TestControllerPrivate s_instance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "helper.h" | ||
|
||
class TestControllerPrivate final : public TestHelper { | ||
Q_OBJECT | ||
private slots: | ||
void getExtensionProxyAddressRanges(); | ||
}; |