]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Fix memleak, adapt adv- to recv-routes code
authorPascal Mathis <mail@pascalmathis.com>
Wed, 16 May 2018 19:55:55 +0000 (21:55 +0200)
committerPascal Mathis <mail@pascalmathis.com>
Wed, 16 May 2018 20:20:44 +0000 (22:20 +0200)
This commit tries to adapt a similar codeflow within the `show bgp [afi]
[safi] neighbor <neighbor> advertised-routes` command compared to its
`received-routes` and `filtered-routes` opponents. Some branching code
has been restructured to achieve this.

Additionally, this commit fixes a memory leak within `received-routes`
(and `filtered-routes`, although the issue has been present before the
previous commit!) where the previous implementation forgot to
deduplicate the BGP attributes.

When a user called `<...> received-routes route-map <RM-TEST>` and that
routemap changed any AS path or community parameters, the duplicated
memory for these parameters was never freed. This has been fixed by
ensuring to call `bgp_attr_undup()` accordingly.

Signed-off-by: Pascal Mathis <mail@pascalmathis.com>
bgpd/bgp_route.c

index 31aca9edd61bae497069b757315d790d652194b6..84ea33b586b32cb962da48c44e041904b7fa3b90 100644 (file)
@@ -10365,8 +10365,10 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
                                                         afi, safi, rmap_name);
 
                                if (type == bgp_show_adj_route_filtered
-                                   && ret != RMAP_DENY)
+                                   && ret != RMAP_DENY) {
+                                       bgp_attr_undup(&attr, ain->attr);
                                        continue;
+                               }
 
                                if (type == bgp_show_adj_route_received
                                    && ret == RMAP_DENY)
@@ -10374,12 +10376,13 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
 
                                route_vty_out_tmp(vty, &rn->p, &attr, safi,
                                                  use_json, json_ar);
+                               bgp_attr_undup(&attr, ain->attr);
                                output_count++;
                        }
                } else if (type == bgp_show_adj_route_advertised) {
                        for (adj = rn->adj_out; adj; adj = adj->next)
                                SUBGRP_FOREACH_PEER (adj->subgroup, paf) {
-                                       if (paf->peer != peer)
+                                       if (paf->peer != peer || !adj->attr)
                                                continue;
 
                                        if (header1) {
@@ -10427,7 +10430,6 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
                                                }
                                                header1 = 0;
                                        }
-
                                        if (header2) {
                                                if (!use_json)
                                                        vty_out(vty,
@@ -10435,24 +10437,22 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
                                                header2 = 0;
                                        }
 
-                                       if (adj->attr) {
-                                               bgp_attr_dup(&attr, adj->attr);
-                                               ret = bgp_output_modifier(
-                                                       peer, &rn->p, &attr,
-                                                       afi, safi, rmap_name);
-                                               if (ret != RMAP_DENY) {
-                                                       route_vty_out_tmp(
-                                                               vty, &rn->p,
-                                                               &attr, safi,
-                                                               use_json,
-                                                               json_ar);
-                                                       output_count++;
-                                               } else
-                                                       filtered_count++;
-
-                                               bgp_attr_undup(&attr,
-                                                              adj->attr);
+                                       bgp_attr_dup(&attr, adj->attr);
+                                       ret = bgp_output_modifier(
+                                               peer, &rn->p, &attr, afi, safi,
+                                               rmap_name);
+
+                                       if (ret != RMAP_DENY) {
+                                               route_vty_out_tmp(vty, &rn->p,
+                                                                 &attr, safi,
+                                                                 use_json,
+                                                                 json_ar);
+                                               output_count++;
+                                       } else {
+                                               filtered_count++;
                                        }
+
+                                       bgp_attr_undup(&attr, adj->attr);
                                }
                }
        }