]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add a function to get the VRF or loopback interface
authorLouis Scalbert <louis.scalbert@6wind.com>
Fri, 22 Apr 2022 16:08:08 +0000 (18:08 +0200)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Sun, 15 Jan 2023 10:22:24 +0000 (12:22 +0200)
Add a function to find the VRF or the loopback interface: the loopback
interface for the default VRF and the VRF master interface otherwise.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
lib/if.c
lib/if.h

index 70c0c18141696d3431a89b573a0641001e6c7fc5..db7321003644beca5d895ad8afa79c2f07cdd8da 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -564,6 +564,20 @@ size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz,
        return count;
 }
 
+/* Get the VRF loopback interface, i.e. the loopback on the default VRF
+ * or the VRF interface.
+ */
+struct interface *if_get_vrf_loopback(vrf_id_t vrf_id)
+{
+       struct interface *ifp = NULL;
+       struct vrf *vrf = vrf_lookup_by_id(vrf_id);
+
+       FOR_ALL_INTERFACES (vrf, ifp)
+               if (if_is_loopback(ifp))
+                       return ifp;
+
+       return NULL;
+}
 
 /* Get interface by name if given name interface doesn't exist create
    one. */
index 91dcd462474f5d567d28e972d36b617bebf5f19e..a653246ccb2ee61d1df3202c6eb5e2e40061ce76 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -532,6 +532,7 @@ static inline bool if_address_is_local(const void *matchaddr, int family,
 struct vrf;
 extern struct interface *if_lookup_by_name_vrf(const char *name, struct vrf *vrf);
 extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id);
+extern struct interface *if_get_vrf_loopback(vrf_id_t vrf_id);
 extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id,
                                        const char *vrf_name);