Forward port IPCHECK_CLONE_LIMIT, IPCHECK_CLONE_PERIOD,
[ircu2.10.12-pk.git] / ircd / IPcheck.c
index 439d60e51fe151cac49c21a1c5929f83a3d620c7..8e9e353201a35f869ec0d5ba5ccaf2e7b3afb033 100644 (file)
  * This file should be edited in a window with a width of 141 characters
  * ick
  */
+#include "config.h"
+
 #include "IPcheck.h"
 #include "client.h"
 #include "ircd.h"
 #include "msg.h"
 #include "numnicks.h"       /* NumNick, NumServ (GODMODE) */
 #include "ircd_alloc.h"
+#include "ircd_events.h"
+#include "ircd_features.h"
 #include "s_debug.h"        /* Debug */
 #include "s_user.h"         /* TARGET_DELAY */
 #include "send.h"
 
 #include <assert.h>
-
+#include <string.h>
 
 struct IPTargetEntry {
   int           count;
@@ -61,14 +65,16 @@ struct IPRegistryEntry {
 #define NOW ((unsigned short)(CurrentTime & MASK_16))
 #define CONNECTED_SINCE(x) (NOW - (x))
 
-#define IPCHECK_CLONE_LIMIT 4
-#define IPCHECK_CLONE_PERIOD 40
-#define IPCHECK_CLONE_DELAY 600
+#define IPCHECK_CLONE_LIMIT feature_int(FEAT_IPCHECK_CLONE_LIMIT)
+#define IPCHECK_CLONE_PERIOD feature_int(FEAT_IPCHECK_CLONE_PERIOD)
+#define IPCHECK_CLONE_DELAY feature_int(FEAT_IPCHECK_CLONE_DELAY)
 
 
 static struct IPRegistryEntry* hashTable[IP_REGISTRY_TABLE_SIZE];
 static struct IPRegistryEntry* freeList = 0;
 
+static struct Timer expireTimer;
+
 static unsigned int ip_registry_hash(unsigned int ip)
 {
   return ((ip >> 16) ^ ip) & (IP_REGISTRY_TABLE_SIZE - 1);
@@ -166,15 +172,16 @@ static void ip_registry_expire_entry(struct IPRegistryEntry* entry)
   }
 }
 
-/*
- * ip_registry_expire
- */
-static void ip_registry_expire()
+/* Callback to run an expiry of the IPcheck registry */
+static void ip_registry_expire(struct Event* ev)
 {
   int i;
   struct IPRegistryEntry* entry;
   struct IPRegistryEntry* entry_next;
 
+  assert(ET_EXPIRE == ev_type(ev));
+  assert(0 != ev_timer(ev));
+
   for (i = 0; i < IP_REGISTRY_TABLE_SIZE; ++i) {
     for (entry = hashTable[i]; entry; entry = entry_next) {
       entry_next = entry->next;
@@ -184,6 +191,16 @@ static void ip_registry_expire()
   }
 }
 
+/*
+ * IPcheck_init()
+ *
+ * Initializes the registry timer
+ */
+void IPcheck_init(void)
+{
+  timer_add(timer_init(&expireTimer), ip_registry_expire, 0, TT_PERIODIC, 60);
+}
+
 /*
  * IPcheck_local_connect
  *
@@ -302,7 +319,6 @@ int ip_registry_check_remote(struct Client* cptr, int is_burst)
       entry->last_connect = NOW;
     }
   }
-  SetIPChecked(cptr);
   return 1;
 }
 
@@ -347,8 +363,8 @@ void ip_registry_connect_succeeded(struct Client *cptr)
     free_targets = entry->target->count;
     tr = " tr";
   }
-  sendcmdto_one(&me, CMD_NOTICE, cptr, ":on %u ca %u(%u) ft %u(%u)%s",
-               entry->connected, entry->attempts, IPCHECK_CLONE_LIMIT,
+  sendcmdto_one(&me, CMD_NOTICE, cptr, "%C :on %u ca %u(%u) ft %u(%u)%s",
+               cptr, entry->connected, entry->attempts, IPCHECK_CLONE_LIMIT,
                free_targets, STARTTARGETS, tr);
 }
 
@@ -369,7 +385,7 @@ void ip_registry_disconnect(struct Client *cptr)
   if (0 == entry) {
     /*
      * trying to find an entry for a server causes this to happen,
-     * servers should never have FLAGS_IPCHECK set
+     * servers should never have FLAG_IPCHECK set
      */
     return;
   }
@@ -550,16 +566,5 @@ void IPcheck_disconnect(struct Client *cptr)
 unsigned short IPcheck_nr(struct Client *cptr)
 {
   assert(0 != cptr);
-  return ip_registry_count(cptr->ip.s_addr);
+  return ip_registry_count(cli_ip(cptr).s_addr);
 }
-
-void IPcheck_expire()
-{
-  static time_t next_expire = 0;
-  if (next_expire < CurrentTime) {
-    ip_registry_expire();
-    next_expire = CurrentTime + 60;
-  }
-}
-
-