Skip to content
Open
Show file tree
Hide file tree
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
101 changes: 95 additions & 6 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,14 @@ static void bgp_process_pending_refresh(struct peer_connection *connection, afi_

if (CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_REFRESH_PENDING)) {
bool plain = CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_REFRESH_PENDING_PLAIN);
struct peer_af *paf = peer_af_find(peer, afi, safi);

UNSET_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_REFRESH_PENDING);
UNSET_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_REFRESH_PENDING_PLAIN);
bgp_route_refresh_send(connection, afi, safi, 0, 0, 0, BGP_ROUTE_REFRESH_BORR);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
Expand All @@ -356,7 +362,15 @@ static void bgp_process_pending_refresh(struct peer_connection *connection, afi_

SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_BORR_SEND);
UNSET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_EORR_SEND);
bgp_announce_route(peer, afi, safi, true);

/* Resync eligibility is re-checked now, with the subgroup's
* current state; it must not start before BoRR, just sent
* above (bgp_resync_combine() can force a shared walk).
*/
if (plain && paf && bgp_resync_eligible(paf))
bgp_resync_start(paf);
else
bgp_announce_route(peer, afi, safi, true);
}
}

Expand Down Expand Up @@ -385,6 +399,12 @@ static void bgp_write_proceed_actions(struct peer_connection *connection)
if (!subgrp)
continue;

if (paf->resync) {
BGP_TIMER_ON(connection->t_generate_updgrp_packets,
bgp_generate_updgrp_packets, 0);
return;
}

next_pkt = paf->next_pkt_to_send;
if (next_pkt && next_pkt->buffer) {
BGP_TIMER_ON(connection->t_generate_updgrp_packets,
Expand Down Expand Up @@ -548,6 +568,29 @@ void bgp_generate_updgrp_packets(struct event *event)
next_pkt = paf->next_pkt_to_send;
}

/*
* Route-refresh resync: one packet for this peer
* alone, alternating with the shared packets. Don't
* take the turn when the subgroup's packet queue is
* full: this peer not advancing in it as fast as the
* others would then stall compaction for the whole
* subgroup (a slow/alternating peer blocking everyone
* else's shared updates).
*/
if (paf->resync &&
(!next_pkt || !next_pkt->buffer ||
(paf->resync->turn &&
!bpacket_queue_is_full(peer->bgp, PAF_PKTQ(paf))))) {
struct stream *rs = bgp_resync_packet(paf);

if (rs) {
peer->pkt_stime[afi][safi] = monotime(NULL);
s = rs;
bgp_packet_add(connection, s);
continue;
}
}

/*
* If we still don't have a packet to send to the peer,
* then try to find out out if we have to send eor or
Expand All @@ -557,16 +600,32 @@ void bgp_generate_updgrp_packets(struct event *event)
* yet.
*/
if (!next_pkt || !next_pkt->buffer) {
if (!event_is_scheduled(paf->t_announce_route)) {
if (!event_is_scheduled(paf->t_announce_route) &&
!paf->resync) {
/* Make sure we supress BGP UPDATES
* for normal processing later again.
*/
UNSET_FLAG(paf->subgroup->sflags,
SUBGRP_STATUS_FORCE_UPDATES);
Comment on lines +608 to +609

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Refresh replies can skip routes

bgp_announce_route(..., true) sets SUBGRP_STATUS_FORCE_UPDATES before starting a 500 ms per-peer timer. During that delay, another peer in the subgroup can drain its queue and reach this block because its own t_announce_route is unset. It clears the shared flag before the requested refresh runs, so duplicate suppression can discard the unchanged routes that must be resent. The requesting peer can then remove those routes when the refresh ends.

This also affects refreshes with resync disabled. Leave the flag clearing in subgroup_announce_route(), which already clears it after the walk.

Suggested change
UNSET_FLAG(paf->subgroup->sflags,
SUBGRP_STATUS_FORCE_UPDATES);
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_packet.c
Line: 608-609

Comment:
**Refresh replies can skip routes**

`bgp_announce_route(..., true)` sets `SUBGRP_STATUS_FORCE_UPDATES` before starting a 500 ms per-peer timer. During that delay, another peer in the subgroup can drain its queue and reach this block because its own `t_announce_route` is unset. It clears the shared flag before the requested refresh runs, so duplicate suppression can discard the unchanged routes that must be resent. The requesting peer can then remove those routes when the refresh ends.

This also affects refreshes with resync disabled. Leave the flag clearing in `subgroup_announce_route()`, which already clears it after the walk.

```suggestion

```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.



/* If route-refresh BoRR message was
* already sent and we are done with
* re-announcing tables for a decent
* afi/safi, we ready to send
* EoRR request.
* EoRR request. Hold off while the
* subgroup's packet queue is still
* full: the resync walk skipped
* destinations with a pending shared
* advertisement (adj->adv), counting
* on that queue to deliver them.
*/
if (CHECK_FLAG(
peer->af_sflags[afi][safi],
PEER_STATUS_BORR_SEND)) {
PEER_STATUS_BORR_SEND) &&
!bpacket_queue_is_full(
peer->bgp,
PAF_PKTQ(paf))) {
bgp_route_refresh_send(connection, afi, safi, 0, 0,
0, BGP_ROUTE_REFRESH_EORR);

Expand Down Expand Up @@ -631,6 +690,8 @@ void bgp_generate_updgrp_packets(struct event *event)
assert(s);
bgp_packet_add(connection, s);
bpacket_queue_advance_peer(paf);
if (paf->resync)
paf->resync->turn = true;
}
} while (s && (++generated < wpq) && (connection->obuf->count <= bm->outq_limit) &&
!event_should_yield(event));
Expand Down Expand Up @@ -3010,6 +3071,7 @@ static int bgp_route_refresh_receive(struct peer_connection *connection, bgp_siz
safi_t safi;
struct stream *s;
uint8_t subtype;
bool plain;
bgp_size_t msg_length =
size - (BGP_MSG_ROUTE_REFRESH_MIN_SIZE - BGP_HEADER_SIZE);

Expand Down Expand Up @@ -3278,6 +3340,17 @@ static int bgp_route_refresh_receive(struct peer_connection *connection, bgp_siz
return BGP_PACKET_NOOP;
}

/*
* Plain ROUTE-REFRESH: no ORF in the message nor previously received,
* normal request, first update not deferred. It asks for what was
* already advertised: candidate for a resync (bgp_resync_eligible()).
*/
plain = size == BGP_MSG_ROUTE_REFRESH_MIN_SIZE - BGP_HEADER_SIZE &&
subtype == BGP_ROUTE_REFRESH_NORMAL &&
!peer->orf_plist[afi][safi] &&
!CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_ORF_WAIT_REFRESH);

/* First update is deferred until ORF or ROUTE-REFRESH is received */
if (CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_ORF_WAIT_REFRESH))
Expand All @@ -3301,7 +3374,14 @@ static int bgp_route_refresh_receive(struct peer_connection *connection, bgp_siz
if (bgp_debug_neighbor_events(peer))
zlog_debug("%pBP rcvd route-refresh (REQUEST) for %s/%s before EoR",
peer, afi2str(afi), safi2str(safi));
/* Can't send BoRR now, postpone after EoR */
/* Can't send BoRR now, postpone after EoR; remember if
* it was resync-eligible (eligibility itself is
* re-checked when the BoRR finally goes out, not
* cached here).
*/
if (plain)
SET_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_REFRESH_PENDING_PLAIN);
SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_REFRESH_PENDING);
return BGP_PACKET_NOOP;
}
Expand All @@ -3320,7 +3400,16 @@ static int bgp_route_refresh_receive(struct peer_connection *connection, bgp_siz
}

