]> jfr.im git - irc/freenode/syn.git/commitdiff
kline.c: handle CIDR klines
authorJanik Kleinhoff <redacted>
Sun, 20 Jan 2019 05:59:05 +0000 (05:59 +0000)
committerJanik Kleinhoff <redacted>
Sun, 20 Jan 2019 06:37:29 +0000 (06:37 +0000)
We could probably use a radix tree to hold CIDR k-lines and match much
more efficiently, but this will do fine for now.

Fixes #1.

kline.c

diff --git a/kline.c b/kline.c
index 00f2f315b10751621c3649186ab26c8cf7aef2ba..e951c60dbb45eb65ae1b3752484c250352af83e5 100644 (file)
--- a/kline.c
+++ b/kline.c
@@ -54,6 +54,8 @@ kline_t* _syn_find_kline(const char *user, const char *host)
         k = n->data;
         if (0 == match(k->host, host))
             return k;
+        if (0 == match_ips(k->host, host))
+            return k;
     }
     return NULL;
 }
@@ -86,7 +88,7 @@ static void syn_add_kline(const char *setter, const char *user, const char *host
         *p = '\0';
     }
 
-    if (strchr(k->host, '*') || strchr(k->host, '?'))
+    if (strchr(k->host, '*') || strchr(k->host, '?') || (strchr(k->host, '/') && valid_ip_or_mask(k->host)))
     {
         mowgli_node_t *n = mowgli_node_create();
         mowgli_node_add(k, n, &ircd_wildcard_klines);
@@ -188,7 +190,7 @@ static void _syn_vkline(const char *host, int duration, const char *reason, va_l
         *p = '\0';
     }
 
-    if (strchr(k->host, '*') || strchr(k->host, '?'))
+    if (strchr(k->host, '*') || strchr(k->host, '?') || (strchr(k->host, '/') && valid_ip_or_mask(k->host)))
     {
         mowgli_node_t *n = mowgli_node_create();
         mowgli_node_add(k, n, &ircd_wildcard_klines);