Skip to content
Snippets Groups Projects

Use name option as unique key to identify the sections

Merged Amin Ben Romdhane requested to merge firewall_name into devel
2 files
+ 17
13
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 16
12
@@ -96,32 +96,34 @@ static void free_firewall_config_dup_list(struct list_head *dup_list)
}
void synchronize_firewall_sections_with_dmmap(const char *package, const char *section_type, const char *dmmap_package,
bool is_dynamic_rule, struct list_head *dup_list)
const char *option_name, bool is_dynamic_rule, struct list_head *dup_list)
{
struct uci_section *s, *stmp, *dmmap_sect;
char *v;
struct uci_section *s = NULL, *stmp = NULL, *dmmap_sec = NULL;
char *option_value = NULL;
uci_foreach_sections(package, section_type, s) {
dmuci_get_value_by_section_string(s, option_name, &option_value);
/*
* create/update corresponding dmmap section that have same config_section link and using param_value_array
*/
if ((dmmap_sect = get_dup_section_in_dmmap(dmmap_package, section_type, section_name(s))) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, section_type, &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(s));
if ((dmmap_sec = get_dup_section_in_dmmap_opt(dmmap_package, section_type, option_name, option_value)) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, section_type, &dmmap_sec);
dmuci_set_value_by_section_bbfdm(dmmap_sec, option_name, option_value);
}
/*
* Add system and dmmap sections to the list
*/
add_firewall_config_dup_list(dup_list, s, dmmap_sect, is_dynamic_rule);
add_firewall_config_dup_list(dup_list, s, dmmap_sec, is_dynamic_rule);
}
/*
* Delete unused dmmap sections
*/
uci_path_foreach_sections_safe(bbfdm, dmmap_package, section_type, stmp, s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if (get_origin_section_from_config(package, section_type, v) == NULL)
dmuci_get_value_by_section_string(s, option_name, &option_value);
if (get_dup_section_in_config_opt(package, section_type, option_name, option_value) == NULL)
dmuci_delete_by_section(s, NULL, NULL);
}
}
@@ -301,7 +303,7 @@ static int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_d
if (DM_STRCMP(creator, "Defaults") == 0) {
// Forwarding sections
synchronize_firewall_sections_with_dmmap("firewall", "forwarding", "dmmap_firewall", true, &dup_list);
synchronize_firewall_sections_with_dmmap("firewall", "forwarding", "dmmap_firewall", "name", true, &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "firewall_chain_rule_instance", "firewall_chain_rule_alias");
@@ -324,7 +326,7 @@ static int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_d
free_firewall_config_dup_list(&dup_list);
// Rule sections
synchronize_firewall_sections_with_dmmap("firewall", "rule", "dmmap_firewall", false, &dup_list);
synchronize_firewall_sections_with_dmmap("firewall", "rule", "dmmap_firewall", "name", false, &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "firewall_chain_rule_instance", "firewall_chain_rule_alias");
@@ -470,6 +472,7 @@ static int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char
dmuci_set_value_by_section(s, "enabled", "0");
dmuci_set_value_by_section(s, "target", "DROP");
dmuci_set_value_by_section(s, "proto", "0");
dmuci_set_value_by_section(s, "name", s_name);
// Update rule section order
snprintf(buf, sizeof(buf), "%lu", DM_STRTOUL(rule_start_pos) + DM_STRTOUL(rules_num));
@@ -480,7 +483,7 @@ static int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char
dmuci_set_value_by_section(chain_args, "rules_num", buf);
dmuci_add_section_bbfdm("dmmap_firewall", "rule", &dmmap_firewall_rule);
dmuci_set_value_by_section(dmmap_firewall_rule, "section_name", s_name);
dmuci_set_value_by_section(dmmap_firewall_rule, "name", s_name);
dmuci_set_value_by_section(dmmap_firewall_rule, "creation_date", creation_date);
dmuci_set_value_by_section(dmmap_firewall_rule, "firewall_chain_rule_instance", *instance);
return 0;
@@ -1569,6 +1572,7 @@ static int set_rule_description(char *refparam, struct dmctx *ctx, void *data, c
break;
dmuci_set_value_by_section(p->config_section, "name", value);
dmuci_set_value_by_section(p->dmmap_section, "name", value);
break;
}
return 0;
Loading