From 504b14c549a6cda65dc77f0743455e98b5f18798 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 19 Jan 2021 15:23:53 +1000 Subject: [PATCH] * add 'jail $jail source stats' csocket command --- src/commands.c | 8 ++++++++ src/commands.h | 3 ++- src/daemon.c | 3 +++ src/source.c | 8 ++++++++ src/source.h | 5 +++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/commands.c b/src/commands.c index f42add1..1b8d040 100644 --- a/src/commands.c +++ b/src/commands.c @@ -70,6 +70,11 @@ struct cmd_desc { .argc = 2, .tokenc = 5, .tokens = { "jail", "", "ip", "release", "", NULL }, .help = "Forcefully release some ip in given jail", + }, { + .type = CMD_JAIL_SOURCE_STATS, + .argc = 1, .tokenc = 4, + .tokens = { "jail", "", "source", "stats", NULL }, + .help = "Show source stats for jail", }, { .type = CMD_JAIL_FILTER_STATS, .argc = 1, .tokenc = 4, @@ -191,6 +196,9 @@ f2b_cmd_parse(f2b_cmd_t *cmd, const char *src) { if (cmd->argc == 5 && strcmp(cmd->args[2], "ip") == 0 && strcmp(cmd->args[3], "release") == 0) { cmd->type = CMD_JAIL_IP_RELEASE; return true; } + if (cmd->argc == 4 && strcmp(cmd->args[2], "source") == 0 && strcmp(cmd->args[3], "stats") == 0) { + cmd->type = CMD_JAIL_SOURCE_STATS; return true; + } if (cmd->argc == 4 && strcmp(cmd->args[2], "filter") == 0 && strcmp(cmd->args[3], "stats") == 0) { cmd->type = CMD_JAIL_FILTER_STATS; return true; } diff --git a/src/commands.h b/src/commands.h index 2327ca1..82bcfcd 100644 --- a/src/commands.h +++ b/src/commands.h @@ -31,7 +31,8 @@ enum f2b_command_type { CMD_JAIL_IP_STATUS, /**< show status of given ip */ CMD_JAIL_IP_BAN, /**< force ban given ip */ CMD_JAIL_IP_RELEASE, /**< force unban given ip */ - CMD_JAIL_FILTER_STATS, /**< show stats of fileter matches */ + CMD_JAIL_SOURCE_STATS, /**< show stats of source */ + CMD_JAIL_FILTER_STATS, /**< show stats of filter matches */ CMD_JAIL_FILTER_RELOAD, /**< reload filter patterns from file */ CMD_MAX_NUMBER, /**< placeholder */ }; diff --git a/src/daemon.c b/src/daemon.c index 608af30..a4d077e 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -137,6 +137,9 @@ f2b_csocket_cmd_process(const f2b_cmd_t *cmd, f2b_buf_t *res) { } else if (cmd->type == CMD_JAIL_IP_RELEASE) { f2b_jail_cmd_ip_xxx(buf, sizeof(buf), jail, -1, cmd->args[4]); f2b_buf_append(res, buf, 0); + } else if (cmd->type == CMD_JAIL_SOURCE_STATS) { + f2b_source_cmd_stats(buf, sizeof(buf), jail->source); + f2b_buf_append(res, buf, 0); } else if (cmd->type == CMD_JAIL_FILTER_STATS) { f2b_filter_cmd_stats(buf, sizeof(buf), jail->filter); f2b_buf_append(res, buf, 0); diff --git a/src/source.c b/src/source.c index 1a7bae8..8f03993 100644 --- a/src/source.c +++ b/src/source.c @@ -109,3 +109,11 @@ f2b_source_ ## CMD(f2b_source_t *source) { \ SOURCE_CMD_ARG0(start, bool) SOURCE_CMD_ARG0(stop, bool) SOURCE_CMD_ARG0(ready, bool) + +void +f2b_source_cmd_stats(char *buf, size_t bufsize, f2b_source_t *source) { + assert(source != NULL); + assert(buf != NULL); + + source->stats(source->cfg, buf, bufsize); +} diff --git a/src/source.h b/src/source.h index b4ccb84..b09720c 100644 --- a/src/source.h +++ b/src/source.h @@ -76,4 +76,9 @@ bool f2b_source_next (f2b_source_t *s, char *buf, size_t bufsize, bool reset); */ bool f2b_source_stop (f2b_source_t *s); +/* handlers for csocket commands processing */ + +/** handler of 'jail $JAIL source stats' cmd */ +void f2b_source_cmd_stats (char *buf, size_t bufsize, f2b_source_t *f); + #endif /* F2B_SOURCE_H_ */