Commit eed75f5532 for frr

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

    pathd: prevent duplicate symbolic path names

    pathd accepts a PCInitiate whose symbolic path name is already used
    by another candidate path, configured or initiated by another PCE,
    and creates a second path with the same name.

    path_pcep_config_initiate_path() only looks at the candidate path by
    its color, endpoint, and preference; never by its name. RFC 8281
    section 5.3 requires the PCC to refuse a conflicting name with
    PCErr 23/1 (SYMBOLIC-PATH-NAME in use).

    This commit refuses a PCInitiate with a duplicate name with PCErr
    23/1, and does not create the path. A PCE re-initiating one of its
    own paths still finds it by its color, endpoint and preference. The
    PCErr for a refused PCInitiate now comes from one helper.

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

diff --git a/pathd/path_pcep.c b/pathd/path_pcep.c
index 3acf029cf6..766df5f1c2 100644
--- a/pathd/path_pcep.c
+++ b/pathd/path_pcep.c
@@ -226,41 +226,54 @@ int pcep_main_event_start_sync_cb(struct path *path, void *arg)
 	return 1;
 }

+/* The PCErr for a refused PCInitiate, NULL when it was not refused */
+static struct pcep_error *initiate_error(struct path *path, int ret)
+{
+	struct pcep_error *error;
+	int error_type, error_value;
+
+	switch (ret) {
+	case ERROR_19_1:
+		error_type = PCEP_ERRT_INVALID_OPERATION;
+		error_value = PCEP_ERRV_LSP_UPDATE_FOR_NON_DELEGATED_LSP;
+		break;
+	case ERROR_19_3:
+		error_type = PCEP_ERRT_INVALID_OPERATION;
+		error_value = PCEP_ERRV_LSP_UPDATE_UNKNOWN_PLSP_ID;
+		break;
+	case ERROR_19_9:
+		error_type = PCEP_ERRT_INVALID_OPERATION;
+		error_value = PCEP_ERRV_LSP_NOT_PCE_INITIATED;
+		break;
+	case ERROR_23_1:
+		/* RFC 8281 section 5.3: the symbolic path name is in use */
+		error_type = PCEP_ERRT_BAD_PARAMETER_VALUE;
+		error_value = PCEP_ERRV_SYMBOLIC_PATH_NAME_IN_USE;
+		break;
+	default:
+		return NULL;
+	}
+
+	error = XCALLOC(MTYPE_PCEP, sizeof(*error));
+	error->path = path;
+	error->error_type = error_type;
+	error->error_value = error_value;
+	return error;
+}
+
 int pcep_main_event_initiate_candidate(struct path *path)
 {
+	struct pcep_error *error;
 	int ret = 0;

 	ret = path_pcep_config_initiate_path(path);
-	if (path->do_remove) {
-		struct pcep_error *error;
-		error = XCALLOC(MTYPE_PCEP, sizeof(*error));
-		error->path = path;
-		error->error_type = PCEP_ERRT_INVALID_OPERATION;
-		switch (ret) {
-		case ERROR_19_1:
-			error->error_value =
-				PCEP_ERRV_LSP_UPDATE_FOR_NON_DELEGATED_LSP;
-			break;
-		case ERROR_19_3:
-			error->error_value =
-				PCEP_ERRV_LSP_UPDATE_UNKNOWN_PLSP_ID;
-			break;
-		case ERROR_19_9:
-			error->error_value = PCEP_ERRV_LSP_NOT_PCE_INITIATED;
-			break;
-		default:
-			zlog_warn("(%s)PCE tried to REMOVE unknown error!",
-				  __func__);
-			XFREE(MTYPE_PCEP, error);
-			pcep_free_path(path);
-			return ret;
-			break;
-		}
-		/*
-		 * On error, the path object (linked by error->path) is
-		 * freed after the error message is sent.
-		 */
+	error = initiate_error(path, ret);
+	if (error != NULL) {
+		/* The error frees the path once the PCErr is sent */
 		pcep_ctrl_send_error(pcep_g->fpt, path->pcc_id, error);
+	} else if (path->do_remove) {
+		zlog_warn("(%s)PCE tried to REMOVE unknown error!", __func__);
+		pcep_free_path(path);
 	} else {
 		if (ret != PATH_NB_ERR && path->srp_id != 0)
 			notify_status(path, ret == PATH_NB_NO_CHANGE);
diff --git a/pathd/path_pcep.h b/pathd/path_pcep.h
index 988f7d1262..358d0dd7c4 100644
--- a/pathd/path_pcep.h
+++ b/pathd/path_pcep.h
@@ -298,6 +298,7 @@ struct pcep_error {
 #define ERROR_19_1 1901
 #define ERROR_19_3 1903
 #define ERROR_19_9 1909
+#define ERROR_23_1 2301
 };

 /* Path Helper Functions */
diff --git a/pathd/path_pcep_config.c b/pathd/path_pcep_config.c
index 3b2b6a6731..5ee71d053d 100644
--- a/pathd/path_pcep_config.c
+++ b/pathd/path_pcep_config.c
@@ -30,6 +30,7 @@ static void copy_candidate_affinity_filters(struct srte_candidate *candidate,
 static struct path_hop *
 path_pcep_config_list_path_hops(struct srte_segment_list *segment_list);
 static struct srte_candidate *lookup_candidate(struct lsp_nb_key *key);
+static struct srte_candidate *lookup_candidate_by_name(const char *name);
 static char *candidate_name(struct srte_candidate *candidate);
 static enum pcep_lsp_operational_status
 status_int_to_ext(enum srte_policy_status status);
@@ -311,6 +312,12 @@ int path_pcep_config_initiate_path(struct path *path)

 		candidate = lookup_candidate(&path->nbkey);
 		if (!candidate) {
+			/* The symbolic path name must not be in use (RFC 8281 section 5.3) */
+			if (path->name != NULL && lookup_candidate_by_name(path->name) != NULL) {
+				zlog_warn("PCE %s tried to initiate a path with a symbolic path name already in use: %s",
+					  path->originator, path->name);
+				return ERROR_23_1;
+			}
 			policy = srte_policy_add(
 				path->nbkey.color, &path->nbkey.endpoint,
 				SRTE_ORIGIN_PCEP, path->originator);
@@ -457,6 +464,26 @@ struct srte_candidate *lookup_candidate(struct lsp_nb_key *key)
 	return srte_candidate_find(policy, key->preference);
 }

+struct srte_candidate *lookup_candidate_by_name(const char *name)
+{
+	struct srte_policy *policy;
+	struct srte_candidate *candidate;
+	char *cname;
+	bool match;
+
+	RB_FOREACH (policy, srte_policy_head, &srte_policies) {
+		RB_FOREACH (candidate, srte_candidate_head, &policy->candidate_paths) {
+			cname = candidate_name(candidate);
+			match = strcmp(cname, name) == 0;
+			XFREE(MTYPE_PCEP, cname);
+			if (match)
+				return candidate;
+		}
+	}
+
+	return NULL;
+}
+
 char *candidate_name(struct srte_candidate *candidate)
 {
 	if (candidate->protocol_origin == SRTE_ORIGIN_PCEP
diff --git a/pathd/path_pcep_pcc.c b/pathd/path_pcep_pcc.c
index eb052141a3..fd5c566e41 100644
--- a/pathd/path_pcep_pcc.c
+++ b/pathd/path_pcep_pcc.c
@@ -1343,11 +1343,6 @@ void handle_pcep_lsp_initiate(struct ctrl_state *ctrl_state,
 		}
 	}

-	/* TODO: If there is a conflict with the symbolic path name of an
-	 * existing LSP, the PCC MUST send a PCErr message with Error-type=23
-	 * (Bad Parameter value) and Error-value=1 (SYMBOLIC-PATH-NAME in
-	 * use) */
-
 	specialize_incoming_path(pcc_state, path);
 	/* TODO: Validate the PCC address received from the PCE is valid */
 	PCEP_DEBUG("%s Received LSP initiate", pcc_state->tag);