Update the Alias value for a few parameters to make them more meaningful

This commit is contained in:
Amin Ben Romdhane 2023-12-18 16:06:12 +01:00
parent c66b1b1168
commit c10303fc51
5 changed files with 76 additions and 22 deletions

View file

@ -180,7 +180,7 @@ static void remove_port_from_bridge_sections(struct uci_section *br_sec, struct
}
}
static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, void *data, char *instance, char *br_inst, char *component)
static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, void *data, char *instance, char *linker, char *component)
{
/* *value=Device.Bridging.Bridge.{i}.
* In file dmmap_provider_bridge set "option svlan_br_inst {i}" or "list cvlan_br_inst {i}" in this(refered "provider_bridge" section)
@ -190,8 +190,11 @@ static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, voi
char pr_br_sec_name[64] = {0};
char *br_sec_name = NULL;
// Get candidate bridge instance
if (DM_STRLEN(br_inst) == 0)
if (DM_STRLEN(linker) == 0) // Linker should be like "cpe-X"
return;
char *br_inst = DM_STRCHR(linker, '-'); // Get bridge instance 'X' which is linker from Alias prefix 'cpe-X'
if (!br_inst)
return;
// section name of bridge in network file
@ -213,16 +216,16 @@ static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, voi
if (DM_LSTRCMP(component, "CVLAN") == 0) {
// Set svlan_br_inst in dmmap_provider_bridge->provider_bridge section
dmuci_add_list_value_by_section(((struct provider_bridge_args *)data)->provider_bridge_sec, "cvlan_br_inst", br_inst);
dmuci_add_list_value_by_section(((struct provider_bridge_args *)data)->provider_bridge_sec, "cvlan_br_inst", br_inst + 1);
} else if (DM_LSTRCMP(component, "SVLAN") == 0) {
// Set svlan_br_inst in dmmap_provider_bridgei->provider_bridge section
dmuci_set_value_by_section(((struct provider_bridge_args *)data)->provider_bridge_sec, "svlan_br_inst", br_inst);
dmuci_set_value_by_section(((struct provider_bridge_args *)data)->provider_bridge_sec, "svlan_br_inst", br_inst + 1);
}
/* Add candidate bridge to this provider bridge instance(network->device->pr_br_{i}) */
// Get network->device(bridge) section name from dmmap_bridge_port->bridge_port->device_section_name
dmmap_bridge_section = get_dup_section_in_dmmap_opt("dmmap_bridge", "device", "bridge_instance", br_inst);
dmmap_bridge_section = get_dup_section_in_dmmap_opt("dmmap_bridge", "device", "bridge_instance", br_inst + 1);
dmuci_get_value_by_section_string(dmmap_bridge_section, "section_name", &br_sec_name);
if (!dmmap_bridge_section || DM_STRLEN(br_sec_name) == 0)
@ -1517,12 +1520,21 @@ static int get_BridgingBridge_Status(char *refparam, struct dmctx *ctx, void *da
/*#Device.Bridging.Bridge.{i}.Alias!UCI:dmmap_bridge/device,@i-1/bridge_alias*/
static int get_BridgingBridge_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(((struct bridge_args *)data)->br_inst);
dmasprintf(value, "cpe-%s", ((struct bridge_args *)data)->br_inst ? ((struct bridge_args *)data)->br_inst : instance);
return 0;
}
static int set_BridgingBridge_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string(ctx, value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
bbfdm_set_fault_message(ctx, "Internal designated unique identifier, not allowed to update");
return FAULT_9007;
}
return 0;
}

View file

