Commit 414203956a for frr

commit 414203956a62ed83bd95b1e220b055f04c07279b
Author: Lincoln Thurlow <lincoln@isi.edu>
Date:   Tue Dec 1 11:00:46 2026 -0800

    pathd: let a PCE take over orphaned paths

    A path initiated by a PCE that went down is removed at that PCE's
    session timeout even when another PCE is ready to manage it, and that
    PCE cannot take it over: a PCInitiate carrying its PLSP-ID is refused
    with PCErr 19/8.

    pathd refuses any PCInitiate with a non-zero PLSP-ID, so it does not
    support the takeover RFC 8281 section 6 defines. That is also the
    exception RFC 8281 section 5.3 makes to the symbolic path name check,
    for LSPs whose State Timeout Interval is running.

    This commit implements the takeover. A PCInitiate with the PLSP-ID of
    a path whose PCE's session timeout is running moves the path to the
    PCE that sent it, which stops the old PCE's timeout from removing it.
    As section 6 specifies, any other non-zero PLSP-ID gets the section
    5.4 errors: PCErr 19/3 for an unknown PLSP-ID, 19/9 for a path that
    is not PCE-initiated, and 19/1 for a path still delegated to a
    connected PCE.

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

diff --git a/pathd/path_pcep_config.c b/pathd/path_pcep_config.c
index 4b5ce1d28b..02a69824b0 100644
--- a/pathd/path_pcep_config.c
+++ b/pathd/path_pcep_config.c
@@ -36,6 +36,7 @@ static void pcep_segment_list_name(char *buf, size_t size, struct path *path);
 static bool segment_list_name_taken(struct path *path, struct srte_candidate *candidate);
 static bool path_name_too_long(struct path *path);
 static bool path_name_reserved(struct path *path);
+static int path_pcep_config_adopt_path(struct path *path);
 static char *candidate_name(struct srte_candidate *candidate);
 static enum pcep_lsp_operational_status
 status_int_to_ext(enum srte_policy_status status);
@@ -277,6 +278,9 @@ int path_pcep_config_initiate_path(struct path *path)
 	struct srte_policy *policy;
 	struct srte_candidate *candidate;

+	if (!path->do_remove && path->plsp_id != 0)
+		return path_pcep_config_adopt_path(path);
+
 	if (path->do_remove) {
 		zlog_warn("PCE %s tried to REMOVE pce-initiate a path ",
 			  path->originator);
@@ -517,6 +521,43 @@ struct srte_candidate *lookup_candidate_by_name(const char *name)
 	return NULL;
 }

+/* RFC 8281 section 6: a PCE takes over an orphaned PCE-initiated path */
+int path_pcep_config_adopt_path(struct path *path)
+{
+	struct srte_candidate *candidate = lookup_candidate(&path->nbkey);
+	struct srte_segment_list *segment_list;
+
+	/* Any other PLSP-ID gets the section 5.4 errors */
+	if (candidate == NULL) {
+		zlog_warn("PCE %s tried to take over unknown PLSP-ID %u", path->originator,
+			  path->plsp_id);
+		return ERROR_19_3;
+	}
+	if (candidate->protocol_origin != SRTE_ORIGIN_PCEP) {
+		zlog_warn("PCE %s tried to take over path %s, which is not PCE-initiated",
+			  path->originator, candidate->name);
+		return ERROR_19_9;
+	}
+	if (!pcep_originator_orphaned(candidate->originator)) {
+		zlog_warn("PCE %s tried to take over path %s, still delegated to PCE %s",
+			  path->originator, candidate->name, candidate->originator);
+		return ERROR_19_1;
+	}
+
+	zlog_info("PCE %s takes over path %s from PCE %s", path->originator, candidate->name,
+		  candidate->originator);
+	strlcpy(candidate->originator, path->originator, sizeof(candidate->originator));
+	strlcpy(candidate->policy->originator, path->originator,
+		sizeof(candidate->policy->originator));
+	segment_list = candidate->lsp ? candidate->lsp->segment_list : NULL;
+	if (segment_list != NULL && segment_list->protocol_origin == SRTE_ORIGIN_PCEP)
+		strlcpy(segment_list->originator, path->originator,
+			sizeof(segment_list->originator));
+	candidate->policy->srp_id = path->srp_id;
+
+	return PATH_NB_NO_CHANGE;
+}
+
 /* "<name>-<plsp_id>", hashed if too long or in the reserved namespace */
 void pcep_segment_list_name(char *buf, size_t size, struct path *path)
 {
diff --git a/pathd/path_pcep_pcc.c b/pathd/path_pcep_pcc.c
index 9827af92bc..ec067e2899 100644
--- a/pathd/path_pcep_pcc.c
+++ b/pathd/path_pcep_pcc.c
@@ -1279,6 +1279,23 @@ void handle_pcep_lsp_initiate(struct ctrl_state *ctrl_state,
 				break;
 			}
 		}
+	} else if (path->plsp_id != 0) {
+		/* RFC 8281 section 6: taking over an orphan by its PLSP-ID */
+		struct nbkey_map_data key, *mapping;
+
+		key.plspid = path->plsp_id;
+		mapping = nbkey_map_find(&pcc_state->nbkey_map, &key);
+		if (mapping == NULL) {
+			/* An unknown PLSP-ID gets PCErr 19/3 (RFC 8281 section 5.4) */
+			flog_warn(EC_PATH_PCEP_PROTOCOL_ERROR,
+				  "PCE initiated path with unknown PLSP ID: %s",
+				  format_pcep_message(msg));
+			send_pcep_error(pcc_state, PCEP_ERRT_INVALID_OPERATION,
+					PCEP_ERRV_LSP_UPDATE_UNKNOWN_PLSP_ID, path);
+			pcep_free_path(path);
+			return;
+		}
+		path->nbkey = mapping->nbkey;
 	} else {
 		if (path->first_hop == NULL /*ero sets first_hop*/) {
 			/* If the PCC receives a PCInitiate message without an
@@ -1296,23 +1313,6 @@ void handle_pcep_lsp_initiate(struct ctrl_state *ctrl_state,
 			return;
 		}

-		if (path->plsp_id != 0) {
-			/* If the PCC receives a PCInitiate message with a
-			 * non-zero PLSP-ID and the R flag in the SRP object set
-			 * to zero, then it MUST send a PCErr message with
-			 * Error-type=19 (Invalid Operation) and Error-value=8
-			 * (Non-zero PLSP-ID in the LSP Initiate Request) */
-			flog_warn(
-				EC_PATH_PCEP_PROTOCOL_ERROR,
-				"PCE initiated path with non-zero PLSP ID: %s",
-				format_pcep_message(msg));
-			send_pcep_error(pcc_state, PCEP_ERRT_INVALID_OPERATION,
-					PCEP_ERRV_LSP_INIT_NON_ZERO_PLSP_ID,
-					path);
-			pcep_free_path(path);
-			return;
-		}
-
 		if (path->name == NULL) {
 			/* If the PCC receives a PCInitiate message without a
 			 * SYMBOLIC-PATH-NAME TLV, then it MUST send a PCErr