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 <pat@voltanet.io>
This commit is contained in:
Pat Ruddy 2020-09-18 10:12:08 +01:00
parent 8e0373314c
commit 1e500ec09f

View File

@ -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)
{