Skip to content

Commit

Permalink
Reconstructed version 0.5.0
Browse files Browse the repository at this point in the history
Reconstructed from:
https://web.archive.org/web/20190708182325/https://www.apachelounge.com/viewtopic.php?p=19159#19159

-----BEGIN UPSTREAM CHANGELOG-----
Added SERVER_BUSY_WRITE, SERVER_BUSY_KEEPALIVE, SERVER_BUSY_DNS,
SERVER_BUSY_LOG, SERVER_CLOSING, SERVER_GRACEFUL state checking
-----END UPSTREAM CHANGELOG-----
  • Loading branch information
NewEraCracker authored and Deltik committed Sep 9, 2011
1 parent f6d7d74 commit 23b1b70
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions mod_antiloris.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
mod_antiloris 0.4
mod_antiloris 0.5
Copyright (C) 2010 Monshouwer Internet Diensten
Author: Kees Monshouwer
Expand Down Expand Up @@ -29,7 +29,7 @@
#include "scoreboard.h"

#define MODULE_NAME "mod_antiloris"
#define MODULE_VERSION "0.4"
#define MODULE_VERSION "0.5"

module AP_MODULE_DECLARE_DATA antiloris_module;

Expand Down Expand Up @@ -61,14 +61,16 @@ static void *create_config(apr_pool_t *p, server_rec *s)
/* Parse the IPReadLimit directive */
static const char *ipreadlimit_config_cmd(cmd_parms *parms, void *mconfig, const char *arg)
{
signed long int limit;

antiloris_config *conf = ap_get_module_config(parms->server->module_config, &antiloris_module);
const char *err = ap_check_cmd_context (parms, GLOBAL_ONLY);

if (err != NULL) {
return err;
}

signed long int limit = strtol(arg, (char **) NULL, 10);
limit = strtol(arg, (char **) NULL, 10);

/* No reasonable person would want more than 2^16. Better would be
to use LONG_MAX but that causes portability problems on win32 */
Expand All @@ -83,7 +85,7 @@ static const char *ipreadlimit_config_cmd(cmd_parms *parms, void *mconfig, const

/* Array describing structure of configuration directives */
static command_rec antiloris_cmds[] = {
AP_INIT_TAKE1("IPReadLimit", ipreadlimit_config_cmd, NULL, RSRC_CONF, "Maximum simultaneous connections in READ state per IP address"),
AP_INIT_TAKE1("IPReadLimit", ipreadlimit_config_cmd, NULL, RSRC_CONF, "Maximum simultaneous connections per IP address"),
{NULL}
};

Expand Down Expand Up @@ -112,6 +114,8 @@ static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, serve

static int pre_connection(conn_rec *c)
{
char *client_ip;

antiloris_config *conf = ap_get_module_config (c->base_server->module_config, &antiloris_module);
sb_handle *sbh = c->sbh;

Expand All @@ -128,14 +132,20 @@ static int pre_connection(conn_rec *c)
ws_record = &ap_scoreboard_image->servers[sbh->child_num][sbh->thread_num];
apr_cpystrn(ws_record->client, c->remote_ip, sizeof(ws_record->client));

char *client_ip = ws_record->client;
client_ip = ws_record->client;

/* Count up the number of connections we are handling right now from this IP address */
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
ws_record = ap_get_scoreboard_worker(i, j);
switch (ws_record->status) {
case SERVER_BUSY_READ:
case SERVER_BUSY_WRITE:
case SERVER_BUSY_KEEPALIVE:
case SERVER_BUSY_DNS:
case SERVER_BUSY_LOG:
case SERVER_CLOSING:
case SERVER_GRACEFUL:
if (strcmp(client_ip, ws_record->client) == 0)
ip_count++;
break;
Expand All @@ -146,7 +156,7 @@ static int pre_connection(conn_rec *c)
}

if (ip_count > conf->limit) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Rejected, too many connections in READ state from %s", c->remote_ip);
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "[client %s] Antiloris rejected, too many connections", c->remote_ip);
return OK;
} else {
return DECLINED;
Expand Down

0 comments on commit 23b1b70

Please sign in to comment.