lpm: skip table entries update if rules found
authorYangchao Zhou <zhouyates@gmail.com>
Mon, 20 Apr 2020 02:48:50 +0000 (10:48 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Fri, 24 Apr 2020 17:19:44 +0000 (19:19 +0200)
Table entries do not need to be updated if the same rules can be found.

Signed-off-by: Yangchao Zhou <zhouyates@gmail.com>
Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
lib/librte_lpm/rte_lpm.c

index 2687564..38ab512 100644 (file)
@@ -283,8 +283,12 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
 
                for (; rule_index < last_rule; rule_index++) {
 
-                       /* If rule already exists update its next_hop and return. */
+                       /* If rule already exists update next hop and return. */
                        if (lpm->rules_tbl[rule_index].ip == ip_masked) {
+
+                               if (lpm->rules_tbl[rule_index].next_hop
+                                               == next_hop)
+                                       return -EEXIST;
                                lpm->rules_tbl[rule_index].next_hop = next_hop;
 
                                return rule_index;
@@ -674,6 +678,12 @@ 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 The rule is the same as
+        * the rule in the rules 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;