Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2005-05-30 13:12:18 UTC

Modified files:
     ircd/IPcheck.c ChangeLog

Log message:

Add debugging statements to IPcheck.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.632 ircu2.10/ChangeLog:1.633
--- ircu2.10/ChangeLog:1.632    Thu May 12 19:03:23 2005
+++ ircu2.10/ChangeLog  Mon May 30 06:11:58 2005
@@ -1,3 +1,8 @@
+2005-05-30  Michael Poole <[EMAIL PROTECTED]>
+
+       * ircd/IPcheck.c: Add Debug()s to try to track why the connected
+       count underflows.
+
 2005-05-12  Michael Poole <[EMAIL PROTECTED]>
 
        * configure.in: Do not try to outsmart the default CFLAGS.
Index: ircu2.10/ircd/IPcheck.c
diff -u ircu2.10/ircd/IPcheck.c:1.38 ircu2.10/ircd/IPcheck.c:1.39
--- ircu2.10/ircd/IPcheck.c:1.38        Sun Mar 20 08:06:17 2005
+++ ircu2.10/ircd/IPcheck.c     Mon May 30 06:11:55 2005
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Code to count users connected from particular IP addresses.
- * @version $Id: IPcheck.c,v 1.38 2005/03/20 16:06:17 entrope Exp $
+ * @version $Id: IPcheck.c,v 1.39 2005/05/30 13:11:55 entrope Exp $
  */
 #include "config.h"
 
@@ -27,11 +27,11 @@
 #include "ircd.h"
 #include "match.h"
 #include "msg.h"
-#include "numnicks.h"       /* NumNick, NumServ (GODMODE) */
 #include "ircd_alloc.h"
 #include "ircd_events.h"
 #include "ircd_features.h"
 #include "ircd_log.h"
+#include "ircd_string.h"    /* ircd_ntoa */
 #include "s_debug.h"        /* Debug */
 #include "s_user.h"         /* TARGET_DELAY */
 #include "send.h"
@@ -219,6 +219,7 @@
     /*
      * expired
      */
+    Debug((DEBUG_DNS, "IPcheck expiring registry for %s (no clients 
connected).", ircd_ntoa(&entry->addr)));
     ip_registry_remove(entry);
     ip_registry_delete_entry(entry);
   }
@@ -275,16 +276,17 @@
     entry       = ip_registry_new_entry();
     ip_registry_canonicalize(&entry->addr, addr);
     ip_registry_add(entry);
