diff --git a/dmtree/tr181/dhcpv4.c b/dmtree/tr181/dhcpv4.c index ab25da2b..6f2acfba 100644 --- a/dmtree/tr181/dhcpv4.c +++ b/dmtree/tr181/dhcpv4.c @@ -173,37 +173,64 @@ int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, return 0; } -int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *s_data, char *dmmap_name, char *proto, int action) +int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *config_s, struct uci_section *dmmap_s, char *dmmap_name, char *proto, int action) { - struct uci_section *s = NULL; - char *linker = NULL, *v; + char *linker = NULL, *added_by_controller = NULL, *curr_proto = NULL; + struct uci_section *interface_s = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0)) return FAULT_9007; + if (value == NULL || *value == '\0') + break; + + if (strncmp(value, "Device.IP.Interface.", 20) != 0) + return FAULT_9007; + adm_entry_get_linker_value(ctx, value, &linker); if (linker == NULL || linker[0] == '\0') return FAULT_9007; - uci_path_foreach_sections(bbfdm, dmmap_name, "interface", s) { - dmuci_get_value_by_section_string(s, "section_name", &v); - if(strcmp(v, linker) == 0) - return FAULT_9007; - } - - uci_foreach_sections("network", "interface", s) { - if(strcmp(section_name(s), linker) == 0){ - dmuci_get_value_by_section_string(s, "proto", &v); - if(strcmp(v, proto) != 0) - return FAULT_9007; - } - } break; case VALUESET: + // Return if the value is empty + if (value == NULL || *value == '\0') + break; + + // Get linker adm_entry_get_linker_value(ctx, value, &linker); - dmuci_set_value_by_section_bbfdm(s_data, "section_name", linker); + + // Get the corresponding network config + get_config_section_of_dmmap_section("network", "interface", linker, &interface_s); + + // break if interface section is not found + if (interface_s == NULL) + break; + + // Get the current proto value + dmuci_get_value_by_section_string(interface_s, "proto", &curr_proto); + if (curr_proto && strcmp(curr_proto, proto) == 0) + break; + + // Update proto option of config section + dmuci_set_value_by_section(interface_s, "proto", proto); + + // Update dmmap section + dmuci_set_value_by_section_bbfdm(dmmap_s, "section_name", linker); + + dmuci_get_value_by_section_string(dmmap_s, "added_by_controller", &added_by_controller); + if (added_by_controller && strcmp(added_by_controller, "1") == 0) { + // Remove added_by_controller option from dmmap section + dmuci_set_value_by_section_bbfdm(dmmap_s, "added_by_controller", ""); + + // Remove the current section + dmuci_delete_by_section(config_s, NULL, NULL); + } else { + dmuci_set_value_by_section(config_s, "proto", "none"); + } + break; } return 0; @@ -571,94 +598,53 @@ static int delObjDHCPv4ServerPoolStaticAddress(char *refparam, struct dmctx *ctx static int addObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char **instance) { struct uci_section *s = NULL, *dmmap_sect = NULL; - char *wan_eth, wanname[16]; + char dhcpv4_s[32]; - char *inst_para = get_last_instance_bbfdm("dmmap_dhcp_client", "interface", "bbf_dhcpv4client_instance"); - dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_eth); - snprintf(wanname, sizeof(wanname), "%s.1", wan_eth); + char *last_inst = get_last_instance_bbfdm("dmmap_dhcp_client", "interface", "bbf_dhcpv4client_instance"); + snprintf(dhcpv4_s, sizeof(dhcpv4_s), "dhcpv4_intf_%d", last_inst ? atoi(last_inst) + 1 : 1); dmuci_add_section("network", "interface", &s); + dmuci_rename_section_by_section(s, dhcpv4_s); dmuci_set_value_by_section(s, "proto", "dhcp"); - dmuci_set_value_by_section(s, "ifname", wanname); - dmuci_set_value_by_section(s, "type", "anywan"); + dmuci_set_value_by_section(s, "disabled", "1"); dmuci_add_section_bbfdm("dmmap_dhcp_client", "interface", &dmmap_sect); - dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); - *instance = update_instance(inst_para, 2, dmmap_sect, "bbf_dhcpv4client_instance"); + dmuci_set_value_by_section(dmmap_sect, "section_name", dhcpv4_s); + dmuci_set_value_by_section(dmmap_sect, "added_by_controller", "1"); + *instance = update_instance(last_inst, 2, dmmap_sect, "bbf_dhcpv4client_instance"); return 0; } static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data; - struct uci_section *s = NULL, *dmmap_section = NULL, *stmp = NULL; - json_object *res, *jobj; - - char *v; - char *type, *ipv4addr = "", *ipv6addr = "", *proto, *mask4; + struct uci_section *s = NULL, *s_tmp = NULL; + char *added_by_controller = NULL; switch (del_action) { case DEL_INST: - if (dhcp_client_args->dhcp_client_conf != NULL) { - dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "proto", "static"); - if (strlen(dhcp_client_args->ip) == 0) { - dmasprintf(&ipv4addr, "%s.%s.%s.%s", instance, instance, instance, instance); - dmasprintf(&mask4, "%s", "255.255.255.0"); - } else { - dmasprintf(&ipv4addr, "%s", dhcp_client_args->ip); - dmasprintf(&mask4, "%s", dhcp_client_args->mask); - } - dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "ipaddr", ipv4addr); - dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "netmask", mask4); + dmuci_get_value_by_section_string(((struct dhcp_client_args*)data)->dhcp_client_dm, "added_by_controller", &added_by_controller); + if (added_by_controller && strcmp(added_by_controller, "1") == 0) { + dmuci_delete_by_section(((struct dhcp_client_args*)data)->dhcp_client_conf, NULL, NULL); + } else { + dmuci_set_value_by_section(((struct dhcp_client_args*)data)->dhcp_client_conf, "proto", "none"); } - dmuci_delete_by_section_unnamed_bbfdm(dhcp_client_args->dhcp_client_dm, NULL, NULL); + + dmuci_delete_by_section(((struct dhcp_client_args*)data)->dhcp_client_dm, NULL, NULL); break; case DEL_ALL: - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "alias") == 0 || strcmp(section_name(s), "loopback") == 0) - continue; - dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); - dmuci_get_value_by_section_string(s, "netmask", &mask4); - 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"); - mask4= dmjson_get_value(jobj, 1, "mask"); - } - } - 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(type, "bridge") != 0) - continue; - - dmuci_set_value_by_section(s, "proto", "static"); + uci_foreach_option_eq_safe("network", "interface", "proto", "dhcp", s_tmp, s) { + struct uci_section *dmmap_section = NULL; get_dmmap_section_of_config_section("dmmap_dhcp_client", "interface", section_name(s), &dmmap_section); - if (strlen(ipv4addr) == 0) { - if(dmmap_section != NULL) - dmuci_get_value_by_section_string(dmmap_section, "bbf_dhcpv4client_instance", &v); - else - dmasprintf(&v, "%d", 0); - dmasprintf(&ipv4addr, "%s.%s.%s.%s", v, v, v, v); - dmasprintf(&mask4, "%s", "255.255.255.0"); + dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &added_by_controller); + if (added_by_controller && strcmp(added_by_controller, "1") == 0) { + dmuci_delete_by_section(s, NULL, NULL); + } else { + dmuci_set_value_by_section(s, "proto", "none"); } - dmuci_set_value_by_section(s, "ipaddr", ipv4addr); - dmuci_set_value_by_section(s, "netmask", mask4); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - } - uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "interface", stmp, s) { - dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); + + dmuci_delete_by_section(dmmap_section, NULL, NULL); } break; } @@ -1788,18 +1774,18 @@ static int set_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (((struct dhcp_client_args *)data)->dhcp_client_conf) { - char *linker = dmstrdup(section_name(((struct dhcp_client_args *)data)->dhcp_client_conf)); - adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; - } + struct uci_section *dhcp_s = ((struct dhcp_client_args *)data)->dhcp_client_conf; + + char *linker = dmstrdup(dhcp_s ? section_name(dhcp_s) : ""); + adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); + if (*value == NULL) + *value = ""; return 0; } static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return set_DHCP_Interface(ctx, value, ((struct dhcp_client_args *)data)->dhcp_client_dm, "dmmap_dhcp_client", "dhcp", action); + return set_DHCP_Interface(ctx, value, ((struct dhcp_client_args *)data)->dhcp_client_conf, ((struct dhcp_client_args *)data)->dhcp_client_dm, "dmmap_dhcp_client", "dhcp", action); } /*#Device.DHCPv4.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/ @@ -1814,18 +1800,14 @@ static int get_DHCPv4Client_Status(char *refparam, struct dmctx *ctx, void *data /*#Device.DHCPv4.Client.{i}.DHCPStatus!UBUS:network.interface/status/interface,@Name/ipv4-address[@i-1].address*/ static int get_DHCPv4Client_DHCPStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "Init"; + struct uci_section *dhcp_s = ((struct dhcp_client_args *)data)->dhcp_client_conf; + json_object *res = NULL; - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - json_object *res; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcp_s ? section_name(dhcp_s) : "", String}}, 1, &res); DM_ASSERT(res, *value = "Requesting"); json_object *jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); char *ipaddr = dmjson_get_value(jobj, 1, "address"); *value = (ipaddr[0] == '\0') ? "Requesting" : "Bound"; - return 0; } @@ -1837,7 +1819,8 @@ static int get_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, static int set_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - json_object *res; + struct uci_section *dhcp_s = ((struct dhcp_client_args *)data)->dhcp_client_conf; + bool b; switch (action) { case VALUECHECK: @@ -1845,10 +1828,9 @@ static int set_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, return FAULT_9007; break; case VALUESET: - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL && strcasecmp(value, "true") != 0) - return 0; - - dmubus_call("network.interface", "renew", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + string_to_bool(value, &b); + if (!b) break; + dmubus_call_set("network.interface", "renew", UBUS_ARGS{{"interface", dhcp_s ? section_name(dhcp_s) : "", String}}, 1); break; } return 0; @@ -1869,14 +1851,12 @@ static int get_DHCPv4Client_SubnetMask(char *refparam, struct dmctx *ctx, void * /*#Device.DHCPv4.Client.{i}.IPRouters!UBUS:network.interface/status/interface,@Name/route[@i-1].nexthop*/ static int get_DHCPv4Client_IPRouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct uci_section *dhcp_s = ((struct dhcp_client_args *)data)->dhcp_client_conf; json_object *res = NULL, *route = NULL, *arrobj = NULL; unsigned pos = 0, idx = 0; char list_ip[256] = {0}; - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcp_s ? section_name(dhcp_s) : "", String}}, 1, &res); DM_ASSERT(res, *value = ""); list_ip[0] = 0; @@ -1896,12 +1876,10 @@ static int get_DHCPv4Client_IPRouters(char *refparam, struct dmctx *ctx, void *d /*#Device.DHCPv4.Client.{i}.DNSServers!UBUS:network.interface/status/interface,@Name/dns-server*/ static int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res; + struct uci_section *dhcp_s = ((struct dhcp_client_args *)data)->dhcp_client_conf; + json_object *res = NULL; - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcp_s ? section_name(dhcp_s) : "", String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value_array_all(res, ",", 1, "dns-server"); return 0; @@ -1910,13 +1888,11 @@ static int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void * /*#Device.DHCPv4.Client.{i}.LeaseTimeRemaining!UBUS:network.interface/status/interface,@Name/data.leasetime*/ static int get_DHCPv4Client_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res; + struct uci_section *dhcp_s = ((struct dhcp_client_args *)data)->dhcp_client_conf; + json_object *res = NULL; - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - DM_ASSERT(res, *value = "-1"); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcp_s ? section_name(dhcp_s) : "", String}}, 1, &res); + DM_ASSERT(res, *value = "0"); *value = dmjson_get_value(res, 2, "data", "leasetime"); return 0; } @@ -2447,7 +2423,7 @@ static int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return set_DHCP_Interface(ctx, value, ((struct dhcp_client_args *)data)->dhcp_client_dm, "dmmap_dhcp_relay", "relay", action); + return set_DHCP_Interface(ctx, value, ((struct dhcp_client_args *)data)->dhcp_client_conf, ((struct dhcp_client_args *)data)->dhcp_client_dm, "dmmap_dhcp_relay", "relay", action); } /*#Device.DHCPv4.Relay.Forwarding.{i}.VendorClassID!UCI:network/interface,@i-1/vendorclass*/ @@ -2717,11 +2693,11 @@ static int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void * { const struct dhcp_args *dhcp = prev_data; const struct dhcp_lease *lease = NULL; - struct client_args client_args = {0}; - char *inst = NULL, *max_inst = NULL; int id = 0; list_for_each_entry(lease, &dhcp->leases, list) { + struct client_args client_args; + char *inst, *max_inst = NULL; init_dhcp_client_args(&client_args, lease); @@ -2800,30 +2776,33 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p /*#Device.DHCPv4.Client.{i}.!UCI:network/interface/dmmap_dhcp_client*/ static int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - char *inst = NULL, *max_inst = NULL, *ipv4addr = "", *mask4 = NULL; - struct dmmap_dup *p = NULL; - json_object *res, *jobj; struct dhcp_client_args dhcp_client_arg = {0}; + char *inst = NULL, *max_inst = NULL; + struct dmmap_dup *p = NULL; LIST_HEAD(dup_list); synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_dhcp_client", "proto", "dhcp", &dup_list); list_for_each_entry(p, &dup_list, list) { + char *ipv4addr = NULL, *mask4 = NULL; + dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); dmuci_get_value_by_section_string(p->config_section, "netmask", &mask4); - if (ipv4addr[0] == '\0') { + if (ipv4addr && ipv4addr[0] == '\0') { + json_object *res = NULL; + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + json_object *jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); ipv4addr = dmjson_get_value(jobj, 1, "address"); mask4 = dmjson_get_value(jobj, 1, "mask"); mask4 = (mask4 && *mask4) ? cidr2netmask(atoi(mask4)) : ""; } } - dhcp_client_arg.ip = dmstrdup(ipv4addr ? ipv4addr : ""); - dhcp_client_arg.mask = dmstrdup(mask4 ? mask4 : ""); dhcp_client_arg.dhcp_client_conf = p->config_section; dhcp_client_arg.dhcp_client_dm = p->dmmap_section; + dhcp_client_arg.ip = dmstrdup(ipv4addr ? ipv4addr : ""); + dhcp_client_arg.mask = dmstrdup(mask4 ? mask4 : ""); inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3, p->dmmap_section, "bbf_dhcpv4client_instance", "bbf_dhcpv4client_alias"); @@ -2831,6 +2810,7 @@ static int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcp_client_arg, inst) == DM_STOP) break; } + free_dmmap_config_dup_list(&dup_list); return 0; } @@ -2841,7 +2821,7 @@ static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_ struct dhcp_client_option_args dhcp_client_opt_args = {0}; struct browse_args browse_args = {0}; char *inst = NULL, *max_inst = NULL, *tag, *value, **sentopts = NULL, **buf = NULL, *tmp, *optionvalue, *v = NULL; - size_t length = 0, lgh2; + size_t length = 0, lgh2 = 0; int i, j; if (dhcp_client_args->dhcp_client_conf != NULL) @@ -2855,7 +2835,7 @@ static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_ dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", buf[0]); dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); } - optionvalue = dmstrdup(buf[1]); + optionvalue = dmstrdup(lgh2 > 1 ? buf[1] : ""); if (lgh2 > 2) { for (j = 2; j < lgh2; j++) { tmp = dmstrdup(optionvalue); @@ -3017,10 +2997,10 @@ static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_n } } - dhcp_relay_arg.ip = dmstrdup(relay_ipv4addr ? relay_ipv4addr : ""); - dhcp_relay_arg.mask = dmstrdup(relay_mask4 ? relay_mask4 : ""); dhcp_relay_arg.dhcp_client_conf = p->config_section; dhcp_relay_arg.dhcp_client_dm = p->dmmap_section; + dhcp_relay_arg.ip = dmstrdup(relay_ipv4addr ? relay_ipv4addr : ""); + dhcp_relay_arg.mask = dmstrdup(relay_mask4 ? relay_mask4 : ""); dmuci_get_value_by_section_string(p->config_section, "network", &relay_network); dhcp_network = get_dhcp_network_from_relay_list(relay_network); @@ -3035,6 +3015,7 @@ static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_n if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcp_relay_arg, inst) == DM_STOP) break; } + free_dmmap_config_dup_list(&dup_list); return 0; } @@ -3071,7 +3052,7 @@ DMLEAF tDHCPv4ClientParams[] = { {"Interface", &DMWRITE, DMT_STRING, get_DHCPv4Client_Interface, set_DHCPv4Client_Interface, BBFDM_BOTH}, {"Status", &DMREAD, DMT_STRING, get_DHCPv4Client_Status, NULL, BBFDM_BOTH}, {"DHCPStatus", &DMREAD, DMT_STRING, get_DHCPv4Client_DHCPStatus, NULL, BBFDM_BOTH}, -{"Renew", &DMWRITE, DMT_BOOL, get_DHCPv4Client_Renew, set_DHCPv4Client_Renew, BBFDM_BOTH}, +{"Renew", &DMWRITE, DMT_BOOL, get_DHCPv4Client_Renew, set_DHCPv4Client_Renew, BBFDM_CWMP}, {"IPAddress", &DMREAD, DMT_STRING, get_DHCPv4Client_IPAddress, NULL, BBFDM_BOTH}, {"SubnetMask", &DMREAD, DMT_STRING, get_DHCPv4Client_SubnetMask, NULL, BBFDM_BOTH}, {"IPRouters", &DMREAD, DMT_STRING, get_DHCPv4Client_IPRouters, NULL, BBFDM_BOTH}, diff --git a/dmtree/tr181/dhcpv4.h b/dmtree/tr181/dhcpv4.h index cd8e98c2..a16b9f97 100644 --- a/dmtree/tr181/dhcpv4.h +++ b/dmtree/tr181/dhcpv4.h @@ -39,7 +39,7 @@ extern DMLEAF tDHCPv4RelayForwardingParams[]; int set_section_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order); int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, char **value); -int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *s_data, char *dmmap_name, char *proto, int action); +int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *config_s, struct uci_section *dmmap_s, char *dmmap_name, char *proto, int action); char *get_dhcp_server_pool_last_instance(char *package, char *section, char *dmmap_package, char *opt_inst); #endif diff --git a/dmtree/tr181/dhcpv6.c b/dmtree/tr181/dhcpv6.c index d6e2623d..d01ce99d 100644 --- a/dmtree/tr181/dhcpv6.c +++ b/dmtree/tr181/dhcpv6.c @@ -85,22 +85,29 @@ static inline int init_dhcpv6_args(struct dhcpv6_args *args, struct uci_section /*#Device.DHCPv6.Client.{i}.!UCI:network/interface/dmmap_dhcpv6*/ static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dmmap_dup *p = NULL; struct dhcpv6_client_args dhcpv6_client_arg = {0}; - json_object *res, *jobj; - char *inst = NULL, *max_inst = NULL, *ipv6addr = NULL; + char *inst = NULL, *max_inst = NULL; + struct dmmap_dup *p = NULL; LIST_HEAD(dup_list); synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_dhcpv6", "proto", "dhcpv6", &dup_list); list_for_each_entry(p, &dup_list, list) { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); - ipv6addr = dmjson_get_value(jobj, 1, "address"); + char *ipv6addr = NULL; + + dmuci_get_value_by_section_string(p->config_section, "ip6addr", &ipv6addr); + if (ipv6addr && ipv6addr[0] == '\0') { + json_object *res = NULL; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); + if (res) { + json_object *jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); + ipv6addr = dmjson_get_value(jobj, 1, "address"); + } } + dhcpv6_client_arg.dhcp_client_conf = p->config_section; dhcpv6_client_arg.dhcp_client_dm = p->dmmap_section; - dhcpv6_client_arg.ip = dmstrdup(ipv6addr?ipv6addr:""); + dhcpv6_client_arg.ip = dmstrdup(ipv6addr ? ipv6addr : ""); inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3, p->dmmap_section, "bbf_dhcpv6client_instance", "bbf_dhcpv6client_alias"); @@ -285,60 +292,55 @@ static int browseDHCPv6ServerPoolClientIPv6PrefixInst(struct dmctx *dmctx, DMNOD static int addObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char **instance) { struct uci_section *s = NULL, *dmmap_sect = NULL; + char dhcpv6_s[32]; - char *inst_para = get_last_instance_bbfdm("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance"); + char *last_inst = get_last_instance_bbfdm("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance"); + snprintf(dhcpv6_s, sizeof(dhcpv6_s), "dhcpv6_intf_%d", last_inst ? atoi(last_inst) + 1 : 1); dmuci_add_section("network", "interface", &s); + dmuci_rename_section_by_section(s, dhcpv6_s); dmuci_set_value_by_section(s, "proto", "dhcpv6"); - dmuci_set_value_by_section(s, "ifname", "@wan"); - dmuci_set_value_by_section(s, "type", "anywan"); + dmuci_set_value_by_section(s, "disabled", "1"); + dmuci_set_value_by_section(s, "reqaddress", "force"); + dmuci_set_value_by_section(s, "reqprefix", "no"); dmuci_add_section_bbfdm("dmmap_dhcpv6", "interface", &dmmap_sect); - dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); - *instance = update_instance(inst_para, 2, dmmap_sect, "bbf_dhcpv6client_instance"); + dmuci_set_value_by_section(dmmap_sect, "section_name", dhcpv6_s); + dmuci_set_value_by_section(dmmap_sect, "added_by_controller", "1"); + *instance = update_instance(last_inst, 2, dmmap_sect, "bbf_dhcpv6client_instance"); return 0; } static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct dhcpv6_client_args *dhcpv6_client_args = (struct dhcpv6_client_args*)data; - struct uci_section *s = NULL, *dmmap_section, *ss = NULL; - int found = 0; - char *proto; + struct uci_section *s = NULL, *s_tmp = NULL; + char *added_by_controller = NULL; switch (del_action) { case DEL_INST: - if(dhcpv6_client_args->dhcp_client_conf != NULL && is_section_unnamed(section_name(dhcpv6_client_args->dhcp_client_conf))){ - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance", section_name(dhcpv6_client_args->dhcp_client_conf), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "bbf_dhcpv6client_instance", "dmmap_dhcpv6", "interface"); - dmuci_delete_by_section_unnamed(dhcpv6_client_args->dhcp_client_conf, NULL, NULL); + dmuci_get_value_by_section_string(((struct dhcpv6_client_args*)data)->dhcp_client_dm, "added_by_controller", &added_by_controller); + if (added_by_controller && strcmp(added_by_controller, "1") == 0) { + dmuci_delete_by_section(((struct dhcpv6_client_args*)data)->dhcp_client_conf, NULL, NULL); } else { - get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(dhcpv6_client_args->dhcp_client_conf), &dmmap_section); - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(dhcpv6_client_args->dhcp_client_conf, NULL, NULL); + dmuci_set_value_by_section(((struct dhcpv6_client_args*)data)->dhcp_client_conf, "proto", "none"); } + + dmuci_delete_by_section(((struct dhcpv6_client_args*)data)->dhcp_client_dm, NULL, NULL); break; case DEL_ALL: - uci_foreach_sections("network", "interface", s) { - if (found != 0) { - dmuci_get_value_by_section_string(ss, "proto", &proto); - if(strcmp(proto, "dhcpv6") == 0) { - get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(ss), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - ss = s; - found++; - } - if (ss != NULL) { - dmuci_get_value_by_section_string(ss, "proto", &proto); - if (strcmp(proto, "dhcpv6") == 0) { - get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(ss), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); + uci_foreach_option_eq_safe("network", "interface", "proto", "dhcpv6", s_tmp, s) { + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(s), &dmmap_section); + + dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &added_by_controller); + if (added_by_controller && strcmp(added_by_controller, "1") == 0) { + dmuci_delete_by_section(s, NULL, NULL); + } else { + dmuci_set_value_by_section(s, "proto", "none"); } + + dmuci_delete_by_section(dmmap_section, NULL, NULL); } break; } @@ -473,18 +475,9 @@ static int get_DHCPv6_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, v /*#Device.DHCPv6.Client.{i}.Enable!UCI:network/interface,@i-1/disabled*/ static int get_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *v = NULL; - - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = "0"; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &v); - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value = "1"; - else - *value = "0"; + char *disabled = NULL; + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &disabled); + *value = (disabled[0] == '1') ? "0" : "1"; return 0; } @@ -529,64 +522,51 @@ static int set_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } + struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->dhcp_client_conf; + char *ifname = NULL; - char *linker = dmstrdup(section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf)); + dmuci_get_value_by_section_string(dhcpv6_s, "ifname", &ifname); + char *parent_s = (ifname && *ifname) ? strchr(ifname, '@') : NULL; + + char *linker = dmstrdup(parent_s ? parent_s + 1 : dhcpv6_s ? section_name(dhcpv6_s) : ""); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); + if (*value == NULL) + *value = ""; return 0; } static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return set_DHCP_Interface(ctx, value, ((struct dhcpv6_client_args *)data)->dhcp_client_dm, "dmmap_dhcpv6", "dhcpv6", action); + return set_DHCP_Interface(ctx, value, ((struct dhcpv6_client_args *)data)->dhcp_client_conf, ((struct dhcpv6_client_args *)data)->dhcp_client_dm, "dmmap_dhcpv6", "dhcpv6", action); } /*#Device.DHCPv6.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/ static int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *v = NULL; - if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = "Error_Misconfigured"; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &v); - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value = "Enabled"; - else - *value = "Disabled"; + char *disabled = NULL; + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &disabled); + *value = (disabled[0] == '1') ? "Disabled" : "Enabled"; return 0; } /*#Device.DHCPv6.Client.{i}.DUID!UBUS:network.interface/status/interface,@Name/data.passthru*/ static int get_DHCPv6Client_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res; + struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->dhcp_client_conf; + json_object *res = NULL; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - if (res) { - *value = dmjson_get_value(res, 2, "data", "passthru"); - } + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcpv6_s ? section_name(dhcpv6_s) : "", String}}, 1, &res); + *value = res ? dmjson_get_value(res, 2, "data", "passthru") : ""; return 0; } /*#Device.DHCPv6.Client.{i}.RequestAddresses!UCI:network/interface,@i-1/reqaddress*/ static int get_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *v = NULL; - if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = "0"; - return 0; - } + char *reqaddress = NULL; - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", &v); - if (strcmp(v, "none") == 0) - *value = "0"; - else - *value = "1"; + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", &reqaddress); + *value = (reqaddress && strcmp(reqaddress, "none") == 0) ? "0" : "1"; return 0; } @@ -610,17 +590,10 @@ static int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, /*#Device.DHCPv6.Client.{i}.RequestPrefixes!UCI:network/interface,@i-1/reqprefix*/ static int get_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *v = ""; - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = "0"; - return 0; - } + char *reqprefix = NULL; - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", &v); - if (strcmp(v, "no") == 0) - *value = "0"; - else - *value = "1"; + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", &reqprefix); + *value = (reqprefix && strcmp(reqprefix, "auto") == 0) ? "1" : "0"; return 0; } @@ -649,7 +622,7 @@ static int get_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - json_object *res; + struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->dhcp_client_conf; bool b; switch (action) { @@ -659,10 +632,8 @@ static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, break; case VALUESET: string_to_bool(value, &b); - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL && !b) - return 0; - - dmubus_call("network.interface", "renew", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + if (!b) break; + dmubus_call_set("network.interface", "renew", UBUS_ARGS{{"interface", dhcpv6_s ? section_name(dhcpv6_s) : "", String}}, 1); break; } return 0; @@ -671,10 +642,6 @@ static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, /*#Device.DHCPv6.Client.{i}.RequestedOptions!UCI:network/interface,@i-1/reqopts*/ static int get_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqopts", value); return 0; } @@ -1361,7 +1328,7 @@ DMLEAF tDHCPv6ClientParams[] = { {"RequestAddresses", &DMWRITE, DMT_BOOL, get_DHCPv6Client_RequestAddresses, set_DHCPv6Client_RequestAddresses, BBFDM_BOTH}, {"RequestPrefixes", &DMWRITE, DMT_BOOL, get_DHCPv6Client_RequestPrefixes, set_DHCPv6Client_RequestPrefixes, BBFDM_BOTH}, //{"RapidCommit", &DMWRITE, DMT_BOOL, get_DHCPv6Client_RapidCommit, set_DHCPv6Client_RapidCommit, BBFDM_BOTH}, -{"Renew", &DMWRITE, DMT_BOOL, get_DHCPv6Client_Renew, set_DHCPv6Client_Renew, BBFDM_BOTH}, +{"Renew", &DMWRITE, DMT_BOOL, get_DHCPv6Client_Renew, set_DHCPv6Client_Renew, BBFDM_CWMP}, //{"SuggestedT1", &DMWRITE, DMT_INT, get_DHCPv6Client_SuggestedT1, set_DHCPv6Client_SuggestedT1, BBFDM_BOTH}, //{"SuggestedT2", &DMWRITE, DMT_INT, get_DHCPv6Client_SuggestedT2, set_DHCPv6Client_SuggestedT2, BBFDM_BOTH}, //{"SupportedOptions", &DMREAD, DMT_STRING, get_DHCPv6Client_SupportedOptions, NULL, BBFDM_BOTH}, diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index 1f0188a0..5180dc0b 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -360,6 +360,28 @@ static char *get_ip_interface_last_instance(char *package, char *section, char* strchr(ifname, '@')) continue; + // skip dhcpv4 sections added by controller + if (strcmp(proto, "dhcp") == 0) { + struct uci_section *dmmap_section = NULL; + char *dhcpv4_user_s = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcp_client", "interface", section_name(s), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &dhcpv4_user_s); + if (dhcpv4_user_s && strcmp(dhcpv4_user_s, "1") == 0) + continue; + } + + // skip dhcpv6 sections added by controller + if (strcmp(proto, "dhcpv6") == 0) { + struct uci_section *dmmap_section = NULL; + char *dhcpv6_user_s = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(s), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &dhcpv6_user_s); + if (dhcpv6_user_s && strcmp(dhcpv6_user_s, "1") == 0) + 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); @@ -586,6 +608,28 @@ static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void strchr(ifname, '@')) continue; + // skip dhcpv4 sections added by controller + if (strcmp(proto, "dhcp") == 0) { + struct uci_section *dmmap_section = NULL; + char *dhcpv4_user_s = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcp_client", "interface", section_name(p->config_section), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &dhcpv4_user_s); + if (dhcpv4_user_s && strcmp(dhcpv4_user_s, "1") == 0) + continue; + } + + // skip dhcpv6 sections added by controller + if (strcmp(proto, "dhcpv6") == 0) { + struct uci_section *dmmap_section = NULL; + char *dhcpv6_user_s = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(p->config_section), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &dhcpv6_user_s); + if (dhcpv6_user_s && strcmp(dhcpv6_user_s, "1") == 0) + continue; + } + inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3, p->dmmap_section, "ip_int_instance", "ip_int_alias"); @@ -599,7 +643,7 @@ static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void 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, *ipaddr, *added_by_user = NULL, *ifname, buf[32] = {0}; + char *inst = NULL, *max_inst = NULL, *ipaddr, *added_by_controller = NULL, *ifname, buf[32] = {0}; json_object *res = NULL, *ipv4_obj = NULL; struct intf_ip_args curr_intf_ip_args = {0}; struct browse_args browse_args = {0}; @@ -613,7 +657,7 @@ static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_ continue; dmmap_s = check_dmmap_network_interface_ipv4("dmmap_network_ipv4", "intf_ipv4", section_name(parent_sec), section_name(intf_s)); - dmuci_get_value_by_section_string(dmmap_s, "added_by_user", &added_by_user); + dmuci_get_value_by_section_string(dmmap_s, "added_by_controller", &added_by_controller); dmuci_get_value_by_section_string(intf_s, "ipaddr", &ipaddr); if (*ipaddr == '\0') { @@ -622,7 +666,7 @@ static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_ ipaddr = dmjson_get_value(ipv4_obj, 1, "address"); } - if (*ipaddr == '\0' && added_by_user && strcmp(added_by_user, "1") != 0) + if (*ipaddr == '\0' && added_by_controller && strcmp(added_by_controller, "1") != 0) continue; if (dmmap_s == NULL) @@ -864,6 +908,7 @@ static int addObjIPInterface(char *refparam, struct dmctx *ctx, void *data, char dmuci_set_value("network", ip_name, "", "interface"); dmuci_set_value("network", ip_name, "proto", "none"); + dmuci_set_value("network", ip_name, "disabled", "1"); dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ip_interface); dmuci_set_value_by_section(dmmap_ip_interface, "section_name", ip_name); @@ -930,7 +975,7 @@ static int addObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void dmuci_add_section_bbfdm("dmmap_network_ipv4", "intf_ipv4", &dmmap_ip_interface_ipv4); 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", last_inst ? ipv4_name : section_name((struct uci_section *)data)); - dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "added_by_user", "1"); + dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "added_by_controller", "1"); *instance = update_instance(last_inst, 5, dmmap_ip_interface_ipv4, "ipv4_instance", NULL, check_browse_section, (void *)&browse_args); return 0; @@ -1647,40 +1692,6 @@ static int get_IPInterface_IPv6PrefixNumberOfEntries(char *refparam, struct dmct return 0; } -/*#Device.IP.Interface.{i}.AutoIPEnable!UCI:network/interface,@i-1/proto*/ -static int get_IPInterface_AutoIPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *proto = NULL; - dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); - *value = (proto && strcmp(proto, "dhcp") == 0) ? "1" : "0"; - return 0; -} - -static int set_IPInterface_AutoIPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *ip_addr = NULL; - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_get_value_by_section_string((struct uci_section *)data, "ipaddr", &ip_addr); - if (b) { - dmuci_set_value_by_section((struct uci_section *)data, "proto", "dhcp"); - dmuci_set_value_by_section((struct uci_section *)data, "ipaddr", ""); - } else { - dmuci_set_value_by_section((struct uci_section *)data, "proto", (ip_addr && *ip_addr) ? "static" : "none"); - dmuci_set_value_by_section((struct uci_section *)data, "ipaddr", (ip_addr && *ip_addr) ? ip_addr : ""); - } - break; - } - return 0; -} - static int get_IPInterface_TWAMPReflectorNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; @@ -1774,16 +1785,16 @@ static int set_IPInterfaceIPv4Address_Alias(char *refparam, struct dmctx *ctx, v /*#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) { - char *ip_addr = ""; + char *ip_addr = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ipaddr", &ip_addr); - if (ip_addr[0] == '\0') { + if (ip_addr && ip_addr[0] == '\0') { json_object *ipv4_obj = dmjson_select_obj_in_array_idx(((struct intf_ip_args *)data)->interface_obj, 0, 1, "ipv4-address"); ip_addr = dmjson_get_value(ipv4_obj, 1, "address"); } - *value = (ip_addr && *ip_addr) ? ip_addr : "0.0.0.0"; + *value = (ip_addr && *ip_addr) ? ip_addr : ""; return 0; } @@ -1808,17 +1819,17 @@ static int set_IPInterfaceIPv4Address_IPAddress(char *refparam, struct dmctx *ct /*#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 = ""; + char *mask = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "netmask", &mask); - if (mask[0] == '\0') { + if (mask && mask[0] == '\0') { json_object *ipv4_obj = dmjson_select_obj_in_array_idx(((struct intf_ip_args *)data)->interface_obj, 0, 1, "ipv4-address"); mask = dmjson_get_value(ipv4_obj, 1, "mask"); mask = (mask && *mask) ? dmstrdup(cidr2netmask(atoi(mask))) : ""; } - *value = (mask && *mask) ? mask : "0.0.0.0"; + *value = (mask && *mask) ? mask : ""; return 0; } @@ -2448,7 +2459,7 @@ DMLEAF tIPInterfaceParams[] = { {"IPv4AddressNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv4AddressNumberOfEntries, NULL, BBFDM_BOTH}, {"IPv6AddressNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv6AddressNumberOfEntries, NULL, BBFDM_BOTH}, {"IPv6PrefixNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv6PrefixNumberOfEntries, NULL, BBFDM_BOTH}, -{"AutoIPEnable", &DMWRITE, DMT_BOOL, get_IPInterface_AutoIPEnable, set_IPInterface_AutoIPEnable, BBFDM_BOTH}, +//{"AutoIPEnable", &DMWRITE, DMT_BOOL, get_IPInterface_AutoIPEnable, set_IPInterface_AutoIPEnable, BBFDM_BOTH}, {"TWAMPReflectorNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_TWAMPReflectorNumberOfEntries, NULL, BBFDM_BOTH}, {0} }; diff --git a/json/tr181.json b/json/tr181.json index 2f7cc04b..ee464101 100644 --- a/json/tr181.json +++ b/json/tr181.json @@ -41814,22 +41814,7 @@ "cwmp", "usp" ], - "datatype": "boolean", - "mapping": [ - { - "type": "uci", - "uci": { - "file": "network", - "section": { - "type": "interface", - "index": "@i-1" - }, - "option": { - "name": "proto" - } - } - } - ] + "datatype": "boolean" }, "TWAMPReflectorNumberOfEntries": { "type": "unsignedInt",