@ -555,18 +555,24 @@ static int get_device_softwareversion(char *refparam, struct dmctx *ctx, void *d
static int get_device_active_fwimage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *bank_obj = NULL, *arrobj = NULL;
char *linker = NULL;
char linker[16] = {0}, *id = NULL;
int i = 0;
dmubus_call("fwbank", "dump", UBUS_ARGS{0}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, bank_obj, i, 1, "bank") {
char *active = dmjson_get_value(bank_obj, 1, "active");
if (active && DM_LSTRCMP(active, "true") == 0) {
linker = dmjson_get_value(bank_obj, 1, "id");
id = dmjson_get_value(bank_obj, 1, "id");
break;
}
}
if (DM_STRLEN(id) == 0) {
*value = "";
return 0;
}
snprintf(linker, sizeof(linker), "cpe-%s", id);
adm_entry_get_reference_param(ctx, "Device.DeviceInfo.FirmwareImage.*.Alias", linker, value);
return 0;
}
@ -574,18 +580,24 @@ static int get_device_active_fwimage(char *refparam, struct dmctx *ctx, void *da
static int get_device_boot_fwimage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *bank_obj = NULL, *arrobj = NULL;
char *linker = NULL;
char linker[16] = {0}, *id = NULL;
int i = 0;
dmubus_call("fwbank", "dump", UBUS_ARGS{0}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, bank_obj, i, 1, "bank") {
char *boot = dmjson_get_value(bank_obj, 1, "boot");
if (boot && DM_LSTRCMP(boot, "true") == 0) {
linker = dmjson_get_value(bank_obj, 1, "id");
id = dmjson_get_value(bank_obj, 1, "id");
break;
}
}
if (DM_STRLEN(id) == 0) {
*value = "";
return 0;
}
snprintf(linker, sizeof(linker), "cpe-%s", id);
adm_entry_get_reference_param(ctx, "Device.DeviceInfo.FirmwareImage.*.Alias", linker, value);
return 0;
}
@ -612,14 +624,16 @@ static int set_device_boot_fwimage(char *refparam, struct dmctx *ctx, void *data
json_object *res = NULL;
char *available = NULL;
char *bank_id = reference.value;
char *bank_id = DM_STRCHR(reference.value, '-'); // Get bank id 'X' which is linker from Alias prefix 'cpe-X'
if (!bank_id)
return FAULT_9001;
get_dmmap_section_of_config_section_cont("dmmap_fw_image", "fw_image", "id", bank_id, &dmmap_s);
get_dmmap_section_of_config_section_cont("dmmap_fw_image", "fw_image", "id", bank_id + 1, &dmmap_s);
dmuci_get_value_by_section_string(dmmap_s, "available", &available);
if (DM_LSTRCMP(available, "false") == 0)
return FAULT_9001;
dmubus_call("fwbank", "set_bootbank", UBUS_ARGS{{"bank", bank_id, Integer}}, 1, &res);
dmubus_call("fwbank", "set_bootbank", UBUS_ARGS{{"bank", bank_id + 1, Integer}}, 1, &res);
char *success = dmjson_get_value(res, 1, "success");
if (DM_LSTRCMP(success, "true") != 0)
return FAULT_9001;
@ -972,12 +986,22 @@ static int get_DeviceInfoSupportedDataModel_Features(char *refparam, struct dmct
static int get_DeviceInfoFirmwareImage_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 1, "id");
char *id = dmjson_get_value((json_object *)data, 1, "id");
dmasprintf(value, "cpe-%s", id ? id : instance);
return 0;
}
static int set_DeviceInfoFirmwareImage_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string(ctx, value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
bbfdm_set_fault_message(ctx, "Internal designated unique identifier, not allowed to update");
return FAULT_9007;
}
return 0;
}

View file

@ -422,7 +422,7 @@ static int get_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *
{
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_iface_alias", value);
if ((*value)[0] == '\0') {
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "name", value);
*value = dmstrdup(section_name((((struct eth_port_args *)data)->sections)->config_section));
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_iface_alias", *value);
}
return 0;

View file

@ -1345,10 +1345,12 @@ static int get_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data,
if ((*value)[0] == '\0') {
char *ip4table = NULL;
char linker[32] = {0};
dmuci_get_value_by_section_string((struct uci_section *)data, "ip4table", &ip4table);
adm_entry_get_reference_param(ctx, "Device.Routing.Router.*.Alias", DM_STRLEN(ip4table) ? ip4table : "254", value);
snprintf(linker, sizeof(linker), "route_table-%s", DM_STRLEN(ip4table) ? ip4table : "254");
adm_entry_get_reference_param(ctx, "Device.Routing.Router.*.Alias", linker, value);
// Store LowerLayers value
dmuci_set_value_by_section(dmmap_section, "Router", *value);
@ -1379,18 +1381,22 @@ static int set_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data,
if (DM_STRLEN(reference.value) == 0)
return FAULT_9007;
char *rt_table = DM_STRCHR(reference.value, '-'); // Get rt_table 'X' which is linker from Alias prefix 'route_table-X'
if (!rt_table)
return FAULT_9007;
// Store LowerLayers value
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &s);
dmuci_set_value_by_section(s, "Router", reference.path);
dmuci_set_value_by_section((struct uci_section *)data, "ip4table", reference.value);
dmuci_set_value_by_section((struct uci_section *)data, "ip6table", reference.value);
dmuci_set_value_by_section((struct uci_section *)data, "ip4table", rt_table + 1);
dmuci_set_value_by_section((struct uci_section *)data, "ip6table", rt_table + 1);
dmuci_get_value_by_section_string((struct uci_section *)data, "device", &device);
uci_foreach_option_eq("network", "interface", "device", device, s) {
dmuci_set_value_by_section(s, "ip4table", reference.value);
dmuci_set_value_by_section(s, "ip6table", reference.value);
dmuci_set_value_by_section(s, "ip4table", rt_table + 1);
dmuci_set_value_by_section(s, "ip6table", rt_table + 1);
}
break;
}

View file

@ -1083,12 +1083,24 @@ static int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refpa
**************************************************************/
static int get_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "rt_table", value);
char *rt_table = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "rt_table", &rt_table);
dmasprintf(value, "route_table-%s", rt_table ? rt_table : instance);
return 0;
}
static int set_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string(ctx, value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
bbfdm_set_fault_message(ctx, "Internal designated unique identifier, not allowed to update");
return FAULT_9007;
}
return 0;
}