[MEDIUM] stats: add "clear table <name> key <value>" to clear table entries

This feature will be required at some point, when the stick tables are
used to enforce security measures. For instance, some visitors may be
incorrectly flagged as abusers and would ask the site admins to remove
their entry from the table.
This commit is contained in:
Willy Tarreau 2010-07-13 13:48:00 +02:00
parent 69f58c8058
commit 88ee39758a

View File

@ -57,6 +57,7 @@
const char stats_sock_usage_msg[] =
"Unknown command. Please enter one of the following commands only :\n"
" clear counters : clear max statistics counters (add 'all' for all counters)\n"
" clear table : remove an entry from a table\n"
" help : this message\n"
" prompt : toggle interactive mode with prompt\n"
" quit : disconnect\n"
@ -388,7 +389,7 @@ int stats_sock_parse_request(struct stream_interface *si, char *line)
s->data_ctx.table.entry = NULL;
si->st0 = STAT_CLI_O_TAB; // stats_dump_table_to_buffer
}
else { /* neither "stat" nor "info" nor "sess" nor "errors"*/
else { /* neither "stat" nor "info" nor "sess" nor "errors" no "table" */
return 0;
}
}
@ -443,7 +444,75 @@ int stats_sock_parse_request(struct stream_interface *si, char *line)
return 1;
}
else if (strcmp(args[1], "table") == 0) {
struct proxy *px;
struct stksess *ts;
unsigned int ip_key;
if (!*args[2]) {
s->data_ctx.cli.msg = "\"table\" argument expected.";
si->st0 = STAT_CLI_PRINT;
return 1;
}
px = find_stktable(args[2]);
if (!px) {
s->data_ctx.cli.msg = "No such table.";
si->st0 = STAT_CLI_PRINT;
return 1;
}
if (strcmp(args[3], "key") != 0) {
s->data_ctx.cli.msg = "\"key\" argument expected.";
si->st0 = STAT_CLI_PRINT;
return 1;
}
if (!*args[4]) {
s->data_ctx.cli.msg = "Key value expected.";
si->st0 = STAT_CLI_PRINT;
return 1;
}
if (px->table.type == STKTABLE_TYPE_IP) {
ip_key = htonl(inetaddr_host(args[4]));
static_table_key.key = (void *)&ip_key;
}
else {
s->data_ctx.cli.msg = "Removing keys from non-ip tables is not supported.";
si->st0 = STAT_CLI_PRINT;
return 1;
}
/* check permissions */
if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
s->data_ctx.cli.msg = stats_permission_denied_msg;
si->st0 = STAT_CLI_PRINT;
return 1;
}
ts = stktable_lookup_key(&px->table, &static_table_key);
if (!ts) {
/* silent return, entry was already removed */
return 1;
}
else if (ts->ref_cnt) {
/* don't delete an entry which is currently referenced */
s->data_ctx.cli.msg = "Entry currently in use, cannot remove.";
si->st0 = STAT_CLI_PRINT;
return 1;
}
eb32_delete(&ts->exp);
ebmb_delete(&ts->key);
stksess_free(&px->table, ts);
/* end of processing */
return 1;
}
else {
/* unknown "clear" argument */
return 0;
}
}