Browse Source

* rename function: f2b_matches_append() -> f2b_matches_prepend()

master
Alex 'AdUser' Z 3 years ago
parent
commit
31ddadccbd
  1. 6
      src/jail.c
  2. 2
      src/matches.c
  3. 10
      src/matches.h
  4. 4
      t/t_matches.c

6
src/jail.c

@ -302,7 +302,7 @@ f2b_jail_process(f2b_jail_t *jail) {
f2b_log_msg(log_debug, "jail '%s': found new ip %s", jail->name, matchbuf); f2b_log_msg(log_debug, "jail '%s': found new ip %s", jail->name, matchbuf);
} }
addr->lastseen = now; addr->lastseen = now;
f2b_matches_append(&addr->matches, match); f2b_matches_prepend(&addr->matches, match);
match = NULL; /* will create new object on next run */ match = NULL; /* will create new object on next run */
if (addr->banned) { if (addr->banned) {
if (addr->banned_at != now) if (addr->banned_at != now)
@ -318,7 +318,7 @@ f2b_jail_process(f2b_jail_t *jail) {
findtime = now - jail->findtime; findtime = now - jail->findtime;
} }
f2b_matches_expire(&addr->matches, findtime); f2b_matches_expire(&addr->matches, findtime);
f2b_matches_append(&addr->matches, match); f2b_matches_prepend(&addr->matches, match);
if (addr->matches.count < jail->maxretry) { if (addr->matches.count < jail->maxretry) {
f2b_log_msg(log_info, "jail '%s': new match for ip %s (%zu/%zu)", f2b_log_msg(log_info, "jail '%s': new match for ip %s (%zu/%zu)",
jail->name, matchbuf, addr->matches.count, jail->maxretry); jail->name, matchbuf, addr->matches.count, jail->maxretry);
@ -605,7 +605,7 @@ f2b_jail_cmd_ip_xxx(char *res, size_t ressize, f2b_jail_t *jail, int op, const c
} }
addr->lastseen = now; addr->lastseen = now;
match = f2b_match_create(now); match = f2b_match_create(now);
f2b_matches_append(&addr->matches, match); f2b_matches_prepend(&addr->matches, match);
f2b_matches_flush(&addr->matches); f2b_matches_flush(&addr->matches);
jail->ipaddrs = f2b_addrlist_append(jail->ipaddrs, addr); jail->ipaddrs = f2b_addrlist_append(jail->ipaddrs, addr);
jail->stats.hosts++; jail->stats.hosts++;

2
src/matches.c

@ -32,7 +32,7 @@ f2b_matches_flush(f2b_matches_t *ms) {
} }
void void
f2b_matches_append(f2b_matches_t *ms, f2b_match_t *m) { f2b_matches_prepend(f2b_matches_t *ms, f2b_match_t *m) {
assert(ms != NULL); assert(ms != NULL);
assert(m != NULL); assert(m != NULL);

10
src/matches.h

@ -41,13 +41,11 @@ f2b_match_t * f2b_match_create(time_t t);
void f2b_matches_flush(f2b_matches_t *ms); void f2b_matches_flush(f2b_matches_t *ms);
/** /**
* @brief Push new match time to struct * @brief Insert new match to head of matches list
* @param m Pointer to struct * @param ms Matches list struct
* @param time Match time * @param match Match entry
* @param score Match score
* @returns true on success, false if capacity exceeded
*/ */
void f2b_matches_append (f2b_matches_t *ms, f2b_match_t *m); void f2b_matches_prepend (f2b_matches_t *ms, f2b_match_t *m);
/** /**
* @brief Remove matches before given time * @brief Remove matches before given time

4
t/t_matches.c

@ -16,7 +16,7 @@ int main() {
assert(match != NULL); assert(match != NULL);
assert(match->next == NULL); assert(match->next == NULL);
f2b_matches_append(&matches, match); f2b_matches_prepend(&matches, match);
assert(matches.count == 1); assert(matches.count == 1);
assert(matches.last == now); assert(matches.last == now);
assert(matches.list == match); assert(matches.list == match);
@ -28,7 +28,7 @@ int main() {
for (size_t i = 1; i < size; i++) { for (size_t i = 1; i < size; i++) {
match = f2b_match_create(now - 60 * (size - i)); match = f2b_match_create(now - 60 * (size - i));
f2b_matches_append(&matches, match); f2b_matches_prepend(&matches, match);
assert(matches.count == i); assert(matches.count == i);
assert(matches.last == now - (time_t) (60 * (size - i))); assert(matches.last == now - (time_t) (60 * (size - i)));
} }

Loading…
Cancel
Save