1
0
mirror of https://github.com/anope/anope.git synced 2026-07-08 05:23:13 +02:00

Cleanup DNS requests when modules are unloaded, fixes unloading m_dnsbl during the middle of queries

This commit is contained in:
Adam
2010-09-14 18:24:14 -04:00
parent 630f3815ce
commit e7ac33fd62
5 changed files with 28 additions and 15 deletions
+6 -1
View File
@@ -48,6 +48,7 @@ enum DNSError
class DNSRequestTimeout; // Forward declarations
struct DNSRecord;
class Module;
/** The request
*/
@@ -57,12 +58,14 @@ class DNSRequest
DNSRequestTimeout *timeout;
public:
Module *creator;
/* Address we're looking up */
Anope::string address;
/* QueryType, A, AAAA, PTR etc */
QueryType QT;
DNSRequest(const Anope::string &addr, QueryType qt, bool cache = false);
DNSRequest(const Anope::string &addr, QueryType qt, bool cache = false, Module *c = NULL);
virtual ~DNSRequest();
@@ -158,6 +161,8 @@ class DNSManager : public Timer
void AddCache(DNSRecord *rr);
bool CheckCache(DNSRequest *request);
void Tick(time_t now);
void Cleanup(Module *mod);
};
/** A DNS timeout, one is made for every DNS request to detect timeouts
-11
View File
@@ -1294,17 +1294,6 @@ class service_reference : public dynamic_reference<T>
inline T *operator->()
{
if (this->invalid)
{
this->invalid = false;
this->ref = NULL;
}
if (!this->ref)
{
this->ref = static_cast<T *>(ModuleManager::GetService(this->name));
if (this->ref)
this->ref->AddReference(this);
}
return this->ref;
}
};
+2 -2
View File
@@ -23,7 +23,7 @@ class DNSBLResolver : public DNSRequest
bool add_to_akill;
public:
DNSBLResolver(User *u, const Blacklist &b, const Anope::string &host, bool add_akill) : DNSRequest(host, DNS_QUERY_A, true), user(u), blacklist(b), add_to_akill(add_akill) { }
DNSBLResolver(Module *c, User *u, const Blacklist &b, const Anope::string &host, bool add_akill) : DNSRequest(host, DNS_QUERY_A, true, c), user(u), blacklist(b), add_to_akill(add_akill) { }
void OnLookupComplete(const DNSRecord *)
{
@@ -120,7 +120,7 @@ class ModuleDNSBL : public Module
try
{
Anope::string dnsbl_host = user_ip.addr() + "." + b.name;
new DNSBLResolver(u, b, dnsbl_host, this->add_to_akill);
new DNSBLResolver(this, u, b, dnsbl_host, this->add_to_akill);
}
catch (const SocketException &ex)
{
+17 -1
View File
@@ -7,7 +7,7 @@ static inline unsigned short GetRandomID()
return random();
}
DNSRequest::DNSRequest(const Anope::string &addr, QueryType qt, bool cache) : address(addr), QT(qt)
DNSRequest::DNSRequest(const Anope::string &addr, QueryType qt, bool cache, Module *c) : address(addr), QT(qt), creator(c)
{
if (!DNSEngine)
DNSEngine = new DNSManager();
@@ -531,6 +531,22 @@ void DNSManager::Tick(time_t now)
}
}
void DNSManager::Cleanup(Module *mod)
{
for (std::map<short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end;)
{
short id = it->first;
DNSRequest *req = it->second;
++it;
if (req->creator && req->creator == mod)
{
delete req;
this->requests.erase(id);
}
}
}
DNSRequestTimeout::DNSRequestTimeout(DNSRequest *r, time_t timeout) : Timer(timeout), request(r)
{
this->done = false;
+3
View File
@@ -240,6 +240,9 @@ int ModuleManager::UnloadModule(Module *m, User *u)
FOREACH_MOD(I_OnModuleUnload, OnModuleUnload(u, m));
if (DNSEngine)
DNSEngine->Cleanup(m);
DeleteModule(m);
return MOD_ERR_OK;
}