]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/reject.c
Show rejectcache/throttle in /testline output.
[irc/rqf/shadowircd.git] / src / reject.c
index 87ec31844e79470053daa23ccedea9d54171b456..c9c7d455be3c1385577d8b6e0af06f814613a506 100644 (file)
@@ -36,7 +36,6 @@
 #include "match.h"
 #include "hash.h"
 
-static rb_patricia_tree_t *global_tree;
 static rb_patricia_tree_t *reject_tree;
 static rb_dlink_list delay_exit;
 static rb_dlink_list reject_list;
@@ -123,6 +122,25 @@ init_reject(void)
        rb_event_add("throttle_expires", throttle_expires, NULL, 10);
 }
 
+unsigned long
+throttle_size(void)
+{
+       unsigned long count;
+       rb_dlink_node *ptr;
+       rb_patricia_node_t *pnode;
+       throttle_t *t;
+
+       count = 0;
+       RB_DLINK_FOREACH(ptr, throttle_list.head)
+       {
+               pnode = ptr->data;
+               t = pnode->data;
+               if (t->count > ConfigFileEntry.throttle_count)
+                       count++;
+       }
+
+       return count;
+}
 
 void
 add_reject(struct Client *client_p, const char *mask1, const char *mask2)
@@ -193,6 +211,31 @@ check_reject(rb_fde_t *F, struct sockaddr *addr)
        return 0;
 }
 
+int
+is_reject_ip(struct sockaddr *addr)
+{
+       rb_patricia_node_t *pnode;
+       reject_t *rdata;
+       int duration;
+
+       /* Reject is disabled */
+       if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0)
+               return 0;
+               
+       pnode = rb_match_ip(reject_tree, addr);
+       if(pnode != NULL)
+       {
+               rdata = pnode->data;
+
+               if(rdata->count > (unsigned long)ConfigFileEntry.reject_after_count)
+               {
+                       duration = rdata->time + ConfigFileEntry.reject_duration - rb_current_time();
+                       return duration > 0 ? duration : 1;
+               }
+       }       
+       return 0;
+}
+
 void 
 flush_reject(void)
 {
@@ -270,8 +313,10 @@ throttle_add(struct sockaddr *addr)
                t = pnode->data;
 
                if(t->count > ConfigFileEntry.throttle_count)
-                       return 1;                       
-
+               {
+                       ServerStats.is_thr++;
+                       return 1;
+               }
                /* Stop penalizing them after they've been throttled */
                t->last = rb_current_time();
                t->count++;
@@ -292,6 +337,25 @@ throttle_add(struct sockaddr *addr)
        return 0;
 }
 
+int
+is_throttle_ip(struct sockaddr *addr)
+{
+       throttle_t *t;
+       rb_patricia_node_t *pnode;
+       int duration;
+
+       if((pnode = rb_match_ip(throttle_tree, addr)) != NULL)
+       {
+               t = pnode->data;
+               if(t->count > ConfigFileEntry.throttle_count)
+               {
+                       duration = t->last + ConfigFileEntry.throttle_duration - rb_current_time();
+                       return duration > 0 ? duration : 1;
+               }
+       }
+       return 0;
+}
+
 static void
 throttle_expires(void *unused)
 {