]> jfr.im git - irc/rqf/shadowircd.git/commitdiff
Show rejectcache/throttle in /testline output.
authorJilles Tjoelker <redacted>
Fri, 19 Dec 2008 18:24:12 +0000 (19:24 +0100)
committerJilles Tjoelker <redacted>
Fri, 19 Dec 2008 18:24:12 +0000 (19:24 +0100)
This adds more RPL_TESTLINE numerics with code '!'.
Different from the other results, the I/K line or
RESV will be shown as well.

include/reject.h
modules/m_testline.c
src/reject.c

index c6e27eedf063f8283bc76ba21fddfdc729fd7141..95e2c43d4573675f870611fa126f763f0b8fbea4 100644 (file)
 void init_reject(void);
 int check_reject(rb_fde_t *F, struct sockaddr *addr);
 void add_reject(struct Client *, const char *mask1, const char *mask2);
+int is_reject_ip(struct sockaddr *addr);
 void flush_reject(void);
 int remove_reject_ip(const char *ip);
 int remove_reject_mask(const char *mask1, const char *mask2);
 unsigned long delay_exit_length(void);
 
 int throttle_add(struct sockaddr *addr);
+int is_throttle_ip(struct sockaddr *addr);
 unsigned long throttle_size(void);
 
 
index 0bcba6ea3bc08b8f0bfab721380514f3e7952f76..215f48d9b2670ed82d3bd89fb4d7ed6f5b68c159 100644 (file)
@@ -39,6 +39,7 @@
 #include "numeric.h"
 #include "s_conf.h"
 #include "s_newconf.h"
+#include "reject.h"
 
 static int mo_testline(struct Client *, struct Client *, int, const char **);
 static int mo_testgecos(struct Client *, struct Client *, int, const char **);
@@ -69,6 +70,7 @@ mo_testline(struct Client *client_p, struct Client *source_p, int parc, const ch
        char *p;
        int host_mask;
        int type;
+       int duration;
 
        mask = LOCAL_COPY(parv[1]);
 
@@ -136,6 +138,21 @@ mo_testline(struct Client *client_p, struct Client *source_p, int parc, const ch
 
                        return 0;
                }
+               /* Otherwise, aconf is an exempt{} */
+               if(aconf == NULL &&
+                               (duration = is_reject_ip((struct sockaddr *)&ip)))
+                       sendto_one(source_p, form_str(RPL_TESTLINE),
+                                       me.name, source_p->name,
+                                       '!',
+                                       duration / 60,
+                                       host, "Reject cache");
+               if(aconf == NULL &&
+                               (duration = is_throttle_ip((struct sockaddr *)&ip)))
+                       sendto_one(source_p, form_str(RPL_TESTLINE),
+                                       me.name, source_p->name,
+                                       '!',
+                                       duration / 60,
+                                       host, "Throttled");
        }
 
        if (username != NULL)
index 6e226ca5b37be6759bb73f984d45e7bc6f05adfa..c9c7d455be3c1385577d8b6e0af06f814613a506 100644 (file)
@@ -211,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)
 {
@@ -312,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)
 {