Skip to content

Commit

Permalink
chore/mozilla upstream (#1136)
Browse files Browse the repository at this point in the history
* cherry-pick commit 5a51e292d44ec0fb07867aff0401b4c2a8fca1e8 from mozila upstream

* cherry-pick commit e8ecb857dcfb804b7766a54e725b442fc6c0e661 from mozila upstream

* cherry-pick commit 16269ffa600905b09678014f64951748fb0ff8ad from mozila upstream
  • Loading branch information
Nethius authored Oct 18, 2024
1 parent c4f32ee commit 60de146
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 29 deletions.
23 changes: 5 additions & 18 deletions client/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool Daemon::activate(const InterfaceConfig& config) {
return false;
}

if (supportDnsUtils() && !dnsutils()->restoreResolvers()) {
if (!dnsutils()->restoreResolvers()) {
return false;
}

Expand Down Expand Up @@ -165,10 +165,6 @@ bool Daemon::activate(const InterfaceConfig& config) {
}

bool Daemon::maybeUpdateResolvers(const InterfaceConfig& config) {
if (!supportDnsUtils()) {
return true;
}

if ((config.m_hopType == InterfaceConfig::MultiHopExit) ||
(config.m_hopType == InterfaceConfig::SingleHop)) {
QList<QHostAddress> resolvers;
Expand Down Expand Up @@ -423,13 +419,8 @@ bool Daemon::deactivate(bool emitSignals) {
}

// Cleanup DNS
if (supportDnsUtils() && !dnsutils()->restoreResolvers()) {
return false;
}

if (!wgutils()->interfaceExists()) {
logger.warning() << "Wireguard interface does not exist.";
return false;
if (!dnsutils()->restoreResolvers()) {
logger.warning() << "Failed to restore DNS resolvers.";
}

// Cleanup peers and routing
Expand All @@ -449,13 +440,9 @@ bool Daemon::deactivate(bool emitSignals) {
}
m_excludedAddrSet.clear();

// Delete the interface
if (!wgutils()->deleteInterface()) {
return false;
}

m_connections.clear();
return true;
// Delete the interface
return wgutils()->deleteInterface();
}

QString Daemon::logs() {
Expand Down
1 change: 0 additions & 1 deletion client/daemon/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class Daemon : public QObject {
virtual WireguardUtils* wgutils() const = 0;
virtual bool supportIPUtils() const { return false; }
virtual IPUtils* iputils() { return nullptr; }
virtual bool supportDnsUtils() const { return false; }
virtual DnsUtils* dnsutils() { return nullptr; }

static bool parseStringList(const QJsonObject& obj, const QString& name,
Expand Down
17 changes: 13 additions & 4 deletions client/daemon/daemonlocalserverconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ void DaemonLocalServerConnection::parseCommand(const QByteArray& data) {

logger.debug() << "Command received:" << type;

// It is expected that sometimes the client will request backend logs
// before the first authentication. In these cases we just return empty
// logs.
if (type == "logs") {
QJsonObject obj;
obj.insert("type", "logs");
obj.insert("logs", "");
write(obj);
return;
}

if (type == "activate") {
InterfaceConfig config;
if (!Daemon::parseConfig(obj, config)) {
Expand All @@ -115,17 +126,15 @@ void DaemonLocalServerConnection::parseCommand(const QByteArray& data) {
if (type == "status") {
QJsonObject obj = Daemon::instance()->getStatus();
obj.insert("type", "status");
m_socket->write(QJsonDocument(obj).toJson(QJsonDocument::Compact));
m_socket->write("\n");
write(obj);
return;
}

if (type == "logs") {
QJsonObject obj;
obj.insert("type", "logs");
obj.insert("logs", Daemon::instance()->logs().replace("\n", "|"));
m_socket->write(QJsonDocument(obj).toJson(QJsonDocument::Compact));
m_socket->write("\n");
write(obj);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions client/mozilla/localsocketcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ LocalSocketController::LocalSocketController() {
m_socket = new QLocalSocket(this);
connect(m_socket, &QLocalSocket::connected, this,
&LocalSocketController::daemonConnected);
connect(m_socket, &QLocalSocket::disconnected, this,
&LocalSocketController::disconnected);
connect(m_socket, &QLocalSocket::disconnected, this,
[&] { errorOccurred(QLocalSocket::PeerClosedError); });
connect(m_socket, &QLocalSocket::errorOccurred, this,
&LocalSocketController::errorOccurred);
connect(m_socket, &QLocalSocket::readyRead, this,
Expand Down
1 change: 0 additions & 1 deletion client/platforms/linux/daemon/linuxdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class LinuxDaemon final : public Daemon {

protected:
WireguardUtils* wgutils() const override { return m_wgutils; }
bool supportDnsUtils() const override { return true; }
DnsUtils* dnsutils() override { return m_dnsutils; }
bool supportIPUtils() const override { return true; }
IPUtils* iputils() override { return m_iputils; }
Expand Down
1 change: 0 additions & 1 deletion client/platforms/macos/daemon/macosdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class MacOSDaemon final : public Daemon {

protected:
WireguardUtils* wgutils() const override { return m_wgutils; }
bool supportDnsUtils() const override { return true; }
DnsUtils* dnsutils() override { return m_dnsutils; }
bool supportIPUtils() const override { return true; }
IPUtils* iputils() override { return m_iputils; }
Expand Down
1 change: 0 additions & 1 deletion client/platforms/windows/daemon/windowsdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class WindowsDaemon final : public Daemon {
protected:
bool run(Op op, const InterfaceConfig& config) override;
WireguardUtils* wgutils() const override { return m_wgutils; }
bool supportDnsUtils() const override { return true; }
DnsUtils* dnsutils() override { return m_dnsutils; }

private:
Expand Down
2 changes: 1 addition & 1 deletion client/platforms/windows/daemon/windowssplittunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ QString WindowsSplitTunnel::convertPath(const QString& path) {
// device should contain : for e.g C:
return "";
}
QByteArray buffer(2048, 0xFF);
QByteArray buffer(2048, 0xFFu);
auto ok = QueryDosDeviceW(qUtf16Printable(driveLetter),
(wchar_t*)buffer.data(), buffer.size() / 2);

Expand Down

0 comments on commit 60de146

Please sign in to comment.