Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: When static default route is present in RIB and advertised to p… #6184

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 81 additions & 21 deletions bgpd/bgp_updgrp_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ void bgp_adj_out_unset_subgroup(struct bgp_node *rn,
if (adj->adv)
bgp_advertise_clean_subgroup(subgrp, adj);

/* If default originate is enabled and the route is default
* route, do not send withdraw. This will prevent deletion of
* the default route at the peer.
*/
if (CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE)
&& is_default_prefix(&rn->p))
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a default route that needs to be withdrawn even when default originate config is present this check will avoid it and return from here. This may lead to default route with peer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if we have default-originate before and then default-originate with route-map option is given to match on some prefix which is not present then already advertised default route needs to be withdrawn and that will not happen due to above check.

Copy link
Contributor Author

@kssoman kssoman Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default route advertisement using default originate is handled seperately in subgroup_default_update_packet() and deletion in subgroup_default_withdraw_packet()

When default route is advertised previously using redistribute command and then default originate is added, it is sufficient to clear the adj out entry since the newly advertised copy of default route will serve as implicit withdraw to the peer, the receiver will replace old copy with the new copy

Will check on the scenario involving routemap change


if (adj->attr && withdraw) {
/* We need advertisement structure. */
adj->adv = bgp_advertise_new();
Expand Down Expand Up @@ -636,12 +644,25 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
rn_p, &attr))
bgp_adj_out_set_subgroup(rn, subgrp,
&attr, ri);
else
else {
/* If default originate is enabled for
* the peer, do not send explicit
* withdraw. This will prevent deletion
* of default route advertised through
* default originate
*/
if (CHECK_FLAG(
peer->af_flags[afi][safi],
PEER_FLAG_DEFAULT_ORIGINATE)
&& is_default_prefix(&rn->p))
break;
ton31337 marked this conversation as resolved.
Show resolved Hide resolved

bgp_adj_out_unset_subgroup(
rn, subgrp, 1,
bgp_addpath_id_for_peer(
peer, afi, safi,
&ri->tx_addpath));
}
}
}

Expand Down Expand Up @@ -709,7 +730,9 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
struct prefix p;
struct peer *from;
struct bgp_node *rn;
struct bgp_path_info *pi;
struct peer *peer;
struct bgp_adj_out *adj;
route_map_result_t ret = RMAP_DENYMATCH;
afi_t afi;
safi_t safi;
Expand All @@ -732,10 +755,6 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)

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. */
attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
Expand Down Expand Up @@ -778,37 +797,78 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
}
}

/* Check if the default route is in local BGP RIB which is
* installed through redistribute or network command
*/
memset(&p, 0, sizeof(p));
p.family = afi2family(afi);
p.prefixlen = 0;
rn = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi, &p, NULL);

if (withdraw) {
/* Withdraw the default route advertised using default
* originate
*/
if (CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
subgroup_default_withdraw_packet(subgrp);
UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE);

/* If default route is present in the local RIB, advertise the
* route
*/
if (rn != NULL) {
for (pi = bgp_node_get_bgp_path_info(rn); pi;
pi = pi->next) {
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
ton31337 marked this conversation as resolved.
Show resolved Hide resolved
if (subgroup_announce_check(
rn, pi, subgrp, &rn->p,
&attr))
bgp_adj_out_set_subgroup(
rn, subgrp, &attr, pi);
}
}
} else {
if (!CHECK_FLAG(subgrp->sflags,
SUBGRP_STATUS_DEFAULT_ORIGINATE)) {

if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
bgp_attr_add_gshut_community(new_attr);

SET_FLAG(subgrp->sflags,
SUBGRP_STATUS_DEFAULT_ORIGINATE);
subgroup_default_update_packet(subgrp, new_attr, from);

/* The 'neighbor x.x.x.x default-originate' default will
* act as an
* implicit withdraw for any previous UPDATEs sent for
* 0.0.0.0/0 so
* clear adj_out for the 0.0.0.0/0 prefix in the BGP
* table.
*/
memset(&p, 0, sizeof(p));
p.family = afi2family(afi);
p.prefixlen = 0;

rn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi,
&p, NULL);
bgp_adj_out_unset_subgroup(
rn, subgrp, 0,
BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
if (rn != NULL) {
/* Remove the adjacency for the previously
* advertised default route
*/
adj = adj_lookup(
rn, subgrp,
BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
if (adj != NULL) {
/* Clean up previous advertisement. */
if (adj->adv)
bgp_advertise_clean_subgroup(
subgrp, adj);

/* Remove from adjacency. */
RB_REMOVE(bgp_adj_out_rb, &rn->adj_out,
adj);

/* Free allocated information. */
adj_free(adj);

bgp_unlock_node(rn);
}
}

/* Advertise the default route */
if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
bgp_attr_add_gshut_community(new_attr);

SET_FLAG(subgrp->sflags,
SUBGRP_STATUS_DEFAULT_ORIGINATE);
subgroup_default_update_packet(subgrp, new_attr, from);
}
}

Expand Down