Commit e16e8e18 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

fix compile warnings

parent b7556dcf
Pipeline #35777 passed with stages
in 1 minute and 31 seconds
......@@ -16,6 +16,7 @@
#include <libubus.h>
#include <libubox/utils.h>
#include <easy/easy.h>
#include <uci.h>
#include "timer.h"
#include "cmdu_ackq.h"
......
......@@ -25,6 +25,8 @@
#include <easy/easy.h>
#include <netlink/netlink.h>
#include "debug.h"
#include "host_config.h"
#include "topologyd.h"
......@@ -1116,6 +1118,147 @@ int host_get_interface_type(struct topologyd_private *priv)
return ret;
}
int host_get_neigh_status(uint8_t *mac_addr)
{
char cmd[256] = {0};
FILE *fp = NULL;
char *line = NULL;
size_t len = 0;
char macaddr_str[18];
int found = 0;
dbg("Inside %s %d\n", __func__, __LINE__);
if (mac_addr == NULL)
return -1;
hwaddr_ntoa(mac_addr, macaddr_str);
snprintf(cmd, 256,
"ip neigh show nud reachable|awk '{print $5}'|grep %s",
macaddr_str);
fp = popen(cmd, "r"); /* flawfinder: ignore */
if (fp == NULL) {
err("unable to execute command");
return -1;
}
dbg("Inside %s %d command is %s\n", __func__, __LINE__, cmd);
while (getline(&line, &len, fp) != -1) {
if (len < 17) {
free(line);
len = 0;
continue;
}
found = 1;
break;
}
free(line);
pclose(fp);
if (found == 0)
return -1;
else
return 0;
}
void host_get_table_cb(struct topologyd_private *priv)
{
struct host_node *p;
int i = 0, ret = -1;
char mac_str[18] = { 0 };
dbg("Inside %s %d\n", __func__, __LINE__);
if (!priv)
return;
for (i = 0; i < NODE_HTABLE_SIZE; i++) {
if (hlist_empty(&priv->host.node_htable[i]))
continue;
hlist_for_each_entry(p, &priv->host.node_htable[i], hlist) {
bool has_ip = p->is_ipaddr;
//if (p->al_node)
// continue;
if (hwaddr_is_zero(p->hwaddr)) // TODO: unlikely..
continue;
if (p->is_copy == 1)
continue;
hwaddr_ntoa(p->hwaddr, mac_str);
if (p->intf_type != HOST_TYPE_ETHER && !p->is_ieee1905_node && p->is_device_mac == 0)
continue;
ret = host_get_neigh_status(p->hwaddr);
if (ret == 0 && has_ip) {
/*Here the node is rechable so
* active status is 1
*/
dbg("ETH node is reachable " MACFMT "\n", MAC2STR(p->hwaddr));
if (p->active != 1) {
//Here as the node is reachable
//we are adding in map-topology
host_send_client_event(priv, p, 1);
host_change_active_state(priv, p, 1);
}
} else {
/*Here as the status is not reachable
*/
dbg("ETH node is unreachable " MACFMT "\n", MAC2STR(p->hwaddr));
if (p->active != 0) {
host_send_client_event(priv, p, 0);
host_change_active_state(priv, p, 0);
}
}
}
}
}
void host_get_wifi_table_cb(struct topologyd_private *priv)
{
struct host_node *p;
int i = 0;
char mac_str[18] = { 0 };
dbg("Inside %s %d\n", __func__, __LINE__);
if (!priv)
return;
for (i = 0; i < NODE_HTABLE_SIZE; i++) {
if (hlist_empty(&priv->host.node_htable[i]))
continue;
hlist_for_each_entry(p, &priv->host.node_htable[i], hlist) {
//if (p->al_node)
// continue;
if (hwaddr_is_zero(p->hwaddr)) // TODO: unlikely..
continue;
if (p->is_copy == 1)
continue;
hwaddr_ntoa(p->hwaddr, mac_str);
dbg("macstr is %s\n", mac_str);
if (p->intf_type != HOST_TYPE_ETHER && !p->is_ieee1905_node && p->is_device_mac == 0) {
if (p->active == 1) {
time_t now;
double diff_t;
now = time(NULL);
diff_t = difftime(now, p->age_time);
if (diff_t > WIFI_TIME_OUT)
host_topo_node_del(priv, NULL, p->hwaddr, 1);
dbg("Timeout diff is ===================%f\n", diff_t);
}
}
}
}
}
/*Here the host periodic refresh timer does as below:
* 1. run the topology refresh algo such that all the new
* non -1905 neighbors can be fetched
......@@ -1174,51 +1317,6 @@ int host_send_arp_req(char *ipaddr_str)
return ret;
}
int host_get_neigh_status(uint8_t *mac_addr)
{
char cmd[256] = {0};
FILE *fp = NULL;
char *line = NULL;
size_t len = 0;
char macaddr_str[18];
int found = 0;
dbg("Inside %s %d\n", __func__, __LINE__);
if (mac_addr == NULL)
return -1;
hwaddr_ntoa(mac_addr, macaddr_str);
snprintf(cmd, 256,
"ip neigh show nud reachable|awk '{print $5}'|grep %s",
macaddr_str);
fp = popen(cmd, "r"); /* flawfinder: ignore */
if (fp == NULL) {
err("unable to execute command");
return -1;
}
dbg("Inside %s %d command is %s\n", __func__, __LINE__, cmd);
while (getline(&line, &len, fp) != -1) {
if (len < 17) {
free(line);
len = 0;
continue;
}
found = 1;
break;
}
free(line);
pclose(fp);
if (found == 0)
return -1;
else
return 0;
}
/*
*{ "topology.host": {"action":"connect","macaddr":"fe:ce:90:d7:5e:64","ipaddr":"192.168.1.157","network":"lan"} }
*{ "topology.host": {"action":"disconnect","macaddr":"fe:ce:90:d7:5e:64","ipaddr":"192.168.1.157","network":"lan"} }
......@@ -1392,103 +1490,6 @@ void host_run_status_check(struct topologyd_private *priv)
}
void host_get_table_cb(struct topologyd_private *priv)
{
struct host_node *p;
int i = 0, ret = -1;
char mac_str[18] = { 0 };
dbg("Inside %s %d\n", __func__, __LINE__);
if (!priv)
return;
for (i = 0; i < NODE_HTABLE_SIZE; i++) {
if (hlist_empty(&priv->host.node_htable[i]))
continue;
hlist_for_each_entry(p, &priv->host.node_htable[i], hlist) {
bool has_ip = p->is_ipaddr;
//if (p->al_node)
// continue;
if (hwaddr_is_zero(p->hwaddr)) // TODO: unlikely..
continue;
if (p->is_copy == 1)
continue;
hwaddr_ntoa(p->hwaddr, mac_str);
if (p->intf_type != HOST_TYPE_ETHER && !p->is_ieee1905_node && p->is_device_mac == 0)
continue;
ret = host_get_neigh_status(p->hwaddr);
if (ret == 0 && has_ip) {
/*Here the node is rechable so
* active status is 1
*/
dbg("ETH node is reachable " MACFMT "\n", MAC2STR(p->hwaddr));
if (p->active != 1) {
//Here as the node is reachable
//we are adding in map-topology
host_send_client_event(priv, p, 1);
host_change_active_state(priv, p, 1);
}
} else {
/*Here as the status is not reachable
*/
dbg("ETH node is unreachable " MACFMT "\n", MAC2STR(p->hwaddr));
if (p->active != 0) {
host_send_client_event(priv, p, 0);
host_change_active_state(priv, p, 0);
}
}
}
}
}
void host_get_wifi_table_cb(struct topologyd_private *priv)
{
struct host_node *p;
int i = 0;
char mac_str[18] = { 0 };
dbg("Inside %s %d\n", __func__, __LINE__);
if (!priv)
return;
for (i = 0; i < NODE_HTABLE_SIZE; i++) {
if (hlist_empty(&priv->host.node_htable[i]))
continue;
hlist_for_each_entry(p, &priv->host.node_htable[i], hlist) {
bool has_ip = p->is_ipaddr;
//if (p->al_node)
// continue;
if (hwaddr_is_zero(p->hwaddr)) // TODO: unlikely..
continue;
if (p->is_copy == 1)
continue;
hwaddr_ntoa(p->hwaddr, mac_str);
dbg("macstr is %s\n", mac_str);
if (p->intf_type != HOST_TYPE_ETHER && !p->is_ieee1905_node && p->is_device_mac == 0) {
if (p->active == 1) {
time_t now;
double diff_t;
now = time(NULL);
diff_t = difftime(now, p->age_time);
if (diff_t > WIFI_TIME_OUT)
host_topo_node_del(priv, NULL, p->hwaddr, 1);
dbg("Timeout diff is ===================%f\n", diff_t);
}
}
}
}
}
int topology_update_client_assoc_event(struct topologyd_private *priv, struct tlv_client_assoc_event *assoc)
{
uint8_t hwaddr[6] = {0};
......@@ -1748,7 +1749,7 @@ out:
int host_send_mid_topology_query(struct topologyd_private *p, uint8_t *dst_mac)
{
struct cmdu_buff *cmdu = NULL;
int ret = 0;
cmdu = host_topology_query_map_tlv();
if (cmdu == NULL)
return -1;
......@@ -1757,6 +1758,7 @@ int host_send_mid_topology_query(struct topologyd_private *p, uint8_t *dst_mac)
} else {
send_cmdu(p, cmdu, dst_mac);
}
cmdu_free(cmdu);
return 0;
}
......
......@@ -31,8 +31,9 @@ int config_add_default_host_mac(const char *config, const char *type,
bool config_set_host_option(char *package_name,
char *section_type, char *search_key, char *search_val,
char *option, char *value, bool persistent);
int config_del_section(const char *config, const char *type, const char *value,
bool persistent);
int host_config_mapagent_get(bool *enable);
bool config_get_al_ifname(char *ifname);
#endif /* HOSTD_CONFIG_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment