From 9467957d5cd430808c1a51febc0efdfce0e7eb9c Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 7 Jun 2023 13:42:23 +0200 Subject: [PATCH] lib: fix next vrf interface lookup avoid loopback interface When the default vrf is submitted, the returned interface may be the loopback interface, which may not be valid. Actually, on vrfs, the vrf interface is bypassed. When being on default vrf, the 'lo' interface should be bypassed too. Fix this by avoiding returning the lo interface too. Fixes: 0760a74d2fc2 ("lib: add utility to get the next index in a vrf") Signed-off-by: Philippe Guibert --- lib/if.c | 8 ++++---- lib/vrf.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/if.c b/lib/if.c index 378ca16e4957..ad49c45b2b48 100644 --- a/lib/if.c +++ b/lib/if.c @@ -325,8 +325,8 @@ struct interface *if_vrf_lookup_by_index_next(ifindex_t ifindex, if (ifindex == 0) { tmp_ifp = RB_MIN(if_index_head, &vrf->ifaces_by_index); - /* skip the vrf interface */ - if (tmp_ifp && if_is_vrf(tmp_ifp)) + /* skip the vrf interface or the lo interface */ + if (tmp_ifp && if_is_loopback(tmp_ifp)) ifindex = tmp_ifp->ifindex; else return tmp_ifp; @@ -334,8 +334,8 @@ struct interface *if_vrf_lookup_by_index_next(ifindex_t ifindex, RB_FOREACH (tmp_ifp, if_index_head, &vrf->ifaces_by_index) { if (found) { - /* skip the vrf interface */ - if (tmp_ifp && if_is_vrf(tmp_ifp)) + /* skip the vrf interface or the lo interface */ + if (tmp_ifp && if_is_loopback(tmp_ifp)) continue; else return tmp_ifp; diff --git a/lib/vrf.h b/lib/vrf.h index 3ebb6ddf5371..eb72c048375c 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -149,6 +149,9 @@ static inline uint32_t vrf_interface_count(struct vrf *vrf) struct interface *ifp; RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { + /* skip the lo interface */ + if (if_is_loopback_exact(ifp)) + continue; /* skip the l3mdev */ if (strncmp(ifp->name, vrf->name, VRF_NAMSIZ) == 0) continue;