diff --git a/src/firewall.c b/src/firewall.c index 65128d4767ee0eec20db63af61569b781c3518af..7757b812b1bc534a9a5917e8afc36f7e96af4afe 100644 --- a/src/firewall.c +++ b/src/firewall.c @@ -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; diff --git a/src/nat.c b/src/nat.c index 647704e95f4dfb9cb655e2e6ce8a961f40614d32..d2d72c6f8bd9030021191559bae97dcef6469a77 100644 --- a/src/nat.c +++ b/src/nat.c @@ -25,7 +25,7 @@ static int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); - synchronize_specific_config_sections_with_dmmap("firewall", "zone", "dmmap_firewall", &dup_list); + synchronize_specific_config_sections_with_dmmap_option("firewall", "zone", "dmmap_firewall", "name", &dup_list); list_for_each_entry(curr_data, &dup_list, list) { inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "interface_setting_instance", "interface_setting_alias");