Browse Source

bgp: ignore NHT when bgpd has never connected zebra

Lou Berger 2 years ago
parent
commit
68bfb6190e
3 changed files with 15 additions and 1 deletions
  1. 2 1
      bgpd/bgp_nht.c
  2. 11 0
      bgpd/bgp_zebra.c
  3. 2 0
      bgpd/bgp_zebra.h

+ 2 - 1
bgpd/bgp_nht.c

@@ -62,7 +62,8 @@ bgp_find_nexthop (struct bgp_info *path, int connected)
   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

+ 11 - 0
bgpd/bgp_zebra.c

@@ -50,6 +50,8 @@ struct in_addr router_id_zebra;
 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 @@ bgp_zclient_reset (void)
 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 @@ bgp_zebra_destroy(void)
   zclient_free(zclient);
   zclient = NULL;
 }
+
+int
+bgp_zebra_num_connects(void)
+{
+  return zclient_num_connects;
+}

+ 2 - 0
bgpd/bgp_zebra.h

@@ -48,4 +48,6 @@ extern struct interface *if_lookup_by_ipv4_exact (struct in_addr *);
 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 */