Author: ZenShadow
authorPerry Lorier <isomer@undernet.org>
Sun, 30 Apr 2000 12:00:07 +0000 (12:00 +0000)
committerPerry Lorier <isomer@undernet.org>
Sun, 30 Apr 2000 12:00:07 +0000 (12:00 +0000)
Log message:

Change the IPcheck API.

git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@222 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

13 files changed:
ChangeLog
RELEASE.NOTES
include/IPcheck.h
ircd/IPcheck.c
ircd/ircd.c
ircd/m_nick.c
ircd/s_auth.c
ircd/s_bsd.c
ircd/s_conf.c
ircd/s_misc.c
ircd/s_serv.c
ircd/s_user.c
ircd/whocmds.c

index c25a3137d47c0cbf2461ba92e356036210a428ca..4055cc18f6213fbb2fbef51cf63fa2df8d098c59 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
          - rewrite of setuid/chroot code.
          - server will no longer run as root
          - -DPROFIL compile option removed
+         - Fixed IPcheck API calls
  
        * config/config-sh.in
          - Fixed up chroot compile options
        * ircd/ircd_signal.c
          - Removed -DPROFIL
 
+       * include/IPcheck.h
+         - Removed old API prototypes, added new ones
+       
        * ircd/IPcheck.c
          - Readability cleanups (well, I -think-...)
          - Changed IPRegistryEntry.last_connect to a time_t.  The previously
            used unsigned short was probably causing interesting things after
            a client had been connected longer than about 65,535 seconds...
+         - Removed old API functions.
+
+       * ircd/whocmds.c
+         - Removed IPcheck.h include
+       
+       * Additionally modified IPcheck API calls in:
+         - ircd/m_nick.c
+         - ircd/m_auth.c
+         - ircd/s_bsd.c
+         - ircd/s_conf.c
+         - ircd/s_misc.c
+         - ircd/s_serv.c
+         - ircd/s_user.c
+       
        
 2000-04-30  Perry Lorier <isomer@coders.net>
        * ircd/s_bsd.c: Sigh. :)
 #
 # ChangeLog for ircu2.10.11
 #
-# $Id: ChangeLog,v 1.119 2000-04-30 11:39:24 isomer Exp $
+# $Id: ChangeLog,v 1.120 2000-04-30 12:00:06 isomer Exp $
 #
 # Insert new changes at beginning of the change list.
 #
index 98daf15e18c2742db98e5a067b81a1671d2cacfa..47c4f2b3e35e7e0d3c5e892828f693f8bad9690d 100644 (file)
@@ -89,7 +89,6 @@ debugging *only*.  It lets you connect up to 255 clients from one
 host with no time conciderations.  If this is enabled on a 
 production server I will personally drive your server into the 
 ground.  You have been warned.
--DIPCHECKDEBUG Debugging statements with IPcheck.
 
 Operating System and Kernel Requirements:
 If you plan allowing more than 1000 clients on your server, you
index f26e222ad88ce87a84fe59272aab4f6a9f9439a4..fe277957b36d6ee0fbc09225bea9ca1dfa85a91d 100644 (file)
 
 struct Client;
 
-/*
+/*----------------------------------------------------------------------------
  * Prototypes
- */
-extern int IPcheck_local_connect(struct in_addr ip, time_t* next_target_out);
-extern void IPcheck_connect_fail(struct in_addr ip);
-extern void IPcheck_connect_succeeded(struct Client *cptr);
-extern int IPcheck_remote_connect(struct Client *cptr, int is_burst);
-extern void IPcheck_disconnect(struct Client *cptr);
-extern unsigned short IPcheck_nr(struct Client *cptr);
-extern void IPcheck_expire();
+ *--------------------------------------------------------------------------*/
+extern int  ip_registry_check_local  (unsigned int   addr, 
+                                     time_t        *next_target_out);
+extern void ip_registry_local_connect(struct Client *cptr);
+extern void ip_registry_connect_fail (unsigned int   addr);
+extern void ip_registry_expire       (void);
+extern void ip_registry_disconnect   (struct Client *cptr);
+extern int  ip_registry_count        (unsigned int   addr);
+extern int  ip_registry_check_remote (struct Client *cptr,
+                                     int            is_burst);
+extern void ip_registry_connect_succeeded(struct Client *cptr);
 
 #endif /* INCLUDED_ipcheck_h */
