patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 2/3] examples/l3fwd: fix return value on rules add
       [not found] <20240715101458.645014-1-g.singh@nxp.com>
@ 2024-07-15 10:14 ` Gagandeep Singh
  2024-07-16  6:55   ` Hemant Agrawal
  2024-07-15 10:14 ` [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes Gagandeep Singh
       [not found] ` <20240806034120.3165295-1-g.singh@nxp.com>
  2 siblings, 1 reply; 12+ messages in thread
From: Gagandeep Singh @ 2024-07-15 10:14 UTC (permalink / raw)
  To: dev, Sean Morrissey, Konstantin Ananyev; +Cc: stable

fix return value on adding the EM or LPM rules.

Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
Fixes: 52def963fc1c ("examples/l3fwd: support config file for LPM/FIB")
Cc: sean.morrissey@intel.com
Cc: stable@dpdk.org

Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
---
 examples/l3fwd/em_route_parse.c  | 11 ++++++-----
 examples/l3fwd/lpm_route_parse.c | 11 ++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/examples/l3fwd/em_route_parse.c b/examples/l3fwd/em_route_parse.c
index da23356dd6..8b534de5f1 100644
--- a/examples/l3fwd/em_route_parse.c
+++ b/examples/l3fwd/em_route_parse.c
@@ -119,7 +119,7 @@ em_add_rules(const char *rule_path,
 	char buff[LINE_MAX];
 	FILE *fh;
 	unsigned int i = 0, rule_size = sizeof(*next);
-	int val;
+	int val, rc;
 
 	*proute_base = NULL;
 	fh = fopen(rule_path, "rb");
@@ -172,13 +172,14 @@ em_add_rules(const char *rule_path,
 			return -EINVAL;
 		}
 
-		if (parser(buff + 1, next) != 0) {
+		rc = parser(buff + 1, next);
+		if (rc != 0) {
 			RTE_LOG(ERR, L3FWD,
-				"%s Line %u: parse rules error\n",
-				rule_path, i);
+				"%s Line %u: parse rules error code = %d\n",
+				rule_path, i, rc);
 			fclose(fh);
 			free(route_rules);
-			return -EINVAL;
+			return rc;
 		}
 
 		route_cnt++;
diff --git a/examples/l3fwd/lpm_route_parse.c b/examples/l3fwd/lpm_route_parse.c
index f7d44aa2cd..f27b66e838 100644
--- a/examples/l3fwd/lpm_route_parse.c
+++ b/examples/l3fwd/lpm_route_parse.c
@@ -184,7 +184,7 @@ lpm_add_rules(const char *rule_path,
 	char buff[LINE_MAX];
 	FILE *fh;
 	unsigned int i = 0, rule_size = sizeof(*next);
-	int val;
+	int val, rc;
 
 	*proute_base = NULL;
 	fh = fopen(rule_path, "rb");
@@ -237,13 +237,14 @@ lpm_add_rules(const char *rule_path,
 			return -EINVAL;
 		}
 
-		if (parser(buff + 1, next) != 0) {
+		rc = parser(buff + 1, next);
+		if (rc != 0) {
 			RTE_LOG(ERR, L3FWD,
-				"%s Line %u: parse rules error\n",
-				rule_path, i);
+				"%s Line %u: parse rules error code = %d\n",
+				rule_path, i, rc);
 			fclose(fh);
 			free(route_rules);
-			return -EINVAL;
+			return rc;
 		}
 
 		route_cnt++;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
       [not found] <20240715101458.645014-1-g.singh@nxp.com>
  2024-07-15 10:14 ` [PATCH 2/3] examples/l3fwd: fix return value on rules add Gagandeep Singh
@ 2024-07-15 10:14 ` Gagandeep Singh
  2024-07-17 10:17   ` Konstantin Ananyev
       [not found] ` <20240806034120.3165295-1-g.singh@nxp.com>
  2 siblings, 1 reply; 12+ messages in thread
From: Gagandeep Singh @ 2024-07-15 10:14 UTC (permalink / raw)
  To: dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable

Application is accepting routes for port ID up to UINT8_MAX
for LPM amd EM routes on parsing the given rule file, but only
up to 32 ports can be enabled as per the variable enabled_port_mask
which is defined as uint32_t.

This patch restricts the rules parsing code to accept routes for
port ID up to 31 only to avoid any unnecessary maintenance of rules
which will never be used.

Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
Fixes: 52def963fc1c ("examples/l3fwd: support config file for LPM/FIB")
Cc: sean.morrissey@intel.com
Cc: stable@dpdk.org

Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
---
 examples/l3fwd/em_route_parse.c  | 6 ++++--
 examples/l3fwd/lpm_route_parse.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/examples/l3fwd/em_route_parse.c b/examples/l3fwd/em_route_parse.c
index 8b534de5f1..65c71cd1ba 100644
--- a/examples/l3fwd/em_route_parse.c
+++ b/examples/l3fwd/em_route_parse.c
@@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
 	/* protocol. */
 	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
 	/* out interface. */
-	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
+	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
+			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
 
 	return 0;
 }
@@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
 	/* protocol. */
 	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
 	/* out interface. */
-	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
+	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
+			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
 
 	return 0;
 }
diff --git a/examples/l3fwd/lpm_route_parse.c b/examples/l3fwd/lpm_route_parse.c
index f27b66e838..357c12d9fe 100644
--- a/examples/l3fwd/lpm_route_parse.c
+++ b/examples/l3fwd/lpm_route_parse.c
@@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct lpm_route_rule *v)
 
 	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32, &v->depth);
 
-	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
+	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
+			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
 
 	return rc;
 }
@@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct lpm_route_rule *v)
 
 	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip, &v->depth);
 
-	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
+	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
+			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
 
 	return rc;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] examples/l3fwd: fix return value on rules add
  2024-07-15 10:14 ` [PATCH 2/3] examples/l3fwd: fix return value on rules add Gagandeep Singh
@ 2024-07-16  6:55   ` Hemant Agrawal
  0 siblings, 0 replies; 12+ messages in thread
From: Hemant Agrawal @ 2024-07-16  6:55 UTC (permalink / raw)
  To: Gagandeep Singh, dev, Sean Morrissey, Konstantin Ananyev; +Cc: stable


