X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/84bfb8ccb31b3ea5a083d0f51b249bba7e62a0b0..255130dde8eed921fea4b23786a5743fbd50cbda:/src/reject.c diff --git a/src/reject.c b/src/reject.c index 6e226ca..ab9163b 100644 --- a/src/reject.c +++ b/src/reject.c @@ -20,7 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA * - * $Id: reject.c 25119 2008-03-13 16:57:05Z androsyn $ */ #include "stdinc.h" @@ -211,6 +210,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 +336,43 @@ 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; +} + +void +flush_throttle(void) +{ + rb_dlink_node *ptr, *next; + rb_patricia_node_t *pnode; + throttle_t *t; + + RB_DLINK_FOREACH_SAFE(ptr, next, throttle_list.head) + { + pnode = ptr->data; + t = pnode->data; + + rb_dlinkDelete(ptr, &throttle_list); + rb_free(t); + rb_patricia_remove(throttle_tree, pnode); + } +} + static void throttle_expires(void *unused) {