From 6178bdafa6a318d50cc8ad82f07c6c798c7024ef Mon Sep 17 00:00:00 2001 From: Benoît Ganne Date: Wed, 4 Nov 2020 10:02:03 +0100 Subject: feature: reset interface feature arc on interface deletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When removing an interface we must reset all per-interface per-feature arc data to ensure we do not get wrong feature arc config data when the sw_if_index is recycled. Type: fix Change-Id: I8c9d850d7c62b7b77193da4258ab5fb9bdda85a6 Signed-off-by: Benoît Ganne --- src/vnet/arp/arp.c | 13 ++------- src/vnet/config.c | 8 ++++++ src/vnet/config.h | 2 ++ src/vnet/feature/feature.c | 67 +++++++++++++++++++++++++++++++++++----------- src/vnet/interface.h | 2 ++ 5 files changed, 65 insertions(+), 27 deletions(-) (limited to 'src/vnet') diff --git a/src/vnet/arp/arp.c b/src/vnet/arp/arp.c index 8b57376522d..e02f3d8b52a 100644 --- a/src/vnet/arp/arp.c +++ b/src/vnet/arp/arp.c @@ -855,17 +855,8 @@ static clib_error_t * vnet_arp_add_del_sw_interface (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) { ethernet_arp_main_t *am = ðernet_arp_main; - - if (!is_add && sw_if_index != ~0) - { - arp_disable (am, sw_if_index); - } - else if (is_add) - { - vnet_feature_enable_disable ("arp", "arp-disabled", - sw_if_index, 1, NULL, 0); - } - + if (is_add) + arp_disable (am, sw_if_index); return (NULL); } diff --git a/src/vnet/config.c b/src/vnet/config.c index 4e9fa36dfc3..c9d4909cdeb 100644 --- a/src/vnet/config.c +++ b/src/vnet/config.c @@ -241,6 +241,14 @@ vnet_get_config_heap (vnet_config_main_t * cm, u32 ci) return heap_elt_at_index (cm->config_string_heap, ci); } +void +vnet_config_del (vnet_config_main_t * cm, u32 config_id) +{ + u32 *p = vnet_get_config_heap (cm, config_id); + vnet_config_t *old = pool_elt_at_index (cm->config_pool, p[-1]); + remove_reference (cm, old); +} + u32 vnet_config_modify_end_node (vlib_main_t * vm, vnet_config_main_t * cm, diff --git a/src/vnet/config.h b/src/vnet/config.h index 7eb3cf0ae1f..ccbbbf433e2 100644 --- a/src/vnet/config.h +++ b/src/vnet/config.h @@ -147,6 +147,8 @@ void vnet_config_init (vlib_main_t * vm, int n_start_node_names, char *feature_node_names[], int n_feature_node_names); +void vnet_config_del (vnet_config_main_t * cm, u32 config_id); + /* Calls to add/delete features from configurations. */ u32 vnet_config_add_feature (vlib_main_t * vm, vnet_config_main_t * cm, diff --git a/src/vnet/feature/feature.c b/src/vnet/feature/feature.c index 1bdd695e1de..c93f586c349 100644 --- a/src/vnet/feature/feature.c +++ b/src/vnet/feature/feature.c @@ -37,7 +37,7 @@ vnet_feature_register (vnet_feature_update_cb_t cb, void *data) } static void -vent_feature_reg_invoke (u32 sw_if_index, u8 arc_index, u8 is_enable) +vnet_feature_reg_invoke (u32 sw_if_index, u8 arc_index, u8 is_enable) { vnet_feature_upd_registration_t *reg; @@ -293,7 +293,7 @@ vnet_feature_enable_disable_with_index (u8 arc_index, u32 feature_index, fm->sw_if_index_has_features[arc_index] = clib_bitmap_set (fm->sw_if_index_has_features[arc_index], sw_if_index, (feature_count > 0)); - vent_feature_reg_invoke (sw_if_index, arc_index, (feature_count > 0)); + vnet_feature_reg_invoke (sw_if_index, arc_index, (feature_count > 0)); fm->feature_count_by_sw_if_index[arc_index][sw_if_index] = feature_count; return 0; @@ -515,9 +515,7 @@ vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index, int verbose) vlib_cli_output (vm, "\n%s:", areg->arc_name); areg = areg->next; - if (NULL == cm[feature_arc].config_index_by_sw_if_index || - vec_len (cm[feature_arc].config_index_by_sw_if_index) <= - sw_if_index) + if (!vnet_have_features (feature_arc, sw_if_index)) { vlib_cli_output (vm, " none configured"); continue; @@ -525,17 +523,8 @@ vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index, int verbose) current_config_index = vec_elt (cm[feature_arc].config_index_by_sw_if_index, sw_if_index); - - if (current_config_index == ~0) - { - vlib_cli_output (vm, " none configured"); - continue; - } - - ASSERT (current_config_index - < vec_len (vcm->config_pool_index_by_user_index)); - - cfg_index = vcm->config_pool_index_by_user_index[current_config_index]; + cfg_index = + vec_elt (vcm->config_pool_index_by_user_index, current_config_index); cfg = pool_elt_at_index (vcm->config_pool, cfg_index); for (i = 0; i < vec_len (cfg->features); i++) @@ -662,6 +651,52 @@ VLIB_CLI_COMMAND (set_interface_feature_command, static) = { }; /* *INDENT-ON* */ +static clib_error_t * +vnet_feature_add_del_sw_interface (vnet_main_t * vnm, u32 sw_if_index, + u32 is_add) +{ + vnet_feature_main_t *fm = &feature_main; + const vnet_feature_arc_registration_t *far; + + if (is_add) + return 0; + + /* + * remove all enabled features from an interface on deletion + */ + for (far = fm->next_arc; far != 0; far = far->next) + { + const u8 arc_index = far->feature_arc_index; + vnet_feature_config_main_t *cm = + vec_elt_at_index (fm->feature_config_mains, arc_index); + const u32 ci = + vec_len (cm->config_index_by_sw_if_index) <= + sw_if_index ? ~0 : vec_elt (cm->config_index_by_sw_if_index, + sw_if_index); + + if (~0 == ci) + continue; + + fm->sw_if_index_has_features[arc_index] = + clib_bitmap_set (fm->sw_if_index_has_features[arc_index], sw_if_index, + 0); + + vnet_feature_reg_invoke (sw_if_index, arc_index, 0); + + if (vec_len (fm->feature_count_by_sw_if_index[arc_index]) > sw_if_index) + vec_elt (fm->feature_count_by_sw_if_index[arc_index], sw_if_index) = + 0; + + vec_elt (cm->config_index_by_sw_if_index, sw_if_index) = ~0; + vnet_config_del (&cm->config_main, ci); + } + + return 0; +} + +VNET_SW_INTERFACE_ADD_DEL_FUNCTION_PRIO (vnet_feature_add_del_sw_interface, + VNET_ITF_FUNC_PRIORITY_HIGH); + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/vnet/interface.h b/src/vnet/interface.h index 5c04c5dc3bb..155e4fc1f0e 100644 --- a/src/vnet/interface.h +++ b/src/vnet/interface.h @@ -179,6 +179,8 @@ static __clib_unused void * __clib_unused_##f = f; _VNET_INTERFACE_FUNCTION_DECL(f,sw_interface_mtu_change) #define VNET_SW_INTERFACE_ADD_DEL_FUNCTION(f) \ _VNET_INTERFACE_FUNCTION_DECL(f,sw_interface_add_del) +#define VNET_SW_INTERFACE_ADD_DEL_FUNCTION_PRIO(f,p) \ + _VNET_INTERFACE_FUNCTION_DECL_PRIO(f,sw_interface_add_del,p) #define VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(f) \ _VNET_INTERFACE_FUNCTION_DECL(f,sw_interface_admin_up_down) #define VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION_PRIO(f,p) \ -- cgit 1.2.3-korg