diff options
author | Dave Barach <dave@barachs.net> | 2020-07-29 18:07:02 -0400 |
---|---|---|
committer | Dave Barach <dave@barachs.net> | 2020-07-29 18:08:01 -0400 |
commit | caebbcf3cd19eff9dd505a89d12e26e331c77922 (patch) | |
tree | 11f4598722ec6d957ee6bfccb4b772be430fb931 | |
parent | 4c5343600d4fa4351816dd44a26c6a9b81e6b47e (diff) |
feature: add vnet_feature_is_enabled
A predicate function which says whether a given sw_if_index has a
certain feature enabled.
int vnet_feature_is_enabled (const char *arc_name,
const char *feature_node_name,
u32 sw_if_index)
returns 1 if the feature is enabled
returns 0 if the feature is not enabled
returns VNET_API_ERROR_INVALID_VALUE if the arc name is not found
returns VNET_API_ERROR_INVALID_VALUE_2 if the feature node name is not found
returns VNET_API_ERROR_INVALID_SW_IF_INDEX if the sw_if_index is not found
Type: improvement
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: Id9ed53e2ae9252efc750ae80fd610456b95cefa4
-rw-r--r-- | src/vnet/feature/feature.c | 57 | ||||
-rw-r--r-- | src/vnet/feature/feature.h | 4 |
2 files changed, 60 insertions, 1 deletions
diff --git a/src/vnet/feature/feature.c b/src/vnet/feature/feature.c index 09dd9cc965f..1bdd695e1de 100644 --- a/src/vnet/feature/feature.c +++ b/src/vnet/feature/feature.c @@ -15,7 +15,6 @@ #include <vnet/feature/feature.h> - vnet_feature_main_t feature_main; typedef struct vnet_feature_upd_registration_t_ @@ -321,6 +320,62 @@ vnet_feature_enable_disable (const char *arc_name, const char *node_name, n_feature_config_bytes); } +int +vnet_feature_is_enabled (const char *arc_name, const char *feature_node_name, + u32 sw_if_index) +{ + vnet_feature_main_t *fm = &feature_main; + vnet_feature_config_main_t *cm; + vnet_config_main_t *ccm; + vnet_config_t *current_config; + vnet_config_feature_t *f; + u32 feature_index; + u32 ci; + u8 arc_index; + u32 *p; + + arc_index = vnet_get_feature_arc_index (arc_name); + + /* No such arc? */ + if (arc_index == (u8) ~ 0) + return VNET_API_ERROR_INVALID_VALUE; + + feature_index = vnet_get_feature_index (arc_index, feature_node_name); + + /* No such feature? */ + if (feature_index == (u32) ~ 0) + return VNET_API_ERROR_INVALID_VALUE_2; + + cm = &fm->feature_config_mains[arc_index]; + + if (sw_if_index < vec_len (cm->config_index_by_sw_if_index)) + ci = vec_elt (cm->config_index_by_sw_if_index, sw_if_index); + else + /* sw_if_index out of range, certainly not enabled */ + return VNET_API_ERROR_INVALID_SW_IF_INDEX; + + /* No features were ever configured? */ + if (ci == ~0) + return 0; + + ccm = &cm->config_main; + + p = heap_elt_at_index (ccm->config_string_heap, ci); + + current_config = pool_elt_at_index (ccm->config_pool, p[-1]); + + /* Find feature with the required index */ + vec_foreach (f, current_config->features) + { + if (f->feature_index == feature_index) + /* Feature was enabled */ + return 1; + } + /* feature wasn't enabled */ + return 0; +} + + u32 vnet_feature_modify_end_node (u8 arc_index, u32 sw_if_index, u32 end_node_index) diff --git a/src/vnet/feature/feature.h b/src/vnet/feature/feature.h index 6eb6de3fba7..9aa32182ef6 100644 --- a/src/vnet/feature/feature.h +++ b/src/vnet/feature/feature.h @@ -488,6 +488,10 @@ typedef void (*vnet_feature_update_cb_t) (u32 sw_if_index, extern void vnet_feature_register (vnet_feature_update_cb_t cb, void *data); +int +vnet_feature_is_enabled (const char *arc_name, const char *feature_node_name, + u32 sw_if_index); + #endif /* included_feature_h */ /* |