GNU libmicrohttpd  0.9.72
daemon_ip_limit.c File Reference

counting of connections per IP More...

#include "internal.h"
#include "daemon_ip_limit.h"
#include "tsearch.h"
Include dependency graph for daemon_ip_limit.c:

Go to the source code of this file.

Functions

static struct MHD_Daemonget_master (struct MHD_Daemon *daemon)
 
static void MHD_ip_count_lock (struct MHD_Daemon *daemon)
 
static void MHD_ip_count_unlock (struct MHD_Daemon *daemon)
 
static int MHD_ip_addr_compare (const void *a1, const void *a2)
 
static int MHD_ip_addr_to_key (const struct sockaddr *addr, socklen_t addrlen, struct MHD_IPCount *key)
 
int MHD_ip_limit_add (struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen)
 
void MHD_ip_limit_del (struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen)
 

Detailed Description

counting of connections per IP

Author
Christian Grothoff

Definition in file daemon_ip_limit.c.

Function Documentation

◆ get_master()

static struct MHD_Daemon* get_master ( struct MHD_Daemon daemon)
static

Trace up to and return master daemon. If the supplied daemon is a master, then return the daemon itself.

Parameters
daemonhandle to a daemon
Returns
master daemon handle

Definition at line 76 of file daemon_ip_limit.c.

References MHD_Daemon::master, and NULL.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_addr_compare()

static int MHD_ip_addr_compare ( const void *  a1,
const void *  a2 
)
static

Tree comparison function for IP addresses (supplied to tsearch() family). We compare everything in the struct up through the beginning of the 'count' field.

Parameters
a1first address to compare
a2second address to compare
Returns
-1, 0 or 1 depending on result of compare

Definition at line 118 of file daemon_ip_limit.c.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_addr_to_key()

static int MHD_ip_addr_to_key ( const struct sockaddr *  addr,
socklen_t  addrlen,
struct MHD_IPCount *  key 
)
static

Parse address and initialize key using the address.

Parameters
addraddress to parse
addrlennumber of bytes in addr
keywhere to store the parsed address
Returns
MHD_YES on success and MHD_NO otherwise (e.g., invalid address type)

Definition at line 137 of file daemon_ip_limit.c.

References MHD_NO, and MHD_YES.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_count_lock()

static void MHD_ip_count_lock ( struct MHD_Daemon daemon)
static

Lock shared structure for IP connection counts and connection DLLs.

Parameters
daemonhandle to daemon where lock is

Definition at line 90 of file daemon_ip_limit.c.

References MHD_mutex_lock_chk_, and MHD_Daemon::per_ip_connection_mutex.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_count_unlock()

static void MHD_ip_count_unlock ( struct MHD_Daemon daemon)
static

Unlock shared structure for IP connection counts and connection DLLs.

Parameters
daemonhandle to daemon where lock is

Definition at line 102 of file daemon_ip_limit.c.

References MHD_mutex_unlock_chk_, and MHD_Daemon::per_ip_connection_mutex.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_limit_add()

int MHD_ip_limit_add ( struct MHD_Daemon daemon,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Check if IP address is over its limit in terms of the number of allowed concurrent connections. If the IP is still allowed, increments the connection counter.

Parameters
daemonhandle to daemon where connection counts are tracked
addraddress to add (or increment counter)
addrlennumber of bytes in addr
Returns
Return MHD_YES if IP below limit, MHD_NO if IP has surpassed limit. Also returns MHD_NO if fails to allocate memory.

Definition at line 188 of file daemon_ip_limit.c.

References _, get_master(), MHD_Daemon::ip_connection_limit, MHD_ip_addr_compare(), MHD_ip_addr_to_key(), MHD_ip_count_lock(), MHD_ip_count_unlock(), MHD_NO, MHD_YES, NULL, MHD_Daemon::per_ip_connection_count, and tsearch().

Here is the call graph for this function:

◆ MHD_ip_limit_del()

void MHD_ip_limit_del ( struct MHD_Daemon daemon,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Decrement connection count for IP address, removing from table count reaches 0.

Parameters
daemonhandle to daemon where connection counts are tracked
addraddress to remove (or decrement counter)
addrlennumber of bytes in addr

Definition at line 255 of file daemon_ip_limit.c.

References _, get_master(), MHD_Daemon::ip_connection_limit, MHD_ip_addr_compare(), MHD_ip_addr_to_key(), MHD_ip_count_lock(), MHD_ip_count_unlock(), MHD_NO, MHD_PANIC, NULL, MHD_Daemon::per_ip_connection_count, tdelete(), and tfind().

Referenced by MHD_connection_cleanup_().

Here is the call graph for this function:
Here is the caller graph for this function: