summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2019-10-25 09:26:18 +0100
committerPeter Powell <petpow@saberuk.com>2019-10-25 09:35:15 +0100
commit23d0ffcddeffcc719c7e7f5fbb1e9d851a46b598 (patch)
tree1717d959cda0bba17e1f82b2840e2c6c5965a64d /src/modules
parent96925ce0e83e6cdb75a2cb66d9278b8c07b419e1 (diff)
Extract connectban's range checking code to a function.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_connectban.cpp35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp
index 9ce583063..12b123498 100644
--- a/src/modules/m_connectban.cpp
+++ b/src/modules/m_connectban.cpp
@@ -30,6 +30,27 @@ class ModuleConnectBan : public Module
unsigned int ipv6_cidr;
std::string banmessage;
+ unsigned char GetRange(LocalUser* user)
+ {
+ int family = user->client_sa.family();
+ switch (family)
+ {
+ case AF_INET:
+ return ipv4_cidr;
+
+ case AF_INET6:
+ return ipv6_cidr;
+
+ case AF_UNIX:
+ // Ranges for UNIX sockets are ignored entirely.
+ return 0;
+ }
+
+ // If we have reached this point then we have encountered a bug.
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "BUG: ModuleConnectBan::GetRange(): socket type %d is unknown!", family);
+ return 0;
+ }
+
public:
Version GetVersion() CXX11_OVERRIDE
{
@@ -52,19 +73,7 @@ class ModuleConnectBan : public Module
if (u->exempt)
return;
- unsigned char range = 32;
-
- switch (u->client_sa.family())
- {
- case AF_INET6:
- range = ipv6_cidr;
- break;
- case AF_INET:
- range = ipv4_cidr;
- break;
- }
-
- irc::sockets::cidr_mask mask(u->client_sa, range);
+ irc::sockets::cidr_mask mask(u->client_sa, GetRange(u));
ConnectMap::iterator i = connects.find(mask);
if (i != connects.end())