On 15-07-2024 15:44, Gagandeep Singh wrote:
> fix return value on adding the EM or LPM rules.
>
> Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
> Fixes: 52def963fc1c ("examples/l3fwd: support config file for LPM/FIB")
> Cc: sean.morrissey@intel.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Gagandeep Singh <g.singh@nxp.com>


Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-15 10:14 ` [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes Gagandeep Singh
@ 2024-07-17 10:17   ` Konstantin Ananyev
  2024-07-18  6:30     ` Gagandeep Singh
  0 siblings, 1 reply; 12+ messages in thread
From: Konstantin Ananyev @ 2024-07-17 10:17 UTC (permalink / raw)
  To: Gagandeep Singh, dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable



> Application is accepting routes for port ID up to UINT8_MAX
> for LPM amd EM routes on parsing the given rule file, but only
> up to 32 ports can be enabled as per the variable enabled_port_mask
> which is defined as uint32_t.
> 
> This patch restricts the rules parsing code to accept routes for
> port ID up to 31 only to avoid any unnecessary maintenance of rules
> which will never be used.

If we want to add this extra check, probably better to do it in setup_lpm().
Where we already check that port is enabled, and If not, then this route rule will be skipped:

        /* populate the LPM table */
        for (i = 0; i < route_num_v4; i++) {
                struct in_addr in;

                /* skip unused ports */
                if ((1 << route_base_v4[i].if_out &
                                enabled_port_mask) == 0)
                        continue;

Same for EM.
Another question here - why we just silently skip the rule with invalid port?
Probably need to fail with error... that what ACL code-path does.

> Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
> Fixes: 52def963fc1c ("examples/l3fwd: support config file for LPM/FIB")
> Cc: sean.morrissey@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> ---
>  examples/l3fwd/em_route_parse.c  | 6 ++++--
>  examples/l3fwd/lpm_route_parse.c | 6 ++++--
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/examples/l3fwd/em_route_parse.c b/examples/l3fwd/em_route_parse.c
> index 8b534de5f1..65c71cd1ba 100644
> --- a/examples/l3fwd/em_route_parse.c
> +++ b/examples/l3fwd/em_route_parse.c
> @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
>  	/* protocol. */
>  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
>  	/* out interface. */
> -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>  	return 0;
>  }
> @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
>  	/* protocol. */
>  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
>  	/* out interface. */
> -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>  	return 0;
>  }
> diff --git a/examples/l3fwd/lpm_route_parse.c b/examples/l3fwd/lpm_route_parse.c
> index f27b66e838..357c12d9fe 100644
> --- a/examples/l3fwd/lpm_route_parse.c
> +++ b/examples/l3fwd/lpm_route_parse.c
> @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct lpm_route_rule *v)
> 
>  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32, &v->depth);
> 
> -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>  	return rc;
>  }
> @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct lpm_route_rule *v)
> 
>  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip, &v->depth);
> 
> -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>  	return rc;
>  }
> --
> 2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-17 10:17   ` Konstantin Ananyev
@ 2024-07-18  6:30     ` Gagandeep Singh
  2024-07-18 10:01       ` Konstantin Ananyev
  0 siblings, 1 reply; 12+ messages in thread
From: Gagandeep Singh @ 2024-07-18  6:30 UTC (permalink / raw)
  To: Konstantin Ananyev, dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable

Hi,

> -----Original Message-----
> From: Konstantin Ananyev <konstantin.ananyev@huawei.com>
> Sent: Wednesday, July 17, 2024 3:48 PM
> To: Gagandeep Singh <G.Singh@nxp.com>; dev@dpdk.org; Konstantin Ananyev
> <konstantin.v.ananyev@yandex.ru>; Sean Morrissey
> <sean.morrissey@intel.com>
> Cc: stable@dpdk.org
> Subject: RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in
> routes
> 
> 
> 
> > Application is accepting routes for port ID up to UINT8_MAX for LPM
> > amd EM routes on parsing the given rule file, but only up to 32 ports
> > can be enabled as per the variable enabled_port_mask which is defined
> > as uint32_t.
> >
> > This patch restricts the rules parsing code to accept routes for port
> > ID up to 31 only to avoid any unnecessary maintenance of rules which
> > will never be used.
> 
> If we want to add this extra check, probably better to do it in setup_lpm().
> Where we already check that port is enabled, and If not, then this route rule will
> be skipped:
> 
>         /* populate the LPM table */
>         for (i = 0; i < route_num_v4; i++) {
>                 struct in_addr in;
> 
>                 /* skip unused ports */
>                 if ((1 << route_base_v4[i].if_out &
>                                 enabled_port_mask) == 0)
>                         continue;
> 
> Same for EM.
I am trying to update the check for MAX if_out value in rules config file parsing which will be before setup_lpm().  
The reason is, restricting and adding only those rules which can be used by the application
while populating the route_base_v4/v6 at first step and avoid unnecessary memory allocation
for local variables to store more not required rules.

> ((1 << route_base_v4[i].if_out &
>                                 enabled_port_mask)
By looking into this check, it seems restriction to maximum 31 port ID while parsing rule file becomes
more valid as this check can pass due to overflow in case value of route_base_v4[i].if_out
Is 31+.

> Another question here - why we just silently skip the rule with invalid port?
In read_config_files_lpm() we are calling the rte_exit in case port ID is 31+.
In setup_lpm, skipping the rules for the ports which are not enabled and not giving error,
I guess probably because of ease of use.
e.g. user has only single ipv4_routes config file with route rules for port ID 0,1,2,3,4
and want to use same file for multiple test cases like
1. when only port 0 enabled
2. when only port 0 and 1 enabled and so on.
In this case, user can avoid to have separate route files for each of the test case.

> Probably need to fail with error... that what ACL code-path does.
> 
> > Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
> > Fixes: 52def963fc1c ("examples/l3fwd: support config file for
> > LPM/FIB")
> > Cc: sean.morrissey@intel.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > ---
> >  examples/l3fwd/em_route_parse.c  | 6 ++++--
> > examples/l3fwd/lpm_route_parse.c | 6 ++++--
> >  2 files changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/examples/l3fwd/em_route_parse.c
> > b/examples/l3fwd/em_route_parse.c index 8b534de5f1..65c71cd1ba 100644
> > --- a/examples/l3fwd/em_route_parse.c
> > +++ b/examples/l3fwd/em_route_parse.c
> > @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
> >  	/* protocol. */
> >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
> >  	/* out interface. */
> > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> >
> >  	return 0;
> >  }
> > @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
> >  	/* protocol. */
> >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
> >  	/* out interface. */
> > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> >
> >  	return 0;
> >  }
> > diff --git a/examples/l3fwd/lpm_route_parse.c
> > b/examples/l3fwd/lpm_route_parse.c
> > index f27b66e838..357c12d9fe 100644
> > --- a/examples/l3fwd/lpm_route_parse.c
> > +++ b/examples/l3fwd/lpm_route_parse.c
> > @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct lpm_route_rule
> > *v)
> >
> >  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32, &v->depth);
> >
> > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> >
> >  	return rc;
> >  }
> > @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct lpm_route_rule
> > *v)
> >
> >  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip, &v->depth);
> >
> > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> >
> >  	return rc;
> >  }
> > --
> > 2.25.1

