summaryrefslogtreecommitdiff
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
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
-rw-r--r--include/client.h3
-rw-r--r--include/hostmask.h2
-rw-r--r--modules/m_gline.c38
-rw-r--r--modules/m_kline.c38
-rw-r--r--src/client.c49
-rw-r--r--src/hostmask.c8
6 files changed, 105 insertions, 33 deletions
diff --git a/include/client.h b/include/client.h
index f8affb4..92fbddc 100644
--- a/include/client.h
+++ b/include/client.h
@@ -36,6 +36,8 @@
#include "channel.h"
#include "s_auth.h"
+struct MaskItem;
+
/*
* status macros.
*/
@@ -461,6 +463,7 @@ extern struct split_nuh_item *find_accept(const char *, const char *,
extern void del_accept(struct split_nuh_item *, struct Client *);
extern void del_all_accepts(struct Client *);
extern void exit_client(struct Client *, struct Client *, const char *);
+extern void conf_try_ban(struct Client *, struct MaskItem *);
extern void check_conf_klines(void);
extern void client_init(void);
extern void dead_link_on_write(struct Client *, int);
diff --git a/include/hostmask.h b/include/hostmask.h
index a8dc7c1..2275c27 100644
--- a/include/hostmask.h
+++ b/include/hostmask.h
@@ -72,7 +72,7 @@ extern int match_ipv4(const struct irc_ssaddr *, const struct irc_ssaddr *, int)
extern void mask_addr(struct irc_ssaddr *, int);
extern void init_host_hash(void);
-extern void add_conf_by_address(const unsigned int, struct MaskItem *);
+extern struct AddressRec *add_conf_by_address(const unsigned int, struct MaskItem *);
extern void delete_one_address_conf(const char *, struct MaskItem *);
extern void clear_out_address_conf(void);
extern void hostmask_expire_temporary(void);
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)
diff --git a/src/client.c b/src/client.c
index 4350e14..f79685f 100644
--- a/src/client.c
+++ b/src/client.c
@@ -76,7 +76,6 @@ static dlink_node *eac_next; /* next aborted client to exit */
static void check_pings_list(dlink_list *);
static void check_unknowns_list(void);
-static void ban_them(struct Client *, struct MaskItem *);
/* client_init()
@@ -358,7 +357,7 @@ check_conf_klines(void)
if (conf->type == CONF_EXEMPT)
continue;
- ban_them(client_p, conf);
+ conf_try_ban(client_p, conf);
continue; /* and go examine next fd/client_p */
}
@@ -368,16 +367,7 @@ check_conf_klines(void)
CONF_GLINE, client_p->localClient->aftype,
client_p->username, NULL, 1)))
{
- if (IsExemptKline(client_p) ||
- IsExemptGline(client_p))
- {
- sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
- "GLINE over-ruled for %s, client is %sline_exempt",
- get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
- continue;
- }
-
- ban_them(client_p, conf);
+ conf_try_ban(client_p, conf);
/* and go examine next fd/client_p */
continue;
}
@@ -387,22 +377,14 @@ check_conf_klines(void)
CONF_KLINE, client_p->localClient->aftype,
client_p->username, NULL, 1)))
{
- if (IsExemptKline(client_p))
- {
- sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
- "KLINE over-ruled for %s, client is kline_exempt",
- get_client_name(client_p, HIDE_IP));
- continue;
- }
-
- ban_them(client_p, conf);
+ conf_try_ban(client_p, conf);
continue;
}
if ((conf = find_matching_name_conf(CONF_XLINE, client_p->info,
NULL, NULL, 0)))
{
- ban_them(client_p, conf);
+ conf_try_ban(client_p, conf);
continue;
}
}
@@ -424,15 +406,15 @@ check_conf_klines(void)
}
/*
- * ban_them
+ * conf_try_ban
*
* inputs - pointer to client to ban
* - pointer to MaskItem
* output - NONE
* side effects - given client_p is banned
*/
-static void
-ban_them(struct Client *client_p, struct MaskItem *conf)
+void
+conf_try_ban(struct Client *client_p, struct MaskItem *conf)
{
const char *user_reason = NULL; /* What is sent to user */
const char *type_string = NULL;
@@ -444,12 +426,29 @@ ban_them(struct Client *client_p, struct MaskItem *conf)
switch (conf->type)
{
case CONF_KLINE:
+ if (IsExemptKline(client_p))
+ {
+ sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
+ "KLINE over-ruled for %s, client is kline_exempt",
+ get_client_name(client_p, HIDE_IP));
+ return;
+ }
+
type_string = kline_string;
break;
case CONF_DLINE:
type_string = dline_string;
break;
case CONF_GLINE:
+ if (IsExemptKline(client_p) ||
+ IsExemptGline(client_p))
+ {
+ sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
+ "GLINE over-ruled for %s, client is %sline_exempt",
+ get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
+ return;
+ }
+
type_string = gline_string;
break;
case CONF_XLINE:
diff --git a/src/hostmask.c b/src/hostmask.c
index 4cf0845..96b85ee 100644
--- a/src/hostmask.c
+++ b/src/hostmask.c
@@ -247,12 +247,12 @@ try_parse_v4_netmask(const char *text, struct irc_ssaddr *addr, int *b)
int
parse_netmask(const char *text, struct irc_ssaddr *addr, int *b)
{
+ if (strchr(text, '.'))
+ return try_parse_v4_netmask(text, addr, b);
#ifdef IPV6
if (strchr(text, ':'))
return try_parse_v6_netmask(text, addr, b);
#endif
- if (strchr(text, '.'))
- return try_parse_v4_netmask(text, addr, b);
return HM_HOST;
}
@@ -630,7 +630,7 @@ find_dline_conf(struct irc_ssaddr *addr, int aftype)
* Output: None
* Side-effects: Adds this entry to the hash table.
*/
-void
+struct AddressRec *
add_conf_by_address(const unsigned int type, struct MaskItem *conf)
{
const char *address;
@@ -674,6 +674,8 @@ add_conf_by_address(const unsigned int type, struct MaskItem *conf)
dlinkAdd(arec, &arec->node, &atable[get_mask_hash(address)]);
break;
}
+
+ return arec;
}
/* void delete_one_address(const char*, struct MaskItem*)