summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authormichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>2014-01-14 18:10:10 +0000
committermichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>2014-01-14 18:10:10 +0000
commitf6ce20726b517875f98a2238fe247635626cfd40 (patch)
treeb57a726aee93004681718abfba26a771f9a5ae77 /modules
parentc45beadd12c70ddb0d43a99a3c1ac66c8f965533 (diff)
- Greatly speedup k-/g-line lookup. Instead of testing every single client against
every single k-/g-line just check the just added ban against connected clients. - Renamed ban_them() to conf_try_ban() - conf_try_ban() removed exemption notices that are now redundant - hostmask.c:parse_netmask(): optimize for the ipv4 case git-svn-id: svn://svn.ircd-hybrid.org/svnroot/ircd-hybrid/branches/8.1.x@2815 82007160-df01-0410-b94d-b575c5fd34c7
Diffstat (limited to 'modules')
-rw-r--r--modules/m_gline.c38
-rw-r--r--modules/m_kline.c38
2 files changed, 72 insertions, 4 deletions
diff --git a/modules/m_gline.c b/modules/m_gline.c
index 7e0ed6b..8326d03 100644
--- a/modules/m_gline.c
+++ b/modules/m_gline.c
@@ -50,6 +50,41 @@
#define GLINE_PLACED 1
+static void
+check_gline(struct AddressRec *arec)
+{
+ dlink_node *ptr = NULL, *ptr_next = NULL;
+
+ DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
+ {
+ struct Client *client_p = ptr->data;
+
+ if (IsDead(client_p))
+ continue;
+
+ if (match(arec->username, client_p->username))
+ continue;
+
+ switch (arec->masktype)
+ {
+ case HM_IPV4:
+ if (client_p->localClient->aftype == AF_INET)
+ if (match_ipv4(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
+ conf_try_ban(client_p, arec->conf);
+ break;
+ case HM_IPV6:
+ if (client_p->localClient->aftype == AF_INET6)
+ if (match_ipv6(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
+ conf_try_ban(client_p, arec->conf);
+ break;
+ default: /* HM_HOST */
+ if (!match(arec->Mask.hostname, client_p->host))
+ conf_try_ban(client_p, arec->conf);
+ break;
+ }
+ }
+}
+
/*! \brief Adds a GLINE to the configuration subsystem.
*
* \param source_p Operator requesting gline
@@ -80,8 +115,7 @@ set_local_gline(const struct Client *source_p, const char *user,
ilog(LOG_TYPE_GLINE, "%s added G-Line for [%s@%s] [%s]",
get_oper_name(source_p), conf->user, conf->host, conf->reason);
- add_conf_by_address(CONF_GLINE, conf);
- rehashed_klines = 1;
+ check_gline(add_conf_by_address(CONF_GLINE, conf));
}
/*! \brief Removes a GLINE from the configuration subsystem.
diff --git a/modules/m_kline.c b/modules/m_kline.c
index 28ce68b..56c2de3 100644
--- a/modules/m_kline.c
+++ b/modules/m_kline.c
@@ -47,6 +47,41 @@
#include "memory.h"
+static void
+check_kline(struct AddressRec *arec)
+{
+ dlink_node *ptr = NULL, *ptr_next = NULL;
+
+ DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
+ {
+ struct Client *client_p = ptr->data;
+
+ if (IsDead(client_p))
+ continue;
+
+ if (match(arec->username, client_p->username))
+ continue;
+
+ switch (arec->masktype)
+ {
+ case HM_IPV4:
+ if (client_p->localClient->aftype == AF_INET)
+ if (match_ipv4(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
+ conf_try_ban(client_p, arec->conf);
+ break;
+ case HM_IPV6:
+ if (client_p->localClient->aftype == AF_INET6)
+ if (match_ipv6(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
+ conf_try_ban(client_p, arec->conf);
+ break;
+ default: /* HM_HOST */
+ if (!match(arec->Mask.hostname, client_p->host))
+ conf_try_ban(client_p, arec->conf);
+ break;
+ }
+ }
+}
+
/* apply_tkline()
*
* inputs -
@@ -88,8 +123,7 @@ m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
conf->setat = CurrentTime;
SetConfDatabase(conf);
- add_conf_by_address(CONF_KLINE, conf);
- rehashed_klines = 1;
+ check_kline(add_conf_by_address(CONF_KLINE, conf));
}
/* static int remove_tkline_match(const char *host, const char *user)