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 /* $ModDesc: Throttles the connections of any users who try connect flood */
25 class ModuleConnectBan : public Module
29 unsigned int threshold;
30 unsigned int banduration;
31 unsigned int ipv4_cidr;
32 unsigned int ipv6_cidr;
35 Implementation eventlist[] = { I_OnUserConnect, I_OnGarbageCollect, I_OnRehash };
36 ServerInstance->Modules->Attach(eventlist, this, 3);
40 virtual ~ModuleConnectBan()
44 virtual Version GetVersion()
46 return Version("Throttles the connections of any users who try connect flood", VF_VENDOR);
49 virtual void OnRehash(User* user)
54 ipv4_cidr = Conf.ReadInteger("connectban", "ipv4cidr", 0, true);
58 ipv6_cidr = Conf.ReadInteger("connectban", "ipv6cidr", 0, true);
62 threshold = Conf.ReadInteger("connectban", "threshold", 0, true);
67 duration = Conf.ReadValue("connectban", "duration", 0, true);
72 banduration = ServerInstance->Duration(duration);
75 virtual void OnUserConnect(LocalUser *u)
80 switch (u->client_sa.sa.sa_family)
90 irc::sockets::cidr_mask mask(u->client_sa, range);
91 i = connects.find(mask);
93 if (i != connects.end())
97 if (i->second >= threshold)
99 // Create zline for set duration.
100 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());
101 if (ServerInstance->XLines->AddLine(zl,NULL))
102 ServerInstance->XLines->ApplyLines();
106 ServerInstance->SNO->WriteGlobalSno('x',"Module m_connectban added Z:line on *@%s to expire on %s: Connect flooding",
107 mask.str().c_str(), ServerInstance->TimeString(zl->expiry).c_str());
108 ServerInstance->SNO->WriteGlobalSno('a', "Connect flooding from IP range %s (%d)", mask.str().c_str(), threshold);
118 virtual void OnGarbageCollect()
120 ServerInstance->Logs->Log("m_connectban",DEBUG, "Clearing map.");
125 MODULE_INIT(ModuleConnectBan)