diff --git a/src/neigh.c b/src/neigh.c index 6f7beebd0cf044892b89a1c062357d6f183a8319..4018b25ab90debbc10631820e6486779a79be276 100644 --- a/src/neigh.c +++ b/src/neigh.c @@ -163,58 +163,53 @@ int neigh_history_entry_update_lastseen(void *priv, uint8_t *macaddr) } #endif -int neigh_history_enqueue(void *priv, uint8_t *macaddr, const char *hostname, - enum neigh_type type, struct neigh_wanstats *ws, - uint32_t timeout) +int neigh_history_enqueue(void *priv, struct neigh_entry *n, uint32_t timeout) { struct topologyd_private *p = (struct topologyd_private *)priv; - struct neigh_history_entry *e = NULL; + struct neigh_history_entry *he = NULL; - e = neigh_history_lookup(&p->neigh_q, macaddr); - if (e) { + he = neigh_history_lookup(&p->neigh_q, n->macaddr); + if (he) { /* stop ageing history as neigh is live */ - e->timeout = timeout; - timer_del(&e->delete_timer); - e->alive = true; + he->timeout = timeout; + timer_del(&he->delete_timer); + he->alive = true; /* set neigh type iff wifi type determined */ - if (type == NEIGH_TYPE_WIFI) - e->type = type; + if (n->type == NEIGH_TYPE_WIFI) + he->type = n->type; - if (hostname && hostname[0] != '\0') - strncpy(e->hostname, hostname, 255); + if (n->hostname && n->hostname[0] != '\0') + strncpy(he->hostname, n->hostname, 255); - if (ws) { - dbg("Update history stats: +ul-pkts = %llu, +dl-pkts = %llu\n", - ws->ul_packets, ws->dl_packets); + dbg("Update history stats: +ul-pkts = %llu, +dl-pkts = %llu\n", + n->ws.ul_packets, n->ws.dl_packets); - e->ws.ul_packets += ws->ul_packets; - e->ws.ul_bytes += ws->ul_bytes; - e->ws.dl_packets += ws->dl_packets; - e->ws.dl_bytes += ws->dl_bytes; - } + he->ws.ul_packets += n->ws.ul_packets; + he->ws.ul_bytes += n->ws.ul_bytes; + he->ws.dl_packets += n->ws.dl_packets; + he->ws.dl_bytes += n->ws.dl_bytes; return 0; } - dbg("No history for " MACFMT " found! Add new..\n", MAC2STR(macaddr)); + dbg("No history cache for " MACFMT " found! Add new..\n", MAC2STR(n->macaddr)); - e = neigh_history_entry_create(priv, macaddr, hostname, type, 0, 0, timeout); - if (e) { - int idx = neigh_hash(macaddr); + he = neigh_history_entry_create(priv, n->macaddr, n->hostname, n->type, + 0, 0, timeout); + if (he) { + int idx = neigh_hash(n->macaddr); /* stop ageing history as neigh is live */ - e->timeout = timeout; - timer_del(&e->delete_timer); - e->alive = true; - if (ws) { - e->ws.ul_packets = ws->ul_packets; - e->ws.ul_bytes = ws->ul_bytes; - e->ws.dl_packets = ws->dl_packets; - e->ws.dl_bytes = ws->dl_bytes; - } - - hlist_add_head(&e->hlist, &p->neigh_q.history[idx]); + he->timeout = timeout; + timer_del(&he->delete_timer); + he->alive = true; + he->ws.ul_packets = n->ws.ul_packets; + he->ws.ul_bytes = n->ws.ul_bytes; + he->ws.dl_packets = n->ws.dl_packets; + he->ws.dl_bytes = n->ws.dl_bytes; + + hlist_add_head(&he->hlist, &p->neigh_q.history[idx]); p->neigh_q.num_history++; return 1; } @@ -869,11 +864,8 @@ struct neigh_entry *neigh_enqueue(void *nq, uint8_t *macaddr, uint16_t state, #if 0 /* add/update history entry for this neigh */ - neigh_history_enqueue(priv, e->macaddr, e->hostname, e->type, - &e->ws, - NEIGH_HISTORY_AGEOUT_DEFAULT); + neigh_history_enqueue(priv, e, NEIGH_HISTORY_AGEOUT_DEFAULT); #endif - return NULL; } diff --git a/src/neigh.h b/src/neigh.h index c6e901bb2a21e8f70f62af9d90ed7658358cca1e..2fa923bb4b91d559257be8cec4b6c967c0c323e7 100644 --- a/src/neigh.h +++ b/src/neigh.h @@ -72,7 +72,7 @@ struct neigh_entry { int unreachable; /* mark entry nonreachable */ int delete_pending; atimer_t delete_timer; - uint32_t ageing_time; /* in msecs */ + uint32_t ageing_time; /* in msecs */ struct timeval ageing_tmo; int probe_cnt; diff --git a/src/netlink.c b/src/netlink.c index 22faf090c037624ad5b7635829988c9afe4c7500..67551c1cb612a051b9cca48f8a6a94b847e886c6 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -210,10 +210,8 @@ static int topologyd_handle_neigh_tbl_change(struct topologyd_private *priv, boo /* new neigh added */ topology_get_neigh_hostname(&priv->neigh_q, macaddr); - /* add/update history entry for this neigh */ - neigh_history_enqueue(priv, new->macaddr, new->hostname, - new->type, &new->ws, - NEIGH_HISTORY_AGEOUT_DEFAULT); + /* add/update history cache for this neigh */ + neigh_history_enqueue(priv, new, NEIGH_HISTORY_AGEOUT_DEFAULT); } /* update bridge port_nos on which the hosts are last seen */ @@ -634,10 +632,8 @@ int topologyd_get_known_neighbors(struct topologyd_private *priv, char *ifname) /* new neigh added */ ret = topology_get_neigh_hostname(&priv->neigh_q, hwaddr); //TODO: cond - /* add/update history entry for this neigh */ - neigh_history_enqueue(priv, new->macaddr, new->hostname, - new->type, &new->ws, - NEIGH_HISTORY_AGEOUT_DEFAULT); + /* add/update history cache for this neigh */ + neigh_history_enqueue(priv, new, NEIGH_HISTORY_AGEOUT_DEFAULT); } nl_object_put((struct nl_object *)neigh); diff --git a/src/topology.h b/src/topology.h index 812cae26ae89eaf2af0f4d3991819223541a636b..cd51c81c650c78704a2f4abb3d5476670ac01eb4 100644 --- a/src/topology.h +++ b/src/topology.h @@ -313,9 +313,7 @@ int nfct_get_entries_nolo(struct topologyd_private *priv); int neigh_history_entry_add(void *priv, struct neigh_history_entry *he); -int neigh_history_enqueue(void *priv, uint8_t *macaddr, const char *hostname, - enum neigh_type type, struct neigh_wanstats *ws, - uint32_t timeout); +int neigh_history_enqueue(void *priv, struct neigh_entry *e, uint32_t timeout); int neigh_history_load_from_json_file(void *priv, const char *file); int neigh_history_store_to_json_file(void *priv, const char *file); diff --git a/src/ubus.c b/src/ubus.c index 336b080b8577a0f341388e703a678fc80dab342d..f909fd25a01eb0da7874854c025e3caacbc18b45 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -770,11 +770,8 @@ static void topologyd_wifi_sta_event_handler(struct topologyd_private *p, /* new wifi neigh added */ topology_get_neigh_hostname(&p->neigh_q, macaddr); - /* add/update history entry for this neigh */ - neigh_history_enqueue(p, new->macaddr, - new->hostname, - new->type, - &new->ws, + /* add/update history cache for this neigh */ + neigh_history_enqueue(p, new, NEIGH_HISTORY_AGEOUT_DEFAULT); } } else if (del) {