From 41852aa0b20bc3cad96c517d8a903d4eb5dcb0e2 Mon Sep 17 00:00:00 2001 From: Mikhail Sennikovsky Date: Wed, 29 Jun 2022 19:09:39 +0200 Subject: conntrack: generalize command parsing Currently the -U command has a special case handling in the do_parse because it does not have EXP_ counterpart. Generalizing it would simplify adding support for new commands w/o EXP_ counterpart. As a preparation step for adding the new "-A" command support, make the -U command be handled the same way as the rest. Signed-off-by: Mikhail Sennikovsky Signed-off-by: Pablo Neira Ayuso --- src/conntrack.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/conntrack.c') diff --git a/src/conntrack.c b/src/conntrack.c index d49ac1a..a0468f3 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -446,6 +446,7 @@ static const int cmd2type[][2] = { ['h'] = { CT_HELP, CT_HELP }, ['C'] = { CT_COUNT, EXP_COUNT }, ['S'] = { CT_STATS, EXP_STATS }, + ['U'] = { CT_UPDATE, 0 }, }; static const int opt2type[] = { @@ -2995,15 +2996,6 @@ static void do_parse(struct ct_cmd *ct_cmd, int argc, char *argv[]) case 'h': case 'C': case 'S': - type = check_type(argc, argv); - if (type == CT_TABLE_DYING || - type == CT_TABLE_UNCONFIRMED) { - exit_error(PARAMETER_PROBLEM, - "Can't do that command with " - "tables `dying' and `unconfirmed'"); - } - add_command(&command, cmd2type[c][type]); - break; case 'U': type = check_type(argc, argv); if (type == CT_TABLE_DYING || @@ -3011,11 +3003,16 @@ static void do_parse(struct ct_cmd *ct_cmd, int argc, char *argv[]) exit_error(PARAMETER_PROBLEM, "Can't do that command with " "tables `dying' and `unconfirmed'"); - } else if (type == CT_TABLE_CONNTRACK) - add_command(&command, CT_UPDATE); - else + } + if (cmd2type[c][type]) + add_command(&command, cmd2type[c][type]); + else { exit_error(PARAMETER_PROBLEM, - "Can't update expectations"); + "Can't do --%s on %s", + get_long_opt(c), + type == CT_TABLE_CONNTRACK ? + "conntrack" : "expectations"); + } break; /* options */ case 's': -- cgit v1.2.3