]> git.proxmox.com Git - mirror_frr.git/blobdiff - ldpd/interface.c
Merge pull request #5412 from opensourcerouting/bfdd-vrf-fix
[mirror_frr.git] / ldpd / interface.c
index 7678152470ecd32d887b34febc499f4bfc126e77..8b45703d22f7e3b535dbcd96ad8e202a515d7f06 100644 (file)
 
 #include "sockopt.h"
 
-static __inline int     iface_compare(struct iface *, struct iface *);
+static __inline int     iface_compare(const struct iface *, const struct iface *);
 static struct if_addr  *if_addr_new(struct kaddr *);
 static struct if_addr  *if_addr_lookup(struct if_addr_head *, struct kaddr *);
 static int              if_start(struct iface *, int);
 static int              if_reset(struct iface *, int);
-static void             if_update_af(struct iface_af *, int);
+static void             if_update_af(struct iface_af *);
 static int              if_hello_timer(struct thread *);
 static void             if_start_hello_timer(struct iface_af *);
 static void             if_stop_hello_timer(struct iface_af *);
@@ -43,9 +43,9 @@ static int             if_leave_ipv6_group(struct iface *, struct in6_addr *);
 RB_GENERATE(iface_head, iface, entry, iface_compare)
 
 static __inline int
-iface_compare(struct iface *a, struct iface *b)
+iface_compare(const struct iface *a, const struct iface *b)
 {
-       return (strcmp(a->name, b->name));
+       return if_cmp_name_func(a->name, b->name);
 }
 
 struct iface *
@@ -81,12 +81,12 @@ ldpe_if_init(struct iface *iface)
        /* ipv4 */
        iface->ipv4.iface = iface;
        iface->ipv4.state = IF_STA_DOWN;
-       RB_INIT(&iface->ipv4.adj_tree);
+       RB_INIT(ia_adj_head, &iface->ipv4.adj_tree);
 
        /* ipv6 */
        iface->ipv6.iface = iface;
        iface->ipv6.state = IF_STA_DOWN;
-       RB_INIT(&iface->ipv6.adj_tree);
+       RB_INIT(ia_adj_head, &iface->ipv6.adj_tree);
 }
 
 void
@@ -103,6 +103,7 @@ ldpe_if_exit(struct iface *iface)
 
        while ((if_addr = LIST_FIRST(&iface->addr_list)) != NULL) {
                LIST_REMOVE(if_addr, entry);
+               assert(if_addr != LIST_FIRST(&iface->addr_list));
                free(if_addr);
        }
 }
@@ -139,7 +140,7 @@ if_update_info(struct iface *iface, struct kif *kif)
 
        /* get index and flags */
        iface->ifindex = kif->ifindex;
-       iface->flags = kif->flags;
+       iface->operative = kif->operative;
 }
 
 struct iface_af *
@@ -209,7 +210,7 @@ if_addr_add(struct kaddr *ka)
                }
        }
 
-       iface = if_lookup(leconf, ka->ifindex);
+       iface = if_lookup_name(leconf, ka->ifname);
        if (iface) {
                if (ka->af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&ka->addr.v6))
                        iface->linklocal = ka->addr.v6;
@@ -229,7 +230,7 @@ if_addr_del(struct kaddr *ka)
        struct if_addr          *if_addr;
        struct nbr              *nbr;
 
-       iface = if_lookup(leconf, ka->ifindex);
+       iface = if_lookup_name(leconf, ka->ifname);
        if (iface) {
                if (ka->af == AF_INET6 &&
                    IN6_ARE_ADDR_EQUAL(&iface->linklocal, &ka->addr.v6))
@@ -305,8 +306,11 @@ if_reset(struct iface *iface, int af)
        ia = iface_af_get(iface, af);
        if_stop_hello_timer(ia);
 
-       while ((adj = RB_ROOT(&ia->adj_tree)) != NULL)
+       while (!RB_EMPTY(ia_adj_head, &ia->adj_tree)) {
+               adj = RB_ROOT(ia_adj_head, &ia->adj_tree);
+
                adj_del(adj, S_SHUTDOWN);
+       }
 
        /* try to cleanup */
        switch (af) {
@@ -328,7 +332,7 @@ if_reset(struct iface *iface, int af)
 }
 
 static void
-if_update_af(struct iface_af *ia, int link_ok)
+if_update_af(struct iface_af *ia)
 {
        int                      addr_ok = 0, socket_ok, rtr_id_ok;
        struct if_addr          *if_addr;
@@ -366,13 +370,14 @@ if_update_af(struct iface_af *ia, int link_ok)
                rtr_id_ok = 0;
 
        if (ia->state == IF_STA_DOWN) {
-               if (!ia->enabled || !link_ok || !addr_ok || !socket_ok ||
-                   !rtr_id_ok)
+               if (!ia->enabled || !ia->iface->operative || !addr_ok ||
+                   !socket_ok || !rtr_id_ok)
                        return;
 
                if_start(ia->iface, ia->af);
        } else if (ia->state == IF_STA_ACTIVE) {
-               if (ia->enabled && link_ok && addr_ok && socket_ok && rtr_id_ok)
+               if (ia->enabled && ia->iface->operative && addr_ok &&
+                   socket_ok && rtr_id_ok)
                        return;
 
                if_reset(ia->iface, ia->af);
@@ -382,14 +387,10 @@ if_update_af(struct iface_af *ia, int link_ok)
 void
 ldp_if_update(struct iface *iface, int af)
 {
-       int                      link_ok;
-
-       link_ok = (iface->flags & IFF_UP) && (iface->flags & IFF_RUNNING);
-
        if (af == AF_INET || af == AF_UNSPEC)
-               if_update_af(&iface->ipv4, link_ok);
+               if_update_af(&iface->ipv4);
        if (af == AF_INET6 || af == AF_UNSPEC)
-               if_update_af(&iface->ipv6, link_ok);
+               if_update_af(&iface->ipv6);
 }
 
 void
@@ -443,8 +444,9 @@ static void
 if_start_hello_timer(struct iface_af *ia)
 {
        THREAD_TIMER_OFF(ia->hello_timer);
-       ia->hello_timer = thread_add_timer(master, if_hello_timer, ia,
-           if_get_hello_interval(ia));
+       ia->hello_timer = NULL;
+       thread_add_timer(master, if_hello_timer, ia, if_get_hello_interval(ia),
+                        &ia->hello_timer);
 }
 
 static void
@@ -464,7 +466,6 @@ if_to_ctl(struct iface_af *ia)
        memcpy(ictl.name, ia->iface->name, sizeof(ictl.name));
        ictl.ifindex = ia->iface->ifindex;
        ictl.state = ia->state;
-       ictl.flags = ia->iface->flags;
        ictl.type = ia->iface->type;
        ictl.hello_holdtime = if_get_hello_holdtime(ia);
        ictl.hello_interval = if_get_hello_interval(ia);