diff --git a/src/neigh.c b/src/neigh.c index 50ff7de7ff674a1af732463269f09baae110fcfe..758e5842f4aa8681b230880a4390c62ae69ff488 100644 --- a/src/neigh.c +++ b/src/neigh.c @@ -337,6 +337,62 @@ void neigh_history_free(void *nq) neigh_history_flush(q); } +int neigh_history_entry_set_1905(void *nq, uint8_t *macaddr, uint8_t val) +{ + struct neigh_history_entry *he = NULL; + + + he = neigh_history_lookup(nq, macaddr); + if (!he) + return -1; + + memcpy(he->aladdr, macaddr, 6); + he->is1905 = !!val; + dbg("%s: set " MACFMT " is1905 = %d\n", __func__, + MAC2STR(he->macaddr), he->is1905); + + return 0; +} + +int neigh_history_entry_set_1905_slave(void *nq, uint8_t *macaddr, + uint8_t *aladdr, uint8_t val) +{ + struct neigh_history_entry *he = NULL; + + + he = neigh_history_lookup(nq, macaddr); + if (!he) + return -1; + + if (aladdr) + memcpy(he->aladdr, aladdr, 6); + + he->is1905_slave = !!val; + dbg("%s: set " MACFMT " is1905_slave = %d\n", __func__, + MAC2STR(he->macaddr), he->is1905_slave); + + return 0; +} + +int neigh_history_entry_set_1905_link(void *nq, uint8_t *macaddr, + uint8_t *aladdr, uint8_t val) +{ + struct neigh_history_entry *he = NULL; + + + he = neigh_history_lookup(nq, macaddr); + if (!he) + return -1; + + if (aladdr) + memcpy(he->aladdr, aladdr, 6); + he->is1905_link = !!val; + dbg("%s: set " MACFMT " is1905_link = %d\n", __func__, + MAC2STR(he->macaddr), he->is1905_link); + + return 0; +} + struct neigh_entry *neigh_entry_create(void *priv, uint8_t *macaddr, uint16_t state, const char *ifname, enum neigh_type type, uint32_t timeout, void *cookie) diff --git a/src/neigh.h b/src/neigh.h index 3d85427a117a02043bc3ddecd9a83d60a253afd3..1f8e8c290d243969db49ca36bb460331f893407f 100644 --- a/src/neigh.h +++ b/src/neigh.h @@ -121,6 +121,13 @@ struct neigh_history_entry { extern void neigh_history_free(void *q); extern struct neigh_history_entry *neigh_history_lookup(void *nq, uint8_t *macaddr); +int neigh_history_entry_set_1905(void *nq, uint8_t *macaddr, uint8_t val); +int neigh_history_entry_set_1905_slave(void *nq, uint8_t *macaddr, + uint8_t *aladdr, uint8_t val); + +int neigh_history_entry_set_1905_link(void *nq, uint8_t *macaddr, + uint8_t *aladdr, uint8_t val); + struct neigh_queue { struct hlist_head table[NEIGH_ENTRIES_MAX]; /* hashtable of struct neigh_entry */ struct hlist_head history[NEIGH_ENTRIES_MAX]; /* hashtable of struct neigh_entry */ diff --git a/src/ubus.c b/src/ubus.c index fb72b4f3402d665102884645cfa79b44fef21b04..e884150b512fa65cac24df2b80b4c4e7fbad060a 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -202,6 +202,7 @@ static void hostmngr_1905topology_cb(struct ubus_request *req, int type, } neigh_set_1905(&priv->neigh_q, node_aladdr, 1); + neigh_history_entry_set_1905(&priv->neigh_q, node_aladdr, 1); /* dbg("%s: Node " MACFMT "\n", __func__, MAC2STR(node_aladdr)); @@ -248,6 +249,7 @@ static void hostmngr_1905topology_cb(struct ubus_request *req, int type, } neigh_set_1905_slave(&priv->neigh_q, if_macaddr, node_aladdr, 1); + neigh_history_entry_set_1905_slave(&priv->neigh_q, if_macaddr, node_aladdr, 1); dbg("%s: Interface " MACFMT "\n", __func__, MAC2STR(if_macaddr)); iter++; } @@ -284,6 +286,7 @@ static void hostmngr_1905topology_cb(struct ubus_request *req, int type, } neigh_set_1905_link(&priv->neigh_q, if_macaddr, node_aladdr, 1); + neigh_history_entry_set_1905_link(&priv->neigh_q, if_macaddr, node_aladdr, 1); dbg("%s: Interface " MACFMT "\n", __func__, MAC2STR(if_macaddr)); iter++; } @@ -626,8 +629,10 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, //if (e->unreachable) // continue; - if (e->is1905 || (e->is1905_slave && !e->is1905_link)) + if (e->is1905 || (e->is1905_slave && !e->is1905_link)) { + dbg("%s: skipping entry " MACFMT"\n", __func__, MAC2STR(e->macaddr)); continue; + } neigh_update_ip_entry_stats(p, &e->ipv4, e); @@ -732,11 +737,17 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, void *wt; - if (he->alive) + if (he->alive) { + dbg("%s: skipping alive history entry " MACFMT"\n", + __func__, MAC2STR(he->macaddr)); continue; + } - if (he->is1905 || (he->is1905_slave && !he->is1905_link)) + if (he->is1905 || (he->is1905_slave && !he->is1905_link)) { + dbg("%s: skipping history entry " MACFMT"\n", + __func__, MAC2STR(he->macaddr)); continue; + } aa = blobmsg_open_table(&bb, ""); hwaddr_ntoa(he->macaddr, macstr);