From 2fc3f46143dcf11def3a5bd00a37e5b278c68516 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 621f5e9..96662c5 100644
--- a/src/neigh.c
+++ b/src/neigh.c
@@ -1101,7 +1101,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 d0fe8d1..3190deb 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 48e26dc..69faa07 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -429,7 +429,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;
@@ -1285,7 +1285,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