Skip to content

Commit

Permalink
bgpd: authorise to select bgp self peer prefix on rr case
Browse files Browse the repository at this point in the history
This commit addresses an issue that happens when using bgp
peering with a rr client, with a received prefix which is the
local ip address of the bgp session.

When using bgp ipv4 unicast session, the local prefix is
received by a peer, and finds out that the proposed prefix
and its next-hop are the same. To avoid a route loop locally,
no nexthop entry is referenced for that prefix, and the route
will not be selected.

When the received peer is a route reflector, the prefix has
to be selected, even if the route can not be installed locally.

Fixes: ("fb8ae704615c") bgpd: prevent routes loop through itself

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
(cherry picked from commit f874552)
  • Loading branch information
pguibert6WIND authored and mergify[bot] committed Nov 17, 2022
1 parent 23f40f2 commit 56dd706
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -3874,6 +3874,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
int vnc_implicit_withdraw = 0;
#endif
int same_attr = 0;
const struct prefix *bgp_nht_param_prefix;

/* Special case for BGP-LU - map LU safi to ordinary unicast safi */
if (orig_safi == SAFI_LABELED_UNICAST)
Expand Down Expand Up @@ -3937,6 +3938,11 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
if (aspath_get_last_as(attr->aspath) == bgp->as)
do_loop_check = 0;

if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
bgp_nht_param_prefix = NULL;
else
bgp_nht_param_prefix = p;

/* AS path loop check. */
if (do_loop_check) {
if (aspath_loop_check(attr->aspath, bgp->as)
Expand Down Expand Up @@ -4445,8 +4451,8 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,

if (bgp_find_or_add_nexthop(bgp, bgp_nexthop, nh_afi,
safi, pi, NULL, connected,
p)
|| CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD))
bgp_nht_param_prefix) ||
CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD))
bgp_path_info_set_flag(dest, pi,
BGP_PATH_VALID);
else {
Expand Down Expand Up @@ -4604,8 +4610,8 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
nh_afi = BGP_ATTR_NH_AFI(afi, new->attr);

if (bgp_find_or_add_nexthop(bgp, bgp, nh_afi, safi, new, NULL,
connected, p)
|| CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD))
connected, bgp_nht_param_prefix) ||
CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD))
bgp_path_info_set_flag(dest, new, BGP_PATH_VALID);
else {
if (BGP_DEBUG(nht, NHT)) {
Expand Down

0 comments on commit 56dd706

Please sign in to comment.