Gagan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-18  6:30     ` Gagandeep Singh
@ 2024-07-18 10:01       ` Konstantin Ananyev
  2024-07-22  3:28         ` Gagandeep Singh
  0 siblings, 1 reply; 12+ messages in thread
From: Konstantin Ananyev @ 2024-07-18 10:01 UTC (permalink / raw)
  To: Gagandeep Singh, dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable



> > > Application is accepting routes for port ID up to UINT8_MAX for LPM
> > > amd EM routes on parsing the given rule file, but only up to 32 ports
> > > can be enabled as per the variable enabled_port_mask which is defined
> > > as uint32_t.
> > >
> > > This patch restricts the rules parsing code to accept routes for port
> > > ID up to 31 only to avoid any unnecessary maintenance of rules which
> > > will never be used.
> >
> > If we want to add this extra check, probably better to do it in setup_lpm().
> > Where we already check that port is enabled, and If not, then this route rule will
> > be skipped:
> >
> >         /* populate the LPM table */
> >         for (i = 0; i < route_num_v4; i++) {
> >                 struct in_addr in;
> >
> >                 /* skip unused ports */
> >                 if ((1 << route_base_v4[i].if_out &
> >                                 enabled_port_mask) == 0)
> >                         continue;
> >
> > Same for EM.
> I am trying to update the check for MAX if_out value in rules config file parsing which will be before setup_lpm().
> The reason is, restricting and adding only those rules which can be used by the application
> while populating the route_base_v4/v6 at first step and avoid unnecessary memory allocation
> for local variables to store more not required rules.

Hmm... but why it is a problem?
 
> 
> > ((1 << route_base_v4[i].if_out &
> >                                 enabled_port_mask)
> By looking into this check, it seems restriction to maximum 31 port ID while parsing rule file becomes
> more valid as this check can pass due to overflow in case value of route_base_v4[i].if_out
> Is 31+.

Agree, I think we need both, and it probably need to be in setup_lpm().
Something like:

if (route_base_v4[i].if_out >= sizeof(enabled_port_mask) * CHAR_BIT ||
   ((1 << route_base_v4[i].if_out & enabled_port_mask) == 0) {
     /* print some error message here*/
     rte_exiit(...);  /* or return an error */
} 
   
> 
> > Another question here - why we just silently skip the rule with invalid port?
> In read_config_files_lpm() we are calling the rte_exit in case port ID is 31+.
> In setup_lpm, skipping the rules for the ports which are not enabled and not giving error,
> I guess probably because of ease of use.
> e.g. user has only single ipv4_routes config file with route rules for port ID 0,1,2,3,4
> and want to use same file for multiple test cases like
> 1. when only port 0 enabled
> 2. when only port 0 and 1 enabled and so on.
> In this case, user can avoid to have separate route files for each of the test case.

The problem as I see it - we are not consistent here.
In some cases we just silently skip rules with invalid (or disabled) port numbers,
in other cases we generate an error and exit.
For me it would be better, if we follow one simple policy (abort with error) here for all cases.
 
> 
> > Probably need to fail with error... that what ACL code-path does.
> >
> > > Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
> > > Fixes: 52def963fc1c ("examples/l3fwd: support config file for
> > > LPM/FIB")
> > > Cc: sean.morrissey@intel.com
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > > ---
> > >  examples/l3fwd/em_route_parse.c  | 6 ++++--
> > > examples/l3fwd/lpm_route_parse.c | 6 ++++--
> > >  2 files changed, 8 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/examples/l3fwd/em_route_parse.c
> > > b/examples/l3fwd/em_route_parse.c index 8b534de5f1..65c71cd1ba 100644
> > > --- a/examples/l3fwd/em_route_parse.c
> > > +++ b/examples/l3fwd/em_route_parse.c
> > > @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
> > >  	/* protocol. */
> > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
> > >  	/* out interface. */
> > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > >
> > >  	return 0;
> > >  }
> > > @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
> > >  	/* protocol. */
> > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
> > >  	/* out interface. */
> > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > >
> > >  	return 0;
> > >  }
> > > diff --git a/examples/l3fwd/lpm_route_parse.c
> > > b/examples/l3fwd/lpm_route_parse.c
> > > index f27b66e838..357c12d9fe 100644
> > > --- a/examples/l3fwd/lpm_route_parse.c
> > > +++ b/examples/l3fwd/lpm_route_parse.c
> > > @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct lpm_route_rule
> > > *v)
> > >
> > >  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32, &v->depth);
> > >
> > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > >
> > >  	return rc;
> > >  }
> > > @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct lpm_route_rule
> > > *v)
> > >
> > >  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip, &v->depth);
> > >
> > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > >
> > >  	return rc;
> > >  }
> > > --
> > > 2.25.1
> 
> Gagan


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-18 10:01       ` Konstantin Ananyev
@ 2024-07-22  3:28         ` Gagandeep Singh
  2024-07-22  4:27           ` Gagandeep Singh
  0 siblings, 1 reply; 12+ messages in thread
From: Gagandeep Singh @ 2024-07-22  3:28 UTC (permalink / raw)
  To: Konstantin Ananyev, dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable

Hi,

