Log message:
Cleanups for IPcheck work.
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@230
c9e4aea6-c8fd-4c43-8297-
357d70d61c8c
+2000-05-02 Thomas Helvey <tomh@inxpress.net>
+
+ * ircd/IPcheck.c: cleanups for ZenShadow's cleanups
+ review emailed privately
+
+ * include/IPcheck.h: removed unneeded include
+
2000-05-02 Kevin L. Mitchell <klmitch@mit.edu>
* ircd/s_user.c (hunt_server): throw in a comment so I know what
2000-05-02 Kevin L. Mitchell <klmitch@mit.edu>
* ircd/s_user.c (hunt_server): throw in a comment so I know what
#
# ChangeLog for ircu2.10.11
#
#
# ChangeLog for ircu2.10.11
#
-# $Id: ChangeLog,v 1.127 2000-05-02 20:25:32 kev Exp $
+# $Id: ChangeLog,v 1.128 2000-05-03 03:32:24 bleep Exp $
#
# Insert new changes at beginning of the change list.
#
#
# Insert new changes at beginning of the change list.
#
#include <sys/types.h> /* time_t, size_t */
#define INCLUDED_sys_types_h
#endif
#include <sys/types.h> /* time_t, size_t */
#define INCLUDED_sys_types_h
#endif
-#ifndef INCLUDED_netinet_in_h
-#include <netinet/in.h> /* in_addr */
-#define INCLUDED_netinet_in_h
-#endif
struct Client;
/*----------------------------------------------------------------------------
* Prototypes
*--------------------------------------------------------------------------*/
struct Client;
/*----------------------------------------------------------------------------
* Prototypes
*--------------------------------------------------------------------------*/
-extern int ip_registry_check_local (unsigned int addr,
- time_t *next_target_out);
+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_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_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 */
extern void ip_registry_connect_succeeded(struct Client *cptr);
#endif /* INCLUDED_ipcheck_h */
-
-/*----------------------------------------------------------------------------
- * Platform Includes
- *--------------------------------------------------------------------------*/
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-
-/*----------------------------------------------------------------------------
- * Application Includes
- *--------------------------------------------------------------------------*/
#include "IPcheck.h"
#include "client.h"
#include "ircd.h"
#include "IPcheck.h"
#include "client.h"
#include "ircd.h"
#include "s_user.h"
#include "send.h"
#include "s_user.h"
#include "send.h"
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
-/*----------------------------------------------------------------------------
- * Data Structures (should be moved to IPcheck.h)
- *--------------------------------------------------------------------------*/
-typedef struct IPTargetEntry {
int count;
unsigned char targets[MAXTARGETS];
int count;
unsigned char targets[MAXTARGETS];
-typedef struct IPRegistryEntry {
+struct IPRegistryEntry {
struct IPRegistryEntry *next;
struct IPTargetEntry *target;
unsigned int addr;
time_t last_connect;
unsigned char connected;
unsigned char attempts;
struct IPRegistryEntry *next;
struct IPTargetEntry *target;
unsigned int addr;
time_t last_connect;
unsigned char connected;
unsigned char attempts;
/*----------------------------------------------------------------------------
* Global Data (ugly!)
*--------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* Global Data (ugly!)
*--------------------------------------------------------------------------*/
-static ip_reg_entry_t *hashTable[IP_REGISTRY_TABLE_SIZE];
-static ip_reg_entry_t *freeList = 0;
+static struct IPRegistryEntry *hashTable[IP_REGISTRY_TABLE_SIZE];
+static struct IPRegistryEntry *freeList = 0;
/*----------------------------------------------------------------------------
/*----------------------------------------------------------------------------
* to the IP argument? Ugly. This should probably be a
* struct in_addr. This is asking for trouble. --ZS)
*--------------------------------------------------------------------------*/
* to the IP argument? Ugly. This should probably be a
* struct in_addr. This is asking for trouble. --ZS)
*--------------------------------------------------------------------------*/
-static unsigned int ip_registry_hash(unsigned int ip) {
+static unsigned int ip_registry_hash(unsigned int ip)
+{
return ((ip >> 16) ^ ip) & (IP_REGISTRY_TABLE_SIZE - 1);
}
return ((ip >> 16) ^ ip) & (IP_REGISTRY_TABLE_SIZE - 1);
}
/*----------------------------------------------------------------------------
* ip_registry_find: Find a given IP registry entry and return it.
*--------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* ip_registry_find: Find a given IP registry entry and return it.
*--------------------------------------------------------------------------*/
-static ip_reg_entry_t *ip_registry_find(unsigned int ip) {
- ip_reg_entry_t *entry;
+static struct IPRegistryEntry *ip_registry_find(unsigned int ip)
+{
+ struct IPRegistryEntry *entry;
for (entry = hashTable[ip_registry_hash(ip)]; entry; entry = entry->next) {
if (entry->addr == ip)
for (entry = hashTable[ip_registry_hash(ip)]; entry; entry = entry->next) {
if (entry->addr == ip)
/*----------------------------------------------------------------------------
* ip_registry_add: Add an entry to the IP registry
*--------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* ip_registry_add: Add an entry to the IP registry
*--------------------------------------------------------------------------*/
-static void ip_registry_add(ip_reg_entry_t *entry) {
+static void ip_registry_add(struct IPRegistryEntry *entry)
+{
unsigned int bucket = ip_registry_hash(entry->addr);
entry->next = hashTable[bucket];
unsigned int bucket = ip_registry_hash(entry->addr);
entry->next = hashTable[bucket];
/*----------------------------------------------------------------------------
* ip_registry_remove: Remove an entry from the IP registry
*--------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* ip_registry_remove: Remove an entry from the IP registry
*--------------------------------------------------------------------------*/
-static void ip_registry_remove(ip_reg_entry_t *entry) {
+static void ip_registry_remove(struct IPRegistryEntry* entry)
+{
unsigned int bucket = ip_registry_hash(entry->addr);
if (hashTable[bucket] == entry)
hashTable[bucket] = entry->next;
else {
unsigned int bucket = ip_registry_hash(entry->addr);
if (hashTable[bucket] == entry)
hashTable[bucket] = entry->next;
else {
+ struct IPRegistryEntry *prev;
for (prev = hashTable[bucket]; prev; prev = prev->next) {
if (prev->next == entry) {
for (prev = hashTable[bucket]; prev; prev = prev->next) {
if (prev->next == entry) {
* ip_registry_new_entry(): Creates and initializes an IP Registry entry.
* NOW ALSO ADDS IT TO THE LIST! --ZS
*--------------------------------------------------------------------------*/
* ip_registry_new_entry(): Creates and initializes an IP Registry entry.
* NOW ALSO ADDS IT TO THE LIST! --ZS
*--------------------------------------------------------------------------*/
-static ip_reg_entry_t *ip_registry_new_entry(unsigned int addr, int attempt) {
- ip_reg_entry_t *entry = freeList;
+static struct IPRegistryEntry *ip_registry_new_entry(unsigned int addr, int attempt)
+{
+ struct IPRegistryEntry* entry = freeList;
if (entry)
freeList = entry->next;
else
if (entry)
freeList = entry->next;
else
- entry = (ip_reg_entry_t *)MyMalloc(sizeof(ip_reg_entry_t));
+ entry = (struct IPRegistryEntry *)MyMalloc(sizeof(struct IPRegistryEntry));
- memset(entry, 0, sizeof(ip_reg_entry_t));
+ memset(entry, 0, sizeof(struct IPRegistryEntry));
entry->last_connect = NOW; /* Seconds since last connect attempt */
entry->connected = 1; /* connected clients for this IP */
entry->attempts = attempt; /* Number attempts for this IP */
entry->last_connect = NOW; /* Seconds since last connect attempt */
entry->connected = 1; /* connected clients for this IP */
entry->attempts = attempt; /* Number attempts for this IP */
* the freelist every once in a while! This is
* potentially a way to DoS the server... -ZS)
*--------------------------------------------------------------------------*/
* the freelist every once in a while! This is
* potentially a way to DoS the server... -ZS)
*--------------------------------------------------------------------------*/
-static void ip_registry_delete_entry(ip_reg_entry_t *entry) {
+static void ip_registry_delete_entry(struct IPRegistryEntry *entry)
+{
if (entry->target)
MyFree(entry->target);
if (entry->target)
MyFree(entry->target);
/*----------------------------------------------------------------------------
* ip_registry_update_free_targets:
*--------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* ip_registry_update_free_targets:
*--------------------------------------------------------------------------*/
-static unsigned int ip_registry_update_free_targets(ip_reg_entry_t *entry) {
+static unsigned int ip_registry_update_free_targets(struct IPRegistryEntry *entry)
+{
unsigned int free_targets = STARTTARGETS;
if (entry->target) {
unsigned int free_targets = STARTTARGETS;
if (entry->target) {
* entry isn't expired, then also check the target
* list to see if it needs to be expired.
*--------------------------------------------------------------------------*/
* entry isn't expired, then also check the target
* list to see if it needs to be expired.
*--------------------------------------------------------------------------*/
-static void ip_registry_expire_entry(ip_reg_entry_t *entry) {
+static void ip_registry_expire_entry(struct IPRegistryEntry *entry)
+{
/*
* Don't touch this number, it has statistical significance
* XXX - blah blah blah
/*
* Don't touch this number, it has statistical significance
* XXX - blah blah blah
if (CONNECTED_SINCE(entry) > 600) {
ip_registry_remove(entry);
ip_registry_delete_entry(entry);
if (CONNECTED_SINCE(entry) > 600) {
ip_registry_remove(entry);
ip_registry_delete_entry(entry);
- } else if (CONNECTED_SINCE(entry) > 120 && 0 != entry->target) {
+ }
+ else if (CONNECTED_SINCE(entry) > 120 && 0 != entry->target) {
MyFree(entry->target);
entry->target = 0;
}
MyFree(entry->target);
entry->target = 0;
}
/*----------------------------------------------------------------------------
* ip_registry_expire: Expire all of the needed entries in the hash table
*--------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* ip_registry_expire: Expire all of the needed entries in the hash table
*--------------------------------------------------------------------------*/
-void ip_registry_expire(void) {
- ip_reg_entry_t *entry;
- ip_reg_entry_t *entry_next;
+void ip_registry_expire(void)
+{
+ struct IPRegistryEntry *entry;
+ struct IPRegistryEntry *entry_next;
static time_t next_expire = 0;
int i;
static time_t next_expire = 0;
int i;
*--------------------------------------------------------------------------*/
int ip_registry_check_local(unsigned int addr, time_t *next_target_out)
{
*--------------------------------------------------------------------------*/
int ip_registry_check_local(unsigned int addr, time_t *next_target_out)
{
- ip_reg_entry_t *entry = ip_registry_find(addr);
+ struct IPRegistryEntry *entry = ip_registry_find(addr);
unsigned int free_targets = STARTTARGETS;
assert(0 != next_target_out);
unsigned int free_targets = STARTTARGETS;
assert(0 != next_target_out);
* 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.
*--------------------------------------------------------------------------*/
* 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) {
+void ip_registry_local_connect(struct Client *cptr)
+{
assert(0 != cptr);
SetIPChecked(cptr);
}
assert(0 != cptr);
SetIPChecked(cptr);
}
* Update the IPcheck registry.
* Return 0 on failure, 1 on success.
*--------------------------------------------------------------------------*/
* Update the IPcheck registry.
* Return 0 on failure, 1 on success.
*--------------------------------------------------------------------------*/
-int ip_registry_check_remote(struct Client* cptr, int is_burst) {
- ip_reg_entry_t *entry;
+int ip_registry_check_remote(struct Client* cptr, int is_burst)
+{
+ struct IPRegistryEntry *entry;
* a way that the client won't be penalized when trying to reconnect
* again.
*--------------------------------------------------------------------------*/
* a way that the client won't be penalized when trying to reconnect
* again.
*--------------------------------------------------------------------------*/
-void ip_registry_connect_fail(unsigned int addr) {
- ip_reg_entry_t *entry = ip_registry_find(addr);
+void ip_registry_connect_fail(unsigned int addr)
+{
+ struct IPRegistryEntry *entry = ip_registry_find(addr);
if (entry)
--entry->attempts;
if (entry)
--entry->attempts;
*
* Finish IPcheck registration of a successfully, locally connected client.
*--------------------------------------------------------------------------*/
*
* Finish IPcheck registration of a successfully, locally connected client.
*--------------------------------------------------------------------------*/
-void ip_registry_connect_succeeded(struct Client *cptr) {
+void ip_registry_connect_succeeded(struct Client *cptr)
+{
const char *tr = "";
unsigned int free_targets = STARTTARGETS;
const char *tr = "";
unsigned int free_targets = STARTTARGETS;
+ struct IPRegistryEntry *entry;
* Remove all expired IPregistry structures from the hash bucket
* that belongs to this clients IP number.
*--------------------------------------------------------------------------*/
* Remove all expired IPregistry structures from the hash bucket
* that belongs to this clients IP number.
*--------------------------------------------------------------------------*/
-void ip_registry_disconnect(struct Client *cptr) {
- ip_reg_entry_t *entry;
+void ip_registry_disconnect(struct Client *cptr)
+{
+ struct IPRegistryEntry *entry;
unsigned int free_targets;
if (0 == entry->target) {
unsigned int free_targets;
if (0 == entry->target) {
- entry->target = (iptarget_entry_t *)MyMalloc(sizeof(iptarget_entry_t));
+ entry->target = (struct IPTargetEntry *)MyMalloc(sizeof(struct IPTargetEntry));
assert(0 != entry->target);
entry->target->count = STARTTARGETS;
}
assert(0 != entry->target);
entry->target->count = STARTTARGETS;
}
*
* Returns number of clients with the same IP number
*--------------------------------------------------------------------------*/
*
* Returns number of clients with the same IP number
*--------------------------------------------------------------------------*/
-int ip_registry_count(unsigned int addr) {
- ip_reg_entry_t *entry = ip_registry_find(addr);
+int ip_registry_count(unsigned int addr)
+{
+ struct IPRegistryEntry *entry = ip_registry_find(addr);
return (entry) ? entry->connected : 0;
}
return (entry) ? entry->connected : 0;
}