lpm: fix condition check in delete
authorNa Na <nana.nn@alibaba-inc.com>
Tue, 3 Nov 2015 02:17:40 +0000 (10:17 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 4 Nov 2015 00:13:11 +0000 (01:13 +0100)
Fixes an issue of check logic in delete_depth_small function.

For a tbl24 entry, the 'ext_entry' field indicates whether we need
to use tbl8_gindex to read the next_hop from a tbl8 entry, or whether
it can be read directly from this entry.

If a route is deleted, the prefix of previous route is used to override
the deleted route.

When checking the depth of the previous route the conditional checks
both the ext_entry and the depth, but the "else" leg fails to take
account that the condition could fail for one of two possible reasons,
leading to an incorrect flow when 'ext_entry == 0' is true,
but 'lpm->tbl24[i].depth > depth' is false.
The fix here is to add a condition check to the else leg so that it
only executes when ext_entry is set.

Signed-off-by: Na Na <nana.nn@alibaba-inc.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
lib/librte_lpm/rte_lpm.c

index 163ba3c..57ec2f0 100644 (file)
@@ -734,8 +734,7 @@ delete_depth_small(struct rte_lpm *lpm, uint32_t ip_masked,
                        if (lpm->tbl24[i].ext_entry == 0 &&
                                        lpm->tbl24[i].depth <= depth ) {
                                lpm->tbl24[i].valid = INVALID;
                        if (lpm->tbl24[i].ext_entry == 0 &&
                                        lpm->tbl24[i].depth <= depth ) {
                                lpm->tbl24[i].valid = INVALID;
-                       }
-                       else {
+                       } else if (lpm->tbl24[i].ext_entry == 1) {
                                /*
                                 * If TBL24 entry is extended, then there has
                                 * to be a rule with depth >= 25 in the
                                /*
                                 * If TBL24 entry is extended, then there has
                                 * to be a rule with depth >= 25 in the
@@ -780,8 +779,7 @@ delete_depth_small(struct rte_lpm *lpm, uint32_t ip_masked,
                        if (lpm->tbl24[i].ext_entry == 0 &&
                                        lpm->tbl24[i].depth <= depth ) {
                                lpm->tbl24[i] = new_tbl24_entry;
                        if (lpm->tbl24[i].ext_entry == 0 &&
                                        lpm->tbl24[i].depth <= depth ) {
                                lpm->tbl24[i] = new_tbl24_entry;
-                       }
-                       else {
+                       } else  if (lpm->tbl24[i].ext_entry == 1) {
                                /*
                                 * If TBL24 entry is extended, then there has
                                 * to be a rule with depth >= 25 in the
                                /*
                                 * If TBL24 entry is extended, then there has
                                 * to be a rule with depth >= 25 in the