diff --git a/dmtree/tr181/atm.c b/dmtree/tr181/atm.c index 03b3de82..2ef1c5c1 100644 --- a/dmtree/tr181/atm.c +++ b/dmtree/tr181/atm.c @@ -238,13 +238,13 @@ static int get_atm_status(char *refparam, struct dmctx *ctx, void *data, char *i *************************************************************/ static int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { - char *instance = NULL, *atm_device = NULL, *v = NULL, *instance_update = NULL; + char *instance = NULL, *atm_device = NULL, *v = NULL; struct uci_section *dmmap_atm = NULL; check_create_dmmap_package("dmmap_dsl"); instance = get_last_instance_bbfdm("dmmap_dsl", "atm-device", "atmlinkinstance"); dmasprintf(&atm_device, "atm%d", instance ? atoi(instance) : 0); - dmasprintf(&instance_update, "%d", instance ? atoi(instance)+ 1 : 1); + dmuci_set_value("dsl", atm_device, "", "atm-device"); dmuci_set_value("dsl", atm_device, "name", "ATM"); dmuci_set_value("dsl", atm_device, "vpi", "8"); diff --git a/dmtree/tr181/ethernet.c b/dmtree/tr181/ethernet.c index 0945b71e..7e534c2f 100644 --- a/dmtree/tr181/ethernet.c +++ b/dmtree/tr181/ethernet.c @@ -45,11 +45,11 @@ static inline int init_eth_rmon(struct eth_rmon_args *args, struct uci_section * /************************************************************* * COMMON Functions **************************************************************/ -static int eth_iface_sysfs(const struct dm_args *args, const char *name, char **value) +static int eth_iface_sysfs(const struct uci_section *data, const char *name, char **value) { char *device; - dmuci_get_value_by_section_string(args->section, "device", &device); + dmuci_get_value_by_section_string((struct uci_section *)data, "device", &device); return get_net_device_sysfs(device, name, value); } @@ -182,7 +182,7 @@ static int dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_nod // Skip this interface section if ifname is empty dmuci_get_value_by_section_string(s, "ifname", &ifname); - if (*ifname == '\0') + if (*ifname == '\0' || strchr(ifname, '@')) continue; dmuci_get_value_by_section_string(s, "macaddr", &macaddr); @@ -241,18 +241,16 @@ static int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, static int browseEthernetLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dm_args args = {0}; struct uci_section *s = NULL; char *inst = NULL, *max_inst = NULL; dmmap_synchronizeEthernetLink(dmctx, NULL, NULL, NULL); uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { - args.section = s; inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5, s, "link_instance", "link_alias", "dmmap", "link"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP) break; } return 0; @@ -262,22 +260,21 @@ static int browseEthernetLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *type, *name, *inst = NULL, *max_inst = NULL; - struct dm_args curr_vlan_term_args = {0}; struct dmmap_dup *p = NULL; LIST_HEAD(dup_list); synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list); list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "type", &type); dmuci_get_value_by_section_string(p->config_section, "name", &name); if (strcmp(type, "untagged") == 0 || (*name != '\0' && !is_vlan_termination_section(name))) continue; - curr_vlan_term_args.section = p->config_section; inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5, p->dmmap_section, "vlan_term_instance", "vlan_term_alias", "dmmap_network", "device"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_vlan_term_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) break; } free_dmmap_config_dup_list(&dup_list); @@ -323,16 +320,13 @@ static int get_linker_interface(char *refparam, struct dmctx *dmctx, void *data, static int get_linker_link(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "device", linker); + dmuci_get_value_by_section_string((struct uci_section *)data, "device", linker); return 0; } static int get_linker_vlan_term(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if(data && ((struct dm_args *)data)->section) - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", linker); - else - *linker = ""; + dmuci_get_value_by_section_string((struct uci_section *)data, "name", linker); return 0; } @@ -365,9 +359,9 @@ static int delObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, cha switch (del_action) { case DEL_INST: - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", §_name); + dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", §_name); // Remove dmmap section - dmuci_delete_by_section(((struct dm_args *)data)->section, NULL, NULL); + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); // Check each network section in the list of sections if (*sect_name == '\0') @@ -430,10 +424,10 @@ static int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void switch (del_action) { case DEL_INST: // Remove device section - dmuci_delete_by_section(((struct dm_args *)data)->section, NULL, NULL); + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); // Remove device section in dmmap_network file - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct dm_args *)data)->section), &dmmap_section); + get_dmmap_section_of_config_section("dmmap_network", "device", section_name((struct uci_section *)data), &dmmap_section); dmuci_delete_by_section(dmmap_section, NULL, NULL); break; case DEL_ALL: @@ -904,7 +898,7 @@ static int get_EthernetLink_Status(char *refparam, struct dmctx *ctx, void *data static int get_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "link_alias", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "link_alias", value); if ((*value)[0] == '\0') dmasprintf(value, "cpe-%s", instance); return 0; @@ -918,7 +912,7 @@ static int set_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section(((struct dm_args *)data)->section, "link_alias", value); + dmuci_set_value_by_section((struct uci_section *)data, "link_alias", value); break; } return 0; @@ -926,7 +920,7 @@ static int set_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, static int get_EthernetLink_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "device", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "device", value); return 0; } @@ -935,7 +929,7 @@ static int get_EthernetLink_LastChange(char *refparam, struct dmctx *ctx, void * json_object *res; char *interface; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", &interface); + dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &interface); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); DM_ASSERT(res, *value = "0"); *value = dmjson_get_value(res, 1, "uptime"); @@ -947,11 +941,11 @@ static int get_EthernetLink_LastChange(char *refparam, struct dmctx *ctx, void * static int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "device", &linker); + dmuci_get_value_by_section_string((struct uci_section *)data, "device", &linker); char *bridge = strstr(linker, "br-"); if (bridge) { char *int_name; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", &int_name); + dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &int_name); struct uci_section *dmmap_section, *port; get_dmmap_section_of_config_section("dmmap_network", "interface", int_name, &dmmap_section); if (dmmap_section != NULL) { @@ -1001,8 +995,8 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void if (linker == NULL || *linker == '\0') return -1; - dmuci_set_value_by_section(((struct dm_args *)data)->section, "device", linker); - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", &int_name); + dmuci_set_value_by_section((struct uci_section *)data, "device", linker); + dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &int_name); struct uci_section *s; uci_foreach_sections("network", "interface", s) { if (strcmp(section_name(s), int_name) == 0) { @@ -1030,7 +1024,7 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void char *interface, *curr_interface; // Remove the network section corresponding to this dmmap interface if exists - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", &curr_interface); + dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &curr_interface); struct uci_section *s, *tmp; uci_foreach_sections_safe("network", "interface", tmp, s) { if (strcmp(section_name(s), curr_interface) == 0) { @@ -1054,8 +1048,8 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void if (*device == '\0') dmasprintf(&device, "br-%s", interface); // Get dmmap section - dmuci_set_value_by_section(((struct dm_args *)data)->section, "device", device); - dmuci_set_value_by_section(((struct dm_args *)data)->section, "section_name", interface); + dmuci_set_value_by_section((struct uci_section *)data, "device", device); + dmuci_set_value_by_section((struct uci_section *)data, "section_name", interface); } } break; @@ -1065,7 +1059,7 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void static int get_EthernetLink_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "mac", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "mac", value); return 0; } @@ -1144,7 +1138,7 @@ static int get_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, { struct uci_section *dmmap_section = NULL; - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct dm_args *)data)->section), &dmmap_section); + get_dmmap_section_of_config_section("dmmap_network", "device", section_name((struct uci_section *)data), &dmmap_section); dmuci_get_value_by_section_string(dmmap_section, "vlan_term_alias", value); if ((*value)[0] == '\0') dmasprintf(value, "cpe-%s", instance); @@ -1161,7 +1155,7 @@ static int set_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, return FAULT_9007; return 0; case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct dm_args *)data)->section), &dmmap_section); + get_dmmap_section_of_config_section("dmmap_network", "device", section_name((struct uci_section *)data), &dmmap_section); dmuci_set_value_by_section(dmmap_section, "vlan_term_alias", value); return 0; } @@ -1170,7 +1164,7 @@ static int set_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, static int get_EthernetVLANTermination_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmstrdup(section_name(((struct dm_args *)data)->section)); + *value = dmstrdup(section_name((struct uci_section *)data)); return 0; } @@ -1182,7 +1176,7 @@ static int get_EthernetVLANTermination_LastChange(char *refparam, struct dmctx * char *devname; *value = "0"; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &devname); + dmuci_get_value_by_section_string((struct uci_section *)data, "name", &devname); uci_foreach_option_eq("network", "interface", "ifname", devname, s) { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); DM_ASSERT(res, *value = "0"); @@ -1198,14 +1192,14 @@ static int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx { char *name, *type, *inner_vid, *dev_name; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &name); - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "type", &type); + dmuci_get_value_by_section_string((struct uci_section *)data, "name", &name); + dmuci_get_value_by_section_string((struct uci_section *)data, "type", &type); char *vid = strchr(name, '.'); if (vid) *vid = '\0'; if (strncmp(type, "8021ad", 6) == 0) { // 8021ad device, will have a vlan termination object as its lowerlayer - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "inner_vid", &inner_vid); + dmuci_get_value_by_section_string((struct uci_section *)data, "inner_vid", &inner_vid); dmasprintf(&dev_name, "%s.%s", name, inner_vid); adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cVLANTermination%c", dmroot, dm_delim, dm_delim, dm_delim), dev_name, value); } else { @@ -1237,7 +1231,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx return -1; // Get type option from device section - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "type", &type); + dmuci_get_value_by_section_string((struct uci_section *)data, "type", &type); if ((strcmp(type, "macvlan") == 0)) { /* type == macvlan */ @@ -1265,7 +1259,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx } else { /* type != macvlan */ char *vid; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "vid", &vid); + dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &vid); if (*vid != '\0') snprintf(new_name, sizeof(new_name), "%s.%s", linker, vid); else @@ -1276,8 +1270,8 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx } // Set ifname and name options of device section - dmuci_set_value_by_section(((struct dm_args *)data)->section, "ifname", linker); - dmuci_set_value_by_section(((struct dm_args *)data)->section, "name", new_name); + dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker); + dmuci_set_value_by_section((struct uci_section *)data, "name", new_name); } else if (strncmp(lower_layer, "Device.Ethernet.VLANTermination.", 32) == 0) { char new_name[16] = {0}, *linker = NULL; struct uci_section *ss = NULL; @@ -1288,7 +1282,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx return -1; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "vid", &vid); + dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &vid); uci_foreach_option_eq("network", "device", "name", linker, ss) { dmuci_get_value_by_section_string(ss, "vid", &inner_vid); @@ -1299,9 +1293,9 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx if (is_name_exist_in_devices(new_name)) return -1; - dmuci_set_value_by_section(((struct dm_args *)data)->section, "ifname", dev_name); - dmuci_set_value_by_section(((struct dm_args *)data)->section, "name", new_name); - dmuci_set_value_by_section(((struct dm_args *)data)->section, "inner_vid", inner_vid); + dmuci_set_value_by_section((struct uci_section *)data, "ifname", dev_name); + dmuci_set_value_by_section((struct uci_section *)data, "name", new_name); + dmuci_set_value_by_section((struct uci_section *)data, "inner_vid", inner_vid); } break; } @@ -1311,7 +1305,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx /*#Device.Ethernet.VLANTermination.{i}.VLANID!UCI:network/device,@i-1/vid*/ static int get_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def(((struct dm_args *)data)->section, "vid", "1"); + *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "vid", "1"); return 0; } @@ -1328,18 +1322,18 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, return 0; case VALUESET: // Get type option from device section - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "type", &type); + dmuci_get_value_by_section_string((struct uci_section *)data, "type", &type); if (strcmp(type, "macvlan") != 0) { /* only when type != macvlan */ - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "ifname", &ifname); + dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname); if (*ifname != '\0') { if (strcmp(type, "8021ad") == 0) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "inner_vid", &inner_vid); + dmuci_get_value_by_section_string((struct uci_section *)data, "inner_vid", &inner_vid); dmasprintf(&name, "%s.%s.%s", ifname, inner_vid, value); } else { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "vid", &old_vid); + dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &old_vid); dmasprintf(&old_name, "%s.%s.", ifname, old_vid); dmasprintf(&name, "%s.%s", ifname, value); } @@ -1348,7 +1342,7 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, return -1; // set ifname option of the corresponding interface section - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &curr_ifname); + dmuci_get_value_by_section_string((struct uci_section *)data, "name", &curr_ifname); uci_foreach_option_eq("network", "interface", "ifname", curr_ifname, s) { dmuci_set_value_by_section(s, "ifname", name); } @@ -1378,13 +1372,13 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, } // set name option of the device section - dmuci_set_value_by_section(((struct dm_args *)data)->section, "name", name); + dmuci_set_value_by_section((struct uci_section *)data, "name", name); dmfree(name); } } // set vid option of the device section - dmuci_set_value_by_section(((struct dm_args *)data)->section, "vid", value); + dmuci_set_value_by_section((struct uci_section *)data, "vid", value); return 0; } return 0; @@ -1393,7 +1387,7 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, /*#Device.Ethernet.VLANTermination.{i}.TPID!UCI:network/device,@i-1/type*/ static int get_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "type", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "type", value); if (strcmp(*value, "8021q") == 0) *value = "33024"; else if (strcmp(*value, "8021ad") == 0) @@ -1412,9 +1406,9 @@ static int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, v return 0; case VALUESET: if (strcmp(value, "33024") == 0) - dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", "8021q"); + dmuci_set_value_by_section((struct uci_section *)data, "type", "8021q"); else if (strcmp(value, "34984") == 0) - dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", "8021ad"); + dmuci_set_value_by_section((struct uci_section *)data, "type", "8021ad"); return 0; } return 0; @@ -1422,7 +1416,7 @@ static int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, v static int get_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "type", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "type", value); *value = (strcmp(*value, "macvlan") == 0) ? "1" : "0"; return 0; } @@ -1439,8 +1433,8 @@ static int set_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx break; case VALUESET: string_to_bool(value, &b); - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "ifname", &ifname); - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &name); + dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname); + dmuci_get_value_by_section_string((struct uci_section *)data, "name", &name); struct uci_section *s = NULL, *dmmap_s = NULL; char *link_instance, new_name[16] = {0}; if (b && *name != '\0') { @@ -1512,10 +1506,10 @@ static int set_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx } } - dmuci_set_value_by_section(((struct dm_args *)data)->section, "name", new_name); - dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", "macvlan"); + dmuci_set_value_by_section((struct uci_section *)data, "name", new_name); + dmuci_set_value_by_section((struct uci_section *)data, "type", "macvlan"); } else { - dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", b ? "macvlan" : "8021q"); + dmuci_set_value_by_section((struct uci_section *)data, "type", b ? "macvlan" : "8021q"); } break; } diff --git a/dmtree/tr181/interfacestack.c b/dmtree/tr181/interfacestack.c index 1ab1d225..d251559e 100644 --- a/dmtree/tr181/interfacestack.c +++ b/dmtree/tr181/interfacestack.c @@ -102,9 +102,14 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre /* Higher layers are Device.IP.Interface.{i}. */ uci_foreach_sections("network", "interface", s) { - char *proto; + char *proto, *ifname; + dmuci_get_value_by_section_string(s, "proto", &proto); - if (strcmp(section_name(s), "loopback") == 0 || *proto == '\0') + dmuci_get_value_by_section_string(s, "ifname", &ifname); + + if (strcmp(section_name(s), "loopback") == 0 || + *proto == '\0' || + strchr(ifname, '@')) continue; // The higher layer is Device.IP.Interface.{i}. diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index b10dd6c0..02891dc4 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 iopsys Software Solutions AB + * Copyright (C) 2020 iopsys Software Solutions AB * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 2.1 @@ -16,137 +16,846 @@ #include "diagnostics.h" #endif -struct ip_args +struct intf_ip_args { - struct uci_section *ip_sec; - char *ip_4address; + struct uci_section *interface_sec; + struct uci_section *dmmap_sec; + json_object *interface_obj; }; -struct ipv6_args -{ - struct uci_section *ip_sec; - char *ip_6address; - char *ip_6mask; - char *ip_6preferred; - char *ip_6valid; -}; - -struct ipv6prefix_args -{ - struct uci_section *ip_sec; - char *ip_6prefixaddress; - char *ip_6prefixmask; - char *ip_6prefixpreferred; - char *ip_6prefixvalid; -}; - -static unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) -{ - return 1; -} - -static unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) -{ - return 1; -} - /************************************************************* * INIT **************************************************************/ -static inline int init_ip_args(struct ip_args *args, struct uci_section *s, char *ip_4address) +static int init_interface_ip_args(struct intf_ip_args *args, struct uci_section *intf_s, struct uci_section *dmmap_s, json_object *intf_obj) { - args->ip_sec = s; - args->ip_4address = ip_4address; + args->interface_sec = intf_s; + args->dmmap_sec = dmmap_s; + args->interface_obj = intf_obj; return 0; } -static inline int init_ipv6_args(struct ipv6_args *args, struct uci_section *s, char *ip_6address, char *ip_6mask, char *ip_6preferred, char *ip_6valid) +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - args->ip_sec = s; - args->ip_6address = ip_6address; - args->ip_6mask = ip_6mask; - args->ip_6preferred = ip_6preferred; - args->ip_6valid = ip_6valid; + *linker = (data) ? dmstrdup(section_name((struct uci_section *)data)) : ""; return 0; } -static inline int init_ipv6prefix_args(struct ipv6prefix_args *args, struct uci_section *s, char *ip_6prefixaddress, char *ip_6prefixmask, char *ip_6prefixpreferred, char *ip_6prefixvalid) +static int get_linker_ipv6_prefix(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - args->ip_sec = s; - args->ip_6prefixaddress = ip_6prefixaddress; - args->ip_6prefixmask = ip_6prefixmask; - args->ip_6prefixpreferred = ip_6prefixpreferred; - args->ip_6prefixvalid = ip_6prefixvalid; + char *assign = NULL; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "0") == 0) { + char *address = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "address"); + char *mask = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "mask"); + dmasprintf(linker, "%s/%s", address, mask); + } else { + *linker = ""; + } return 0; } /************************************************************* * COMMON Functions **************************************************************/ -static int get_ip_iface_sysfs(const struct ip_args *ip, const char *name, char **value) +static int get_ip_iface_sysfs(const struct uci_section *data, const char *name, char **value) { - return get_net_iface_sysfs(section_name(ip->ip_sec), name, value); + return get_net_iface_sysfs(section_name((struct uci_section *)data), name, value); } -static char *ubus_call_get_value_with_two_objects(char *interface, char *obj1, char *obj2, char *key) +static void create_firewall_zone_config(char *iface) { - json_object *res, *jobj1 = NULL, *jobj2 = NULL; - char *value = ""; + struct uci_section *s; + char *value, *name; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if (res) { - jobj1 = dmjson_select_obj_in_array_idx(res, 0, 1, obj1); - if(jobj1) - jobj2 = dmjson_get_obj(jobj1, 1, obj2); - if(jobj2) - value = dmjson_get_value(jobj2, 1, key); + dmuci_add_section("firewall", "zone", &s, &value); + dmasprintf(&name, "fwl_%s", iface); + dmuci_set_value_by_section(s, "name", name); + dmuci_set_value_by_section(s, "input", "DROP"); + dmuci_set_value_by_section(s, "forward", "DROP"); + dmuci_set_value_by_section(s, "output", "ACCEPT"); + dmuci_set_value_by_section(s, "network", iface); + dmfree(name); +} + +static struct uci_section *update_dmmap_network_interface(char *dmmap_file_name, char *dmmap_sec_name, char *parent_section, char *section_name, char *option, char *value, bool assign) +{ + struct uci_section *dmmap_section = NULL; + char *sec_name, *name, *opt_value; + + uci_path_foreach_option_eq(bbfdm, dmmap_file_name, dmmap_sec_name, "parent_section", parent_section, dmmap_section) { + dmuci_get_value_by_section_string(dmmap_section, "section_name", &sec_name); + dmuci_get_value_by_section_string(dmmap_section, option, &opt_value); + if (strcmp(sec_name, section_name) == 0 && strcmp(opt_value, value) == 0) + return dmmap_section; } - return value; -} -static char *ubus_call_get_value(char *interface, char *obj, char *key) -{ - json_object *res, *jobj; - char *value = ""; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, obj); - value = dmjson_get_value(jobj, 1, key); + if (!dmmap_section) { + dmuci_add_section_bbfdm(dmmap_file_name, dmmap_sec_name, &dmmap_section, &name); + dmuci_set_value_by_section_bbfdm(dmmap_section, "parent_section", parent_section); + dmuci_set_value_by_section_bbfdm(dmmap_section, "section_name", section_name); + dmuci_set_value_by_section_bbfdm(dmmap_section, option, value); + if (assign) dmuci_set_value_by_section_bbfdm(dmmap_section, "assign", "1"); } - return value; + + return dmmap_section; } -static char *get_child_prefix_linker(char *interface) +static void synchronize_intf_ipv4_sections_with_dmmap(void) { - char *address = NULL, *mask = NULL, *value; - json_object *res, *jobj, *jobj1, *jobj2; + json_object *res = NULL, *ipv4_obj = NULL, *arrobj = NULL; + struct uci_section *s = NULL, *stmp = NULL; + char *dmmap_intf_s, *dmmap_address; + bool found = false; + int i = 0; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if(res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix"); - if(jobj) { - jobj1 = dmjson_get_obj(jobj, 1, "assigned"); - if(jobj1) { - jobj2 = dmjson_get_obj(jobj1, 1, "lan"); - if(jobj2) { - address = dmjson_get_value(jobj2, 1, "address"); - mask = dmjson_get_value(jobj2, 1, "mask"); - dmasprintf(&value, "%s/%s", address,mask); - return value; - } + uci_path_foreach_sections_safe(bbfdm, "dmmap_network_ipv4", "intf_ipv4", stmp, s) { + dmuci_get_value_by_section_string(s, "section_name", &dmmap_intf_s); + dmuci_get_value_by_section_string(s, "address", &dmmap_address); + found = false; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dmmap_intf_s, String}}, 1, &res); + + dmjson_foreach_obj_in_array(res, arrobj, ipv4_obj, i, 1, "ipv4-address") { + + char *address = dmjson_get_value(ipv4_obj, 1, "address"); + if (address && *address && strcmp(address, dmmap_address) == 0) { + found = true; + break; } + + } + + if (!found) + dmuci_delete_by_section(s, NULL, NULL); + } +} + +static void synchronize_intf_ipv6_sections_with_dmmap(void) +{ + json_object *res = NULL, *ipv6_obj = NULL, *arrobj = NULL; + struct uci_section *s = NULL, *stmp = NULL; + char *dmmap_intf_s, *dmmap_address; + bool found = false; + int i = 0; + + uci_path_foreach_sections_safe(bbfdm, "dmmap_network_ipv6", "intf_ipv6", stmp, s) { + dmuci_get_value_by_section_string(s, "section_name", &dmmap_intf_s); + dmuci_get_value_by_section_string(s, "address", &dmmap_address); + found = false; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dmmap_intf_s, String}}, 1, &res); + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_obj, i, 1, "ipv6-address") { + + char *address = dmjson_get_value(ipv6_obj, 1, "address"); + if (address && *address && strcmp(address, dmmap_address) == 0) { + found = true; + break; + } + + } + + if (found) + continue; + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_obj, i, 1, "ipv6-prefix-assignment") { + + char *address = dmjson_get_value(ipv6_obj, 2, "local-address", "address"); + if (address && *address && strcmp(address, dmmap_address) == 0) { + found = true; + break; + } + + } + + if (!found) + dmuci_delete_by_section(s, NULL, NULL); + } +} + +static void synchronize_intf_ipv6_prefix_sections_with_dmmap(void) +{ + json_object *res = NULL, *ipv6_prefix_obj = NULL, *arrobj = NULL; + struct uci_section *s = NULL, *stmp = NULL; + char *dmmap_intf_s, *dmmap_address, ipv6_prefix[256] = {0}; + bool found = false; + int i = 0; + + uci_path_foreach_sections_safe(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", stmp, s) { + dmuci_get_value_by_section_string(s, "section_name", &dmmap_intf_s); + dmuci_get_value_by_section_string(s, "address", &dmmap_address); + found = false; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dmmap_intf_s, String}}, 1, &res); + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_prefix_obj, i, 1, "ipv6-prefix") { + + char *address = dmjson_get_value(ipv6_prefix_obj, 1, "address"); + char *mask = dmjson_get_value(ipv6_prefix_obj, 1, "mask"); + if (*address == '\0' || *mask == '\0') + continue; + + snprintf(ipv6_prefix, sizeof(ipv6_prefix), "%s/%s", address, mask); + if (strcmp(ipv6_prefix, dmmap_address) == 0) { + found = true; + break; + } + + } + + if (found) + continue; + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_prefix_obj, i, 1, "ipv6-prefix-assignment") { + + char *address = dmjson_get_value(ipv6_prefix_obj, 1, "address"); + char *mask = dmjson_get_value(ipv6_prefix_obj, 1, "mask"); + if (*address == '\0' || *mask == '\0') + continue; + + snprintf(ipv6_prefix, sizeof(ipv6_prefix), "%s/%s", address, mask); + if (strcmp(ipv6_prefix, dmmap_address) == 0) { + found = true; + break; + } + + } + + if (!found) + dmuci_delete_by_section(s, NULL, NULL); + } +} + +static char *get_ip_interface_last_instance(char *package, char *section, char* dmmap_package, char *opt_inst) +{ + struct uci_section *s = NULL, *dmmap_section = NULL; + char *instance = NULL, *last_inst = NULL, *v = NULL, *proto, *ifname; + + uci_foreach_sections(package, section, s) { + + dmuci_get_value_by_section_string(s, "proto", &proto); + dmuci_get_value_by_section_string(s, "ifname", &ifname); + + if (strcmp(section_name(s), "loopback") == 0 || + *proto == '\0' || + strchr(ifname, '@')) + continue; + + get_dmmap_section_of_config_section(dmmap_package, section, section_name(s), &dmmap_section); + if (dmmap_section == NULL) { + dmuci_add_section_bbfdm(dmmap_package, section, &dmmap_section, &v); + dmuci_set_value_by_section(dmmap_section, "section_name", section_name(s)); + } + instance = update_instance(last_inst, 4, dmmap_section, opt_inst, dmmap_package, section); + if(last_inst) + dmfree(last_inst); + last_inst = dmstrdup(instance); + } + return instance; +} + +static int delete_ip_intertace_instance(struct uci_section *s) +{ + // Get dmmap section related to this interface section + struct uci_section *dmmap_section = NULL; + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section); + + // Read the type option from interface section + char *type; + dmuci_get_value_by_section_string(s, "type", &type); + + // Check the type value ==> if bridge : there is a Bridging.Bridge. object mapped to this interface, remove only proto option from the section + // Check the type value ==> else : there is no Bridging.Bridge. object mapped to this interface, remove the section + if (strcmp(type, "bridge") == 0) { + /* type is bridge ==> remove only proto option from the interface section and ip instance option from dmmap section */ + dmuci_set_value_by_section(s, "proto", ""); + dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); + } else { + /* Remove the device section corresponding to this interface if exists */ + char *device = get_device( section_name(s)); + struct uci_section *ss = NULL, *stmp = NULL; + uci_foreach_option_eq_safe("network", "device", "name", device, stmp, ss) { + char *device_type; + dmuci_get_value_by_section_string(ss, "type", &device_type); + if (strcmp(device_type, "untagged") == 0) dmuci_delete_by_section(ss, NULL, NULL); + break; + } + /* type is not bridge */ + /* remove dmmap section related to this interface */ + dmuci_delete_by_section(dmmap_section, NULL, NULL); + + /* Remove "IPv4Address" child section related to this "IP.Interface." object */ + uci_foreach_option_eq_safe("dmmap_network_ipv4", "intf_ipv4", "parent_section", section_name(s), stmp, ss) { + dmuci_delete_by_section(ss, NULL, NULL); + } + + /* Remove "IPv6Address" child section related to this "IP.Interface." object */ + uci_foreach_option_eq_safe("dmmap_network_ipv6", "intf_ipv6", "parent_section", section_name(s), stmp, ss) { + dmuci_delete_by_section(ss, NULL, NULL); + } + + /* Remove "IPv6PrefixAddress" child section related to this "IP.Interface." object */ + uci_foreach_option_eq_safe("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "parent_section", section_name(s), stmp, ss) { + dmuci_delete_by_section(ss, NULL, NULL); + } + + /* remove interface section */ + dmuci_delete_by_section(s, NULL, NULL); + } + return 0; +} + +static bool interface_section_with_dhcpv6_exists(const char *sec_name) +{ + struct uci_section *s = NULL; + char buf[32] = {0}; + + snprintf(buf, sizeof(buf), "@%s", sec_name); + + uci_foreach_sections("network", "interface", s) { + + char *ifname; + dmuci_get_value_by_section_string(s, "ifname", &ifname); + if (strcmp(ifname, buf) == 0) { + char *proto; + dmuci_get_value_by_section_string(s, "proto", &proto); + if (strcmp(proto, "dhcpv6") == 0) + return true; } } - return ""; + + return false; +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.IP.Interface.{i}.!UCI:network/interface/dmmap_network*/ +static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *inst = NULL, *max_inst = NULL; + char *proto, *ifname; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list); + list_for_each_entry(p, &dup_list, list) { + + dmuci_get_value_by_section_string(p->config_section, "proto", &proto); + dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); + + if (strcmp(section_name(p->config_section), "loopback") == 0 || + *proto == '\0' || + strchr(ifname, '@')) + continue; + + inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5, + p->dmmap_section, "ip_int_instance", "ip_int_alias", "dmmap_network", "interface"); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *parent_sec = (struct uci_section *)prev_data, *intf_s = NULL, *dmmap_s = NULL; + char *inst = NULL, *max_inst = NULL, *ifname, buf[32] = {0}; + json_object *res = NULL, *ipv4_obj = NULL, *arrobj = NULL; + struct intf_ip_args curr_intf_ip_args = {0}; + struct browse_args browse_args = {0}; + int i = 0; + + snprintf(buf, sizeof(buf), "@%s", section_name(parent_sec)); + + synchronize_intf_ipv4_sections_with_dmmap(); + uci_foreach_sections("network", "interface", intf_s) { + + dmuci_get_value_by_section_string(intf_s, "ifname", &ifname); + if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && strcmp(ifname, buf) != 0) + continue; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(intf_s), String}}, 1, &res); + + dmjson_foreach_obj_in_array(res, arrobj, ipv4_obj, i, 1, "ipv4-address") { + + char *address = dmjson_get_value(ipv4_obj, 1, "address"); + if (*address == '\0') + continue; + + dmmap_s = update_dmmap_network_interface("dmmap_network_ipv4", "intf_ipv4", section_name(parent_sec), section_name(intf_s), "address", address, false); + + init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv4_obj); + + browse_args.option = "parent_section"; + browse_args.value = section_name(parent_sec); + + inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, + dmmap_s, "ipv4_instance", "ipv4_alias", "dmmap_network_ipv4", "intf_ipv4", + check_browse_section, (void *)&browse_args); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP) + goto end; + } + } + +end: + return 0; +} + +static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *parent_sec = (struct uci_section *)prev_data, *intf_s = NULL, *dmmap_s = NULL; + char *inst = NULL, *max_inst = NULL, *ifname, buf[32] = {0}; + json_object *res = NULL, *ipv6_obj = NULL, *arrobj = NULL; + struct intf_ip_args curr_intf_ip_args = {0}; + struct browse_args browse_args = {0}; + int i = 0; + + snprintf(buf, sizeof(buf), "@%s", section_name(parent_sec)); + + synchronize_intf_ipv6_sections_with_dmmap(); + uci_foreach_sections("network", "interface", intf_s) { + + dmuci_get_value_by_section_string(intf_s, "ifname", &ifname); + if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && strcmp(ifname, buf) != 0) + continue; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(intf_s), String}}, 1, &res); + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_obj, i, 1, "ipv6-address") { + + char *address = dmjson_get_value(ipv6_obj, 1, "address"); + if (*address == '\0') + continue; + + dmmap_s = update_dmmap_network_interface("dmmap_network_ipv6", "intf_ipv6", section_name(parent_sec), section_name(intf_s), "address", address, false); + + init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_obj); + + browse_args.option = "parent_section"; + browse_args.value = section_name(parent_sec); + + inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, + dmmap_s, "ipv6_instance", "ipv6_alias", "dmmap_network_ipv6", "intf_ipv6", + check_browse_section, (void *)&browse_args); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP) + goto end; + } + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_obj, i, 1, "ipv6-prefix-assignment") { + + char *address = dmjson_get_value(ipv6_obj, 2, "local-address", "address"); + if (*address == '\0') + continue; + + dmmap_s = update_dmmap_network_interface("dmmap_network_ipv6", "intf_ipv6", section_name(parent_sec), section_name(intf_s), "address", address, true); + + init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_obj); + + browse_args.option = "parent_section"; + browse_args.value = section_name(parent_sec); + + inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, + dmmap_s, "ipv6_instance", "ipv6_alias", "dmmap_network_ipv6", "intf_ipv6", + check_browse_section, (void *)&browse_args); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP) + goto end; + } + } + +end: + return 0; +} + +static int browseIPInterfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *parent_sec = (struct uci_section *)prev_data, *intf_s = NULL, *dmmap_s = NULL; + char *inst = NULL, *max_inst = NULL, *ifname, buf[32] = {0}, ipv6_prefix[256] = {0}; + json_object *res = NULL, *ipv6_prefix_obj = NULL, *arrobj = NULL; + struct intf_ip_args curr_intf_ip_args = {0}; + struct browse_args browse_args = {0}; + int i = 0; + + snprintf(buf, sizeof(buf), "@%s", section_name(parent_sec)); + + synchronize_intf_ipv6_prefix_sections_with_dmmap(); + uci_foreach_sections("network", "interface", intf_s) { + + dmuci_get_value_by_section_string(intf_s, "ifname", &ifname); + if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && strcmp(ifname, buf) != 0) + continue; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(intf_s), String}}, 1, &res); + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_prefix_obj, i, 1, "ipv6-prefix") { + + char *address = dmjson_get_value(ipv6_prefix_obj, 1, "address"); + char *mask = dmjson_get_value(ipv6_prefix_obj, 1, "mask"); + if (*address == '\0' || *mask == '\0') + continue; + + snprintf(ipv6_prefix, sizeof(ipv6_prefix), "%s/%s", address, mask); + dmmap_s = update_dmmap_network_interface("dmmap_network_ipv6_prefix","intf_ipv6_prefix", section_name(parent_sec), section_name(intf_s), "address", ipv6_prefix, false); + + init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_prefix_obj); + + browse_args.option = "parent_section"; + browse_args.value = section_name(parent_sec); + + inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, + dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias", "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", + check_browse_section, (void *)&browse_args); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP) + goto end; + } + + dmjson_foreach_obj_in_array(res, arrobj, ipv6_prefix_obj, i, 1, "ipv6-prefix-assignment") { + + char *address = dmjson_get_value(ipv6_prefix_obj, 1, "address"); + char *mask = dmjson_get_value(ipv6_prefix_obj, 1, "mask"); + if (*address == '\0' || *mask == '\0') + continue; + + snprintf(ipv6_prefix, sizeof(ipv6_prefix), "%s/%s", address, mask); + dmmap_s = update_dmmap_network_interface("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", section_name(parent_sec), section_name(intf_s), "address", ipv6_prefix, true); + + init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_prefix_obj); + + browse_args.option = "parent_section"; + browse_args.value = section_name(parent_sec); + + inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, + dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias", "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", + check_browse_section, (void *)&browse_args); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP) + goto end; + } + } + +end: + return 0; +} + +/************************************************************* +* ADD & DEL OBJ +**************************************************************/ +static int addObjIPInterface(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *last_inst = NULL, *v, ip_name[32] = {0}; + struct uci_section *dmmap_ip_interface; + + last_inst = get_ip_interface_last_instance("network", "interface", "dmmap_network", "ip_int_instance"); + snprintf(ip_name, sizeof(ip_name), "ip_interface_%d", last_inst ? atoi(last_inst) + 1 : 1); + + dmuci_set_value("network", ip_name, "", "interface"); + dmuci_set_value("network", ip_name, "proto", "static"); + + dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ip_interface, &v); + dmuci_set_value_by_section(dmmap_ip_interface, "section_name", ip_name); + *instance = update_instance(last_inst, 4, dmmap_ip_interface, "ip_int_instance", "dmmap_network", "interface"); + return 0; +} + +static int delObjIPInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *stmp = NULL; + + switch (del_action) { + case DEL_INST: + delete_ip_intertace_instance((struct uci_section *)data); + break; + case DEL_ALL: + uci_foreach_sections_safe("network", "interface", stmp, s) { + char *proto, *ifname; + dmuci_get_value_by_section_string(s, "proto", &proto); + dmuci_get_value_by_section_string(s, "ifname", &ifname); + + if (strcmp(section_name(s), "loopback") == 0 || + *proto == '\0' || + strchr(ifname, '@')) + continue; + + delete_ip_intertace_instance(s); + } + break; + } + return 0; +} + +static int addObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + // check the proto option from the interface section parent, if proto="static" ==> we can add a new object, else return 9001 error + char *proto; + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strcmp(proto, "static") != 0) + return FAULT_9001; + + char *last_inst = NULL, *ip_inst, *v, ipv4_name[64] = {0}, buf[32] = {0}; + struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv4; + struct browse_args browse_args = {0}; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface); + dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst); + + last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv4", "intf_ipv4", "ipv4_instance", "parent_section", section_name((struct uci_section *)data)); + snprintf(ipv4_name, sizeof(ipv4_name), "ip_interface_%s_ipv4_%d", ip_inst, last_inst ? atoi(last_inst) + 1 : 1); + snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data)); + + dmuci_set_value("network", ipv4_name, "", "interface"); + dmuci_set_value("network", ipv4_name, "ifname", buf); + dmuci_set_value("network", ipv4_name, "proto", "static"); + dmuci_set_value("network", ipv4_name, "ipaddr", "0.0.0.0"); + dmuci_set_value("network", ipv4_name, "netmask", "0.0.0.0"); + + browse_args.option = "parent_section"; + browse_args.value = section_name((struct uci_section *)data); + + dmuci_add_section_bbfdm("dmmap_network_ipv4", "intf_ipv4", &dmmap_ip_interface_ipv4, &v); + dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "parent_section", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "section_name", ipv4_name); + dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "address", "0.0.0.0"); + + *instance = update_instance(last_inst, 6, dmmap_ip_interface_ipv4, "ipv4_instance", "dmmap_network_ipv4", "intf_ipv4", check_browse_section, (void *)&browse_args); + return 0; +} + +static int delObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *stmp = NULL, *dmmap_s = NULL; + char *proto, *ifname, buf[32] = {0}; + + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + if (strcmp(proto, "static") != 0) + return FAULT_9001; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ifname", &ifname); + if (strchr(ifname, '@')) { + dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL); + } else { + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipaddr", ""); + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "netmask", ""); + } + + dmuci_delete_by_section(((struct intf_ip_args *)data)->dmmap_sec, NULL, NULL); + break; + case DEL_ALL: + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strcmp(proto, "static") != 0) + return FAULT_9001; + + snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data)); + + uci_foreach_sections_safe("network", "interface", stmp, s) { + + dmuci_get_value_by_section_string(s, "ifname", &ifname); + + if (strcmp(section_name(s), section_name((struct uci_section *)data)) == 0) { + dmuci_set_value_by_section(s, "ipaddr", ""); + dmuci_set_value_by_section(s, "netmask", ""); + + get_dmmap_section_of_config_section("dmmap_network_ipv4", "intf_ipv4", section_name(s), &dmmap_s); + dmuci_delete_by_section(dmmap_s, NULL, NULL); + } else if (strcmp(ifname, buf) == 0) { + get_dmmap_section_of_config_section("dmmap_network_ipv4", "intf_ipv4", section_name(s), &dmmap_s); + dmuci_delete_by_section(dmmap_s, NULL, NULL); + + dmuci_delete_by_section(s, NULL, NULL); + } else { + continue; + } + } + break; + } + return 0; +} + +static int addObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + // check the proto option from the interface section parent, if proto="static" ==> you can add a new object, else return 9001 error + char *proto; + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data)))) + return FAULT_9001; + + char *last_inst = NULL, *ip_inst, *v, ipv6_name[64] = {0}, buf[32] = {0}; + struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6; + struct browse_args browse_args = {0}; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface); + dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst); + + last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6", "intf_ipv6", "ipv6_instance", "parent_section", section_name((struct uci_section *)data)); + snprintf(ipv6_name, sizeof(ipv6_name), "ip_interface_%s_ipv6_%d", ip_inst, last_inst ? atoi(last_inst) + 1 : 1); + snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data)); + + dmuci_set_value("network", ipv6_name, "", "interface"); + dmuci_set_value("network", ipv6_name, "ifname", buf); + dmuci_set_value("network", ipv6_name, "proto", "static"); + dmuci_set_value("network", ipv6_name, "ip6addr", "::"); + + browse_args.option = "parent_section"; + browse_args.value = section_name((struct uci_section *)data); + + dmuci_add_section_bbfdm("dmmap_network_ipv6", "intf_ipv6", &dmmap_ip_interface_ipv6, &v); + dmuci_set_value_by_section(dmmap_ip_interface_ipv6, "parent_section", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_ip_interface_ipv6, "section_name", ipv6_name); + dmuci_set_value_by_section(dmmap_ip_interface_ipv6, "address", "::"); + + *instance = update_instance(last_inst, 6, dmmap_ip_interface_ipv6, "ipv6_instance", "dmmap_network_ipv6", "intf_ipv6", check_browse_section, (void *)&browse_args); + return 0; +} + +static int delObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *stmp = NULL, *dmmap_s = NULL; + char *proto, *ifname, buf[32] = {0}; + + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec)))) + return FAULT_9001; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ifname", &ifname); + if (strchr(ifname, '@')) { + dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL); + } else { + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6addr", ""); + } + + dmuci_delete_by_section(((struct intf_ip_args *)data)->dmmap_sec, NULL, NULL); + break; + case DEL_ALL: + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data)))) + return FAULT_9001; + + snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data)); + + uci_foreach_sections_safe("network", "interface", stmp, s) { + + dmuci_get_value_by_section_string(s, "ifname", &ifname); + + if (strcmp(section_name(s), section_name((struct uci_section *)data)) == 0) { + dmuci_set_value_by_section(s, "ip6addr", ""); + + get_dmmap_section_of_config_section("dmmap_network_ipv6", "intf_ipv6", section_name(s), &dmmap_s); + dmuci_delete_by_section(dmmap_s, NULL, NULL); + } else if (strcmp(ifname, buf) == 0) { + get_dmmap_section_of_config_section("dmmap_network_ipv6", "intf_ipv6", section_name(s), &dmmap_s); + dmuci_delete_by_section(dmmap_s, NULL, NULL); + + dmuci_delete_by_section(s, NULL, NULL); + } else { + continue; + } + } + break; + } + return 0; +} + +static int addObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + // check the proto option from the interface section parent, if proto="static" ==> you can add a new object, else return 9001 error + char *proto; + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data)))) + return FAULT_9001; + + char *last_inst = NULL, *ip_inst, *v, ipv6_prefix_name[64] = {0}, buf[32] = {0}; + struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6_prefix; + struct browse_args browse_args = {0}; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface); + dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst); + + last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "ipv6_prefix_instance", "parent_section", section_name((struct uci_section *)data)); + snprintf(ipv6_prefix_name, sizeof(ipv6_prefix_name), "ip_interface_%s_ipv6_prefix_%d", ip_inst, last_inst ? atoi(last_inst) + 1 : 1); + snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data)); + + dmuci_set_value("network", ipv6_prefix_name, "", "interface"); + dmuci_set_value("network", ipv6_prefix_name, "ifname", buf); + dmuci_set_value("network", ipv6_prefix_name, "proto", "static"); + dmuci_set_value("network", ipv6_prefix_name, "ip6prefix", "::/64"); + + browse_args.option = "parent_section"; + browse_args.value = section_name((struct uci_section *)data); + + dmuci_add_section_bbfdm("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", &dmmap_ip_interface_ipv6_prefix, &v); + dmuci_set_value_by_section(dmmap_ip_interface_ipv6_prefix, "parent_section", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_ip_interface_ipv6_prefix, "section_name", ipv6_prefix_name); + dmuci_set_value_by_section(dmmap_ip_interface_ipv6_prefix, "address", "::/64"); + + *instance = update_instance(last_inst, 6, dmmap_ip_interface_ipv6_prefix, "ipv6_prefix_instance", "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", check_browse_section, (void *)&browse_args); + return 0; +} + +static int delObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *stmp = NULL, *dmmap_s = NULL; + char *proto, *ifname, buf[32] = {0}; + + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec)))) + return FAULT_9001; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ifname", &ifname); + if (strchr(ifname, '@')) { + dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL); + } else { + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6prefix", ""); + } + + dmuci_delete_by_section(((struct intf_ip_args *)data)->dmmap_sec, NULL, NULL); + break; + case DEL_ALL: + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data)))) + return FAULT_9001; + + snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data)); + uci_foreach_sections_safe("network", "interface", stmp, s) { + + dmuci_get_value_by_section_string(s, "ifname", &ifname); + + if (strcmp(section_name(s), section_name((struct uci_section *)data)) == 0) { + dmuci_set_value_by_section(s, "ip6prefix", ""); + + get_dmmap_section_of_config_section("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", section_name(s), &dmmap_s); + dmuci_delete_by_section(dmmap_s, NULL, NULL); + } else if (strcmp(ifname, buf) == 0) { + get_dmmap_section_of_config_section("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", section_name(s), &dmmap_s); + dmuci_delete_by_section(dmmap_s, NULL, NULL); + + dmuci_delete_by_section(s, NULL, NULL); + } else { + continue; + } + } + break; + } + return 0; } /************************************************************* * GET & SET PARAM **************************************************************/ -/* - * *** Device.IP. *** - */ static int get_IP_IPv4Capable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = folder_exists("/proc/sys/net/ipv4") ? "1" : "0"; @@ -250,6 +959,7 @@ static int get_IP_IPv6Status(char *refparam, struct dmctx *ctx, void *data, char return 0; } +/*#Device.IP.ULAPrefix!UCI:network/globals,globals/ula_prefix*/ static int get_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("network", "globals", "ula_prefix", value); @@ -274,90 +984,70 @@ static int get_IP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, vo { struct uci_section *s = NULL; int cnt = 0; - char *proto; + char *proto, *ifname; uci_foreach_sections("network", "interface", s) { dmuci_get_value_by_section_string(s, "proto", &proto); - if (strcmp(section_name(s), "loopback") == 0 || *proto == '\0') + dmuci_get_value_by_section_string(s, "ifname", &ifname); + + if (strcmp(section_name(s), "loopback") == 0 || + *proto == '\0' || + strchr(ifname, '@')) continue; + cnt++; } dmasprintf(value, "%d", cnt); return 0; } -/* - * *** Device.IP.Interface. *** - */ /*#Device.IP.Interface.{i}.Enable!UCI:network/interface,@i-1/disabled*/ static int get_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *v; - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "disabled", &v); - *value = (*v != '1') ? "1" : "0"; + char *disabled; + dmuci_get_value_by_section_string((struct uci_section *)data, "disabled", &disabled); + *value = (*disabled == '1') ? "0" : "1"; return 0; } static int set_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "disabled", (b) ? "0" : "1"); - break; - } - return 0; -} -/*#Device.IP.Interface.{i}.Status!UCI:network/interface,@i-1/disabled*/ -static int get_IPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *val = NULL; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); - DM_ASSERT(res, *value = "Down"); - val = dmjson_get_value(res, 1, "up"); - *value = !strcmp(val, "true") ? "Up" : "Down"; - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.Status!UCI:network/interface,@i-1/disabled*/ -static int get_IPInterfaceIPv4Address_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *val = NULL; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); - DM_ASSERT(res, *value = "Disabled"); - val = dmjson_get_value(res, 1, "up"); - *value = !strcmp(val, "true") ? "Enabled" : "Disabled"; - return 0; -} - -static int get_IPInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(section_name(((struct ip_args *)data)->ip_sec)); - return 0; -} - -static int get_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -static int set_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ switch (action) { case VALUECHECK: if (dm_validate_boolean(value)) return FAULT_9007; break; case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "disabled", b ? "0" : "1"); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Enable!UCI:network/interface,@i-1/disabled*/ +static int get_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *disabled; + dmuci_get_value_by_section_string((struct uci_section *)data, "disabled", &disabled); + *value = (*disabled == '1') ? "0" : "1"; + return 0; +} + +static int set_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "disabled", b ? "0" : "1"); break; } return 0; @@ -366,9 +1056,7 @@ static int set_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *d /*#Device.IP.Interface.{i}.IPv6Enable!UCI:network/interface,@i-1/ipv6*/ static int get_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *v; - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv6", &v); - *value = (*v != '0') ? "1" : "0"; + *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ipv6", "1"); return 0; } @@ -383,22 +1071,213 @@ static int set_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *d break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv6", (b) ? "" : "0"); + dmuci_set_value_by_section((struct uci_section *)data, "ipv6", b ? "1" : "0"); break; } return 0; } +/*#Device.IP.Interface.{i}.Status!UCI:network/interface,@i-1/disabled*/ +static int get_IPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res); + DM_ASSERT(res, *value = "Down"); + char *up = dmjson_get_value(res, 1, "up"); + *value = (strcmp(up, "true") == 0) ? "Up" : "Down"; + return 0; +} + +/*#Device.IP.Interface.{i}.Alias!UCI:dmmap_network/interface,@i-1/ip_int_alias*/ +static int get_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "ip_int_alias", value); + if ((*value)[0] == '\0') + dmasprintf(value, "cpe-%s", instance); + return 0; +} + +static int set_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) + return FAULT_9007; + break; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "ip_int_alias", value); + break; + } + return 0; +} + +static int get_IPInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(section_name((struct uci_section *)data)); + return 0; +} + /*#Device.IP.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ static int get_IPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); - DM_ASSERT(res, *value = ""); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res); + DM_ASSERT(res, *value = "0"); *value = dmjson_get_value(res, 1, "uptime"); return 0; } +static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *proto; + + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strstr(proto, "ppp")) { + char linker[64] = {0}; + snprintf(linker, sizeof(linker), "%s", section_name((struct uci_section *)data)); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value != NULL) + return 0; + } + + char *device = get_device(section_name((struct uci_section *)data)); + if (device[0] != '\0') { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cVLANTermination%c", dmroot, dm_delim, dm_delim, dm_delim), device, value); + if (*value != NULL) + return 0; + } + + if (device[0] != '\0') { + char linker[32] = {0}; + strncpy(linker, device, sizeof(linker) - 1); + char *vid = strchr(linker, '.'); + if (vid) *vid = '\0'; + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value != NULL) + return 0; + } + + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker = NULL; + char lower_layer[256] = {0}; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, 0, NULL, 0)) + return FAULT_9007; + break; + case VALUESET: + 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); + + if (linker == NULL || *linker == '\0') + return -1; + + struct uci_section *s = NULL, *stmp = NULL; + + // Remove the device section corresponding to this interface if exists + char *device = get_device(section_name((struct uci_section *)data)); + uci_foreach_option_eq_safe("network", "device", "name", device, stmp, s) { + char *type; + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "untagged") == 0) dmuci_delete_by_section(s, NULL, NULL); + break; + } + + char *mac_vlan = strchr(linker, '_'); + if (mac_vlan) { + // Check if there is an interface that has the same ifname ==> if yes, remove it + uci_foreach_option_eq_safe("network", "interface", "ifname", linker, stmp, s) { + dmuci_delete_by_section(s, NULL, NULL); + } + + // Check if there is an dmmap link section that has the same device ==> if yes, update section name + get_dmmap_section_of_config_section_eq("dmmap", "link", "device", linker, &s); + dmuci_set_value_by_section_bbfdm(s, "section_name", section_name((struct uci_section *)data)); + + } else { + // Check if there is an interface that has the same name of device ==> if yes, remove it + char device[32] = {0}; + strncpy(device, linker, sizeof(device) - 1); + char *vid = strchr(device, '.'); + if (vid) { + *vid = '\0'; + uci_foreach_option_eq_safe("network", "interface", "ifname", device, stmp, s) { + dmuci_delete_by_section(s, NULL, NULL); + } + } + } + + // Update ifname list + dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker); + + } else if (strncmp(lower_layer, "Device.Ethernet.Link.", 21) == 0) { + adm_entry_get_linker_value(ctx, lower_layer, &linker); + + if (linker == NULL || *linker == '\0') + return -1; + + // Get interface name from Ethernet.Link. object + struct uci_section *s = NULL; + char *interface, *ifname = NULL; + get_dmmap_section_of_config_section_eq("dmmap", "link", "device", linker, &s); + dmuci_get_value_by_section_string(s, "section_name", &interface); + + dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname); + if (ifname && *ifname) { + + // Update the new interface section with proto=dhcp + uci_foreach_sections("network", "interface", s) { + if (strcmp(section_name(s), interface) == 0) { + dmuci_set_value_by_section(s, "proto", "dhcp"); + break; + } + } + + // Get dmmap section related to this interface section and remove it + struct uci_section *dmmap_section = NULL; + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); + + // Get the current ip instance + char *ip_int_instance; + dmuci_get_value_by_section_string(dmmap_section, "ip_int_instance", &ip_int_instance); + + // Get the new dmmap section related to the new interface section and update ip instance option + struct uci_section *new_dmmap_section = NULL; + get_dmmap_section_of_config_section("dmmap_network", "interface", interface, &new_dmmap_section); + dmuci_set_value_by_section(new_dmmap_section, "ip_int_instance", ip_int_instance); + + // remove dmmap section + dmuci_delete_by_section(dmmap_section, NULL, NULL); + + // remove the current interface section + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + + } else { + char *device = get_device(interface); + dmuci_set_value_by_section((struct uci_section *)data, "ifname", device); + } + } + break; + } + return 0; +} + static int get_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "Device.Routing.Router.1"; @@ -429,7 +1308,7 @@ static int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, bool b; char *ubus_object; - switch (action) { + switch (action) { case VALUECHECK: if (dm_validate_boolean(value)) return FAULT_9007; @@ -447,6 +1326,7 @@ static int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, return 0; } +/*#Device.IP.Interface.{i}.MaxMTUSize!SYSFS:/sys/class/net/@Name/mtu*/ static int get_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "mtu", value); @@ -460,7 +1340,7 @@ static int set_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *d return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "mtu", value); + dmuci_set_value_by_section((struct uci_section *)data, "mtu", value); break; } return 0; @@ -468,19 +1348,13 @@ static int set_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *d static int get_IPInterface_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (strcmp(section_name(((struct ip_args *)data)->ip_sec), "loopback") == 0) - *value = "Loopback"; - else - *value = "Normal"; + *value = (strcmp(section_name((struct uci_section *)data), "loopback") == 0) ? "Loopback" : "Normal"; return 0; } static int get_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (strcmp(section_name(((struct ip_args *)data)->ip_sec), "loopback") == 0) - *value = "1"; - else - *value = "0"; + *value = (strcmp(section_name((struct uci_section *)data), "loopback") == 0) ? "1" : "0"; return 0; } @@ -499,25 +1373,24 @@ static int set_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *dat static int get_IPInterface_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s; - char *inst; + struct uci_section *s = NULL; + int cnt = 0; - *value = "0"; - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "interface", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "ipv4_instance", &inst); - if(inst[0] != '\0') - *value = "1"; + synchronize_intf_ipv4_sections_with_dmmap(); + uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv4", "intf_ipv4", "parent_section", section_name((struct uci_section *)data), s) { + cnt++; } + dmasprintf(value, "%d", cnt); return 0; } static int get_IPInterface_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s; + struct uci_section *s = NULL; int cnt = 0; - *value = "0"; - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { + synchronize_intf_ipv6_sections_with_dmmap(); + uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6", "intf_ipv6", "parent_section", section_name((struct uci_section *)data), s) { cnt++; } dmasprintf(value, "%d", cnt); @@ -526,11 +1399,11 @@ static int get_IPInterface_IPv6AddressNumberOfEntries(char *refparam, struct dmc static int get_IPInterface_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s; + struct uci_section *s = NULL; int cnt = 0; - *value = "0"; - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { + synchronize_intf_ipv6_prefix_sections_with_dmmap(); + uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "parent_section", section_name((struct uci_section *)data), s) { cnt++; } dmasprintf(value, "%d", cnt); @@ -541,375 +1414,307 @@ static int get_IPInterface_TWAMPReflectorNumberOfEntries(char *refparam, struct { struct uci_section *s = NULL; int cnt = 0; - uci_foreach_option_eq("twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)data)->ip_sec), s) { - cnt++; + + uci_foreach_option_eq("twamp", "twamp_reflector", "interface", section_name((struct uci_section *)data), s) { + cnt++; } dmasprintf(value, "%d", cnt); return 0; } -/* - * *** Device.IP.Interface.{i}.IPv4Address.{i}. *** - */ -static struct uci_section *create_firewall_zone_config(char *iface) +/*#Device.IP.Interface.{i}.IPv4Address.{i}.Enable!UCI:network/interface,@i-1/disabled*/ +static int get_IPInterfaceIPv4Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s; - char *value, *name; - - dmuci_add_section("firewall", "zone", &s, &value); - dmasprintf(&name, "fwl_%s", iface); - dmuci_set_value_by_section(s, "name", name); - dmuci_set_value_by_section(s, "input", "DROP"); - dmuci_set_value_by_section(s, "forward", "DROP"); - dmuci_set_value_by_section(s, "output", "ACCEPT"); - dmuci_set_value_by_section(s, "network", iface); - dmfree(name); - return s; -} - -static int get_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *input = "", *forward = ""; - struct uci_section *s = NULL; - - uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "input", &input); - dmuci_get_value_by_section_string(s, "forward", &forward); - if (strcmp(input, "ACCEPT") !=0 && strcmp(forward, "ACCEPT") !=0) { - *value = "1"; - return 0; - } - } - *value = "0"; + char *disabled = NULL; + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "disabled", &disabled); + *value = (disabled && *disabled == '1') ? "0" : "1"; return 0; } -static int set_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_IPInterfaceIPv4Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - int cnt = 0; - struct uci_section *s = NULL; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - value = b ? "DROP" : "ACCEPT"; - uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) { - dmuci_set_value_by_section(s, "input", value); - dmuci_set_value_by_section(s, "forward", value); - cnt++; - } - if (cnt == 0 && b) - create_firewall_zone_config(section_name(((struct ip_args *)data)->ip_sec)); - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.IPAddress!UCI:network/interface,@i-1/ipaddr*/ -static int get_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct ip_args *)data)->ip_4address; - return 0; -} - -static int set_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, 15, NULL, 0, IPv4Address, 1)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", value); - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.SubnetMask!UCI:network/interface,@i-1/netmask*/ -static int get_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *jobj; - char *mask; - - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "netmask", &mask); - if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - mask = dmjson_get_value(jobj, 1, "mask"); - if (mask[0] == '\0') - return 0; - mask = cidr2netmask(atoi(mask)); - } - } - *value = mask; - return 0; -} - -static int set_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, 15, NULL, 0, IPv4Address, 1)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "netmask", value); - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.AddressingType!UCI:network/interface,@i-1/proto*/ -static int get_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", value); - if (strcmp(*value, "static") == 0) - *value = "Static"; - else if (strcmp(*value, "dhcp") == 0) - *value = "DHCP"; - else - *value = ""; - return 0; -} - -static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *proto, *device, linker[64] = {0}; - - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); - if (strstr(proto, "ppp")) { - snprintf(linker, sizeof(linker), "%s", section_name(((struct ip_args *)data)->ip_sec)); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value != NULL) - return 0; - } - - device = get_device(section_name(((struct ip_args *)data)->ip_sec)); - if (device[0] != '\0') { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cVLANTermination%c", dmroot, dm_delim, dm_delim, dm_delim), device, value); - if (*value != NULL) - return 0; - } - - if (device[0] != '\0') { - char linker[32] = {0}; - strncpy(linker, device, sizeof(linker) - 1); - char *vid = strchr(linker, '.'); - if (vid) *vid = '\0'; - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value != NULL) - return 0; - } - - if (*value == NULL) - *value = ""; - return 0; -} - -static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker = NULL; - char lower_layer[256] = {0}; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, 0, NULL, 0)) - return FAULT_9007; - return 0; - case VALUESET: - 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); - - if (linker == NULL || *linker == '\0') - return -1; - - struct uci_section *s = NULL, *stmp = NULL; - - // Remove the device section corresponding to this interface if exists - char *device = get_device(section_name(((struct ip_args *)data)->ip_sec)); - uci_foreach_option_eq_safe("network", "device", "name", device, stmp, s) { - char *type; - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "untagged") == 0) dmuci_delete_by_section(s, NULL, NULL); - break; - } - - char *mac_vlan = strchr(linker, '_'); - if (mac_vlan) { - // Check if there is an interface that has the same ifname ==> if yes, remove it - uci_foreach_option_eq_safe("network", "interface", "ifname", linker, stmp, s) { - dmuci_delete_by_section(s, NULL, NULL); - } - - // Check if there is an dmmap link section that has the same device ==> if yes, update section name - get_dmmap_section_of_config_section_eq("dmmap", "link", "device", linker, &s); - dmuci_set_value_by_section_bbfdm(s, "section_name", section_name(((struct ip_args *)data)->ip_sec)); - - } else { - // Check if there is an interface that has the same name of device ==> if yes, remove it - char device[32] = {0}; - strncpy(device, linker, sizeof(device) - 1); - char *vid = strchr(device, '.'); - if (vid) { - *vid = '\0'; - uci_foreach_option_eq_safe("network", "interface", "ifname", device, stmp, s) { - dmuci_delete_by_section(s, NULL, NULL); - } - } - } - - // Update ifname list - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ifname", linker); - - } else if (strncmp(lower_layer, "Device.Ethernet.Link.", 21) == 0) { - adm_entry_get_linker_value(ctx, lower_layer, &linker); - - if (linker == NULL || *linker == '\0') - return -1; - - // Get interface name from Ethernet.Link. object - struct uci_section *s = NULL; - char *interface; - get_dmmap_section_of_config_section_eq("dmmap", "link", "device", linker, &s); - dmuci_get_value_by_section_string(s, "section_name", &interface); - - // Update the new interface section with proto=dhcp - uci_foreach_sections("network", "interface", s) { - if (strcmp(section_name(s), interface) == 0) { - dmuci_set_value_by_section(s, "proto", "dhcp"); - break; - } - } - - // Get dmmap section related to this interface section and remove it - struct uci_section *dmmap_section = NULL; - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - - // Get the current ip instance - char *ip_int_instance; - dmuci_get_value_by_section_string(dmmap_section, "ip_int_instance", &ip_int_instance); - - // Get the new dmmap section related to the new interface section and update ip instance option - struct uci_section *new_dmmap_section = NULL; - get_dmmap_section_of_config_section("dmmap_network", "interface", interface, &new_dmmap_section); - dmuci_set_value_by_section(new_dmmap_section, "ip_int_instance", ip_int_instance); - - // remove dmmap section - dmuci_delete_by_section(dmmap_section, NULL, NULL); - - // remove the current interface section - dmuci_delete_by_section(((struct ip_args *)data)->ip_sec, NULL, NULL); - } - return 0; - } - return 0; -} - -/* - * *** Device.IP.Interface.{i}.IPv6Address.{i}. *** - */ -/*#Device.IP.Interface.{i}.IPv6Address.{i}.IPAddress!UCI:network/interface,@i-1/ip6addr*/ -static int get_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct ipv6_args *)data)->ip_6address; - return 0; -} - -static int set_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, 45, NULL, 0, IPv6Address, 1)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", value); - return 0; - } - return 0; -} - -static int get_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -static int set_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ switch (action) { case VALUECHECK: if (dm_validate_boolean(value)) return FAULT_9007; break; case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "disabled", b ? "0" : "1"); break; } return 0; } +/*#Device.IP.Interface.{i}.IPv4Address.{i}.Status!UCI:network/interface,@i-1/disabled*/ +static int get_IPInterfaceIPv4Address_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + get_IPInterfaceIPv4Address_Enable(refparam, ctx, data, instance, value); + *value = ((*value)[0] == '1') ? "Enabled" : "Disabled"; + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Address.{i}.Alias!UCI:dmmap_network_ipv4/intf_ipv4,@i-1/ipv4_alias*/ +static int get_IPInterfaceIPv4Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "ipv4_alias", value); + if ((*value)[0] == '\0') + dmasprintf(value, "cpe-%s", instance); + return 0; +} + +static int set_IPInterfaceIPv4Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "ipv4_alias", value); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Address.{i}.IPAddress!UCI:network/interface,@i-1/ipaddr*/ +static int get_IPInterfaceIPv4Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "address"); + return 0; +} + +static int set_IPInterfaceIPv4Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 15, NULL, 0, IPv4Address, 1)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + if (proto && strcmp(proto, "static") == 0) { + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipaddr", value); + dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "address", value); + } + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Address.{i}.SubnetMask!UCI:network/interface,@i-1/netmask*/ +static int get_IPInterfaceIPv4Address_SubnetMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *mask = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "mask"); + *value = (mask && *mask) ? cidr2netmask(atoi(mask)) : ""; + return 0; +} + +static int set_IPInterfaceIPv4Address_SubnetMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 15, NULL, 0, IPv4Address, 1)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + if (proto && strcmp(proto, "static") == 0) + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "netmask", value); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Address.{i}.AddressingType!UCI:network/interface,@i-1/proto*/ +static int get_IPInterfaceIPv4Address_AddressingType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", value); + *value = (strcmp(*value, "dhcp") == 0) ? "DHCP" : "Static"; + return 0; +} + +static int get_IPInterfaceIPv4Address_X_IOPSYS_EU_FirewallEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *input = NULL, *forward = NULL; + + *value = "0"; + uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct intf_ip_args *)data)->interface_sec), s) { + dmuci_get_value_by_section_string(s, "input", &input); + dmuci_get_value_by_section_string(s, "forward", &forward); + if (input && strcmp(input, "ACCEPT") != 0 && forward && strcmp(forward, "ACCEPT") != 0) { + *value = "1"; + break; + } + } + + return 0; +} + +static int set_IPInterfaceIPv4Address_X_IOPSYS_EU_FirewallEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL; + int cnt = 0; + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + value = b ? "DROP" : "ACCEPT"; + uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct intf_ip_args *)data)->interface_sec), s) { + dmuci_set_value_by_section(s, "input", value); + dmuci_set_value_by_section(s, "forward", value); + cnt++; + } + if (cnt == 0 && b) + create_firewall_zone_config(section_name(((struct intf_ip_args *)data)->interface_sec)); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Address.{i}.Enable!UCI:network/interface,@i-1/ipv6*/ +static int get_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmuci_get_value_by_section_fallback_def(((struct intf_ip_args *)data)->interface_sec, "ipv6", "1"); + return 0; +} + +static int set_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipv6", b ? "1" : "0"); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Address.{i}.Status!UCI:network/interface,@i-1/ipv6*/ static int get_IPInterfaceIPv6Address_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "Enabled"; + get_IPInterfaceIPv6Address_Enable(refparam, ctx, data, instance, value); + *value = ((*value)[0] == '1') ? "Enabled" : "Disabled"; return 0; } static int get_IPInterfaceIPv6Address_IPAddressStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if(((struct ipv6_args *)data)->ip_6valid[0] != '\0') - *value = "Preferred"; + char *assign = NULL, *preferred = NULL; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "1") == 0) + preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "preferred"); else - *value = "Unknown"; + preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); + + *value = (preferred && *preferred != '\0') ? "Preferred" : "Invalid"; + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Address.{i}.Alias!UCI:dmmap_network_ipv6/intf_ipv6,@i-1/ipv6_alias*/ +static int get_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "ipv6_alias", value); + if ((*value)[0] == '\0') + dmasprintf(value, "cpe-%s", instance); + return 0; +} + +static int set_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "ipv6_alias", value); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Address.{i}.IPAddress!UCI:network/interface,@i-1/ip6addr*/ +static int get_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "address", value); + return 0; +} + +static int set_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 45, NULL, 0, IPv6Address, 1)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + if (proto && strcmp(proto, "static") == 0) { + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6addr", value); + dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "address", value); + } + break; + } return 0; } static int get_IPInterfaceIPv6Address_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ubus_call_get_value_with_two_objects(section_name(((struct ipv6_args *)data)->ip_sec), "ipv6-prefix-assignment", "local-address", "address"); - if(*value[0] != '\0') + char *assign = NULL; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "1") == 0) { *value = "AutoConfigured"; - else { - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", value); - if (strcmp(*value, "static") == 0) - *value = "Static"; - else if (strcmp(*value, "dhcpv6") == 0) - *value = "DHCPv6"; - else - *value = "WellKnown"; + } else { + char *proto; + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + *value = (strcmp(proto, "dhcpv6") == 0) ? "DHCPv6" : "Static"; } return 0; } static int get_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dmmap_section; - char *inst; + char *assign = NULL; - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ipv6_args *)data)->ip_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "ip_int_instance", &inst); + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "1") == 0) { + struct uci_section *dmmap_section = NULL; + char *ip_inst = NULL, *ipv6_prefix_inst = NULL, *parent_section, *section_name; - *value = ""; - if(((struct ipv6prefix_args *)data)->ip_6prefixaddress[0] != '\0') - dmasprintf(value, "Device.IP.Interface.%s.IPv6Prefix.1", inst); + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "parent_section", &parent_section); + get_dmmap_section_of_config_section("dmmap_network", "interface", parent_section, &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "ip_int_instance", &ip_inst); + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "section_name", §ion_name); + get_dmmap_section_of_config_section("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", section_name, &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "ipv6_prefix_instance", &ipv6_prefix_inst); + + if (ip_inst && *ip_inst && ipv6_prefix_inst && *ipv6_prefix_inst) + dmasprintf(value, "Device.IP.Interface.%s.IPv6Prefix.%s", ip_inst, ipv6_prefix_inst); + } return 0; } @@ -926,178 +1731,178 @@ static int set_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, return 0; } -/*#Device.IP.Interface.{i}.IPv6Address.{i}.PreferredLifetime!UCI:network/interface,@i-1/adv_preferred_lifetime*/ static int get_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char local_time[32] = {0}; - char *preferred = ((struct ipv6_args *)data)->ip_6preferred; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + char *assign = NULL, *preferred = NULL, local_time[32] = {0}; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "1") == 0) + preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "preferred"); + else + preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); + + if (preferred && *preferred && get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) return 0; - *value = dmstrdup(local_time); + + *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; return 0; } static int set_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char buf[32] = "", *proto; - - switch (action) { + switch (action) { case VALUECHECK: if (dm_validate_dateTime(value)) return FAULT_9007; - return 0; + break; case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); - if(strcasecmp(proto, "static") == 0) { - get_shift_time_shift(value, buf); - if (!(*buf)) - return 0; - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "adv_preferred_lifetime", buf); - } - return 0; + break; } return 0; } -/*#Device.IP.Interface.{i}.IPv6Address.{i}.ValidLifetime!UCI:network/interface,@i-1/adv_valid_lifetime*/ static int get_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char local_time[32] = {0}; - char *preferred = ((struct ipv6_args *)data)->ip_6valid; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + char *assign = NULL, *preferred = NULL, local_time[32] = {0}; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "1") == 0) + preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "preferred"); + else + preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); + + if (preferred && *preferred && get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) return 0; - *value = dmstrdup(local_time); + + *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; return 0; } static int set_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char buf[32] = "", *proto; - - switch (action) { + switch (action) { case VALUECHECK: if (dm_validate_dateTime(value)) return FAULT_9007; - return 0; + break; case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); - if(strcasecmp(proto, "static") == 0) { - get_shift_time_shift(value, buf); - if (!(*buf)) - return 0; - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "adv_valid_lifetime", buf); - } - return 0; + break; } return 0; } -/* - * *** Device.IP.Interface.{i}.IPv6Prefix.{i}. *** - */ +/*#Device.IP.Interface.{i}.IPv6Prefix.{i}.Enable!UCI:network/interface,@i-1/ipv6*/ static int get_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "1"; + char *ipv6 = NULL; + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ipv6", &ipv6); + *value = (ipv6 && *ipv6 != '0') ? "1" : "0"; return 0; } static int set_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + bool b; + switch (action) { case VALUECHECK: if (dm_validate_boolean(value)) return FAULT_9007; break; case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipv6", b ? "1" : "0"); break; } return 0; } +/*#Device.IP.Interface.{i}.IPv6Prefix.{i}.Status!UCI:network/interface,@i-1/ipv6*/ static int get_IPInterfaceIPv6Prefix_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "Enabled"; + get_IPInterfaceIPv6Prefix_Enable(refparam, ctx, data, instance, value); + *value = ((*value)[0] == '1') ? "Enabled" : "Disabled"; return 0; } static int get_IPInterfaceIPv6Prefix_PrefixStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if(((struct ipv6prefix_args *)data)->ip_6prefixvalid[0] != '\0') - *value = "Preferred"; - else - *value = "Unknown"; + char *preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); + *value = (preferred && *preferred) ? "Preferred" : "Invalid"; + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Prefix.{i}.Alias!UCI:dmmap_network_ipv6_prefix/intf_ipv6_prefix,@i-1/ipv6_prefix_alias*/ +static int get_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "ipv6_prefix_alias", value); + if ((*value)[0] == '\0') + dmasprintf(value, "cpe-%s", instance); + return 0; +} + +static int set_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "ipv6_prefix_alias", value); + break; + } return 0; } /*#Device.IP.Interface.{i}.IPv6Prefix.{i}.Prefix!UCI:network/interface,@i-1/ip6prefix*/ static int get_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct ipv6prefix_args *)data)->ip_6prefixaddress; - if(((struct ipv6prefix_args *)data)->ip_6prefixmask[0] != '\0') - dmasprintf(value, "%s/%s", ((struct ipv6prefix_args *)data)->ip_6prefixaddress, ((struct ipv6prefix_args *)data)->ip_6prefixmask); + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "address", value); return 0; } static int set_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *proto; - switch (action) { + char *proto = NULL; + + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 49, NULL, 0, IPv6Prefix, 1)) return FAULT_9007; - return 0; + break; case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6prefix_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "ip6prefix", value); - return 0; + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + if (proto && strcmp(proto, "static") == 0) { + dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6prefix", value); + dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "address", value); + } + break; } return 0; } static int get_IPInterfaceIPv6Prefix_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ubus_call_get_value(section_name(((struct ipv6prefix_args *)data)->ip_sec), "ipv6-prefix-assignment", "address"); - if(*value[0] != '\0') + char *assign = NULL; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "1") == 0) { *value = "AutoConfigured"; - else { - dmuci_get_value_by_section_string(((struct ipv6prefix_args *)data)->ip_sec, "proto", value); - if (strcmp(*value, "static") == 0) - *value = "Static"; - else if (strcmp(*value, "dhcpv6") == 0) - *value = "DHCPv6"; - else - *value = "WellKnown"; - } - return 0; -} - -static int get_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Static"; - return 0; -} - -static int set_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, -1, StaticType, 4, NULL, 0)) - return FAULT_9007; - break; - case VALUESET: - break; + } else { + char *proto = NULL; + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); + *value = (proto && strcmp(proto, "dhcpv6") == 0) ? "DHCPv6" : "Static"; } return 0; } static int get_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *linker; - dmasprintf(&linker, "%s/%s", ((struct ipv6prefix_args *)data)->ip_6prefixaddress, ((struct ipv6prefix_args *)data)->ip_6prefixmask); - if(linker[0] != '\0') + char *linker = NULL; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "address", &linker); + if (linker && *linker) adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) *value = ""; @@ -1119,7 +1924,15 @@ static int set_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx * static int get_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = get_child_prefix_linker(section_name(((struct ipv6prefix_args *)data)->ip_sec)); + char *assign = NULL; + + dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); + if (assign && strcmp(assign, "0") == 0) { + char *address = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "address"); + char *mask = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "mask"); + if (address && *address && mask && *mask) + dmasprintf(value, "%s/%s", address, mask); + } return 0; } @@ -1139,17 +1952,18 @@ static int set_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmct static int get_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char local_time[32] = {0}; - char *preferred = ((struct ipv6prefix_args *)data)->ip_6prefixpreferred; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + + char *preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); + if (preferred && *preferred && get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) return 0; - *value = dmstrdup(local_time); + + *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; return 0; } static int set_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - switch (action) { + switch (action) { case VALUECHECK: if (dm_validate_dateTime(value)) return FAULT_9007; @@ -1163,17 +1977,18 @@ static int set_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dm static int get_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char local_time[32] = {0}; - char *preferred = ((struct ipv6prefix_args *)data)->ip_6prefixvalid; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + + char *valid = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "valid"); + if (valid && *valid && get_shift_time_time(atoi(valid), local_time, sizeof(local_time)) == -1) return 0; - *value = dmstrdup(local_time); + + *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; return 0; } static int set_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - switch (action) { + switch (action) { case VALUECHECK: if (dm_validate_dateTime(value)) return FAULT_9007; @@ -1184,686 +1999,67 @@ static int set_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx return 0; } -/* - * *** Device.IP.Interface.{i}.Stats. *** - */ -static int get_ip_interface_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.BytesSent!SYSFS:/sys/class/net/@Name/statistics/tx_bytes*/ +static int get_IPInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/tx_bytes", value); } -static int get_ip_interface_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.BytesReceived!SYSFS:/sys/class/net/@Name/statistics/rx_bytes*/ +static int get_IPInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/rx_bytes", value); } -static int get_ip_interface_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.PacketsSent!SYSFS:/sys/class/net/@Name/statistics/tx_packets*/ +static int get_IPInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/tx_packets", value); } -static int get_ip_interface_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.PacketsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_packets*/ +static int get_IPInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/rx_packets", value); } -static int get_ip_interface_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.ErrorsSent!SYSFS:/sys/class/net/@Name/statistics/tx_errors*/ +static int get_IPInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/tx_errors", value); } -static int get_ip_interface_statistics_rx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.ErrorsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_errors*/ +static int get_IPInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/rx_errors", value); } -static int get_ip_interface_statistics_tx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.DiscardPacketsSent!SYSFS:/sys/class/net/@Name/statistics/tx_dropped*/ +static int get_IPInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/tx_dropped", value); } -static int get_ip_interface_statistics_rx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.DiscardPacketsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_dropped*/ +static int get_IPInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/rx_dropped", value); } -static int get_ip_interface_statistics_rx_multicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.IP.Interface.{i}.Stats.MulticastPacketsReceived!SYSFS:/sys/class/net/@Name/statistics/multicast*/ +static int get_IPInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_ip_iface_sysfs(data, "statistics/multicast", value); } -/************************************************************* -* GET & SET ALIAS -**************************************************************/ -/*#Device.IP.Interface.{i}.Alias!UCI:dmmap_network/interface,@i-1/ip_int_alias*/ -static int get_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "ip_int_alias", value); - if ((*value)[0] == '\0') - dmasprintf(value, "cpe-%s", instance); - return 0; -} - -static int set_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "ip_int_alias", value); - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.Alias!UCI:dmmap_network/interface,@i-1/ipv4_alias*/ -static int get_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "ipv4_alias", value); - if ((*value)[0] == '\0') - dmasprintf(value, "cpe-%s", instance); - return 0; -} - -static int set_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "ipv4_alias", value); - return 0; - } - return 0; -} - -static int get_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "ipv6_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if (strcmp(name, section_name(((struct ipv6_args *)data)->ip_sec)) == 0) { - dmuci_get_value_by_section_string(dmmap_section, "ipv6_alias", value); - if ((*value)[0] == '\0') - dmasprintf(value, "cpe-%s", instance); - } - } - return 0; -} - -static int set_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) - return FAULT_9007; - return 0; - case VALUESET: - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "ipv6_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if(strcmp(name, section_name(((struct ipv6_args *)data)->ip_sec)) == 0) - break; - } - dmuci_set_value_by_section(dmmap_section, "ipv6_alias", value); - return 0; - } - return 0; -} - -static int get_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "ipv6prefix_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if(strcmp(name, section_name(((struct ipv6prefix_args *)data)->ip_sec)) == 0) { - dmuci_get_value_by_section_string(dmmap_section, "ipv6prefix_alias", value); - if ((*value)[0] == '\0') - dmasprintf(value, "cpe-%s", instance); - } - } - return 0; -} - -static int set_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) - return FAULT_9007; - return 0; - case VALUESET: - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "ipv6prefix_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if(strcmp(name, section_name(((struct ipv6prefix_args *)data)->ip_sec)) == 0) - break; - } - dmuci_set_value_by_section(dmmap_section, "ipv6prefix_alias", value); - return 0; - } - return 0; -} - -/************************************************************* -* ADD & DEL OBJ -**************************************************************/ -static char *get_last_instance_cond(char *dmmap_package, char *package, char *section, char *opt_inst, char *opt_cond, char *cond_val, char *opt_filter, char *filter_val, char *refused_interface) -{ - struct uci_section *s, *dmmap_section; - char *inst = NULL, *val, *val_f; - char *ipv4addr = "", *ipv6addr = "", *proto; - json_object *res, *jobj; - - uci_foreach_sections(package, section, s) { - if (opt_cond) dmuci_get_value_by_section_string(s, opt_cond, &val); - if (opt_filter) dmuci_get_value_by_section_string(s, opt_filter, &val_f); - if(opt_cond && opt_filter && (strcmp(val, cond_val) == 0 || strcmp(val_f, filter_val) == 0)) - continue; - if (strcmp(section_name(s), refused_interface)==0) - continue; - - dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); - if (ipv4addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipv4addr = dmjson_get_value(jobj, 1, "address"); - } - } - dmuci_get_value_by_section_string(s, "ip6addr", &ipv6addr); - if (ipv6addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); - ipv6addr = dmjson_get_value(jobj, 1, "address"); - } - } - dmuci_get_value_by_section_string(s, "proto", &proto); - if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(val, "bridge") != 0) { - continue; - } - get_dmmap_section_of_config_section(dmmap_package, section, section_name(s), &dmmap_section); - inst = update_instance(inst, 4, dmmap_section, opt_inst, dmmap_package, section); - } - return inst; -} - -static int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *last_inst, *v; - char ip_name[32], ib[16]; - char *p = ip_name; - struct uci_section *dmmap_ip_interface; - - last_inst = get_last_instance_cond("dmmap_network", "network", "interface", "ip_int_instance", "type", "alias", "proto", "", "loopback"); - snprintf(ib, sizeof(ib), "%d", last_inst ? atoi(last_inst)+1 : 1); - dmstrappendstr(p, "ip_interface_"); - dmstrappendstr(p, ib); - dmstrappendend(p); - dmuci_set_value("network", ip_name, "", "interface"); - dmuci_set_value("network", ip_name, "proto", "dhcp"); - - dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ip_interface, &v); - dmuci_set_value_by_section(dmmap_ip_interface, "section_name", ip_name); - *instance = update_instance(last_inst, 4, dmmap_ip_interface, "ip_int_instance", "dmmap_network", "interface"); - return 0; -} - -static int delete_ip_intertace_instance(struct uci_section *s) -{ - // Get dmmap section related to this interface section - struct uci_section *dmmap_section = NULL; - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section); - - // Read the type option from interface section - char *type; - dmuci_get_value_by_section_string(s, "type", &type); - - // Check the type value ==> if bridge : there is a Bridging.Bridge. object mapped to this interface, remove only proto option from the section - // Check the type value ==> else : there is no Bridging.Bridge. object mapped to this interface, remove the section - if (strcmp(type, "bridge") == 0) { - /* type is bridge ==> remove only proto option from the interface section and ip instance option from dmmap section */ - dmuci_set_value_by_section(s, "proto", ""); - dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); - } else { - /* Remove the device section corresponding to this interface if exists */ - char *device = get_device( section_name(s)); - struct uci_section *ss = NULL, *stmp = NULL; - uci_foreach_option_eq_safe("network", "device", "name", device, stmp, ss) { - char *device_type; - dmuci_get_value_by_section_string(ss, "type", &device_type); - if (strcmp(device_type, "untagged") == 0) dmuci_delete_by_section(ss, NULL, NULL); - break; - } - /* type is not bridge ==> remove interface and dmmap section */ - dmuci_delete_by_section(s, NULL, NULL); - dmuci_delete_by_section(dmmap_section, NULL, NULL); - } - return 0; -} - -static int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s = NULL, *stmp = NULL; - char *proto = NULL; - - switch (del_action) { - case DEL_INST: - delete_ip_intertace_instance(((struct ip_args *)data)->ip_sec); - break; - case DEL_ALL: - uci_foreach_sections_safe("network", "interface", stmp, s) { - dmuci_get_value_by_section_string(s, "proto", &proto); - if (strcmp(section_name(s), "loopback") == 0 || *proto == '\0') - continue; - - delete_ip_intertace_instance(s); - } - break; - } - return 0; -} - -static int add_ipv4(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *instance; - struct uci_section *dmmap_section; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "ipv4_instance", &instance); - *instancepara = update_instance(instance, 4, dmmap_section, "ipv4_instance", "dmmap_network", "interface"); - if(instance[0] == '\0') { - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", *instancepara); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", "0.0.0.0"); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static"); - } - return 0; -} - -static int delete_ipv4(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *dmmap_section; - - switch (del_action) { - case DEL_INST: - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", ""); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - if(dmmap_section != NULL) - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); - break; - case DEL_ALL: - return FAULT_9005; - } - return 0; -} - -static int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - struct uci_section *s, *ss; - char *ip, *name, *inst, *curr_inst; - - uci_foreach_sections("network", "interface", s) { - if(strcmp(section_name(s), section_name(((struct ipv6_args *)data)->ip_sec)) != 0) - continue; - dmuci_get_value_by_section_string(s, "ip6addr", &ip); - break; - } - if(ip[0] == '\0') { - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name(((struct ipv6_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "ipv6_instance", &inst); - } - dmasprintf(&curr_inst, "%d", atoi(inst)+1); - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "ip6addr", "::"); - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "proto", "static"); - dmuci_add_section_bbfdm("dmmap_network", "ipv6", &ss, &name); - dmuci_set_value_by_section_bbfdm(ss, "section_name", section_name(((struct ipv6_args *)data)->ip_sec)); - dmuci_set_value_by_section_bbfdm(ss, "ipv6_instance", curr_inst); - } - return 0; -} - -static int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *dmmap_section; - - get_dmmap_section_of_config_section("dmmap_network", "ipv6", section_name(((struct ipv6_args *)data)->ip_sec), &dmmap_section); - switch (del_action) { - case DEL_INST: - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "ip6addr", ""); - dmuci_set_value_by_section(dmmap_section, "ipv6_instance", ""); - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "proto", ""); - break; - case DEL_ALL: - return FAULT_9005; - } - return 0; -} - -static int add_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - struct uci_section *s, *ss; - char *ip, *name, *inst, *curr_inst; - - uci_foreach_sections("network", "interface", s) { - if(strcmp(section_name(s), section_name(((struct ipv6prefix_args *)data)->ip_sec)) != 0) - continue; - dmuci_get_value_by_section_string(s, "ip6prefix", &ip); - break; - } - if(ip[0] == '\0') { - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name(((struct ipv6prefix_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "ipv6prefix_instance", &inst); - } - dmasprintf(&curr_inst, "%d", atoi(inst)+1); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6prefix", "::"); - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "proto", "static"); - dmuci_add_section_bbfdm("dmmap_network", "ipv6prefix", &ss, &name); - dmuci_set_value_by_section_bbfdm(ss, "section_name", section_name(((struct ipv6prefix_args *)data)->ip_sec)); - dmuci_set_value_by_section_bbfdm(ss, "ipv6prefix_instance", curr_inst); - } - return 0; -} - -static int delete_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *dmmap_section; - - get_dmmap_section_of_config_section("dmmap_network", "ipv6prefix", section_name(((struct ipv6prefix_args *)data)->ip_sec), &dmmap_section); - switch (del_action) { - case DEL_INST: - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "ip6prefix", ""); - dmuci_set_value_by_section(dmmap_section, "ipv6prefix_instance", ""); - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "proto", ""); - break; - case DEL_ALL: - return FAULT_9005; - } - return 0; -} - -/************************************************************************** -* LINKER -***************************************************************************/ -static int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct ip_args *)data)->ip_sec) { - dmasprintf(linker,"%s", section_name(((struct ip_args *)data)->ip_sec)); - return 0; - } else { - *linker = ""; - return 0; - } -} - -static int get_linker_ipv6_prefix(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (((struct ipv6prefix_args *)data)->ip_sec) { - dmasprintf(linker,"%s", get_child_prefix_linker(section_name(((struct ipv6prefix_args *)data)->ip_sec))); - return 0; - } else { - *linker = ""; - return 0; - } -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.IP.Interface.{i}.!UCI:network/interface/dmmap_network*/ -static int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *inst = NULL, *max_inst = NULL; - char *proto, *ipv4addr = ""; - struct ip_args curr_ip_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "proto", &proto); - if (strcmp(section_name(p->config_section), "loopback") == 0 || *proto == '\0') - continue; - - /* IPv4 address */ - dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); - if (ipv4addr[0] == '\0') - ipv4addr = ubus_call_get_value(section_name(p->config_section), "ipv4-address", "address"); - - init_ip_args(&curr_ip_args, p->config_section, ipv4addr); - - inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5, - p->dmmap_section, "ip_int_instance", "ip_int_alias", "dmmap_network", "interface"); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ip_args, inst) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -static int browseIfaceIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *inst = NULL, *max_inst = NULL; - struct uci_section *dmmap_section; - struct browse_args browse_args = {0}; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)prev_data)->ip_sec), &dmmap_section); - if(((struct ip_args *)prev_data)->ip_4address[0] != '\0') { - - browse_args.option = "section_name"; - browse_args.value = section_name(((struct ip_args *)prev_data)->ip_sec); - - inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, - dmmap_section, "ipv4_instance", "ipv4_alias", "dmmap_network", "interface", - check_browse_section, (void *)&browse_args); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, inst) == DM_STOP) - goto end; - } -end: - return 0; -} - -static struct uci_section *update_dmmap_network_ipv6(char *curr_inst, char *section_name) -{ - struct uci_section *s = NULL; - char *inst, *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name, s) { - dmuci_get_value_by_section_string(s, "ipv6_instance", &inst); - if(strcmp(curr_inst, inst) == 0) - return s; - } - if (!s) { - dmuci_add_section_bbfdm("dmmap_network", "ipv6", &s, &name); - dmuci_set_value_by_section_bbfdm(s, "section_name", section_name); - dmuci_set_value_by_section_bbfdm(s, "ipv6_instance", curr_inst); - } - return s; -} - -static int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s; - char *inst = NULL, *max_inst = NULL, *ipv6addr = "", *ipv6mask = "", *ipv6_preferred = "", *ipv6_valid = "", buf[16]=""; - struct ipv6_args curr_ipv6_args = {0}; - struct browse_args browse_args = {0}; - json_object *res, *jobj, *jobj1; - int entries = 0; - - if(prev_data && ((struct ip_args *)prev_data)->ip_sec) { - - browse_args.option = "section_name"; - browse_args.value = section_name(((struct ip_args *)prev_data)->ip_sec); - - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "ip6addr", &ipv6addr); - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "adv_preferred_lifetime", &ipv6_preferred); - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "adv_valid_lifetime", &ipv6_valid); - if (ipv6addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)prev_data)->ip_sec), String}}, 1, &res); - while (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix-assignment"); - if(jobj) { - jobj1 = dmjson_get_obj(jobj, 1, "local-address"); - if(jobj1) { - ipv6addr = dmjson_get_value(jobj1, 1, "address"); - ipv6mask = dmjson_get_value(jobj1, 1, "mask"); - goto browse; - } - } - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "ipv6-address"); - if(jobj) { - ipv6addr = dmjson_get_value(jobj, 1, "address"); - ipv6mask = dmjson_get_value(jobj, 1, "mask"); - if (ipv6_preferred[0] == '\0') - ipv6_preferred = dmjson_get_value(jobj, 1, "preferred"); - if (ipv6_valid[0] == '\0') - ipv6_valid = dmjson_get_value(jobj, 1, "valid"); - entries++; - snprintf(buf, sizeof(buf), "%d", entries); - s = update_dmmap_network_ipv6(buf, section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6_args(&curr_ipv6_args, ((struct ip_args *)prev_data)->ip_sec, ipv6addr, ipv6mask, ipv6_preferred, ipv6_valid); - - inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, - s, "ipv6_instance", "ipv6_alias", "dmmap_network", "ipv6", - check_browse_section, (void *)&browse_args); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6_args, inst) == DM_STOP) - goto end; - } else - goto end; - } - } -browse: - s = update_dmmap_network_ipv6("1", section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6_args(&curr_ipv6_args, ((struct ip_args *)prev_data)->ip_sec, ipv6addr, ipv6mask, ipv6_preferred, ipv6_valid); - - inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, - s, "ipv6_instance", "ipv6_alias", "dmmap_network", "ipv6", - check_browse_section, (void *)&browse_args); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6_args, inst) == DM_STOP) - goto end; - } -end: - return 0; -} - - -static struct uci_section *update_dmmap_network_ipv6prefix(char *curr_inst, char *section_name) -{ - struct uci_section *s = NULL; - char *inst, *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name, s) { - dmuci_get_value_by_section_string(s, "ipv6prefix_instance", &inst); - if(strcmp(curr_inst, inst) == 0) - return s; - } - if (!s) { - dmuci_add_section_bbfdm("dmmap_network", "ipv6prefix", &s, &name); - dmuci_set_value_by_section_bbfdm(s, "section_name", section_name); - dmuci_set_value_by_section_bbfdm(s, "ipv6prefix_instance", curr_inst); - } - return s; -} - -static int browseIfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s; - char *inst = NULL, *max_inst = NULL, *ipv6prefixaddr = "", *ipv6prefixmask = "", *ipv6prefix_preferred = "", *ipv6prefix_valid = "", buf[16] = ""; - struct ipv6prefix_args curr_ipv6prefix_args = {0}; - struct browse_args browse_args = {0}; - json_object *res, *jobj; - int entries = 0; - - if(prev_data && ((struct ip_args *)prev_data)->ip_sec) { - - browse_args.option = "section_name"; - browse_args.value = section_name(((struct ip_args *)prev_data)->ip_sec); - - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "ip6prefix", &ipv6prefixaddr); - if (ipv6prefixaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)prev_data)->ip_sec), String}}, 1, &res); - while (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix-assignment"); - if(jobj) { - ipv6prefixaddr = dmjson_get_value(jobj, 1, "address"); - ipv6prefixmask = dmjson_get_value(jobj, 1, "mask"); - ipv6prefix_preferred = dmjson_get_value(jobj, 1, "preferred"); - ipv6prefix_valid = dmjson_get_value(jobj, 1, "valid"); - goto browse; - } - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "ipv6-prefix"); - if(jobj) { - ipv6prefixaddr = dmjson_get_value(jobj, 1, "address"); - ipv6prefixmask = dmjson_get_value(jobj, 1, "mask"); - ipv6prefix_preferred = dmjson_get_value(jobj, 1, "preferred"); - ipv6prefix_valid = dmjson_get_value(jobj, 1, "valid"); - entries++; - snprintf(buf, sizeof(buf), "%d", entries); - s = update_dmmap_network_ipv6prefix(buf, section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6prefix_args(&curr_ipv6prefix_args, ((struct ip_args *)prev_data)->ip_sec, ipv6prefixaddr, ipv6prefixmask, ipv6prefix_preferred, ipv6prefix_valid); - - inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, - s, "ipv6prefix_instance", "ipv6prefix_alias", "dmmap_network", "ipv6prefix", - check_browse_section, (void *)&browse_args); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6prefix_args, inst) == DM_STOP) - goto end; - } else - goto end; - } - } -browse: - s = update_dmmap_network_ipv6prefix("1", section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6prefix_args(&curr_ipv6prefix_args, ((struct ip_args *)prev_data)->ip_sec, ipv6prefixaddr, ipv6prefixmask, ipv6prefix_preferred, ipv6prefix_valid); - - inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 7, - s, "ipv6prefix_instance", "ipv6prefix_alias", "dmmap_network", "ipv6prefix", - check_browse_section, (void *)&browse_args); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6prefix_args, inst) == DM_STOP) - goto end; - } -end: - return 0; -} - -static struct dm_forced_inform_s IPv4INFRM = {0, get_ipv4_finform}; -static struct dm_forced_inform_s IPv6INFRM = {0, get_ipv6_finform}; - +/********************************************************************************************************************************** +* OBJ & PARAM DEFINITION +***********************************************************************************************************************************/ /* *** Device.IP. *** */ DMOBJ tIPObj[] = { /* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/ -{"Interface", &DMWRITE, add_ip_interface, delete_ip_interface, NULL, browseIPIfaceInst, NULL, NULL, NULL, tIPInterfaceObj, tIPInterfaceParams, get_linker_ip_interface, BBFDM_BOTH, LIST_KEY{"Name", "Alias", NULL}}, +{"Interface", &DMWRITE, addObjIPInterface, delObjIPInterface, NULL, browseIPInterfaceInst, NULL, NULL, NULL, tIPInterfaceObj, tIPInterfaceParams, get_linker_ip_interface, BBFDM_BOTH, LIST_KEY{"Alias", "Name", NULL}}, #ifdef BBF_TR143 {"Diagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsObj, tIPDiagnosticsParams, NULL, BBFDM_BOTH}, #endif @@ -1883,12 +2079,12 @@ DMLEAF tIPParams[] = { {0} }; -/* *** Device.IP.Interface. *** */ +/* *** Device.IP.Interface.{i}. *** */ DMOBJ tIPInterfaceObj[] = { /* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/ -{"IPv4Address", &DMWRITE, add_ipv4, delete_ipv4, NULL, browseIfaceIPv4Inst, NULL, NULL, NULL, NULL, tIPInterfaceIPv4AddressParams, NULL, BBFDM_BOTH, LIST_KEY{"IPAddress", "SubnetMast", "Alias", NULL}}, -{"IPv6Address", &DMWRITE, add_ipv6, delete_ipv6, NULL, browseIfaceIPv6Inst, NULL, NULL, NULL, NULL, tIPInterfaceIPv6AddressParams, NULL, BBFDM_BOTH, LIST_KEY{"IPAddress", "Alias", NULL}}, -{"IPv6Prefix", &DMWRITE, add_ipv6_prefix, delete_ipv6_prefix, NULL, browseIfaceIPv6PrefixInst, NULL, NULL, NULL, NULL, tIPInterfaceIPv6PrefixParams, get_linker_ipv6_prefix, BBFDM_BOTH, LIST_KEY{"Prefix", "Alias", NULL}}, +{"IPv4Address", &DMWRITE, addObjIPInterfaceIPv4Address, delObjIPInterfaceIPv4Address, NULL, browseIPInterfaceIPv4AddressInst, NULL, NULL, NULL, NULL, tIPInterfaceIPv4AddressParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", "IPAddress", "SubnetMask", NULL}}, +{"IPv6Address", &DMWRITE, addObjIPInterfaceIPv6Address, delObjIPInterfaceIPv6Address, NULL, browseIPInterfaceIPv6AddressInst, NULL, NULL, NULL, NULL, tIPInterfaceIPv6AddressParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", "IPAddress", NULL}}, +{"IPv6Prefix", &DMWRITE, addObjIPInterfaceIPv6Prefix, delObjIPInterfaceIPv6Prefix, NULL, browseIPInterfaceIPv6PrefixInst, NULL, NULL, NULL, NULL, tIPInterfaceIPv6PrefixParams, get_linker_ipv6_prefix, BBFDM_BOTH, LIST_KEY{"Alias", "Prefix", NULL}}, {"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIPInterfaceStatsParams, NULL, BBFDM_BOTH}, {0} }; @@ -1898,19 +2094,21 @@ DMLEAF tIPInterfaceParams[] = { {"Enable", &DMWRITE, DMT_BOOL, get_IPInterface_Enable, set_IPInterface_Enable, NULL, NULL, BBFDM_BOTH}, {"IPv4Enable", &DMWRITE, DMT_BOOL, get_IPInterface_IPv4Enable, set_IPInterface_IPv4Enable, NULL, NULL, BBFDM_BOTH}, {"IPv6Enable", &DMWRITE, DMT_BOOL, get_IPInterface_IPv6Enable, set_IPInterface_IPv6Enable, NULL, NULL, BBFDM_BOTH}, +//{"ULAEnable", &DMWRITE, DMT_BOOL, get_IPInterface_ULAEnable, set_IPInterface_ULAEnable, NULL, NULL, BBFDM_BOTH}, {"Status", &DMREAD, DMT_STRING, get_IPInterface_Status, NULL, NULL, NULL, BBFDM_BOTH}, {"Alias", &DMWRITE, DMT_STRING, get_IPInterface_Alias, set_IPInterface_Alias, NULL, NULL, BBFDM_BOTH}, {"Name", &DMREAD, DMT_STRING, get_IPInterface_Name, NULL, NULL, NULL, BBFDM_BOTH}, {"LastChange", &DMREAD, DMT_UNINT, get_IPInterface_LastChange, NULL, NULL, NULL, BBFDM_BOTH}, {"LowerLayers", &DMWRITE, DMT_STRING, get_IPInterface_LowerLayers, set_IPInterface_LowerLayers, NULL, NULL, BBFDM_BOTH}, {"Router", &DMWRITE, DMT_STRING, get_IPInterface_Router, set_IPInterface_Router, NULL, NULL, BBFDM_BOTH}, -{"Reset", &DMWRITE, DMT_BOOL, get_IPInterface_Reset, set_IPInterface_Reset, NULL, NULL, BBFDM_BOTH}, +{"Reset", &DMWRITE, DMT_BOOL, get_IPInterface_Reset, set_IPInterface_Reset, NULL, NULL, BBFDM_CWMP}, {"MaxMTUSize", &DMWRITE, DMT_UNINT, get_IPInterface_MaxMTUSize, set_IPInterface_MaxMTUSize, NULL, NULL, BBFDM_BOTH}, {"Type", &DMREAD, DMT_STRING, get_IPInterface_Type, NULL, NULL, NULL, BBFDM_BOTH}, {"Loopback", &DMWRITE, DMT_BOOL, get_IPInterface_Loopback, set_IPInterface_Loopback, NULL, NULL, BBFDM_BOTH}, {"IPv4AddressNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv4AddressNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, {"IPv6AddressNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv6AddressNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, {"IPv6PrefixNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv6PrefixNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +//{"AutoIPEnable", &DMWRITE, DMT_BOOL, get_IPInterface_AutoIPEnable, set_IPInterface_AutoIPEnable, NULL, NULL, BBFDM_BOTH}, {"TWAMPReflectorNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_TWAMPReflectorNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; @@ -1918,28 +2116,29 @@ DMLEAF tIPInterfaceParams[] = { /* *** Device.IP.Interface.{i}.IPv4Address.{i}. *** */ DMLEAF tIPInterfaceIPv4AddressParams[] = { /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_IPInterface_Enable, set_IPInterface_Enable, &IPv4INFRM, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_IPInterfaceIPv4Address_Status, NULL, &IPv4INFRM, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_ipv4_alias, set_ipv4_alias, &IPv4INFRM, NULL, BBFDM_BOTH}, -{CUSTOM_PREFIX"FirewallEnabled", &DMWRITE, DMT_BOOL, get_firewall_enabled, set_firewall_enabled, &IPv4INFRM, NULL, BBFDM_BOTH}, -{"IPAddress", &DMWRITE, DMT_STRING, get_ipv4_address, set_ipv4_address, &IPv4INFRM, NULL, BBFDM_BOTH}, -{"SubnetMask", &DMWRITE, DMT_STRING, get_ipv4_netmask, set_ipv4_netmask, &IPv4INFRM, NULL, BBFDM_BOTH}, -{"AddressingType", &DMREAD, DMT_STRING, get_ipv4_addressing_type, NULL, &IPv4INFRM, NULL, BBFDM_BOTH}, +{"Enable", &DMWRITE, DMT_BOOL, get_IPInterfaceIPv4Address_Enable, set_IPInterfaceIPv4Address_Enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_IPInterfaceIPv4Address_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_IPInterfaceIPv4Address_Alias, set_IPInterfaceIPv4Address_Alias, NULL, NULL, BBFDM_BOTH}, +{"IPAddress", &DMWRITE, DMT_STRING, get_IPInterfaceIPv4Address_IPAddress, set_IPInterfaceIPv4Address_IPAddress, NULL, NULL, BBFDM_BOTH}, +{"SubnetMask", &DMWRITE, DMT_STRING, get_IPInterfaceIPv4Address_SubnetMask, set_IPInterfaceIPv4Address_SubnetMask, NULL, NULL, BBFDM_BOTH}, +{"AddressingType", &DMREAD, DMT_STRING, get_IPInterfaceIPv4Address_AddressingType, NULL, NULL, NULL, BBFDM_BOTH}, +{CUSTOM_PREFIX"FirewallEnabled", &DMWRITE, DMT_BOOL, get_IPInterfaceIPv4Address_X_IOPSYS_EU_FirewallEnabled, set_IPInterfaceIPv4Address_X_IOPSYS_EU_FirewallEnabled, NULL, NULL, BBFDM_BOTH}, {0} }; /* *** Device.IP.Interface.{i}.IPv6Address.{i}. *** */ DMLEAF tIPInterfaceIPv6AddressParams[] = { /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_IPInterfaceIPv6Address_Enable, set_IPInterfaceIPv6Address_Enable, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_IPInterfaceIPv6Address_Status, NULL, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"IPAddressStatus", &DMREAD, DMT_STRING, get_IPInterfaceIPv6Address_IPAddressStatus, NULL, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Address_Alias, set_IPInterfaceIPv6Address_Alias, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"IPAddress", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Address_IPAddress, set_IPInterfaceIPv6Address_IPAddress, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"Origin", &DMREAD, DMT_STRING, get_IPInterfaceIPv6Address_Origin, NULL, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"Prefix", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Address_Prefix, set_IPInterfaceIPv6Address_Prefix, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"PreferredLifetime", &DMWRITE, DMT_TIME, get_IPInterfaceIPv6Address_PreferredLifetime, set_IPInterfaceIPv6Address_PreferredLifetime, &IPv6INFRM, NULL, BBFDM_BOTH}, -{"ValidLifetime", &DMWRITE, DMT_TIME, get_IPInterfaceIPv6Address_ValidLifetime, set_IPInterfaceIPv6Address_ValidLifetime, &IPv6INFRM, NULL, BBFDM_BOTH}, +{"Enable", &DMWRITE, DMT_BOOL, get_IPInterfaceIPv6Address_Enable, set_IPInterfaceIPv6Address_Enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_IPInterfaceIPv6Address_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"IPAddressStatus", &DMREAD, DMT_STRING, get_IPInterfaceIPv6Address_IPAddressStatus, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Address_Alias, set_IPInterfaceIPv6Address_Alias, NULL, NULL, BBFDM_BOTH}, +{"IPAddress", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Address_IPAddress, set_IPInterfaceIPv6Address_IPAddress, NULL, NULL, BBFDM_BOTH}, +{"Origin", &DMREAD, DMT_STRING, get_IPInterfaceIPv6Address_Origin, NULL, NULL, NULL, BBFDM_BOTH}, +{"Prefix", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Address_Prefix, set_IPInterfaceIPv6Address_Prefix, NULL, NULL, BBFDM_BOTH}, +{"PreferredLifetime", &DMWRITE, DMT_TIME, get_IPInterfaceIPv6Address_PreferredLifetime, set_IPInterfaceIPv6Address_PreferredLifetime, NULL, NULL, BBFDM_BOTH}, +{"ValidLifetime", &DMWRITE, DMT_TIME, get_IPInterfaceIPv6Address_ValidLifetime, set_IPInterfaceIPv6Address_ValidLifetime, NULL, NULL, BBFDM_BOTH}, +//{"Anycast", &DMWRITE, DMT_BOOL, get_IPInterfaceIPv6Address_Anycast, set_IPInterfaceIPv6Address_Anycast, NULL, NULL, BBFDM_BOTH}, {0} }; @@ -1952,9 +2151,11 @@ DMLEAF tIPInterfaceIPv6PrefixParams[] = { {"Alias", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Prefix_Alias, set_IPInterfaceIPv6Prefix_Alias, NULL, NULL, BBFDM_BOTH}, {"Prefix", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Prefix_Prefix, set_IPInterfaceIPv6Prefix_Prefix, NULL, NULL, BBFDM_BOTH}, {"Origin", &DMREAD, DMT_STRING, get_IPInterfaceIPv6Prefix_Origin, NULL, NULL, NULL, BBFDM_BOTH}, -{"StaticType", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Prefix_StaticType, set_IPInterfaceIPv6Prefix_StaticType, NULL, NULL, BBFDM_BOTH}, +//{"StaticType", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Prefix_StaticType, set_IPInterfaceIPv6Prefix_StaticType, NULL, NULL, BBFDM_BOTH}, {"ParentPrefix", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Prefix_ParentPrefix, set_IPInterfaceIPv6Prefix_ParentPrefix, NULL, NULL, BBFDM_BOTH}, {"ChildPrefixBits", &DMWRITE, DMT_STRING, get_IPInterfaceIPv6Prefix_ChildPrefixBits, set_IPInterfaceIPv6Prefix_ChildPrefixBits, NULL, NULL, BBFDM_BOTH}, +//{"OnLink", &DMWRITE, DMT_BOOL, get_IPInterfaceIPv6Prefix_OnLink, set_IPInterfaceIPv6Prefix_OnLink, NULL, NULL, BBFDM_BOTH}, +//{"Autonomous", &DMWRITE, DMT_BOOL, get_IPInterfaceIPv6Prefix_Autonomous, set_IPInterfaceIPv6Prefix_Autonomous, NULL, NULL, BBFDM_BOTH}, {"PreferredLifetime", &DMWRITE, DMT_TIME, get_IPInterfaceIPv6Prefix_PreferredLifetime, set_IPInterfaceIPv6Prefix_PreferredLifetime, NULL, NULL, BBFDM_BOTH}, {"ValidLifetime", &DMWRITE, DMT_TIME, get_IPInterfaceIPv6Prefix_ValidLifetime, set_IPInterfaceIPv6Prefix_ValidLifetime, NULL, NULL, BBFDM_BOTH}, {0} @@ -1963,20 +2164,20 @@ DMLEAF tIPInterfaceIPv6PrefixParams[] = { /* *** Device.IP.Interface.{i}.Stats. *** */ DMLEAF tIPInterfaceStatsParams[] = { /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"BytesSent", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_tx_bytes, NULL, NULL, NULL, BBFDM_BOTH}, -{"BytesReceived", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_rx_bytes, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsSent", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_tx_packets, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsReceived", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_rx_packets, NULL, NULL, NULL, BBFDM_BOTH}, -{"ErrorsSent", &DMREAD, DMT_UNINT, get_ip_interface_statistics_tx_errors, NULL, NULL, NULL, BBFDM_BOTH}, -{"ErrorsReceived", &DMREAD, DMT_UNINT, get_ip_interface_statistics_rx_errors, NULL, NULL, NULL, BBFDM_BOTH}, -{"DiscardPacketsSent", &DMREAD, DMT_UNINT, get_ip_interface_statistics_tx_discardpackets, NULL, NULL, NULL, BBFDM_BOTH}, -{"DiscardPacketsReceived", &DMREAD, DMT_UNINT, get_ip_interface_statistics_rx_discardpackets, NULL, NULL, NULL, BBFDM_BOTH}, -//{"UnicastPacketsSent", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_tx_unicastpackets, NULL, NULL, NULL, BBFDM_BOTH}, -//{"UnicastPacketsReceived", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_rx_unicastpackets, NULL, NULL, NULL, BBFDM_BOTH}, -//{"MulticastPacketsSent", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_tx_multicastpackets, NULL, NULL, NULL, BBFDM_BOTH}, -{"MulticastPacketsReceived", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_rx_multicastpackets, NULL, NULL, NULL, BBFDM_BOTH}, -//{"BroadcastPacketsSent", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_tx_broadcastpackets, NULL, NULL, NULL, BBFDM_BOTH}, -//{"BroadcastPacketsReceived", &DMREAD, DMT_UNLONG, get_ip_interface_statistics_rx_broadcastpackets, NULL, NULL, NULL, BBFDM_BOTH}, -//{"UnknownProtoPacketsReceived", &DMREAD, DMT_UNINT, get_ip_interface_statistics_rx_unknownprotopackets, NULL, NULL, NULL, BBFDM_BOTH}, +{"BytesSent", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_BytesSent, NULL, NULL, NULL, BBFDM_BOTH}, +{"BytesReceived", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_BytesReceived, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsSent", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_PacketsSent, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsReceived", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_PacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, +{"ErrorsSent", &DMREAD, DMT_UNINT, get_IPInterfaceStats_ErrorsSent, NULL, NULL, NULL, BBFDM_BOTH}, +{"ErrorsReceived", &DMREAD, DMT_UNINT, get_IPInterfaceStats_ErrorsReceived, NULL, NULL, NULL, BBFDM_BOTH}, +//{"UnicastPacketsSent", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_UnicastPacketsSent, NULL, NULL, NULL, BBFDM_BOTH}, +//{"UnicastPacketsReceived", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_UnicastPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, +{"DiscardPacketsSent", &DMREAD, DMT_UNINT, get_IPInterfaceStats_DiscardPacketsSent, NULL, NULL, NULL, BBFDM_BOTH}, +{"DiscardPacketsReceived", &DMREAD, DMT_UNINT, get_IPInterfaceStats_DiscardPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, +//{"MulticastPacketsSent", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_MulticastPacketsSent, NULL, NULL, NULL, BBFDM_BOTH}, +{"MulticastPacketsReceived", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_MulticastPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, +//{"BroadcastPacketsSent", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_BroadcastPacketsSent, NULL, NULL, NULL, BBFDM_BOTH}, +//{"BroadcastPacketsReceived", &DMREAD, DMT_UNLONG, get_IPInterfaceStats_BroadcastPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, +//{"UnknownProtoPacketsReceived", &DMREAD, DMT_UNINT, get_IPInterfaceStats_UnknownProtoPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; diff --git a/dmtree/tr181/ip.h b/dmtree/tr181/ip.h index 50837393..66b29a87 100644 --- a/dmtree/tr181/ip.h +++ b/dmtree/tr181/ip.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 iopsys Software Solutions AB + * Copyright (C) 2020 iopsys Software Solutions AB * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 2.1 @@ -23,6 +23,6 @@ extern DMLEAF tIPInterfaceIPv4AddressParams[]; extern DMLEAF tIPInterfaceIPv6AddressParams[]; extern DMLEAF tIPInterfaceIPv6PrefixParams[]; extern DMLEAF tIPInterfaceStatsParams[]; -extern DMLEAF tIPInterfaceTWAMPReflectorParams[]; -#endif +#endif //__IP_H + diff --git a/json/tr181.json b/json/tr181.json index 350ecb7e..314fedeb 100644 --- a/json/tr181.json +++ b/json/tr181.json @@ -39835,6 +39835,21 @@ { "max": 49 } + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "globals", + "name": "globals" + }, + "option": { + "name": "ula_prefix" + } + } + } ] }, "InterfaceNumberOfEntries": { @@ -39912,7 +39927,22 @@ "cwmp", "usp" ], - "datatype": "boolean" + "datatype": "boolean", + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "interface", + "index": "@i-1" + }, + "option": { + "name": "disabled" + } + } + } + ] }, "IPv6Enable": { "type": "boolean", @@ -40103,6 +40133,12 @@ "min": 64, "max": 65535 } + ], + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/mtu" + } ] }, "Type": { @@ -40208,7 +40244,22 @@ "cwmp", "usp" ], - "datatype": "boolean" + "datatype": "boolean", + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "interface", + "index": "@i-1" + }, + "option": { + "name": "disabled" + } + } + } + ] }, "Status": { "type": "string", @@ -40259,9 +40310,9 @@ { "type": "uci", "uci": { - "file": "dmmap_network", + "file": "dmmap_network_ipv4", "section": { - "type": "interface", + "type": "intf_ipv4", "index": "@i-1" }, "option": { @@ -40396,7 +40447,13 @@ "cwmp", "usp" ], - "datatype": "unsignedLong" + "datatype": "unsignedLong", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/tx_bytes" + } + ] }, "BytesReceived": { "type": "unsignedLong", @@ -40406,7 +40463,13 @@ "cwmp", "usp" ], - "datatype": "unsignedLong" + "datatype": "unsignedLong", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/rx_bytes" + } + ] }, "PacketsSent": { "type": "unsignedLong", @@ -40416,7 +40479,13 @@ "cwmp", "usp" ], - "datatype": "unsignedLong" + "datatype": "unsignedLong", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/tx_packets" + } + ] }, "PacketsReceived": { "type": "unsignedLong", @@ -40426,7 +40495,13 @@ "cwmp", "usp" ], - "datatype": "unsignedLong" + "datatype": "unsignedLong", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/rx_packets" + } + ] }, "ErrorsSent": { "type": "unsignedInt", @@ -40436,7 +40511,13 @@ "cwmp", "usp" ], - "datatype": "unsignedInt" + "datatype": "unsignedInt", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/tx_errors" + } + ] }, "ErrorsReceived": { "type": "unsignedInt", @@ -40446,7 +40527,13 @@ "cwmp", "usp" ], - "datatype": "unsignedInt" + "datatype": "unsignedInt", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/rx_errors" + } + ] }, "UnicastPacketsSent": { "type": "unsignedLong", @@ -40476,7 +40563,13 @@ "cwmp", "usp" ], - "datatype": "unsignedInt" + "datatype": "unsignedInt", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/tx_dropped" + } + ] }, "DiscardPacketsReceived": { "type": "unsignedInt", @@ -40486,7 +40579,13 @@ "cwmp", "usp" ], - "datatype": "unsignedInt" + "datatype": "unsignedInt", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/rx_dropped" + } + ] }, "MulticastPacketsSent": { "type": "unsignedLong", @@ -40506,7 +40605,13 @@ "cwmp", "usp" ], - "datatype": "unsignedLong" + "datatype": "unsignedLong", + "mapping": [ + { + "type": "sysfs", + "file": "/sys/class/net/@Name/statistics/multicast" + } + ] }, "BroadcastPacketsSent": { "type": "unsignedLong", @@ -40669,7 +40774,22 @@ "cwmp", "usp" ], - "datatype": "boolean" + "datatype": "boolean", + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "interface", + "index": "@i-1" + }, + "option": { + "name": "ipv6" + } + } + } + ] }, "Status": { "type": "string", @@ -40685,6 +40805,21 @@ "Enabled", "Error_Misconfigured", "Error" + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "interface", + "index": "@i-1" + }, + "option": { + "name": "ipv6" + } + } + } ] }, "IPAddressStatus": { @@ -40720,6 +40855,21 @@ { "max": 64 } + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "dmmap_network_ipv6", + "section": { + "type": "intf_ipv6", + "index": "@i-1" + }, + "option": { + "name": "ipv6_alias" + } + } + } ] }, "IPAddress": { @@ -40788,22 +40938,7 @@ "cwmp", "usp" ], - "datatype": "dateTime", - "mapping": [ - { - "type": "uci", - "uci": { - "file": "network", - "section": { - "type": "interface", - "index": "@i-1" - }, - "option": { - "name": "adv_preferred_lifetime" - } - } - } - ] + "datatype": "dateTime" }, "ValidLifetime": { "type": "dateTime", @@ -40813,22 +40948,7 @@ "cwmp", "usp" ], - "datatype": "dateTime", - "mapping": [ - { - "type": "uci", - "uci": { - "file": "network", - "section": { - "type": "interface", - "index": "@i-1" - }, - "option": { - "name": "adv_valid_lifetime" - } - } - } - ] + "datatype": "dateTime" }, "Anycast": { "type": "boolean", @@ -40861,7 +40981,22 @@ "cwmp", "usp" ], - "datatype": "boolean" + "datatype": "boolean", + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "interface", + "index": "@i-1" + }, + "option": { + "name": "ipv6" + } + } + } + ] }, "Status": { "type": "string", @@ -40876,6 +41011,21 @@ "Disabled", "Enabled", "Error" + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "interface", + "index": "@i-1" + }, + "option": { + "name": "ipv6" + } + } + } ] }, "PrefixStatus": { @@ -40908,6 +41058,21 @@ { "max": 64 } + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "dmmap_network_ipv6_prefix", + "section": { + "type": "intf_ipv6_prefix", + "index": "@i-1" + }, + "option": { + "name": "ipv6_prefix_alias" + } + } + } ] }, "Prefix": { diff --git a/libbbf_api/dmbbf.c b/libbbf_api/dmbbf.c index a4b4ada3..13ce0d5a 100644 --- a/libbbf_api/dmbbf.c +++ b/libbbf_api/dmbbf.c @@ -589,7 +589,7 @@ static int rootcmp(char *inparam, char *rootobj) char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_inst, char * (*up_instance)(int action, char **last_inst, char **max_inst, void *argv[]), int argc, ...) { va_list arg; - char *instance, *last_inst = NULL;; + char *instance, *last_inst = NULL; int i = 0; unsigned int action, pos = instance_ranck - 1; void *argv[argc+1]; @@ -620,10 +620,9 @@ char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_i char *update_instance(char *max_inst, int argc, ...) { va_list arg; - char *instance; + char *instance, *last_inst = NULL; int i = 0; void *argv[argc+1]; - char *last_inst; va_start(arg, argc); for (i = 0; i < argc; i++) { diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index a74f072c..e99f1077 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -811,7 +811,7 @@ int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_packag void get_dmmap_section_of_config_section(char* dmmap_package, char* section_type, char *section_name, struct uci_section **dmmap_section) { - struct uci_section* s; + struct uci_section *s; uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, "section_name", section_name, s) { *dmmap_section = s; @@ -822,7 +822,7 @@ void get_dmmap_section_of_config_section(char* dmmap_package, char* section_type void get_dmmap_section_of_config_section_eq(char* dmmap_package, char* section_type, char *opt, char* value, struct uci_section **dmmap_section) { - struct uci_section* s; + struct uci_section *s; uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, opt, value, s) { *dmmap_section = s; @@ -833,7 +833,7 @@ void get_dmmap_section_of_config_section_eq(char* dmmap_package, char* section_t void get_dmmap_section_of_config_section_cont(char* dmmap_package, char* section_type, char *opt, char* value, struct uci_section **dmmap_section) { - struct uci_section* s; + struct uci_section *s; uci_path_foreach_option_cont(bbfdm, dmmap_package, section_type, opt, value, s) { *dmmap_section = s; @@ -844,7 +844,7 @@ void get_dmmap_section_of_config_section_cont(char* dmmap_package, char* section void get_config_section_of_dmmap_section(char* package, char* section_type, char *section_name, struct uci_section **config_section) { - struct uci_section* s; + struct uci_section *s; uci_foreach_sections(package, section_type, s) { if (strcmp(section_name(s), section_name) == 0) { @@ -1235,16 +1235,6 @@ int get_shift_time_time(int shift_time, char *local_time, int size) return 0; } -int get_shift_time_shift(char *local_time, char *shift) -{ - struct tm tm = {0}; - - strptime(local_time,"%Y-%m-%dT%H:%M:%SZ", &tm); - sprintf(shift, "%u", (unsigned int)(mktime(&tm) - time(NULL))); - - return 0; -} - int command_exec_output_to_array(char *cmd, char **output, int *length) { FILE *fp; diff --git a/libbbf_api/dmcommon.h b/libbbf_api/dmcommon.h index d136076b..d16abe86 100644 --- a/libbbf_api/dmcommon.h +++ b/libbbf_api/dmcommon.h @@ -234,13 +234,6 @@ struct dmmap_sect { char *instance; }; -struct dm_args -{ - struct uci_section *section; - struct uci_section *dmmap_section; - char *name; -}; - struct sysfs_dmsection { struct list_head list; char *sysfs_folder_path; @@ -306,7 +299,6 @@ struct uci_section *get_dup_section_in_dmmap_opt(char *dmmap_package, char *sect struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* section_type, char*sect_name, char *opt_name, char* opt_value); bool elt_exists_in_array(char **str_array, char *str, int length); int get_shift_time_time(int shift_time, char *local_time, int size); -int get_shift_time_shift(char *local_time, char *shift); int command_exec_output_to_array(char *cmd, char **output, int *length); int bbf_api_copy_temporary_file_to_original_file(char *f1, char *f2); struct uci_section *is_dmmap_section_exist(char* package, char* section);