From: Daniel Walton Date: Wed, 28 Sep 2016 00:40:58 +0000 (+0000) Subject: pimd: sort pim_ifchannel_list X-Git-Tag: frr-3.0-branchpoint~64^2~10^2~192 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=bbd64ce1e7b71c8412dc71aa21bc5c5fda8b3165;p=mirror_frr.git pimd: sort pim_ifchannel_list Signed-off-by: Daniel Walton Reviewed-by: Donald Sharp --- diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index e55ef30b3..b6012d1ed 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -72,6 +72,24 @@ static void *if_list_clean(struct pim_interface *pim_ifp) return 0; } +static int +pim_ifchannel_compare (struct pim_ifchannel *ch1, struct pim_ifchannel *ch2) +{ + if (ntohl(ch1->sg.grp.s_addr) < ntohl(ch2->sg.grp.s_addr)) + return -1; + + if (ntohl(ch1->sg.grp.s_addr) > ntohl(ch2->sg.grp.s_addr)) + return 1; + + if (ntohl(ch1->sg.src.s_addr) < ntohl(ch2->sg.src.s_addr)) + return -1; + + if (ntohl(ch1->sg.src.s_addr) > ntohl(ch2->sg.src.s_addr)) + return 1; + + return 0; +} + struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim) { struct pim_interface *pim_ifp; @@ -142,6 +160,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim) return if_list_clean(pim_ifp); } pim_ifp->pim_ifchannel_list->del = (void (*)(void *)) pim_ifchannel_free; + pim_ifp->pim_ifchannel_list->cmp = (int (*)(void *, void *)) pim_ifchannel_compare; ifp->info = pim_ifp; diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 1bc10f4cc..ee388b7d6 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -429,7 +429,7 @@ pim_ifchannel_add(struct interface *ifp, PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch->flags); /* Attach to list */ - listnode_add(pim_ifp->pim_ifchannel_list, ch); + listnode_add_sort(pim_ifp->pim_ifchannel_list, ch); zassert(IFCHANNEL_NOINFO(ch));