[PATCH v2] app/testpmd: validate dscp and vlan table entries for meter creation

Khadem Ullah 14pwcse1224 at uetpeshawar.edu.pk
Wed Aug 27 13:18:37 CEST 2025


Add validation mechanism for meter creation. The maximum
possible entries are
[<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>]
[<vlan_tbl_entry0> <vlan_tbl_entry1> ... <vlan_tbl_entry15>].
Currently, testpmd allows any input table entries for dscp
and vlan tables.

This patch validates the maximum possible dscp and vlan table
entries for meter creation.

Fixes: 9f5488e326d3b ("app/testpmd: support different input color method")
Cc: stable at dpdk.org

Signed-off-by: Khadem Ullah <14pwcse1224 at uetpeshawar.edu.pk>
---
 app/test-pmd/cmdline_mtr.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
index e16c5b268f..256d5b4238 100644
--- a/app/test-pmd/cmdline_mtr.c
+++ b/app/test-pmd/cmdline_mtr.c
@@ -85,14 +85,33 @@ parse_uint(uint64_t *value, const char *str)
 	return 0;
 }
 
+static int
+validate_input_color_table_entries(char *str)
+{
+	char *token = strtok_r(str, PARSE_DELIMITER, &str);
+	for (int i = 0; token != NULL; i++) {
+		if (i > ((MAX_DSCP_TABLE_ENTRIES + MAX_VLAN_TABLE_ENTRIES) - 1))
+			return -1;
+		token = strtok_r(str, PARSE_DELIMITER, &str);
+	}
+	return 0;
+}
+
 static int
 parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
 	enum rte_color **vlan_table)
 {
 	enum rte_color *vlan, *dscp;
 	char *token;
+	char *temp_str = strdup(str);
 	int i = 0;
 
+	if (validate_input_color_table_entries(temp_str)) {
+		free(temp_str);
+		return -1;
+	}
+	free(temp_str);
+
 	token = strtok_r(str, PARSE_DELIMITER, &str);
 	if (token == NULL)
 		return 0;
-- 
2.43.0



More information about the stable mailing list