From ce95ba5ab750c7505f01165d5811262065533f01 Mon Sep 17 00:00:00 2001 From: anlan_cs Date: Fri, 26 May 2023 13:17:22 +0800 Subject: [PATCH] pimd: Fix missing promotion for primary address Assume that `pim_ifp` has two ip (v4) addresses, one is primary, the other is secondary. After remove primary ip, the secondary ip doesn't be promoted, so `pim_ifp->primary_address` will wrongly be set to "0.0.0.0", it leads to `pim_sock_delete(ifp)` on this interface. Add the promotion for primary address. Fixed #13590 Signed-off-by: anlan_cs --- pimd/pim_iface.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index b1beb45630..7da7a98fb7 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -893,6 +893,7 @@ pim_addr pim_find_primary_addr(struct interface *ifp) #else int v4_addrs = 0; int v6_addrs = 0; + struct connected *promote_ifc = NULL; for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { switch (ifc->address->family) { @@ -906,15 +907,24 @@ pim_addr pim_find_primary_addr(struct interface *ifp) continue; } - if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) - continue; - if (ifc->address->family != PIM_AF) continue; + if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) { + promote_ifc = ifc; + continue; + } + return pim_addr_from_prefix(ifc->address); } + + /* Promote the new primary address. */ + if (v4_addrs && promote_ifc) { + UNSET_FLAG(promote_ifc->flags, ZEBRA_IFA_SECONDARY); + return pim_addr_from_prefix(promote_ifc->address); + } + /* * If we have no v4_addrs and v6 is configured * We probably are using unnumbered