From f9d2c345f1a2208005b2eac521e15aed0d2c09eb Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Wed, 26 Aug 2020 11:24:46 +0100 Subject: [PATCH] Ticket refs #2974: Referenced objects have trailing dot --- dmtree/tr143/diagnostics.c | 8 +++++-- dmtree/tr181/bridging.c | 22 ++++--------------- dmtree/tr181/dhcpv4.c | 38 +++++++++++++-------------------- dmtree/tr181/dhcpv6.c | 27 +++++++++-------------- dmtree/tr181/dns.c | 8 +++++-- dmtree/tr181/dynamicdns.c | 10 +++++---- dmtree/tr181/ethernet.c | 10 ++------- dmtree/tr181/firewall.c | 16 +++++++++----- dmtree/tr181/interfacestack.c | 10 ++++----- dmtree/tr181/ip.c | 9 +++----- dmtree/tr181/nat.c | 8 +++++-- dmtree/tr181/ppp.c | 9 +++----- dmtree/tr181/qos-iopsyswrt.c | 15 ++++++++++--- dmtree/tr181/qos-openwrt.c | 4 +++- dmtree/tr181/routing.c | 10 +++++---- dmtree/tr181/times.c | 9 +++++--- dmtree/tr181/wifi.c | 9 +++----- dmtree/tr181/x_iopsys_eu_igmp.c | 12 +++++------ dmtree/tr181/x_iopsys_eu_mld.c | 5 ++++- dmtree/tr181/x_iopsys_eu_owsd.c | 5 +++-- libbbf_api/dmbbf.c | 2 ++ libbbf_api/dmcommon.c | 9 ++++++++ libbbf_api/dmcommon.h | 1 + 23 files changed, 132 insertions(+), 124 deletions(-) diff --git a/dmtree/tr143/diagnostics.c b/dmtree/tr143/diagnostics.c index 09bd9b09..e6f1e2d0 100644 --- a/dmtree/tr143/diagnostics.c +++ b/dmtree/tr143/diagnostics.c @@ -654,6 +654,7 @@ static int set_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct { char *linker = NULL, *tmp, *device = NULL; struct uci_section *curr_section = NULL; + char interface[256] = {0}; json_object *res; switch (action) { @@ -662,7 +663,8 @@ static int set_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct return FAULT_9007; return 0; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", linker, String}}, 1, &res); if (!res) return 0; @@ -1043,6 +1045,7 @@ static int set_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct d { char *linker = NULL, *tmp, *device = NULL; struct uci_section *curr_section = NULL; + char interface[256] = {0}; json_object *res; switch (action) { @@ -1051,7 +1054,8 @@ static int set_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct d return FAULT_9007; return 0; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", linker, String}}, 1, &res); if (!res) return 0; diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index b60323e5..245407cc 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -652,10 +652,7 @@ static void set_lowerlayers_management_port(struct dmctx *ctx, void *data, char p = new_device; for (pch = strtok_r(value, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { - if (pch[strlen(pch)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", pch); - else - strncpy(lower_layer, pch, sizeof(lower_layer) - 1); + append_dot_to_string(lower_layer, pch, sizeof(lower_layer)); snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.Port.", ((struct bridge_port_args *)data)->br_inst); @@ -1451,10 +1448,7 @@ static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, } else { /* Management Port ==> false */ - if (value[strlen(value)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", value); - else - strncpy(lower_layer, value, sizeof(lower_layer) - 1); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); char *linker = NULL; adm_entry_get_linker_value(ctx, lower_layer, &linker); @@ -2026,11 +2020,7 @@ static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo return FAULT_9007; return 0; case VALUESET: - if (value[strlen(value)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", value); - else - strncpy(lower_layer, value, sizeof(lower_layer) - 1); - + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.VLAN.", ((struct bridge_vlanport_args *)data)->br_inst); /* Check the path object is correct or no */ @@ -2114,11 +2104,7 @@ static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo return FAULT_9007; return 0; case VALUESET: - if (value[strlen(value)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", value); - else - strncpy(lower_layer, value, sizeof(lower_layer) - 1); - + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.Port.", ((struct bridge_vlanport_args *)data)->br_inst); if (strncmp(lower_layer, lower_layer_path, strlen(lower_layer_path)) == 0) { diff --git a/dmtree/tr181/dhcpv4.c b/dmtree/tr181/dhcpv4.c index 2eaf2a88..ff3531ad 100644 --- a/dmtree/tr181/dhcpv4.c +++ b/dmtree/tr181/dhcpv4.c @@ -1157,6 +1157,7 @@ static int get_dhcp_interface(char *refparam, struct dmctx *ctx, void *data, cha static int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char interface[256] = {0}; char *linker; switch (action) { @@ -1165,7 +1166,8 @@ static int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx return FAULT_9007; return 0; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) { dmuci_set_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "interface", linker); dmfree(linker); @@ -1477,7 +1479,8 @@ static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; - char *linker = NULL, *newvalue = NULL, *v; + char *linker = NULL, *v; + char interface[256] = {0}; switch (action) { case VALUECHECK: @@ -1487,11 +1490,8 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d if(strlen(value) == 0 || strcmp(value, "") == 0) return FAULT_9007; - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", s) { dmuci_get_value_by_section_string(s, "section_name", &v); if(strcmp(v, linker) == 0) @@ -1506,11 +1506,8 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d } break; case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker); break; } @@ -2179,7 +2176,8 @@ static int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; - char *linker = NULL, *newvalue = NULL, *v; + char *linker = NULL, *v; + char interface[256] = {0}; switch (action) { case VALUECHECK: @@ -2189,11 +2187,8 @@ static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx if (strlen(value) == 0 || strcmp(value, "") == 0) return FAULT_9007; - if (value[strlen(value)-1] != '.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker == NULL) return FAULT_9007; uci_path_foreach_sections(bbfdm, "dmmap_dhcp_relay", "interface", s) { @@ -2210,11 +2205,8 @@ static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx } break; case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker); break; } diff --git a/dmtree/tr181/dhcpv6.c b/dmtree/tr181/dhcpv6.c index 8d0e787f..4b2b5559 100644 --- a/dmtree/tr181/dhcpv6.c +++ b/dmtree/tr181/dhcpv6.c @@ -557,23 +557,19 @@ static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; - char *linker = NULL, *newvalue = NULL, *v; + char *linker = NULL, *v; + char interface[256] = {0}; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0)) return FAULT_9007; - if (strlen(value) == 0 || strcmp(value, "") == 0) { + if (strlen(value) == 0 || strcmp(value, "") == 0) return FAULT_9007; - } - if (value[strlen(value)-1] != '.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else { - adm_entry_get_linker_value(ctx, value, &linker); - } + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); uci_path_foreach_sections(bbfdm, "dmmap_dhcpv6", "interface", s) { dmuci_get_value_by_section_string(s, "section_name", &v); if (strcmp(v, linker) == 0) @@ -588,12 +584,8 @@ static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d } break; case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else { - adm_entry_get_linker_value(ctx, value, &linker); - } + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_args *)data)->dhcp_client_dm, "section_name", linker); break; } @@ -914,7 +906,7 @@ static int get_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, voi static int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker; + char interface[256] = {0}, *linker; switch (action) { case VALUECHECK: @@ -922,7 +914,8 @@ static int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, voi return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) { dmuci_set_value_by_section(((struct dhcpv6_args *)data)->dhcp_sec, "interface", linker); dmfree(linker); diff --git a/dmtree/tr181/dns.c b/dmtree/tr181/dns.c index 283ab2e5..59c6a9c8 100644 --- a/dmtree/tr181/dns.c +++ b/dmtree/tr181/dns.c @@ -639,6 +639,7 @@ static int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data, static int set_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *ointerface, *ip, *interface; + char intf[256] = {0}; switch (action) { case VALUECHECK: @@ -646,8 +647,9 @@ static int set_server_interface(char *refparam, struct dmctx *ctx, void *data, c return FAULT_9007; break; case VALUESET: + append_dot_to_string(intf, value, sizeof(intf)); + adm_entry_get_linker_value(ctx, intf, &interface); dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &ointerface); - adm_entry_get_linker_value(ctx, value, &interface); if (strcmp(ointerface, interface) == 0) return 0; dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str); @@ -774,6 +776,7 @@ static int set_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *da static int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *ointerface, *ip, *interface; + char intf[256] = {0}; switch (action) { case VALUECHECK: @@ -781,8 +784,9 @@ static int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *dat return FAULT_9007; break; case VALUESET: + append_dot_to_string(intf, value, sizeof(intf)); + adm_entry_get_linker_value(ctx, intf, &interface); dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &ointerface); - adm_entry_get_linker_value(ctx, value, &interface); if (strcmp(ointerface, interface) == 0) return 0; dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str); diff --git a/dmtree/tr181/dynamicdns.c b/dmtree/tr181/dynamicdns.c index 8699a135..295766a8 100644 --- a/dmtree/tr181/dynamicdns.c +++ b/dmtree/tr181/dynamicdns.c @@ -473,7 +473,7 @@ static int get_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void * static int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker = NULL; + char lower_layer[256] = {0}, *linker = NULL; switch (action) { case VALUECHECK: @@ -481,7 +481,8 @@ static int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void * return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); + adm_entry_get_linker_value(ctx, lower_layer, &linker); if (linker) dmuci_set_value_by_section((struct uci_section *)data, "service_name", linker); else @@ -504,7 +505,7 @@ static int get_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, voi static int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker = NULL; + char interface[256] = {0}, *linker = NULL; switch (action) { case VALUECHECK: @@ -512,7 +513,8 @@ static int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, voi return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) dmuci_set_value_by_section((struct uci_section *)data, "interface", linker); else diff --git a/dmtree/tr181/ethernet.c b/dmtree/tr181/ethernet.c index 242e16f8..1a2f7cad 100644 --- a/dmtree/tr181/ethernet.c +++ b/dmtree/tr181/ethernet.c @@ -992,10 +992,7 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void return FAULT_9007; break; case VALUESET: - if (value[strlen(value)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", value); - else - strncpy(lower_layer, value, sizeof(lower_layer) - 1); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); if (strncmp(lower_layer, "Device.Ethernet.Interface.", 26) == 0) { char *linker, *int_name; @@ -1218,10 +1215,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx return FAULT_9007; break; case VALUESET: - if (value[strlen(value)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", value); - else - strncpy(lower_layer, value, sizeof(lower_layer) - 1); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); if (strncmp(lower_layer, "Device.Ethernet.Link.", 21) == 0) { char new_name[16] = {0}, *linker = NULL, *type; diff --git a/dmtree/tr181/firewall.c b/dmtree/tr181/firewall.c index 349efdb6..b6d72f5e 100644 --- a/dmtree/tr181/firewall.c +++ b/dmtree/tr181/firewall.c @@ -140,7 +140,7 @@ static int get_firewall_config(char *refparam, struct dmctx *ctx, void *data, ch static int get_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "Device.Firewall.Level.1."; + *value = "Device.Firewall.Level.1"; return 0; } @@ -178,7 +178,7 @@ static int get_level_description(char *refparam, struct dmctx *ctx, void *data, static int get_level_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "Device.Firewall.Chain.1."; + *value = "Device.Firewall.Chain.1"; return 0; } @@ -906,18 +906,21 @@ static int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *da { char *iface, *zone, *net; struct uci_section *s = NULL; + char interface[256] = {0}; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0)) return FAULT_9007; - adm_entry_get_linker_value(ctx, value, &iface); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &iface); if (iface == NULL || iface[0] == '\0') return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &iface); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &iface); if (iface && iface[0] != '\0') { uci_foreach_sections("firewall", "zone", s) { dmuci_get_value_by_section_string(s, "network", &net); @@ -937,6 +940,7 @@ static int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data { char *iface, *zone, *net; struct uci_section *s = NULL; + char interface[256] = {0}; switch (action) { case VALUECHECK: @@ -948,7 +952,9 @@ static int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data dmuci_set_value_by_section((struct uci_section *)data, "dest", ""); break; } - adm_entry_get_linker_value(ctx, value, &iface); + + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &iface); if (iface != NULL && iface[0] != '\0') { uci_foreach_sections("firewall", "zone", s) { dmuci_get_value_by_section_string(s, "name", &net); diff --git a/dmtree/tr181/interfacestack.c b/dmtree/tr181/interfacestack.c index b99305a3..0ebe04e2 100644 --- a/dmtree/tr181/interfacestack.c +++ b/dmtree/tr181/interfacestack.c @@ -111,7 +111,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre layer_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_network", "interface", s, "section_name", section_name(s), "ip_int_instance", "ip_int_alias"); if (*layer_inst == '\0') continue; - snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.IP.Interface.%s.", layer_inst); + snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.IP.Interface.%s", layer_inst); higheralias = get_alias_by_section("dmmap_network", "interface", s, "ip_int_alias"); if (*higheralias == '\0') @@ -127,7 +127,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre layer_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_network", "interface", s, "section_name", section_name(s), "ppp_int_instance", "ppp_int_alias"); if (*layer_inst == '\0') continue; - snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "Device.PPP.Interface.%s.", layer_inst); + snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "Device.PPP.Interface.%s", layer_inst); loweralias = get_alias_by_section("dmmap_network", "interface", s, "ppp_int_alias"); if (*loweralias == '\0') snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", layer_inst); @@ -197,7 +197,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre layer_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_network", "interface", s, "section_name", section_name(s), "ppp_int_instance", "ppp_int_alias"); if (*layer_inst == '\0') continue; - snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.PPP.Interface.%s.", layer_inst); + snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.PPP.Interface.%s", layer_inst); higheralias = get_alias_by_section("dmmap_network", "interface", s, "ppp_int_alias"); if (*higheralias == '\0') @@ -277,7 +277,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre if (*layer_inst == '\0') continue; - snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.VLANTermination.%s.", layer_inst); + snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.VLANTermination.%s", layer_inst); higheralias = get_alias_by_section("dmmap_network", "device", s, "vlan_term_alias"); if (*higheralias == '\0') @@ -335,7 +335,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre if (*layer_inst == '\0') continue; - snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.Link.%s.", layer_inst); + snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.Link.%s", layer_inst); dmuci_get_value_by_section_string(s, "link_alias", &higheralias); if (*higheralias == '\0') diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index 313818d7..386a3b4d 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -401,7 +401,7 @@ static int get_IPInterface_LastChange(char *refparam, struct dmctx *ctx, void *d static int get_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "Device.Routing.Router.1."; + *value = "Device.Routing.Router.1"; return 0; } @@ -731,10 +731,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * return FAULT_9007; return 0; case VALUESET: - if (value[strlen(value)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", value); - else - strncpy(lower_layer, value, sizeof(lower_layer) - 1); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); if (strncmp(lower_layer, "Device.Ethernet.VLANTermination.", 32) == 0) { adm_entry_get_linker_value(ctx, lower_layer, &linker); @@ -914,7 +911,7 @@ static int get_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, *value = ""; if(((struct ipv6prefix_args *)data)->ip_6prefixaddress[0] != '\0') - dmasprintf(value, "Device.IP.Interface.%s.IPv6Prefix.1.", inst); + dmasprintf(value, "Device.IP.Interface.%s.IPv6Prefix.1", inst); return 0; } diff --git a/dmtree/tr181/nat.c b/dmtree/tr181/nat.c index 684e3098..0e0a1745 100644 --- a/dmtree/tr181/nat.c +++ b/dmtree/tr181/nat.c @@ -245,6 +245,7 @@ static int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx static int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *iface, *pch, *pchr, buf[256] = ""; + char interface[256] = {0}; switch (action) { case VALUECHECK: @@ -255,7 +256,8 @@ static int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx strcpy(buf, value); dmuci_set_value_by_section((struct uci_section *)data, "network", ""); for(pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) { - adm_entry_get_linker_value(ctx, pch, &iface); + append_dot_to_string(interface, pch, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &iface); if (iface) { dmuci_add_list_value_by_section((struct uci_section *)data, "network", iface); dmfree(iface); @@ -363,6 +365,7 @@ static int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi { char *iface, *network, *zone; struct uci_section *s = NULL; + char interface[256] = {0}; switch (action) { case VALUECHECK: @@ -370,7 +373,8 @@ static int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &iface); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &iface); if (iface[0] != '\0') { uci_foreach_sections("firewall", "zone", s) { dmuci_get_value_by_section_string(s, "network", &network); diff --git a/dmtree/tr181/ppp.c b/dmtree/tr181/ppp.c index c2e0d769..ff2bddcf 100644 --- a/dmtree/tr181/ppp.c +++ b/dmtree/tr181/ppp.c @@ -285,7 +285,7 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker, *newvalue = NULL; + char lower_layer[256] = {0}, *linker; switch (action) { case VALUECHECK: @@ -293,11 +293,8 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch return FAULT_9007; return 0; case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); + adm_entry_get_linker_value(ctx, lower_layer, &linker); if(linker) dmuci_set_value_by_section(((struct uci_section *)data), "ifname", linker); else diff --git a/dmtree/tr181/qos-iopsyswrt.c b/dmtree/tr181/qos-iopsyswrt.c index 9e8c1fe1..06bcb4f6 100644 --- a/dmtree/tr181/qos-iopsyswrt.c +++ b/dmtree/tr181/qos-iopsyswrt.c @@ -925,13 +925,16 @@ int os_get_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void * int os_set_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *interface_linker = NULL; + char interface[256] = {0}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0)) return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &interface_linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &interface_linker); if (interface_linker) dmuci_set_value_by_section((struct uci_section *)data, "ifname", interface_linker); break; @@ -3073,13 +3076,16 @@ int os_get_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, cha int os_set_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *interface_linker = NULL; + char interface[256] = {0}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0)) return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &interface_linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &interface_linker); if (interface_linker) dmuci_set_value_by_section((struct uci_section *)data, "ifname", interface_linker); break; @@ -3484,13 +3490,16 @@ int os_get_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, ch int os_set_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *interface_linker = NULL; + char interface[256] = {0}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0)) return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &interface_linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &interface_linker); dmuci_set_value_by_section((struct uci_section *)data, "ifname", interface_linker); break; } diff --git a/dmtree/tr181/qos-openwrt.c b/dmtree/tr181/qos-openwrt.c index 3fb3ad61..f26c590f 100644 --- a/dmtree/tr181/qos-openwrt.c +++ b/dmtree/tr181/qos-openwrt.c @@ -596,6 +596,7 @@ int get_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *in int set_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker; + char lower_layer[256] = {0}; switch (action) { case VALUECHECK: @@ -603,7 +604,8 @@ int set_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *in return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); + adm_entry_get_linker_value(ctx, lower_layer, &linker); dmuci_set_value("qos", "Default", "default", linker); break; } diff --git a/dmtree/tr181/routing.c b/dmtree/tr181/routing.c index 31d7755a..62a10f40 100644 --- a/dmtree/tr181/routing.c +++ b/dmtree/tr181/routing.c @@ -649,7 +649,7 @@ static int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, static int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker; + char interface[256] = {0}, *linker = NULL; switch (action) { case VALUECHECK: @@ -657,7 +657,8 @@ static int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, return FAULT_9007; return 0; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) { dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", linker); dmfree(linker); @@ -790,7 +791,7 @@ static int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmct static int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker; + char interface[256] = {0}, *linker = NULL; switch (action) { case VALUECHECK: @@ -798,7 +799,8 @@ static int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmct return FAULT_9007; return 0; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) { dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", linker); dmfree(linker); diff --git a/dmtree/tr181/times.c b/dmtree/tr181/times.c index 7fddf8b1..362c3706 100644 --- a/dmtree/tr181/times.c +++ b/dmtree/tr181/times.c @@ -165,15 +165,18 @@ static int get_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, ch static int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *iface= NULL; + char interface[256] = {0}, *iface = NULL; + switch (action) { case VALUECHECK: - adm_entry_get_linker_value(ctx, value, &iface); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &iface); if (iface == NULL || iface[0] == '\0') return FAULT_9007; break; case VALUESET: - adm_entry_get_linker_value(ctx, value, &iface); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &iface); dmuci_set_value("system", "ntp", "interface", iface); return 0; } diff --git a/dmtree/tr181/wifi.c b/dmtree/tr181/wifi.c index c00ce575..117949ac 100644 --- a/dmtree/tr181/wifi.c +++ b/dmtree/tr181/wifi.c @@ -1948,7 +1948,7 @@ static int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, c static int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker, *newvalue = NULL; + char lower_layer[256] = {0}, *linker; switch (action) { case VALUECHECK: @@ -1956,11 +1956,8 @@ static int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, c return FAULT_9007; return 0; case VALUESET: - if (value[strlen(value)-1] != '.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); + adm_entry_get_linker_value(ctx, lower_layer, &linker); if (linker) { dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", linker); dmfree(linker); diff --git a/dmtree/tr181/x_iopsys_eu_igmp.c b/dmtree/tr181/x_iopsys_eu_igmp.c index 52b6e2cd..2484a2a7 100644 --- a/dmtree/tr181/x_iopsys_eu_igmp.c +++ b/dmtree/tr181/x_iopsys_eu_igmp.c @@ -228,12 +228,9 @@ static int get_br_key_from_lower_layer(char *lower_layer, char *key, size_t s_ke int get_mcast_snooping_interface_val(char *value, char *ifname, size_t s_ifname) { - char lower_layer[250] = {0}; + char lower_layer[256] = {0}; - if (value[strlen(value)-1] != '.') - snprintf(lower_layer, sizeof(lower_layer), "%s.", value); - else - strncpy(lower_layer, value, sizeof(lower_layer) - 1); + append_dot_to_string(lower_layer, value, sizeof(lower_layer)); /* Check if the value is valid or not. */ if (strncmp(lower_layer, "Device.Bridging.Bridge.", 23) != 0) @@ -1781,7 +1778,10 @@ static int set_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da interface_linker = dmstrdup(ifname); is_br = true; } else { - adm_entry_get_linker_value(ctx, value, &linker); + char interface[256] = {0}; + + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); uci_foreach_sections("network", "interface", s) { if(strcmp(section_name(s), linker) != 0) { continue; diff --git a/dmtree/tr181/x_iopsys_eu_mld.c b/dmtree/tr181/x_iopsys_eu_mld.c index 4622455e..01303d9a 100644 --- a/dmtree/tr181/x_iopsys_eu_mld.c +++ b/dmtree/tr181/x_iopsys_eu_mld.c @@ -651,7 +651,10 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat if (get_mcast_snooping_interface_val(value, ifname, sizeof(ifname)) == 0) { interface_linker = dmstrdup(ifname); } else { - adm_entry_get_linker_value(ctx, value, &linker); + char interface[256] = {0}; + + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); uci_foreach_sections("network", "interface", s) { if(strcmp(section_name(s), linker) != 0) { continue; diff --git a/dmtree/tr181/x_iopsys_eu_owsd.c b/dmtree/tr181/x_iopsys_eu_owsd.c index 2be7f23a..63374ee9 100644 --- a/dmtree/tr181/x_iopsys_eu_owsd.c +++ b/dmtree/tr181/x_iopsys_eu_owsd.c @@ -107,13 +107,14 @@ static int get_x_iopsys_eu_owsd_virtualhost_interface(char *refparam, struct dmc static int set_x_iopsys_eu_owsd_virtualhost_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker; + char interface[256] = {0}, *linker; switch (action) { case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); + append_dot_to_string(interface, value, sizeof(interface)); + adm_entry_get_linker_value(ctx, interface, &linker); if (linker) { dmuci_set_value_by_section((struct uci_section *)data, "interface", linker); dmfree(linker); diff --git a/libbbf_api/dmbbf.c b/libbbf_api/dmbbf.c index e7edc9d0..c74b07be 100644 --- a/libbbf_api/dmbbf.c +++ b/libbbf_api/dmbbf.c @@ -2053,6 +2053,8 @@ static int get_linker_check_obj(DMOBJECT_ARGS) return FAULT_9005; } if (link_val && link_val[0] != '\0' && strcmp(link_val, dmctx->linker) == 0) { + if (node->current_object[strlen(node->current_object) - 1] == '.') + node->current_object[strlen(node->current_object) - 1] = 0; dmctx->linker_param = dmstrdup(node->current_object); dmctx->stop = true; return 0; diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index d9bbb8b1..e9eb11e7 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -1779,3 +1779,12 @@ int check_browse_section(struct uci_section *s, void *data) return 0; return -1; } + +void append_dot_to_string(char *new_string, const char *string, size_t len) +{ + if (string[strlen(string) - 1] != '.') + snprintf(new_string, len, "%s.", string); + else + strncpy(new_string, string, len - 1); +} + diff --git a/libbbf_api/dmcommon.h b/libbbf_api/dmcommon.h index 22716b55..95653a96 100644 --- a/libbbf_api/dmcommon.h +++ b/libbbf_api/dmcommon.h @@ -333,4 +333,5 @@ int is_vlan_termination_section(char *name); void sync_dmmap_bool_to_uci_list(struct uci_section *s, char *section, char *value, bool b); void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, char *value); int check_browse_section(struct uci_section *s, void *data); +void append_dot_to_string(char *new_string, const char *string, size_t len); #endif