diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index 46cb3101..af29f86c 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -1813,11 +1813,15 @@ static int delObjBridgingBridgeVLANPort(char *refparam, struct dmctx *ctx, void static int addObjBridgingBridgeVLAN(char *refparam, struct dmctx *ctx, void *data, char **instance) { struct uci_section *br_vlan_s = NULL; + char vlan_name[32]= {0}; int inst = get_last_inst("dmmap_bridge_vlan", "bridge_vlan", "br_inst", "bridge_vlan_instance", ((struct bridge_args *)data)->br_inst); dmasprintf(instance, "%d", inst+1); + snprintf(vlan_name, sizeof(vlan_name), "br_%s_vlan_%s", ((struct bridge_args *)data)->br_inst, *instance); + dmuci_add_section_bbfdm("dmmap_bridge_vlan", "bridge_vlan", &br_vlan_s); + dmuci_set_value_by_section(br_vlan_s, "name", vlan_name); dmuci_set_value_by_section(br_vlan_s, "br_inst", ((struct bridge_args *)data)->br_inst); dmuci_set_value_by_section(br_vlan_s, "bridge_vlan_instance", *instance); dmuci_set_value_by_section(br_vlan_s, "device", ((struct bridge_args *)data)->bridge_sec_name); @@ -2646,33 +2650,19 @@ static int set_BridgingBridgeVLAN_Alias(char *refparam, struct dmctx *ctx, void static int get_BridgingBridgeVLAN_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct bridge_vlan_args *)data)->bridge_vlan_sec, "device", value); + dmuci_get_value_by_section_string(((struct bridge_vlan_args *)data)->bridge_vlan_sec, "name", value); return 0; } static int set_BridgingBridgeVLAN_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *s = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 64, NULL, NULL)) return FAULT_9007; return 0; case VALUESET: - dmuci_rename_section_by_section(((struct bridge_vlan_args *)data)->bridge_sec, value); - - // Update name in dmmap_bridge section of this bridge instance - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge", "device", "bridge_instance", ((struct bridge_vlan_args *)data)->br_inst, s) { - dmuci_set_value_by_section(s, "section_name", value); - } - - // Update name in dmmap_bridge_port sections of this bridge instance - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", ((struct bridge_vlan_args *)data)->br_inst, s) { - dmuci_set_value_by_section(s, "device_section_name", value); - } - - // Update name in dmmap_bridge_vlan section of this bridge instance - dmuci_set_value_by_section(((struct bridge_vlan_args *)data)->bridge_vlan_sec, "device", value); + dmuci_set_value_by_section(((struct bridge_vlan_args *)data)->bridge_vlan_sec, "name", value); return 0; } return 0; diff --git a/dmtree/tr181/dynamicdns.c b/dmtree/tr181/dynamicdns.c index cbda1195..a0fd9be0 100644 --- a/dmtree/tr181/dynamicdns.c +++ b/dmtree/tr181/dynamicdns.c @@ -697,6 +697,7 @@ static int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *da { struct uci_section *s; char *service_name; + char *curr_sec_name; switch (action) { case VALUECHECK: @@ -704,12 +705,24 @@ static int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *da return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "section_name", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &curr_sec_name); dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name); + + // Setting section name + dmuci_set_value_by_section((struct uci_section *)data, "section_name", value); + + // Update section name of config ddns service section uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) { dmuci_rename_section_by_section(s, value); break; } + + // Update section name of dmmap_ddns service section + uci_path_foreach_option_eq(bbfdm, "dmmap_ddns", "service", "section_name", curr_sec_name, s) { + dmuci_set_value_by_section(s, "section_name", value); + break; + } + break; } return 0; diff --git a/dmtree/tr181/users.c b/dmtree/tr181/users.c index 17c25829..d6c2d9f8 100644 --- a/dmtree/tr181/users.c +++ b/dmtree/tr181/users.c @@ -106,7 +106,7 @@ static int get_user_enable(char *refparam, struct dmctx *ctx, void *data, char * static int get_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmstrdup(section_name(((struct dmmap_dup *)data)->config_section)); + dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "section_name", value); return 0; } diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index 53483ce9..d11dd652 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -264,10 +264,14 @@ struct uci_section *get_origin_section_from_config(char *package, char *section_ struct uci_section *s = NULL; uci_foreach_sections(package, section_type, s) { - if (strcmp(section_name(s), orig_section_name) == 0) { + char sec_name[32] = {0}; + + dmuci_replace_invalid_characters_from_section_name(orig_section_name, sec_name, sizeof(sec_name)); + + if (strcmp(section_name(s), sec_name) == 0) return s; - } } + return NULL; } @@ -275,8 +279,15 @@ struct uci_section *get_dup_section_in_dmmap(char *dmmap_package, char *section_ { struct uci_section *s; - uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, "section_name", orig_section_name, s) { - return s; + uci_path_foreach_sections(bbfdm, dmmap_package, section_type, s) { + char *dmmap_sec_name = NULL; + char sec_name[32] = {0}; + + dmuci_get_value_by_section_string(s, "section_name", &dmmap_sec_name); + dmuci_replace_invalid_characters_from_section_name(dmmap_sec_name, sec_name, sizeof(sec_name)); + + if (strcmp(sec_name, orig_section_name) == 0) + return s; } return NULL; diff --git a/libbbf_api/dmuci.c b/libbbf_api/dmuci.c index 9d97b978..6c0ae27b 100644 --- a/libbbf_api/dmuci.c +++ b/libbbf_api/dmuci.c @@ -555,8 +555,11 @@ int dmuci_delete(char *package, char *section, char *option, char *value) int dmuci_rename_section(char *package, char *section, char *value) { struct uci_ptr ptr = {0}; + char sec_name[32] = {0}; - if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, NULL, value)) + dmuci_replace_invalid_characters_from_section_name(value, sec_name, sizeof(sec_name)); + + if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, NULL, sec_name)) return -1; if (uci_rename(uci_ctx, &ptr) != UCI_OK) @@ -750,8 +753,11 @@ int dmuci_del_list_value_by_section(struct uci_section *s, char *option, char *v int dmuci_rename_section_by_section(struct uci_section *s, char *value) { struct uci_ptr up = {0}; + char sec_name[32] = {0}; - if (dmuci_lookup_ptr_by_section(uci_ctx, &up, s, NULL, value) == -1) + dmuci_replace_invalid_characters_from_section_name(value, sec_name, sizeof(sec_name)); + + if (dmuci_lookup_ptr_by_section(uci_ctx, &up, s, NULL, sec_name) == -1) return -1; if (uci_rename(uci_ctx, &up) != UCI_OK) @@ -924,3 +930,19 @@ bool dmuci_string_to_boolean(char *value) return false; } +void dmuci_replace_invalid_characters_from_section_name(char *old_sec_name, char *new_sec_name, size_t len) +{ + *new_sec_name = 0; + + if (!DM_STRLEN(old_sec_name)) + return; + + DM_STRNCPY(new_sec_name, old_sec_name, len); + + for (int i = 0; i < strlen(new_sec_name); i++) { + + // Replace all {'.' or '-'} with '_' + if (new_sec_name[i] == '.' || new_sec_name[i] == '-') + new_sec_name[i] = '_'; + } +} diff --git a/libbbf_api/dmuci.h b/libbbf_api/dmuci.h index 71fb5425..2db3a99d 100644 --- a/libbbf_api/dmuci.h +++ b/libbbf_api/dmuci.h @@ -377,6 +377,7 @@ int dmuci_set_value_varstate(char *package, char *section, char *option, char *v char *dmuci_get_value_by_path(char *path, char *package, char *section, char *option); char *dmuci_set_value_by_path(char *path, char *package, char *section, char *option, char *value); bool dmuci_string_to_boolean(char *value); +void dmuci_replace_invalid_characters_from_section_name(char *old_sec_name, char *new_sec_name, size_t len); #endif