diff --git a/src/host.c b/src/host.c index 881b2b2ff706574a979d05a2f87e561016d540aa..3318260ba977c5aa85bf0b684cc30c708f19b507 100644 --- a/src/host.c +++ b/src/host.c @@ -1035,7 +1035,7 @@ int host_get_wifi_data(struct topologyd_private *priv, struct host_node *p) len = json_object_array_length(sta_array); for (i = 0; i < len; i++) { - struct json_object *sta_obj, *sta_obj_macaddr, *jobj_ptr, *stat_obj; + struct json_object *sta_obj, *sta_obj_macaddr, *jobj_ptr; unsigned char macaddr[6] = {0}; sta_obj = json_object_array_get_idx(sta_array, i); @@ -1086,31 +1086,6 @@ int host_get_wifi_data(struct topologyd_private *priv, struct host_node *p) p->in_network = json_object_get_int64(jobj_ptr); - json_object_object_get_ex(sta_obj, "stats", &stat_obj); - if (!stat_obj) - continue; - - json_object_object_get_ex(stat_obj, "rx_data_bytes", &jobj_ptr); - if (!jobj_ptr) - continue; - - p->stats.rx_bytes = json_object_get_int64(jobj_ptr); - json_object_object_get_ex(stat_obj, "tx_total_bytes", &jobj_ptr); - if (!jobj_ptr) - continue; - - p->stats.tx_bytes = json_object_get_int64(jobj_ptr); - json_object_object_get_ex(stat_obj, "rx_data_pkts", &jobj_ptr); - if (!jobj_ptr) - continue; - - p->stats.rx_packets = json_object_get_int64(jobj_ptr); - json_object_object_get_ex(stat_obj, "tx_total_pkts", &jobj_ptr); - if (!jobj_ptr) - continue; - - p->stats.tx_packets = json_object_get_int64(jobj_ptr); - dbg("%s: sta: is Wifi %s\n", __func__, macstr); p->intf_type = HOST_TYPE_WIFI; if (p->active != 1) @@ -1753,14 +1728,10 @@ int topology_update_host_vendor_specific_data(struct node *n, dbg("Node not found\n"); continue; } - hn->stats.tx_bytes = BUF_GET_BE64(t->data[offset]); - offset += 8; - hn->stats.rx_bytes = BUF_GET_BE64(t->data[offset]); - offset += 8; - hn->stats.tx_packets = BUF_GET_BE64(t->data[offset]); - offset += 8; - hn->stats.rx_packets = BUF_GET_BE64(t->data[offset]); - offset += 8; + /*offset increment by 32 as to skip Bytes for statistics + statitstics collection is being done periodically in separate flow. */ + offset += 32; + dbg("\t\ttxbytes: [%lld] rxbytes: [%lld]\n", hn->stats.tx_bytes, hn->stats.rx_bytes); dbg("\t\ttxpackets: [%lld] rxpackets: [%lld]\n", hn->stats.tx_packets, hn->stats.rx_packets); } @@ -2099,3 +2070,131 @@ int host_copy_node_data(struct host_node *src_host, struct host_node *dest_host return 0; } + +int host_is_device_address(struct topologyd_private *priv, char *address, int family) +{ + struct json_object *interfaces = NULL; + int i = 0, len = 0; + bool ret = 0; + + dbg("Inside %s %d\n", __func__, __LINE__); + + if (!priv) + return 0; + + if (!json_object_is_type(priv->network_dump, json_type_object)) + return 0; + + ret = json_object_object_get_ex(priv->network_dump, "interface", &interfaces); + if (!ret || !interfaces) + return 0; + + if (!json_object_is_type(interfaces, json_type_array)) + return 0; + + len = json_object_array_length(interfaces); + + for (i = 0; i < len; i++) { + struct json_object *sta_obj = NULL, *jobj_network = NULL, *ipv4_arr = NULL; + struct json_object *ipv6_arr = NULL; + const char *network; + int ipv4_len, j, ipv6_len; + + sta_obj = json_object_array_get_idx(interfaces, i); + ret = json_object_object_get_ex(sta_obj, "interface", &jobj_network); + if (!ret || !jobj_network) + continue; + + network = json_object_get_string(jobj_network); + if (!network) + continue; + + if (family == AF_INET) { + ret = json_object_object_get_ex(sta_obj, "ipv4-address", &ipv4_arr); + if (!ret || !ipv4_arr) + continue; + + if (!json_object_is_type(ipv4_arr, json_type_array)) + return 0; + + ipv4_len = json_object_array_length(ipv4_arr); + for (j = 0; j < ipv4_len; j++) { + struct json_object *jobj_ptr = NULL, *iface = NULL; + const char *ipaddr; + + iface = json_object_array_get_idx(ipv4_arr, j); + if (!iface) + continue; + + ret = json_object_object_get_ex(iface, "address", &jobj_ptr); + if (!ret || !jobj_ptr) + continue; + + ipaddr = json_object_get_string(jobj_ptr); + if (!ipaddr) + continue; + if (!strncmp(address, ipaddr, 15)) + return 1; + } + } + else if (family == AF_INET6) { + ret = json_object_object_get_ex(sta_obj, "ipv6-prefix-assignment", &ipv6_arr); + if (!ret || !ipv6_arr) + continue; + + if (!json_object_is_type(ipv6_arr, json_type_array)) + return 0; + ipv6_len = json_object_array_length(ipv6_arr); + for (j = 0; j < ipv6_len; j++) { + struct json_object *jobj_ptr = NULL, *iface = NULL, *local_addr=NULL; + const char *ipaddr; + struct sockaddr_in6 sa6; + + iface = json_object_array_get_idx(ipv6_arr, j); + if (!iface) + continue; + ret = json_object_object_get_ex(iface, "local-address", &local_addr); + if (!ret || !local_addr) + continue; + ret = json_object_object_get_ex(local_addr, "address", &jobj_ptr); + if (!ret || !jobj_ptr) + continue; + ipaddr = json_object_get_string(jobj_ptr); + if (!ipaddr) + continue; + inet_pton(AF_INET6, ipaddr, &sa6.sin6_addr); + + if (!memcmp(sa6.sin6_addr.s6_addr, address, 16)) + return 1; + } + + ret = json_object_object_get_ex(sta_obj, "ipv6-address", &ipv6_arr); + if (!ret || !ipv6_arr) + continue; + + if (!json_object_is_type(ipv6_arr, json_type_array)) + return 0; + ipv6_len = json_object_array_length(ipv6_arr); + for (j = 0; j < ipv6_len; j++) { + struct json_object *jobj_ptr = NULL, *iface = NULL; + const char *ipaddr; + struct sockaddr_in6 sa6; + + iface = json_object_array_get_idx(ipv6_arr, j); + if (!iface) + continue; + ret = json_object_object_get_ex(iface, "address", &jobj_ptr); + if (!ret || !jobj_ptr) + continue; + ipaddr = json_object_get_string(jobj_ptr); + if (!ipaddr) + continue; + inet_pton(AF_INET6, ipaddr, &sa6.sin6_addr); + + if (!memcmp(sa6.sin6_addr.s6_addr, address, 16)) + return 1; + } + } + } + return 0; +} diff --git a/src/host.h b/src/host.h index adae744699381037c5b18a5067f9c91728d7d851..3ff79cf489b23b93832dcb7c64f879bcde80f236 100644 --- a/src/host.h +++ b/src/host.h @@ -171,6 +171,6 @@ bool is_local_mapagent_available(void); int host_get_wifi_data(struct topologyd_private *priv, struct host_node *p); void host_send_topology_query_all(struct topologyd_private *priv); int host_node_get_statistics(struct topologyd_private *priv); - +int host_is_device_address(struct topologyd_private *priv, char *address, int family); #endif /* HOSTD_H */ diff --git a/src/host_nodes.c b/src/host_nodes.c index 6dc4379f4279dcf82850f01af95720494336bae2..2e01e47443162e4bda221b3a4a5db0c360267a8a 100644 --- a/src/host_nodes.c +++ b/src/host_nodes.c @@ -259,7 +259,8 @@ int host_node_ipv6_stats_received(enum nf_conntrack_msg_type type, int i; struct sockaddr_in6 sa6; int count; - char ipv6_addr[16]; + char ipv6_addr[sizeof(int)*4]; + char ipv6_dst_addr[sizeof(int)*4]; int addr_part; nfct_get_attr_grp(ct, ATTR_GRP_ORIG_IPV6, &grp_ipv6); @@ -272,6 +273,20 @@ int host_node_ipv6_stats_received(enum nf_conntrack_msg_type type, addr_part = (grp_ipv6.src[3]); memcpy(&ipv6_addr[12], &addr_part, sizeof(int)); + addr_part = (grp_ipv6.dst[0]); + memcpy(&ipv6_dst_addr[0], &addr_part, sizeof(int)); + addr_part = (grp_ipv6.dst[1]); + memcpy(&ipv6_dst_addr[4], &addr_part, sizeof(int)); + addr_part = (grp_ipv6.dst[2]); + memcpy(&ipv6_dst_addr[8], &addr_part, sizeof(int)); + addr_part = (grp_ipv6.dst[3]); + memcpy(&ipv6_dst_addr[12], &addr_part, sizeof(int)); + + if (priv == NULL) + return NFCT_CB_CONTINUE; + + if (host_is_device_address(priv, ipv6_dst_addr, AF_INET6)) + return NFCT_CB_CONTINUE; for (i = 0; i < NODE_HTABLE_SIZE ; i++) { if ((hlist_empty(&priv->host.node_htable[i]))) @@ -287,7 +302,7 @@ int host_node_ipv6_stats_received(enum nf_conntrack_msg_type type, inet_pton(AF_INET6, host->ipv6addr[count], &sa6.sin6_addr); - if (!memcmp(ipv6_addr, sa6.sin6_addr.s6_addr, 16)) { + if (!memcmp(ipv6_addr, sa6.sin6_addr.s6_addr, sizeof(int)*4)) { return host_node_update_stats(ct, host); } } @@ -307,9 +322,14 @@ int host_node_stats_received(enum nf_conntrack_msg_type type, int i; struct sockaddr_in sa; int count; + struct in_addr dest_addr; ret_val=nfct_get_attr_grp(ct, ATTR_GRP_ORIG_IPV4, &grp_ipv4); - if (ret_val) + if (ret_val || priv == NULL) + return NFCT_CB_CONTINUE; + + memcpy(&dest_addr, &grp_ipv4.dst, sizeof(grp_ipv4.dst)); + if (host_is_device_address(priv, inet_ntoa(dest_addr), AF_INET)) return NFCT_CB_CONTINUE; for (i = 0; i < NODE_HTABLE_SIZE ; i++) { @@ -424,6 +444,7 @@ int host_node_get_statistics(struct topologyd_private *priv) } } } + cth = nfct_open(CONNTRACK, 0); if (!cth) { err("Can't open handler\n");