From b787157a528c5730b4d82c06f17de8eccf0b3508 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 24 Oct 2017 20:23:06 -0400 Subject: [PATCH] bgpd: When we don't have a route-map to apply don't apply the original When we display the advertised-routes and we don't have a route-map to apply do not re-apply the route-map. This does two things: 1) Fixes a display issue with the show command. 2) More importantly stops leaking memory like a sieve for when you have a full bgp table. Fixes: #1345 Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 55 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index cc7b80df82..3a7cfc4f2c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1157,49 +1157,50 @@ static int bgp_output_modifier(struct peer *peer, struct prefix *p, struct attr *attr, afi_t afi, safi_t safi, const char *rmap_name) { - struct bgp_filter *filter; struct bgp_info info; route_map_result_t ret; struct route_map *rmap = NULL; - filter = &peer->filter[afi][safi]; + /* + * So if we get to this point and have no rmap_name + * we want to just show the output as it currently + * exists. + */ + if (!rmap_name) + return RMAP_PERMIT; /* Apply default weight value. */ if (peer->weight[afi][safi]) attr->weight = peer->weight[afi][safi]; - if (rmap_name) { - rmap = route_map_lookup_by_name(rmap_name); + rmap = route_map_lookup_by_name(rmap_name); - if (rmap == NULL) - return RMAP_DENY; - } else { - if (ROUTE_MAP_OUT_NAME(filter)) { - rmap = ROUTE_MAP_OUT(filter); - - if (rmap == NULL) - return RMAP_DENY; - } - } + /* + * If we have a route map name and we do not find + * the routemap that means we have an implicit + * deny. + */ + if (rmap == NULL) + return RMAP_DENY; /* Route map apply. */ - if (rmap) { - /* Duplicate current value to new strucutre for modification. */ - info.peer = peer; - info.attr = attr; + /* Duplicate current value to new strucutre for modification. */ + info.peer = peer; + info.attr = attr; - SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT); + SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT); - /* Apply BGP route map to the attribute. */ - ret = route_map_apply(rmap, p, RMAP_BGP, &info); + /* Apply BGP route map to the attribute. */ + ret = route_map_apply(rmap, p, RMAP_BGP, &info); - peer->rmap_type = 0; + peer->rmap_type = 0; + + if (ret == RMAP_DENYMATCH) + /* + * caller has multiple error paths with bgp_attr_flush() + */ + return RMAP_DENY; - if (ret == RMAP_DENYMATCH) - /* caller has multiple error paths with bgp_attr_flush() - */ - return RMAP_DENY; - } return RMAP_PERMIT; } -- 2.39.5