|
|
@ -56,11 +56,6 @@ f2b_jail_apply_config(f2b_jail_t *jail, f2b_config_section_t *section) { |
|
|
|
jail->enabled = true; |
|
|
|
jail->enabled = true; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (strcmp(param->name, "incr_ban") == 0) { |
|
|
|
|
|
|
|
if (strcmp(param->value, "yes") == 0) |
|
|
|
|
|
|
|
jail->incr_ban = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (strcmp(param->name, "bantime") == 0) { |
|
|
|
if (strcmp(param->name, "bantime") == 0) { |
|
|
|
jail->bantime = atoi(param->value); |
|
|
|
jail->bantime = atoi(param->value); |
|
|
|
if (jail->bantime <= 0) |
|
|
|
if (jail->bantime <= 0) |
|
|
@ -79,6 +74,14 @@ f2b_jail_apply_config(f2b_jail_t *jail, f2b_config_section_t *section) { |
|
|
|
jail->maxretry = DEFAULT_MAXRETRY; |
|
|
|
jail->maxretry = DEFAULT_MAXRETRY; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (strcmp(param->name, "incr_bantime") == 0) { |
|
|
|
|
|
|
|
jail->incr_bantime = atof(param->value); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (strcmp(param->name, "incr_findtime") == 0) { |
|
|
|
|
|
|
|
jail->incr_findtime = atof(param->value); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
if (strcmp(param->name, "source") == 0) { |
|
|
|
if (strcmp(param->name, "source") == 0) { |
|
|
|
f2b_jail_parse_compound_value(param->value, jail->source_name, jail->source_init); |
|
|
|
f2b_jail_parse_compound_value(param->value, jail->source_name, jail->source_init); |
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -115,8 +118,12 @@ f2b_jail_ban(f2b_jail_t *jail, f2b_ipaddr_t *addr) { |
|
|
|
addr->matches.used = 0; |
|
|
|
addr->matches.used = 0; |
|
|
|
addr->banned = true; |
|
|
|
addr->banned = true; |
|
|
|
addr->banned_at = addr->lastseen; |
|
|
|
addr->banned_at = addr->lastseen; |
|
|
|
|
|
|
|
if (jail->incr_bantime > 0) { |
|
|
|
|
|
|
|
bantime = jail->bantime + (int) (addr->bancount * (jail->bantime * jail->incr_bantime)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
bantime = jail->bantime; |
|
|
|
|
|
|
|
} |
|
|
|
addr->bancount++; |
|
|
|
addr->bancount++; |
|
|
|
bantime = jail->bantime * ((jail->incr_ban) ? addr->bancount : 1); |
|
|
|
|
|
|
|
addr->release_at = addr->banned_at + bantime; |
|
|
|
addr->release_at = addr->banned_at + bantime; |
|
|
|
|
|
|
|
|
|
|
|
if (f2b_backend_check(jail->backend, addr->text)) { |
|
|
|
if (f2b_backend_check(jail->backend, addr->text)) { |
|
|
@ -126,7 +133,7 @@ f2b_jail_ban(f2b_jail_t *jail, f2b_ipaddr_t *addr) { |
|
|
|
|
|
|
|
|
|
|
|
if (f2b_backend_ban(jail->backend, addr->text)) { |
|
|
|
if (f2b_backend_ban(jail->backend, addr->text)) { |
|
|
|
f2b_log_msg(log_note, "jail '%s': banned ip %s for %.1fhrs", |
|
|
|
f2b_log_msg(log_note, "jail '%s': banned ip %s for %.1fhrs", |
|
|
|
jail->name, addr->text, bantime / 3600); |
|
|
|
jail->name, addr->text, (float) bantime / 3600); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -181,6 +188,7 @@ f2b_jail_process(f2b_jail_t *jail) { |
|
|
|
char logline[LOGLINE_MAX] = ""; |
|
|
|
char logline[LOGLINE_MAX] = ""; |
|
|
|
char matchbuf[IPADDR_MAX] = ""; |
|
|
|
char matchbuf[IPADDR_MAX] = ""; |
|
|
|
time_t now = time(NULL); |
|
|
|
time_t now = time(NULL); |
|
|
|
|
|
|
|
time_t findtime = 0; |
|
|
|
|
|
|
|
|
|
|
|
assert(jail != NULL); |
|
|
|
assert(jail != NULL); |
|
|
|
|
|
|
|
|
|
|
@ -210,7 +218,12 @@ f2b_jail_process(f2b_jail_t *jail) { |
|
|
|
f2b_log_msg(log_warn, "jail '%s': ip %s was already banned", jail->name, matchbuf); |
|
|
|
f2b_log_msg(log_warn, "jail '%s': ip %s was already banned", jail->name, matchbuf); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
f2b_matches_expire(&addr->matches, now - jail->findtime); |
|
|
|
if (jail->incr_findtime > 0) { |
|
|
|
|
|
|
|
findtime = now - jail->findtime - (int) (addr->bancount * (jail->findtime * jail->incr_findtime)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
findtime = now - jail->findtime; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
f2b_matches_expire(&addr->matches, findtime); |
|
|
|
f2b_matches_append(&addr->matches, now); |
|
|
|
f2b_matches_append(&addr->matches, now); |
|
|
|
if (addr->matches.used < jail->maxretry) { |
|
|
|
if (addr->matches.used < jail->maxretry) { |
|
|
|
f2b_log_msg(log_info, "jail '%s': new match %s (%d/%d)", jail->name, matchbuf, addr->matches.used, addr->matches.max); |
|
|
|
f2b_log_msg(log_info, "jail '%s': new match %s (%d/%d)", jail->name, matchbuf, addr->matches.used, addr->matches.max); |
|
|
|