diff --git a/libbbfdm/dmtree/tr181/deviceinfo.c b/libbbfdm/dmtree/tr181/deviceinfo.c index 6fe025e2..374bd9a6 100644 --- a/libbbfdm/dmtree/tr181/deviceinfo.c +++ b/libbbfdm/dmtree/tr181/deviceinfo.c @@ -803,13 +803,18 @@ static int dmmap_synchronizeVcfInst(struct dmctx *dmctx, DMNODE *parent_node, vo **************************************************************/ static int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { + struct dm_data curr_data = {0}; struct uci_section *s = NULL; char *inst = NULL; dmmap_synchronizeVcfInst(dmctx, parent_node, prev_data, prev_instance); uci_path_foreach_sections(bbfdm, "dmmap", "vcf", s) { + + curr_data.config_section = s; + inst = handle_instance(dmctx, parent_node, s, "vcf_instance", "vcf_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP) + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -835,13 +840,14 @@ static int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da static int browseDeviceInfoProcessorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - char *inst = NULL; int nbr_cpus = get_number_of_cpus(); + struct dm_data curr_data = {0}; + char *inst = NULL; int i; for (i = 0; i < nbr_cpus; i++) { inst = handle_instance_without_section(dmctx, parent_node, i+1); - if (DM_LINK_INST_OBJ(dmctx, parent_node, NULL, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -863,13 +869,19 @@ static int browseDeviceInfoSupportedDataModelInst(struct dmctx *dmctx, DMNODE *p static int browseDeviceInfoFirmwareImageInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { json_object *res = NULL, *bank_obj = NULL, *arrobj = NULL; + struct dm_data curr_data = {0}; char *inst = NULL; int id = 0, i = 0; dmubus_call("fwbank", "dump", UBUS_ARGS{0}, 0, &res); + dmjson_foreach_obj_in_array(res, arrobj, bank_obj, i, 1, "bank") { + + curr_data.json_object = bank_obj; + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)bank_obj, inst) == DM_STOP) + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -878,15 +890,18 @@ static int browseDeviceInfoFirmwareImageInst(struct dmctx *dmctx, DMNODE *parent static int browseProcessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct process_entry *entry = NULL; + struct dm_data curr_data = {0}; char *inst = NULL; int id = 0; init_processes(); list_for_each_entry(entry, &process_list, list) { + curr_data.additional_data = entry; + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, entry, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst) == DM_STOP) break; } return 0; @@ -1178,13 +1193,13 @@ static int get_deviceinfo_modelnumber (char *refparam, struct dmctx *ctx, void * static int get_vcf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "name", value); return 0; } static int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((struct uci_section *)data, "version", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "version", value); return 0; } @@ -1195,7 +1210,7 @@ static int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *ins char *config_name = NULL; *value = "0001-01-01T00:00:00Z"; - dmuci_get_value_by_section_string((struct uci_section *)data, "name", &config_name); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "name", &config_name); if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { while ((d_file = readdir (dir)) != NULL) { if (config_name && DM_STRCMP(config_name, d_file->d_name) == 0) { @@ -1215,24 +1230,24 @@ static int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *ins static int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((struct uci_section *)data, "backup_restore", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "backup_restore", value); return 0; } static int get_vcf_desc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((struct uci_section *)data, "description", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "description", value); return 0; } static int get_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, (struct uci_section *)data, "vcf_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->config_section, "vcf_alias", instance, value); } static int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, (struct uci_section *)data, "vcf_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->config_section, "vcf_alias", instance, value); } static int get_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) @@ -1377,7 +1392,7 @@ 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) { - char *id = dmjson_get_value((json_object *)data, 1, "id"); + char *id = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "id"); dmasprintf(value, "cpe-%s", id ? id : instance); return 0; } @@ -1400,7 +1415,7 @@ static int get_DeviceInfoFirmwareImage_Name(char *refparam, struct dmctx *ctx, v { char *name; - name = dmstrdup(dmjson_get_value((json_object *)data, 1, "fwver")); + name = dmstrdup(dmjson_get_value(((struct dm_data *)data)->json_object, 1, "fwver")); if (DM_STRLEN(name) > 64 ) { name[64] = '\0'; } @@ -1411,7 +1426,7 @@ static int get_DeviceInfoFirmwareImage_Name(char *refparam, struct dmctx *ctx, v static int get_DeviceInfoFirmwareImage_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((json_object *)data, 1, "swver"); + *value = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "swver"); return 0; } @@ -1419,7 +1434,7 @@ static int get_DeviceInfoFirmwareImage_Available(char *refparam, struct dmctx *c { struct uci_section *s = NULL; - char *id = dmjson_get_value((json_object *)data, 1, "id"); + char *id = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "id"); uci_path_foreach_option_eq(bbfdm, "dmmap_fw_image", "fw_image", "id", id, s) { dmuci_get_value_by_section_string(s, "available", value); @@ -1446,13 +1461,13 @@ static int set_DeviceInfoFirmwareImage_Available(char *refparam, struct dmctx *c string_to_bool(value, &b); if (!b) { - char *boot = dmjson_get_value((json_object *)data, 1, "boot"); - char *active = dmjson_get_value((json_object *)data, 1, "active"); + char *boot = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "boot"); + char *active = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "active"); if (DM_LSTRCMP(boot, "true") == 0 || DM_LSTRCMP(active, "true") == 0) return FAULT_9001; } - id = dmjson_get_value((json_object *)data, 1, "id"); + id = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "id"); uci_path_foreach_option_eq(bbfdm, "dmmap_fw_image", "fw_image", "id", id, s) { dmuci_set_value_by_section_bbfdm(s, "available", b ? "true" : "false"); @@ -1469,7 +1484,7 @@ static int set_DeviceInfoFirmwareImage_Available(char *refparam, struct dmctx *c static int get_DeviceInfoFirmwareImage_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((json_object *)data, 1, "status"); + *value = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "status"); return 0; } @@ -1534,37 +1549,37 @@ static int get_process_number_of_entries(char* refparam, struct dmctx *ctx, void static int get_process_pid(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = data ? ((struct process_entry *)data)->pid : ""; + *value = data ? ((struct process_entry *)((struct dm_data *)data)->additional_data)->pid : ""; return 0; } static int get_process_command(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = data ? ((struct process_entry *)data)->command : ""; + *value = data ? ((struct process_entry *)((struct dm_data *)data)->additional_data)->command : ""; return 0; } static int get_process_size(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = data ? ((struct process_entry *)data)->size : ""; + *value = data ? ((struct process_entry *)((struct dm_data *)data)->additional_data)->size : ""; return 0; } static int get_process_priority(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = data ? ((struct process_entry *)data)->priority : ""; + *value = data ? ((struct process_entry *)((struct dm_data *)data)->additional_data)->priority : ""; return 0; } static int get_process_cpu_time(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = data ? ((struct process_entry *)data)->cputime : ""; + *value = data ? ((struct process_entry *)((struct dm_data *)data)->additional_data)->cputime : ""; return 0; } static int get_process_state(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = data ? ((struct process_entry *)data)->state : ""; + *value = data ? ((struct process_entry *)((struct dm_data *)data)->additional_data)->state : ""; return 0; } @@ -1653,7 +1668,7 @@ static int operate_DeviceInfoVendorConfigFile_Backup(char *refparam, struct dmct char *user = dmjson_get_value((json_object *)value, 1, "Username"); char *pass = dmjson_get_value((json_object *)value, 1, "Password"); - dmuci_get_value_by_section_string((struct uci_section *)data, "name", &vcf_name); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "name", &vcf_name); int res = bbf_config_backup(url, user, pass, vcf_name, backup_command, backup_path); @@ -1751,7 +1766,7 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx char *commandKey = dmjson_get_value((json_object *)value, 1, "CommandKey"); char *keep_config = dmjson_get_value((json_object *)value, 1, BBF_VENDOR_PREFIX"KeepConfig"); - char *bank_id = dmjson_get_value((json_object *)data, 1, "id"); + char *bank_id = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "id"); int res = bbf_fw_image_download(url, auto_activate, username, password, file_size, checksum_algorithm, checksum, bank_id, command, obj_path, commandKey, keep_config); @@ -1835,7 +1850,7 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx last_idx++; } - char *bank_id = dmjson_get_value((json_object *)data, 1, "id"); + char *bank_id = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "id"); if (!DM_STRLEN(bank_id)) return USP_FAULT_COMMAND_FAILURE; diff --git a/libbbfdm/dmtree/tr181/interfacestack.c b/libbbfdm/dmtree/tr181/interfacestack.c index 92108af6..923fda7a 100644 --- a/libbbfdm/dmtree/tr181/interfacestack.c +++ b/libbbfdm/dmtree/tr181/interfacestack.c @@ -111,6 +111,7 @@ static int create_interface_stack_instance(struct dmctx *dmctx, DMNODE *parent_n struct interfacestack_data *data, struct uci_section *s, char *path, char *inst_number, char *inst_alias, int *curr_inst) { + struct dm_data curr_data = {0}; char *instance = NULL, *inst = NULL; char *LowerLayer = NULL; @@ -129,7 +130,10 @@ static int create_interface_stack_instance(struct dmctx *dmctx, DMNODE *parent_n data->LowerAlias = get_lower_alias_value(data->LowerLayer); inst = handle_instance_without_section(dmctx, parent_node, ++(*curr_inst)); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)data, inst) == DM_STOP) + + curr_data.additional_data = (void *)data; + + if (DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst) == DM_STOP) return -1; end: @@ -219,6 +223,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre dmuci_get_value_by_section_string(mg_port_s, "bridge_port_alias", &mg_port_alias); uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", br_instance, port_s) { + struct dm_data curr_data = {0}; char *management = NULL; char *instance_value = NULL; char *alias_value = NULL; @@ -238,7 +243,8 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre curr_interfacestack_data.LowerAlias = alias_value; inst = handle_instance_without_section(dmctx, parent_node, ++idx); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_interfacestack_data, inst) == DM_STOP) + curr_data.additional_data = (void *)&curr_interfacestack_data; + if (DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst) == DM_STOP) goto end; /* Higher Layer is Device.Bridging.Bridge.{i}.Port.{i}.*/ @@ -285,25 +291,25 @@ static int set_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *dat static int get_InterfaceStack_HigherLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct interfacestack_data *)data)->HigherLayer; + *value = ((struct interfacestack_data *)((struct dm_data *)data)->additional_data)->HigherLayer; return 0; } static int get_InterfaceStack_LowerLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct interfacestack_data *)data)->LowerLayer; + *value = ((struct interfacestack_data *)((struct dm_data *)data)->additional_data)->LowerLayer; return 0; } static int get_InterfaceStack_HigherAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct interfacestack_data *)data)->HigherAlias; + *value = ((struct interfacestack_data *)((struct dm_data *)data)->additional_data)->HigherAlias; return 0; } static int get_InterfaceStack_LowerAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct interfacestack_data *)data)->LowerAlias; + *value = ((struct interfacestack_data *)((struct dm_data *)data)->additional_data)->LowerAlias; return 0; } diff --git a/libbbfdm/dmtree/tr181/ppp.c b/libbbfdm/dmtree/tr181/ppp.c index c0442962..8a25f3d1 100644 --- a/libbbfdm/dmtree/tr181/ppp.c +++ b/libbbfdm/dmtree/tr181/ppp.c @@ -12,12 +12,6 @@ #include "dmlayer.h" #include "ppp.h" -struct ppp_args -{ - struct uci_section *iface_s; - struct uci_section *dmmap_s; -}; - /************************************************************* * COMMON FUNCTIONS **************************************************************/ @@ -77,7 +71,7 @@ static void dmmap_synchronizePPPInterface(struct dmctx *dmctx, DMNODE *parent_no **************************************************************/ static int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct ppp_args curr_ppp_args = {0}; + struct dm_data curr_data = {0}; struct uci_section *s = NULL; char *inst = NULL; @@ -91,8 +85,8 @@ static int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *p if (DM_STRLEN(iface_name)) get_config_section_of_dmmap_section("network", "interface", iface_name, &iface_s); - curr_ppp_args.iface_s = iface_s; - curr_ppp_args.dmmap_s = s; + curr_data.config_section = iface_s; + curr_data.dmmap_section = s; inst = handle_instance(dmctx, parent_node, s, "ppp_int_instance", "ppp_int_alias"); @@ -104,7 +98,7 @@ static int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *p dmuci_set_value_by_section(s, "name", name); } - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ppp_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst) == DM_STOP) break; } return 0; @@ -133,16 +127,16 @@ static int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, c { switch (del_action) { case DEL_INST: - if (((struct ppp_args *)data)->iface_s) { - dmuci_set_value_by_section(((struct ppp_args *)data)->iface_s, "proto", "none"); - ppp___reset_options(((struct ppp_args *)data)->iface_s); + if (((struct dm_data *)data)->config_section) { + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "proto", "none"); + ppp___reset_options(((struct dm_data *)data)->config_section); } // Update PPP Interface Top Layers ppp___Update_PPP_Interface_Top_Layers(refparam, ""); // Remove dmmap section - dmuci_delete_by_section(((struct ppp_args *)data)->dmmap_s, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: break; @@ -155,17 +149,17 @@ static int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, c **************************************************************/ static int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char *disabled = NULL; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "disabled", &disabled); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "disabled", &disabled); *value = (disabled && *disabled == '1') ? "0" : "1"; return 0; } static int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; bool b; switch (action) { @@ -175,9 +169,9 @@ static int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *i break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section(ppp->dmmap_s, "disabled", b ? "0" : "1"); - if (ppp->iface_s) - dmuci_set_value_by_section(ppp->iface_s, "disabled", b ? "0" : "1"); + dmuci_set_value_by_section(ppp->dmmap_section, "disabled", b ? "0" : "1"); + if (ppp->config_section) + dmuci_set_value_by_section(ppp->config_section, "disabled", b ? "0" : "1"); break; } return 0; @@ -193,18 +187,18 @@ static int get_PPPInterface_Status(char *refparam, struct dmctx *ctx, void *data /*#Device.PPP.Interface.{i}.Alias!UCI:dmmap_network/interface,@i-1/ppp_int_alias*/ static int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct ppp_args *)data)->dmmap_s, "ppp_int_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "ppp_int_alias", instance, value); } static int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct ppp_args *)data)->dmmap_s, "ppp_int_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "ppp_int_alias", instance, value); } /*#Device.PPP.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ static int get_PPPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { json_object *res = NULL; @@ -243,14 +237,14 @@ static int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, static int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct ppp_args *)data)->dmmap_s, "name", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "name", value); return 0; } /*#Device.PPP.Interface.{i}.ConnectionStatus!UBUS:network.interface/status/interface,@Name/up*/ static int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { char *status = NULL, *uptime = NULL, *pending = NULL; @@ -284,7 +278,7 @@ static int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *i static int get_PPPInterface_LastConnectionError(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { json_object *res = NULL; @@ -332,15 +326,15 @@ static int get_PPPInterface_LastConnectionError(char *refparam, struct dmctx *ct /*#Device.PPP.Interface.{i}.Username!UCI:network/interface,@i-1/username*/ static int get_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "username", value); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "username", value); return 0; } static int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; switch (action) { case VALUECHECK: @@ -348,9 +342,9 @@ static int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char return FAULT_9007; return 0; case VALUESET: - dmuci_set_value_by_section(ppp->dmmap_s, "username", value); - if (ppp->iface_s) - dmuci_set_value_by_section(ppp->iface_s, "username", value); + dmuci_set_value_by_section(ppp->dmmap_section, "username", value); + if (ppp->config_section) + dmuci_set_value_by_section(ppp->config_section, "username", value); return 0; } return 0; @@ -359,16 +353,16 @@ static int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char /*#Device.PPP.Interface.{i}.Password!UCI:network/interface,@i-1/password*/ static int get_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "password", value); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "password", value); return 0; } /*#Device.PPP.Interface.{i}.Password!UCI:network/interface,@i-1/password*/ static int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; switch (action) { case VALUECHECK: @@ -376,9 +370,9 @@ static int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char return FAULT_9007; return 0; case VALUESET: - dmuci_set_value_by_section(ppp->dmmap_s, "password", value); - if (ppp->iface_s) - dmuci_set_value_by_section(ppp->iface_s, "password", value); + dmuci_set_value_by_section(ppp->dmmap_section, "password", value); + if (ppp->config_section) + dmuci_set_value_by_section(ppp->config_section, "password", value); return 0; } return 0; @@ -386,10 +380,10 @@ static int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char static int get_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char *pppd_opt = NULL; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "pppd_options", &pppd_opt); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "pppd_options", &pppd_opt); if (pppd_opt && *pppd_opt == '\0') { *value = "1500"; return 0; @@ -451,7 +445,7 @@ static int configure_pppd_mru(char *pppd_opt, char *mru_str, struct uci_section static int set_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char mru_str[1024] = {0}; char *pppd_opt = NULL; @@ -462,17 +456,17 @@ static int set_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void * break; case VALUESET: snprintf(mru_str, sizeof(mru_str), "%s %s", "mru", value); - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "pppd_options", &pppd_opt); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "pppd_options", &pppd_opt); if (pppd_opt && *pppd_opt == '\0') { - dmuci_set_value_by_section(ppp->dmmap_s, "pppd_options", mru_str); - if (ppp->iface_s) - dmuci_set_value_by_section(ppp->iface_s, "pppd_options", mru_str); + dmuci_set_value_by_section(ppp->dmmap_section, "pppd_options", mru_str); + if (ppp->config_section) + dmuci_set_value_by_section(ppp->config_section, "pppd_options", mru_str); } else { // If mru is specified then we need to replace and keep the rest of the options intact. - configure_pppd_mru(pppd_opt, mru_str, ppp->dmmap_s, value); - if (ppp->iface_s) - configure_pppd_mru(pppd_opt, mru_str, ppp->iface_s, value); + configure_pppd_mru(pppd_opt, mru_str, ppp->dmmap_section, value); + if (ppp->config_section) + configure_pppd_mru(pppd_opt, mru_str, ppp->config_section, value); } break; } @@ -481,7 +475,7 @@ static int set_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void * static int get_PPPInterface_CurrentMRUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { char intf[64] = {0}; @@ -495,7 +489,7 @@ static int get_PPPInterface_CurrentMRUSize(char *refparam, struct dmctx *ctx, vo static int get_PPPInterface_LCPEcho(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { char *lcp_echo = NULL, *token = NULL; @@ -519,7 +513,7 @@ static int get_PPPInterface_LCPEcho(char *refparam, struct dmctx *ctx, void *dat static int get_PPPInterface_LCPEchoRetry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { char *lcp_retry = NULL, *token = NULL; @@ -636,16 +630,16 @@ static int handle_supported_ncp_options(struct uci_section *s, char *instance, i static int get_PPPInterface_IPCPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; - int ret = handle_supported_ncp_options(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, instance, IPCP); + int ret = handle_supported_ncp_options(ppp->config_section ? ppp->config_section : ppp->dmmap_section, instance, IPCP); *value = ret ? "0" : "1"; return 0; } static int set_PPPInterface_IPCPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; switch (action) { case VALUECHECK: @@ -653,9 +647,9 @@ static int set_PPPInterface_IPCPEnable(char *refparam, struct dmctx *ctx, void * return FAULT_9007; break; case VALUESET: - configure_supported_ncp_options(ppp->dmmap_s, value, "noip"); - if (ppp->iface_s) - configure_supported_ncp_options(ppp->iface_s, value, "noip"); + configure_supported_ncp_options(ppp->dmmap_section, value, "noip"); + if (ppp->config_section) + configure_supported_ncp_options(ppp->config_section, value, "noip"); break; } @@ -664,16 +658,16 @@ static int set_PPPInterface_IPCPEnable(char *refparam, struct dmctx *ctx, void * static int get_PPPInterface_IPv6CPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; - int ret = handle_supported_ncp_options(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, instance, IPCPv6); + int ret = handle_supported_ncp_options(ppp->config_section ? ppp->config_section : ppp->dmmap_section, instance, IPCPv6); *value = ret ? "0" : "1"; return 0; } static int set_PPPInterface_IPv6CPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; switch (action) { case VALUECHECK: @@ -681,9 +675,9 @@ static int set_PPPInterface_IPv6CPEnable(char *refparam, struct dmctx *ctx, void return FAULT_9007; break; case VALUESET: - configure_supported_ncp_options(ppp->dmmap_s, value, "noipv6"); - if (ppp->iface_s) - configure_supported_ncp_options(ppp->iface_s, value, "noipv6"); + configure_supported_ncp_options(ppp->dmmap_section, value, "noipv6"); + if (ppp->config_section) + configure_supported_ncp_options(ppp->config_section, value, "noipv6"); break; } return 0; @@ -721,7 +715,7 @@ static int get_PPPInterfacePPPoE_SessionID(char *refparam, struct dmctx *ctx, vo static int get_PPPInterfaceIPCP_LocalIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { json_object *res = NULL; @@ -737,7 +731,7 @@ static int get_PPPInterfaceIPCP_LocalIPAddress(char *refparam, struct dmctx *ctx static int get_PPPInterfaceIPCP_RemoteIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { json_object *res = NULL; @@ -757,7 +751,7 @@ static int get_PPPInterfaceIPCP_RemoteIPAddress(char *refparam, struct dmctx *ct static int get_PPPInterfaceIPCP_DNSServers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { json_object *res = NULL; @@ -772,7 +766,7 @@ static int get_PPPInterfaceIPCP_DNSServers(char *refparam, struct dmctx *ctx, vo static int get_PPPInterfaceIPv6CP_LocalInterfaceIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { json_object *res = NULL; @@ -788,7 +782,7 @@ static int get_PPPInterfaceIPv6CP_LocalInterfaceIdentifier(char *refparam, struc static int get_PPPInterfaceIPv6CP_RemoteInterfaceIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { json_object *res = NULL; @@ -803,7 +797,7 @@ static int get_PPPInterfaceIPv6CP_RemoteInterfaceIdentifier(char *refparam, stru static int ppp_read_sysfs(void *data, const char *name, char **value) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; *value = "0"; @@ -946,20 +940,20 @@ static int get_PPPInterfaceStats_UnicastPacketsReceived(char *refparam, struct d static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; - dmuci_get_value_by_section_string(ppp->dmmap_s, "LowerLayers", value); + dmuci_get_value_by_section_string(ppp->dmmap_section, "LowerLayers", value); if ((*value)[0] == '\0') { char *device = NULL; char buf[256] = {0}; - if (ppp->iface_s) { - device = get_device(section_name(ppp->iface_s)); + if (ppp->config_section) { + device = get_device(section_name(ppp->config_section)); if (DM_STRLEN(device) == 0) - dmuci_get_value_by_section_string(ppp->iface_s, "device", &device); + dmuci_get_value_by_section_string(ppp->config_section, "device", &device); } else { - dmuci_get_value_by_section_string(ppp->dmmap_s, "device", &device); + dmuci_get_value_by_section_string(ppp->dmmap_section, "device", &device); } if (DM_STRLEN(device) == 0) @@ -977,7 +971,7 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch end: // Store LowerLayers value - dmuci_set_value_by_section(ppp->dmmap_s, "LowerLayers", buf); + dmuci_set_value_by_section(ppp->dmmap_section, "LowerLayers", buf); *value = dmstrdup(buf); } else { @@ -990,7 +984,7 @@ end: static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char eth_mac_vlan[] = "Device.Ethernet."BBF_VENDOR_PREFIX"MACVLAN"; char *allowed_objects[] = { eth_mac_vlan, @@ -1013,17 +1007,17 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch return 0; case VALUESET: // Store LowerLayers value under dmmap_ppp section - dmuci_set_value_by_section(ppp->dmmap_s, "LowerLayers", reference.path); + dmuci_set_value_by_section(ppp->dmmap_section, "LowerLayers", reference.path); snprintf(proto, sizeof(proto), "ppp%s", (DM_STRLEN(reference.value)) ? (!DM_LSTRNCMP(reference.value, "atm", 3) || !DM_LSTRNCMP(reference.value, "ptm", 3)) ? "oa" : "oe" : ""); // Update proto option - dmuci_set_value_by_section(ppp->dmmap_s, "proto", proto); - if (ppp->iface_s) dmuci_set_value_by_section(ppp->iface_s, "proto", proto); + dmuci_set_value_by_section(ppp->dmmap_section, "proto", proto); + if (ppp->config_section) dmuci_set_value_by_section(ppp->config_section, "proto", proto); // Update device option - dmuci_set_value_by_section(ppp->dmmap_s, "device", reference.value); - if (ppp->iface_s) dmuci_set_value_by_section(ppp->iface_s, "device", DM_STRLEN(reference.value) ? reference.value : section_name(ppp->iface_s)); + dmuci_set_value_by_section(ppp->dmmap_section, "device", reference.value); + if (ppp->config_section) dmuci_set_value_by_section(ppp->config_section, "device", DM_STRLEN(reference.value) ? reference.value : section_name(ppp->config_section)); // Update PPP Interface Top Layers ppp___Update_PPP_Interface_Top_Layers(refparam, reference.value); @@ -1048,12 +1042,12 @@ static int get_PPP_SupportedNCPs(char *refparam, struct dmctx *ctx, void *data, /*#Device.PPP.Interface.{i}.PPPoE.ACName!UCI:network/interface,@i-1/ac*/ static int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char *proto; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "proto", &proto); if (DM_LSTRCMP(proto, "pppoe") == 0) { - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "ac", value); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "ac", value); return 0; } return 0; @@ -1061,7 +1055,7 @@ static int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char *proto_intf; switch (action) { @@ -1069,14 +1063,14 @@ static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL)) return FAULT_9007; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto_intf); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "proto", &proto_intf); if (DM_LSTRCMP(proto_intf, "pppoe") != 0) return FAULT_9001; break; case VALUESET: - dmuci_set_value_by_section(ppp->dmmap_s, "ac", value); - if (ppp->iface_s) - dmuci_set_value_by_section(ppp->iface_s, "ac", value); + dmuci_set_value_by_section(ppp->dmmap_section, "ac", value); + if (ppp->config_section) + dmuci_set_value_by_section(ppp->config_section, "ac", value); break; } return 0; @@ -1085,12 +1079,12 @@ static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void /*#Device.PPP.Interface.{i}.PPPoE.ServiceName!UCI:network/interface,@i-1/service*/ static int get_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char *proto; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "proto", &proto); if (DM_LSTRCMP(proto, "pppoe") == 0) { - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "service", value); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "service", value); return 0; } return 0; @@ -1098,7 +1092,7 @@ static int get_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, static int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ppp_args *ppp = (struct ppp_args *)data; + struct dm_data *ppp = (struct dm_data *)data; char *proto; switch (action) { @@ -1106,14 +1100,14 @@ static int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL)) return FAULT_9007; - dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto); + dmuci_get_value_by_section_string(ppp->config_section ? ppp->config_section : ppp->dmmap_section, "proto", &proto); if (DM_LSTRCMP(proto, "pppoe") != 0) return FAULT_9001; break; case VALUESET: - dmuci_set_value_by_section(ppp->dmmap_s, "service", value); - if (ppp->iface_s) - dmuci_set_value_by_section(ppp->iface_s, "service", value); + dmuci_set_value_by_section(ppp->dmmap_section, "service", value); + if (ppp->config_section) + dmuci_set_value_by_section(ppp->config_section, "service", value); break; } return 0; @@ -1124,7 +1118,7 @@ static int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, *************************************************************/ static int operate_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *ppp_s = ((struct ppp_args *)data)->iface_s; + struct uci_section *ppp_s = ((struct dm_data *)data)->config_section; if (ppp_s) { char interface_obj[64] = {0}; diff --git a/libbbfdm/dmtree/tr181/routing.c b/libbbfdm/dmtree/tr181/routing.c index 24998720..618a40d1 100644 --- a/libbbfdm/dmtree/tr181/routing.c +++ b/libbbfdm/dmtree/tr181/routing.c @@ -13,6 +13,8 @@ #include "dmlayer.h" #include "routing.h" +#define MAX_ROUTE_LEN 512 + struct route_args { char *iface; char *metric; @@ -28,29 +30,6 @@ struct route6_args { char gateway[INET6_ADDRSTRLEN + 8]; }; -struct routingfwdargs -{ - struct uci_section *routefwdsection; - int type; -}; - -enum enum_route_type { - ROUTE_STATIC, - ROUTE_DYNAMIC -}; - -#define MAX_ROUTE_LEN 512 - -/******************************** - * init function - ********************************/ -static inline int init_args_route_forwarding(struct routingfwdargs *args, struct uci_section *s, int type) -{ - args->routefwdsection = s; - args->type = type; - return 0; -} - /************************************************************************************* **** function related to get_object_router_ipv4forwarding **** **************************************************************************************/ @@ -199,7 +178,6 @@ static int parse_route6_line(const char *line, struct route6_args *route6) static void dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct uci_section *router_s = (struct uci_section *)prev_data; struct uci_section *s = NULL, *stmp = NULL; struct route_args route = {0}; FILE *pp = NULL; @@ -207,7 +185,7 @@ static void dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DM char line[MAX_ROUTE_LEN] = {0}; char cmd[32] = {0}; - dmuci_get_value_by_section_string(router_s, "rt_table", &rt_table); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->dmmap_section, "rt_table", &rt_table); snprintf(cmd, sizeof(cmd), "ip route show table %s", rt_table); uci_path_foreach_option_eq_safe(bbfdm, "dmmap_routing", "route_dynamic", "table", rt_table, stmp, s) { @@ -269,7 +247,6 @@ static void dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DM static void dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct uci_section *router_s = (struct uci_section *)prev_data; struct uci_section *s = NULL, *stmp = NULL; struct route6_args route6 = {0}; FILE *pp = NULL; @@ -277,7 +254,7 @@ static void dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DM char line[MAX_ROUTE_LEN] = {0}; char cmd[32] = {0}; - dmuci_get_value_by_section_string(router_s, "rt_table", &rt_table); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->dmmap_section, "rt_table", &rt_table); snprintf(cmd, sizeof(cmd), "ip -6 route show table %s", rt_table); uci_path_foreach_option_eq_safe(bbfdm, "dmmap_routing", "route6_dynamic", "table", rt_table, stmp, s) { @@ -351,6 +328,11 @@ static void create_routing_route_section(char *rt_table) } } +static struct uci_section *route_sec(void *data) +{ + return ((struct dm_data *)data)->config_section ? ((struct dm_data *)data)->config_section : ((struct dm_data *)data)->dmmap_section; +} + /************************************************************* * ENTRY METHOD **************************************************************/ @@ -359,6 +341,7 @@ static int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev struct uci_section *s = NULL; char *inst = NULL, *idx = NULL, *device = NULL, *proto = NULL; struct uci_section *dmmap_route = NULL; + struct dm_data curr_data = {0}; create_routing_route_section("254"); uci_foreach_sections("network", "interface", s) { @@ -380,9 +363,11 @@ static int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev uci_path_foreach_sections(bbfdm, "dmmap_routing", "router", dmmap_route) { + curr_data.dmmap_section = dmmap_route; + inst = handle_instance(dmctx, parent_node, dmmap_route, "router_instance", "router_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dmmap_route, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst) == DM_STOP) break; } return 0; @@ -391,15 +376,12 @@ static int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.!UCI:network/route/dmmap_routing*/ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct uci_section *router_s = (struct uci_section *)prev_data; - struct routingfwdargs curr_routefwdargs = {0}; struct dm_data *curr_data = NULL; struct uci_section *s = NULL; - char *rt_table = NULL; - char *inst = NULL; + char *rt_table = NULL, *inst = NULL; LIST_HEAD(dup_list); - dmuci_get_value_by_section_string(router_s, "rt_table", &rt_table); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->dmmap_section, "rt_table", &rt_table); // Enable Routes synchronize_specific_config_sections_with_dmmap("network", "route", "dmmap_routing", &dup_list); @@ -410,11 +392,9 @@ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo if (DM_STRCMP(rt_table, table) != 0 || (DM_STRLEN(table) == 0 && DM_STRCMP(rt_table, "254") != 0)) continue; - init_args_route_forwarding(&curr_routefwdargs, curr_data->config_section, ROUTE_STATIC); - inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "route_instance", "route_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, curr_data, inst) == DM_STOP) goto end; } free_dmmap_config_dup_list(&dup_list); @@ -423,11 +403,14 @@ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo dmmap_synchronizeRoutingRouterIPv4Forwarding(dmctx, parent_node, prev_data, prev_instance); uci_path_foreach_option_eq(bbfdm, "dmmap_routing", "route_dynamic", "table", rt_table, s) { - init_args_route_forwarding(&curr_routefwdargs, s, ROUTE_DYNAMIC); + curr_data = dmcalloc(1, sizeof(struct dm_data)); - inst = handle_instance(dmctx, parent_node, s, "route_instance", "route_alias"); + curr_data->config_section = NULL; + curr_data->dmmap_section = s; - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP) + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "route_instance", "route_alias"); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, curr_data, inst) == DM_STOP) goto end; } @@ -438,15 +421,12 @@ end: /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.!UCI:network/route6/dmmap_routing*/ static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct uci_section *router_s = (struct uci_section *)prev_data; - struct routingfwdargs curr_route6fwdargs = {0}; struct dm_data *curr_data = NULL; struct uci_section *s = NULL; - char *rt_table = NULL; - char *inst = NULL; + char *rt_table = NULL, *inst = NULL; LIST_HEAD(dup_list); - dmuci_get_value_by_section_string(router_s, "rt_table", &rt_table); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->dmmap_section, "rt_table", &rt_table); // Enable Routes synchronize_specific_config_sections_with_dmmap("network", "route6", "dmmap_routing", &dup_list); @@ -457,11 +437,9 @@ static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo if (DM_STRCMP(rt_table, table) != 0 || (DM_STRLEN(table) == 0 && DM_STRCMP(rt_table, "254") != 0)) continue; - init_args_route_forwarding(&curr_route6fwdargs, curr_data->config_section, ROUTE_STATIC); - inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "route6_instance", "route6_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, curr_data, inst) == DM_STOP) goto end; } free_dmmap_config_dup_list(&dup_list); @@ -470,11 +448,14 @@ static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo dmmap_synchronizeRoutingRouterIPv6Forwarding(dmctx, parent_node, prev_data, prev_instance); uci_path_foreach_option_eq(bbfdm, "dmmap_routing", "route6_dynamic", "table", rt_table, s) { - init_args_route_forwarding(&curr_route6fwdargs, s, ROUTE_DYNAMIC); + curr_data = dmcalloc(1, sizeof(struct dm_data)); + + curr_data->config_section = NULL; + curr_data->dmmap_section = s; inst = handle_instance(dmctx, parent_node, s, "route6_instance", "route6_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, curr_data, inst) == DM_STOP) goto end; } @@ -484,6 +465,7 @@ end: static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { + struct dm_data curr_data = {0}; struct uci_section *s = NULL; char *inst = NULL; int id = 0, i; @@ -499,8 +481,12 @@ static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx char *if_name = section_name(s); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", if_name, String}}, 1, &res); dmjson_foreach_obj_in_array(res, arrobj, route_obj, i, 1, "route") { + + curr_data.json_object = route_obj; + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)route_obj, inst) == DM_STOP) + + if (DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst) == DM_STOP) break; } } @@ -560,12 +546,12 @@ static int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struc static int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) { + if (((struct dm_data *)data)->config_section == NULL) { // Dynamic route *value = "1"; - } else { + } else { //Static route char *disabled = NULL; - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "disabled", &disabled); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "disabled", &disabled); *value = (disabled && *disabled == '1') ? "0" : "1"; } return 0; @@ -581,11 +567,11 @@ static int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, v return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; string_to_bool(value, &b); - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "disabled", b ? "0" : "1"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "disabled", b ? "0" : "1"); return 0; } return 0; @@ -601,7 +587,7 @@ static int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, v /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestIPAddress!UCI:network/route,@i-1/target*/ static int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "target", value); + dmuci_get_value_by_section_string(route_sec(data), "target", value); return 0; } @@ -613,10 +599,10 @@ static int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, v return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "target", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "target", value); return 0; } return 0; @@ -625,7 +611,7 @@ static int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, v /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestSubnetMask!UCI:network/route,@i-1/netmask*/ static int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "netmask", value); + dmuci_get_value_by_section_string(route_sec(data), "netmask", value); return 0; } @@ -637,10 +623,10 @@ static int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "netmask", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "netmask", value); return 0; } return 0; @@ -648,19 +634,19 @@ static int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, static int get_router_ipv4forwarding_static_route(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC) ? "1" : "0"; + *value = (((struct dm_data *)data)->config_section) ? "1" : "0"; return 0; } static int get_router_ipv4forwarding_forwarding_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def(((struct routingfwdargs *)data)->routefwdsection, "table", "-1"); + *value = dmuci_get_value_by_section_fallback_def(route_sec(data), "table", "-1"); return 0; } static int set_router_ipv4forwarding_forwarding_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *s = NULL, *dmmap_section = NULL; + struct uci_section *s = NULL; switch (action) { case VALUECHECK: @@ -678,13 +664,11 @@ static int set_router_ipv4forwarding_forwarding_policy(char *refparam, struct dm bbfdm_set_fault_message(ctx, "Route table '%s' value doesn't exist on the device. It's only allowed to set an available route table."); return FAULT_9007; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "table", value); - - get_dmmap_section_of_config_section("dmmap_routing", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "route_instance", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "table", value); + dmuci_set_value_by_section(((struct dm_data *)data)->dmmap_section, "route_instance", ""); break; } return 0; @@ -692,13 +676,13 @@ static int set_router_ipv4forwarding_forwarding_policy(char *refparam, struct dm static int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section) *value = "Static"; else { json_object *res = NULL; char *interface; - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "interface", &interface); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "interface", &interface); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); DM_ASSERT(res, *value = "DHCPv4"); char *proto = dmjson_get_value(res, 1, "proto"); @@ -710,7 +694,7 @@ static int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, v /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.GatewayIPAddress!UCI:network/route,@i-1/gateway*/ static int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "gateway", value); + dmuci_get_value_by_section_string(route_sec(data), "gateway", value); return 0; } @@ -722,10 +706,10 @@ static int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "gateway", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "gateway", value); return 0; } return 0; @@ -735,7 +719,7 @@ static int get_RoutingRouterForwarding_Interface(char *refparam, struct dmctx *c { char *linker = NULL; - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "interface", &linker); + dmuci_get_value_by_section_string(route_sec(data), "interface", &linker); _bbfdm_get_references(ctx, "Device.IP.Interface.", "Name", linker, value); return 0; } @@ -757,10 +741,10 @@ static int set_RoutingRouterForwarding_Interface(char *refparam, struct dmctx *c return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", reference.value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "interface", reference.value); return 0; } return 0; @@ -769,7 +753,7 @@ static int set_RoutingRouterForwarding_Interface(char *refparam, struct dmctx *c /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.ForwardingMetric!UCI:network/route,@i-1/metric*/ static int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def(((struct routingfwdargs *)data)->routefwdsection, "metric", "0"); + *value = dmuci_get_value_by_section_fallback_def(route_sec(data), "metric", "0"); return 0; } @@ -781,10 +765,10 @@ static int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, v return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "metric", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "metric", value); return 0; } return 0; @@ -792,12 +776,12 @@ static int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, v static int get_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) { + if (((struct dm_data *)data)->config_section == NULL) { // Dynamic route *value = "1"; } else { char *disabled = NULL; - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "disabled", &disabled); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "disabled", &disabled); *value = (disabled && *disabled == '1') ? "0" : "1"; } return 0; @@ -813,11 +797,11 @@ static int set_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx * return FAULT_9007; break; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; string_to_bool(value, &b); - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "disabled", b ? "0" : "1"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "disabled", b ? "0" : "1"); break; } return 0; @@ -833,7 +817,7 @@ static int get_RoutingRouterIPv6Forwarding_Status(char *refparam, struct dmctx * /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.DestIPPrefix!UCI:network/route,@i-1/target*/ static int get_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "target", value); + dmuci_get_value_by_section_string(route_sec(data), "target", value); return 0; } @@ -845,10 +829,10 @@ static int set_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct d return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "target", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "target", value); return 0; } return 0; @@ -856,13 +840,13 @@ static int set_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct d static int get_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def(((struct routingfwdargs *)data)->routefwdsection, "table", "-1"); + *value = dmuci_get_value_by_section_fallback_def(route_sec(data), "table", "-1"); return 0; } static int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *s = NULL, *dmmap_section = NULL; + struct uci_section *s = NULL; switch (action) { case VALUECHECK: @@ -880,13 +864,11 @@ static int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, stru bbfdm_set_fault_message(ctx, "Route table '%s' value doesn't exist on the device. It's only allowed to set an available route table."); return FAULT_9007; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "table", value); - - get_dmmap_section_of_config_section("dmmap_routing", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "route_instance", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "table", value); + dmuci_set_value_by_section(((struct dm_data *)data)->dmmap_section, "route_instance", ""); break; } return 0; @@ -895,7 +877,7 @@ static int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, stru /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.NextHop!UCI:network/route,@i-1/gateway*/ static int get_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "gateway", value); + dmuci_get_value_by_section_string(route_sec(data), "gateway", value); return 0; } @@ -907,10 +889,10 @@ static int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "gateway", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "gateway", value); return 0; } return 0; @@ -918,14 +900,15 @@ static int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx static int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC) ? "Static" : "DHCPv6"; + *value = (((struct dm_data *)data)->config_section) ? "Static" : "DHCPv6"; return 0; } + /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.ForwardingMetric!UCI:network/route,@i-1/metric*/ static int get_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def(((struct routingfwdargs *)data)->routefwdsection, "metric", "0"); + *value = dmuci_get_value_by_section_fallback_def(route_sec(data), "metric", "0"); return 0; } @@ -937,10 +920,10 @@ static int set_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, stru return FAULT_9007; return 0; case VALUESET: - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) + if (((struct dm_data *)data)->config_section == NULL) // Dynamic route return 0; - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "metric", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "metric", value); return 0; } return 0; @@ -1001,10 +984,10 @@ static int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, st char *target, *mask, *nexthop, *gateway, *ip_target, buf[64]; *value = "NoForwardingEntry"; - target = dmjson_get_value((struct json_object *)data, 1, "target"); - mask = dmjson_get_value((struct json_object *)data, 1, "mask"); + target = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "target"); + mask = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "mask"); snprintf(buf, sizeof(buf), "%s/%s", target, mask); - nexthop = dmjson_get_value((struct json_object *)data, 1, "nexthop"); + nexthop = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "nexthop"); uci_foreach_sections("network", "route6", s) { dmuci_get_value_by_section_string(s, "target", &ip_target); dmuci_get_value_by_section_string(s, "gateway", &gateway); @@ -1024,8 +1007,8 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, char cmd[32] = {0}; char *iface = NULL; - char *source = dmjson_get_value((struct json_object *)data, 1, "source"); - char *nexthop = dmjson_get_value((struct json_object *)data, 1, "nexthop"); + char *source = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "source"); + char *nexthop = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "nexthop"); snprintf(cmd, sizeof(cmd), "ip -6 route show"); @@ -1060,7 +1043,7 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, static int get_RoutingRouteInformationInterfaceSetting_SourceRouter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((struct json_object *)data, 1, "target"); + *value = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "target"); return 0; } @@ -1068,12 +1051,13 @@ static int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refpa { *value = "0001-01-01T00:00:00Z"; - char *valid = dmjson_get_value((struct json_object *)data, 1, "valid"); + char *valid = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "valid"); if (valid && *valid != '\0' && DM_STRTOL(valid) > 0) { char local_time[32] = {0}; if (get_shift_utc_time(DM_STRTOL(valid), local_time, sizeof(local_time)) == -1) return 0; + *value = dmstrdup(local_time); } return 0; @@ -1086,7 +1070,7 @@ static int get_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data { char *rt_table = NULL; - dmuci_get_value_by_section_string((struct uci_section *)data, "rt_table", &rt_table); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "rt_table", &rt_table); dmasprintf(value, "route_table-%s", rt_table ? rt_table : instance); return 0; } @@ -1107,78 +1091,22 @@ static int set_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data static int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - int route_type = ((struct routingfwdargs *)data)->type; - struct uci_section *dmmap_section = NULL; - - if (route_type == ROUTE_DYNAMIC) - dmmap_section = ((struct routingfwdargs *)data)->routefwdsection; - else - get_dmmap_section_of_config_section("dmmap_routing", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); - - dmuci_get_value_by_section_string(dmmap_section, "route_alias", value); - if ((*value)[0] == '\0') - dmasprintf(value, "cpe-%s", instance); - return 0; + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "route_alias", instance, value); } static int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - int route_type = ((struct routingfwdargs *)data)->type; - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (bbfdm_validate_string(ctx, value, -1, 64, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (route_type == ROUTE_DYNAMIC) - dmmap_section = ((struct routingfwdargs *)data)->routefwdsection; - else - get_dmmap_section_of_config_section("dmmap_routing", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); - - dmuci_set_value_by_section(dmmap_section, "route_alias", value); - return 0; - } - return 0; + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "route_alias", instance, value); } static int get_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - int route6_type = ((struct routingfwdargs *)data)->type; - struct uci_section *dmmap_section = NULL; - - if (route6_type == ROUTE_DYNAMIC) - dmmap_section = ((struct routingfwdargs *)data)->routefwdsection; - else - get_dmmap_section_of_config_section("dmmap_routing", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); - - dmuci_get_value_by_section_string(dmmap_section, "route6_alias", value); - if ((*value)[0] == '\0') - dmasprintf(value, "cpe-%s", instance); - return 0; + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "route6_alias", instance, value); } static int set_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - int route6_type = ((struct routingfwdargs *)data)->type; - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (bbfdm_validate_string(ctx, value, -1, 64, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (route6_type == ROUTE_DYNAMIC) - dmmap_section = ((struct routingfwdargs *)data)->routefwdsection; - else - get_dmmap_section_of_config_section("dmmap_routing", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); - - dmuci_set_value_by_section(dmmap_section, "route6_alias", value); - return 0; - } - return 0; + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "route6_alias", instance, value); } /************************************************************* @@ -1256,17 +1184,17 @@ static int delete_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, switch (del_action) { case DEL_INST: // Return 9008 error if the removed route is dynamic - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) { + if (((struct dm_data *)data)->config_section == NULL) { // Dynamic route bbfdm_set_fault_message(ctx, "This is a dynamic 'route' instance, therefore it's not permitted to delete it."); return FAULT_9008; } // Remove dmmap section - get_dmmap_section_of_config_section("dmmap_routing", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); + get_dmmap_section_of_config_section("dmmap_routing", "route", section_name(((struct dm_data *)data)->config_section), &dmmap_section); dmuci_delete_by_section(dmmap_section, NULL, NULL); // Remove config section - dmuci_delete_by_section(((struct routingfwdargs *)data)->routefwdsection, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); break; case DEL_ALL: dmuci_get_value_by_section_string((struct uci_section *)data, "rt_table", &rt_table); @@ -1314,17 +1242,17 @@ static int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, switch (del_action) { case DEL_INST: // Return 9008 error if the removed route6 is dynamic - if (((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC) { + if (((struct dm_data *)data)->config_section == NULL) { // Dynamic route bbfdm_set_fault_message(ctx, "This is a dynamic 'route' instance, therefore it's not permitted to delete it."); return FAULT_9008; } // Remove dmmap section - get_dmmap_section_of_config_section("dmmap_routing", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section); + get_dmmap_section_of_config_section("dmmap_routing", "route6", section_name(((struct dm_data *)data)->config_section), &dmmap_section); dmuci_delete_by_section(dmmap_section, NULL, NULL); // Remove config section - dmuci_delete_by_section(((struct routingfwdargs *)data)->routefwdsection, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); break; case DEL_ALL: dmuci_get_value_by_section_string((struct uci_section *)data, "rt_table", &rt_table); diff --git a/libbbfdm/dmtree/tr181/security.c b/libbbfdm/dmtree/tr181/security.c index e685eaa3..788659d3 100644 --- a/libbbfdm/dmtree/tr181/security.c +++ b/libbbfdm/dmtree/tr181/security.c @@ -22,17 +22,15 @@ static char certifcates_paths[MAX_CERT][CERT_PATH_LEN]; struct certificate_profile { char *path; X509 *cert; - struct uci_section *dmmap_sect; }; /************************************************************* * INIT **************************************************************/ -void init_certificate(char *path, X509 *cert, struct uci_section *dmsect, struct certificate_profile *certprofile) +void init_certificate(char *path, X509 *cert, struct certificate_profile *certprofile) { certprofile->path = path; certprofile->cert = cert; - certprofile->dmmap_sect = dmsect; } /************************************************************* @@ -142,9 +140,10 @@ static int get_certificate_paths(void) **************************************************************/ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { + struct certificate_profile certificateprofile = {0}; + struct uci_section *dmmap_sec = NULL; + struct dm_data curr_data = {0}; char *inst = NULL; - struct uci_section *dmmap_sect = NULL; - struct certificate_profile certificateprofile = {}; int i, status; get_certificate_paths(); @@ -164,16 +163,18 @@ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_nod continue; } - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_security", "security_certificate", "path", certifcates_paths[i])) == NULL) { - dmuci_add_section_bbfdm("dmmap_security", "security_certificate", &dmmap_sect); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "path", certifcates_paths[i]); + if ((dmmap_sec = get_dup_section_in_dmmap_opt("dmmap_security", "security_certificate", "path", certifcates_paths[i])) == NULL) { + dmuci_add_section_bbfdm("dmmap_security", "security_certificate", &dmmap_sec); + dmuci_set_value_by_section_bbfdm(dmmap_sec, "path", certifcates_paths[i]); } - init_certificate(certifcates_paths[i], cert, dmmap_sect, &certificateprofile); + init_certificate(certifcates_paths[i], cert, &certificateprofile); - inst = handle_instance(dmctx, parent_node, dmmap_sect, "security_certificate_instance", "security_certificate_alias"); + curr_data.additional_data = (void *)&certificateprofile; - status = DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&certificateprofile, inst); + inst = handle_instance(dmctx, parent_node, dmmap_sec, "security_certificate_instance", "security_certificate_alias"); + + status = DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst); X509_free(cert); cert = NULL; @@ -195,7 +196,7 @@ static int get_Security_CertificateNumberOfEntries(char *refparam, struct dmctx static int get_SecurityCertificate_LastModif(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct certificate_profile *cert_profile = (struct certificate_profile *)data; + struct certificate_profile *cert_profile = (struct certificate_profile *)((struct dm_data *)data)->additional_data; char buf[sizeof("AAAA-MM-JJTHH:MM:SSZ")] = "0001-01-01T00:00:00Z"; struct stat b; @@ -208,7 +209,7 @@ static int get_SecurityCertificate_LastModif(char *refparam, struct dmctx *ctx, static int get_SecurityCertificate_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct certificate_profile *cert_profile = (struct certificate_profile *)data; + struct certificate_profile *cert_profile = (struct certificate_profile *)((struct dm_data *)data)->additional_data; ASN1_INTEGER *serial = X509_get_serialNumber(cert_profile->cert); *value = generate_serial_number((char *)serial->data, serial->length); @@ -218,7 +219,7 @@ static int get_SecurityCertificate_SerialNumber(char *refparam, struct dmctx *ct static int get_SecurityCertificate_Issuer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct certificate_profile *cert_profile = (struct certificate_profile *)data; + struct certificate_profile *cert_profile = (struct certificate_profile *)((struct dm_data *)data)->additional_data; char buf[256] = {0}; X509_NAME_oneline(X509_get_issuer_name(cert_profile->cert), buf, sizeof(buf)); @@ -232,7 +233,7 @@ static int get_SecurityCertificate_Issuer(char *refparam, struct dmctx *ctx, voi static int get_SecurityCertificate_NotBefore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct certificate_profile *cert_profile = (struct certificate_profile *)data; + struct certificate_profile *cert_profile = (struct certificate_profile *)((struct dm_data *)data)->additional_data; char not_before_str[DATE_LEN]; struct tm tm; @@ -249,7 +250,7 @@ static int get_SecurityCertificate_NotBefore(char *refparam, struct dmctx *ctx, static int get_SecurityCertificate_NotAfter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct certificate_profile *cert_profile = (struct certificate_profile *)data; + struct certificate_profile *cert_profile = (struct certificate_profile *)((struct dm_data *)data)->additional_data; char not_after_str[DATE_LEN]; struct tm tm; @@ -266,7 +267,7 @@ static int get_SecurityCertificate_NotAfter(char *refparam, struct dmctx *ctx, v static int get_SecurityCertificate_Subject(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct certificate_profile *cert_profile = (struct certificate_profile *)data; + struct certificate_profile *cert_profile = (struct certificate_profile *)((struct dm_data *)data)->additional_data; char buf[256] = {0}; X509_NAME_oneline(X509_get_subject_name(cert_profile->cert), buf, sizeof(buf)); @@ -280,7 +281,7 @@ static int get_SecurityCertificate_Subject(char *refparam, struct dmctx *ctx, vo static int get_SecurityCertificate_SignatureAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct certificate_profile *cert_profile = (struct certificate_profile *)data; + struct certificate_profile *cert_profile = (struct certificate_profile *)((struct dm_data *)data)->additional_data; *value = dmstrdup(get_certificate_sig_alg(X509_get_signature_nid(cert_profile->cert)));