From: Mike Stepanek (mstepane) Date: Wed, 9 Jun 2021 13:38:41 +0000 (+0000) Subject: Merge pull request #2931 in SNORT/snort3 from ~OSERHIIE/snort3:dump_config to master X-Git-Tag: 3.1.6.0~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f7be44ad9a5d39330f1d8d27de868e16976d127;p=thirdparty%2Fsnort3.git Merge pull request #2931 in SNORT/snort3 from ~OSERHIIE/snort3:dump_config to master Squashed commit of the following: commit ddc9f5cae9538ae04a1ce6f161a457b4bb217b53 Author: Oleksandr Serhiienko Date: Mon Jun 7 12:50:48 2021 +0300 main: fix config dump for list-based inspector aliases --- diff --git a/src/main/shell.cc b/src/main/shell.cc index cd2ce0b49..bf9ea951e 100644 --- a/src/main/shell.cc +++ b/src/main/shell.cc @@ -180,19 +180,20 @@ void Shell::config_open_table(bool is_root_node, bool is_list, int idx, if ( idx ) node_type = Parameter::PT_TABLE; - add_config_child_node(table_name, node_type); + add_config_child_node(table_name, node_type, idx); } } } -void Shell::add_config_child_node(const std::string& node_name, snort::Parameter::Type type) +void Shell::add_config_child_node(const std::string& node_name, snort::Parameter::Type type, + bool is_root_list_item) { if ( !s_config_output || !s_current_node ) return; - std::string name; - if ( s_current_node->get_name() != node_name ) - name = node_name; + // element of the top-level list is anonymous + std::string name = ( !is_root_list_item && s_current_node->get_name() != node_name ) ? + node_name : ""; auto new_node = new TreeConfigNode(s_current_node, name, type); s_current_node->add_child_node(new_node); diff --git a/src/main/shell.h b/src/main/shell.h index 356efeff3..93d0b804a 100644 --- a/src/main/shell.h +++ b/src/main/shell.h @@ -76,7 +76,8 @@ public: static void config_open_table(bool is_root_node, bool is_list, int idx, const std::string& table_name, const snort::Parameter* p); static void set_config_value(const std::string& fqn, const snort::Value& value); - static void add_config_child_node(const std::string& node_name, snort::Parameter::Type type); + static void add_config_child_node(const std::string& node_name, snort::Parameter::Type type, + bool is_root_list_item); static void update_current_config_node(const std::string& node_name = ""); static void config_close_table(); static void set_config_output(ConfigOutput* config_output); diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 10e85a15b..932c67b69 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -543,7 +543,7 @@ static bool begin(Module* m, const Parameter* p, const char* s, int idx, int dep { const Parameter* table_item_params = reinterpret_cast(p->range); - Shell::add_config_child_node(get_sub_table(fqn), p->type); + Shell::add_config_child_node(get_sub_table(fqn), p->type, false); if ( !begin(m, table_item_params, fqn.c_str(), idx, depth+1) ) return false;