1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Throttles the connections of any users who try connect flood */
19 class ModuleConnectBan : public Module
23 unsigned int threshold;
24 unsigned int banduration;
25 unsigned int ipv4_cidr;
26 unsigned int ipv6_cidr;
28 ModuleConnectBan(InspIRCd* Me) : Module(Me)
30 Implementation eventlist[] = { I_OnUserConnect, I_OnGarbageCollect, I_OnRehash };
31 ServerInstance->Modules->Attach(eventlist, this, 3);
35 virtual ~ModuleConnectBan()
39 virtual Version GetVersion()
41 return Version("$Id$", VF_VENDOR,API_VERSION);
44 virtual void OnRehash(User* user, const std::string ¶meter)
46 ConfigReader Conf(ServerInstance);
49 ipv4_cidr = Conf.ReadInteger("connectban", "ipv4cidr", 0, true);
53 ipv6_cidr = Conf.ReadInteger("connectban", "ipv6cidr", 0, true);
57 threshold = Conf.ReadInteger("connectban", "threshold", 0, true);
62 duration = Conf.ReadValue("connectban", "duration", 0, true);
67 banduration = ServerInstance->Duration(duration);
70 virtual void OnUserConnect(User *u)
75 switch (u->GetProtocolFamily())
77 #ifdef SUPPORT_IP6LINKS
91 i = connects.find(u->GetCIDRMask(range));
93 if (i != connects.end())
97 if (i->second >= threshold)
99 // Create zline for set duration.
100 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), banduration, ServerInstance->Config->ServerName, "Connect flooding", u->GetCIDRMask(range));
101 if (ServerInstance->XLines->AddLine(zl,NULL))
102 ServerInstance->XLines->ApplyLines();
106 ServerInstance->SNO->WriteToSnoMask('x', "Connect flooding from IP range %s (%d)", u->GetCIDRMask(range), threshold);
112 connects[u->GetCIDRMask(range)] = 1;
116 virtual void OnGarbageCollect()
118 ServerInstance->Logs->Log("m_connectban",DEBUG, "Clearing map.");
123 MODULE_INIT(ModuleConnectBan)