aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-10-15 00:48:23 +0100
committerGravatar Sadie Powell2022-10-16 19:51:24 +0100
commit8e419d0b2aebe37a5aa49e23c477d997d9c35810 (patch)
treef84c9a9a3743682c41e68a6c79e314671bf63bee /src/modules
parentFix various inappropriate uses of UINT_MAX. (diff)
Refactor the DNS resolvers in the spanningtree module.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_spanningtree/main.cpp2
-rw-r--r--src/modules/m_spanningtree/resolvers.cpp46
-rw-r--r--src/modules/m_spanningtree/resolvers.h29
3 files changed, 32 insertions, 45 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 55ca9ee62..241c498f5 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -265,7 +265,7 @@ void ModuleSpanningTree::ConnectServer(std::shared_ptr<Link> x, std::shared_ptr<
start_type = DNS::QUERY_A;
}
- auto snr = new ServernameResolver(*DNS, x->IPAddr, x, start_type, y);
+ auto snr = new ServerNameResolver(*DNS, x->IPAddr, x, start_type, y);
try
{
DNS->Process(snr);
diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp
index 44e3e7dc6..fbaa6c21b 100644
--- a/src/modules/m_spanningtree/resolvers.cpp
+++ b/src/modules/m_spanningtree/resolvers.cpp
@@ -34,19 +34,14 @@
#include "link.h"
#include "treesocket.h"
-/** This class is used to resolve server hostnames during /connect and autoconnect.
- * As of 1.1, the resolver system is separated out from BufferedSocket, so we must do this
- * resolver step first ourselves if we need it. This is totally nonblocking, and will
- * callback to OnLookupComplete or OnError when completed. Once it has completed we
- * will have an IP address which we can then use to continue our connection.
- */
-ServernameResolver::ServernameResolver(DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> x, DNS::QueryType qt, std::shared_ptr<Autoconnect> myac)
+ServerNameResolver::ServerNameResolver(DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> l, DNS::QueryType qt, std::shared_ptr<Autoconnect> a)
: DNS::Request(mgr, Utils->Creator, hostname, qt)
- , query(qt), host(hostname), MyLink(x), myautoconnect(myac)
+ , autoconnect(a)
+ , link(l)
{
}
-void ServernameResolver::OnLookupComplete(const DNS::Query* r)
+void ServerNameResolver::OnLookupComplete(const DNS::Query* r)
{
const DNS::ResourceRecord* const ans_record = r->FindAnswerOfType(this->question.type);
if (!ans_record)
@@ -56,7 +51,7 @@ void ServernameResolver::OnLookupComplete(const DNS::Query* r)
}
irc::sockets::sockaddrs sa(false);
- if (!sa.from_ip_port(ans_record->rdata, MyLink->Port))
+ if (!sa.from_ip_port(ans_record->rdata, link->Port))
{
// We had a result but it wasn't a valid IPv4/IPv6.
OnError(r);
@@ -67,21 +62,21 @@ void ServernameResolver::OnLookupComplete(const DNS::Query* r)
* Passing a hostname directly to BufferedSocket causes it to
* just bail and set its FD to -1.
*/
- TreeServer* CheckDupe = Utils->FindServer(MyLink->Name);
+ TreeServer* CheckDupe = Utils->FindServer(link->Name);
if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
{
- auto newsocket = new TreeSocket(MyLink, myautoconnect, sa);
+ auto newsocket = new TreeSocket(link, autoconnect, sa);
if (!newsocket->HasFd())
{
/* Something barfed, show the opers */
ServerInstance->SNO.WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
- MyLink->Name.c_str(), newsocket->GetError().c_str());
+ link->Name.c_str(), newsocket->GetError().c_str());
ServerInstance->GlobalCulls.AddItem(newsocket);
}
}
}
-void ServernameResolver::OnError(const DNS::Query* r)
+void ServerNameResolver::OnError(const DNS::Query* r)
{
if (r->error == DNS::ERROR_UNLOADED)
{
@@ -89,9 +84,9 @@ void ServernameResolver::OnError(const DNS::Query* r)
return;
}
- if (query == DNS::QUERY_AAAA)
+ if (question.type == DNS::QUERY_AAAA)
{
- auto snr = new ServernameResolver(this->manager, host, MyLink, DNS::QUERY_A, myautoconnect);
+ auto snr = new ServerNameResolver(this->manager, question.name, link, DNS::QUERY_A, autoconnect);
try
{
this->manager->Process(snr);
@@ -103,23 +98,24 @@ void ServernameResolver::OnError(const DNS::Query* r)
}
}
- ServerInstance->SNO.WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s", MyLink->Name.c_str(), this->manager->GetErrorStr(r->error).c_str());
- Utils->Creator->ConnectServer(myautoconnect, false);
+ ServerInstance->SNO.WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s",
+ link->Name.c_str(), this->manager->GetErrorStr(r->error).c_str());
+ Utils->Creator->ConnectServer(autoconnect, false);
}
-SecurityIPResolver::SecurityIPResolver(Module* me, DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> x, DNS::QueryType qt)
+SecurityIPResolver::SecurityIPResolver(Module* me, DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> l, DNS::QueryType qt)
: DNS::Request(mgr, me, hostname, qt)
- , MyLink(x), mine(me), host(hostname), query(qt)
+ , link(l)
{
}
bool SecurityIPResolver::CheckIPv4()
{
// We only check IPv4 addresses if we have checked IPv6.
- if (query != DNS::QUERY_AAAA)
+ if (question.type != DNS::QUERY_AAAA)
return false;
- auto res = new SecurityIPResolver(mine, this->manager, host, MyLink, DNS::QUERY_A);
+ auto res = new SecurityIPResolver(creator, manager, question.name, link, DNS::QUERY_A);
try
{
this->manager->Process(res);
@@ -136,7 +132,7 @@ void SecurityIPResolver::OnLookupComplete(const DNS::Query* r)
{
for (std::shared_ptr<Link> L : Utils->LinkBlocks)
{
- if (L->IPAddr == host)
+ if (L->IPAddr == question.name)
{
for (const auto& ans_record : r->answers)
{
@@ -145,7 +141,7 @@ void SecurityIPResolver::OnLookupComplete(const DNS::Query* r)
Utils->ValidIPs.push_back(ans_record.rdata);
ServerInstance->Logs.Normal(MODNAME, "Resolved '%s' as a valid IP address for link '%s'",
- ans_record.rdata.c_str(), MyLink->Name.c_str());
+ ans_record.rdata.c_str(), link->Name.c_str());
}
break;
}
@@ -161,7 +157,7 @@ void SecurityIPResolver::OnError(const DNS::Query* r)
return;
ServerInstance->Logs.Debug(MODNAME, "Could not resolve IP associated with link '%s': %s",
- MyLink->Name.c_str(), this->manager->GetErrorStr(r->error).c_str());
+ link->Name.c_str(), this->manager->GetErrorStr(r->error).c_str());
}
CacheRefreshTimer::CacheRefreshTimer()
diff --git a/src/modules/m_spanningtree/resolvers.h b/src/modules/m_spanningtree/resolvers.h
index c9e02f6cf..06cb2ed8a 100644
--- a/src/modules/m_spanningtree/resolvers.h
+++ b/src/modules/m_spanningtree/resolvers.h
@@ -31,39 +31,30 @@
#include "utils.h"
#include "link.h"
-/** Handle resolving of server IPs for the cache
- */
+// Handles resolving whitelisted hostnames for the inbound connection whitelist.
class SecurityIPResolver final
: public DNS::Request
{
private:
- std::shared_ptr<Link> MyLink;
- Module* mine;
- std::string host;
- DNS::QueryType query;
+ std::shared_ptr<Link> link;
bool CheckIPv4();
+
public:
- SecurityIPResolver(Module* me, DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> x, DNS::QueryType qt);
+ SecurityIPResolver(Module* mod, DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> l, DNS::QueryType qt);
void OnLookupComplete(const DNS::Query* r) override;
void OnError(const DNS::Query* q) override;
};
-/** This class is used to resolve server hostnames during /connect and autoconnect.
- * As of 1.1, the resolver system is separated out from BufferedSocket, so we must do this
- * resolver step first ourselves if we need it. This is totally nonblocking, and will
- * callback to OnLookupComplete or OnError when completed. Once it has completed we
- * will have an IP address which we can then use to continue our connection.
- */
-class ServernameResolver final
+// Handles resolving server hostnames when making an outbound connection.
+class ServerNameResolver final
: public DNS::Request
{
private:
- DNS::QueryType query;
- std::string host;
- std::shared_ptr<Link> MyLink;
- std::shared_ptr<Autoconnect> myautoconnect;
+ std::shared_ptr<Autoconnect> autoconnect;
+ std::shared_ptr<Link> link;
+
public:
- ServernameResolver(DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> x, DNS::QueryType qt, std::shared_ptr<Autoconnect> myac);
+ ServerNameResolver(DNS::Manager* mgr, const std::string& hostname, std::shared_ptr<Link> l, DNS::QueryType qt, std::shared_ptr<Autoconnect> a);
void OnLookupComplete(const DNS::Query* r) override;
void OnError(const DNS::Query* q) override;
};