[PATCH v1] net/cpfl: fix cpfl parser issue

Praveen Shetty praveen.shetty at intel.com
Tue Jul 30 07:09:52 CEST 2024


CPFL parser was incorrectly parsing the mask value of the
next_proto_id field as a string instead of unsigned integer.
This patch will fix this issue.

Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
Cc: stable at dpdk.org

Signed-off-by: Praveen Shetty <praveen.shetty at intel.com>
---
 drivers/net/cpfl/cpfl_flow_parser.c | 31 ++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/net/cpfl/cpfl_flow_parser.c b/drivers/net/cpfl/cpfl_flow_parser.c
index 40569ddc6f..9845bd1ad3 100644
--- a/drivers/net/cpfl/cpfl_flow_parser.c
+++ b/drivers/net/cpfl/cpfl_flow_parser.c
@@ -213,16 +213,29 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
 
 		if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
 		    js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
-			mask = cpfl_json_t_to_string(object, "mask");
-			if (!mask) {
-				PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
-				goto err;
-			}
-			if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
-				PMD_DRV_LOG(ERR, "The 'mask' is too long.");
-				goto err;
+			/* Added a check for parsing mask value of the next_proto_id field. */
+			if (strcmp(name, "next_proto_id") == 0) {
+				uint32_t mask_32b;
+				int ret;
+				ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
+				if (ret < 0) {
+					PMD_DRV_LOG(ERR, "Can not parse uint32 'mask'.");
+					goto err;
+				}
+				js_field->fields[i].mask_32b = mask_32b;
+			} else {
+				mask = cpfl_json_t_to_string(object, "mask");
+				if (!mask) {
+					PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
+					goto err;
+				}
+				if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
+					PMD_DRV_LOG(ERR, "The 'mask' is too long.");
+					goto err;
+				}
+				rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
 			}
-			strncpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
+
 		} else {
 			uint32_t mask_32b;
 			int ret;
-- 
2.34.1



More information about the dev mailing list