/* Perform route refreshment to the peer */
bgp_announce_route(peer, afi, safi, true);
{
struct peer_af *paf = peer_af_find(peer, afi, safi);

if (plain && paf && bgp_resync_eligible(paf)) {
bgp_resync_start(paf);
BGP_TIMER_ON(connection->t_generate_updgrp_packets,
bgp_generate_updgrp_packets, 0);
} else
bgp_announce_route(peer, afi, safi, true);
}

/* No FSM action necessary */
return BGP_PACKET_NOOP;
Expand Down
16 changes: 16 additions & 0 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -7491,6 +7491,22 @@ void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi, bool force)
return;
subgrp = PAF_SUBGRP(paf);

/*
* A resync in progress answers a ROUTE-REFRESH: the walk below
* replaces it, and must resend everything to the peer.
*
* Known limitation: SUBGRP_STATUS_FORCE_UPDATES is subgroup-wide,
* not per peer. An unrelated force=false caller (e.g. nexthop
* tracking) landing on a peer that happens to be resyncing will
* force a full re-announce to every other peer sharing that
* subgroup too, not just this one - there is no per-peer force
* mechanism to scope this more tightly.
*/
if (paf->resync) {
bgp_resync_stop(paf);
force = true;
}

/*
* Ignore if subgroup doesn't exist (implies AF is not negotiated)
* or a refresh has already been triggered.
Expand Down
15 changes: 15 additions & 0 deletions bgpd/bgp_updgrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,9 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
json_object_int_add(json_subgrp_event,
"peerRefreshEvents",
subgrp->peer_refreshes_combined);
json_object_int_add(json_subgrp_event,
"peerRefreshResyncEvents",
subgrp->peer_refreshes_resync);
json_object_int_add(json_subgrp_event,
"mergeCheckEvents",
subgrp->merge_checks_triggered);
Expand Down Expand Up @@ -968,6 +971,8 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
subgrp->updgrp_switch_events);
vty_out(vty, " Peer refreshes combined: %u\n",
subgrp->peer_refreshes_combined);
vty_out(vty, " Peer refreshes resync: %u\n",
subgrp->peer_refreshes_resync);
vty_out(vty, " Merge checks triggered: %u\n",
subgrp->merge_checks_triggered);
vty_out(vty, " Coalesce Time: %u%s\n",
Expand Down Expand Up @@ -1995,6 +2000,8 @@ void update_subgroup_split_peer(struct peer_af *paf,
if (updgrp == old_subgrp->update_group)
return;

bgp_resync_stop(paf);

subgrp = old_subgrp;
old_id = old_subgrp->update_group->id;

Expand Down Expand Up @@ -2029,6 +2036,12 @@ void update_subgroup_split_peer(struct peer_af *paf,
return;
}

/*
* A resync cursor is only valid against the subgroup it was
* started for; it does not carry over to the new one below.
*/
bgp_resync_stop(paf);

