Commit d7c170f6ea for frr

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

    pathd: hash PCEP segment list names too long

    Two PCEP paths whose names share their first 64 characters get the
    same segment list name, and the second path is refused.

    pathd names the segment list of a PCEP path "<name>-<plsp_id>" and
    cuts it to the 64 characters frr-pathd.yang allows. Locally
    configured dynamic paths report "<policy>-<candidate>" as their name,
    up to 129 characters.

    This commit names the segment list "pcep-hash-" followed by the start
    of the name, a hash of the full name and the PLSP-ID, when
    "<name>-<plsp_id>" does not fit. Names starting with "pcep-hash-" are
    reserved for these: configured segment lists cannot use them, and a
    PCEP path whose name starts with it is always hashed, so a configured
    name never matches a hashed one.

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

diff --git a/pathd/path_nb_config.c b/pathd/path_nb_config.c
index 88f5281ebd..363a491fe2 100644
--- a/pathd/path_nb_config.c
+++ b/pathd/path_nb_config.c
@@ -32,6 +32,12 @@ int pathd_srte_segment_list_create(struct nb_cb_create_args *args)
 	if (args->event == NB_EV_VALIDATE) {
 		/* Refuse names reserved for, or already used by PCEP */
 		name = yang_dnode_get_string(args->dnode, "name");
+		if (strncmp(name, SRTE_PCEP_HASHED_PREFIX, strlen(SRTE_PCEP_HASHED_PREFIX)) == 0) {
+			snprintfrr(args->errmsg, args->errmsg_len,
+				   "Segment list names starting with %s are reserved for PCEP",
+				   SRTE_PCEP_HASHED_PREFIX);
+			return NB_ERR_VALIDATION;
+		}
 		segment_list = srte_segment_list_find(name);
 		if (segment_list != NULL && segment_list->protocol_origin == SRTE_ORIGIN_PCEP) {
 			snprintfrr(args->errmsg, args->errmsg_len,
diff --git a/pathd/path_pcep_config.c b/pathd/path_pcep_config.c
index 0a440e2227..7df85ba9bc 100644
--- a/pathd/path_pcep_config.c
+++ b/pathd/path_pcep_config.c
@@ -8,6 +8,7 @@
 #include <northbound.h>
 #include <yang.h>
 #include <printfrr.h>
+#include "jhash.h"
 #include "pceplib/pcep_msg_objects.h"
 #include "pathd/pathd.h"
 #include "pathd/path_pcep.h"
@@ -31,6 +32,8 @@ 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 void pcep_segment_list_name(char *buf, size_t size, struct path *path);
+static bool path_name_reserved(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);
@@ -371,7 +374,7 @@ int path_pcep_config_update_path(struct path *path)
 	struct path_hop *hop;
 	struct path_metric *metric;
 	int index;
-	char segment_list_name_buff[64 + 1 + 64 + 1 + 11 + 1];
+	char segment_list_name_buff[SRTE_NAME_LENGTH];
 	char *segment_list_name = NULL;
 	struct srte_candidate *candidate;
 	struct srte_segment_list *segment_list = NULL;
@@ -395,8 +398,7 @@ int path_pcep_config_update_path(struct path *path)
 	if (path->first_hop == NULL)
 		return PATH_NB_ERR;

-	snprintf(segment_list_name_buff, sizeof(segment_list_name_buff),
-		 "%s-%u", path->name, path->plsp_id);
+	pcep_segment_list_name(segment_list_name_buff, sizeof(segment_list_name_buff), path);
 	segment_list_name = segment_list_name_buff;

 	segment_list = srte_segment_list_add(segment_list_name);
@@ -489,6 +491,27 @@ struct srte_candidate *lookup_candidate_by_name(const char *name)
 	return NULL;
 }

+/* "<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)
+{
+	uint32_t hash;
+
+	if (!path_name_reserved(path) &&
+	    snprintfrr(buf, size, "%s-%u", path->name, path->plsp_id) < (ssize_t)size)
+		return;
+
+	hash = jhash(path->name, strlen(path->name), 0);
+	snprintfrr(buf, size, SRTE_PCEP_HASHED_PREFIX "%.*s-%08x-%u",
+		   (int)(SRTE_YANG_NAME_MAX_LENGTH - 20 - strlen(SRTE_PCEP_HASHED_PREFIX)),
+		   path->name, hash, path->plsp_id);
+}
+
+bool path_name_reserved(struct path *path)
+{
+	return path->name != NULL &&
+	       strncmp(path->name, SRTE_PCEP_HASHED_PREFIX, strlen(SRTE_PCEP_HASHED_PREFIX)) == 0;
+}
+
 char *candidate_name(struct srte_candidate *candidate)
 {
 	if (candidate->protocol_origin == SRTE_ORIGIN_PCEP
diff --git a/pathd/pathd.h b/pathd/pathd.h
index 7fc21dbe31..ee1d10f09c 100644
--- a/pathd/pathd.h
+++ b/pathd/pathd.h
@@ -198,6 +198,8 @@ RB_PROTOTYPE(srte_segment_entry_head, srte_segment_entry, entry,
 /* Name length limit in frr-pathd.yang */
 #define SRTE_YANG_NAME_MAX_LENGTH 64
 #define SRTE_NAME_LENGTH	  (SRTE_YANG_NAME_MAX_LENGTH + 1)
+/* Prefix of hashed PCEP segment list names, reserved from configuration */
+#define SRTE_PCEP_HASHED_PREFIX "pcep-hash-"

 struct srte_segment_list {
 	RB_ENTRY(srte_segment_list) entry;