From 1e500ec09ff8c94fea6d5da76acd6bdbf56f0418 Mon Sep 17 00:00:00 2001 From: Pat Ruddy Date: Fri, 18 Sep 2020 10:12:08 +0100 Subject: [PATCH] bgpd: add utility to check if a vrf is active From RFC4382: A VRF is up(1) when there is at least one interface associated with the VRF whose ifOperStatus is up(1). A VRF is down(2) when: a. There does not exist at least one interface whose ifOperStatus is up(1). b. There are no interfaces associated with the VRF. Run through interfaces associated with a vrf and return true if there is one in the up state. Signed-off-by: Pat Ruddy --- bgpd/bgpd.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 9089608062..65c7233e03 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -2165,6 +2165,23 @@ static inline int afindex(afi_t afi, safi_t safi) } } +static inline bool is_bgp_vrf_active(struct bgp *bgp) +{ + struct vrf *vrf; + struct interface *ifp; + + /* if there is one interface in the vrf which is up then it is deemed + * active + */ + vrf = vrf_lookup_by_name(bgp->name); + if (vrf == NULL) + return false; + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) + if (if_is_up(ifp)) + return true; + return false; +} + /* If the peer is not a peer-group but is bound to a peer-group return 1 */ static inline int peer_group_active(struct peer *peer) { -- 2.39.5