From f373ce6cfc8972a39fb074a4408134c235035e67 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 15 Jun 2021 19:49:19 -0400 Subject: [PATCH] bgpd: apply cond-adv policy to update group The new outbound filter to apply conditional advertisement policy was not working properly due to complications with update groups. The two routemaps were properly copied into the update group peer filter but not the conditional advertisement state. Signed-off-by: Quentin Young Signed-off-by: Mark Stapp --- bgpd/bgp_conditional_adv.c | 22 ++++++++++++++++++++-- bgpd/bgp_updgrp.c | 8 ++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c index 9c2826fa13..fc44e86cbc 100644 --- a/bgpd/bgp_conditional_adv.c +++ b/bgpd/bgp_conditional_adv.c @@ -258,6 +258,25 @@ static void bgp_conditional_adv_timer(struct thread *t) ? UPDATE_TYPE_WITHDRAW : UPDATE_TYPE_ADVERTISE; + /* + * Update condadv update type so + * subgroup_announce_check() can properly apply + * outbound policy according to advertisement state + */ + paf = peer_af_find(peer, afi, safi); + if (paf && (SUBGRP_PEER(PAF_SUBGRP(paf)) + ->filter[afi][safi] + .advmap.update_type != + filter->advmap.update_type)) { + /* Handle change to peer advmap */ + if (BGP_DEBUG(update, UPDATE_OUT)) + zlog_debug( + "%s: advmap.update_type changed for peer %s, adjusting update_group.", + __func__, peer->host); + + update_group_adjust_peer(paf); + } + /* Send regular update as per the existing policy. * There is a change in route-map, match-rule, ACLs, * or route-map filter configuration on the same peer. @@ -270,11 +289,10 @@ static void bgp_conditional_adv_timer(struct thread *t) __func__, peer->host, get_afi_safi_str(afi, safi, false)); - - paf = peer_af_find(peer, afi, safi); if (paf) { update_subgroup_split_peer(paf, NULL); subgrp = paf->subgroup; + if (subgrp && subgrp->update_group) subgroup_announce_table( paf->subgroup, NULL); diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 13d5ec6b86..f1173941a0 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -218,6 +218,8 @@ static void conf_copy(struct peer *dst, struct peer *src, afi_t afi, MTYPE_BGP_FILTER_NAME, CONDITION_MAP_NAME(srcfilter)); CONDITION_MAP(dstfilter) = CONDITION_MAP(srcfilter); } + + dstfilter->advmap.update_type = srcfilter->advmap.update_type; } /** @@ -389,6 +391,9 @@ static unsigned int updgrp_hash_key_make(const void *p) strlen(filter->advmap.aname), SEED1), key); + if (filter->advmap.update_type) + key = jhash_1word(filter->advmap.update_type, key); + if (peer->default_rmap[afi][safi].name) key = jhash_1word( jhash(peer->default_rmap[afi][safi].name, @@ -588,6 +593,9 @@ static bool updgrp_hash_cmp(const void *p1, const void *p2) && strcmp(fl1->advmap.aname, fl2->advmap.aname))) return false; + if (fl1->advmap.update_type != fl2->advmap.update_type) + return false; + if ((pe1->default_rmap[afi][safi].name && !pe2->default_rmap[afi][safi].name) || (!pe1->default_rmap[afi][safi].name