]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: fix default-originate route-map processing
authorIgor Ryzhov <iryzhov@nfware.com>
Wed, 8 Sep 2021 18:06:44 +0000 (21:06 +0300)
committermergify-bot <noreply@mergify.io>
Thu, 16 Sep 2021 10:51:57 +0000 (10:51 +0000)
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>
(cherry picked from commit bf844bac67a32941a311c9e986282f36ee58f0a5)

bgpd/bgp_updgrp_adv.c

index 18829aa7477a944debe9e28d48da67d9df2f64ff..9a99ce26cefa0591278522017bc805a41c92f120 100644 (file)
@@ -811,6 +811,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
@@ -824,24 +828,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);