Merge "[qca-nss-clients] Check neigh entry state"
diff --git a/gre/nss_connmgr_gre_v4.c b/gre/nss_connmgr_gre_v4.c
index 5383604..b5a02c7 100644
--- a/gre/nss_connmgr_gre_v4.c
+++ b/gre/nss_connmgr_gre_v4.c
@@ -98,9 +98,12 @@
 		neigh = neigh_lookup(&arp_tbl, (const void *)&raddr,  rt->dst.dev);
 	}
 
-	if (neigh && !is_valid_ether_addr(neigh->ha)) {
-		neigh_release(neigh);
-		neigh = NULL;
+	if (neigh) {
+		if (!(neigh->nud_state & NUD_VALID) || !is_valid_ether_addr(neigh->ha)) {
+			nss_connmgr_gre_info("neigh lookup failed for %pI4, state=%x, neigh->ha=%pM\n", &raddr, neigh->nud_state, neigh->ha);
+			neigh_release(neigh);
+			neigh = NULL;
+		}
 	}
 
 	/*
@@ -119,6 +122,13 @@
 		msleep(2000);
 	}
 
+	if (!(neigh->nud_state & NUD_VALID) || !is_valid_ether_addr(neigh->ha)) {
+		ip_rt_put(rt);
+		neigh_release(neigh);
+		nss_connmgr_gre_warning("invalid neigh state (%x) or invalid MAC(%pM) for %pI4\n", neigh->nud_state, neigh->ha,  &raddr);
+		return GRE_ERR_NEIGH_CREATE;
+	}
+
 	if (neigh->dev->type == ARPHRD_LOOPBACK) {
 		ip_rt_put(rt);
 		neigh_release(neigh);
diff --git a/gre/nss_connmgr_gre_v6.c b/gre/nss_connmgr_gre_v6.c
index 9b45fa0..eb82663 100644
--- a/gre/nss_connmgr_gre_v6.c
+++ b/gre/nss_connmgr_gre_v6.c
@@ -118,9 +118,12 @@
 #else
 	neigh = rt->dst.ops->neigh_lookup(&rt->dst, NULL, &dst_addr);
 #endif
-	if (neigh && !is_valid_ether_addr(neigh->ha)) {
-		neigh_release(neigh);
-		neigh = NULL;
+	if (neigh) {
+		if (!(neigh->nud_state & NUD_VALID) || !is_valid_ether_addr(neigh->ha)) {
+			nss_connmgr_gre_warning("neigh state is either invalid (%x) or mac address is null (%pM) for %pI6", neigh->nud_state, neigh->ha, dest_ip);
+			neigh_release(neigh);
+			neigh = NULL;
+		}
 	}
 
 	if (!neigh) {
@@ -152,11 +155,19 @@
 #else
 		neigh = rt->dst.ops->neigh_lookup(&rt->dst, NULL, &dst_addr);
 #endif
-		if (!neigh || !is_valid_ether_addr(neigh->ha)) {
+
+		if (!neigh) {
 			ip6_rt_put(rt);
 			nss_connmgr_gre_warning("Err in MAC address, neighbour look up failed\n");
 			return GRE_ERR_NEIGH_LOOKUP;
 		}
+
+		if (!(neigh->nud_state & NUD_VALID) || !is_valid_ether_addr(neigh->ha)) {
+			ip6_rt_put(rt);
+			nss_connmgr_gre_warning("Err in MAC address, invalid neigh state (%x) or invalid mac(%pM)\n", neigh->nud_state, neigh->ha);
+			neigh_release(neigh);
+			return GRE_ERR_NEIGH_LOOKUP;
+		}
 	}
 
 	ether_addr_copy(dest_mac, neigh->ha);