Commit 30c01fe828 for frr

commit 30c01fe82831d150a213539fcbdad7d5825190f9
Author: Lincoln Thurlow <lincoln@isi.edu>
Date:   Tue Dec 1 11:00:45 2026 -0800

    pathd: delete PCE-initiated paths at timeout

    pathd keeps a PCE-initiated path, and its symbolic name, after the
    PCEP session timeout of its PCE expires, so no PCE can initiate a path
    with that name again.

    At the session timeout, pathd only unsets the segment lists of the
    paths, so the policy and candidate path stay without a path. RFC 8281
    section 6 has PCE-initiated LSPs cleaned up when the State Timeout
    Interval expires.

    This commit deletes, at the session timeout of a PCE, the candidate
    paths that PCE initiated, which frees their names, and their policies
    unless they still have other candidate paths.

    Signed-off-by: Lincoln Thurlow <lincoln@isi.edu>

diff --git a/pathd/pathd.c b/pathd/pathd.c
index 5ea23bf730..80c85be6d6 100644
--- a/pathd/pathd.c
+++ b/pathd/pathd.c
@@ -1226,13 +1226,27 @@ void srte_candidate_status_update(struct srte_candidate *candidate, int status)
 	trigger_pathd_candidate_updated(candidate);
 }

+static bool srte_policy_has_other_candidates(struct srte_policy *policy,
+					     struct srte_candidate *candidate)
+{
+	struct srte_candidate *other;
+
+	RB_FOREACH (other, srte_candidate_head, &policy->candidate_paths) {
+		if (other != candidate && !CHECK_FLAG(other->flags, F_CANDIDATE_DELETED))
+			return true;
+	}
+	return false;
+}
+
 /**
- * Flags the segment lists from give originator for removal.
+ * Removes what an originator set up, at its PCEP session timeout.
  *
- * The function srte_apply_changes must be called afterward for
- * the segment list to be removed.
+ * The candidate paths the originator initiated are deleted, with their
+ * policy unless it has other candidate paths. The segment lists it set on
+ * other candidate paths are flagged for removal. The function
+ * srte_apply_changes must be called afterward.
  *
- * @param originator The originator tag of the segment list to be marked
+ * @param originator The originator tag of the paths and segment lists
  */
 void srte_candidate_unset_segment_list(const char *originator)
 {
@@ -1260,6 +1274,15 @@ void srte_candidate_unset_segment_list(const char *originator)
 				continue;
 			}

+			/* At the session timeout, PCE-initiated paths are removed (RFC 8281) */
+			if (candidate->protocol_origin == SRTE_ORIGIN_PCEP &&
+			    strcmp(candidate->originator, originator) == 0) {
+				SET_FLAG(candidate->flags, F_CANDIDATE_DELETED);
+				if (!srte_policy_has_other_candidates(policy, candidate))
+					SET_FLAG(policy->flags, F_POLICY_DELETED);
+				continue;
+			}
+
 			/* The candidate->lsp->segment_list is operational data,
 			 * configured by the PCE. We dont want to modify the
 			 * candidate->segment_list,