+    Debug((DEBUG_DNS, "IPcheck added new registry for local connection from 
%s.", ircd_ntoa(&entry->addr)));
     return 1;
   }
-  /* Note that this also connects server connects.
+  /* Note that this also counts server connects.
    * It is hard and not interesting, to change that.
-   *
-   * Don't allow more then 255 connects from one IP number, ever
+   * Refuse connection if it would overflow the counter.
    */
   if (0 == ++entry->connected)
   {
     entry->connected--;
+    Debug((DEBUG_DNS, "IPcheck refusing local connection from %s: counter 
overflow.", ircd_ntoa(&entry->addr)));
     return 0;
   }
 
@@ -302,17 +304,17 @@
       *next_target_out = CurrentTime - (TARGET_DELAY * free_targets - 1);
   }
   else if ((CurrentTime - cli_since(&me)) > IPCHECK_CLONE_DELAY) {
-    /* 
+    /*
      * Don't refuse connection when we just rebooted the server
      */
-#ifdef NOTHROTTLE 
-    return 1;
-#else
+#ifndef NOTHROTTLE
     assert(entry->connected > 0);
     --entry->connected;
+    Debug((DEBUG_DNS, "IPcheck refusing local connection from %s: too fast.", 
ircd_ntoa(&entry->addr)));
     return 0;
-#endif        
+#endif
   }
+  Debug((DEBUG_DNS, "IPcheck accepting local connection from %s.", 
ircd_ntoa(&entry->addr)));
   return 1;
 }
 
@@ -332,8 +334,10 @@
    * Mark that we did add/update an IPregistry entry
    */
   SetIPChecked(cptr);
-  if (!irc_in_addr_valid(&cli_ip(cptr)))
+  if (!irc_in_addr_valid(&cli_ip(cptr))) {
+    Debug((DEBUG_DNS, "IPcheck accepting remote connection from invalid %s.", 
ircd_ntoa(&cli_ip(cptr))));
     return 1;
+  }
   entry = ip_registry_find(&cli_ip(cptr));
   if (0 == entry) {
     entry = ip_registry_new_entry();
@@ -341,27 +345,27 @@
     if (is_burst)
       entry->attempts = 0;
     ip_registry_add(entry);
+    Debug((DEBUG_DNS, "IPcheck added new registry for remote connection from 
%s.", ircd_ntoa(&entry->addr)));
+    return 1;
   }
-  else {
-    if (0 == ++entry->connected) {
-      /* 
-       * Don't allow more then 255 connects from one IP number, ever
+  /* Avoid overflowing the connection counter. */
+  if (0 == ++entry->connected) {
+    Debug((DEBUG_DNS, "IPcheck refusing remote connection from %s: counter 
overflow.", ircd_ntoa(&entry->addr)));
+    return 0;
+  }
+  if (CONNECTED_SINCE(entry->last_connect) > IPCHECK_CLONE_PERIOD)
+    entry->attempts = 0;
+  if (!is_burst) {
+    if (0 == ++entry->attempts) {
+      /*
+       * Check for overflow
        */
-      return 0;
-    }
-    if (CONNECTED_SINCE(entry->last_connect) > IPCHECK_CLONE_PERIOD)
-      entry->attempts = 0;
-    if (!is_burst) {
-      if (0 == ++entry->attempts) {
-        /*
-         * Check for overflow
-         */
-        --entry->attempts;
-      }
-      ip_registry_update_free_targets(entry);
-      entry->last_connect = NOW;
+      --entry->attempts;
     }
+    ip_registry_update_free_targets(entry);
+    entry->last_connect = NOW;
   }
+  Debug((DEBUG_DNS, "IPcheck counting remote connection from %s.", 
ircd_ntoa(&entry->addr)));
   return 1;
 }
 
@@ -373,10 +377,9 @@
 void ip_registry_connect_fail(const struct irc_in_addr *addr)
 {
   struct IPRegistryEntry* entry = ip_registry_find(addr);
-  if (entry)
-  {
-    if (0 == --entry->attempts)
-      ++entry->attempts;
+  if (entry && 0 == --entry->attempts) {
+    Debug((DEBUG_DNS, "IPcheck noting local connection failure for %s.", 
ircd_ntoa(&entry->addr)));
+    ++entry->attempts;
   }
 }
 
@@ -392,15 +395,13 @@
   unsigned int free_targets     = STARTTARGETS;
   struct IPRegistryEntry* entry = ip_registry_find(&cli_ip(cptr));
 
-  if (!entry) {
-    Debug((DEBUG_ERROR, "Missing registry entry for: %s", cli_sock_ip(cptr)));
-    return;
-  }
+  assert(entry);
   if (entry->target) {
     memcpy(cli_targets(cptr), entry->target->targets, MAXTARGETS);
     free_targets = entry->target->count;
     tr = " tr";
   }
+  Debug((DEBUG_DNS, "IPcheck noting local connection success for %s.", 
ircd_ntoa(&entry->addr)));
   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);
@@ -414,17 +415,16 @@
 void ip_registry_disconnect(struct Client *cptr)
 {
   struct IPRegistryEntry* entry = ip_registry_find(&cli_ip(cptr));
-  if (0 == entry) {
-    /*
-     * trying to find an entry for a server causes this to happen,
-     * servers should never have FLAG_IPCHECK set
-     */
+  if (!irc_in_addr_valid(&cli_ip(cptr))) {
+    Debug((DEBUG_DNS, "IPcheck noting dicconnect from invalid %s.", 
ircd_ntoa(&cli_ip(cptr))));
     return;
   }
+  assert(entry);
+  assert(entry->connected > 0);
+  Debug((DEBUG_DNS, "IPcheck noting disconnect from %s.", 
ircd_ntoa(&entry->addr)));
   /*
    * If this was the last one, set `last_connect' to disconnect time (used for 
expiration)
    */
-  /* assert(entry->connected > 0); */
   if (0 == --entry->connected) {
     if (CONNECTED_SINCE(entry->last_connect) > IPCHECK_CLONE_LIMIT * 
IPCHECK_CLONE_PERIOD) {
       /*
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to