return new;
}
-static void vertex_parent_free(void *p)
+static void vertex_parent_free(struct vertex_parent *p)
{
+ vertex_nexthop_free(p->local_nexthop);
+ vertex_nexthop_free(p->nexthop);
XFREE(MTYPE_OSPF_VERTEX_PARENT, p);
}
new->lsa = lsa->data;
new->children = list_new();
new->parents = list_new();
- new->parents->del = vertex_parent_free;
+ new->parents->del = (void (*)(void *))vertex_parent_free;
new->parents->cmp = vertex_parent_cmp;
new->lsa_p = lsa;
memcpy(copy, vertex, sizeof(struct vertex));
copy->parents = list_new();
- copy->parents->del = vertex_parent_free;
+ copy->parents->del = (void (*)(void *))vertex_parent_free;
copy->parents->cmp = vertex_parent_cmp;
copy->children = list_new();
/*
* Consider supplied next-hop for inclusion to the supplied list of
* equal-cost next-hops, adjust list as necessary.
+ *
+ * Returns vertex parent pointer if created otherwise `NULL` if it already
+ * exists.
*/
-static void ospf_spf_add_parent(struct vertex *v, struct vertex *w,
- struct vertex_nexthop *newhop,
- struct vertex_nexthop *newlhop,
- unsigned int distance)
+static struct vertex_parent *ospf_spf_add_parent(struct vertex *v,
+ struct vertex *w,
+ struct vertex_nexthop *newhop,
+ struct vertex_nexthop *newlhop,
+ unsigned int distance)
{
struct vertex_parent *vp, *wp;
struct listnode *node;
zlog_debug(
"%s: ... nexthop already on parent list, skipping add",
__func__);
- return;
+
+ return NULL;
}
}
newlhop);
listnode_add_sort(w->parents, vp);
- return;
+ return vp;
}
static int match_stub_prefix(struct lsa_header *lsa, struct in_addr v_link_addr,
memcpy(lnh, nh,
sizeof(struct vertex_nexthop));
- ospf_spf_add_parent(v, w, nh, lnh,
- distance);
+ if (ospf_spf_add_parent(v, w, nh, lnh,
+ distance) ==
+ NULL) {
+ vertex_nexthop_free(nh);
+ vertex_nexthop_free(lnh);
+ }
return 1;
} else
zlog_info(
memcpy(lnh, nh,
sizeof(struct vertex_nexthop));
- ospf_spf_add_parent(v, w, nh, lnh,
- distance);
+ if (ospf_spf_add_parent(v, w, nh, lnh,
+ distance) ==
+ NULL) {
+ vertex_nexthop_free(nh);
+ vertex_nexthop_free(lnh);
+ }
+
return 1;
} else
zlog_info(
lnh = vertex_nexthop_new();
memcpy(lnh, nh, sizeof(struct vertex_nexthop));
- ospf_spf_add_parent(v, w, nh, lnh, distance);
+ if (ospf_spf_add_parent(v, w, nh, lnh, distance) ==
+ NULL) {
+ vertex_nexthop_free(nh);
+ vertex_nexthop_free(lnh);
+ }
+
return 1;
}
} /* end V is the root */
sizeof(struct vertex_nexthop));
added = 1;
- ospf_spf_add_parent(v, w, nh, lnh,
- distance);
+ if (ospf_spf_add_parent(v, w, nh, lnh,
+ distance) ==
+ NULL) {
+ vertex_nexthop_free(nh);
+ vertex_nexthop_free(lnh);
+ }
}
/*
* Note lack of return is deliberate. See next
lnh = NULL;
}
- ospf_spf_add_parent(v, w, vp->nexthop, lnh, distance);
+ nh = vertex_nexthop_new();
+ *nh = *vp->nexthop;
+
+ if (ospf_spf_add_parent(v, w, nh, lnh, distance) == NULL) {
+ vertex_nexthop_free(nh);
+ vertex_nexthop_free(lnh);
+ }
}
return added;