]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Allow interface lookup by VRF_UNKNOWN
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 5 Jan 2018 14:21:55 +0000 (09:21 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 12 Jan 2018 14:19:43 +0000 (09:19 -0500)
Modify if_lookup_by_index to accept a VRF_UNKNOWN
as a vrf_id.  This will cause it to look in all
vrf's for the interface pointer.

Subsequently all if_XXXX functions that call this function
will also get this behavior.

VRF_UNKNOWN *should* not be used for interface creation
as that this will break some core assumptions.

This work is part of allowing vrf route leaking.  Currently
it is possible to create a route in the linux kernel that has
a nexthop across vrf boundaries.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/if.c
lib/if.h

index 8e6a9a6968eb0cf6c7f8c065494c7adab936be8a..fdcd563a5deded3917e7371f3490add85bf16d58 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -219,6 +219,18 @@ struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
        struct vrf *vrf;
        struct interface if_tmp;
 
+       if (vrf_id == VRF_UNKNOWN) {
+               struct interface *ifp;
+
+               RB_FOREACH(vrf, vrf_id_head, &vrfs_by_id) {
+                       ifp = if_lookup_by_index(ifindex, vrf->vrf_id);
+                       if (ifp)
+                               return ifp;
+               }
+
+               return NULL;
+       }
+
        vrf = vrf_lookup_by_id(vrf_id);
        if (!vrf)
                return NULL;
index eb8af2041b21fdb0f8f62cde261cf2a9712c766c..79f96a7c452ee5306fd965a3668fe96ec5cc8648 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -452,6 +452,13 @@ struct nbr_connected {
 /* Prototypes. */
 extern int if_cmp_name_func(char *, char *);
 
+/*
+ * Passing in VRF_UNKNOWN is a valid thing to do, unless we
+ * are creating a new interface.
+ *
+ * This is useful for vrf route-leaking.  So more than anything
+ * else think before you use VRF_UNKNOWN
+ */
 extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id);
 extern struct interface *if_create(const char *name,  vrf_id_t vrf_id);
 extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);