From ac30c3be85d8cf0ffedc3083b1c810bc42f4e41b Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakob.olsson@iopsys.eu>
Date: Tue, 12 Dec 2023 10:34:51 +0100
Subject: [PATCH] defer hosts event if hostname is not found

---
 src/neigh.c   | 2 +-
 src/netlink.c | 2 +-
 src/ubus.c    | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/neigh.c b/src/neigh.c
index cc99ae2..9560dd7 100644
--- a/src/neigh.c
+++ b/src/neigh.c
@@ -1103,7 +1103,7 @@ void hostmngr_get_wifi_stations(struct hostmngr_private *priv,
 			neigh_history_enqueue(priv, new,
 					      priv->cfg.history_ageout);
 
-			if (!ipaddr_is_zero(&new->ipv4))
+			if (!ipaddr_is_zero(&new->ipv4) && (!new->ipv4_type_dhcp || strlen(new->hostname)))
 				hostmngr_host_event(priv, HOST_EVENT_CONNECT, new);
 			else
 				new->event_pending = 1;
diff --git a/src/netlink.c b/src/netlink.c
index 42d8e15..c7cc29e 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -202,7 +202,7 @@ static int hostmngr_handle_neigh_tbl_change(struct hostmngr_private *priv, bool
 			return 0;
 		}
 
-		if (e->event_pending && !ipaddr_is_zero(&e->ipv4)) {
+		if (e->event_pending && !ipaddr_is_zero(&e->ipv4) && strlen(e->hostname)) {
 			e->event_pending = 0;
 			hostmngr_host_event(priv, HOST_EVENT_CONNECT, e);
 		}
diff --git a/src/ubus.c b/src/ubus.c
index 66095e3..359b810 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -426,7 +426,7 @@ static void hostmngr_1905topology_cb(struct ubus_request *req, int type,
 						neigh_history_enqueue(priv, rn,
 								      priv->cfg.history_ageout);
 
-						if (!ipaddr_is_zero(&rn->ipv4))
+						if (!ipaddr_is_zero(&rn->ipv4) && (!rn->ipv4_type_dhcp || strlen(rn->hostname)))
 							hostmngr_host_event(priv, HOST_EVENT_CONNECT, rn);
 						else
 							rn->event_pending = 1;
@@ -1282,7 +1282,7 @@ static void hostmngr_wifi_sta_event_handler(struct hostmngr_private *p,
 				neigh_history_enqueue(p, new,
 						      p->cfg.history_ageout);
 
-				if (!ipaddr_is_zero(&new->ipv4))
+				if (!ipaddr_is_zero(&new->ipv4) && (!new->ipv4_type_dhcp || strlen(new->hostname)))
 					hostmngr_host_event(p, HOST_EVENT_CONNECT, new);
 				else
 					new->event_pending = 1;
-- 
GitLab