From 841ae62a898d12d29bd8f6e721de423870650439 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 23 Sep 2024 12:01:20 +0200 Subject: [PATCH] bgpd: bmp, handle imported bgp instances in bmp_send_peerup() When a BMP target comes up, only the peer up events of the current BGP instance are sent. - Apply the peer up event for external peers that are imported by the BMP target. - handle the peer up event when an imported vrf is configured in a target. Signed-off-by: Philippe Guibert --- bgpd/bgp_bmp.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 3bac6a8f1d..f98361f0ab 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -617,21 +617,34 @@ static struct stream *bmp_peerstate(struct peer *peer, bool down) return s; } - -static int bmp_send_peerup(struct bmp *bmp) +static int bmp_send_peerup_per_instance(struct bmp *bmp, struct bgp *bgp) { struct peer *peer; struct listnode *node; struct stream *s; /* Walk down all peers */ - for (ALL_LIST_ELEMENTS_RO(bmp->targets->bgp->peer, node, peer)) { + for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { s = bmp_peerstate(peer, false); if (s) { pullwr_write_stream(bmp->pullwr, s); stream_free(s); } } + return 0; +} + +static int bmp_send_peerup(struct bmp *bmp) +{ + struct bmp_imported_bgp *bib; + struct bgp *bgp; + + bmp_send_peerup_per_instance(bmp, bmp->targets->bgp); + frr_each (bmp_imported_bgps, &bmp->targets->imported_bgps, bib) { + bgp = bgp_lookup_by_name(bib->name); + if (bgp) + bmp_send_peerup_per_instance(bmp, bgp); + } return 0; } @@ -2691,6 +2704,8 @@ DEFPY(bmp_import_vrf, { VTY_DECLVAR_CONTEXT_SUB(bmp_targets, bt); struct bmp_imported_bgp *bib; + struct bgp *bgp; + struct bmp *bmp; if (!bt->bgp) { vty_out(vty, "%% BMP target, BGP instance not found\n"); @@ -2715,10 +2730,18 @@ DEFPY(bmp_import_vrf, if (bib) return CMD_SUCCESS; - bmp_imported_bgp_get(bt, (char *)vrfname); - /* TODO: handle loc-rib peer up and other peers state changes + bib = bmp_imported_bgp_get(bt, (char *)vrfname); + bgp = bgp_lookup_by_name(bib->name); + if (!bgp) + return CMD_SUCCESS; + /* TODO: handle loc-rib peer up changes * TODO: Start the syncronisation */ + frr_each (bmp_session, &bt->sessions, bmp) { + if (bmp->state != BMP_PeerUp && bmp->state != BMP_Run) + continue; + bmp_send_peerup_per_instance(bmp, bgp); + } return CMD_SUCCESS; } -- 2.39.5