/*
* Create a new subgroup under the specified update group, and copy
* over relevant state to it.
Expand Down Expand Up @@ -2155,6 +2168,8 @@ void update_group_show_stats(struct bgp *bgp, struct vty *vty)
bgp->update_group_stats.updgrp_switch_events);
vty_out(vty, "Peer route refreshes combined: %u\n",
bgp->update_group_stats.peer_refreshes_combined);
vty_out(vty, "Peer route refreshes resync: %u\n",
bgp->update_group_stats.peer_refreshes_resync);
vty_out(vty, "Merge checks triggered: %u\n",
bgp->update_group_stats.merge_checks_triggered);
}
Expand Down
28 changes: 28 additions & 0 deletions bgpd/bgp_updgrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ struct update_group {
uint32_t merge_events;
uint32_t updgrp_switch_events;
uint32_t peer_refreshes_combined;
uint32_t peer_refreshes_resync;
uint32_t adj_count;
uint32_t split_events;
uint32_t merge_checks_triggered;
Expand Down Expand Up @@ -235,6 +236,7 @@ struct update_subgroup {
uint32_t merge_events;
uint32_t updgrp_switch_events;
uint32_t peer_refreshes_combined;
uint32_t peer_refreshes_resync;
uint32_t adj_count;
uint32_t split_events;
uint32_t merge_checks_triggered;
Expand Down Expand Up @@ -452,6 +454,9 @@ extern void peer_af_announce_route(struct peer_af *paf, int combine);
extern struct bgp_adj_out *bgp_adj_out_alloc(struct update_subgroup *subgrp,
struct bgp_dest *dest,
uint32_t addpath_tx_id);
extern struct bgp_adj_out *adj_lookup(struct bgp_dest *dest,
struct update_subgroup *subgrp,
uint32_t addpath_tx_id);
extern void bgp_adj_out_remove_subgroup(struct bgp_dest *dest,
struct bgp_adj_out *adj,
struct update_subgroup *subgrp);
Expand Down Expand Up @@ -523,6 +528,28 @@ static inline void update_group_adjust_peer_afs(struct peer *peer)
}
}

/*
* Route-refresh resync of one peer (VPN only): a cursor over the two-level
* VPN table. The current RD and prefix nodes are locked by the iteration
* (bgp_table_top/bgp_route_next), the current RD table by bgp_table_lock.
*/
struct bgp_resync {
struct bgp_dest *rd_dest;
struct bgp_table *table;
struct bgp_dest *dest;

/* a shared packet was sent since the last resync packet */
bool turn;

uint32_t sent;
uint32_t packets;
};

extern bool bgp_resync_eligible(struct peer_af *paf);
extern void bgp_resync_start(struct peer_af *paf);
extern void bgp_resync_stop(struct peer_af *paf);
extern struct stream *bgp_resync_packet(struct peer_af *paf);

/*
* update_group_remove_peer_afs
*
Expand All @@ -537,6 +564,7 @@ static inline void update_group_remove_peer_afs(struct peer *peer)
paf = peer->peer_af_array[afidx];
if (paf != NULL) {
bgp_stop_announce_route_timer(paf);
bgp_resync_stop(paf);
update_subgroup_remove_peer(PAF_SUBGRP(paf), paf);
}
}
Expand Down
6 changes: 3 additions & 3 deletions bgpd/bgp_updgrp_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ static int bgp_adj_out_compare(const struct bgp_adj_out *o1,
}
RB_GENERATE(bgp_adj_out_rb, bgp_adj_out, adj_entry, bgp_adj_out_compare);

static inline struct bgp_adj_out *adj_lookup(struct bgp_dest *dest,
struct update_subgroup *subgrp,
uint32_t addpath_tx_id)
inline struct bgp_adj_out *adj_lookup(struct bgp_dest *dest,
struct update_subgroup *subgrp,
uint32_t addpath_tx_id)
{
struct bgp_adj_out lookup;

Expand Down
Loading
Loading