From b046830173a95b9f2d72865b3389174b7b7ff5d9 Mon Sep 17 00:00:00 2001 From: Brian Russell Date: Wed, 17 Feb 2021 15:51:45 +0000 Subject: policer: add api to configure input policing Add a new API to apply a policer to an input interface. Type: improvement Signed-off-by: Brian Russell Change-Id: Ie8aff9120149b63d85363a9a5afdcaed60a93700 --- src/vnet/policer/policer.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/vnet/policer/policer.c') diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c index fb2ce7598fa..678e5884cdd 100644 --- a/src/vnet/policer/policer.c +++ b/src/vnet/policer/policer.c @@ -165,6 +165,38 @@ policer_bind_worker (u8 *name, u32 worker, bool bind) return 0; } +int +policer_input (u8 *name, u32 sw_if_index, bool apply) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + policer_t *policer; + u32 policer_index; + uword *p; + + p = hash_get_mem (pm->policer_index_by_name, name); + if (p == 0) + { + return VNET_API_ERROR_NO_SUCH_ENTRY; + } + + policer = &pm->policers[p[0]]; + policer_index = policer - pm->policers; + + if (apply) + { + vec_validate (pm->policer_index_by_sw_if_index, sw_if_index); + pm->policer_index_by_sw_if_index[sw_if_index] = policer_index; + } + else + { + pm->policer_index_by_sw_if_index[sw_if_index] = ~0; + } + + vnet_feature_enable_disable ("device-input", "policer-input", sw_if_index, + apply, 0, 0); + return 0; +} + u8 * format_policer_instance (u8 * s, va_list * va) { -- cgit 1.2.3-korg