]> git.proxmox.com Git - mirror_frr.git/blobdiff - eigrpd/eigrp_topology.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / eigrpd / eigrp_topology.c
index 94775622d98d02d144d3c6eae26b983810f19df7..0cb4e0e9f45c3d2086fd399393f287ab16ebf7d1 100644 (file)
@@ -37,6 +37,7 @@
 #include "log.h"
 #include "linklist.h"
 #include "vty.h"
+#include "lib_errors.h"
 
 #include "eigrpd/eigrp_structs.h"
 #include "eigrpd/eigrpd.h"
 #include "eigrpd/eigrp_fsm.h"
 #include "eigrpd/eigrp_memory.h"
 
-static int eigrp_prefix_entry_cmp(struct eigrp_prefix_entry *,
-                                 struct eigrp_prefix_entry *);
-static void eigrp_prefix_entry_del(struct eigrp_prefix_entry *);
 static int eigrp_nexthop_entry_cmp(struct eigrp_nexthop_entry *,
-                                   struct eigrp_nexthop_entry *);
+                                  struct eigrp_nexthop_entry *);
 
 /*
  * Returns linkedlist used as topology table
@@ -63,45 +61,9 @@ static int eigrp_nexthop_entry_cmp(struct eigrp_nexthop_entry *,
  * del - assigned function executed before deleting topology node by list
  * function
  */
