bgpd, zebra: Use next hop tracking for connected routes too

Allow next hop tracking to work with connected routes
And cleanup obsolete code in bgp_scan and bgp_import.

Signed-off-by: Dinesh Dutt <ddutt@cumulusnetworks.com>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Edits: Paul Jakma <paul.jakma@hpe.com> Rebase re-ordering conflicts with
       NHT route-map, potential errors.
diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c
index 02a1468..7b6d0f8 100644
--- a/zebra/zebra_rnh.c
+++ b/zebra/zebra_rnh.c
@@ -212,7 +212,8 @@
     {
       if (!nrn->info)
 	  continue;
-
+      
+      rnh = nrn->info;
       prn = route_node_match(ptable, &nrn->p);
       if (!prn)
 	rib = NULL;
@@ -223,11 +224,18 @@
 	      if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED))
 		continue;
 	      if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
-		break;
+		{
+		  if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
+		    {
+		      if (rib->type == ZEBRA_ROUTE_CONNECT)
+			break;
+		    }
+		  else
+		    break;
+		}
 	    }
 	}
 
-      rnh = nrn->info;
       if (compare_state(rib, rnh->state))
 	{
 	  if (IS_ZEBRA_DEBUG_NHT)
@@ -598,7 +606,9 @@
 	print_nh(nexthop, vty);
     }
   else
-    vty_out(vty, " unresolved%s", VTY_NEWLINE);
+    vty_out(vty, " unresolved%s%s",
+	    CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED) ? "(Connected)" : "",
+	    VTY_NEWLINE);
 
   vty_out(vty, " Client list:");
   for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client))
diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h
index 97dbba7..574c95f 100644
--- a/zebra/zebra_rnh.h
+++ b/zebra/zebra_rnh.h
@@ -30,6 +30,7 @@
 struct rnh
 {
   u_char flags;
+#define ZEBRA_NHT_CONNECTED  	0x1
   struct rib *state;
   struct list *client_list;
   struct route_node *node;
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 4a8b55f..f0e8d12 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -748,6 +748,7 @@
   struct stream *s;
   struct prefix p;
   u_short l = 0;
+  u_char connected;
 
   if (IS_ZEBRA_DEBUG_NHT)
     zlog_debug("nexthop_register msg from client %s: length=%d\n",
@@ -757,14 +758,19 @@
 
   while (l < length)
     {
+      connected = stream_getc(s);
       p.family = stream_getw(s);
       p.prefixlen = stream_getc(s);
-      l += 3;
+      l += 4;
       stream_get(&p.u.prefix, s, PSIZE(p.prefixlen));
       l += PSIZE(p.prefixlen);
       rnh = zebra_add_rnh(&p, 0);
 
       client->nh_reg_time = quagga_time(NULL);
+      
+      if (connected)
+	SET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
+
       zebra_add_rnh_client(rnh, client, vrf_id);
     }
   zebra_evaluate_rnh_table(0, AF_INET);
@@ -789,9 +795,10 @@
 
   while (l < length)
     {
+      (void)stream_getc(s);
       p.family = stream_getw(s);
       p.prefixlen = stream_getc(s);
-      l += 3;
+      l += 4;
       stream_get(&p.u.prefix, s, PSIZE(p.prefixlen));
       l += PSIZE(p.prefixlen);
       rnh = zebra_lookup_rnh(&p, 0);