From f6458d2612fafcf8592373383680fdc7ad226d80 Mon Sep 17 00:00:00 2001
From: Anjan Chanda <anjan.chanda@iopsys.eu>
Date: Thu, 23 Nov 2023 14:20:57 +0100
Subject: [PATCH] fix remote host's mediatype

---
 src/neigh.c |  1 -
 src/neigh.h |  1 +
 src/ubus.c  | 21 +++++++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/neigh.c b/src/neigh.c
index dcd70e8..f72048f 100644
--- a/src/neigh.c
+++ b/src/neigh.c
@@ -634,7 +634,6 @@ struct neigh_entry *neigh_lookup_by_ipaddr(void *priv, struct ip_address *ip)
 	return NULL;
 }
 
-
 struct neigh_entry *neigh_lookup_by_aladdr(void *priv, uint8_t *aladdr)
 {
 	struct hostmngr_private *p = (struct hostmngr_private *)priv;
diff --git a/src/neigh.h b/src/neigh.h
index 4718b0c..79517bc 100644
--- a/src/neigh.h
+++ b/src/neigh.h
@@ -64,6 +64,7 @@ struct neigh_entry {
 	char ifname[16];
 	uint16_t brport;		/* valid when 'ifname' is bridge type */
 	enum neigh_type type;
+	uint8_t isremote;		/* true when connected behind extender */
 	uint8_t is1905;
 	uint8_t is1905_slave;		/* member interface of 1905 device */
 	uint8_t is1905_link;		/* 1905 interface forming link with nbr */
diff --git a/src/ubus.c b/src/ubus.c
index 0207e1a..501ecfe 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -387,6 +387,26 @@ static void hostmngr_1905topology_cb(struct ubus_request *req, int type,
 				return;
 			}
 
+			/* appropriately set neigh-type of non-local hosts */
+			if (memcmp(node_aladdr, priv->ieee1905id, 6)) {
+				struct neigh_entry *rn = NULL;
+
+				rn = neigh_lookup(&priv->neigh_q, xbr_macaddr);
+				if (rn) {
+					rn->isremote = 1;
+					n = neigh_lookup_by_aladdr(priv, node_aladdr);
+					if (n) {
+						struct node_interface *nif = NULL;
+
+						list_for_each_entry(nif, &rn->iflist, list) {
+							if (!memcmp(nif->macaddr, xbr_viaaddr, 6) &&
+							    nif->mediatype == IF_MEDIA_WIFI)
+								rn->type =NEIGH_TYPE_WIFI;
+						}
+					}
+				}
+			}
+
 			dbg("%s: Xbr " MACFMT "\n", __func__, MAC2STR(xbr_macaddr));
 			dbg("%s: Xif " MACFMT "\n", __func__, MAC2STR(xbr_viaaddr));
 			iter++;
@@ -704,6 +724,7 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj,
 			blobmsg_add_string(&bb, "macaddr", macstr);
 			blobmsg_add_string(&bb, "hostname", e->hostname);
 			blobmsg_add_u8(&bb, "active", e->unreachable ? false : true);
+			blobmsg_add_u8(&bb, "local", e->isremote ? false : true);
 
 			t = gmtime(&e->lastchange);
 			strftime(tbuf, sizeof(tbuf), "%Y-%m-%dT%H:%M:%SZ", t);
-- 
GitLab