[v3] net/cpfl: fix cpfl parser issue
Checks
Commit Message
CPFL parser was incorrectly parsing the mask value of the
next_proto_id field from recipe.json file as a string
instead of unsigned integer.
Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
Cc: stable@dpdk.org
Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>
---
v2:
* Fixed CI issues.
v3:
* Addressed review comments.
---
drivers/net/cpfl/cpfl_flow_parser.c | 34 +++++++++++++++++++----------
1 file changed, 22 insertions(+), 12 deletions(-)
Comments
On Fri, Aug 23, 2024 at 11:14:50AM +0000, Praveen Shetty wrote:
> CPFL parser was incorrectly parsing the mask value of the
> next_proto_id field from recipe.json file as a string
> instead of unsigned integer.
>
> Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
> Cc: stable@dpdk.org
>
> Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>
>
> ---
> v2:
> * Fixed CI issues.
> v3:
> * Addressed review comments.
> ---
> drivers/net/cpfl/cpfl_flow_parser.c | 34 +++++++++++++++++++----------
> 1 file changed, 22 insertions(+), 12 deletions(-)
>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied to dpdk-next-net-intel,
thanks,
/Bruce
@@ -198,6 +198,8 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
for (i = 0; i < len; i++) {
json_t *object;
const char *name, *mask;
+ uint32_t mask_32b = 0;
+ int ret;
object = json_array_get(ob_fields, i);
name = cpfl_json_t_to_string(object, "name");
@@ -213,20 +215,28 @@ 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) {
+ ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
+ if (ret < 0) {
+ PMD_DRV_LOG(ERR, "Cannot 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 (rte_strscpy(js_field->fields[i].mask,
+ mask, CPFL_JS_STR_SIZE) < 0) {
+ PMD_DRV_LOG(ERR, "The 'mask' is too long.");
+ goto err;
+ }
}
- strncpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
- } else {
- uint32_t mask_32b;
- int ret;
+ } else {
ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
if (ret < 0) {
PMD_DRV_LOG(ERR, "Can not parse uint32 'mask'.");