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

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.
This commit is contained in:
Adam
2014-05-20 21:10:49 -04:00
parent 20ce170024
commit 866f3f32ab
20 changed files with 115 additions and 112 deletions
+2 -2
View File
@@ -502,7 +502,7 @@ class OSDefcon : public Module
if (DConfig.sessionlimit <= 0 || !session_service)
return;
Session *session = session_service->FindSession(u->ip);
Session *session = session_service->FindSession(u->ip.addr());
Exception *exception = session_service->FindException(u);
if (DConfig.Check(DEFCON_REDUCE_SESSION) && !exception)
@@ -511,7 +511,7 @@ class OSDefcon : public Module
{
if (!DConfig.sle_reason.empty())
{
Anope::string message = DConfig.sle_reason.replace_all_cs("%IP%", u->ip);
Anope::string message = DConfig.sle_reason.replace_all_cs("%IP%", u->ip.addr());
u->SendMessage(OperServ, message);
}
if (!DConfig.sle_detailsloc.empty())
+1 -1
View File
@@ -180,7 +180,7 @@ class CommandOSUserList : public Command
if (!pattern.empty())
{
Anope::string mask = u2->nick + "!" + u2->GetIdent() + "@" + u2->GetDisplayedHost(), mask2 = u2->nick + "!" + u2->GetIdent() + "@" + u2->host, mask3 = u2->nick + "!" + u2->GetIdent() + "@" + (!u2->ip.empty() ? u2->ip : u2->host);
Anope::string mask = u2->nick + "!" + u2->GetIdent() + "@" + u2->GetDisplayedHost(), mask2 = u2->nick + "!" + u2->GetIdent() + "@" + u2->host, mask3 = u2->nick + "!" + u2->GetIdent() + "@" + u2->ip.addr();
if (!Anope::Match(mask, pattern) && !Anope::Match(mask2, pattern) && !Anope::Match(mask3, pattern))
continue;
if (!modes.empty())
+7 -7
View File
@@ -64,10 +64,10 @@ class MySessionService : public SessionService
for (std::vector<Exception *>::const_iterator it = this->Exceptions->begin(), it_end = this->Exceptions->end(); it != it_end; ++it)
{
Exception *e = *it;
if (Anope::Match(u->host, e->mask) || Anope::Match(u->ip, e->mask))
if (Anope::Match(u->host, e->mask) || Anope::Match(u->ip.addr(), e->mask))
return e;
if (cidr(e->mask).match(sockaddrs(u->ip)))
if (cidr(e->mask).match(u->ip))
return e;
}
return NULL;
@@ -109,9 +109,9 @@ class MySessionService : public SessionService
return NULL;
}
SessionMap::iterator FindSessionIterator(const Anope::string &ip)
SessionMap::iterator FindSessionIterator(const sockaddrs &ip)
{
cidr c(ip, ip.find(':') != Anope::string::npos ? ipv6_cidr : ipv4_cidr);
cidr c(ip, ip.ipv6() ? ipv6_cidr : ipv4_cidr);
if (!c.valid())
return this->Sessions.end();
return this->Sessions.find(c);
@@ -668,7 +668,7 @@ class OSSession : public Module
if (u->Quitting() || !session_limit || exempt || !u->server || u->server->IsULined())
return;
cidr u_ip(u->ip, u->ip.find(':') != Anope::string::npos ? ipv6_cidr : ipv4_cidr);
cidr u_ip(u->ip, u->ip.ipv6() ? ipv6_cidr : ipv4_cidr);
if (!u_ip.valid())
return;
@@ -705,7 +705,7 @@ class OSSession : public Module
{
if (!sle_reason.empty())
{
Anope::string message = sle_reason.replace_all_cs("%IP%", u->ip);
Anope::string message = sle_reason.replace_all_cs("%IP%", u->ip.addr());
u->SendMessage(OperServ, message);
}
if (!sle_detailsloc.empty())
@@ -729,7 +729,7 @@ class OSSession : public Module
}
else
{
session = new Session(u->ip, u->ip.find(':') != Anope::string::npos ? ipv6_cidr : ipv4_cidr);
session = new Session(u->ip, u->ip.ipv6() ? ipv6_cidr : ipv4_cidr);
}
}
+1 -1
View File
@@ -122,7 +122,7 @@ class ModuleSQLAuthentication : public Module
if (u)
{
q.SetValue("n", u->nick);
q.SetValue("i", u->ip);
q.SetValue("i", u->ip.addr());
}
else
{
+1 -1
View File
@@ -135,7 +135,7 @@ class ModuleSQLOper : public Module
SQL::Query q(this->query);
q.SetValue("a", u->Account()->display);
q.SetValue("i", u->ip);
q.SetValue("i", u->ip.addr());
this->SQL->Run(new SQLOperResult(this, u), q);
+1 -1
View File
@@ -95,7 +95,7 @@ void IRC2SQL::OnUserConnect(User *u, bool &exempt)
query.SetValue("vhost", u->vhost);
query.SetValue("chost", u->chost);
query.SetValue("realname", u->realname);
query.SetValue("ip", u->ip);
query.SetValue("ip", u->ip.addr());
query.SetValue("ident", u->GetIdent());
query.SetValue("vident", u->GetVIdent());
query.SetValue("secure", u->HasMode("SSL") || u->HasExt("ssl") ? "Y" : "N");
+9 -10
View File
@@ -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
{
+2 -4
View File
@@ -334,9 +334,7 @@ class ModuleProxyScan : 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;
@@ -364,7 +362,7 @@ class ModuleProxyScan : public Module
con = new SOCKS5ProxyConnect(p, p.ports[k]);
else
continue;
con->Connect(user->ip, p.ports[k]);
con->Connect(user->ip.addr(), p.ports[k]);
}
catch (const SocketException &ex)
{
+1 -2
View File
@@ -212,8 +212,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
request.reply("vhost", iface->Sanitize(u->vhost));
if (!u->chost.empty())
request.reply("chost", iface->Sanitize(u->chost));
if (!u->ip.empty())
request.reply("ip", u->ip);
request.reply("ip", u->ip.addr());
request.reply("timestamp", stringify(u->timestamp));
request.reply("signon", stringify(u->signon));
if (u->Account())
+3 -6
View File
@@ -53,13 +53,10 @@ class SGLineManager : public XLineManager
if (!x->GetReal().empty() && !Anope::Match(u->realname, x->GetReal()))
return false;
if (x->GetHost().find('/') != Anope::string::npos)
{
if (cidr(x->GetHost()).match(sockaddrs(u->ip)))
return true;
}
if (x->c && x->c->match(u->ip))
return true;
if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost()) || Anope::Match(u->ip, x->GetHost()))
if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost()) || Anope::Match(u->ip.addr(), x->GetHost()))
return true;
return false;