]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Make if_lookup_by_index understand if VRF is backed by netns or not
authorDinesh G Dutt <5016467+ddutt@users.noreply.github.com>
Mon, 26 Aug 2019 12:38:28 +0000 (12:38 +0000)
committerDinesh G Dutt <5016467+ddutt@users.noreply.github.com>
Mon, 26 Aug 2019 12:38:28 +0000 (12:38 +0000)
FRR has two implementations of VRF, one backed by netns and the other by
the proper VRF implementation in the Linux kernel. In certain places, the
code assumes that a VRF is netns and so lookups fail. One example of this
is in IPv6 RA code. This causes functionality such as Unnumbered BGP to
fail. To fix this, this patch makes if_lookup_by_index handle the
behavior based on the backend, similar to if_get_by_index. For the two
places in if.c that were calling if_lookup_by_index to be specific to
the VRF, I renamed the existing code, if_lookup_by_ifindex and made it a
static function that is never exposed or called by any routine outside of
if.c.

Signed-off-by: Dinesh G Dutt <5016467+ddutt@users.noreply.github.com>
lib/if.c

index 9ee2f02e624785b73f249e967a0abccc72f30195..ea83418e9125bd357ed61fa3ca8444e83591a035 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -45,6 +45,8 @@ DEFINE_MTYPE_STATIC(LIB, NBR_CONNECTED, "Neighbor Connected")
 DEFINE_MTYPE(LIB, CONNECTED_LABEL, "Connected interface label")
 DEFINE_MTYPE_STATIC(LIB, IF_LINK_PARAMS, "Informational Link Parameters")
 
+static struct interface *if_lookup_by_ifindex(ifindex_t ifindex,
+                                             vrf_id_t vrf_id);
 static int if_cmp_func(const struct interface *, const struct interface *);
 static int if_cmp_index_func(const struct interface *ifp1,
                             const struct interface *ifp2);
@@ -257,8 +259,9 @@ void if_delete(struct interface *ifp)
        XFREE(MTYPE_IF, ifp);
 }
 
-/* Interface existance check by index. */
-struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
+/* Used only internally to check within VRF only */
+static struct interface *if_lookup_by_ifindex(ifindex_t ifindex,
+                                             vrf_id_t vrf_id)
 {
        struct vrf *vrf;
        struct interface if_tmp;
@@ -271,6 +274,19 @@ struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
        return RB_FIND(if_index_head, &vrf->ifaces_by_index, &if_tmp);
 }
 
+/* Interface existance check by index. */
+struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
+{
+       switch (vrf_get_backend()) {
+       case VRF_BACKEND_UNKNOWN:
+       case VRF_BACKEND_NETNS:
+               return(if_lookup_by_ifindex(ifindex, vrf_id));
+       case VRF_BACKEND_VRF_LITE:
+               return(if_lookup_by_index_all_vrf(ifindex));
+       }
+       return NULL;
+}
+
 const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id)
 {
        struct interface *ifp;
@@ -329,7 +345,7 @@ struct interface *if_lookup_by_index_all_vrf(ifindex_t ifindex)
                return NULL;
 
        RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
-               ifp = if_lookup_by_index(ifindex, vrf->vrf_id);
+               ifp = if_lookup_by_ifindex(ifindex, vrf->vrf_id);
                if (ifp)
                        return ifp;
        }
@@ -489,7 +505,7 @@ struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id)
        switch (vrf_get_backend()) {
        case VRF_BACKEND_UNKNOWN:
        case VRF_BACKEND_NETNS:
-               ifp = if_lookup_by_index(ifindex, vrf_id);
+               ifp = if_lookup_by_ifindex(ifindex, vrf_id);
                if (ifp)
                        return ifp;
                return if_create_ifindex(ifindex, vrf_id);