From 7c33d9d2f226c96808a108b36ea5a9097992116f Mon Sep 17 00:00:00 2001
From: Rahul Thakur <rahul.thakur@iopsys.eu>
Date: Wed, 20 Mar 2024 12:34:07 +0530
Subject: [PATCH] ubus: update host active criteria

update the criteria to mark host as active to be based on ndm_state
as I think this is a better reflection of the state and also covers
both link lost and host down scenario
---
 src/ubus.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ubus.c b/src/ubus.c
index 6a5bfd0..1ac4266 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -753,7 +753,6 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj,
 			hwaddr_ntoa(e->macaddr, macstr);
 			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);
@@ -789,6 +788,12 @@ int hostmngr_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj,
 
 			rtnl_neigh_state2str(e->state, statestr, sizeof(statestr));
 			blobmsg_add_string(&bb, "ndm_state", statestr);
+
+			if (!strcmp(statestr, "reachable"))
+				blobmsg_add_u8(&bb, "active", true);
+			else
+				blobmsg_add_u8(&bb, "active", false);
+
 			blobmsg_add_u32(&bb, "num_tcp", e->num_tcp);
 			blobmsg_add_u32(&bb, "num_udp", e->num_udp);
 			blobmsg_add_u64(&bb, "active_connections", e->num_tcp + e->num_udp);
-- 
GitLab