From 8c60d320aed02dda92c75fbb2ac80e712a4d1bee Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Tue, 5 May 2020 14:57:50 +0100 Subject: [PATCH] Delete Object: fix issues related IP.Interface. and Bridging.Bridge. objects --- dmtree/tr181/bridging.c | 67 +++++++++++++++++++++++++++++++++-------- dmtree/tr181/ip.c | 24 ++++++++++++--- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index 62d0f963..91854321 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -792,32 +792,73 @@ static int addObjBridgingBridge(char *refparam, struct dmctx *ctx, void *data, c static int delObjBridgingBridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct uci_section *bridge_s = NULL, *dmmap_section = NULL; - char *bridgekey = NULL; + struct uci_section *bridge_s = NULL, *stmp = NULL, *dmmap_section = NULL; + char *bridgekey = NULL, *proto; switch (del_action) { case DEL_INST: + // Get dmmap section related to this interface bridge section get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridge_args *)data)->bridge_sec), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); - dmuci_set_value_by_section(((struct bridge_args *)data)->bridge_sec, "type", ""); - dmuci_set_value_by_section(((struct bridge_args *)data)->bridge_sec, "ifname", ""); + + // Read the proto option from interface bridge section + dmuci_get_value_by_section_string(((struct bridge_args *)data)->bridge_sec, "proto", &proto); + + // Check the proto value ==> if empty : there is no IP.Interface. object mapped to this interface bridge, remove the section + // Check the proto value ==> else : there is an IP.Interface. object mapped to this interface bridge, remove only type option from the section + if (*proto == '\0') { + /* proto is empty ==> remove interface bridge and dmmap section */ + + dmuci_delete_by_section(((struct bridge_args *)data)->bridge_sec, NULL, NULL); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + } else { + /* proto is not empty ==> remove only type option from the interface bridge section and bridge instance option from dmmap section */ + + dmuci_set_value_by_section(((struct bridge_args *)data)->bridge_sec, "type", ""); + dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); + } + + // Remove all bridge port sections related to this interface bridge section remove_bridge_sections("dmmap_bridge_port", "bridge_port", "br_inst", ((struct bridge_args *)data)->br_inst); + + // Remove all bridge vlan sections related to this interface bridge section remove_bridge_sections("dmmap_bridge_vlan", "bridge_vlan", "br_inst", ((struct bridge_args *)data)->br_inst); + + // Remove all bridge vlanport sections related to this interface bridge section remove_bridge_sections("dmmap_bridge_vlanport", "bridge_vlanport", "br_inst", ((struct bridge_args *)data)->br_inst); break; case DEL_ALL: - uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { + uci_foreach_option_eq_safe("network", "interface", "type", "bridge", stmp, bridge_s) { + + // Get dmmap section related to this interface bridge section get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(bridge_s), &dmmap_section); + + // Get bridge instance for each interface bridge section dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &bridgekey); - dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); - dmuci_set_value_by_section(bridge_s, "type", ""); - dmuci_set_value_by_section(bridge_s, "ifname", ""); + + // Read the proto option from interface bridge section + dmuci_get_value_by_section_string(bridge_s, "proto", &proto); + + // Check the proto value ==> if empty : there is no IP.Interface mapped to this interface bridge, remove the section + // Check the proto value ==> else : there is an IP.Interface mapped to this interface bridge, remove only type option from the section + if (*proto == '\0') { + /* proto is empty ==> remove interface bridge and dmmap section */ + + dmuci_delete_by_section(bridge_s, NULL, NULL); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + } else { + /* proto is not empty ==> remove only type option from the interface bridge section and bridge instance option from dmmap section */ + + dmuci_set_value_by_section(bridge_s, "type", ""); + dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); + } + + // Remove all bridge port sections related to this interface bridge section remove_bridge_sections("dmmap_bridge_port", "bridge_port", "br_inst", bridgekey); + + // Remove all bridge vlan sections related to this interface bridge section remove_bridge_sections("dmmap_bridge_vlan", "bridge_vlan", "br_inst", bridgekey); + + // Remove all bridge vlanport sections related to this interface bridge section remove_bridge_sections("dmmap_bridge_vlanport", "bridge_vlanport", "br_inst", bridgekey); } break; diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index a754bc0a..e1706711 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -1501,14 +1501,30 @@ static int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char static int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *dmmap_section = NULL; + char *type; switch (del_action) { case DEL_INST: - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ifname", ""); + // Get dmmap section related to this interface section get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); + + // Read the type option from interface section + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "type", &type); + + // Check the type value ==> if bridge : there is a Bridging.Bridge. object mapped to this interface, remove only proto option from the section + // Check the type value ==> else : there is no Bridging.Bridge. object mapped to this interface, remove the section + if (strcmp(type, "bridge") == 0) { + /* type is bridge ==> remove only proto option from the interface section and ip instance option from dmmap section */ + + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); + dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); + dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); + } else { + /* type is not bridge ==> remove interface and dmmap section */ + + dmuci_delete_by_section(((struct ip_args *)data)->ip_sec, NULL, NULL); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + } break; case DEL_ALL: return FAULT_9005;