From ba82306465d61f99fd353f2533a1447801d6c676 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 25 Dec 2021 09:34:12 +0000 Subject: Fix not looking up IPv4 addresses when a server has an IPv6 address. Closes #1811. --- src/modules/m_spanningtree/resolvers.cpp | 47 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'src/modules/m_spanningtree/resolvers.cpp') diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp index 2811737b8..a339c7756 100644 --- a/src/modules/m_spanningtree/resolvers.cpp +++ b/src/modules/m_spanningtree/resolvers.cpp @@ -113,6 +113,25 @@ SecurityIPResolver::SecurityIPResolver(Module* me, DNS::Manager* mgr, const std: { } +bool SecurityIPResolver::CheckIPv4() +{ + // We only check IPv4 addresses if we have checked IPv6. + if (query != DNS::QUERY_AAAA) + return false; + + SecurityIPResolver* res = new SecurityIPResolver(mine, this->manager, host, MyLink, DNS::QUERY_A); + try + { + this->manager->Process(res); + return true; + } + catch (const DNS::Exception&) + { + delete res; + return false; + } +} + void SecurityIPResolver::OnLookupComplete(const DNS::Query *r) { for (std::vector >::iterator i = Utils->LinkBlocks.begin(); i != Utils->LinkBlocks.end(); ++i) @@ -123,31 +142,27 @@ void SecurityIPResolver::OnLookupComplete(const DNS::Query *r) for (std::vector::const_iterator j = r->answers.begin(); j != r->answers.end(); ++j) { const DNS::ResourceRecord& ans_record = *j; - if (ans_record.type == this->question.type) - Utils->ValidIPs.push_back(ans_record.rdata); + if (ans_record.type != this->question.type) + continue; + + Utils->ValidIPs.push_back(ans_record.rdata); + ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Resolved '%s' as a valid IP address for link '%s'", + ans_record.rdata.c_str(), MyLink->Name.c_str()); } break; } } + + CheckIPv4(); } void SecurityIPResolver::OnError(const DNS::Query *r) { // This can be called because of us being unloaded but we don't have to do anything differently - if (query == DNS::QUERY_AAAA) - { - SecurityIPResolver* res = new SecurityIPResolver(mine, this->manager, host, MyLink, DNS::QUERY_A); - try - { - this->manager->Process(res); - return; - } - catch (DNS::Exception &) - { - delete res; - } - } - ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Could not resolve IP associated with Link '%s': %s", + if (CheckIPv4()) + return; + + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Could not resolve IP associated with link '%s': %s", MyLink->Name.c_str(), this->manager->GetErrorStr(r->error).c_str()); } -- cgit v1.3.1-10-gc9f91