> -----Original Message-----
> From: Konstantin Ananyev <konstantin.ananyev@huawei.com>
> Sent: Thursday, July 18, 2024 3:32 PM
> To: Gagandeep Singh <G.Singh@nxp.com>; dev@dpdk.org; Konstantin Ananyev
> <konstantin.v.ananyev@yandex.ru>; Sean Morrissey
> <sean.morrissey@intel.com>
> Cc: stable@dpdk.org
> Subject: RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in
> routes
> 
> 
> 
> > > > Application is accepting routes for port ID up to UINT8_MAX for
> > > > LPM amd EM routes on parsing the given rule file, but only up to
> > > > 32 ports can be enabled as per the variable enabled_port_mask
> > > > which is defined as uint32_t.
> > > >
> > > > This patch restricts the rules parsing code to accept routes for
> > > > port ID up to 31 only to avoid any unnecessary maintenance of
> > > > rules which will never be used.
> > >
> > > If we want to add this extra check, probably better to do it in setup_lpm().
> > > Where we already check that port is enabled, and If not, then this
> > > route rule will be skipped:
> > >
> > >         /* populate the LPM table */
> > >         for (i = 0; i < route_num_v4; i++) {
> > >                 struct in_addr in;
> > >
> > >                 /* skip unused ports */
> > >                 if ((1 << route_base_v4[i].if_out &
> > >                                 enabled_port_mask) == 0)
> > >                         continue;
> > >
> > > Same for EM.
> > I am trying to update the check for MAX if_out value in rules config file parsing
> which will be before setup_lpm().
> > The reason is, restricting and adding only those rules which can be
> > used by the application while populating the route_base_v4/v6 at first
> > step and avoid unnecessary memory allocation for local variables to store more
> not required rules.
> 
> Hmm... but why it is a problem?
Not really a problem, Just trying to optimize wherever it Is possible.

> 
> >
> > > ((1 << route_base_v4[i].if_out &
> > >                                 enabled_port_mask)
> > By looking into this check, it seems restriction to maximum 31 port ID
> > while parsing rule file becomes more valid as this check can pass due
> > to overflow in case value of route_base_v4[i].if_out Is 31+.
> 
> Agree, I think we need both, and it probably need to be in setup_lpm().
> Something like:
> 
> if (route_base_v4[i].if_out >= sizeof(enabled_port_mask) * CHAR_BIT ||
>    ((1 << route_base_v4[i].if_out & enabled_port_mask) == 0) {
>      /* print some error message here*/
>      rte_exiit(...);  /* or return an error */ }
> 
Yes, I can change it to this.

> >
> > > Another question here - why we just silently skip the rule with invalid port?
> > In read_config_files_lpm() we are calling the rte_exit in case port ID is 31+.
> > In setup_lpm, skipping the rules for the ports which are not enabled
> > and not giving error, I guess probably because of ease of use.
> > e.g. user has only single ipv4_routes config file with route rules for
> > port ID 0,1,2,3,4 and want to use same file for multiple test cases
> > like 1. when only port 0 enabled 2. when only port 0 and 1 enabled and
> > so on.
> > In this case, user can avoid to have separate route files for each of the test case.
> 
> The problem as I see it - we are not consistent here.
> In some cases we just silently skip rules with invalid (or disabled) port numbers, in
> other cases we generate an error and exit.
> For me it would be better, if we follow one simple policy (abort with error) here
> for all cases.
Ok, I will add the rte_exit if route port is invalid or not enabled. 
With this change onwards It will be assumed user will add only those routes
With port IDs which are valid and enabled in the application.

> 
> >
> > > Probably need to fail with error... that what ACL code-path does.
> > >
> > > > Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
> > > > Fixes: 52def963fc1c ("examples/l3fwd: support config file for
> > > > LPM/FIB")
> > > > Cc: sean.morrissey@intel.com
> > > > Cc: stable@dpdk.org
> > > >
> > > > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > > > ---
> > > >  examples/l3fwd/em_route_parse.c  | 6 ++++--
> > > > examples/l3fwd/lpm_route_parse.c | 6 ++++--
> > > >  2 files changed, 8 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/examples/l3fwd/em_route_parse.c
> > > > b/examples/l3fwd/em_route_parse.c index 8b534de5f1..65c71cd1ba
> > > > 100644
> > > > --- a/examples/l3fwd/em_route_parse.c
> > > > +++ b/examples/l3fwd/em_route_parse.c
> > > > @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
> > > >  	/* protocol. */
> > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
> > > >  	/* out interface. */
> > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > >
> > > >  	return 0;
> > > >  }
> > > > @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
> > > >  	/* protocol. */
> > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
> > > >  	/* out interface. */
> > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > >
> > > >  	return 0;
> > > >  }
> > > > diff --git a/examples/l3fwd/lpm_route_parse.c
> > > > b/examples/l3fwd/lpm_route_parse.c
> > > > index f27b66e838..357c12d9fe 100644
> > > > --- a/examples/l3fwd/lpm_route_parse.c
> > > > +++ b/examples/l3fwd/lpm_route_parse.c
> > > > @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct
> > > > lpm_route_rule
> > > > *v)
> > > >
> > > >  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32, &v->depth);
> > > >
> > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > >
> > > >  	return rc;
> > > >  }
> > > > @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct
> > > > lpm_route_rule
> > > > *v)
> > > >
> > > >  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip,
> > > > &v->depth);
> > > >
> > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > >
> > > >  	return rc;
> > > >  }
> > > > --
> > > > 2.25.1
> >
> > Gagan


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-22  3:28         ` Gagandeep Singh
@ 2024-07-22  4:27           ` Gagandeep Singh
  2024-07-23 16:22             ` Konstantin Ananyev
  0 siblings, 1 reply; 12+ messages in thread
From: Gagandeep Singh @ 2024-07-22  4:27 UTC (permalink / raw)
  To: Konstantin Ananyev, dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable

Hi,

<snip>
> > > > > Application is accepting routes for port ID up to UINT8_MAX for
> > > > > LPM amd EM routes on parsing the given rule file, but only up to
> > > > > 32 ports can be enabled as per the variable enabled_port_mask
> > > > > which is defined as uint32_t.
> > > > >
> > > > > This patch restricts the rules parsing code to accept routes for
> > > > > port ID up to 31 only to avoid any unnecessary maintenance of
> > > > > rules which will never be used.
> > > >
> > > > If we want to add this extra check, probably better to do it in setup_lpm().
> > > > Where we already check that port is enabled, and If not, then this
> > > > route rule will be skipped:
> > > >
> > > >         /* populate the LPM table */
> > > >         for (i = 0; i < route_num_v4; i++) {
> > > >                 struct in_addr in;
> > > >
> > > >                 /* skip unused ports */
> > > >                 if ((1 << route_base_v4[i].if_out &
> > > >                                 enabled_port_mask) == 0)
> > > >                         continue;
> > > >
> > > > Same for EM.
> > > I am trying to update the check for MAX if_out value in rules config
> > > file parsing
> > which will be before setup_lpm().
> > > The reason is, restricting and adding only those rules which can be
> > > used by the application while populating the route_base_v4/v6 at
> > > first step and avoid unnecessary memory allocation for local
> > > variables to store more
> > not required rules.
> >
> > Hmm... but why it is a problem?
> Not really a problem, Just trying to optimize wherever it Is possible.
> 
> >
> > >
> > > > ((1 << route_base_v4[i].if_out &
> > > >                                 enabled_port_mask)
> > > By looking into this check, it seems restriction to maximum 31 port
> > > ID while parsing rule file becomes more valid as this check can pass
> > > due to overflow in case value of route_base_v4[i].if_out Is 31+.
> >
> > Agree, I think we need both, and it probably need to be in setup_lpm().
> > Something like:
> >
> > if (route_base_v4[i].if_out >= sizeof(enabled_port_mask) * CHAR_BIT ||
> >    ((1 << route_base_v4[i].if_out & enabled_port_mask) == 0) {
> >      /* print some error message here*/
> >      rte_exiit(...);  /* or return an error */ }
> >
> Yes, I can change it to this.

I re-checked the code, IMO we should restrict the rules in " read_config_files"
May be we can move this check to read_config_files.
As having this check in the setup can result in rte_exit() call when no user rule file
Is given and application is using the default rules. In that case route_base_v4 will
Have 16 rules for 16 ports (default rules). 
So this check will fails always unless user enable all the 16 ports with -p option.

> 
> > >
> > > > Another question here - why we just silently skip the rule with invalid port?
> > > In read_config_files_lpm() we are calling the rte_exit in case port ID is 31+.
> > > In setup_lpm, skipping the rules for the ports which are not enabled
> > > and not giving error, I guess probably because of ease of use.
> > > e.g. user has only single ipv4_routes config file with route rules
> > > for port ID 0,1,2,3,4 and want to use same file for multiple test
> > > cases like 1. when only port 0 enabled 2. when only port 0 and 1
> > > enabled and so on.
> > > In this case, user can avoid to have separate route files for each of the test
> case.
> >
> > The problem as I see it - we are not consistent here.
> > In some cases we just silently skip rules with invalid (or disabled)
> > port numbers, in other cases we generate an error and exit.
> > For me it would be better, if we follow one simple policy (abort with
> > error) here for all cases.
> Ok, I will add the rte_exit if route port is invalid or not enabled.
> With this change onwards It will be assumed user will add only those routes With
> port IDs which are valid and enabled in the application.
> 
> >
> > >
> > > > Probably need to fail with error... that what ACL code-path does.
> > > >
> > > > > Fixes: e7e6dd643092 ("examples/l3fwd: support config file for
> > > > > EM")
> > > > > Fixes: 52def963fc1c ("examples/l3fwd: support config file for
> > > > > LPM/FIB")
> > > > > Cc: sean.morrissey@intel.com
> > > > > Cc: stable@dpdk.org
> > > > >
> > > > > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > > > > ---
> > > > >  examples/l3fwd/em_route_parse.c  | 6 ++++--
> > > > > examples/l3fwd/lpm_route_parse.c | 6 ++++--
> > > > >  2 files changed, 8 insertions(+), 4 deletions(-)
> > > > >
> > > > > diff --git a/examples/l3fwd/em_route_parse.c
> > > > > b/examples/l3fwd/em_route_parse.c index 8b534de5f1..65c71cd1ba
> > > > > 100644
> > > > > --- a/examples/l3fwd/em_route_parse.c
> > > > > +++ b/examples/l3fwd/em_route_parse.c
> > > > > @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
> > > > >  	/* protocol. */
> > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
> > > > >  	/* out interface. */
> > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > >
> > > > >  	return 0;
> > > > >  }
> > > > > @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
> > > > >  	/* protocol. */
> > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
> > > > >  	/* out interface. */
> > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > >
> > > > >  	return 0;
> > > > >  }
> > > > > diff --git a/examples/l3fwd/lpm_route_parse.c
> > > > > b/examples/l3fwd/lpm_route_parse.c
> > > > > index f27b66e838..357c12d9fe 100644
> > > > > --- a/examples/l3fwd/lpm_route_parse.c
> > > > > +++ b/examples/l3fwd/lpm_route_parse.c
> > > > > @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct
> > > > > lpm_route_rule
> > > > > *v)
> > > > >
> > > > >  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32,
> > > > > &v->depth);
> > > > >
> > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > >
> > > > >  	return rc;
> > > > >  }
> > > > > @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct
> > > > > lpm_route_rule
> > > > > *v)
> > > > >
> > > > >  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip,
> > > > > &v->depth);
> > > > >
> > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > >
> > > > >  	return rc;
> > > > >  }
> > > > > --
> > > > > 2.25.1
> > >
> > > Gagan


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-22  4:27           ` Gagandeep Singh
@ 2024-07-23 16:22             ` Konstantin Ananyev
  2024-07-24  8:02               ` Konstantin Ananyev
  0 siblings, 1 reply; 12+ messages in thread