-struct list *eigrp_topology_new()
+struct route_table *eigrp_topology_new()
 {
-       struct list *new = list_new();
-       new->cmp = (int (*)(void *, void *))eigrp_prefix_entry_cmp;
-       new->del = (void (*)(void *))eigrp_prefix_entry_del;
-
-       return new;
-}
-
-/*
- * Topology node comparison
- */
-
-static int eigrp_prefix_entry_cmp(struct eigrp_prefix_entry *node1,
-                                 struct eigrp_prefix_entry *node2)
-{
-       if (node1->af == AF_INET) {
-               if (node2->af == AF_INET) {
-                       if (node1->destination->u.prefix4.s_addr
-                           < node2->destination->u.prefix4.s_addr)
-                               return -1;
-                       if (node1->destination->u.prefix4.s_addr
-                           > node2->destination->u.prefix4.s_addr)
-                               return 1;
-                       else
-                               return 0;
-               } else
-                       return 1;
-       } else
-               return 1;
-}
-
-/*
- * Topology node delete
- */
-
-static void eigrp_prefix_entry_del(struct eigrp_prefix_entry *node)
-{
-       list_delete_and_null(&node->entries);
+       return route_table_init();
 }
 
 /*
@@ -126,7 +88,7 @@ struct eigrp_prefix_entry *eigrp_prefix_entry_new()
  * Topology entry comparison
  */
 static int eigrp_nexthop_entry_cmp(struct eigrp_nexthop_entry *entry1,
-                                   struct eigrp_nexthop_entry *entry2)
+                                  struct eigrp_nexthop_entry *entry2)
 {
        if (entry1->distance < entry2->distance)
                return -1;
@@ -155,37 +117,41 @@ struct eigrp_nexthop_entry *eigrp_nexthop_entry_new()
 /*
  * Freeing topology table list
  */
-void eigrp_topology_free(struct list *list)
+void eigrp_topology_free(struct route_table *table)
 {
-       list_delete_and_null(&list);
+       eigrp_topology_delete_all(table);
+       route_table_finish(table);
 }
 
 /*
- * Deleting all topology nodes in table
+ * Adding topology node to topology table
  */
-void eigrp_topology_cleanup(struct list *topology)
+void eigrp_prefix_entry_add(struct route_table *topology,
+                           struct eigrp_prefix_entry *pe)
 {
-       assert(topology);
+       struct route_node *rn;
 
-       eigrp_topology_delete_all(topology);
-}
+       rn = route_node_get(topology, pe->destination);
+       if (rn->info) {
+               if (IS_DEBUG_EIGRP_EVENT) {
+                       char buf[PREFIX_STRLEN];
 
-/*
- * Adding topology node to topology table
- */
-void eigrp_prefix_entry_add(struct list *topology,
-                           struct eigrp_prefix_entry *node)
-{
-       if (listnode_lookup(topology, node) == NULL) {
-               listnode_add_sort(topology, node);
+                       zlog_debug(
+                               "%s: %s Should we have found this entry in the topo table?",
+                               __PRETTY_FUNCTION__,
+                               prefix2str(pe->destination, buf, sizeof(buf)));
+               }
        }
+
+       rn->info = pe;
+       route_lock_node(rn);
 }
 
 /*
  * Adding topology entry to topology node
  */
 void eigrp_nexthop_entry_add(struct eigrp_prefix_entry *node,
-                             struct eigrp_nexthop_entry *entry)
+                            struct eigrp_nexthop_entry *entry)
 {
        struct list *l = list_new();
 
@@ -198,37 +164,51 @@ void eigrp_nexthop_entry_add(struct eigrp_prefix_entry *node,
                eigrp_zebra_route_add(node->destination, l);
        }
 
-       list_delete_and_null(&l);
+       list_delete(&l);
 }
 
 /*
  * Deleting topology node from topology table
  */
-void eigrp_prefix_entry_delete(struct list *topology,
-                              struct eigrp_prefix_entry *node)
+void eigrp_prefix_entry_delete(struct route_table *table,
+                              struct eigrp_prefix_entry *pe)
 {
        struct eigrp *eigrp = eigrp_lookup();
+       struct eigrp_nexthop_entry *ne;
+       struct listnode *node, *nnode;
+       struct route_node *rn;
+
+       if (!eigrp)
+               return;
+
+       rn = route_node_lookup(table, pe->destination);
+       if (!rn)
+               return;
 
        /*
         * Emergency removal of the node from this list.
         * Whatever it is.
         */
-       listnode_delete(eigrp->topology_changes_internalIPV4, node);
-
-       if (listnode_lookup(topology, node) != NULL) {
-               list_delete_and_null(&node->entries);
-               list_delete_and_null(&node->rij);
-               listnode_delete(topology, node);
-               eigrp_zebra_route_delete(node->destination);
-               XFREE(MTYPE_EIGRP_PREFIX_ENTRY, node);
-       }
+       listnode_delete(eigrp->topology_changes_internalIPV4, pe);
+
+       for (ALL_LIST_ELEMENTS(pe->entries, node, nnode, ne))
+               eigrp_nexthop_entry_delete(pe, ne);
+       list_delete(&pe->entries);
+       list_delete(&pe->rij);
+       eigrp_zebra_route_delete(pe->destination);
+       prefix_free(pe->destination);
+
+       rn->info = NULL;
+       route_unlock_node(rn); // Lookup above
+       route_unlock_node(rn); // Initial creation
+       XFREE(MTYPE_EIGRP_PREFIX_ENTRY, pe);
 }
 
 /*
  * Deleting topology entry from topology node
  */
 void eigrp_nexthop_entry_delete(struct eigrp_prefix_entry *node,
-                                struct eigrp_nexthop_entry *entry)
+                               struct eigrp_nexthop_entry *entry)
 {
        if (listnode_lookup(node->entries, entry) != NULL) {
                listnode_delete(node->entries, entry);
@@ -240,35 +220,37 @@ void eigrp_nexthop_entry_delete(struct eigrp_prefix_entry *node,
 /*
  * Deleting all nodes from topology table
  */
-void eigrp_topology_delete_all(struct list *topology)
+void eigrp_topology_delete_all(struct route_table *topology)
 {
-       list_delete_all_node(topology);
-}
+       struct route_node *rn;
+       struct eigrp_prefix_entry *pe;
 
-/*
- * Return 0 if topology is not empty
- * otherwise return 1
- */
-unsigned int eigrp_topology_table_isempty(struct list *topology)
-{
-       if (topology->count)
-               return 1;
-       else
-               return 0;
+       for (rn = route_top(topology); rn; rn = route_next(rn)) {
+               pe = rn->info;
+
+               if (!pe)
+                       continue;
+
+               eigrp_prefix_entry_delete(topology, pe);
+       }
 }
 
 struct eigrp_prefix_entry *
-eigrp_topology_table_lookup_ipv4(struct list *topology_table,
+eigrp_topology_table_lookup_ipv4(struct route_table *table,
                                 struct prefix *address)
 {
-       struct eigrp_prefix_entry *data;
-       struct listnode *node;
-       for (ALL_LIST_ELEMENTS_RO(topology_table, node, data)) {
-               if (prefix_same(data->destination, address))
-                       return data;
-       }
+       struct eigrp_prefix_entry *pe;
+       struct route_node *rn;
 
-       return NULL;
+       rn = route_node_lookup(table, address);
+       if (!rn)
+               return NULL;
+
+       pe = rn->info;
+
+       route_unlock_node(rn);
+
+       return pe;
 }
 
 /*
@@ -294,7 +276,7 @@ struct list *eigrp_topology_get_successor(struct eigrp_prefix_entry *table_node)
         * If we have no successors return NULL
         */
        if (!successors->count) {
-               list_delete_and_null(&successors);
+               list_delete(&successors);
                successors = NULL;
        }
 
@@ -337,20 +319,24 @@ eigrp_prefix_entry_lookup(struct list *entries, struct eigrp_neighbor *nbr)
 struct list *eigrp_neighbor_prefixes_lookup(struct eigrp *eigrp,
                                            struct eigrp_neighbor *nbr)
 {
-       struct listnode *node1, *node11, *node2, *node22;
-       struct eigrp_prefix_entry *prefix;
+       struct listnode *node2, *node22;
        struct eigrp_nexthop_entry *entry;
+       struct eigrp_prefix_entry *pe;
+       struct route_node *rn;
 
        /* create new empty list for prefixes storage */
        struct list *prefixes = list_new();
 
        /* iterate over all prefixes in topology table */
-       for (ALL_LIST_ELEMENTS(eigrp->topology_table, node1, node11, prefix)) {
+       for (rn = route_top(eigrp->topology_table); rn; rn = route_next(rn)) {
+               if (!rn->info)
+                       continue;
+               pe = rn->info;
                /* iterate over all neighbor entry in prefix */
-               for (ALL_LIST_ELEMENTS(prefix->entries, node2, node22, entry)) {
+               for (ALL_LIST_ELEMENTS(pe->entries, node2, node22, entry)) {
                        /* if entry is from specified neighbor, add to list */
                        if (entry->adv_router == nbr) {
-                               listnode_add(prefixes, prefix);
+                               listnode_add(prefixes, pe);
                        }
                }
        }
@@ -359,17 +345,18 @@ struct list *eigrp_neighbor_prefixes_lookup(struct eigrp *eigrp,
        return prefixes;
 }
 
-enum metric_change eigrp_topology_update_distance(struct eigrp_fsm_action_message *msg)
+enum metric_change
+eigrp_topology_update_distance(struct eigrp_fsm_action_message *msg)
 {
        struct eigrp *eigrp = msg->eigrp;
        struct eigrp_prefix_entry *prefix = msg->prefix;
        struct eigrp_nexthop_entry *entry = msg->entry;
        enum metric_change change = METRIC_SAME;
-       u_int32_t new_reported_distance;
+       uint32_t new_reported_distance;
 
        assert(entry);
 
-       switch(msg->data_type) {
+       switch (msg->data_type) {
        case EIGRP_CONNECTED:
                if (prefix->nt == EIGRP_TOPOLOGY_TYPE_CONNECTED)
                        return change;
@@ -386,8 +373,8 @@ enum metric_change eigrp_topology_update_distance(struct eigrp_fsm_action_messag
                        return change; // No change
                }
 
-               new_reported_distance = eigrp_calculate_metrics(eigrp,
-                                                               msg->metrics);
+               new_reported_distance =
+                       eigrp_calculate_metrics(eigrp, msg->metrics);
 
                if (entry->reported_distance < new_reported_distance) {
                        change = METRIC_INCREASE;
@@ -411,10 +398,11 @@ enum metric_change eigrp_topology_update_distance(struct eigrp_fsm_action_messag
                }
                break;
        default:
-               zlog_err("%s: Please implement handler", __PRETTY_FUNCTION__);
+               flog_err(EC_LIB_DEVELOPMENT, "%s: Please implement handler",
+                        __PRETTY_FUNCTION__);
                break;
        }
- distance_done:
+distance_done:
        /*
         * Move to correct position in list according to new distance
         */
@@ -426,11 +414,19 @@ enum metric_change eigrp_topology_update_distance(struct eigrp_fsm_action_messag
 
 void eigrp_topology_update_all_node_flags(struct eigrp *eigrp)
 {
-       struct list *table = eigrp->topology_table;
-       struct eigrp_prefix_entry *data;
-       struct listnode *node, *nnode;
-       for (ALL_LIST_ELEMENTS(table, node, nnode, data)) {
-               eigrp_topology_update_node_flags(data);
+       struct eigrp_prefix_entry *pe;
+       struct route_node *rn;
+
+       if (!eigrp)
+               return;
+
+       for (rn = route_top(eigrp->topology_table); rn; rn = route_next(rn)) {
+               pe = rn->info;
+
+               if (!pe)
+                       continue;
+
+               eigrp_topology_update_node_flags(pe);
        }
 }
 
@@ -440,18 +436,27 @@ void eigrp_topology_update_node_flags(struct eigrp_prefix_entry *dest)
        struct eigrp_nexthop_entry *entry;
        struct eigrp *eigrp = eigrp_lookup();
 
+       assert(eigrp);
+
        for (ALL_LIST_ELEMENTS_RO(dest->entries, node, entry)) {
-               if (((uint64_t)entry->distance
-                    <= (uint64_t)dest->distance * (uint64_t)eigrp->variance)
-                   && entry->distance != EIGRP_MAX_METRIC) // is successor
-               {
-                       entry->flags |= EIGRP_NEXTHOP_ENTRY_SUCCESSOR_FLAG;
-                       entry->flags &= ~EIGRP_NEXTHOP_ENTRY_FSUCCESSOR_FLAG;
-               } else if (entry->reported_distance
-                          < dest->fdistance) // is feasible successor
-               {
-                       entry->flags |= EIGRP_NEXTHOP_ENTRY_FSUCCESSOR_FLAG;
-                       entry->flags &= ~EIGRP_NEXTHOP_ENTRY_SUCCESSOR_FLAG;
+               if (entry->reported_distance < dest->fdistance) {
+                       // is feasible successor, can be successor
+                       if (((uint64_t)entry->distance
+                            <= (uint64_t)dest->distance
+                                       * (uint64_t)eigrp->variance)
+                           && entry->distance != EIGRP_MAX_METRIC) {
+                               // is successor
+                               entry->flags |=
+                                       EIGRP_NEXTHOP_ENTRY_SUCCESSOR_FLAG;
+                               entry->flags &=
+                                       ~EIGRP_NEXTHOP_ENTRY_FSUCCESSOR_FLAG;
+                       } else {
+                               // is feasible successor only
+                               entry->flags |=
+                                       EIGRP_NEXTHOP_ENTRY_FSUCCESSOR_FLAG;
+                               entry->flags &=
+                                       ~EIGRP_NEXTHOP_ENTRY_SUCCESSOR_FLAG;
+                       }
                } else {
                        entry->flags &= ~EIGRP_NEXTHOP_ENTRY_FSUCCESSOR_FLAG;
                        entry->flags &= ~EIGRP_NEXTHOP_ENTRY_SUCCESSOR_FLAG;
@@ -462,18 +467,21 @@ void eigrp_topology_update_node_flags(struct eigrp_prefix_entry *dest)
 void eigrp_update_routing_table(struct eigrp_prefix_entry *prefix)
 {
        struct eigrp *eigrp = eigrp_lookup();
-       struct list *successors =
-               eigrp_topology_get_successor_max(prefix, eigrp->max_paths);
+       struct list *successors;
        struct listnode *node;
        struct eigrp_nexthop_entry *entry;
 
+       if (!eigrp)
+               return;
+
+       successors = eigrp_topology_get_successor_max(prefix, eigrp->max_paths);
+
        if (successors) {
-               eigrp_zebra_route_add(prefix->destination,
-                                     successors);
+               eigrp_zebra_route_add(prefix->destination, successors);
                for (ALL_LIST_ELEMENTS_RO(successors, node, entry))
                        entry->flags |= EIGRP_NEXTHOP_ENTRY_INTABLE_FLAG;
 
-               list_delete_and_null(&successors);
+               list_delete(&successors);
        } else {
                eigrp_zebra_route_delete(prefix->destination);
                for (ALL_LIST_ELEMENTS_RO(prefix->entries, node, entry))
@@ -484,12 +492,18 @@ void eigrp_update_routing_table(struct eigrp_prefix_entry *prefix)
 void eigrp_topology_neighbor_down(struct eigrp *eigrp,
                                  struct eigrp_neighbor *nbr)
 {
-       struct listnode *node1, *node11, *node2, *node22;
-       struct eigrp_prefix_entry *prefix;
+       struct listnode *node2, *node22;
+       struct eigrp_prefix_entry *pe;
        struct eigrp_nexthop_entry *entry;
+       struct route_node *rn;
+
+       for (rn = route_top(eigrp->topology_table); rn; rn = route_next(rn)) {
+               pe = rn->info;
+
+               if (!pe)
+                       continue;
 
-       for (ALL_LIST_ELEMENTS(eigrp->topology_table, node1, node11, prefix)) {
-               for (ALL_LIST_ELEMENTS(prefix->entries, node2, node22, entry)) {
+               for (ALL_LIST_ELEMENTS(pe->entries, node2, node22, entry)) {
                        struct eigrp_fsm_action_message msg;
 
                        if (entry->adv_router != nbr)
@@ -501,7 +515,7 @@ void eigrp_topology_neighbor_down(struct eigrp *eigrp,
                        msg.data_type = EIGRP_INT;
                        msg.adv_router = nbr;
                        msg.entry = entry;
-                       msg.prefix = prefix;
+                       msg.prefix = pe;
                        eigrp_fsm_event(&msg);
                }
        }
@@ -510,7 +524,7 @@ void eigrp_topology_neighbor_down(struct eigrp *eigrp,
        eigrp_update_send_all(eigrp, nbr->ei);
 }
 
-void eigrp_update_topology_table_prefix(struct list *table,
+void eigrp_update_topology_table_prefix(struct route_table *table,
                                        struct eigrp_prefix_entry *prefix)
 {
        struct listnode *node1, *node2;