-
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.
Fix the DNS handling in StateOnPartial
wip fix dns Add test code FIX test code remove unsued tests cleanup
- Loading branch information
Showing
10 changed files
with
279 additions
and
29 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,56 @@ | ||
/* 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 <qassert.h> | ||
#include <qhostaddress.h> | ||
|
||
#include "dnshelper.h" | ||
#include "ipaddress.h" | ||
#include "models/server.h" | ||
#include "rfc/rfc1112.h" | ||
#include "rfc/rfc1918.h" | ||
#include "rfc/rfc4193.h" | ||
#include "rfc/rfc4291.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
Oops, something went wrong.