From 8e0373314c7d42f674d47408e4ab71eb6cf48232 Mon Sep 17 00:00:00 2001 From: Pat Ruddy Date: Fri, 18 Sep 2020 10:05:54 +0100 Subject: [PATCH] lib: add utility to count interfaces connected to a vrf Run through the vrf's interface list and return a count, skipping the l3mdev which has a name which matches the vrf name. Signed-off-by: Pat Ruddy --- lib/vrf.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/vrf.h b/lib/vrf.h index c636b9ea7e..430217760d 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -167,6 +167,20 @@ static inline void vrf_reset_user_cfged(struct vrf *vrf) UNSET_FLAG(vrf->status, VRF_CONFIGURED); } +static inline uint32_t vrf_interface_count(struct vrf *vrf) +{ + uint32_t count = 0; + struct interface *ifp; + + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { + /* skip the l3mdev */ + if (strncmp(ifp->name, vrf->name, VRF_NAMSIZ) == 0) + continue; + count++; + } + return count; +} + /* * Utilities to obtain the user data */ -- 2.39.5