mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 18:04:03 +00:00
lib: add utility to get the next index in a vrf
Add if_vrf_lookup_by_index_next to get the next ifindex in a vrf given the previous ifindex or 0 for the first. Signed-off-by: Pat Ruddy <pat@voltanet.io>
This commit is contained in:
parent
0d020cd6d9
commit
0760a74d2f
34
lib/if.c
34
lib/if.c
@ -351,6 +351,40 @@ struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Interface existance check by index. */
|
||||||
|
struct interface *if_vrf_lookup_by_index_next(ifindex_t ifindex,
|
||||||
|
vrf_id_t vrf_id)
|
||||||
|
{
|
||||||
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
||||||
|
struct interface *tmp_ifp;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
if (!vrf)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
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))
|
||||||
|
ifindex = tmp_ifp->ifindex;
|
||||||
|
else
|
||||||
|
return tmp_ifp;
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
return tmp_ifp;
|
||||||
|
}
|
||||||
|
if (tmp_ifp->ifindex == ifindex)
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id)
|
const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id)
|
||||||
{
|
{
|
||||||
struct interface *ifp;
|
struct interface *ifp;
|
||||||
|
2
lib/if.h
2
lib/if.h
@ -513,6 +513,8 @@ extern struct interface *if_create_name(const char *name, vrf_id_t vrf_id);
|
|||||||
/* Create new interface, adds to index list only */
|
/* Create new interface, adds to index list only */
|
||||||
extern struct interface *if_create_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
|
extern struct interface *if_create_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
|
||||||
extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);
|
extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);
|
||||||
|
extern struct interface *if_vrf_lookup_by_index_next(ifindex_t ifindex,
|
||||||
|
vrf_id_t vrf_id);
|
||||||
extern struct interface *if_lookup_by_index_all_vrf(ifindex_t);
|
extern struct interface *if_lookup_by_index_all_vrf(ifindex_t);
|
||||||
extern struct interface *if_lookup_exact_address(const void *matchaddr,
|
extern struct interface *if_lookup_exact_address(const void *matchaddr,
|
||||||
int family, vrf_id_t vrf_id);
|
int family, vrf_id_t vrf_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user