]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_updgrp_adv.c
bgpd: partially revert e23b9ef6d271223d29c7f91a10d98aa6dcd252b3
[mirror_frr.git] / bgpd / bgp_updgrp_adv.c
index 6ffb1d448b2009b64ab02f7fff66368b6a2479de..7196bbbf12932fe311215c0fc42ade6cf99c6fa3 100644 (file)
@@ -49,6 +49,7 @@
 #include "bgpd/bgp_mplsvpn.h"
 #include "bgpd/bgp_updgrp.h"
 #include "bgpd/bgp_advertise.h"
+#include "bgpd/bgp_addpath.h"
 
 
 /********************
@@ -97,11 +98,45 @@ static void adj_free(struct bgp_adj_out *adj)
        XFREE(MTYPE_BGP_ADJ_OUT, adj);
 }
 
+static void subgrp_withdraw_stale_addpath(struct updwalk_context *ctx,
+                                         struct update_subgroup *subgrp)
+{
+       struct bgp_adj_out *adj, *adj_next;
+       uint32_t id;
+       struct bgp_path_info *pi;
+       afi_t afi = SUBGRP_AFI(subgrp);
+       safi_t safi = SUBGRP_SAFI(subgrp);
+       struct peer *peer = SUBGRP_PEER(subgrp);
+
+       /* Look through all of the paths we have advertised for this rn and send
+        * a withdraw for the ones that are no longer present */
+       for (adj = ctx->rn->adj_out; adj; adj = adj_next) {
+               adj_next = adj->next;
+
+               if (adj->subgroup == subgrp) {
+                       for (pi = ctx->rn->info; pi; pi = pi->next) {
+                               id = bgp_addpath_id_for_peer(peer, afi, safi,
+                                       &pi->tx_addpath);
+
+                               if (id == adj->addpath_tx_id) {
+                                       break;
+                               }
+                       }
+
+                       if (!pi) {
+                               subgroup_process_announce_selected(
+                                       subgrp, NULL, ctx->rn,
+                                       adj->addpath_tx_id);
+                       }
+               }
+       }
+}
+
 static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
 {
        struct updwalk_context *ctx = arg;
        struct update_subgroup *subgrp;
-       struct bgp_info *ri;
+       struct bgp_path_info *pi;
        afi_t afi;
        safi_t safi;
        struct peer *peer;
@@ -131,58 +166,40 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
                if (!subgrp->t_coalesce) {
                        /* An update-group that uses addpath */
                        if (addpath_capable) {
-                               /* Look through all of the paths we have
-                                * advertised for this rn and
-                                * send a withdraw for the ones that are no
-                                * longer present */
-                               for (adj = ctx->rn->adj_out; adj;
-                                    adj = adj_next) {
-                                       adj_next = adj->next;
-
-                                       if (adj->subgroup == subgrp) {
-                                               for (ri = ctx->rn->info; ri;
-                                                    ri = ri->next) {
-                                                       if (ri->addpath_tx_id
-                                                           == adj->addpath_tx_id) {
-                                                               break;
-                                                       }
-                                               }
+                               subgrp_withdraw_stale_addpath(ctx, subgrp);
 
-                                               if (!ri) {
-                                                       subgroup_process_announce_selected(
-                                                               subgrp, NULL,
-                                                               ctx->rn,
-                                                               adj->addpath_tx_id);
-                                               }
-                                       }
-                               }
-
-                               for (ri = ctx->rn->info; ri; ri = ri->next) {
+                               for (pi = ctx->rn->info; pi; pi = pi->next) {
                                        /* Skip the bestpath for now */
-                                       if (ri == ctx->ri)
+                                       if (pi == ctx->pi)
                                                continue;
 
                                        subgroup_process_announce_selected(
-                                               subgrp, ri, ctx->rn,
-                                               ri->addpath_tx_id);
+                                               subgrp, pi, ctx->rn,
+                                               bgp_addpath_id_for_peer(
+                                                       peer, afi, safi,
+                                                       &pi->tx_addpath));
                                }
 
                                /* Process the bestpath last so the "show [ip]
                                 * bgp neighbor x.x.x.x advertised"
                                 * output shows the attributes from the bestpath
                                 */
-                               if (ctx->ri)
+                               if (ctx->pi)
                                        subgroup_process_announce_selected(
-                                               subgrp, ctx->ri, ctx->rn,
-                                               ctx->ri->addpath_tx_id);
+                                               subgrp, ctx->pi, ctx->rn,
+                                               bgp_addpath_id_for_peer(
+                                                       peer, afi, safi,
+                                                       &ctx->pi->tx_addpath));
                        }
 
                        /* An update-group that does not use addpath */
                        else {
-                               if (ctx->ri) {
+                               if (ctx->pi) {
                                        subgroup_process_announce_selected(
-                                               subgrp, ctx->ri, ctx->rn,
-                                               ctx->ri->addpath_tx_id);
+                                               subgrp, ctx->pi, ctx->rn,
+                                               bgp_addpath_id_for_peer(
+                                                       peer, afi, safi,
+                                                       &ctx->pi->tx_addpath));
                                } else {
                                        /* Find the addpath_tx_id of the path we
                                         * had advertised and
@@ -429,19 +446,31 @@ bgp_advertise_clean_subgroup(struct update_subgroup *subgrp,
 
 void bgp_adj_out_set_subgroup(struct bgp_node *rn,
                              struct update_subgroup *subgrp, struct attr *attr,
-                             struct bgp_info *binfo)
+                             struct bgp_path_info *path)
 {
        struct bgp_adj_out *adj = NULL;
        struct bgp_advertise *adv;
+       struct peer *peer;
+       afi_t afi;
+       safi_t safi;
+
+       peer = SUBGRP_PEER(subgrp);
+       afi = SUBGRP_AFI(subgrp);
+       safi = SUBGRP_SAFI(subgrp);
 
        if (DISABLE_BGP_ANNOUNCE)
                return;
 
        /* Look for adjacency information. */
-       adj = adj_lookup(rn, subgrp, binfo->addpath_tx_id);
+       adj = adj_lookup(
+               rn, subgrp,
+               bgp_addpath_id_for_peer(peer, afi, safi, &path->tx_addpath));
 
        if (!adj) {
-               adj = bgp_adj_out_alloc(subgrp, rn, binfo->addpath_tx_id);
+               adj = bgp_adj_out_alloc(
+                       subgrp, rn,
+                       bgp_addpath_id_for_peer(peer, afi, safi,
+                                             &path->tx_addpath));
                if (!adj)
                        return;
        }
@@ -452,8 +481,9 @@ void bgp_adj_out_set_subgroup(struct bgp_node *rn,
 
        adv = adj->adv;
        adv->rn = rn;
-       assert(adv->binfo == NULL);
-       adv->binfo = bgp_info_lock(binfo); /* bgp_info adj_out reference */
+       assert(adv->pathi == NULL);
+       /* bgp_path_info adj_out reference */
+       adv->pathi = bgp_path_info_lock(path);
 
        if (attr)
                adv->baa = bgp_advertise_intern(subgrp->hash, attr);
@@ -568,7 +598,7 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
                             struct bgp_table *table)
 {
        struct bgp_node *rn;
-       struct bgp_info *ri;
+       struct bgp_path_info *ri;
        struct attr attr;
        struct peer *peer;
        afi_t afi;
@@ -594,9 +624,11 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
        for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn))
                for (ri = rn->info; ri; ri = ri->next)
 
-                       if (CHECK_FLAG(ri->flags, BGP_INFO_SELECTED)
+                       if (CHECK_FLAG(ri->flags, BGP_PATH_SELECTED)
                            || (addpath_capable
-                               && bgp_addpath_tx_path(peer, afi, safi, ri))) {
+                               && bgp_addpath_tx_path(
+                                          peer->addpath_type[afi][safi],
+                                          ri))) {
                                if (subgroup_announce_check(rn, ri, subgrp,
                                                            &rn->p, &attr))
                                        bgp_adj_out_set_subgroup(rn, subgrp,
@@ -604,7 +636,9 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
                                else
                                        bgp_adj_out_unset_subgroup(
                                                rn, subgrp, 1,
-                                               ri->addpath_tx_id);
+                                               bgp_addpath_id_for_peer(
+                                                       peer, afi, safi,
+                                                       &ri->tx_addpath));
                        }
 
        /*
@@ -663,11 +697,12 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
 {
        struct bgp *bgp;
        struct attr attr;
-       struct bgp_info *info, init_info, tmp_info;
+       struct aspath *aspath;
+       struct bgp_path_info tmp_info;
        struct prefix p;
        struct peer *from;
        struct bgp_node *rn;
-       struct bgp_info *ri;
+       struct bgp_path_info *ri;
        struct peer *peer;
        int ret = RMAP_DENYMATCH;
        afi_t afi;
@@ -687,59 +722,46 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
        from = bgp->peer_self;
 
        bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
+       aspath = attr.aspath;
+
        attr.local_pref = bgp->default_local_pref;
 
+       memset(&p, 0, sizeof(p));
+       p.family = afi2family(afi);
+       p.prefixlen = 0;
+
        if ((afi == AFI_IP6) || peer_cap_enhe(peer, afi, safi)) {
-               /* IPv6 global nexthop must be included.
-                */
+               /* IPv6 global nexthop must be included. */
                attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
 
-               /* If the peer is on shared nextwork and
-                * we have link-local nexthop set it. */
+               /* If the peer is on shared nextwork and we have link-local
+                  nexthop set it. */
                if (peer->shared_network
                    && !IN6_IS_ADDR_UNSPECIFIED(&peer->nexthop.v6_local))
                        attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
        }
-       init_info.attr = &attr;
-       info = &init_info;
-       bgp_attr_intern(info->attr);
-
-       memset(&p, 0, sizeof(p));
-       p.family = afi2family(afi);
-       p.prefixlen = 0;
 
        if (peer->default_rmap[afi][safi].name) {
                SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
                for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
                     rn = bgp_route_next(rn)) {
                        for (ri = rn->info; ri; ri = ri->next) {
+                               struct attr dummy_attr;
+
+                               /* Provide dummy so the route-map can't modify
+                                * the attributes */
+                               bgp_attr_dup(&dummy_attr, ri->attr);
                                tmp_info.peer = ri->peer;
-                               tmp_info.attr = ri->attr;
-
-                               /* Reset attributes every time to avoid \
-                                * unexpected as-path prepends */
-                               bgp_attr_default_set(tmp_info.attr,
-                                                    BGP_ORIGIN_IGP);
-
-                               if ((afi == AFI_IP6)
-                                   || peer_cap_enhe(peer, afi, safi)) {
-                                       tmp_info.attr->mp_nexthop_len =
-                                               BGP_ATTR_NHLEN_IPV6_GLOBAL;
-
-                                       if (peer->shared_network
-                                           && !IN6_IS_ADDR_UNSPECIFIED(
-                                                      &peer->nexthop.v6_local))
-                                               tmp_info.attr->mp_nexthop_len =
-                                                       BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
-                               }
+                               tmp_info.attr = &dummy_attr;
 
                                ret = route_map_apply(
                                        peer->default_rmap[afi][safi].map,
                                        &rn->p, RMAP_BGP, &tmp_info);
 
-                               info = &tmp_info;
-                               bgp_attr_intern(info->attr);
-
+                               /* The route map might have set attributes. If
+                                * we don't flush them
+                                * here, they will be leaked. */
+                               bgp_attr_flush(&dummy_attr);
                                if (ret != RMAP_DENYMATCH)
                                        break;
                        }
@@ -761,13 +783,12 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
                                SUBGRP_STATUS_DEFAULT_ORIGINATE)) {
 
                        if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
-                               bgp_attr_add_gshut_community(info->attr);
+                               bgp_attr_add_gshut_community(&attr);
                        }
 
                        SET_FLAG(subgrp->sflags,
                                 SUBGRP_STATUS_DEFAULT_ORIGINATE);
-                       subgroup_default_update_packet(subgrp, info->attr,
-                                                      from);
+                       subgroup_default_update_packet(subgrp, &attr, from);
 
                        /* The 'neighbor x.x.x.x default-originate' default will
                         * act as an
@@ -787,7 +808,8 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
                                BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
                }
        }
-       aspath_unintern(&info->attr->aspath);
+
+       aspath_unintern(&aspath);
 }
 
 /*
@@ -830,10 +852,10 @@ void subgroup_announce_all(struct update_subgroup *subgrp)
  * input route.
  */
 void group_announce_route(struct bgp *bgp, afi_t afi, safi_t safi,
-                         struct bgp_node *rn, struct bgp_info *ri)
+                         struct bgp_node *rn, struct bgp_path_info *pi)
 {
        struct updwalk_context ctx;
-       ctx.ri = ri;
+       ctx.pi = pi;
        ctx.rn = rn;
        update_group_af_walk(bgp, afi, safi, group_announce_route_walkcb, &ctx);
 }