]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_zebra.c
*: use rb-trees to store interfaces instead of sorted linked-lists
[mirror_frr.git] / bgpd / bgp_zebra.c
index c90257d6598583103fc7ea159421653eeca360db..9c8f56636c37f3905359c82cb211184c6be954c9 100644 (file)
@@ -591,18 +591,22 @@ static int zebra_read_route(int command, struct zclient *zclient,
 
 struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id)
 {
-       struct listnode *ifnode;
+       struct vrf *vrf;
        struct listnode *cnode;
        struct interface *ifp;
        struct connected *connected;
        struct prefix_ipv4 p;
        struct prefix *cp;
 
+       vrf = vrf_lookup_by_id(vrf_id);
+       if (!vrf)
+               return NULL;
+
        p.family = AF_INET;
        p.prefix = *addr;
        p.prefixlen = IPV4_MAX_BITLEN;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) {
+       RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) {
                for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
                        cp = connected->address;
 
@@ -616,13 +620,17 @@ struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id)
 
 struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id)
 {
-       struct listnode *ifnode;
+       struct vrf *vrf;
        struct listnode *cnode;
        struct interface *ifp;
        struct connected *connected;
        struct prefix *cp;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) {
+       vrf = vrf_lookup_by_id(vrf_id);
+       if (!vrf)
+               return NULL;
+
+       RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) {
                for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
                        cp = connected->address;
 
@@ -637,18 +645,22 @@ struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id)
 struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex,
                                    vrf_id_t vrf_id)
 {
-       struct listnode *ifnode;
+       struct vrf *vrf;
        struct listnode *cnode;
        struct interface *ifp;
        struct connected *connected;
        struct prefix_ipv6 p;
        struct prefix *cp;
 
+       vrf = vrf_lookup_by_id(vrf_id);
+       if (!vrf)
+               return NULL;
+
        p.family = AF_INET6;
        p.prefix = *addr;
        p.prefixlen = IPV6_MAX_BITLEN;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) {
+       RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) {
                for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
                        cp = connected->address;
 
@@ -669,13 +681,17 @@ struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex,
 struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr,
                                          ifindex_t ifindex, vrf_id_t vrf_id)
 {
-       struct listnode *ifnode;
+       struct vrf *vrf;
        struct listnode *cnode;
        struct interface *ifp;
        struct connected *connected;
        struct prefix *cp;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) {
+       vrf = vrf_lookup_by_id(vrf_id);
+       if (!vrf)
+               return NULL;
+
+       RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) {
                for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
                        cp = connected->address;