aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2022-10-17 11:40:32 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2022-10-17 13:35:40 +0200
commitd333065abaf0891f4004ca92ef3fadf32eb70767 (patch)
tree76d6ac11579fce4483febb54a773b9941a8a653a
parent1831c27adeb851b7b28e57342f4893a1d3b7dce2 (diff)
fix(hicn-light): fib_contains incorrectly matches subprefixes
Change-Id: I9575012a4980649a05a490057bf4a71675792396 Ticket: HICN-811 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
-rw-r--r--hicn-light/src/hicn/core/fib.c4
-rw-r--r--hicn-light/src/hicn/test/test-fib.cc51
2 files changed, 53 insertions, 2 deletions
diff --git a/hicn-light/src/hicn/core/fib.c b/hicn-light/src/hicn/core/fib.c
index 2e8492457..70c5599fb 100644
--- a/hicn-light/src/hicn/core/fib.c
+++ b/hicn-light/src/hicn/core/fib.c
@@ -381,6 +381,8 @@ fib_entry_t *fib_contains(const fib_t *fib, const hicn_prefix_t *prefix) {
if (!curr) return NULL;
if (search.match_len != prefix_len) return NULL;
+ if (prefix_len != search.prefix_len) return NULL;
+
return curr->is_used ? curr->entry : NULL;
}
@@ -488,7 +490,7 @@ static void fib_node_remove(fib_t *fib, const hicn_prefix_t *prefix) {
case 0:
_fib_remove(fib, curr, search.parent);
- if (!search.parent->is_used)
+ if (search.parent && !search.parent->is_used)
_fib_remove(fib, search.parent, search.gparent);
break;
}
diff --git a/hicn-light/src/hicn/test/test-fib.cc b/hicn-light/src/hicn/test/test-fib.cc
index d2c5d1e1c..6e1f59077 100644
--- a/hicn-light/src/hicn/test/test-fib.cc
+++ b/hicn-light/src/hicn/test/test-fib.cc
@@ -49,10 +49,11 @@ class FibTest : public ::testing::Test {
fib_t *fib;
};
-void _fib_add_prefix(fib_t *fib, const hicn_prefix_t *prefix) {
+fib_entry_t *_fib_add_prefix(fib_t *fib, const hicn_prefix_t *prefix) {
fib_entry_t *entry =
fib_entry_create(prefix, STRATEGY_TYPE_UNDEFINED, NULL, NULL);
fib_add(fib, entry);
+ return entry;
}
#if 0
@@ -119,6 +120,7 @@ TEST_F(FibTest, FibAddFive) {
HICN_PREFIX(b002_3, "b002::3/128");
HICN_PREFIX(inner_b002_2, "b002::2/127");
HICN_PREFIX(inner_b002_abcd_0, "b002::abcd:0:0:0/127");
+
const hicn_prefix_t *prefix_array[] = {
&b002_2, &inner_b002_2, &b002_3, &b002,
&b002_abcd_0, &inner_b002_abcd_0, &b002_abcd_1};
@@ -135,3 +137,50 @@ TEST_F(FibTest, FibAddFive) {
EXPECT_TRUE(fib_is_valid(fib));
EXPECT_TRUE(fib_check_preorder(fib, prefix_array, used_array));
}
+
+TEST_F(FibTest, FibAddRemove) {
+ HICN_PREFIX(b002_64, "b002::/64");
+ HICN_PREFIX(b002_128, "b002::/128");
+
+ const hicn_prefix_t *prefix_array_1[] = {&b002_128};
+ bool used_array_1[] = {true};
+ const hicn_prefix_t *prefix_array_2[] = {};
+ bool used_array_2[] = {};
+ const hicn_prefix_t *prefix_array_3[] = {&b002_64};
+ bool used_array_3[] = {true};
+
+ fib_entry_t *entry = _fib_add_prefix(fib, &b002_128);
+ fib_dump(fib);
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array_1, used_array_1));
+
+ fib_remove_entry(fib, entry);
+ fib_dump(fib);
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array_2, used_array_2));
+
+ entry = _fib_add_prefix(fib, &b002_64);
+ fib_dump(fib);
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array_3, used_array_3));
+}
+
+TEST_F(FibTest, FibAddNested) {
+ HICN_PREFIX(b002_64, "b002::/64");
+ HICN_PREFIX(b002_128, "b002::/128");
+
+ const hicn_prefix_t *prefix_array_1[] = {&b002_128};
+ bool used_array_1[] = {true};
+ const hicn_prefix_t *prefix_array_2[] = {&b002_128, &b002_64};
+ bool used_array_2[] = {true, true};
+
+ _fib_add_prefix(fib, &b002_128);
+ fib_dump(fib);
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array_1, used_array_1));
+
+ _fib_add_prefix(fib, &b002_64);
+ fib_dump(fib);
+ EXPECT_TRUE(fib_is_valid(fib));
+ EXPECT_TRUE(fib_check_preorder(fib, prefix_array_2, used_array_2));
+}