summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules/dns.h19
-rw-r--r--src/coremods/core_dns.cpp14
-rw-r--r--src/coremods/core_hostname_lookup.cpp19
-rw-r--r--src/modules/m_spanningtree/resolvers.cpp9
4 files changed, 32 insertions, 29 deletions
diff --git a/include/modules/dns.h b/include/modules/dns.h
index 1ba54cc61..5f2836761 100644
--- a/include/modules/dns.h
+++ b/include/modules/dns.h
@@ -117,6 +117,18 @@ namespace DNS
Query() : error(ERROR_NONE), cached(false) { }
Query(const Question& q) : question(q), error(ERROR_NONE), cached(false) { }
+
+ const ResourceRecord* FindAnswerOfType(QueryType qtype) const
+ {
+ for (std::vector<DNS::ResourceRecord>::const_iterator i = answers.begin(); i != answers.end(); ++i)
+ {
+ const DNS::ResourceRecord& rr = *i;
+ if (rr.type == qtype)
+ return &rr;
+ }
+
+ return NULL;
+ }
};
class ReplySocket;
@@ -136,11 +148,12 @@ namespace DNS
/** A DNS query.
*/
- class Request : public Timer, public Question
+ class Request : public Timer
{
protected:
Manager* const manager;
public:
+ Question question;
/* Use result cache if available */
bool use_cache;
/* Request id */
@@ -150,8 +163,8 @@ namespace DNS
Request(Manager* mgr, Module* mod, const std::string& addr, QueryType qt, bool usecache = true)
: Timer((ServerInstance->Config->dns_timeout ? ServerInstance->Config->dns_timeout : 5))
- , Question(addr, qt)
, manager(mgr)
+ , question(addr, qt)
, use_cache(usecache)
, id(0)
, creator(mod)
@@ -178,7 +191,7 @@ namespace DNS
*/
bool Tick(time_t now)
{
- Query rr(*this);
+ Query rr(this->question);
rr.error = ERROR_TIMEDOUT;
this->OnError(&rr);
delete this;
diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp
index 25182eb1b..c95d42ea3 100644
--- a/src/coremods/core_dns.cpp
+++ b/src/coremods/core_dns.cpp
@@ -416,7 +416,7 @@ class MyManager : public Manager, public Timer, public EventHandler
if (!request)
continue;
- Query rr(*request);
+ Query rr(request->question);
rr.error = ERROR_UNKNOWN;
request->OnError(&rr);
@@ -426,7 +426,7 @@ class MyManager : public Manager, public Timer, public EventHandler
void Process(DNS::Request* req)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Processing request to lookup " + req->name + " of type " + ConvToStr(req->type) + " to " + this->myserver.addr());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Processing request to lookup " + req->question.name + " of type " + ConvToStr(req->question.type) + " to " + this->myserver.addr());
/* Create an id */
unsigned int tries = 0;
@@ -463,7 +463,7 @@ class MyManager : public Manager, public Timer, public EventHandler
Packet p;
p.flags = QUERYFLAGS_RD;
p.id = req->id;
- p.question = *req;
+ p.question = req->question;
unsigned char buffer[524];
unsigned short len = p.Pack(buffer, sizeof(buffer));
@@ -479,7 +479,7 @@ class MyManager : public Manager, public Timer, public EventHandler
}
// Update name in the original request so question checking works for PTR queries
- req->name = p.question.name;
+ req->question.name = p.question.name;
if (SocketEngine::SendTo(this, buffer, len, 0, &this->myserver.sa, this->myserver.sa_size()) != len)
throw Exception("DNS: Unable to send query");
@@ -568,7 +568,7 @@ class MyManager : public Manager, public Timer, public EventHandler
return;
}
- if (static_cast<Question&>(*request) != recv_packet.question)
+ if (request->question != recv_packet.question)
{
// This can happen under high latency, drop it silently, do not fail the request
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received an answer that isn't for a question we asked");
@@ -631,7 +631,7 @@ class MyManager : public Manager, public Timer, public EventHandler
}
else
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Lookup complete for " + request->name);
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Lookup complete for " + request->question.name);
ServerInstance->stats.DnsGood++;
request->OnLookupComplete(&recv_packet);
this->AddCache(recv_packet);
@@ -815,7 +815,7 @@ class ModuleDNS : public Module
if (req->creator == mod)
{
- Query rr(*req);
+ Query rr(req->question);
rr.error = ERROR_UNLOADED;
req->OnError(&rr);
diff --git a/src/coremods/core_hostname_lookup.cpp b/src/coremods/core_hostname_lookup.cpp
index cbd80931c..b9adc9c2e 100644
--- a/src/coremods/core_hostname_lookup.cpp
+++ b/src/coremods/core_hostname_lookup.cpp
@@ -37,21 +37,6 @@ class UserResolver : public DNS::Request
*/
const bool fwd;
- const DNS::ResourceRecord* FindAnswerOfType(const DNS::Query* response, DNS::QueryType qtype)
- {
- for (std::vector<DNS::ResourceRecord>::const_iterator it = response->answers.begin(); it != response->answers.end(); ++it)
- {
- const DNS::ResourceRecord& rr = *it;
-
- if (rr.type == qtype)
- {
- return &rr;
- }
- }
-
- return NULL;
- }
-
public:
/** Create a resolver.
* @param mgr DNS Manager
@@ -80,10 +65,10 @@ class UserResolver : public DNS::Request
return;
}
- const DNS::ResourceRecord* ans_record = FindAnswerOfType(r, this->type);
+ const DNS::ResourceRecord* ans_record = r->FindAnswerOfType(this->question.type);
if (ans_record == NULL)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "DNS result for %s: no record of type %d", uuid.c_str(), this->type);
+ OnError(r);
return;
}
diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp
index 3d04a5085..6682b8dbe 100644
--- a/src/modules/m_spanningtree/resolvers.cpp
+++ b/src/modules/m_spanningtree/resolvers.cpp
@@ -42,7 +42,12 @@ ServernameResolver::ServernameResolver(DNS::Manager* mgr, const std::string& hos
void ServernameResolver::OnLookupComplete(const DNS::Query *r)
{
- const DNS::ResourceRecord &ans_record = r->answers[0];
+ const DNS::ResourceRecord* const ans_record = r->FindAnswerOfType(this->question.type);
+ if (!ans_record)
+ {
+ OnError(r);
+ return;
+ }
/* Initiate the connection, now that we have an IP to use.
* Passing a hostname directly to BufferedSocket causes it to
@@ -51,7 +56,7 @@ void ServernameResolver::OnLookupComplete(const DNS::Query *r)
TreeServer* CheckDupe = Utils->FindServer(MyLink->Name.c_str());
if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
{
- TreeSocket* newsocket = new TreeSocket(MyLink, myautoconnect, ans_record.rdata);
+ TreeSocket* newsocket = new TreeSocket(MyLink, myautoconnect, ans_record->rdata);
if (newsocket->GetFd() > -1)
{
/* We're all OK */