]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_table.c
bgpd: fix bgp_table range lookup
[mirror_frr.git] / bgpd / bgp_table.c
index 234553b6ead27dd8262d00e666f3115b86a62c9e..53175bfccf05828d513c1c0626541053ac35c2f1 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_table.h"
+#include "bgp_addpath.h"
 
 void bgp_table_lock(struct bgp_table *rt)
 {
@@ -66,6 +67,8 @@ static struct route_node *bgp_node_create(route_table_delegate_t *delegate,
 {
        struct bgp_node *node;
        node = XCALLOC(MTYPE_BGP_NODE, sizeof(struct bgp_node));
+
+       RB_INIT(bgp_adj_out_rb, &node->adj_out);
        return bgp_node_to_rnode(node);
 }
 
@@ -76,7 +79,16 @@ static void bgp_node_destroy(route_table_delegate_t *delegate,
                             struct route_table *table, struct route_node *node)
 {
        struct bgp_node *bgp_node;
+       struct bgp_table *rt;
        bgp_node = bgp_node_from_rnode(node);
+       rt = table->info;
+
+       if (rt->bgp) {
+               bgp_addpath_free_node_data(&rt->bgp->tx_addpath,
+                                        &bgp_node->tx_addpath,
+                                        rt->afi, rt->safi);
+       }
+
        XFREE(MTYPE_BGP_NODE, bgp_node);
 }
 
@@ -101,10 +113,10 @@ struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t afi, safi_t safi)
        /*
         * Set up back pointer to bgp_table.
         */
-       rt->route_table->info = rt;
+       route_table_set_info(rt->route_table, rt);
 
        /*
-        * pointer to bgp instance allows working back from bgp_info to bgp
+        * pointer to bgp instance allows working back from bgp_path_info to bgp
         */
        rt->bgp = bgp;
 
@@ -144,9 +156,12 @@ 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->info && node->p.prefixlen == p->prefixlen) {
+       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;
                        break;
                }
@@ -154,22 +169,22 @@ 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);
 
-       if (matched->info) {
+       if (bgp_node_has_bgp_path_info_data(matched)) {
                bgp_lock_node(matched);
                listnode_add(matches, matched);
        }
 
        while ((node = bgp_route_next_until_maxlen(node, matched, maxlen))) {
                if (prefix_match(p, &node->p)) {
-                       if (node->info) {
+                       if (bgp_node_has_bgp_path_info_data(node)) {
                                bgp_lock_node(node);
                                listnode_add(matches, node);
                        }