From 18c1b7f1ad6c41779700ad36d743b66944061166 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Tue, 4 Feb 2020 12:43:36 +0000 Subject: service-quasselcore: Add bindhost functionality --- .../net-irc/quassel/quassel-bind-host.patch | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 service-quasselcore/patches/net-irc/quassel/quassel-bind-host.patch diff --git a/service-quasselcore/patches/net-irc/quassel/quassel-bind-host.patch b/service-quasselcore/patches/net-irc/quassel/quassel-bind-host.patch new file mode 100644 index 0000000..2bf8726 --- /dev/null +++ b/service-quasselcore/patches/net-irc/quassel/quassel-bind-host.patch @@ -0,0 +1,116 @@ +diff --git a/src/common/main.cpp b/src/common/main.cpp +index 0ee13ecd..2df950a0 100644 +--- a/src/common/main.cpp ++++ b/src/common/main.cpp +@@ -185,6 +185,7 @@ int main(int argc, char **argv) + #ifndef BUILD_QTUI + // put core-only arguments here + cliParser->addOption("listen", 0, "The address(es) quasselcore will listen on", "
[,
[,...]]", "::,0.0.0.0"); ++ cliParser->addOption("bind-host", 0, "The address quasselcore will make outgoing connections from.", "address", ""); + cliParser->addOption("port", 'p', "The port quasselcore will listen at", "port", "4242"); + cliParser->addSwitch("norestore", 'n', "Don't restore last core's state"); + cliParser->addSwitch("config-from-environment", 0, "Load configuration from environment variables"); +diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp +index fa8ae9bf..af335e1f 100644 +--- a/src/core/corenetwork.cpp ++++ b/src/core/corenetwork.cpp +@@ -22,6 +22,7 @@ + + #include + #include ++#include + + #include "core.h" + #include "coreidentity.h" +@@ -244,6 +245,76 @@ void CoreNetwork::connectToIrc(bool reconnecting) + displayStatusMsg(tr("Connecting to %1:%2...").arg(server.host).arg(server.port)); + displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Connecting to %1:%2...").arg(server.host).arg(server.port)); + ++ QHostInfo targetinfo; ++ ++ // Qt caches DNS entries for a minute, resulting in round-robin (e.g. for chat.freenode.net) not working if several users ++ // connect at a similar time. QHostInfo::fromName(), however, always performs a fresh lookup, overwriting the cache entry. ++ if (! server.useProxy) { ++ //Avoid hostname lookups when a proxy is specified. The lookups won't use the proxy and may therefore leak the DNS ++ //hostname of the server. Qt's DNS cache also isn't used by the proxy so we don't need to refresh the entry. ++ //TODO: don't do this twice if bind-host is set ++ targetinfo = QHostInfo::fromName(server.host); ++ } else if (Quassel::isOptionSet("bind-host")) { ++ qWarning() << tr("bind-host not supported if proxy is set"); ++ } ++ ++ if (!server.useProxy && Quassel::isOptionSet("bind-host")) { ++ QHostAddress hostaddr = QHostAddress(); ++ QString bindaddr = Quassel::optionValue("bind-host"); ++ ++ QHostInfo bindinfo = QHostInfo::fromName(bindaddr); ++ ++ if (bindinfo.error() != QHostInfo::NoError) { ++ qWarning() << qPrintable(tr("Could not look up bind host \"%1\": %2").arg(bindaddr).arg(bindinfo.errorString())); ++ } else if (targetinfo.error() != QHostInfo::NoError) { ++ qWarning() << qPrintable(tr("Could not look up server host %1").arg(targetinfo.errorString())); ++ } else { ++ QHostAddress baddr4 = QHostAddress(); ++ QHostAddress baddr6 = QHostAddress(); ++ for (int i = 0; i < bindinfo.addresses().size(); i++) { ++ if (!baddr4.isNull() && !baddr6.isNull()) { ++ break; ++ } ++ if (baddr4.isNull() && bindinfo.addresses()[i].protocol() == QAbstractSocket::IPv4Protocol) { ++ baddr4 = bindinfo.addresses()[i]; ++ } ++ if (baddr6.isNull() && bindinfo.addresses()[i].protocol() == QAbstractSocket::IPv6Protocol) { ++ baddr6 = bindinfo.addresses()[i]; ++ } ++ } ++ ++ QHostAddress taddr4 = QHostAddress(); ++ QHostAddress taddr6 = QHostAddress(); ++ for (int i = 0; i < targetinfo.addresses().size(); i++) { ++ if (!taddr4.isNull() && !taddr6.isNull()) { ++ break; ++ } ++ if (taddr4.isNull() && targetinfo.addresses()[i].protocol() == QAbstractSocket::IPv4Protocol) { ++ taddr4 = targetinfo.addresses()[i]; ++ } ++ if (taddr6.isNull() && targetinfo.addresses()[i].protocol() == QAbstractSocket::IPv6Protocol) { ++ taddr6 = targetinfo.addresses()[i]; ++ } ++ } ++ ++ QHostAddress bind = QHostAddress(); ++ if (!baddr6.isNull() && !taddr6.isNull()) { ++ bind = baddr6; ++ } else if (!baddr4.isNull() && !taddr4.isNull()) { ++ bind = baddr4; ++ } else { ++ qWarning() << tr("Mismatched bind-host and server family."); ++ } ++ ++ if (!bind.isNull()) { ++ qWarning() << qPrintable(tr("Binding to %1").arg(bind.toString())); ++ if (!socket.bind(bind)) { ++ qWarning() << qPrintable(tr("Could not bind to %1").arg(bind.toString())); ++ } ++ } ++ } ++ } ++ + if (server.useProxy) { + QNetworkProxy proxy((QNetworkProxy::ProxyType)server.proxyType, server.proxyHost, server.proxyPort, server.proxyUser, server.proxyPass); + socket.setProxy(proxy); +@@ -256,14 +327,6 @@ void CoreNetwork::connectToIrc(bool reconnecting) + + // Reset tracking for valid timestamps in PONG replies + setPongTimestampValid(false); +- +- // Qt caches DNS entries for a minute, resulting in round-robin (e.g. for chat.freenode.net) not working if several users +- // connect at a similar time. QHostInfo::fromName(), however, always performs a fresh lookup, overwriting the cache entry. +- if (! server.useProxy) { +- //Avoid hostname lookups when a proxy is specified. The lookups won't use the proxy and may therefore leak the DNS +- //hostname of the server. Qt's DNS cache also isn't used by the proxy so we don't need to refresh the entry. +- QHostInfo::fromName(server.host); +- } + #ifdef HAVE_SSL + if (server.useSsl) { + CoreIdentity *identity = identityPtr(); -- cgit v1.2.3-2-gb3c3