2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 class ModuleConnectBan : public Module
26 unsigned int threshold;
27 unsigned int banduration;
28 unsigned int ipv4_cidr;
29 unsigned int ipv6_cidr;
32 Version GetVersion() CXX11_OVERRIDE
34 return Version("Throttles the connections of IP ranges who try to connect flood.", VF_VENDOR);
37 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
39 ConfigTag* tag = ServerInstance->Config->ConfValue("connectban");
41 ipv4_cidr = tag->getInt("ipv4cidr", 32, 1, 32);
42 ipv6_cidr = tag->getInt("ipv6cidr", 128, 1, 128);
43 threshold = tag->getInt("threshold", 10, 1);
44 banduration = tag->getDuration("duration", 10*60, 1);
47 void OnSetUserIP(LocalUser* u) CXX11_OVERRIDE
55 switch (u->client_sa.sa.sa_family)
65 irc::sockets::cidr_mask mask(u->client_sa, range);
66 i = connects.find(mask);
68 if (i != connects.end())
72 if (i->second >= threshold)
74 // Create zline for set duration.
75 ZLine* zl = new ZLine(ServerInstance->Time(), banduration, ServerInstance->Config->ServerName, "Your IP range has been attempting to connect too many times in too short a duration. Wait a while, and you will be able to connect.", mask.str());
76 if (!ServerInstance->XLines->AddLine(zl, NULL))
81 ServerInstance->XLines->ApplyLines();
82 std::string maskstr = mask.str();
83 std::string timestr = InspIRCd::TimeString(zl->expiry);
84 ServerInstance->SNO->WriteGlobalSno('x',"Module m_connectban added Z:line on *@%s to expire on %s: Connect flooding",
85 maskstr.c_str(), timestr.c_str());
86 ServerInstance->SNO->WriteGlobalSno('a', "Connect flooding from IP range %s (%d)", maskstr.c_str(), threshold);
96 void OnGarbageCollect()
98 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Clearing map.");
103 MODULE_INIT(ModuleConnectBan)