[dpdk-dev] [PATCH] lpm: skip table entries update if rules found

Yangchao Zhou zhouyates at gmail.com
Fri Apr 17 15:48:30 CEST 2020


Table entries do not need to be updated if the same rules can be found.

Signed-off-by: Yangchao Zhou <zhouyates at gmail.com>
---
 lib/librte_lpm/rte_lpm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
index 268756419..ee44fc4e5 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -287,7 +287,7 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
 			if (lpm->rules_tbl[rule_index].ip == ip_masked) {
 				lpm->rules_tbl[rule_index].next_hop = next_hop;
 
-				return rule_index;
+				return -EEXIST;
 			}
 		}
 
@@ -674,6 +674,10 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
 	/* Add the rule to the rule table. */
 	rule_index = rule_add(lpm, ip_masked, depth, next_hop);
 
+	/* Skip table entries update if rule is found in rule table */
+	if (rule_index == -EEXIST)
+		return 0;
+
 	/* If the is no space available for new rule return error. */
 	if (rule_index < 0) {
 		return rule_index;
-- 
2.17.1



More information about the dev mailing list