diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh index 871521d5c4f1703d7df7d71ca336f30acd4ff638..8aa7297b28c64335c2b4224fbe77994a71b49d96 100755 --- a/gitlab-ci/install-dependencies.sh +++ b/gitlab-ci/install-dependencies.sh @@ -69,7 +69,7 @@ exec_cmd bzip2 -d libnetfilter_conntrack-1.0.9.tar.bz2 exec_cmd tar -xvf libnetfilter_conntrack-1.0.9.tar -exec_cmd git clone https://dev.iopsys.eu/bbf/bbfdm.git +exec_cmd git clone -b release-7.3 https://dev.iopsys.eu/bbf/bbfdm.git cd libnfnetlink-1.0.2 exec_cmd "./configure" diff --git a/src/bbf_plugin/hosts.c b/src/bbf_plugin/hosts.c index 67d25daa0b4aa60914e38f5ea6d2b66560abb1f3..8f8257be087b545625427272664565cddf8808e0 100644 --- a/src/bbf_plugin/hosts.c +++ b/src/bbf_plugin/hosts.c @@ -21,95 +21,6 @@ DM_MAP_OBJ tDynamicObj[] = { {0} }; -static int host_get_last_instance(void) -{ - struct uci_section *s = is_dmmap_section_exist("dmmap_hosts", "global"); - int last_inst = 0; - - if (s == NULL) { - dmuci_add_section_bbfdm("dmmap_hosts", "global", &s); - } else { - char *last_instance = NULL; - - dmuci_get_option_value_string_bbfdm("dmmap_hosts", "@global[0]", "last_instance", &last_instance); - last_inst = DM_STRTOUL(last_instance); - } - - return last_inst; -} - -static void synchronize_hosts_array_with_dmmap(json_object *res) -{ - struct uci_section *s = NULL, *stmp = NULL; - json_object *hosts_arr = NULL; - char *mac = NULL, *host_mac = NULL; - bool host_read_idx = false; - int host_idx = 0; - - if (!res) - return; - - json_object_object_get_ex(res, "hosts", &hosts_arr); - int nbre_hosts = (hosts_arr) ? json_object_array_length(hosts_arr) : 0; - - uci_path_foreach_sections_safe(bbfdm, "dmmap_hosts", "host", stmp, s) { - - dmuci_get_value_by_section_string(s, "mac", &mac); - - if (host_idx < nbre_hosts) { - if (!host_read_idx) { - json_object *host_obj = json_object_array_get_idx(hosts_arr, host_idx); - host_mac = dmjson_get_value(host_obj, 1, "macaddr"); - host_read_idx = true; - } - - if (DM_STRCMP(mac, host_mac) == 0) { - host_read_idx = false; - host_idx++; - continue; - } - } - - // Remove host from dmmap - dmuci_delete_by_section(s, NULL, NULL); - } -} - -static char *host_get_instance(char *mac, int idx, int *last_instance) -{ - struct uci_section *s = NULL; - char *inst = NULL; - int i = 0; - - uci_path_foreach_sections(bbfdm, "dmmap_hosts", "host", s) { - char *curr_mac = NULL; - - if (i > idx) - goto create_host; - - i++; - - dmuci_get_value_by_section_string(s, "mac", &curr_mac); - if (DM_STRCMP(curr_mac, mac) == 0) { - dmuci_get_value_by_section_string(s, "instance", &inst); - return inst; - } - } - -create_host: - { - dmasprintf(&inst, "%lu", ++(*last_instance)); - - dmuci_add_section_bbfdm("dmmap_hosts", "host", &s); - dmuci_set_value_by_section(s, "mac", mac); - dmuci_set_value_by_section(s, "instance", inst); - - dmuci_set_value_bbfdm("dmmap_hosts", "@global[0]", "last_instance", inst); - } - - return inst; -} - /************************************************************* * ENTRY METHOD **************************************************************/ @@ -117,20 +28,14 @@ create_host: static int browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { json_object *res = NULL, *host_obj = NULL, *arrobj = NULL; - int idx = 0, last_inst = 0; + int idx = 0, i = 0; char *inst = NULL; - last_inst = host_get_last_instance(); - dmubus_call("hosts", "show", UBUS_ARGS{0}, 0, &res); - synchronize_hosts_array_with_dmmap(res); - dmjson_foreach_obj_in_array(res, arrobj, host_obj, idx, 1, "hosts") { - char *mac = dmjson_get_value(host_obj, 1, "macaddr"); - - inst = host_get_instance(mac, idx, &last_inst); + inst = handle_instance_without_section(dmctx, parent_node, ++i); if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)host_obj, inst) == DM_STOP) break;