From: Konstantin Ananyev @ 2024-07-23 16:22 UTC (permalink / raw)
  To: Gagandeep Singh, dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable

> > > > > > Application is accepting routes for port ID up to UINT8_MAX for
> > > > > > LPM amd EM routes on parsing the given rule file, but only up to
> > > > > > 32 ports can be enabled as per the variable enabled_port_mask
> > > > > > which is defined as uint32_t.
> > > > > >
> > > > > > This patch restricts the rules parsing code to accept routes for
> > > > > > port ID up to 31 only to avoid any unnecessary maintenance of
> > > > > > rules which will never be used.
> > > > >
> > > > > If we want to add this extra check, probably better to do it in setup_lpm().
> > > > > Where we already check that port is enabled, and If not, then this
> > > > > route rule will be skipped:
> > > > >
> > > > >         /* populate the LPM table */
> > > > >         for (i = 0; i < route_num_v4; i++) {
> > > > >                 struct in_addr in;
> > > > >
> > > > >                 /* skip unused ports */
> > > > >                 if ((1 << route_base_v4[i].if_out &
> > > > >                                 enabled_port_mask) == 0)
> > > > >                         continue;
> > > > >
> > > > > Same for EM.
> > > > I am trying to update the check for MAX if_out value in rules config
> > > > file parsing
> > > which will be before setup_lpm().
> > > > The reason is, restricting and adding only those rules which can be
> > > > used by the application while populating the route_base_v4/v6 at
> > > > first step and avoid unnecessary memory allocation for local
> > > > variables to store more
> > > not required rules.
> > >
> > > Hmm... but why it is a problem?
> > Not really a problem, Just trying to optimize wherever it Is possible.
> >
> > >
> > > >
> > > > > ((1 << route_base_v4[i].if_out &
> > > > >                                 enabled_port_mask)
> > > > By looking into this check, it seems restriction to maximum 31 port
> > > > ID while parsing rule file becomes more valid as this check can pass
> > > > due to overflow in case value of route_base_v4[i].if_out Is 31+.
> > >
> > > Agree, I think we need both, and it probably need to be in setup_lpm().
> > > Something like:
> > >
> > > if (route_base_v4[i].if_out >= sizeof(enabled_port_mask) * CHAR_BIT ||
> > >    ((1 << route_base_v4[i].if_out & enabled_port_mask) == 0) {
> > >      /* print some error message here*/
> > >      rte_exiit(...);  /* or return an error */ }
> > >
> > Yes, I can change it to this.
> 
> I re-checked the code, IMO we should restrict the rules in " read_config_files"
> May be we can move this check to read_config_files.
> As having this check in the setup can result in rte_exit() call when no user rule file
> Is given and application is using the default rules. In that case route_base_v4 will
> Have 16 rules for 16 ports (default rules).
> So this check will fails always unless user enable all the 16 ports with -p option.

Ah yes, you are right.
That's why probably right now we probably just do 'continue;' here...
Yeh, probably the easiest way is to put this check before setup_lpm() -
in parsing code, or straight after that.
Can I ask you for one more thing: can we add a new function that would
do this check and use it everywhere (lpm/em/acl).

> >
> > > >
> > > > > Another question here - why we just silently skip the rule with invalid port?
> > > > In read_config_files_lpm() we are calling the rte_exit in case port ID is 31+.
> > > > In setup_lpm, skipping the rules for the ports which are not enabled
> > > > and not giving error, I guess probably because of ease of use.
> > > > e.g. user has only single ipv4_routes config file with route rules
> > > > for port ID 0,1,2,3,4 and want to use same file for multiple test
> > > > cases like 1. when only port 0 enabled 2. when only port 0 and 1
> > > > enabled and so on.
> > > > In this case, user can avoid to have separate route files for each of the test
> > case.
> > >
> > > The problem as I see it - we are not consistent here.
> > > In some cases we just silently skip rules with invalid (or disabled)
> > > port numbers, in other cases we generate an error and exit.
> > > For me it would be better, if we follow one simple policy (abort with
> > > error) here for all cases.
> > Ok, I will add the rte_exit if route port is invalid or not enabled.
> > With this change onwards It will be assumed user will add only those routes With
> > port IDs which are valid and enabled in the application.
> >
> > >
> > > >
> > > > > Probably need to fail with error... that what ACL code-path does.
> > > > >
> > > > > > Fixes: e7e6dd643092 ("examples/l3fwd: support config file for
> > > > > > EM")
> > > > > > Fixes: 52def963fc1c ("examples/l3fwd: support config file for
> > > > > > LPM/FIB")
> > > > > > Cc: sean.morrissey@intel.com
> > > > > > Cc: stable@dpdk.org
> > > > > >
> > > > > > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > > > > > ---
> > > > > >  examples/l3fwd/em_route_parse.c  | 6 ++++--
> > > > > > examples/l3fwd/lpm_route_parse.c | 6 ++++--
> > > > > >  2 files changed, 8 insertions(+), 4 deletions(-)
> > > > > >
> > > > > > diff --git a/examples/l3fwd/em_route_parse.c
> > > > > > b/examples/l3fwd/em_route_parse.c index 8b534de5f1..65c71cd1ba
> > > > > > 100644
> > > > > > --- a/examples/l3fwd/em_route_parse.c
> > > > > > +++ b/examples/l3fwd/em_route_parse.c
> > > > > > @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
> > > > > >  	/* protocol. */
> > > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
> > > > > >  	/* out interface. */
> > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > >
> > > > > >  	return 0;
> > > > > >  }
> > > > > > @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
> > > > > >  	/* protocol. */
> > > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
> > > > > >  	/* out interface. */
> > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > >
> > > > > >  	return 0;
> > > > > >  }
> > > > > > diff --git a/examples/l3fwd/lpm_route_parse.c
> > > > > > b/examples/l3fwd/lpm_route_parse.c
> > > > > > index f27b66e838..357c12d9fe 100644
> > > > > > --- a/examples/l3fwd/lpm_route_parse.c
> > > > > > +++ b/examples/l3fwd/lpm_route_parse.c
> > > > > > @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct
> > > > > > lpm_route_rule
> > > > > > *v)
> > > > > >
> > > > > >  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32,
> > > > > > &v->depth);
> > > > > >
> > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > >
> > > > > >  	return rc;
> > > > > >  }
> > > > > > @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct
> > > > > > lpm_route_rule
> > > > > > *v)
> > > > > >
> > > > > >  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip,
> > > > > > &v->depth);
> > > > > >
> > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > >
> > > > > >  	return rc;
> > > > > >  }
> > > > > > --
> > > > > > 2.25.1
> > > >
> > > > Gagan
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-23 16:22             ` Konstantin Ananyev
@ 2024-07-24  8:02               ` Konstantin Ananyev
  2024-08-02 10:13                 ` Gagandeep Singh
  0 siblings, 1 reply; 12+ messages in thread
From: Konstantin Ananyev @ 2024-07-24  8:02 UTC (permalink / raw)
  To: Konstantin Ananyev, Gagandeep Singh, dev, Konstantin Ananyev,
	Sean Morrissey
  Cc: stable



> > > > > > > Application is accepting routes for port ID up to UINT8_MAX for
> > > > > > > LPM amd EM routes on parsing the given rule file, but only up to
> > > > > > > 32 ports can be enabled as per the variable enabled_port_mask
> > > > > > > which is defined as uint32_t.
> > > > > > >
> > > > > > > This patch restricts the rules parsing code to accept routes for
> > > > > > > port ID up to 31 only to avoid any unnecessary maintenance of
> > > > > > > rules which will never be used.
> > > > > >
> > > > > > If we want to add this extra check, probably better to do it in setup_lpm().
> > > > > > Where we already check that port is enabled, and If not, then this
> > > > > > route rule will be skipped:
> > > > > >
> > > > > >         /* populate the LPM table */
> > > > > >         for (i = 0; i < route_num_v4; i++) {
> > > > > >                 struct in_addr in;
> > > > > >
> > > > > >                 /* skip unused ports */
> > > > > >                 if ((1 << route_base_v4[i].if_out &
> > > > > >                                 enabled_port_mask) == 0)
> > > > > >                         continue;
> > > > > >
> > > > > > Same for EM.
> > > > > I am trying to update the check for MAX if_out value in rules config
> > > > > file parsing
> > > > which will be before setup_lpm().
> > > > > The reason is, restricting and adding only those rules which can be
> > > > > used by the application while populating the route_base_v4/v6 at
> > > > > first step and avoid unnecessary memory allocation for local
> > > > > variables to store more
> > > > not required rules.
> > > >
> > > > Hmm... but why it is a problem?
> > > Not really a problem, Just trying to optimize wherever it Is possible.
> > >
> > > >
> > > > >
> > > > > > ((1 << route_base_v4[i].if_out &
> > > > > >                                 enabled_port_mask)
> > > > > By looking into this check, it seems restriction to maximum 31 port
> > > > > ID while parsing rule file becomes more valid as this check can pass
> > > > > due to overflow in case value of route_base_v4[i].if_out Is 31+.
> > > >
> > > > Agree, I think we need both, and it probably need to be in setup_lpm().
> > > > Something like:
> > > >
> > > > if (route_base_v4[i].if_out >= sizeof(enabled_port_mask) * CHAR_BIT ||
> > > >    ((1 << route_base_v4[i].if_out & enabled_port_mask) == 0) {
> > > >      /* print some error message here*/
> > > >      rte_exiit(...);  /* or return an error */ }
> > > >
> > > Yes, I can change it to this.
> >
> > I re-checked the code, IMO we should restrict the rules in " read_config_files"
> > May be we can move this check to read_config_files.
> > As having this check in the setup can result in rte_exit() call when no user rule file
> > Is given and application is using the default rules. In that case route_base_v4 will
> > Have 16 rules for 16 ports (default rules).
> > So this check will fails always unless user enable all the 16 ports with -p option.
> 
> Ah yes, you are right.
> That's why probably right now we probably just do 'continue;' here...
> Yeh, probably the easiest way is to put this check before setup_lpm() -
> in parsing code, or straight after that.
> Can I ask you for one more thing: can we add a new function that would
> do this check and use it everywhere (lpm/em/acl).

As alternative thought - we might add to setup_lpm() an extra parameter
to indicate what do we want to do on rule with invalid/disabled port - just skip it or fail.
Another alternative - remove default route ability at all, though that one
is a change in behavior and probably there would be some complaints.  

> 
> > >
> > > > >
> > > > > > Another question here - why we just silently skip the rule with invalid port?
> > > > > In read_config_files_lpm() we are calling the rte_exit in case port ID is 31+.
> > > > > In setup_lpm, skipping the rules for the ports which are not enabled
> > > > > and not giving error, I guess probably because of ease of use.
> > > > > e.g. user has only single ipv4_routes config file with route rules
> > > > > for port ID 0,1,2,3,4 and want to use same file for multiple test
> > > > > cases like 1. when only port 0 enabled 2. when only port 0 and 1
> > > > > enabled and so on.
> > > > > In this case, user can avoid to have separate route files for each of the test
> > > case.
> > > >
> > > > The problem as I see it - we are not consistent here.
> > > > In some cases we just silently skip rules with invalid (or disabled)
> > > > port numbers, in other cases we generate an error and exit.
> > > > For me it would be better, if we follow one simple policy (abort with
> > > > error) here for all cases.
> > > Ok, I will add the rte_exit if route port is invalid or not enabled.
> > > With this change onwards It will be assumed user will add only those routes With
> > > port IDs which are valid and enabled in the application.
> > >
> > > >
> > > > >
> > > > > > Probably need to fail with error... that what ACL code-path does.
> > > > > >
> > > > > > > Fixes: e7e6dd643092 ("examples/l3fwd: support config file for
> > > > > > > EM")
> > > > > > > Fixes: 52def963fc1c ("examples/l3fwd: support config file for
> > > > > > > LPM/FIB")
> > > > > > > Cc: sean.morrissey@intel.com
> > > > > > > Cc: stable@dpdk.org
> > > > > > >
> > > > > > > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > > > > > > ---
> > > > > > >  examples/l3fwd/em_route_parse.c  | 6 ++++--
> > > > > > > examples/l3fwd/lpm_route_parse.c | 6 ++++--
> > > > > > >  2 files changed, 8 insertions(+), 4 deletions(-)
> > > > > > >
> > > > > > > diff --git a/examples/l3fwd/em_route_parse.c
> > > > > > > b/examples/l3fwd/em_route_parse.c index 8b534de5f1..65c71cd1ba
> > > > > > > 100644
> > > > > > > --- a/examples/l3fwd/em_route_parse.c
> > > > > > > +++ b/examples/l3fwd/em_route_parse.c
> > > > > > > @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
> > > > > > >  	/* protocol. */
> > > > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
> > > > > > >  	/* out interface. */
> > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > > >
> > > > > > >  	return 0;
> > > > > > >  }
> > > > > > > @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
> > > > > > >  	/* protocol. */
> > > > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
> > > > > > >  	/* out interface. */
> > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > > >
> > > > > > >  	return 0;
> > > > > > >  }
> > > > > > > diff --git a/examples/l3fwd/lpm_route_parse.c
> > > > > > > b/examples/l3fwd/lpm_route_parse.c
> > > > > > > index f27b66e838..357c12d9fe 100644
> > > > > > > --- a/examples/l3fwd/lpm_route_parse.c
> > > > > > > +++ b/examples/l3fwd/lpm_route_parse.c
> > > > > > > @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct
> > > > > > > lpm_route_rule
> > > > > > > *v)
> > > > > > >
> > > > > > >  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32,
> > > > > > > &v->depth);
> > > > > > >
> > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > > >
> > > > > > >  	return rc;
> > > > > > >  }
> > > > > > > @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct
> > > > > > > lpm_route_rule
> > > > > > > *v)
> > > > > > >
> > > > > > >  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip,
> > > > > > > &v->depth);
> > > > > > >
> > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> > > > > > >
> > > > > > >  	return rc;
> > > > > > >  }
> > > > > > > --
> > > > > > > 2.25.1
> > > > >
> > > > > Gagan
> >


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
  2024-07-24  8:02               ` Konstantin Ananyev
