From afbb1c59a3b4dbbe41b1869642b31e39fb0136d2 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Fri, 7 Oct 2016 09:44:42 -0400 Subject: [PATCH] bgp: ignore NHT when bgpd has never connected to zebra --- bgpd/bgp_nht.c | 4 +++- bgpd/bgp_zebra.c | 12 ++++++++++++ bgpd/bgp_zebra.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index ef70d0e4f9..d1f7fe341e 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -41,6 +41,7 @@ #include "bgpd/bgp_debug.h" #include "bgpd/bgp_nht.h" #include "bgpd/bgp_fsm.h" +#include "bgpd/bgp_zebra.h" extern struct zclient *zclient; @@ -234,7 +235,8 @@ bgp_find_or_add_nexthop (struct bgp *bgp, afi_t afi, struct bgp_info *ri, else if (peer) bnc->nht_info = (void *)peer; - return (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID)); + return (bgp_zebra_num_connects() == 0 || + CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID)); } void diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 789dba53f8..11e888d7e9 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -109,6 +109,8 @@ bgp_install_info_to_zebra (struct bgp *bgp) return 1; } +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, @@ -2087,6 +2089,8 @@ bgp_zebra_connected (struct zclient *zclient) { struct bgp *bgp; + zclient_num_connects++; /* increment even if not responding */ + /* At this point, we may or may not have BGP instances configured, but * we're only interested in the default VRF (others wouldn't have learnt * the VRF from Zebra yet.) @@ -2109,6 +2113,8 @@ bgp_zebra_connected (struct zclient *zclient) 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, 0); @@ -2143,3 +2149,9 @@ bgp_zebra_destroy(void) 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 af921af82f..24b4634eb6 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -62,4 +62,6 @@ extern struct interface *if_lookup_by_ipv6 (struct in6_addr *, ifindex_t, vrf_id extern struct interface *if_lookup_by_ipv6_exact (struct in6_addr *, ifindex_t, vrf_id_t); #endif /* HAVE_IPV6 */ +extern int bgp_zebra_num_connects(void); + #endif /* _QUAGGA_BGP_ZEBRA_H */ -- 2.39.5