]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: fix bgp_table range lookup
authorMarcel Röthke <marcel.roethke@haw-hamburg.de>
Fri, 16 Aug 2019 14:20:05 +0000 (16:20 +0200)
committerMarcel Röthke <marcel.roethke@haw-hamburg.de>
Tue, 20 Aug 2019 08:31:43 +0000 (10:31 +0200)
In case the topmost node has a larger prefix length than the lookup
prefix it never matches even if it was still lower than maxlen

This also alters a test case to check for this bug.

Signed-off-by: Marcel Röthke <marcel.roethke@haw-hamburg.de>
bgpd/bgp_table.c
tests/bgpd/test_bgp_table.c
tests/bgpd/test_bgp_table.py

index ecde71279d2deed6f5b6e96d49cea506afd5c5f2..53175bfccf05828d513c1c0626541053ac35c2f1 100644 (file)
@@ -156,8 +156,10 @@ void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p,
        struct bgp_node *node = bgp_node_from_rnode(table->route_table->top);
        struct bgp_node *matched = NULL;
 
-       while (node && node->p.prefixlen <= p->prefixlen
-              && prefix_match(&node->p, p)) {
+       if (node == NULL)
+               return;
+
+       while (node->p.prefixlen <= p->prefixlen && prefix_match(&node->p, p)) {
                if (bgp_node_has_bgp_path_info_data(node)
                    && node->p.prefixlen == p->prefixlen) {
                        matched = node;
@@ -167,10 +169,10 @@ void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p,
                        &p->u.prefix, node->p.prefixlen)]);
        }
 
-       if (node == NULL)
-               return;
-
-       if ((matched == NULL && node->p.prefixlen > maxlen) || !node->parent)
+       if (matched == NULL && node->p.prefixlen <= maxlen
+           && prefix_match(p, &node->p) && node->parent == NULL)
+               matched = node;
+       else if ((matched == NULL && node->p.prefixlen > maxlen) || !node->parent)
                return;
        else if (matched == NULL)
                matched = node = bgp_node_from_rnode(node->parent);
index 7b38df5f66a27e092c4e1a96c301ec349f87e36c..819c2d728269b6e95ee593bf5d2e7cb660aae5c5 100644 (file)
@@ -183,7 +183,7 @@ static void test_range_lookup(void)
 
        do_test(table, "16.0.0.0/8", 16, "16.0.0.0/16", NULL);
 
-       do_test(table, "0.0.0.0/3", 21, "1.16.0.0/16", "1.16.128.0/18",
+       do_test(table, "0.0.0.0/2", 21, "1.16.0.0/16", "1.16.128.0/18",
                "1.16.192.0/18", "1.16.64.0/19", "1.16.160.0/19",
                "1.16.32.0/20", "1.16.32.0/21", "16.0.0.0/16", NULL);
 }
index 4423530fe0e31f49c9efe81c1570bb85e1cc5c8d..4deaf08c22e16dda9890cdc9fce53c65c57d25bd 100644 (file)
@@ -3,5 +3,5 @@ import frrtest
 class TestTable(frrtest.TestMultiOut):
     program = './test_bgp_table'
 
-for i in range(6):
+for i in range(9):
     TestTable.onesimple('Checks successfull')