@ 2024-08-02 10:13                 ` Gagandeep Singh
  0 siblings, 0 replies; 12+ messages in thread
From: Gagandeep Singh @ 2024-08-02 10:13 UTC (permalink / raw)
  To: Konstantin Ananyev, dev, Konstantin Ananyev, Sean Morrissey; +Cc: stable

Hi,

> -----Original Message-----
> From: Konstantin Ananyev <konstantin.ananyev@huawei.com>
> Sent: Wednesday, July 24, 2024 1:32 PM
> To: Konstantin Ananyev <konstantin.ananyev@huawei.com>; Gagandeep
> Singh <G.Singh@nxp.com>; dev@dpdk.org; Konstantin Ananyev
> <konstantin.v.ananyev@yandex.ru>; Sean Morrissey
> <sean.morrissey@intel.com>
> Cc: stable@dpdk.org
> Subject: RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID
> in routes
> 
> 
> 
> > > > > > > > Application is accepting routes for port ID up to
> > > > > > > > UINT8_MAX for LPM amd EM routes on parsing the given rule
> > > > > > > > file, but only up to
> > > > > > > > 32 ports can be enabled as per the variable
> > > > > > > > enabled_port_mask which is defined as uint32_t.
> > > > > > > >
> > > > > > > > This patch restricts the rules parsing code to accept
> > > > > > > > routes for port ID up to 31 only to avoid any unnecessary
> > > > > > > > maintenance of rules which will never be used.
> > > > > > >
> > > > > > > If we want to add this extra check, probably better to do it in
> setup_lpm().
> > > > > > > Where we already check that port is enabled, and If not,
> > > > > > > then this route rule will be skipped:
> > > > > > >
> > > > > > >         /* populate the LPM table */
> > > > > > >         for (i = 0; i < route_num_v4; i++) {
> > > > > > >                 struct in_addr in;
> > > > > > >
> > > > > > >                 /* skip unused ports */
> > > > > > >                 if ((1 << route_base_v4[i].if_out &
> > > > > > >                                 enabled_port_mask) == 0)
> > > > > > >                         continue;
> > > > > > >
> > > > > > > Same for EM.
> > > > > > I am trying to update the check for MAX if_out value in rules
> > > > > > config file parsing
> > > > > which will be before setup_lpm().
> > > > > > The reason is, restricting and adding only those rules which
> > > > > > can be used by the application while populating the
> > > > > > route_base_v4/v6 at first step and avoid unnecessary memory
> > > > > > allocation for local variables to store more
> > > > > not required rules.
> > > > >
> > > > > Hmm... but why it is a problem?
> > > > Not really a problem, Just trying to optimize wherever it Is possible.
> > > >
> > > > >
> > > > > >
> > > > > > > ((1 << route_base_v4[i].if_out &
> > > > > > >                                 enabled_port_mask)
> > > > > > By looking into this check, it seems restriction to maximum 31
> > > > > > port ID while parsing rule file becomes more valid as this
> > > > > > check can pass due to overflow in case value of
> route_base_v4[i].if_out Is 31+.
> > > > >
> > > > > Agree, I think we need both, and it probably need to be in
> setup_lpm().
> > > > > Something like:
> > > > >
> > > > > if (route_base_v4[i].if_out >= sizeof(enabled_port_mask) * CHAR_BIT
> ||
> > > > >    ((1 << route_base_v4[i].if_out & enabled_port_mask) == 0) {
> > > > >      /* print some error message here*/
> > > > >      rte_exiit(...);  /* or return an error */ }
> > > > >
> > > > Yes, I can change it to this.
> > >
> > > I re-checked the code, IMO we should restrict the rules in "
> read_config_files"
> > > May be we can move this check to read_config_files.
> > > As having this check in the setup can result in rte_exit() call when
> > > no user rule file Is given and application is using the default
> > > rules. In that case route_base_v4 will Have 16 rules for 16 ports (default
> rules).
> > > So this check will fails always unless user enable all the 16 ports with -p
> option.
> >
> > Ah yes, you are right.
> > That's why probably right now we probably just do 'continue;' here...
> > Yeh, probably the easiest way is to put this check before setup_lpm()
> > - in parsing code, or straight after that.
> > Can I ask you for one more thing: can we add a new function that would
> > do this check and use it everywhere (lpm/em/acl).
> 
> As alternative thought - we might add to setup_lpm() an extra parameter to
> indicate what do we want to do on rule with invalid/disabled port - just skip
> it or fail.
> Another alternative - remove default route ability at all, though that one is a
> change in behavior and probably there would be some complaints.
Sorry for late reply, first option looks ok to me. I can add a user given option in
Setup functions to decide skip or continue. 
In V2, also will try to create a common function for this check for all the setup
Functions.

> 
> >
> > > >
> > > > > >
> > > > > > > Another question here - why we just silently skip the rule with
> invalid port?
> > > > > > In read_config_files_lpm() we are calling the rte_exit in case port ID
> is 31+.
> > > > > > In setup_lpm, skipping the rules for the ports which are not
> > > > > > enabled and not giving error, I guess probably because of ease of
> use.
> > > > > > e.g. user has only single ipv4_routes config file with route
> > > > > > rules for port ID 0,1,2,3,4 and want to use same file for
> > > > > > multiple test cases like 1. when only port 0 enabled 2. when
> > > > > > only port 0 and 1 enabled and so on.
> > > > > > In this case, user can avoid to have separate route files for
> > > > > > each of the test
> > > > case.
> > > > >
> > > > > The problem as I see it - we are not consistent here.
> > > > > In some cases we just silently skip rules with invalid (or
> > > > > disabled) port numbers, in other cases we generate an error and exit.
> > > > > For me it would be better, if we follow one simple policy (abort
> > > > > with
> > > > > error) here for all cases.
> > > > Ok, I will add the rte_exit if route port is invalid or not enabled.
> > > > With this change onwards It will be assumed user will add only
> > > > those routes With port IDs which are valid and enabled in the
> application.
> > > >
> > > > >
> > > > > >
> > > > > > > Probably need to fail with error... that what ACL code-path does.
> > > > > > >
> > > > > > > > Fixes: e7e6dd643092 ("examples/l3fwd: support config file
> > > > > > > > for
> > > > > > > > EM")
> > > > > > > > Fixes: 52def963fc1c ("examples/l3fwd: support config file
> > > > > > > > for
> > > > > > > > LPM/FIB")
> > > > > > > > Cc: sean.morrissey@intel.com
> > > > > > > > Cc: stable@dpdk.org
> > > > > > > >
> > > > > > > > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > > > > > > > ---
> > > > > > > >  examples/l3fwd/em_route_parse.c  | 6 ++++--
> > > > > > > > examples/l3fwd/lpm_route_parse.c | 6 ++++--
> > > > > > > >  2 files changed, 8 insertions(+), 4 deletions(-)
> > > > > > > >
> > > > > > > > diff --git a/examples/l3fwd/em_route_parse.c
> > > > > > > > b/examples/l3fwd/em_route_parse.c index
> > > > > > > > 8b534de5f1..65c71cd1ba
> > > > > > > > 100644
> > > > > > > > --- a/examples/l3fwd/em_route_parse.c
> > > > > > > > +++ b/examples/l3fwd/em_route_parse.c
> > > > > > > > @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct
> em_rule *v)
> > > > > > > >  	/* protocol. */
> > > > > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0,
> UINT8_MAX, 0);
> > > > > > > >  	/* out interface. */
> > > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,
> 0);
> > > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1,
> 0);
> > > > > > > >
> > > > > > > >  	return 0;
> > > > > > > >  }
> > > > > > > > @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct
> em_rule *v)
> > > > > > > >  	/* protocol. */
> > > > > > > >  	GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0,
> UINT8_MAX, 0);
> > > > > > > >  	/* out interface. */
> > > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,
> 0);
> > > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1,
> 0);
> > > > > > > >
> > > > > > > >  	return 0;
> > > > > > > >  }
> > > > > > > > diff --git a/examples/l3fwd/lpm_route_parse.c
> > > > > > > > b/examples/l3fwd/lpm_route_parse.c
> > > > > > > > index f27b66e838..357c12d9fe 100644
> > > > > > > > --- a/examples/l3fwd/lpm_route_parse.c
> > > > > > > > +++ b/examples/l3fwd/lpm_route_parse.c
> > > > > > > > @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct
> > > > > > > > lpm_route_rule
> > > > > > > > *v)
> > > > > > > >
> > > > > > > >  	rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32,
> > > > > > > > &v->depth);
> > > > > > > >
> > > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,
> 0);
> > > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1,
> 0);
> > > > > > > >
> > > > > > > >  	return rc;
> > > > > > > >  }
> > > > > > > > @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct
> > > > > > > > lpm_route_rule
> > > > > > > > *v)
> > > > > > > >
> > > > > > > >  	rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip,
> > > > > > > > &v->depth);
> > > > > > > >
> > > > > > > > -	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,
> 0);
> > > > > > > > +	GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> > > > > > > > +			(sizeof(enabled_port_mask) * CHAR_BIT) - 1,
> 0);
> > > > > > > >
> > > > > > > >  	return rc;
> > > > > > > >  }
> > > > > > > > --
> > > > > > > > 2.25.1
> > > > > >
> > > > > > Gagan
> > >


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [v2 2/3] examples/l3fwd: fix return value on rules add
       [not found] ` <20240806034120.3165295-1-g.singh@nxp.com>
