cache_map cache;
irc::sockets::sockaddrs myserver;
+ bool unloading;
/** Maximum number of entries in cache
*/
DNS::Request* requests[MAX_REQUEST_ID+1];
MyManager(Module* c) : Manager(c), Timer(5*60, true)
+ , unloading(false)
{
for (unsigned int i = 0; i <= MAX_REQUEST_ID; ++i)
requests[i] = NULL;
~MyManager()
{
+ // Ensure Process() will fail for new requests
+ unloading = true;
+
for (unsigned int i = 0; i <= MAX_REQUEST_ID; ++i)
{
DNS::Request* request = requests[i];
if (!request)
continue;
- Query rr(*request);
+ Query rr(request->question);
rr.error = ERROR_UNKNOWN;
request->OnError(&rr);
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());
+ if ((unloading) || (req->creator->dying))
+ throw Exception("Module is being unloaded");
+
+ 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;
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));
}
// 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");
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");
}
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);
if (req->creator == mod)
{
- Query rr(*req);
+ Query rr(req->question);
rr.error = ERROR_UNLOADED;
req->OnError(&rr);