X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fpolicer%2Fpolicer.c;h=9611fe0fa4e6534f99109f6354da31e620ab0b23;hb=b7b929931a07fbb27b43d5cd105f366c3e29807e;hp=290a6af57e25fb12c1f94f557cc4b09194b837ec;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c index 290a6af57e2..9611fe0fa4e 100644 --- a/src/vnet/policer/policer.c +++ b/src/vnet/policer/policer.c @@ -16,6 +16,8 @@ #include #include +vnet_policer_main_t vnet_policer_main; + clib_error_t * policer_add_del (vlib_main_t * vm, u8 * name, @@ -33,13 +35,26 @@ policer_add_del (vlib_main_t * vm, if (is_add == 0) { + /* free policer config and template */ if (p == 0) { vec_free (name); return clib_error_return (0, "No such policer configuration"); } + pool_put_index (pm->configs, p[0]); + pool_put_index (pm->policer_templates, p[0]); hash_unset_mem (pm->policer_config_by_name, name); + + /* free policer */ + p = hash_get_mem (pm->policer_index_by_name, name); + if (p == 0) + { + vec_free (name); + return clib_error_return (0, "No such policer"); + } + pool_put_index (pm->policers, p[0]); hash_unset_mem (pm->policer_index_by_name, name); + vec_free (name); return 0; } @@ -413,12 +428,13 @@ configure_policer_command_fn (vlib_main_t * vm, u8 is_add = 1; u8 *name = 0; u32 pi; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; - memset (&c, 0, sizeof (c)); + clib_memset (&c, 0, sizeof (c)); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { @@ -433,13 +449,19 @@ configure_policer_command_fn (vlib_main_t * vm, foreach_config_param #undef _ else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + error = policer_add_del (vm, name, &c, &pi, is_add); + +done: unformat_free (line_input); - return policer_add_del (vm, name, &c, &pi, is_add); + return error; } /* *INDENT-OFF* */ @@ -493,6 +515,27 @@ VLIB_CLI_COMMAND (show_policer_command, static) = { }; /* *INDENT-ON* */ +static clib_error_t * +show_policer_pools_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + + vlib_cli_output (vm, "pool sizes: configs=%d templates=%d policers=%d", + pool_elts (pm->configs), + pool_elts (pm->policer_templates), + pool_elts (pm->policers)); + return 0; +} +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_policer_pools_command, static) = { + .path = "show policer pools", + .short_help = "show policer pools", + .function = show_policer_pools_command_fn, +}; +/* *INDENT-ON* */ + clib_error_t * policer_init (vlib_main_t * vm) {