Commit 775c86e94a for frr

commit 775c86e94ac82aad15ca553c65a4884c1e0e9523
Author: Enke Chen <enchen@paloaltonetworks.com>
Date:   Wed Nov 18 16:34:56 2026 -0800

    bgpd: remove SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED flag

    Follow-up to 6d90893361 ("bgpd: replace SUBGRP_STATUS_DEFAULT_ORIGINATE
    with default_originate_attr"), which replaced SUBGRP_STATUS_DEFAULT_ORIGINATE
    with default_originate_attr as the sentinel for the synthesized default
    route.

    SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED was used solely to gate scount
    increments/decrements inside the packet-send functions, ensuring the
    sent-prefix counter is adjusted only on the first send and the final
    withdraw rather than on every re-evaluation.

    Now that default_originate_attr already encodes this state (non-NULL
    iff the synthesized default is currently active), the flag is redundant.
    Move the scount adjustments to the callers in bgp_updgrp_adv.c where
    the before/after state of default_originate_attr is directly visible:

      - scount++ when default_originate_attr transitions NULL -> non-NULL
        (first origination of the synthesized default)
      - scount-- at each withdraw call site, all of which are already
        guarded by "if (subgrp->default_originate_attr)"

    Both adjustments are guarded by !DISABLE_BGP_ANNOUNCE, matching the
    original placement after the early-return check inside the packet
    functions, so pfxSnt is not inflated when announce is disabled.

    Remove the flag definition, its comment, and all manipulation from
    subgroup_default_update_packet() and subgroup_default_withdraw_packet().

    Signed-off-by: Enke Chen <enchen@paloaltonetworks.com>

diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h
index 3b27d1a3fc..e1cc322ae6 100644
--- a/bgpd/bgp_updgrp.h
+++ b/bgpd/bgp_updgrp.h
@@ -244,13 +244,6 @@ struct update_subgroup {
 	uint16_t sflags;
 #define SUBGRP_STATUS_FORCE_UPDATES (1 << 1)
 #define SUBGRP_STATUS_TABLE_REPARSING (1 << 2)
-/*
- * This flag has been added to ensure that the SNT counters
- * gets incremented and decremented only during the creation
- * and deletion workflows of default originate,
- * not during the update workflow.
- */
-#define SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED (1 << 3)

 	/*
 	 * Interned attributes of the synthesized default route sent via
diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c
index a289d74978..5e4224b700 100644
--- a/bgpd/bgp_updgrp_adv.c
+++ b/bgpd/bgp_updgrp_adv.c
@@ -1134,6 +1134,8 @@ void subgroup_default_originate_unconfig(struct update_subgroup *subgrp)
 		if (bgp_debug_update(NULL, &p, subgrp->update_group, 0))
 			zlog_debug("u%" PRIu64 ":s%" PRIu64 " default-originate WITHDRAW (unset)",
 				   subgrp->update_group->id, subgrp->id);
+		if (!DISABLE_BGP_ANNOUNCE)
+			subgrp->scount--;
 		bgp_attr_unintern(&subgrp->default_originate_attr);
 		subgrp->default_originate_attr = NULL;
 		subgroup_default_withdraw_packet(subgrp);
@@ -1346,6 +1348,8 @@ rmap_done:;
 			if (do_debug)
 				zlog_debug("u%" PRIu64 ":s%" PRIu64 " default-originate WITHDRAW",
 					   subgrp->update_group->id, subgrp->id);
+			if (!DISABLE_BGP_ANNOUNCE)
+				subgrp->scount--;
 			bgp_attr_unintern(&subgrp->default_originate_attr);
 			subgrp->default_originate_attr = NULL;
 			subgroup_default_withdraw_packet(subgrp);
@@ -1377,6 +1381,8 @@ rmap_done:;
 						zlog_debug("u%" PRIu64 ":s%" PRIu64
 							   " default-originate WITHDRAW (route-map deny)",
 							   subgrp->update_group->id, subgrp->id);
+					if (!DISABLE_BGP_ANNOUNCE)
+						subgrp->scount--;
 					bgp_attr_unintern(&subgrp->default_originate_attr);
 					subgrp->default_originate_attr = NULL;
 					subgroup_default_withdraw_packet(subgrp);
@@ -1422,6 +1428,8 @@ rmap_done:;
 					   subgrp->update_group->id, subgrp->id);
 			if (subgrp->default_originate_attr)
 				bgp_attr_unintern(&subgrp->default_originate_attr);
+			else if (!DISABLE_BGP_ANNOUNCE)
+				subgrp->scount++;
 			subgrp->default_originate_attr = new_interned;
 			subgroup_default_update_packet(subgrp, new_interned, from);
 		} else if (!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES) ||
diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c
index 7e27c39481..69a3381f57 100644
--- a/bgpd/bgp_updgrp_packet.c
+++ b/bgpd/bgp_updgrp_packet.c
@@ -1322,12 +1322,6 @@ void subgroup_default_update_packet(struct update_subgroup *subgrp,

 	(void)bpacket_queue_add(SUBGRP_PKTQ(subgrp), s, &vecarr);
 	subgroup_trigger_write(subgrp);
-
-	if (!CHECK_FLAG(subgrp->sflags,
-			SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED)) {
-		subgrp->scount++;
-		SET_FLAG(subgrp->sflags, SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED);
-	}
 }

 /*
@@ -1504,12 +1498,6 @@ void subgroup_default_withdraw_packet(struct update_subgroup *subgrp)

 	(void)bpacket_queue_add(SUBGRP_PKTQ(subgrp), s, NULL);
 	subgroup_trigger_write(subgrp);
-
-	if (CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED)) {
-		subgrp->scount--;
-		UNSET_FLAG(subgrp->sflags,
-			   SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED);
-	}
 }

 static void