Skip to content

Commit

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

-----BEGIN UPSTREAM CHANGELOG-----
Added compatibility with apache 2.4
-----END UPSTREAM CHANGELOG-----
  • Loading branch information
diovoemor authored and Deltik committed Feb 19, 2012
1 parent 23b1b70 commit 4ebab7b
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions mod_antiloris.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
mod_antiloris 0.5
mod_antiloris 0.5.1
Copyright (C) 2010 Monshouwer Internet Diensten
Author: Kees Monshouwer
Expand All @@ -25,11 +25,16 @@
#include "http_connection.h"
#include "http_log.h"
#include "ap_mpm.h"
#include "ap_release.h"
#include "apr_strings.h"
#include "scoreboard.h"

#define MODULE_NAME "mod_antiloris"
#define MODULE_VERSION "0.5"
#define MODULE_VERSION "0.5.1"

#ifdef APLOG_USE_MODULE
APLOG_USE_MODULE(antiloris);
#endif

module AP_MODULE_DECLARE_DATA antiloris_module;

Expand Down Expand Up @@ -61,7 +66,7 @@ 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;
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);
Expand All @@ -70,7 +75,7 @@ static const char *ipreadlimit_config_cmd(cmd_parms *parms, void *mconfig, const
return err;
}

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 @@ -85,7 +90,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 per IP address"),
AP_INIT_TAKE1("IPReadLimit", ipreadlimit_config_cmd, NULL, RSRC_CONF, "Maximum simultaneous connections per IP address"),
{NULL}
};

Expand All @@ -108,13 +113,14 @@ static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, serve
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME " " MODULE_VERSION " started");
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
ap_add_version_component(p, MODULE_NAME "/" MODULE_VERSION);
return OK;
}


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

antiloris_config *conf = ap_get_module_config (c->base_server->module_config, &antiloris_module);
sb_handle *sbh = c->sbh;
Expand All @@ -130,14 +136,18 @@ static int pre_connection(conn_rec *c)
worker_score *ws_record;

ws_record = &ap_scoreboard_image->servers[sbh->child_num][sbh->thread_num];
apr_cpystrn(ws_record->client, c->remote_ip, sizeof(ws_record->client));
apr_cpystrn(ws_record->client, c->client_ip, sizeof(ws_record->client));

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);
#if AP_SERVER_MAJORVERSION_NUMBER == 2 && AP_SERVER_MINORVERSION_NUMBER > 2
ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
#else
ws_record = ap_get_scoreboard_worker(i, j);
#endif
switch (ws_record->status) {
case SERVER_BUSY_READ:
case SERVER_BUSY_WRITE:
Expand All @@ -156,25 +166,18 @@ static int pre_connection(conn_rec *c)
}

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


static void child_init (apr_pool_t *p, server_rec *s)
{
ap_add_version_component(p, MODULE_NAME "/" MODULE_VERSION);
}


static void register_hooks(apr_pool_t *p)
{
ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_process_connection(pre_connection, NULL, NULL, APR_HOOK_FIRST);
ap_hook_child_init(child_init, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA antiloris_module = {
Expand Down

0 comments on commit 4ebab7b

Please sign in to comment.