[PATCH v3] app/testpmd: validate dscp and vlan table entries for meter creation
Khadem Ullah
14pwcse1224 at uetpeshawar.edu.pk
Thu Aug 28 07:29:01 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 | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
index e16c5b268f..0c5897ada8 100644
--- a/app/test-pmd/cmdline_mtr.c
+++ b/app/test-pmd/cmdline_mtr.c
@@ -85,15 +85,35 @@ parse_uint(uint64_t *value, const char *str)
return 0;
}
+static int
+validate_input_color_table_entries(char *str)
+{
+ char *saveptr;
+ char *token = strtok_r(str, PARSE_DELIMITER, &saveptr);
+ for (int i = 0; token != NULL; i++) {
+ if (i > ((MAX_DSCP_TABLE_ENTRIES + MAX_VLAN_TABLE_ENTRIES) - 1))
+ return -1;
+ token = strtok_r(NULL, PARSE_DELIMITER, &saveptr);
+ }
+ 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 *token, *saveptr;
+ char *temp_str = strdup(str);
int i = 0;
- token = strtok_r(str, PARSE_DELIMITER, &str);
+ if (validate_input_color_table_entries(temp_str)) {
+ free(temp_str);
+ return -1;
+ }
+ free(temp_str);
+
+ token = strtok_r(str, PARSE_DELIMITER, &saveptr);
if (token == NULL)
return 0;
@@ -117,7 +137,7 @@ parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
if (i == MAX_DSCP_TABLE_ENTRIES)
break;
- token = strtok_r(str, PARSE_DELIMITER, &str);
+ token = strtok_r(NULL, PARSE_DELIMITER, &saveptr);
if (token == NULL) {
free(dscp);
return -1;
@@ -126,7 +146,7 @@ parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
*dscp_table = dscp;
- token = strtok_r(str, PARSE_DELIMITER, &str);
+ token = strtok_r(NULL, PARSE_DELIMITER, &saveptr);
if (token == NULL)
return 0;
@@ -154,7 +174,7 @@ parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
if (i == MAX_VLAN_TABLE_ENTRIES)
break;
- token = strtok_r(str, PARSE_DELIMITER, &str);
+ token = strtok_r(NULL, PARSE_DELIMITER, &saveptr);
if (token == NULL) {
free(vlan);
free(*dscp_table);
--
2.43.0
More information about the stable
mailing list