diff options
author | Adam <Adam@anope.org> | 2014-05-20 21:10:49 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2014-05-20 21:16:00 -0400 |
commit | 866f3f32ab3713e9867747f150df3698e456744e (patch) | |
tree | 20aabb18d88ee72a4fd412e17ebe30585496bd97 /modules/m_dnsbl.cpp | |
parent | 20ce170024779aebbc1462146905c976836a552f (diff) |
Speed up akill xline checks
Cache xline nick, user, host, etc instead of rebuilding it everytime its
requested. Store users ip in sockaddr form and not string form to
prevent having to rebuild sockaddrs when checking xlines.
Also do not try to convert empty config values in Config::Get as this
can be rather common if a non string configuration value is not set, and
the cost of the ConvertException is great.
Diffstat (limited to 'modules/m_dnsbl.cpp')
-rw-r--r-- | modules/m_dnsbl.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/modules/m_dnsbl.cpp b/modules/m_dnsbl.cpp index b19a66ea4..1c10b09d5 100644 --- a/modules/m_dnsbl.cpp +++ b/modules/m_dnsbl.cpp @@ -54,18 +54,18 @@ class DNSBLResolver : public Request record_reason = this->blacklist.replies[result]; } - Anope::string reason = this->blacklist.reason; + Anope::string reason = this->blacklist.reason, addr = user->ip.addr(); reason = reason.replace_all_cs("%n", user->nick); reason = reason.replace_all_cs("%u", user->GetIdent()); reason = reason.replace_all_cs("%g", user->realname); reason = reason.replace_all_cs("%h", user->host); - reason = reason.replace_all_cs("%i", user->ip); + reason = reason.replace_all_cs("%i", addr); reason = reason.replace_all_cs("%r", record_reason); reason = reason.replace_all_cs("%N", Config->GetBlock("networkinfo")->Get<const Anope::string>("networkname")); BotInfo *OperServ = Config->GetClient("OperServ"); - Log(creator, "dnsbl", OperServ) << user->GetMask() << " (" << user->ip << ") appears in " << this->blacklist.name; - XLine *x = new XLine("*@" + user->ip, OperServ ? OperServ->nick : "m_dnsbl", Anope::CurTime + this->blacklist.bantime, reason, XLineManager::GenerateUID()); + Log(creator, "dnsbl", OperServ) << user->GetMask() << " (" << addr << ") appears in " << this->blacklist.name; + XLine *x = new XLine("*@" + addr, OperServ ? OperServ->nick : "m_dnsbl", Anope::CurTime + this->blacklist.bantime, reason, XLineManager::GenerateUID()); if (this->add_to_akill && akills) { akills->AddXLine(x); @@ -130,22 +130,21 @@ class ModuleDNSBL : public Module return; /* At this time we only support IPv4 */ - sockaddrs user_ip; - user_ip.pton(AF_INET, user->ip); - if (!user_ip.valid()) + if (!user->ip.valid() || user->ip.sa.sa_family != AF_INET) /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */ return; - const unsigned long &ip = user_ip.sa4.sin_addr.s_addr; + const unsigned long &ip = user->ip.sa4.sin_addr.s_addr; unsigned long reverse_ip = (ip << 24) | ((ip & 0xFF00) << 8) | ((ip & 0xFF0000) >> 8) | (ip >> 24); - user_ip.sa4.sin_addr.s_addr = reverse_ip; + sockaddrs reverse = user->ip; + reverse.sa4.sin_addr.s_addr = reverse_ip; for (unsigned i = 0; i < this->blacklists.size(); ++i) { const Blacklist &b = this->blacklists[i]; - Anope::string dnsbl_host = user_ip.addr() + "." + b.name; + Anope::string dnsbl_host = reverse.addr() + "." + b.name; DNSBLResolver *res = NULL; try { |