examples/l3fwd: support single route file
PATCH v2 1/3 examples/l3fwd: support single route file
IPv6 rules file needs to be specified together with IPv4 rules file to configure user given rules. But if user want to give only IPv4 or only IPv6 rules, application returns error:
"Missing 1 or more rule files"
With this patch application can accept only IPv4,
only IPv6 or both IP rules.
--- examples/l3fwd/em_route_parse.c | 18 ++++++++++-------- examples/l3fwd/lpm_route_parse.c | 17 ++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-)
examples/l3fwd/em_route_parse.c +10 -8
@@ -249,8 +249,7 @@ voidread_config_files_em (void) {/* ipv4 check */ -if (parm_config.rule_ipv4_name !=NULL && - parm_config.rule_ipv6_name !=NULL ) { +if (parm_config.rule_ipv4_name !=NULL ) {/* ipv4 check */ route_num_v4 =em_add_rules (parm_config.rule_ipv4_name, &em_route_base_v4, &em_parse_v4_rule);
@@ -258,7 +257,14 @@ read_config_files_em(void)em_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add EM IPv4 rules\n" ); } - + }else { +RTE_LOG (INFO ,L3FWD ,"Missing IPv4 rule file, using default instead\n" ); +if (em_add_default_v4_rules () <0 ) { +em_free_routes (); +rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); + } + } +if (parm_config.rule_ipv6_name !=NULL ) {/* ipv6 check */ route_num_v6 =em_add_rules (parm_config.rule_ipv6_name, &em_route_base_v6, &em_parse_v6_rule);
@@ -267,11 +273,7 @@ read_config_files_em(void)rte_exit (EXIT_FAILURE ,"Failed to add EM IPv6 rules\n" ); } }else { -RTE_LOG (INFO ,L3FWD ,"Missing 1 or more rule files, using default instead\n" ); -if (em_add_default_v4_rules () <0 ) { -em_free_routes (); -rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); - } +RTE_LOG (INFO ,L3FWD ,"Missing IPv6 rule file, using default instead\n" );if (em_add_default_v6_rules () <0 ) {em_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add default IPv6 rules\n" );
examples/l3fwd/lpm_route_parse.c +10 -7
@@ -271,8 +271,7 @@ lpm_free_routes(void)void read_config_files_lpm (void ) { -if (parm_config.rule_ipv4_name !=NULL && - parm_config.rule_ipv6_name !=NULL ) { +if (parm_config.rule_ipv4_name !=NULL ) {/* ipv4 check */ route_num_v4 =lpm_add_rules (parm_config.rule_ipv4_name, &route_base_v4, &lpm_parse_v4_rule);
@@ -280,7 +279,15 @@ read_config_files_lpm(void)lpm_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add IPv4 rules\n" ); } + }else { +RTE_LOG (INFO ,L3FWD ,"Missing IPv4 rule file, using default instead\n" ); +if (lpm_add_default_v4_rules () <0 ) { +lpm_free_routes (); +rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); + } + } +if (parm_config.rule_ipv6_name !=NULL ) {/* ipv6 check */ route_num_v6 =lpm_add_rules (parm_config.rule_ipv6_name, &route_base_v6, &lpm_parse_v6_rule);
@@ -289,11 +296,7 @@ read_config_files_lpm(void)rte_exit (EXIT_FAILURE ,"Failed to add IPv6 rules\n" ); } }else { -RTE_LOG (INFO ,L3FWD ,"Missing 1 or more rule files, using default instead\n" ); -if (lpm_add_default_v4_rules () <0 ) { -lpm_free_routes (); -rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); - } +RTE_LOG (INFO ,L3FWD ,"Missing IPv6 rule file, using default instead\n" );if (lpm_add_default_v6_rules () <0 ) {lpm_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add default IPv6 rules\n" );
Signature · 1 line
2.25.1
PATCH v2 2/3 examples/l3fwd: fix return value on rules add
fix return value on adding the EM or LPM rules.
--- examples/l3fwd/em_route_parse.c | 11 ++++++----- examples/l3fwd/lpm_route_parse.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-)
examples/l3fwd/em_route_parse.c +6 -5
@@ -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++;
examples/l3fwd/lpm_route_parse.c +6 -5
@@ -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++;
Signature · 1 line
2.25.1
Re: [PATCH 2/3] examples/l3fwd: fix return value on rules add
Quoted 8 lines · Gagandeep Singh
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")Signed-off-by Gagandeep Singh <[email protected]>
PATCH v2 3/3 examples/l3fwd: fix maximum acceptable port ID in routes
In reply to Gagandeep SinghApplication 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.
--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
examples/l3fwd/em_route_parse.c +4 -2
@@ -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 ; }
examples/l3fwd/lpm_route_parse.c +4 -2
@@ -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; }
Signature · 1 line
2.25.1
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Quoted 10 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to 32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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.
Quoted 61 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config file for EM")Fixes 52def963fc1c ("examples/l3fwd: support config file for LPM/FIB")Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)examples/l3fwd/em_route_parse.c +4
-2@@ -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 ; }examples/l3fwd/lpm_route_parse.c +4
-3@@ -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
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Hi,
Quoted 34 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Wednesday, July 17, 2024 3:48 PM
To: Gagandeep Singh <[email protected]>; [email protected]; Konstantin Ananyev <[email protected]>; Sean Morrissey <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routesQuoted 8 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to 32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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;
Quoted 1 line
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.
Quoted 2 lines
((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+.
Quoted 1 line
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.
Quoted 59 lines
Probably need to fail with error... that what ACL code-path does.
Quoted 57 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config file for EM")Fixes 52def963fc1c ("examples/l3fwd: support config file forLPM/FIB")
Cc: [email protected]
Cc: [email protected]Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/examples/l3fwd/em_route_parse.cindex8b534de5f1..65c71cd1ba100644examples/l3fwd/em_route_parse.c +4
-2@@ -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 ; }examples/l3fwd/lpm_route_parse.c +2
-1@@ -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;}
examples/l3fwd/lpm_route_parse.c +0
-0@@ -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);
Quoted 8 lines
Quoted 8 lines
examples/l3fwd/lpm_route_parse.c +2
-1-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
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Quoted 24 lines
Quoted 24 lines
Quoted 10 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to 32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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;
Quoted 5 lines
Quoted 1 line
Same for EM.
I am trying to update the check for MAX
if_outvalue in rules config file parsing which will be beforesetup_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?
Quoted 6 lines
Quoted 3 lines
((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 */
} Quoted 10 lines
Quoted 2 lines
Another question here - why we just silently skip the rule with invalid port?
In
read_config_files_lpm()we are calling therte_exitin case port ID is 31+. Insetup_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 singleipv4_routesconfig 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.
Quoted 70 lines
Quoted 60 lines
Probably need to fail with error... that what ACL code-path does.
Quoted 57 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config file for EM")Fixes 52def963fc1c ("examples/l3fwd: support config file forLPM/FIB")
Cc: [email protected]
Cc: [email protected]Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/examples/l3fwd/em_route_parse.cindex8b534de5f1..65c71cd1ba100644examples/l3fwd/em_route_parse.c +4
-2@@ -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 ; }examples/l3fwd/lpm_route_parse.c +2
-1@@ -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;}
examples/l3fwd/lpm_route_parse.c +0
-0@@ -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);Quoted 8 lines
Quoted 8 lines
examples/l3fwd/lpm_route_parse.c +2
-1-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.1Gagan
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Hi,
Quoted 35 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Thursday, July 18, 2024 3:32 PM
To: Gagandeep Singh <[email protected]>; [email protected]; Konstantin Ananyev <[email protected]>; Sean Morrissey <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routesQuoted 23 lines
Quoted 23 lines
Quoted 8 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to 32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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.
Quoted 8 lines
Quoted 1 line
I am trying to update the check for MAX
if_outvalue in rules config file parsingwhich will be before
setup_lpm().Quoted 3 lines
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.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
((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+.
Quoted 8 lines
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.
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
Another question here - why we just silently skip the rule with invalid port?
In
read_config_files_lpm()we are calling therte_exitin case port ID is 31+. Insetup_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 singleipv4_routesconfig 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.
Quoted 5 lines
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.
Quoted 75 lines
Quoted 75 lines
Quoted 65 lines
Probably need to fail with error... that what ACL code-path does.
Quoted 61 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config file for EM")Fixes 52def963fc1c ("examples/l3fwd: support config file forLPM/FIB")
Cc: [email protected]
Cc: [email protected]Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/examples/l3fwd/em_route_parse.cindex8b534de5f1..65c71cd1ba100644examples/l3fwd/em_route_parse.c +4
-2@@ -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 ; }examples/l3fwd/lpm_route_parse.c +0
-0@@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct
lpm_route_rule
*v)examples/l3fwd/lpm_route_parse.c +2
-1rc =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);Quoted 8 lines
Quoted 8 lines
examples/l3fwd/lpm_route_parse.c +2
-2-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
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Hi,
<snip>
Quoted 46 lines
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to 32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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;Quoted 8 lines
Quoted 6 lines
/* 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_outvalue in rules config file parsingQuoted 8 lines
which will be before
setup_lpm().Quoted 4 lines
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.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
((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:
Quoted 6 lines
Quoted 5 lines
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.
Quoted 99 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Another question here - why we just silently skip the rule with invalid port?
In
read_config_files_lpm()we are calling therte_exitin case port ID is 31+. Insetup_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 singleipv4_routesconfig 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 testcase.
Quoted 6 lines
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_exitif 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.Quoted 77 lines
Quoted 77 lines
Quoted 67 lines
Probably need to fail with error... that what ACL code-path does.
Quoted 63 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config file forEM")
Fixes 52def963fc1c ("examples/l3fwd: support config file forLPM/FIB")
Cc: [email protected]
Cc: [email protected]Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/examples/l3fwd/em_route_parse.cindex8b534de5f1..65c71cd1ba100644examples/l3fwd/em_route_parse.c +4
-2@@ -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 ; }examples/l3fwd/lpm_route_parse.c +0
-0@@ -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);examples/l3fwd/lpm_route_parse.c +2
-1-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);Quoted 8 lines
Quoted 8 lines
examples/l3fwd/lpm_route_parse.c +2
-2-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
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Quoted 51 lines
Quoted 51 lines
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to 32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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;Quoted 8 lines
Quoted 6 lines
/* 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_outvalue in rules config file parsingQuoted 8 lines
which will be before
setup_lpm().Quoted 4 lines
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.
Quoted 16 lines
Quoted 7 lines
Quoted 4 lines
((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 */ }
Quoted 8 lines
Quoted 1 line
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 toread_config_files.
As having this check in the setup can result inrte_exit()call when no user rule file Is given and application is using the default rules. In that caseroute_base_v4will 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).
Quoted 100 lines
Quoted 99 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Another question here - why we just silently skip the rule with invalid port?
In
read_config_files_lpm()we are calling therte_exitin case port ID is 31+. Insetup_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 singleipv4_routesconfig 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 testcase.
Quoted 6 lines
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_exitif 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.Quoted 77 lines
Quoted 77 lines
Quoted 67 lines
Probably need to fail with error... that what ACL code-path does.
Quoted 63 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config file forEM")
Fixes 52def963fc1c ("examples/l3fwd: support config file forLPM/FIB")
Cc: [email protected]
Cc: [email protected]Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/examples/l3fwd/em_route_parse.cindex8b534de5f1..65c71cd1ba100644examples/l3fwd/em_route_parse.c +4
-2@@ -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 ; }examples/l3fwd/lpm_route_parse.c +0
-0@@ -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);examples/l3fwd/lpm_route_parse.c +2
-1-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);Quoted 8 lines
Quoted 8 lines
examples/l3fwd/lpm_route_parse.c +2
-2-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
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Quoted 62 lines
Quoted 53 lines
Quoted 53 lines
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to 32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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;Quoted 8 lines
Quoted 6 lines
/* 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_outvalue in rules config file parsingQuoted 8 lines
which will be before
setup_lpm().Quoted 4 lines
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.
Quoted 16 lines
Quoted 7 lines
Quoted 4 lines
((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 */ }Quoted 8 lines
Quoted 1 line
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 toread_config_files.
As having this check in the setup can result inrte_exit()call when no user rule file Is given and application is using the default rules. In that caseroute_base_v4will Have 16 rules for 16 ports (default rules).
So this check will fails always unless user enable all the 16 ports with -p option.
Quoted 6 lines
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 beforesetup_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.
Quoted 101 lines
Quoted 101 lines
Quoted 100 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Another question here - why we just silently skip the rule with invalid port?
Quoted 8 lines
Quoted 8 lines
In
read_config_files_lpm()we are calling therte_exitin case port ID is 31+. Insetup_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 singleipv4_routesconfig 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 testcase.
Quoted 6 lines
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_exitif 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.Quoted 77 lines
Quoted 77 lines
Quoted 67 lines
Probably need to fail with error... that what ACL code-path does.
Quoted 63 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config file forEM")
Fixes 52def963fc1c ("examples/l3fwd: support config file forLPM/FIB")
Cc: [email protected]
Cc: [email protected]Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/examples/l3fwd/em_route_parse.cindex8b534de5f1..65c71cd1ba100644examples/l3fwd/em_route_parse.c +4
-2@@ -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 ; }examples/l3fwd/lpm_route_parse.c +0
-0@@ -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);examples/l3fwd/lpm_route_parse.c +2
-1-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);Quoted 8 lines
Quoted 8 lines
examples/l3fwd/lpm_route_parse.c +2
-2-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
RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routes
Hi,
Quoted 88 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Wednesday, July 24, 2024 1:32 PM
To: Konstantin Ananyev <[email protected]>; Gagandeep Singh <[email protected]>; [email protected]; Konstantin Ananyev <[email protected]>; Sean Morrissey <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH 3/3] examples/l3fwd: fix maximum acceptable port ID in routesQuoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
Application is accepting routes for port ID up to
UINT8_MAXfor LPM amd EM routes on parsing the given rule file, but only up to
32 ports can be enabled as per the variableenabled_port_maskwhich is defined asuint32_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().Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
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;Quoted 8 lines
Quoted 6 lines
/* 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_outvalue in rules config file parsingQuoted 8 lines
which will be before
setup_lpm().Quoted 4 lines
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.
Quoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
((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+.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Agree, I think we need both, and it probably need to be in
setup_lpm().Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
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 */ }Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Yes, I can change it to this.
I re-checked the code, IMO we should restrict the rules in "
read_config_files"Quoted 4 lines
Quoted 4 lines
May be we can move this check to
read_config_files.
As having this check in the setup can result inrte_exit()call when no user rule file Is given and application is using the default rules. In that caseroute_base_v4will Have 16 rules for 16 ports (defaultrules).
Quoted 1 line
Quoted 1 line
So this check will fails always unless user enable all the 16 ports with -p
option.
Quoted 7 lines
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 beforesetup_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).
Quoted 5 lines
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.
Quoted 123 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Another question here - why we just silently skip the rule with
invalid port?
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
In
read_config_files_lpm()we are calling therte_exitin case port IDis 31+.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
In
setup_lpm, skipping the rules for the ports which are not enabled and not giving error, I guess probably because of ease ofuse.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
e.g. user has only single
ipv4_routesconfig 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 testcase.
Quoted 7 lines
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.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Ok, I will add the
rte_exitif 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 theapplication.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Probably need to fail with error... that what ACL code-path does.
Quoted 15 lines
Fixes e7e6dd643092 ("examples/l3fwd: support config filefor
EM")Fixes 52def963fc1c ("examples/l3fwd: support config filefor
LPM/FIB")
Cc: [email protected]
Cc: [email protected]Signed-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 6 ++++-- examples/l3fwd/lpm_route_parse.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
examples/l3fwd/em_route_parse.c em_parse_v6_rule(char *str, struct
Quoted 7 lines
(quoted diff) +0
-0
b/examples/l3fwd/em_route_parse.cindex8b534de5f1..65c71cd1ba
100644examples/l3fwd/em_route_parse.c +0
-0@@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct
em_rule*v)Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/em_route_parse.c em_parse_v6_rule(char *str, struct · line 66
Quoted 2 lines
examples/l3fwd/em_route_parse.c +0
-0/* protocol. */ GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0,
UINT8_MAX, 0);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/em_route_parse.c em_parse_v6_rule(char *str, struct · line 68
Quoted 2 lines
examples/l3fwd/em_route_parse.c +0
-1/* out interface. */ - GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,0);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/em_route_parse.c em_parse_v6_rule(char *str, struct · line 69
Quoted 2 lines
examples/l3fwd/em_route_parse.c +2
-0+ GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, + (sizeof(enabled_port_mask) * CHAR_BIT) - 1,0);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
examples/l3fwd/em_route_parse.c em_parse_v4_rule(char *str, struct
Quoted 4 lines
examples/l3fwd/em_route_parse.c +0
-0return 0 ; }@@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct
em_rule*v)Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/em_route_parse.c em_parse_v4_rule(char *str, struct · line 104
Quoted 2 lines
examples/l3fwd/em_route_parse.c +0
-0/* protocol. */ GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0,
UINT8_MAX, 0);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/em_route_parse.c em_parse_v4_rule(char *str, struct · line 105
Quoted 2 lines
examples/l3fwd/em_route_parse.c +0
-1/* out interface. */ - GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,0);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/em_route_parse.c em_parse_v4_rule(char *str, struct · line 107
Quoted 2 lines
examples/l3fwd/em_route_parse.c +2
-0+ GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, + (sizeof(enabled_port_mask) * CHAR_BIT) - 1,0);
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
examples/l3fwd/em_route_parse.c +0
-0return 0 ; }examples/l3fwd/lpm_route_parse.c +0
-0@@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct
lpm_route_rule
*v)Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
examples/l3fwd/lpm_route_parse.c
Quoted 4 lines
rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR],
v->ip_32,&v->depth);examples/l3fwd/lpm_route_parse.c +0
-1- GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,0);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/lpm_route_parse.c
Quoted 2 lines
examples/l3fwd/lpm_route_parse.c +2
-0+ GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, + (sizeof(enabled_port_mask) * CHAR_BIT) - 1,0);
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
examples/l3fwd/lpm_route_parse.c
Quoted 11 lines
examples/l3fwd/lpm_route_parse.c +0
-0return 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);examples/l3fwd/lpm_route_parse.c +0
-1- GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX,0);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
examples/l3fwd/lpm_route_parse.c
Quoted 2 lines
examples/l3fwd/lpm_route_parse.c +2
-0+ GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, + (sizeof(enabled_port_mask) * CHAR_BIT) - 1,0);
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
return rc;
}
--
2.25.1Gagan
v2 cover L3fwd changes
In reply to Gagandeep Singhv2 changes:
* Handled a comment to enhance the invalid port ID logic and added a user option to decide exit or silently skip in case invalid port in the rules list.
Gagandeep Singh (3):
examples/l3fwd: support single route file
examples/l3fwd: fix return value on rules add
examples/l3fwd: enhance valid ports checking
examples/l3fwd/em_route_parse.c | 33 ++++++++++-------- examples/l3fwd/l3fwd.h | 16 +++++++++ examples/l3fwd/l3fwd_em.c | 22 ++++++++---- examples/l3fwd/l3fwd_fib.c | 26 +++++++++----- examples/l3fwd/l3fwd_lpm.c | 26 +++++++++----- examples/l3fwd/l3fwd_route.h | 2 ++ examples/l3fwd/lpm_route_parse.c | 28 ++++++++------- examples/l3fwd/main.c | 60 ++++++++++++++++++++++++++------ 8 files changed, 154 insertions(+), 59 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 examples/l3fwd: support single route file
IPv6 rules file needs to be specified together with IPv4 rules file to configure user given rules. But if user want to give only IPv4 or only IPv6 rules, application returns error:
"Missing 1 or more rule files"
With this patch application can accept only IPv4,
only IPv6 or both IP rules.
--- examples/l3fwd/em_route_parse.c | 18 ++++++++++-------- examples/l3fwd/lpm_route_parse.c | 17 ++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-)
examples/l3fwd/em_route_parse.c +10 -8
@@ -249,8 +249,7 @@ voidread_config_files_em (void) {/* ipv4 check */ -if (parm_config.rule_ipv4_name !=NULL && - parm_config.rule_ipv6_name !=NULL ) { +if (parm_config.rule_ipv4_name !=NULL ) {/* ipv4 check */ route_num_v4 =em_add_rules (parm_config.rule_ipv4_name, &em_route_base_v4, &em_parse_v4_rule);
@@ -258,7 +257,14 @@ read_config_files_em(void)em_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add EM IPv4 rules\n" ); } - + }else { +RTE_LOG (INFO ,L3FWD ,"Missing IPv4 rule file, using default instead\n" ); +if (em_add_default_v4_rules () <0 ) { +em_free_routes (); +rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); + } + } +if (parm_config.rule_ipv6_name !=NULL ) {/* ipv6 check */ route_num_v6 =em_add_rules (parm_config.rule_ipv6_name, &em_route_base_v6, &em_parse_v6_rule);
@@ -267,11 +273,7 @@ read_config_files_em(void)rte_exit (EXIT_FAILURE ,"Failed to add EM IPv6 rules\n" ); } }else { -RTE_LOG (INFO ,L3FWD ,"Missing 1 or more rule files, using default instead\n" ); -if (em_add_default_v4_rules () <0 ) { -em_free_routes (); -rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); - } +RTE_LOG (INFO ,L3FWD ,"Missing IPv6 rule file, using default instead\n" );if (em_add_default_v6_rules () <0 ) {em_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add default IPv6 rules\n" );
examples/l3fwd/lpm_route_parse.c +10 -7
@@ -271,8 +271,7 @@ lpm_free_routes(void)void read_config_files_lpm (void ) { -if (parm_config.rule_ipv4_name !=NULL && - parm_config.rule_ipv6_name !=NULL ) { +if (parm_config.rule_ipv4_name !=NULL ) {/* ipv4 check */ route_num_v4 =lpm_add_rules (parm_config.rule_ipv4_name, &route_base_v4, &lpm_parse_v4_rule);
@@ -280,7 +279,15 @@ read_config_files_lpm(void)lpm_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add IPv4 rules\n" ); } + }else { +RTE_LOG (INFO ,L3FWD ,"Missing IPv4 rule file, using default instead\n" ); +if (lpm_add_default_v4_rules () <0 ) { +lpm_free_routes (); +rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); + } + } +if (parm_config.rule_ipv6_name !=NULL ) {/* ipv6 check */ route_num_v6 =lpm_add_rules (parm_config.rule_ipv6_name, &route_base_v6, &lpm_parse_v6_rule);
@@ -289,11 +296,7 @@ read_config_files_lpm(void)rte_exit (EXIT_FAILURE ,"Failed to add IPv6 rules\n" ); } }else { -RTE_LOG (INFO ,L3FWD ,"Missing 1 or more rule files, using default instead\n" ); -if (lpm_add_default_v4_rules () <0 ) { -lpm_free_routes (); -rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); - } +RTE_LOG (INFO ,L3FWD ,"Missing IPv6 rule file, using default instead\n" );if (lpm_add_default_v6_rules () <0 ) {lpm_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add default IPv6 rules\n" );
Signature · 1 line
2.25.1
PATCH v2 2/3 examples/l3fwd: fix return value on rules add
In reply to Gagandeep Singhfix return value on adding the EM or LPM rules.
--- examples/l3fwd/em_route_parse.c | 11 ++++++----- examples/l3fwd/lpm_route_parse.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-)
examples/l3fwd/em_route_parse.c +6 -5
@@ -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++;
examples/l3fwd/lpm_route_parse.c +6 -5
@@ -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++;
Signature · 1 line
2.25.1
PATCH v2 3/3 examples/l3fwd: enhance valid ports checking
In reply to Gagandeep SinghThe current port ID validation logic in the routes add code has two issues:
- It can pass if port ID in route is 31+.
- It silently skips rules with disabled or invalid port IDs
This patch is:
- Improving the enabled port IDs check logic.
- Introducing a user option, "exit_on_failure", to control the behavior when attempting to add rules for disabled or invalid port IDs (either exit or skip)
- Creating a port ID validation function for use across various setup functions
--- examples/l3fwd/em_route_parse.c | 4 +-- examples/l3fwd/l3fwd.h | 16 +++++++++ examples/l3fwd/l3fwd_em.c | 22 ++++++++---- examples/l3fwd/l3fwd_fib.c | 26 +++++++++----- examples/l3fwd/l3fwd_lpm.c | 26 +++++++++----- examples/l3fwd/l3fwd_route.h | 2 ++ examples/l3fwd/main.c | 60 +++++++++++++++++++++++++++------ 7 files changed, 122 insertions(+), 34 deletions(-)
examples/l3fwd/em_route_parse.c +2 -2
@@ -10,8 +10,8 @@#include "l3fwd.h" #include "l3fwd_route.h" -static struct em_rule *em_route_base_v4; -static struct em_rule *em_route_base_v6; +struct em_rule *em_route_base_v4; +struct em_rule *em_route_base_v6;enum {CB_FLD_DST_ADDR ,
examples/l3fwd/l3fwd.h +16 -0
@@ -56,6 +56,15 @@#define L3FWD_HASH_ENTRIES (1024*1024*1)#endif +/* Select Longest-Prefix, Exact match, Forwarding Information Base or Access Control. */ +enum L3FWD_LOOKUP_MODE { +L3FWD_LOOKUP_DEFAULT , +L3FWD_LOOKUP_LPM , +L3FWD_LOOKUP_EM , +L3FWD_LOOKUP_FIB , +L3FWD_LOOKUP_ACL +}; +struct parm_cfg {const char *rule_ipv4_name;const char *rule_ipv6_name;
@@ -101,6 +110,9 @@ extern struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];/* mask of enabled ports */ extern uint32_t enabled_port_mask; +/* Skip or exit on invalid route */ +extern bool exit_on_failure; +/* Used only in exact match mode. */ extern int ipv6;/**< ipv6 is false by default. */ extern uint32_t hash_entry_number;
@@ -218,6 +230,10 @@ init_mem(uint16_t portid, unsigned int nb_mbuf);int config_port_max_pkt_len (struct rte_eth_conf *conf,struct rte_eth_dev_info *dev_info); +int +l3fwd_validate_routes_port (enum L3FWD_LOOKUP_MODE mode,uint32_t i, +bool is_ipv4); +/* Function pointers for ACL, LPM, EM or FIB functionality. */ void setup_acl (const int socketid);
examples/l3fwd/l3fwd_em.c +16 -6
@@ -384,9 +384,14 @@ populate_ipv4_flow_into_table(const struct rte_hash *h)struct in_addr src;struct in_addr dst; -if ((1 << em_route_base_v4[i].if_out & - enabled_port_mask) ==0 ) -continue ; + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_EM , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX: %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, em_route_base_v4[i].if_out); +else +continue ; + } entry = &em_route_base_v4[i];convert_ipv4_5tuple (&(entry->v4_key), &newkey);
@@ -436,9 +441,14 @@ populate_ipv6_flow_into_table(const struct rte_hash *h)struct em_rule *entry;union ipv6_5tuple_host newkey; -if ((1 << em_route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_EM , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d given in IPv6 rule is not" +" enabled\n" , i, em_route_base_v6[i].if_out); +else +continue ; + } entry = &em_route_base_v6[i];convert_ipv6_5tuple (&(entry->v6_key), &newkey);
examples/l3fwd/l3fwd_fib.c +18 -8
@@ -670,10 +670,15 @@ setup_fib(const int socketid)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 ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_FIB , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, route_base_v4[i].if_out); +else +continue ; + }rte_eth_dev_info_get (route_base_v4[i].if_out, &dev_info);
@@ -724,10 +729,15 @@ setup_fib(const int socketid)/* Populate the fib IPv6 table. */ for (i =0 ; i < route_num_v6; i++) { -/* Skip unused ports. */ -if ((1 << route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; +/* Check for valid ports. */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_FIB , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d given in IPv6 rule is not" +" enabled\n" , i, route_base_v6[i].if_out); +else +continue ; + }rte_eth_dev_info_get (route_base_v6[i].if_out, &dev_info);
examples/l3fwd/l3fwd_lpm.c +18 -8
@@ -583,10 +583,15 @@ setup_lpm(const int socketid)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 ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_LPM , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX: %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, route_base_v4[i].if_out); +else +continue ; + }rte_eth_dev_info_get (route_base_v4[i].if_out, &dev_info);
@@ -627,10 +632,15 @@ setup_lpm(const int socketid)/* populate the LPM table */ for (i =0 ; i < route_num_v6; i++) { -/* skip unused ports */ -if ((1 << route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_LPM , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d Port ID %d given in IPv6 rule is not" +" enabled\n" , i, route_base_v6[i].if_out); +else +continue ; + }rte_eth_dev_info_get (route_base_v6[i].if_out, &dev_info);
examples/l3fwd/l3fwd_route.h +2 -0
@@ -82,6 +82,8 @@ struct em_rule {extern struct lpm_route_rule *route_base_v4;extern struct lpm_route_rule *route_base_v6; +extern struct em_rule *em_route_base_v4; +extern struct em_rule *em_route_base_v6;extern int route_num_v4;extern int route_num_v6;
examples/l3fwd/main.c +50 -10
114 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [v2 3/3] examples/l3fwd: enhance valid ports checking
Quoted 15 lines · On Tue, 6 Aug 2024 09:11:20 +0530 Gagandeep Singh <[email protected]> wrote:
The current port ID validation logic in the routes add code has two issues:
- It can pass if port ID in route is 31+.
- It silently skips rules with disabled or invalid port IDsThis patch is:
- Improving the enabled port IDs check logic.
- Introducing a user option, "exit_on_failure", to control the behavior when attempting to add rules for disabled or invalid port IDs (either exit or skip)
- Creating a port ID validation function for use across various setup functions
Quoted 1 line
Signed-off-by Gagandeep Singh <[email protected]>
Patch looks fine, but other changes in the intervening time have caused conflicts with this patch. Needs to be rebased.
Re: [v2 3/3] examples/l3fwd: enhance valid ports checking
13/11/2024 20:39, Stephen Hemminger:
Quoted 18 lines
Quoted 15 lines · On Tue, 6 Aug 2024 09:11:20 +0530 Gagandeep Singh <[email protected]> wrote:
The current port ID validation logic in the routes add code has two issues:
- It can pass if port ID in route is 31+.
- It silently skips rules with disabled or invalid port IDsThis patch is:
- Improving the enabled port IDs check logic.
- Introducing a user option, "exit_on_failure", to control the behavior when attempting to add rules for disabled or invalid port IDs (either exit or skip)
- Creating a port ID validation function for use across various setup functions
Quoted 4 lines
Quoted 1 line
Signed-off-by Gagandeep Singh <[email protected]>Patch looks fine, but other changes in the intervening time have caused conflicts with this patch. Needs to be rebased.
Waiting for a rebase please?
RE: [v2 3/3] examples/l3fwd: enhance valid ports checking
Hi,
Quoted 26 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, November 19, 2024 10:43 PM
To: Gagandeep Singh <[email protected]>
Cc: [email protected]; Stephen Hemminger <[email protected]>
Subject: Re: [v2 3/3] examples/l3fwd: enhance valid ports checking13/11/2024 20:39, Stephen Hemminger:
Quoted 18 lines
Quoted 15 lines · On Tue, 6 Aug 2024 09:11:20 +0530 Gagandeep Singh <[email protected]> wrote:
The current port ID validation logic in the routes add code has two issues:
- It can pass if port ID in route is 31+.
- It silently skips rules with disabled or invalid port IDsThis patch is:
- Improving the enabled port IDs check logic.
- Introducing a user option, "exit_on_failure", to control the behavior when attempting to add rules for disabled or invalid port IDs (either exit or skip)
- Creating a port ID validation function for use across various setup functions
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Gagandeep Singh <[email protected]>Patch looks fine, but other changes in the intervening time have caused conflicts with this patch. Needs to be rebased.
Waiting for a rebase please?
I have sent the rebase series as v3.
v3 cover L3fwd changes
In reply to Gagandeep Singhv3 changes:
* rebased the series to latest commit.
v2 changes:
* Handled a comment to enhance the invalid port ID logic and added a user option to decide exit or silently skip in case invalid port in the rules list.
Gagandeep Singh (3):
examples/l3fwd: support single route file
examples/l3fwd: fix return value on rules add
examples/l3fwd: enhance valid ports checking
examples/l3fwd/em_route_parse.c | 33 +++++++++--------- examples/l3fwd/l3fwd.h | 16 +++++++++ examples/l3fwd/l3fwd_em.c | 22 ++++++++---- examples/l3fwd/l3fwd_fib.c | 26 +++++++++----- examples/l3fwd/l3fwd_lpm.c | 26 +++++++++----- examples/l3fwd/l3fwd_route.h | 2 ++ examples/l3fwd/lpm_route_parse.c | 28 ++++++++------- examples/l3fwd/main.c | 58 +++++++++++++++++++++++++++----- 8 files changed, 153 insertions(+), 58 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/3 examples/l3fwd: support single route file
IPv6 rules file needs to be specified together with IPv4 rules file to configure user given rules. But if user want to give only IPv4 or only IPv6 rules, application returns error:
"Missing 1 or more rule files"
With this patch application can accept only IPv4,
only IPv6 or both IP rules.
--- examples/l3fwd/em_route_parse.c | 18 ++++++++++-------- examples/l3fwd/lpm_route_parse.c | 17 ++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-)
examples/l3fwd/em_route_parse.c +10 -8
@@ -249,8 +249,7 @@ voidread_config_files_em (void) {/* ipv4 check */ -if (parm_config.rule_ipv4_name !=NULL && - parm_config.rule_ipv6_name !=NULL ) { +if (parm_config.rule_ipv4_name !=NULL ) {/* ipv4 check */ route_num_v4 =em_add_rules (parm_config.rule_ipv4_name, &em_route_base_v4, &em_parse_v4_rule);
@@ -258,7 +257,14 @@ read_config_files_em(void)em_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add EM IPv4 rules\n" ); } - + }else { +RTE_LOG (INFO ,L3FWD ,"Missing IPv4 rule file, using default instead\n" ); +if (em_add_default_v4_rules () <0 ) { +em_free_routes (); +rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); + } + } +if (parm_config.rule_ipv6_name !=NULL ) {/* ipv6 check */ route_num_v6 =em_add_rules (parm_config.rule_ipv6_name, &em_route_base_v6, &em_parse_v6_rule);
@@ -267,11 +273,7 @@ read_config_files_em(void)rte_exit (EXIT_FAILURE ,"Failed to add EM IPv6 rules\n" ); } }else { -RTE_LOG (INFO ,L3FWD ,"Missing 1 or more rule files, using default instead\n" ); -if (em_add_default_v4_rules () <0 ) { -em_free_routes (); -rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); - } +RTE_LOG (INFO ,L3FWD ,"Missing IPv6 rule file, using default instead\n" );if (em_add_default_v6_rules () <0 ) {em_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add default IPv6 rules\n" );
examples/l3fwd/lpm_route_parse.c +10 -7
@@ -270,8 +270,7 @@ lpm_free_routes(void)void read_config_files_lpm (void ) { -if (parm_config.rule_ipv4_name !=NULL && - parm_config.rule_ipv6_name !=NULL ) { +if (parm_config.rule_ipv4_name !=NULL ) {/* ipv4 check */ route_num_v4 =lpm_add_rules (parm_config.rule_ipv4_name, &route_base_v4, &lpm_parse_v4_rule);
@@ -279,7 +278,15 @@ read_config_files_lpm(void)lpm_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add IPv4 rules\n" ); } + }else { +RTE_LOG (INFO ,L3FWD ,"Missing IPv4 rule file, using default instead\n" ); +if (lpm_add_default_v4_rules () <0 ) { +lpm_free_routes (); +rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); + } + } +if (parm_config.rule_ipv6_name !=NULL ) {/* ipv6 check */ route_num_v6 =lpm_add_rules (parm_config.rule_ipv6_name, &route_base_v6, &lpm_parse_v6_rule);
@@ -288,11 +295,7 @@ read_config_files_lpm(void)rte_exit (EXIT_FAILURE ,"Failed to add IPv6 rules\n" ); } }else { -RTE_LOG (INFO ,L3FWD ,"Missing 1 or more rule files, using default instead\n" ); -if (lpm_add_default_v4_rules () <0 ) { -lpm_free_routes (); -rte_exit (EXIT_FAILURE ,"Failed to add default IPv4 rules\n" ); - } +RTE_LOG (INFO ,L3FWD ,"Missing IPv6 rule file, using default instead\n" );if (lpm_add_default_v6_rules () <0 ) {lpm_free_routes ();rte_exit (EXIT_FAILURE ,"Failed to add default IPv6 rules\n" );
Signature · 1 line
2.25.1
PATCH v3 2/3 examples/l3fwd: fix return value on rules add
In reply to Gagandeep Singhfix return value on adding the EM or LPM rules.
--- examples/l3fwd/em_route_parse.c | 11 ++++++----- examples/l3fwd/lpm_route_parse.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-)
examples/l3fwd/em_route_parse.c +6 -5
@@ -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++;
examples/l3fwd/lpm_route_parse.c +6 -5
@@ -183,7 +183,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" );
@@ -236,13 +236,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++;
Signature · 1 line
2.25.1
PATCH v3 3/3 examples/l3fwd: enhance valid ports checking
In reply to Gagandeep SinghThe current port ID validation logic in the routes add code has two issues:
- It can pass if port ID in route is 31+.
- It silently skips rules with disabled or invalid port IDs
This patch is:
- Improving the enabled port IDs check logic.
- Introducing a user option, "exit_on_failure", to control the behavior when attempting to add rules for disabled or invalid port IDs (either exit or skip)
- Creating a port ID validation function for use across various setup functions
--- examples/l3fwd/em_route_parse.c | 4 +-- examples/l3fwd/l3fwd.h | 16 +++++++++ examples/l3fwd/l3fwd_em.c | 22 +++++++++---- examples/l3fwd/l3fwd_fib.c | 26 ++++++++++----- examples/l3fwd/l3fwd_lpm.c | 26 ++++++++++----- examples/l3fwd/l3fwd_route.h | 2 ++ examples/l3fwd/main.c | 58 ++++++++++++++++++++++++++++----- 7 files changed, 121 insertions(+), 33 deletions(-)
examples/l3fwd/em_route_parse.c +2 -2
@@ -10,8 +10,8 @@#include "l3fwd.h" #include "l3fwd_route.h" -static struct em_rule *em_route_base_v4; -static struct em_rule *em_route_base_v6; +struct em_rule *em_route_base_v4; +struct em_rule *em_route_base_v6;enum {CB_FLD_DST_ADDR ,
examples/l3fwd/l3fwd.h +16 -0
@@ -57,6 +57,15 @@#define L3FWD_HASH_ENTRIES (1024*1024*1)#endif +/* Select Longest-Prefix, Exact match, Forwarding Information Base or Access Control. */ +enum L3FWD_LOOKUP_MODE { +L3FWD_LOOKUP_DEFAULT , +L3FWD_LOOKUP_LPM , +L3FWD_LOOKUP_EM , +L3FWD_LOOKUP_FIB , +L3FWD_LOOKUP_ACL +}; +struct parm_cfg {const char *rule_ipv4_name;const char *rule_ipv6_name;
@@ -102,6 +111,9 @@ extern struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];/* mask of enabled ports */ extern uint32_t enabled_port_mask; +/* Skip or exit on invalid route */ +extern bool exit_on_failure; +/* Used only in exact match mode. */ extern int ipv6;/**< ipv6 is false by default. */ extern uint32_t hash_entry_number;
@@ -222,6 +234,10 @@ init_mem(uint16_t portid, unsigned int nb_mbuf);int config_port_max_pkt_len (struct rte_eth_conf *conf,struct rte_eth_dev_info *dev_info); +int +l3fwd_validate_routes_port (enum L3FWD_LOOKUP_MODE mode,uint32_t i, +bool is_ipv4); +/* Function pointers for ACL, LPM, EM or FIB functionality. */ void setup_acl (const int socketid);
examples/l3fwd/l3fwd_em.c +16 -6
@@ -384,9 +384,14 @@ populate_ipv4_flow_into_table(const struct rte_hash *h)struct in_addr src;struct in_addr dst; -if ((1 << em_route_base_v4[i].if_out & - enabled_port_mask) ==0 ) -continue ; + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_EM , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX: %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, em_route_base_v4[i].if_out); +else +continue ; + } entry = &em_route_base_v4[i];convert_ipv4_5tuple (&(entry->v4_key), &newkey);
@@ -436,9 +441,14 @@ populate_ipv6_flow_into_table(const struct rte_hash *h)struct em_rule *entry;union ipv6_5tuple_host newkey; -if ((1 << em_route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_EM , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d given in IPv6 rule is not" +" enabled\n" , i, em_route_base_v6[i].if_out); +else +continue ; + } entry = &em_route_base_v6[i];convert_ipv6_5tuple (&(entry->v6_key), &newkey);
examples/l3fwd/l3fwd_fib.c +18 -8
@@ -667,10 +667,15 @@ setup_fib(const int socketid)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 ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_FIB , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, route_base_v4[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v4[i].if_out, &dev_info);if (ret <0 )
@@ -725,10 +730,15 @@ setup_fib(const int socketid)/* Populate the fib IPv6 table. */ for (i =0 ; i < route_num_v6; i++) { -/* Skip unused ports. */ -if ((1 << route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; +/* Check for valid ports. */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_FIB , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d given in IPv6 rule is not" +" enabled\n" , i, route_base_v6[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v6[i].if_out, &dev_info);if (ret <0 )
examples/l3fwd/l3fwd_lpm.c +18 -8
@@ -583,10 +583,15 @@ setup_lpm(const int socketid)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 ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_LPM , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX: %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, route_base_v4[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v4[i].if_out, &dev_info);if (ret <0 )
@@ -630,10 +635,15 @@ setup_lpm(const int socketid)/* populate the LPM table */ for (i =0 ; i < route_num_v6; i++) { -/* skip unused ports */ -if ((1 << route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_LPM , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d Port ID %d given in IPv6 rule is not" +" enabled\n" , i, route_base_v6[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v6[i].if_out, &dev_info);if (ret <0 )
examples/l3fwd/l3fwd_route.h +2 -0
@@ -81,6 +81,8 @@ struct em_rule {extern struct lpm_route_rule *route_base_v4;extern struct lpm_route_rule *route_base_v6; +extern struct em_rule *em_route_base_v4; +extern struct em_rule *em_route_base_v6;extern int route_num_v4;extern int route_num_v6;
examples/l3fwd/main.c +49 -9
112 lines not on this page · raw message
Signature · 1 line
2.25.1
RE: [v3 3/3] examples/l3fwd: enhance valid ports checking
Quoted 281 lines
The current port ID validation logic in the routes add code has two issues:
- It can pass if port ID in route is 31+.
- It silently skips rules with disabled or invalid port IDsThis patch is:
- Improving the enabled port IDs check logic.
- Introducing a user option, "exit_on_failure", to control the behavior when attempting to add rules for disabled or invalid port IDs (either exit or skip)
- Creating a port ID validation function for use across various setup functionsSigned-off-by Gagandeep Singh <[email protected]>--- examples/l3fwd/em_route_parse.c | 4 +-- examples/l3fwd/l3fwd.h | 16 +++++++++ examples/l3fwd/l3fwd_em.c | 22 +++++++++---- examples/l3fwd/l3fwd_fib.c | 26 ++++++++++----- examples/l3fwd/l3fwd_lpm.c | 26 ++++++++++----- examples/l3fwd/l3fwd_route.h | 2 ++ examples/l3fwd/main.c | 58 ++++++++++++++++++++++++++++----- 7 files changed, 121 insertions(+), 33 deletions(-)examples/l3fwd/em_route_parse.c +2
-2@@ -10,8 +10,8 @@#include "l3fwd.h" #include "l3fwd_route.h" -static struct em_rule *em_route_base_v4; -static struct em_rule *em_route_base_v6; +struct em_rule *em_route_base_v4; +struct em_rule *em_route_base_v6;enum {CB_FLD_DST_ADDR ,examples/l3fwd/l3fwd.h +16
-0@@ -57,6 +57,15 @@#define L3FWD_HASH_ENTRIES (1024*1024*1)#endif +/* Select Longest-Prefix, Exact match, Forwarding Information Base or Access Control. */ +enum L3FWD_LOOKUP_MODE { +L3FWD_LOOKUP_DEFAULT , +L3FWD_LOOKUP_LPM , +L3FWD_LOOKUP_EM , +L3FWD_LOOKUP_FIB , +L3FWD_LOOKUP_ACL +}; +struct parm_cfg {const char *rule_ipv4_name;const char *rule_ipv6_name;@@ -102,6 +111,9 @@ extern struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];/* mask of enabled ports */ extern uint32_t enabled_port_mask; +/* Skip or exit on invalid route */ +extern bool exit_on_failure; +/* Used only in exact match mode. */ extern int ipv6;/**< ipv6 is false by default. */ extern uint32_t hash_entry_number;@@ -222,6 +234,10 @@ init_mem(uint16_t portid, unsigned int nb_mbuf);int config_port_max_pkt_len (struct rte_eth_conf *conf,struct rte_eth_dev_info *dev_info); +int +l3fwd_validate_routes_port (enum L3FWD_LOOKUP_MODE mode,uint32_t i, +bool is_ipv4); +/* Function pointers for ACL, LPM, EM or FIB functionality. */ void setup_acl (const int socketid);examples/l3fwd/l3fwd_em.c +16
-6@@ -384,9 +384,14 @@ populate_ipv4_flow_into_table(const struct rte_hash *h)struct in_addr src;struct in_addr dst; -if ((1 << em_route_base_v4[i].if_out & - enabled_port_mask) ==0 ) -continue ; + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_EM , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX: %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, em_route_base_v4[i].if_out); +else +continue ; + } entry = &em_route_base_v4[i];convert_ipv4_5tuple (&(entry->v4_key), &newkey);@@ -436,9 +441,14 @@ populate_ipv6_flow_into_table(const struct rte_hash *h)struct em_rule *entry;union ipv6_5tuple_host newkey; -if ((1 << em_route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_EM , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d given in IPv6 rule is not" +" enabled\n" , i, em_route_base_v6[i].if_out); +else +continue ; + } entry = &em_route_base_v6[i];convert_ipv6_5tuple (&(entry->v6_key), &newkey);examples/l3fwd/l3fwd_fib.c +18
-8@@ -667,10 +667,15 @@ setup_fib(const int socketid)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 ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_FIB , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, route_base_v4[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v4[i].if_out, &dev_info);if (ret <0 )@@ -725,10 +730,15 @@ setup_fib(const int socketid)/* Populate the fib IPv6 table. */ for (i =0 ; i < route_num_v6; i++) { -/* Skip unused ports. */ -if ((1 << route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; +/* Check for valid ports. */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_FIB , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d: Port ID %d given in IPv6 rule is not" +" enabled\n" , i, route_base_v6[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v6[i].if_out, &dev_info);if (ret <0 )examples/l3fwd/l3fwd_lpm.c +18
-8@@ -583,10 +583,15 @@ setup_lpm(const int socketid)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 ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_LPM , i, true); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX: %d: Port ID %d in IPv4 rule is not" +" enabled\n" , i, route_base_v4[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v4[i].if_out, &dev_info);if (ret <0 )@@ -630,10 +635,15 @@ setup_lpm(const int socketid)/* populate the LPM table */ for (i =0 ; i < route_num_v6; i++) { -/* skip unused ports */ -if ((1 << route_base_v6[i].if_out & - enabled_port_mask) ==0 ) -continue ; +/* Check for valid ports */ + ret =l3fwd_validate_routes_port (L3FWD_LOOKUP_LPM , i, false); +if (ret) { +if (exit_on_failure) +rte_exit (EXIT_FAILURE ,"IDX %d Port ID %d given in IPv6 rule is not" +" enabled\n" , i, route_base_v6[i].if_out); +else +continue ; + } ret =rte_eth_dev_info_get (route_base_v6[i].if_out, &dev_info);if (ret <0 )examples/l3fwd/l3fwd_route.h +2
-0@@ -81,6 +81,8 @@ struct em_rule {extern struct lpm_route_rule *route_base_v4;extern struct lpm_route_rule *route_base_v6; +extern struct em_rule *em_route_base_v4; +extern struct em_rule *em_route_base_v6;extern int route_num_v4;extern int route_num_v6;examples/l3fwd/main.c +25
-9@@ -63,14 +63,6 @@ uint32_t mb_mempool_cache_size = MEMPOOL_CACHE_SIZE;/**< Ports set in promiscuous mode off by default. */ static int promiscuous_on; -/* Select Longest-Prefix, Exact match, Forwarding Information Base or Access Control. */ -enum L3FWD_LOOKUP_MODE { -L3FWD_LOOKUP_DEFAULT , -L3FWD_LOOKUP_LPM , -L3FWD_LOOKUP_EM , -L3FWD_LOOKUP_FIB , -L3FWD_LOOKUP_ACL -};static enum L3FWD_LOOKUP_MODE lookup_mode;/* Global variables. */ @@ -92,7 +84,8 @@ xmm_t val_eth[RTE_MAX_ETHPORTS];/* mask of enabled ports */ uint32_t enabled_port_mask; - +bool exit_on_failure;/**< Skip the route rule with invalid or */ +/**< disabled port ID */ /* Used only in exact match mode. */ int ipv6;/**< ipv6 is false by default. */ @@ -271,6 +264,43 @@ l3fwd_set_alg(const char *optarg) parm_config.alg =parse_acl_alg (optarg); } +/* This function will work only after read_config_files step */ +int +l3fwd_validate_routes_port (enum L3FWD_LOOKUP_MODE mode,uint32_t i, +bool is_ipv4) +{ +uint32_t max_port_count = (sizeof (enabled_port_mask) *CHAR_BIT ); + +if (mode ==L3FWD_LOOKUP_LPM || + mode ==L3FWD_LOOKUP_FIB ) { +if (is_ipv4) { +if (route_base_v4[i].if_out >= max_port_count || + ((1 << route_base_v4[i].if_out & + enabled_port_mask) ==0 )) +return -1 ; + }else { +if (route_base_v6[i].if_out >= max_port_count || + ((1 << route_base_v6[i].if_out & + enabled_port_mask) ==0 )) +return -1 ; + } + }else if (mode ==L3FWD_LOOKUP_EM ) { +if (is_ipv4) { + if (em_route_base_v4[i].if_out >= max_port_count ||
examples/l3fwd/main.c l3fwd_set_alg(const char *optarg) · line 299
Quoted 10 lines
examples/l3fwd/main.c +10
-0+ ((1 << em_route_base_v4[i].if_out & + enabled_port_mask) == 0)) +return -1 ; + }else { +if (em_route_base_v6[i].if_out >= max_port_count || + ((1 << em_route_base_v6[i].if_out & + enabled_port_mask) ==0 )) +return -1 ; + } + }
Stupid q - why we don't have any checks for ACL mode?
Quoted 2 lines
examples/l3fwd/main.c +2
-0+return 0 ; +}
Re: [v3 0/3] L3fwd changes
In reply to Gagandeep SinghQuoted 13 lines · On Wed, 20 Nov 2024 09:35:13 +0530 Gagandeep Singh <[email protected]> wrote:
v3 changes:
* rebased the series to latest commit.v2 changes:
* Handled a comment to enhance the invalid port ID logic and added a user option to decide exit or silently skip in case invalid port in the rules list.Gagandeep Singh (3):
examples/l3fwd: support single route file
examples/l3fwd: fix return value on rules add
examples/l3fwd: enhance valid ports checking
Quoted 10 lines
examples/l3fwd/em_route_parse.c | 33 +++++++++--------- examples/l3fwd/l3fwd.h | 16 +++++++++ examples/l3fwd/l3fwd_em.c | 22 ++++++++---- examples/l3fwd/l3fwd_fib.c | 26 +++++++++----- examples/l3fwd/l3fwd_lpm.c | 26 +++++++++----- examples/l3fwd/l3fwd_route.h | 2 ++ examples/l3fwd/lpm_route_parse.c | 28 ++++++++------- examples/l3fwd/main.c | 58 +++++++++++++++++++++++++++----- 8 files changed, 153 insertions(+), 58 deletions(-)
These patches appear to have gotten stuck in the backlog. Running automated patch review shows minor issues. Please rebase, fix issues and resubmit.
## DPDK Patch Review: l3fwd Patchset v3 (bundle-1634)
### Overview
This patchset contains 3 patches by Gagandeep Singh targeting the l3fwd example application.
---
## Patch 1/3: examples/l3fwd: support single route file
### Commit Message
| Check | Status | Notes | |-------|--------|-------| | Subject ≤60 chars | ✅ Pass | 41 characters | | Lowercase after colon | ✅ Pass | | | Correct prefix | ✅ Pass | `examples/l3fwd:` is correct | | No trailing period | ✅ Pass | | | Imperative mood | ✅ Pass | "support" | | Body wrapped ≤75 chars | ✅ Pass | | | Body doesn't start with "It" | ✅ Pass | | | Signed-off-by present | ✅ Pass | Line 108 |
### Code Review
| Check | Status | Notes | |-------|--------|-------| | Lines ≤100 chars | ✅ Pass | | | Consistent style | ✅ Pass | |
**Info:** This is a feature patch that decouples IPv4 and IPv6 rule file requirements. Logic looks sound.
---
## Patch 2/3: examples/l3fwd: fix return value on rules add
### Commit Message
| Check | Status | Notes | |-------|--------|-------| | Subject ≤60 chars | ✅ Pass | 45 characters | | Lowercase after colon | ✅ Pass | | | Correct prefix | ✅ Pass | | | No trailing period | ✅ Pass | | | Body wrapped ≤75 chars | ✅ Pass | | | Body doesn't start with "It" | ✅ Pass | Starts with "fix" | | Signed-off-by present | ✅ Pass | | | Fixes: tag present | ✅ Pass | Two Fixes tags (lines 304-305) | | Fixes: format (12-char SHA) | ✅ Pass | `e7e6dd643092`, `52def963fc1c` | | Cc: [email protected] | ✅ Pass | Line 307 | | Tag order correct | ✅ Pass | Fixes → Cc → blank → Signed-off-by |
### Issues
**Warning:** The commit body is very terse — just one line:
``` fix return value on adding the EM or LPM rules. ```
Consider expanding to explain *why* this matters (e.g., "The original code always returned -EINVAL, losing the actual parser error code which is needed for debugging").
### Code Review
| Check | Status | Notes | |-------|--------|-------| | Lines ≤100 chars | ✅ Pass | | | Code compiles independently | ✅ Pass | Appears self-contained |
**Info:** Good fix — propagates actual error codes instead of masking them with -EINVAL.
---
## Patch 3/3: examples/l3fwd: validate port ID in route rules
### Commit Message
| Check | Status | Notes | |-------|--------|-------| | Subject ≤60 chars | ✅ Pass | ~47 characters | | Lowercase after colon | ✅ Pass | | | Correct prefix | ✅ Pass | | | No trailing period | ✅ Pass | | | Body wrapped ≤75 chars | ✅ Pass | | | Signed-off-by present | ✅ Pass | |
### Issues
**Warning — Missing Fixes: tag:** The commit message explicitly states this fixes a bug:
Quoted 2 lines
"The current port ID validation logic... has two issues:
- It can pass if port ID in route is 31+."
This is a bug fix and should have a Fixes: tag referencing the commit that introduced the flawed port validation logic.
**Warning — Missing Cc: [email protected]:** Since this fixes a bug (port IDs ≥32 bypass validation), it's a candidate for stable backport.
### Code Review
| Check | Status | Notes | |-------|--------|-------| | Lines ≤100 chars | ⚠️ Check | Some lines are borderline | | Explicit comparisons | ✅ Pass | Uses `== 0`, `!= NULL` style |
**Error — Inconsistent error message format:**
The error messages across files use different formats:
| Location | Message Format | |----------|----------------| | l3fwd_em.c:575 | `"IDX: %d: Port ID %d in IPv4 rule..."` | | l3fwd_em.c:593 | `"IDX %d: Port ID %d given in IPv6 rule..."` | | l3fwd_fib.c:617 | `"IDX %d: Port ID %d in IPv4 rule..."` | | l3fwd_lpm.c:661 | `"IDX: %d: Port ID %d in IPv4 rule..."` |
Should standardize to one format (suggest: "IDX %d: Port ID %d...").
**Warning — Comment style:**
```c bool exit_on_failure; /**< Skip the route rule with invalid or */ /**< disabled port ID */ ```
Multi-line Doxygen comments should use a single /** ... */ block, not multiple /**< continuations.
**Info — Code duplication:** The l3fwd_validate_routes_port() function has significant code duplication between the LPM/FIB and EM branches. Consider refactoring to reduce repetition.
---
## Summary
| Patch | Verdict | Blocking Issues | |-------|---------|-----------------| | 1/3 | **Acceptable** | None | | 2/3 | **Acceptable** | None (minor: terse body) | | 3/3 | **Needs revision** | Missing Fixes tag, inconsistent error messages |
### Required Changes for Patch 3/3:
1. Add Fixes: tag identifying the original commit with the port validation bug
2. Add Cc: [email protected]
3. Standardize error message format across all files
### Recommended Changes:
- Patch 2/3: Expand commit body to explain the impact of the fix
- Patch 3/3: Clean up the multi-line Doxygen comment
- Patch 3/3: Consider refactoring l3fwd_validate_routes_port() to reduce duplication