bgpd: Fix BGP-LS initial TED sync and cleanup on peer deactivation#21286
Open
cscarpitta wants to merge 3 commits intoFRRouting:masterfrom
Open
bgpd: Fix BGP-LS initial TED sync and cleanup on peer deactivation#21286cscarpitta wants to merge 3 commits intoFRRouting:masterfrom
cscarpitta wants to merge 3 commits intoFRRouting:masterfrom
Conversation
Greptile SummaryThis PR fixes two correctness gaps in the BGP-LS subsystem: the TED was never populated on startup because the initial sync was never requested, and stale self-originated routes plus TED state were left behind when the last BGP-LS peer was deactivated.
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Peer as BGP-LS Peer
participant bgpd as bgpd (peer_deactivate)
participant LSTD as bgp_ls_withdraw_ted
participant RIB as BGP RIB (async work queue)
participant TED as ls_ted
participant Zebra as Zebra LS DB
Note over Peer,Zebra: --- Initial Registration ---
Peer->>bgpd: activate (first peer)
bgpd->>Zebra: ls_register()
bgpd->>Zebra: ls_request_sync()
Zebra-->>bgpd: LS_MSG_EVENT_SYNC messages
bgpd->>TED: ls_vertex/edge/subnet add
bgpd->>RIB: bgp_ls_originate_node/link/prefix
Note over Peer,Zebra: --- Peer Deactivation (last peer) ---
Peer->>bgpd: deactivate (last peer)
bgpd->>LSTD: bgp_ls_withdraw_ted(bgp)
LSTD->>RIB: bgp_clear_route(peer_self, AFI_BGP_LS, SAFI_BGP_LS)
RIB-->>Peer: BGP UPDATE withdrawals (async)
LSTD->>TED: bgp_ls_ted_clear() — remove all vertices/edges/subnets
bgpd->>Zebra: bgp_ls_unregister()
Note over Peer,Zebra: --- Re-activation ---
Peer->>bgpd: activate (new peer)
bgpd->>Zebra: ls_register()
bgpd->>Zebra: ls_request_sync()
Zebra-->>bgpd: LS_MSG_EVENT_SYNC messages
bgpd->>TED: re-populate
bgpd->>RIB: re-originate all NLRIs
Reviews (1): Last reviewed commit: "tests: Verify BGP-LS routes withdrawn on..." | Re-trigger Greptile |
After registering with the LS database, no initial sync is requested, so the TED remains empty until the IGP sends unsolicited updates. Any topology changes that occurred before registration are permanently missed and never originated as BGP-LS NLRIs. Additionally, LS_MSG_EVENT_SYNC messages are not handled in the TED processors, so any sync response from zebra is silently dropped. Request a sync via ls_request_sync() immediately after registration, following the same pattern used by other TED consumers such as pathd. Handle LS_MSG_EVENT_SYNC alongside LS_MSG_EVENT_ADD in bgp_ls_process_vertex(), bgp_ls_process_edge(), and bgp_ls_process_subnet(). Signed-off-by: Carmine Scarpitta <[email protected]>
When the last BGP-LS peer is deactivated, locally originated BGP-LS routes are not withdrawn from the RIB, leaving stale routes on peers. The TED is also not cleared, so the next registration re-originates on top of stale state. Add bgp_ls_withdraw_ted() which removes all self-originated paths via bgp_clear_route() and clears all TED entries. Call it in peer_deactivate() when the last BGP-LS peer is being deactivated, before unregistering from the LS database. Signed-off-by: Carmine Scarpitta <[email protected]>
Add test_bgp_ls_peer_deactivate() to verify that deactivating the last BGP-LS peer on r2 withdraws all locally originated routes on r2 and clears all received routes on rr. Add test_bgp_ls_peer_reactivate() to verify that reactivating the peer triggers a fresh TED sync, re-originates all BGP-LS NLRIs on r2, and re-advertises them to rr. Signed-off-by: Carmine Scarpitta <[email protected]>
a4c3b6e to
431b681
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two issues in the BGP-LS code.
Initial sync: After registering with the LS database, BGP-LS never requests a sync, leaving the TED empty until the IGP sends unsolicited updates. Fix by calling `ls_request_sync() after registration.
Peer deactivation: When the last BGP-LS peer is deactivated, self-originated routes are not withdrawn and the TED is not cleared, leaving stale state. Fix by adding
bgp_ls_withdraw_ted()and calling it frompeer_deactivate().