bgp: ignore NHT when bgpd has never connected zebra
diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c
index 50f14ce..0cfcadd 100644
--- a/bgpd/bgp_nht.c
+++ b/bgpd/bgp_nht.c
@@ -62,7 +62,8 @@
if (connected && !(CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED)))
return 0;
- return (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID));
+ return (bgp_zebra_num_connects() == 0 ||
+ CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID));
}
static void
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 38fecd9..45d502a 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -50,6 +50,8 @@
struct stream *bgp_nexthop_buf = NULL;
struct stream *bgp_ifindices_buf = NULL;
+int zclient_num_connects;
+
/* Router-id update message from zebra. */
static int
bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length,
@@ -1171,12 +1173,15 @@
static void
bgp_zebra_connected (struct zclient *zclient)
{
+ zclient_num_connects++;
zclient_send_requests (zclient, VRF_DEFAULT);
}
void
bgp_zebra_init (struct thread_master *master)
{
+ zclient_num_connects = 0;
+
/* Set default values. */
zclient = zclient_new (master);
zclient_init (zclient, ZEBRA_ROUTE_BGP);
@@ -1207,3 +1212,9 @@
zclient_free(zclient);
zclient = NULL;
}
+
+int
+bgp_zebra_num_connects(void)
+{
+ return zclient_num_connects;
+}
diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h
index 9a592c3..5d4ed62 100644
--- a/bgpd/bgp_zebra.h
+++ b/bgpd/bgp_zebra.h
@@ -48,4 +48,6 @@
extern struct interface *if_lookup_by_ipv6 (struct in6_addr *);
extern struct interface *if_lookup_by_ipv6_exact (struct in6_addr *);
+extern int bgp_zebra_num_connects(void);
+
#endif /* _QUAGGA_BGP_ZEBRA_H */