diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c index 6f4916b3c311..17d6592c0f78 100644 --- a/bgpd/bgp_advertise.c +++ b/bgpd/bgp_advertise.c @@ -83,10 +83,25 @@ void bgp_advertise_free(struct bgp_advertise *adv) void bgp_advertise_add(struct bgp_advertise_attr *baa, struct bgp_advertise *adv) { - adv->next = baa->adv; - if (baa->adv) - baa->adv->prev = adv; - baa->adv = adv; + struct bgp_advertise *spot, *prev = NULL; + + spot = baa->adv; + + while (spot) { + prev = spot; + spot = spot->next; + } + + if (prev) { + prev->next = adv; + adv->prev = prev; + } else + adv->prev = NULL; + + adv->next = NULL; + + if (!baa->adv) + baa->adv = adv; } void bgp_advertise_delete(struct bgp_advertise_attr *baa,