Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

ban.c File Reference


Detailed Description

Banning control.

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "ban.h"
#include "sockets.h"
#include "version.h"
#include "token.h"
#include "lib/atoms.h"
#include "lib/file.h"
#include "lib/cq.h"
#include "lib/misc.h"
#include "lib/tm.h"
#include "lib/zalloc.h"
#include "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "lib/override.h"

Data Structures

struct  addr_info
 Information kept in the info table, per IP address. More...


Defines

#define BAN_DELAY   300 /**< Initial ban delay: 5 minutes */
 Initial ban delay: 5 minutes.

#define MAX_REQUEST   5 /**< Maximum of 5 requests... */
 Maximum of 5 requests..

#define MAX_PERIOD   60 /**< ...per minute */
 ...per minute

#define MAX_BAN   10800 /**< 3 hours */
 3 hours

#define BAN_REMIND   5 /**< Every so many attemps, tell them about it */
 Every so many attemps, tell them about it.

#define SOCK_BUFFER   512 /**< Reduced socket buffer */
 Reduced socket buffer.


Functions

 RCSID ("$Id:ban.c, v 1.18 2005/09/16 21:51:44 rmanfredi Exp $")
void ipf_destroy (cqueue_t *cq, gpointer obj)
 Called from callout queue when it's time to destroy the record.

addr_infoipf_make (const host_addr_t addr, time_t now)
 Create new addr_info structure for said IP.

void ipf_free (struct addr_info *ipf)
 Free addr_info structure.

void ipf_unban (cqueue_t *unused_cq, gpointer obj)
 Called from callout queue when it's time to unban the IP.

ban_type_t ban_allow (const host_addr_t addr)
 Check whether we can allow connection from `ip' to proceed.

void ban_record (const host_addr_t addr, const gchar *msg)
 Record banning with specific message for a given IP, for MAX_BAN seconds.

gboolean reclaim_fd (void)
 Internal version of ban_reclaim_fd().

gboolean ban_reclaim_fd (void)
 Reclaim a file descriptor used for banning.

void ban_force (struct gnutella_socket *s)
 Force banning of the connection.

gboolean ban_is_banned (const host_addr_t addr)
 Check whether IP is already recorded as being banned.

gint ban_delay (const host_addr_t addr)
gchar * ban_message (const host_addr_t addr)
void ban_init (void)
 Initialize the banning system.

void ban_max_recompute (void)
 Recompute the maximum amount of file descriptors we dedicate to banning.

void free_info (gpointer unused_key, gpointer value, gpointer unused_udata)
void ban_close (void)
 Called at shutdown time to reclaim all memory.

const gchar * ban_vendor (const gchar *vendor)
 Check whether servent identified by its vendor string should be banned.


Variables

GHashTable * info
 Info by IP address.

gfloat decay_coeff
 Decay coefficient, per second.

zone_tipf_zone
 Zone for addr_info allocation.

GList * banned_head = NULL
GList * banned_tail = NULL
const gchar harmful [] = "Harmful version banned, upgrade required"
const gchar refused [] = "Connection refused"
const gchar too_old [] = "Outdated version, please upgrade"


Define Documentation

#define BAN_DELAY   300 /**< Initial ban delay: 5 minutes */
 

Initial ban delay: 5 minutes.

#define BAN_REMIND   5 /**< Every so many attemps, tell them about it */
 

Every so many attemps, tell them about it.

#define MAX_BAN   10800 /**< 3 hours */
 

3 hours

#define MAX_PERIOD   60 /**< ...per minute */
 

...per minute

#define MAX_REQUEST   5 /**< Maximum of 5 requests... */
 

Maximum of 5 requests..

#define SOCK_BUFFER   512 /**< Reduced socket buffer */
 

Reduced socket buffer.


Function Documentation

ban_type_t ban_allow const host_addr_t  addr  ) 
 

Check whether we can allow connection from `ip' to proceed.

Returns:

BAN_OK ok, can proceed with connection. BAN_FIRST will ban, but send back message, then close connection. BAN_FORCE don't send back anything, and call ban_force(). BAN_MSG will ban with explicit message and tailored error code.

Every BAN_REMIND attempts, return BAN_FIRST to let them know that they have been banned, in case they "missed" our previous indications or did not get the Retry-After right. --RAM, 2004-06-21

void ban_close void   ) 
 

Called at shutdown time to reclaim all memory.

gint ban_delay const host_addr_t  addr  ) 
 

Returns:
banning delay for banned IP.

void ban_force struct gnutella_socket s  ) 
 

Force banning of the connection.

We're putting it in a list and forgetting about it.

void ban_init void   ) 
 

Initialize the banning system.

gboolean ban_is_banned const host_addr_t  addr  ) 
 

Check whether IP is already recorded as being banned.

void ban_max_recompute void   ) 
 

Recompute the maximum amount of file descriptors we dedicate to banning.

gchar* ban_message const host_addr_t  addr  ) 
 

Returns:
banning message for banned IP.

gboolean ban_reclaim_fd void   )  [static]
 

Reclaim a file descriptor used for banning.

Invoked from the outside as a callback to reclaim file descriptors.

This routine is called when there is a shortage of file descriptors, so we activate the "file_descriptor_shortage" property. However, if we have nothing to reclaim, we activate the "file_descriptor_runout" property instead, which signifies that processing will be degraded.

Returns:
TRUE if we did reclaim something, FALSE if there was nothing.

void ban_record const host_addr_t  addr,
const gchar *  msg
 

Record banning with specific message for a given IP, for MAX_BAN seconds.

const gchar* ban_vendor const gchar *  vendor  ) 
 

Check whether servent identified by its vendor string should be banned.

When we ban, we ban for both gnet and download connections. Such banning is exceptional, usually restricted to some versions and the servent's author is informed about the banning.

Returns:
NULL if we shall not ban, a banning reason string otherwise.

void free_info gpointer  unused_key,
gpointer  value,
gpointer  unused_udata
[static]
 

void ipf_destroy cqueue_t unused_cq,
gpointer  obj
[static]
 

Called from callout queue when it's time to destroy the record.

void ipf_free struct addr_info ipf  )  [static]
 

Free addr_info structure.

struct addr_info* ipf_make const host_addr_t  addr,
time_t  now
[static]
 

Create new addr_info structure for said IP.

void ipf_unban cqueue_t unused_cq,
gpointer  obj
[static]
 

Called from callout queue when it's time to unban the IP.

Compute new scheduling delay.

If counter is negative or null, we can remove the entry. Since we round to an integer, we must consider `delay' and not the original counter.

RCSID "$Id:ban.  c,
v 1.18 2005/09/16 21:51:44 rmanfredi Exp $" 
 

gboolean reclaim_fd void   )  [static]
 

Internal version of ban_reclaim_fd().

Reclaim a file descriptor used for banning.

Returns:
TRUE if we did reclaim something, FALSE if there was nothing.


Variable Documentation

GList* banned_head = NULL [static]
 

GList* banned_tail = NULL [static]
 

gfloat decay_coeff [static]
 

Decay coefficient, per second.

const gchar harmful[] = "Harmful version banned, upgrade required" [static]
 

GHashTable* info [static]
 

Info by IP address.

zone_t* ipf_zone [static]
 

Zone for addr_info allocation.

const gchar refused[] = "Connection refused" [static]
 

const gchar too_old[] = "Outdated version, please upgrade" [static]
 


Generated on Sun Feb 12 10:49:59 2006 for Gtk-Gnutella by doxygen 1.3.6