[v2,1/3] examples/l3fwd: support single route file

Message ID 20240806034120.3165295-2-g.singh@nxp.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series L3fwd changes |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Gagandeep Singh Aug. 6, 2024, 3:41 a.m. UTC
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.

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

Patch

diff --git a/examples/l3fwd/em_route_parse.c b/examples/l3fwd/em_route_parse.c
index 6c16832e94..da23356dd6 100644
--- a/examples/l3fwd/em_route_parse.c
+++ b/examples/l3fwd/em_route_parse.c
@@ -249,8 +249,7 @@  void
 read_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");
diff --git a/examples/l3fwd/lpm_route_parse.c b/examples/l3fwd/lpm_route_parse.c
index f2028d79e1..f7d44aa2cd 100644
--- a/examples/l3fwd/lpm_route_parse.c
+++ b/examples/l3fwd/lpm_route_parse.c
@@ -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");