Commit 1b6b56fc07 for frr

commit 1b6b56fc072abcb391b0ba36887c3d934c414619
Author: Nageswara Soma <nsoma@cisco.com>
Date:   Tue Nov 24 20:56:37 2026 -0800

    pimd: fix OIF ownership when PIM join or (*,G) ends

    Keep PIM OIF ownership only for an active downstream
    join that has not lost Assert. Local membership and
    inheritance keep their own GM and STAR bits.

    Preserve STAR when a (*,G) PIM join ends but local
    membership still justifies inheritance. Also retain
    STAR when local membership ends but the parent PIM
    join remains eligible, even without a child ifchannel.

    Evaluate STAR from parent interest independently of
    the child's own join. An (S,G,rpt) prune blocks parent
    PIM-join inheritance but cannot cancel an eligible
    local receiver.

    Align the JOIN path with the NOINFO path as a
    consistency cleanup; existing paths already maintain
    STAR in that case. Remove the unused inheritance-only
    helper.

    Signed-off-by: Nageswara Soma <nsoma@cisco.com>

diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c
index f87d67f4fd..19a75b754c 100644
--- a/pimd/pim_ifchannel.c
+++ b/pimd/pim_ifchannel.c
@@ -296,6 +296,7 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch,
 			if (ch->ifjoin_state == PIM_IFJOIN_NOINFO) {
 				for (ALL_LIST_ELEMENTS_RO(up->sources, up_node,
 							  child)) {
+					struct pim_ifchannel *child_chrpt;
 					struct channel_oil *c_oil =
 						child->channel_oil;

@@ -308,13 +309,15 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch,
 					if (!c_oil)
 						continue;

-					/*
-					 * If the S,G has no if channel and the
-					 * c_oil still
-					 * has output here then the *,G was
-					 * supplying the implied
-					 * if channel.  So remove it.
-					 */
+					/* Local membership can still justify inheritance. */
+					pim_ifchannel_find(ch->interface, &child->sg, &child_ch,
+							   &child_chrpt);
+					if (pim_upstream_evaluate_join_desired_interface(child,
+											 NULL,
+											 child_chrpt,
+											 ch))
+						continue;
+
 					if (channel_oil_oif_find(c_oil, pim_ifp->mroute_vif_index))
 						pim_channel_del_inherited_oif(
 							c_oil, ch->interface,
@@ -339,8 +342,10 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch,
 					pim_ifchannel_find(ch->interface, &child->sg, &child_ch,
 							   &child_chrpt);

-					if (pim_upstream_eval_inherit_if(child, child_ch,
-									 child_chrpt, ch)) {
+					if (pim_upstream_evaluate_join_desired_interface(child,
+											 NULL,
+											 child_chrpt,
+											 ch)) {
 						pim_channel_add_oif(
 							child->channel_oil,
 							ch->interface,
@@ -1311,23 +1316,15 @@ void pim_ifchannel_local_membership_del(struct interface *ifp, pim_sgaddr *sg)

 			pim_ifchannel_find(ifp, &child->sg, &chchannel, &chchannelrpt);

-			pim_ifp = ifp->info;
-
 			if (PIM_DEBUG_EVENTS)
 				zlog_debug("%s %s: Prune(S,G)=(%s:%u:%u)%s(%s) from (%s:%u:%u)%s",
 					   __FILE__, __func__, PIM_DEBUG_VRF(up->pim->vrf),
 					   up->sg_str, ifp->name, PIM_DEBUG_VRF(child->pim->vrf),
 					   child->sg_str);

-			/*
-			 * If the S,G has no if channel and the c_oil still
-			 * has output here then the *,G was supplying the
-			 * implied
-			 * if channel.  So remove it.
-			 */
-			if (!pim_upstream_evaluate_join_desired_interface(child, chchannel,
-									  chchannelrpt, starch) ||
-			    (!chchannel && channel_oil_oif_find(c_oil, pim_ifp->mroute_vif_index))) {
+			/* STAR is owned by the parent, not the child's own join. */
+			if (!pim_upstream_evaluate_join_desired_interface(child, NULL,
+									  chchannelrpt, starch)) {
 				pim_channel_del_inherited_oif(c_oil, ifp,
 						__func__);
 			}
diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c
index 26a9dec1c8..991fc0c80e 100644
--- a/pimd/pim_upstream.c
+++ b/pimd/pim_upstream.c
@@ -1477,33 +1477,6 @@ struct pim_upstream *pim_upstream_add(struct pim_instance *pim, pim_sgaddr *sg,
 	return up;
 }

-/*
- * Passed in up must be the upstream for ch.  starch is NULL if no
- * information
- * This function is copied over from
- * pim_upstream_evaluate_join_desired_interface but limited to
- * parent (*,G)'s includes/joins.
- */
-int pim_upstream_eval_inherit_if(struct pim_upstream *up, struct pim_ifchannel *ch,
-				 struct pim_ifchannel *chrpt, struct pim_ifchannel *starch)
-{
-	/* if there is an explicit prune for this interface we cannot
-	 * add it to the OIL
-	 */
-	if (chrpt)
-		return 0;
-
-	/* Check if the OIF can be inherited from the (*,G) entry
-	 */
-	if (starch) {
-		if (!pim_macro_ch_lost_assert(starch)
-		    && pim_macro_chisin_joins_or_include(starch))
-			return 1;
-	}
-
-	return 0;
-}
-
 /*
  * Passed in up must be the upstream for ch.  starch is NULL if no
  * information
diff --git a/pimd/pim_upstream.h b/pimd/pim_upstream.h
index 064cf09ef8..a3d3302f00 100644
--- a/pimd/pim_upstream.h
+++ b/pimd/pim_upstream.h
@@ -324,8 +324,6 @@ bool pim_upstream_evaluate_join_desired(struct pim_instance *pim,
 int pim_upstream_evaluate_join_desired_interface(struct pim_upstream *up, struct pim_ifchannel *ch,
 						 struct pim_ifchannel *chrpt,
 						 struct pim_ifchannel *starch);
-int pim_upstream_eval_inherit_if(struct pim_upstream *up, struct pim_ifchannel *ch,
-				 struct pim_ifchannel *chrpt, struct pim_ifchannel *starch);
 void pim_upstream_update_join_desired(struct pim_instance *pim,
 				      struct pim_upstream *up);

diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c
index d7684e706e..428be743de 100644
--- a/pimd/pim_zebra.c
+++ b/pimd/pim_zebra.c
@@ -27,6 +27,7 @@
 #include "pim_join.h"
 #include "pim_zlookup.h"
 #include "pim_ifchannel.h"
+#include "pim_macro.h"
 #include "pim_rp.h"
 #include "pim_igmpv3.h"
 #include "pim_jp_agg.h"
@@ -490,10 +491,11 @@ void pim_forward_stop(struct pim_ifchannel *origch)
 			   origch->interface->name, up->channel_oil->installed);

 	/*
-	 * If a channel is being removed, check to see if we still need
-	 * to inherit the interface.  If so make sure it is added in
+	 * Retain PIM ownership only for an active downstream join that has not
+	 * lost Assert. Local membership and inheritance keep their own GM and
+	 * STAR bits.
 	 */
-	if (pim_upstream_evaluate_join_desired_interface(up, ch, chrpt, origch->parent))
+	if (ch && pim_macro_chisin_joins(ch) && !pim_macro_ch_lost_assert(ch))
 		pim_channel_add_oif(up->channel_oil, origch->interface, PIM_OIF_FLAG_PROTO_PIM,
 				    __func__);
 	else