}
static void ospf_vertex_free(void *);
-/*
- * List of allocated vertices, to simplify cleanup of SPF.
- * Not thread-safe obviously. If it ever needs to be, it'd have to be
- * dynamically allocated at begin of ospf_spf_calculate
- */
-static struct list vertex_list = {.del = ospf_vertex_free};
/*
* Heap related functions, for the managment of the candidates, to
return IPV4_ADDR_CMP(&a->nexthop->router, &b->nexthop->router);
}
-static struct vertex *ospf_vertex_new(struct ospf_lsa *lsa)
+static struct vertex *ospf_vertex_new(struct ospf_area *area,
+ struct ospf_lsa *lsa)
{
struct vertex *new;
lsa->stat = new;
- listnode_add(&vertex_list, new);
+ listnode_add(area->spf_vertex_list, new);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Created %s vertex %s", __func__,
static void ospf_spf_init(struct ospf_area *area, struct ospf_lsa *root_lsa,
bool is_dry_run, bool is_root_node)
{
+ struct list *vertex_list;
struct vertex *v;
- /* Create root node. */
- v = ospf_vertex_new(root_lsa);
+ /* Create vertex list */
+ vertex_list = list_new();
+ vertex_list->del = ospf_vertex_free;
+ area->spf_vertex_list = vertex_list;
+ /* Create root node. */
+ v = ospf_vertex_new(area, root_lsa);
area->spf = v;
+
area->spf_dry_run = is_dry_run;
area->spf_root_node = is_root_node;
/* Is there already vertex W in candidate list? */
if (w_lsa->stat == LSA_SPF_NOT_EXPLORED) {
/* prepare vertex W. */
- w = ospf_vertex_new(w_lsa);
+ w = ospf_vertex_new(area, w_lsa);
/* Calculate nexthop to W. */
if (ospf_nexthop_calculation(area, v, w, l, distance,
route_table_finish(rtrs);
}
+void ospf_spf_cleanup(struct vertex *spf, struct list *vertex_list)
+{
+ /*
+ * Free nexthop information, canonical versions of which are
+ * attached the first level of router vertices attached to the
+ * root vertex, see ospf_nexthop_calculation.
+ */
+ ospf_canonical_nexthops_free(spf);
+
+ /* Free SPF vertices list with deconstructor ospf_vertex_free. */
+ list_delete(&vertex_list);
+}
+
#if 0
static void
ospf_rtrs_print (struct route_table *rtrs)
mtype_stats_alloc(MTYPE_OSPF_VERTEX));
/* If this is a dry run then keep the SPF data in place */
- if (!area->spf_dry_run) {
- /*
- * Free nexthop information, canonical versions of which are
- * attached the first level of router vertices attached to the
- * root vertex, see ospf_nexthop_calculation.
- */
- ospf_canonical_nexthops_free(area->spf);
-
- /*
- * Free SPF vertices, but not the list. List has
- * ospf_vertex_free as deconstructor.
- */
- list_delete_all_node(&vertex_list);
- }
+ if (!area->spf_dry_run)
+ ospf_spf_cleanup(area->spf, area->spf_vertex_list);
}
int ospf_spf_calculate_areas(struct ospf *ospf, struct route_table *new_table,