summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2021-09-08 21:06:44 +0300
committerIgor Ryzhov <iryzhov@nfware.com>2021-09-08 23:37:50 +0300
commitbf844bac67a32941a311c9e986282f36ee58f0a5 (patch)
treec589423dd5a91d9ab51f8fbdb101ffe98a778737
parentc21258471764b99e7d1a5242bb17918bd7380740 (diff)
bgpd: fix default-originate route-map processing
When processing a route-map for default-originate, we actually want to match by attributes in routes from the RIB, but set attributes in the newly originated route. Currently, it's not the case. Instead, we construct a dummy path combining attributes from both routes, and we end up with multiple problems: - match by as-path doesn't work - communities from the matched RIB route are copied to the newly originated route - we corrupt the RIB routes To fix the issue, we should use the new route-map API that allows using separate match/set objects. Fixes #9584. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
-rw-r--r--bgpd/bgp_updgrp_adv.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c
index 9c2288cba3..2b1f186790 100644
--- a/bgpd/bgp_updgrp_adv.c
+++ b/bgpd/bgp_updgrp_adv.c
@@ -812,6 +812,10 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
}
if (peer->default_rmap[afi][safi].name) {
+ struct bgp_path_info tmp_pi = {0};
+
+ tmp_pi.peer = bgp->peer_self;
+
SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
/* Iterate over the RIB to see if we can announce
@@ -825,24 +829,16 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
for (pi = bgp_dest_get_bgp_path_info(dest); pi;
pi = pi->next) {
- struct attr tmp_attr;
- struct bgp_path_info tmp_pi;
- struct bgp_path_info_extra tmp_pie;
-
- tmp_attr = *pi->attr;
- tmp_attr.aspath = attr.aspath;
+ struct attr tmp_attr = attr;
- prep_for_rmap_apply(&tmp_pi, &tmp_pie, dest, pi,
- pi->peer, &tmp_attr);
+ tmp_pi.attr = &tmp_attr;
- ret = route_map_apply(
+ ret = route_map_apply_ext(
peer->default_rmap[afi][safi].map,
- bgp_dest_get_prefix(dest), &tmp_pi);
+ bgp_dest_get_prefix(dest), pi, &tmp_pi);
if (ret == RMAP_DENYMATCH) {
- /* The aspath belongs to 'attr' */
- tmp_attr.aspath = NULL;
- bgp_attr_flush(&tmp_attr);
+ bgp_attr_undup(&tmp_attr, &attr);
continue;
} else {
new_attr = bgp_attr_intern(&tmp_attr);