+
index 48fe0445d16947e021d6badf6f02f7949e931bb6..6a5b5585e1f18ef0c4332a0edf8b4e1b6c2cfe9a 100644 (file)
@@ -75,7 +75,7 @@ typedef struct IPRegistryEntry {
 
 #define IPCHECK_CLONE_LIMIT 2
 #define IPCHECK_CLONE_PERIOD 20
-#define IPCHECK_CLONE_DELAY  1
+#define IPCHECK_CLONE_DELAY  600
 
 
 /*----------------------------------------------------------------------------
@@ -235,11 +235,16 @@ static void ip_registry_expire_entry(ip_reg_entry_t *entry) {
 /*----------------------------------------------------------------------------
  * ip_registry_expire:  Expire all of the needed entries in the hash table
  *--------------------------------------------------------------------------*/
-static void ip_registry_expire(void) {
+void ip_registry_expire(void) {
   ip_reg_entry_t *entry;
   ip_reg_entry_t *entry_next;
+  static time_t   next_expire = 0;
   int i;
 
+  /* Only do this if we're ready to */
+  if (next_expire >= CurrentTime)
+    return;
+
   for (i = 0; i < IP_REGISTRY_TABLE_SIZE; ++i) {
     for (entry = hashTable[i]; entry; entry = entry_next) {
       entry_next = entry->next;
@@ -247,6 +252,8 @@ static void ip_registry_expire(void) {
         ip_registry_expire_entry(entry);
     }
   }
+
+  next_expire = CurrentTime + 60;
 }
 
 
@@ -282,6 +289,8 @@ int ip_registry_check_local(unsigned int addr, time_t *next_target_out)
   ip_reg_entry_t *entry        = ip_registry_find(addr);
   unsigned int free_targets = STARTTARGETS;
  
+  assert(0 != next_target_out);
+
   if (0 == entry) {
     entry = ip_registry_new_entry(addr, 1);
     return 1;
@@ -315,6 +324,18 @@ int ip_registry_check_local(unsigned int addr, time_t *next_target_out)
 }
 
 
+/*----------------------------------------------------------------------------
+ * ip_registry_local_connect
+ *
+ * Does anything that needs to be done once we actually have a client
+ * structure to play with on a local connection that passed the IPcheck test.
+ *--------------------------------------------------------------------------*/
+void ip_registry_local_connect(struct Client *cptr) {
+  assert(0 != cptr);
+  SetIPChecked(cptr);
+}
+
+
 /*----------------------------------------------------------------------------
  * IPcheck_remote_connect
  *
@@ -327,7 +348,11 @@ int ip_registry_check_local(unsigned int addr, time_t *next_target_out)
  *   Return 0 on failure, 1 on success.
  *--------------------------------------------------------------------------*/
 int ip_registry_check_remote(struct Client* cptr, int is_burst) {
-  ip_reg_entry_t *entry = ip_registry_find(cptr->ip.s_addr);
+  ip_reg_entry_t *entry;
+
+  assert(cptr);
+
+  entry = ip_registry_find(cptr->ip.s_addr);
 
   SetIPChecked(cptr);
 
@@ -384,7 +409,11 @@ void ip_registry_connect_fail(unsigned int addr) {
 void ip_registry_connect_succeeded(struct Client *cptr) {
   const char     *tr           = "";
   unsigned int free_targets     = STARTTARGETS;
-  ip_reg_entry_t *entry        = ip_registry_find(cptr->ip.s_addr);
+  ip_reg_entry_t *entry;
+
+  assert(cptr);
+
+  entry = ip_registry_find(cptr->ip.s_addr);
 
   if (!entry) {
     Debug((DEBUG_ERROR, "Missing registry entry for: %s", cptr->sock_ip));
@@ -415,7 +444,14 @@ void ip_registry_connect_succeeded(struct Client *cptr) {
  *     that belongs to this clients IP number.
  *--------------------------------------------------------------------------*/
 void ip_registry_disconnect(struct Client *cptr) {
-  ip_reg_entry_t *entry = ip_registry_find(cptr->ip.s_addr);
+  ip_reg_entry_t *entry;
+
+  assert(0 != cptr);
+
+  if (!IsIPChecked(cptr))
+    return;
+
+  entry = ip_registry_find(cptr->ip.s_addr);
 
   /* Entry is probably a server if this happens. */
   if (0 == entry)
@@ -486,123 +522,6 @@ int ip_registry_count(unsigned int addr) {
 }
 
 
-/*----------------------------------------------------------------------------
- * IPcheck_local_connect
- *
- * Event:
- *   A new connection was accept()-ed with IP number `cptr->ip.s_addr'.
- *
- * Action:
- *   Update the IPcheck registry.
- *   Return:
- *     1 : You're allowed to connect.
- *     0 : You're not allowed to connect.
- *
- * Throttling:
- *
- * A connection should be rejected when a connection from the same IP number was
- * received IPCHECK_CLONE_LIMIT times before this connect attempt, with
- * reconnect intervals of IPCHECK_CLONE_PERIOD seconds or less.
- *
- * Free target inheritance:
- *
- * When the client is accepted, then the number of Free Targets
- * of the cptr is set to the value stored in the found IPregistry
- * structure, or left at STARTTARGETS.  This can be done by changing
- * cptr->nexttarget to be `now - (TARGET_DELAY * (FREE_TARGETS - 1))',
- * where FREE_TARGETS may range from 0 till STARTTARGETS.
- *--------------------------------------------------------------------------*/
-int IPcheck_local_connect(struct in_addr a, time_t* next_target_out) {
-  assert(0 != next_target_out);
-  return ip_registry_check_local(a.s_addr, next_target_out);
-}
-
-
-/*----------------------------------------------------------------------------
- * IPcheck_remote_connect
- *
- * Event:
- *   A remote client connected to Undernet, with IP number `cptr->ip.s_addr'
- *   and hostname `hostname'.
- *
- * Action:
- *   Update the IPcheck registry.
- *   Return 0 on failure, 1 on success.
- *--------------------------------------------------------------------------*/
-int IPcheck_remote_connect(struct Client *cptr, int is_burst) {
-  assert(0 != cptr);
-  return ip_registry_check_remote(cptr, is_burst);
-}
-
-
-/*----------------------------------------------------------------------------
- * IPcheck_connect_fail
- *
- * Event:
- *   This local client failed to connect due to legal reasons.
- *
- * Action:
- *   Neutralize the effect of calling IPcheck_local_connect, in such
- *   a way that the client won't be penalized when trying to reconnect
- *   again.
- *--------------------------------------------------------------------------*/
-void IPcheck_connect_fail(struct in_addr a) {
-  ip_registry_connect_fail(a.s_addr);
-}
-
-
-/*----------------------------------------------------------------------------
- * IPcheck_connect_succeeded
- *
- * Event:
- *   A client succeeded to finish the registration.
- *
- * Finish IPcheck registration of a successfully, locally connected client.
- *--------------------------------------------------------------------------*/
-void IPcheck_connect_succeeded(struct Client *cptr) {
-  assert(0 != cptr);
-  ip_registry_connect_succeeded(cptr);
-}
-
-
-/*----------------------------------------------------------------------------
- * IPcheck_disconnect
- *
- * Event:
- *   A local client disconnected or a remote client left Undernet.
- *
- * Action:
- *   Update the IPcheck registry.
- *   Remove all expired IPregistry structures from the hash bucket
- *     that belongs to this clients IP number.
- *--------------------------------------------------------------------------*/
-void IPcheck_disconnect(struct Client *cptr) {
-  assert(0 != cptr);
-  ip_registry_disconnect(cptr);
-}
-
-
-/*----------------------------------------------------------------------------
- * IPcheck_nr
- *
- * Returns number of clients with the same IP number
- *--------------------------------------------------------------------------*/
-unsigned short IPcheck_nr(struct Client *cptr) {
-  assert(0 != cptr);
-  return ip_registry_count(cptr->ip.s_addr);
-}
 
 
-/*----------------------------------------------------------------------------
- * IPcheck_expire
- *
- * Expire old entries
- *--------------------------------------------------------------------------*/
-void IPcheck_expire() {
-  static time_t next_expire = 0;
 
-  if (next_expire < CurrentTime) {
-    ip_registry_expire();
-    next_expire = CurrentTime + 60;
-  }
-}
index 6012ea5e11a02b1714ea6f614b01643d9c5e4c2b..ededf241ae1b8d78a60b5a5dc1411b48cf93e05b 100644 (file)
@@ -495,7 +495,7 @@ static void event_loop(void) {
     /* timeout pending queries that haven't been responded to */
     timeout_auth_queries(CurrentTime);
 
-    IPcheck_expire();
+    ip_registry_expire();
 
     if (GlobalRehashFlag) {
       rehash(&me, 1);
index 945e3a9cb2a66ac7e0b96c24c710fd87ad9881c1..fe02d167a9c9f9c9e47d99d2dcfa8139a5666774 100644 (file)
@@ -217,7 +217,7 @@ int m_nick(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
    */
   if (IsUnknown(acptr) && MyConnect(acptr)) {
     ++ServerStats->is_ref;
-    IPcheck_connect_fail(acptr->ip);
+    ip_registry_connect_fail(acptr->ip.s_addr);
     exit_client(cptr, acptr, &me, "Overridden by other sign on");
     return set_nick_name(cptr, sptr, nick, parc, parv);
   }
@@ -382,7 +382,7 @@ int ms_nick(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
    */
   if (IsUnknown(acptr) && MyConnect(acptr)) {
     ++ServerStats->is_ref;
-    IPcheck_connect_fail(acptr->ip);
+    ip_registry_connect_fail(acptr->ip.s_addr);
     exit_client(cptr, acptr, &me, "Overridden by other sign on");
     return set_nick_name(cptr, sptr, nick, parc, parv);
   }
@@ -665,7 +665,7 @@ int m_nick(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   if (IsUnknown(acptr) && MyConnect(acptr))
   {
     ++ServerStats->is_ref;
-    IPcheck_connect_fail(acptr->ip);
+    ip_registry_connect_fail(acptr->ip.s_addr);
     exit_client(cptr, acptr, &me, "Overridden by other sign on");
     return set_nick_name(cptr, sptr, nick, parc, parv);
   }
index c6879173866499550c0b3477461ad797856b626a..ebb1dd64f3c040e581b8e86a7e6d717c03746347 100644 (file)
@@ -177,7 +177,7 @@ static void auth_kill_client(struct AuthRequest* auth)
 
   if (IsDNSPending(auth))
     delete_resolver_queries(auth);
-  IPcheck_disconnect(auth->client);
+  ip_registry_disconnect(auth->client);
   Count_unknowndisconnects(UserStats);
   free_client(auth->client);
   free_auth_request(auth);
index b7d7b46d286293d11d04dac2ff4e9d30d20ed53a..2d82dbb80899a114aefd8de1bdac0206877dbcb9 100644 (file)
@@ -547,63 +547,60 @@ int net_close_unregistered_connections(struct Client* source)
   return count;
 }
 
-/*
+/*----------------------------------------------------------------------------
+ * add_connection
+ *
  * Creates a client which has just connected to us on the given fd.
  * The sockhost field is initialized with the ip# of the host.
  * The client is not added to the linked list of clients, it is
  * passed off to the auth handler for dns and ident queries.
- */
-void add_connection(struct Listener* listener, int fd)
-{
+ *--------------------------------------------------------------------------*/
+void add_connection(struct Listener* listener, int fd) {
   struct sockaddr_in addr;
-  struct Client*     new_client;
+  struct Client      *new_client;
   time_t             next_target = 0;
+
   const char* const throttle_message =
          "ERROR: Your host is trying to (re)connect too fast -- throttled\r\n";
        /* 12345678901234567890123456789012345679012345678901234567890123456 */
   
   assert(0 != listener);
+
   /*
-   * Removed preliminary access check. Full check is performed in
-   * m_server and m_user instead. Also connection time out help to
-   * get rid of unwanted connections.
+   * Removed preliminary access check. Full check is performed in m_server and
+   * m_user instead. Also connection time out help to get rid of unwanted
+   * connections.  
    */
   if (!os_get_peername(fd, &addr) || !os_set_nonblocking(fd)) {
     ++ServerStats->is_ref;
     close(fd);
     return;
   }
+
+
   /*
    * Add this local client to the IPcheck registry.
+   *
    * If it is a connection to a user port and if the site has been throttled,
    * reject the user.
    */
-  if (!IPcheck_local_connect(addr.sin_addr, &next_target) && !listener->server) {
-#ifdef IPCHECKDEBUG     
-   char buff[512];
-   snprintf(buff,512,"\n\rNOTICE * :IPCheck=%i connections active\n\r%s",
-       IPcheck_nr(cptr),
-       throttle_message);
-   buff[511]=0;
-   send(fd,buff,strlen(buff),0);
-#else
-    /*
-     * strlen(throttle_message) == 66
-     *
-     * strlen is slow, so we use the constant here.
-     */
+  if (!ip_registry_check_local(addr.sin_addr.s_addr, &next_target) &&
+      !listener->server) {
     send(fd, throttle_message, 66, 0);
-#endif
     close(fd);
     ++ServerStats->is_ref;
     return;
   }
 
-  new_client = make_client(0,
-      (listener->server) ? STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER);
+  new_client = make_client(0, ((listener->server) ? 
+                              STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER));
+
+  if (!listener->server)
+    ip_registry_local_connect(new_client);
+
   /*
-   * Copy ascii address to 'sockhost' just in case. Then we
-   * have something valid to put into error messages...
+   * Copy ascii address to 'sockhost' just in case. Then we have something
+   * valid to put into error messages...  
    */
   ircd_ntoa_r(new_client->sock_ip, (const char*) &addr.sin_addr);   
   strcpy(new_client->sockhost, new_client->sock_ip);
@@ -614,19 +611,16 @@ void add_connection(struct Listener* listener, int fd)
     new_client->nexttarget = next_target;
 
   new_client->fd = fd;
-
-  if (!listener->server)
-    SetIPChecked(new_client);
   new_client->listener = listener;
   ++listener->ref_count;
 
   Count_newunknown(UserStats);
-  /*
-   * if we've made it this far we can put the client on the auth query pile
-   */
+
+  /* if we've made it this far we can put the client on the auth query pile */
   start_auth(new_client);
 }
 
+
 /*
  * read_packet
  *
index ec96c4900cc27e34d46e9d566f1dbccd4ab1acf0..a28b545e97b7920dfea09119cb876f84bdce77e5 100644 (file)
@@ -498,7 +498,7 @@ check_limit_and_attach(struct Client* cptr, struct ConfItem* aconf)
        * clients connected with the same IP number
        */
       unsigned short nr = *aconf->passwd - '0';
-      if (IPcheck_nr(cptr) > nr)
+      if (ip_registry_count(cptr->ip.s_addr) > nr)
         return ACR_TOO_MANY_FROM_IP; /* Already got nr with that ip# */
     }
 #ifdef USEONE
index a5b122c4ec276adb1e304015e3bcfd35b5260b16..82fb0648c11e78c0abac383caa98418831316191 100644 (file)
@@ -277,11 +277,9 @@ static void exit_one_client(struct Client* bcptr, const char* comment)
   else if (IsUnknown(bcptr) || IsConnecting(bcptr) || IsHandshake(bcptr))
     Count_unknowndisconnects(UserStats);
 
-  /*
-   * Update IPregistry
-   */
-  if (IsIPChecked(bcptr))
-    IPcheck_disconnect(bcptr);
+  /* Update IPregistry */
+  ip_registry_disconnect(bcptr);
+
 
   /* 
    * Remove from serv->client_list
index cd7e82627ee4600d899509e59aa2c572e39f4947..96958ed4d9787950d6fff779281ce20ea1714909 100644 (file)
@@ -138,7 +138,7 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
      * XXX - if this comes from a server port, it will not have been added
      * to the IP check registry, see add_connection in s_bsd.c 
      */
-    IPcheck_connect_fail(cptr->ip);
+    ip_registry_connect_fail(cptr->ip.s_addr);
   }
 
   det_confs_butmask(cptr, CONF_LEAF | CONF_HUB | CONF_SERVER | CONF_UWORLD);
index a7c0c03e7c150ae575ec68eb038b88db8f6f222c..ff7cb118c38b8e02eb9e5f6982578ca77d650098 100644 (file)
@@ -457,7 +457,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
                               get_client_name(sptr, HIDE_IP));
         }
         ++ServerStats->is_ref;
-        IPcheck_connect_fail(sptr->ip);
+        ip_registry_connect_fail(sptr->ip.s_addr);
         return exit_client(cptr, sptr, &me,
                           "Sorry, your connection class is full - try "
                           "again later or try another server");
@@ -476,7 +476,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
         /* Can this ever happen? */
       case ACR_BAD_SOCKET:
         ++ServerStats->is_ref;
-        IPcheck_connect_fail(sptr->ip);
+        ip_registry_connect_fail(sptr->ip.s_addr);
         return exit_client(cptr, sptr, &me, "Unknown error -- Try again");
     }
     ircd_strncpy(user->host, sptr->sockhost, HOSTLEN);
@@ -498,7 +498,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
         && strcmp(sptr->passwd, aconf->passwd))
     {
       ServerStats->is_ref++;
-      IPcheck_connect_fail(sptr->ip);
+      ip_registry_connect_fail(sptr->ip.s_addr);
       send_reply(sptr, ERR_PASSWDMISMATCH);
       return exit_client(cptr, sptr, &me, "Bad Password");
     }
@@ -508,7 +508,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
      */
     if (find_kill(sptr)) {
       ServerStats->is_ref++;
-      IPcheck_connect_fail(sptr->ip);
+      ip_registry_connect_fail(sptr->ip.s_addr);
       return exit_client(cptr, sptr, &me, "K-lined");
     }
     /*
@@ -627,7 +627,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
     nextping = CurrentTime;
     if (sptr->snomask & SNO_NOISY)
       set_snomask(sptr, sptr->snomask & SNO_NOISY, SNO_ADD);
-    IPcheck_connect_succeeded(sptr);
+    ip_registry_connect_succeeded(sptr);
   }
   else
     /* if (IsServer(cptr)) */
@@ -656,7 +656,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
       if (IsBurst(acptr) || Protocol(acptr) < 10)
         break;
     }
-    if (!IPcheck_remote_connect(sptr, (acptr != &me)))
+    if (!ip_registry_check_remote(sptr, (acptr != &me)))
       /*
        * We ran out of bits to count this
        */
index c06a3af02f84dfcdd7382218598203d04b2e0015..47f774f687bc2cc9b04ce1d3b0b2fda89311ed4e 100644 (file)
@@ -23,7 +23,6 @@
  * $Id$
  */
 #include "whocmds.h"
-#include "IPcheck.h"
 #include "channel.h"
 #include "client.h"
 #include "hash.h"