summaryrefslogtreecommitdiffstats
path: root/lib/if.c
diff options
context:
space:
mode:
authorDinesh G Dutt <5016467+ddutt@users.noreply.github.com>2019-08-26 14:38:28 +0200
committerDinesh G Dutt <5016467+ddutt@users.noreply.github.com>2019-08-26 14:38:28 +0200
commit47b474b57e8ea740e7adf1438ccaae8c93553385 (patch)
treedd95ce4bc025086156f903510c0cba2ebb5e3604 /lib/if.c
parentMerge pull request #4821 from vishaldhingra/lcomm_json (diff)
downloadfrr-47b474b57e8ea740e7adf1438ccaae8c93553385.tar.xz
frr-47b474b57e8ea740e7adf1438ccaae8c93553385.zip
lib: Make if_lookup_by_index understand if VRF is backed by netns or not
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>
Diffstat (limited to 'lib/if.c')
-rw-r--r--lib/if.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/if.c b/lib/if.c
index 9ee2f02e6..ea83418e9 100644
--- 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);