diff --git a/src/history.c b/src/history.c index 41df8c5fc0fd881f4c2ed42af4232a75009e37de..d7840ccd64f9dbb59b6da1293966625bc2ce7d49 100644 --- a/src/history.c +++ b/src/history.c @@ -30,6 +30,7 @@ int neigh_history_add_entry_json(struct json_object *jarray, { struct json_object *e, *es; char macstr[18] = {0}; + char alstr[18] = {0}; char ipstr[128] = {0}; int remtime; @@ -37,6 +38,7 @@ int neigh_history_add_entry_json(struct json_object *jarray, return -1; hwaddr_ntoa(he->macaddr, macstr); + hwaddr_ntoa(he->aladdr, alstr); remtime = timer_remaining_ms(&he->delete_timer) / 1000; inet_ntop(he->ip.family, &he->ip.addr, ipstr, sizeof(ipstr)); @@ -52,6 +54,9 @@ int neigh_history_add_entry_json(struct json_object *jarray, json_object_object_add(e, "ageout", json_object_new_int(remtime)); json_object_object_add(e, "mediatype", json_object_new_int(he->type)); json_object_object_add(e, "is1905", json_object_new_int(he->is1905)); + json_object_object_add(e, "is1905_interface", json_object_new_int(he->is1905_slave)); + json_object_object_add(e, "is1905_link", json_object_new_int(he->is1905_link)); + json_object_object_add(e, "ieee1905id", json_object_new_string(alstr)); json_object_object_add(e, "stats", es); json_object_object_add(es, "tx_packets", json_object_new_int64(he->ws.ul_packets)); json_object_object_add(es, "tx_bytes", json_object_new_int64(he->ws.ul_bytes)); @@ -157,6 +162,9 @@ int neigh_history_load_from_json_file(void *priv, const char *file) struct json_object *je, *je_ws; char macstr[18] = {0}; char ipstr[128] = {0}; + char alstr[18] = {0}; + int is1905_slave = 0; + int is1905_link = 0; int createtime = 0; int lastchange = 0; int lastseen = 0; @@ -179,6 +187,14 @@ int neigh_history_load_from_json_file(void *priv, const char *file) json_get_key_value(je, "ageout", &timeout); json_get_key_value(je, "mediatype", &type); json_get_key_value(je, "is1905", &is1905); + json_get_key_value(je, "is1905_interface", &is1905_slave); + json_get_key_value(je, "is1905_link", &is1905_link); + json_get_key_value(je, "ieee1905id", alstr); + if (!hwaddr_aton(alstr, he.aladdr)) { + dbg("Invalid alid in history!\n"); + return -1; + } + json_object_object_get_ex(je, "stats", &je_ws); json_get_key_value(je_ws, "tx_packets", &he.ws.ul_packets); json_get_key_value(je_ws, "tx_bytes", &he.ws.ul_bytes); @@ -198,6 +214,8 @@ int neigh_history_load_from_json_file(void *priv, const char *file) he.lastseen = lastseen; he.timeout = timeout; he.is1905 = is1905; + he.is1905_slave = is1905_slave; + he.is1905_link = is1905_link; he.type = type; dbg("macstr = '%s' (macaddr = " MACFMT" )\n", macstr, MAC2STR(he.macaddr)); @@ -209,6 +227,9 @@ int neigh_history_load_from_json_file(void *priv, const char *file) dbg("remtime = %u\n", he.timeout); dbg("mediatype = %d\n", he.type); dbg("is1905 = %d\n", he.is1905); + dbg("is1905_interface = %d\n", he.is1905_slave); + dbg("is1905_link = %d\n", he.is1905_link); + dbg("ieee1905id = '%s' (macaddr = " MACFMT" )\n", alstr, MAC2STR(he.aladdr)); dbg("tx-packets = %ju\n", (uintmax_t)he.ws.ul_packets); dbg("tx-bytes = %ju\n", (uintmax_t)he.ws.ul_bytes); dbg("rx-packets = %ju\n", (uintmax_t)he.ws.dl_packets); diff --git a/src/neigh.c b/src/neigh.c index ac6176e6c7f4a046588b9e9a56f3358674f4878c..50ff7de7ff674a1af732463269f09baae110fcfe 100644 --- a/src/neigh.c +++ b/src/neigh.c @@ -194,6 +194,9 @@ int neigh_history_enqueue(void *priv, struct neigh_entry *n, uint32_t timeout) } he->is1905 = n->is1905; + he->is1905_slave = n->is1905_slave; + he->is1905_link = n->is1905_link; + memcpy(he->aladdr, n->aladdr, 6); he->lastchange = n->lastchange; dbg("Update history stats: +ul-pkts = %ju, +dl-pkts = %ju\n", @@ -222,6 +225,9 @@ int neigh_history_enqueue(void *priv, struct neigh_entry *n, uint32_t timeout) } he->is1905 = n->is1905; + he->is1905_slave = n->is1905_slave; + he->is1905_link = n->is1905_link; + memcpy(he->aladdr, n->aladdr, 6); he->lastchange = n->lastchange; /* stop ageing history as neigh is live */ @@ -272,6 +278,9 @@ int neigh_history_entry_add(void *priv, struct neigh_history_entry *he) strncpy(e->ifname, he->ifname, 16); e->lastchange = he->lastchange; e->is1905 = he->is1905; + e->is1905_slave = he->is1905_slave; + e->is1905_link = he->is1905_link; + memcpy(e->aladdr, he->aladdr, 6); e->ws.ul_packets = he->ws.ul_packets; e->ws.ul_bytes = he->ws.ul_bytes; @@ -380,6 +389,9 @@ static void neigh_entry_delete(struct neigh_entry *e) he->state = e->state; he->type = e->type; he->is1905 = e->is1905; + he->is1905_slave = e->is1905_slave; + he->is1905_link = e->is1905_link; + memcpy(he->aladdr, e->aladdr, 6); he->lastchange = e->lastchange; memcpy(&he->ip, &e->ipv4, sizeof(struct ip_address)); if (e->ifname[0] != '\0') { @@ -823,12 +835,13 @@ int neigh_set_1905(void *nq, uint8_t *macaddr, uint8_t val) if (!e) return -1; + memcpy(e->aladdr, macaddr, 6); e->is1905 = !!val; return 0; } -int neigh_set_1905_slave(void *nq, uint8_t *macaddr, uint8_t val) +int neigh_set_1905_slave(void *nq, uint8_t *macaddr, uint8_t *aladdr, uint8_t val) { struct neigh_entry *e = NULL; @@ -837,11 +850,30 @@ int neigh_set_1905_slave(void *nq, uint8_t *macaddr, uint8_t val) if (!e) return -1; + if (aladdr) + memcpy(e->aladdr, aladdr, 6); + e->is1905_slave = !!val; return 0; } +int neigh_set_1905_link(void *nq, uint8_t *macaddr, uint8_t *aladdr, uint8_t val) +{ + struct neigh_entry *e = NULL; + + + e = neigh_lookup(nq, macaddr); + if (!e) + return -1; + + if (aladdr) + memcpy(e->aladdr, aladdr, 6); + e->is1905_link = !!val; + + return 0; +} + bool is_neigh_1905(void *nq, uint8_t *macaddr) { struct neigh_entry *e = NULL; diff --git a/src/neigh.h b/src/neigh.h index 43785c2fa9b51527763949abe1cbae60358dba34..3d85427a117a02043bc3ddecd9a83d60a253afd3 100644 --- a/src/neigh.h +++ b/src/neigh.h @@ -66,6 +66,8 @@ struct neigh_entry { enum neigh_type type; uint8_t is1905; uint8_t is1905_slave; /* member interface of 1905 device */ + uint8_t is1905_link; /* 1905 interface forming link with nbr */ + uint8_t aladdr[6]; void *cookie; char hostname[256]; struct ip_address ipv4; /* from dhcp-lease table or neigh cache */ @@ -99,6 +101,9 @@ struct neigh_history_entry { uint16_t state; bool alive; uint8_t is1905; + uint8_t is1905_slave; + uint8_t is1905_link; + uint8_t aladdr[6]; uint8_t macaddr[6]; char hostname[256]; char ifname[16]; @@ -171,7 +176,8 @@ void neigh_mark_reachable(void *nq, uint8_t *macaddr, const char *ifname); int neigh_set_type(void *q, uint8_t *macaddr, enum neigh_type type); uint16_t neigh_get_brport(void *q, uint8_t *macaddr); int neigh_set_1905(void *q, uint8_t *macaddr, uint8_t val); -int neigh_set_1905_slave(void *q, uint8_t *macaddr, uint8_t val); +int neigh_set_1905_slave(void *nq, uint8_t *macaddr, uint8_t *aladdr, uint8_t val); +int neigh_set_1905_link(void *nq, uint8_t *macaddr, uint8_t *aladdr, uint8_t val); bool is_neigh_1905(void *q, uint8_t *macaddr); bool is_neigh_1905_slave(void *q, uint8_t *macaddr); diff --git a/src/ubus.c b/src/ubus.c index a5e6a13955bcb86cb205996b79651fdf7f3eeb10..fb72b4f3402d665102884645cfa79b44fef21b04 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -247,7 +247,7 @@ static void hostmngr_1905topology_cb(struct ubus_request *req, int type, return; } - neigh_set_1905_slave(&priv->neigh_q, if_macaddr, 1); + neigh_set_1905_slave(&priv->neigh_q, if_macaddr, node_aladdr, 1); dbg("%s: Interface " MACFMT "\n", __func__, MAC2STR(if_macaddr)); iter++; } @@ -283,8 +283,7 @@ static void hostmngr_1905topology_cb(struct ubus_request *req, int type, return; } - neigh_set_1905_slave(&priv->neigh_q, if_macaddr, 0); - neigh_set_1905(&priv->neigh_q, if_macaddr, 1); + neigh_set_1905_link(&priv->neigh_q, if_macaddr, node_aladdr, 1); dbg("%s: Interface " MACFMT "\n", __func__, MAC2STR(if_macaddr)); iter++; } @@ -568,7 +567,8 @@ int hostmngr_ubus_show_arptable(struct ubus_context *ctx, struct ubus_object *ob hwaddr_ntoa(e->macaddr, macstr); blobmsg_add_string(&bb, "macaddr", macstr); blobmsg_add_u8(&bb, "is1905", e->is1905 ? true : false); - blobmsg_add_u8(&bb, "is1905_slave", e->is1905_slave ? true : false); + blobmsg_add_u8(&bb, "is1905_interface", e->is1905_slave ? true : false); + blobmsg_add_u8(&bb, "is1905_link", e->is1905_link ? true : false); blobmsg_add_u32(&bb, "ndm_state", e->state); brport = neigh_get_brport(q, e->macaddr); @@ -615,6 +615,7 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, char statestr[128] = {0}; char ipstr[128] = {0}; char *ifname = NULL; + char alstr[18] = {0}; char tbuf[64] = {0}; long leasetime_rem; char *net = NULL; @@ -625,7 +626,7 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, //if (e->unreachable) // continue; - if (e->is1905_slave) + if (e->is1905 || (e->is1905_slave && !e->is1905_link)) continue; neigh_update_ip_entry_stats(p, &e->ipv4, e); @@ -651,7 +652,14 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_string(&bb, "address_source", e->ipv4_type_dhcp ? "DHCP": "Static"); blobmsg_add_u32(&bb, "lease_time_remaining", leasetime_rem); blobmsg_add_string(&bb, "interface_type", interface_type2str(e->type)); - blobmsg_add_u8(&bb, "is1905", e->is1905 ? true : false); + if (e->is1905_link) { + blobmsg_add_u8(&bb, "is1905", true); + hwaddr_ntoa(e->aladdr, alstr); + blobmsg_add_string(&bb, "ieee1905id", alstr); + } else { + blobmsg_add_u8(&bb, "is1905", false); + } + blobmsg_add_string(&bb, "link_macaddr", ""); //TODO rtnl_neigh_state2str(e->state, statestr, sizeof(statestr)); blobmsg_add_string(&bb, "ndm_state", statestr); @@ -717,6 +725,7 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, hlist_for_each_entry(he, &q->history[i], hlist) { struct ip_address_entry *ipv4, *ipv6; char ipstr[128] = {0}; + char alstr[18] = {0}; char tbuf[64] = {0}; char *net = NULL; struct tm *t; @@ -726,6 +735,9 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, if (he->alive) continue; + if (he->is1905 || (he->is1905_slave && !he->is1905_link)) + continue; + aa = blobmsg_open_table(&bb, ""); hwaddr_ntoa(he->macaddr, macstr); blobmsg_add_string(&bb, "macaddr", macstr); @@ -743,7 +755,13 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_string(&bb, "address_source", he->ipv4_type_dhcp ? "DHCP": "Static"); blobmsg_add_u32(&bb, "lease_time_remaining", 0); blobmsg_add_string(&bb, "interface_type", interface_type2str(he->type)); - blobmsg_add_u8(&bb, "is1905", he->is1905 ? true : false); + if (he->is1905_link) { + blobmsg_add_u8(&bb, "is1905", true); + hwaddr_ntoa(he->aladdr, alstr); + blobmsg_add_string(&bb, "ieee1905id", alstr); + } else { + blobmsg_add_u8(&bb, "is1905", false); + } blobmsg_add_string(&bb, "link_macaddr", ""); //TODO blobmsg_add_string(&bb, "ndm_state", "Unknown"); blobmsg_add_u32(&bb, "num_tcp", 0); @@ -848,6 +866,14 @@ int hostmngr_ubus_show_history(struct ubus_context *ctx, struct ubus_object *obj blobmsg_add_u8(&bb, "alive", e->alive ? true : false); blobmsg_add_string(&bb, "interface_type", interface_type2str(e->type)); blobmsg_add_u8(&bb, "is1905", e->is1905 ? true : false); + blobmsg_add_u8(&bb, "is1905_interface", e->is1905_slave ? true : false); + blobmsg_add_u8(&bb, "is1905_link", e->is1905_link ? true : false); + if (e->is1905_link) { + char alstr[18] = {0}; + + hwaddr_ntoa(e->aladdr, alstr); + blobmsg_add_string(&bb, "ieee1905id", alstr); + } wt = blobmsg_open_table(&bb, "stats"); blobmsg_add_u64(&bb, "tx_packets", e->ws.ul_packets);