@ 2024-08-06  3:41   ` Gagandeep Singh
  0 siblings, 0 replies; 12+ messages in thread
From: Gagandeep Singh @ 2024-08-06  3:41 UTC (permalink / raw)
  To: dev, Sean Morrissey; +Cc: stable

fix return value on adding the EM or LPM rules.

Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
Fixes: 52def963fc1c ("examples/l3fwd: support config file for LPM/FIB")
Cc: sean.morrissey@intel.com
Cc: stable@dpdk.org

Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
---
 examples/l3fwd/em_route_parse.c  | 11 ++++++-----
 examples/l3fwd/lpm_route_parse.c | 11 ++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/examples/l3fwd/em_route_parse.c b/examples/l3fwd/em_route_parse.c
index da23356dd6..8b534de5f1 100644
--- a/examples/l3fwd/em_route_parse.c
+++ b/examples/l3fwd/em_route_parse.c
@@ -119,7 +119,7 @@ em_add_rules(const char *rule_path,
 	char buff[LINE_MAX];
 	FILE *fh;
 	unsigned int i = 0, rule_size = sizeof(*next);
-	int val;
+	int val, rc;
 
 	*proute_base = NULL;
 	fh = fopen(rule_path, "rb");
@@ -172,13 +172,14 @@ em_add_rules(const char *rule_path,
 			return -EINVAL;
 		}
 
-		if (parser(buff + 1, next) != 0) {
+		rc = parser(buff + 1, next);
+		if (rc != 0) {
 			RTE_LOG(ERR, L3FWD,
-				"%s Line %u: parse rules error\n",
-				rule_path, i);
+				"%s Line %u: parse rules error code = %d\n",
+				rule_path, i, rc);
 			fclose(fh);
 			free(route_rules);
-			return -EINVAL;
+			return rc;
 		}
 
 		route_cnt++;
diff --git a/examples/l3fwd/lpm_route_parse.c b/examples/l3fwd/lpm_route_parse.c
index f7d44aa2cd..f27b66e838 100644
--- a/examples/l3fwd/lpm_route_parse.c
+++ b/examples/l3fwd/lpm_route_parse.c
@@ -184,7 +184,7 @@ lpm_add_rules(const char *rule_path,
 	char buff[LINE_MAX];
 	FILE *fh;
 	unsigned int i = 0, rule_size = sizeof(*next);
-	int val;
+	int val, rc;
 
 	*proute_base = NULL;
 	fh = fopen(rule_path, "rb");
@@ -237,13 +237,14 @@ lpm_add_rules(const char *rule_path,
 			return -EINVAL;
 		}
 
-		if (parser(buff + 1, next) != 0) {
+		rc = parser(buff + 1, next);
+		if (rc != 0) {
 			RTE_LOG(ERR, L3FWD,
-				"%s Line %u: parse rules error\n",
-				rule_path, i);
+				"%s Line %u: parse rules error code = %d\n",
+				rule_path, i, rc);
 			fclose(fh);
 			free(route_rules);
-			return -EINVAL;
+			return rc;
 		}
 
 		route_cnt++;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-08-06  3:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240715101458.645014-1-g.singh@nxp.com>
2024-07-15 10:14 ` [PATCH 2/3] examples/l3fwd: fix return value on rules add Gagandeep Singh
2024-07-16  6:55   ` Hemant Agrawal
2024-07-15 10:14 ` [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes Gagandeep Singh
2024-07-17 10:17   ` Konstantin Ananyev
2024-07-18  6:30     ` Gagandeep Singh
2024-07-18 10:01       ` Konstantin Ananyev
2024-07-22  3:28         ` Gagandeep Singh
2024-07-22  4:27           ` Gagandeep Singh
2024-07-23 16:22             ` Konstantin Ananyev
2024-07-24  8:02               ` Konstantin Ananyev
2024-08-02 10:13                 ` Gagandeep Singh
     [not found] ` <20240806034120.3165295-1-g.singh@nxp.com>
2024-08-06  3:41   ` [v2 2/3] examples/l3fwd: fix return value on rules add Gagandeep Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).