From f3c17d94e0b6826ed8ca3d47afaf3ae5214169e7 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 30 Oct 2024 09:45:47 +0100 Subject: [PATCH] bgpd: bmp, define hook for router-id updates At startup, if bmp loc-rib is enabled, the peer_id of the loc-rib per peer header message has the router-id set to 0.0.0.0. Actually, the router-id has been updated after the peer up message is sent, and the information is not refreshed. Create a hook API to handle router id events: withdraw and updates. Use that hook in BMP module to send peer down, and peer up events when necessary. Signed-off-by: Philippe Guibert --- bgpd/bgp_bmp.c | 23 +++++++++++++++++++++++ bgpd/bgpd.c | 4 ++++ bgpd/bgpd.h | 1 + 3 files changed, 28 insertions(+) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 019ea2669d..c33313b3ce 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -3179,6 +3179,28 @@ static int bgp_bmp_early_fini(void) return 0; } +/* called when the routerid of an instance changes */ +static int bmp_routerid_update(struct bgp *bgp, bool withdraw) +{ + struct bmp_bgp *bmpbgp = bmp_bgp_find(bgp); + + if (!bmpbgp) + return 0; + + bmp_bgp_update_vrf_status(bmpbgp, vrf_state_unknown); + + if (bmpbgp->vrf_state == vrf_state_down) + /* do not send peer events, router id will not be enough to set state to up + */ + return 0; + + /* vrf_state is up: trigger a peer event + */ + bmp_send_all_safe(bmpbgp, bmp_peerstate(bgp->peer_self, withdraw)); + return 1; +} + + /* called when a bgp instance goes up/down, implying that the underlying VRF * has been created or deleted in zebra */ @@ -3232,6 +3254,7 @@ static int bgp_bmp_module_init(void) hook_register(frr_early_fini, bgp_bmp_early_fini); hook_register(bgp_instance_state, bmp_vrf_state_changed); hook_register(bgp_vrf_status_changed, bmp_vrf_itf_state_changed); + hook_register(bgp_routerid_update, bmp_routerid_update); return 0; } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 74f79cdd72..f0b4f6c262 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -86,6 +86,7 @@ DEFINE_QOBJ_TYPE(bgp); DEFINE_QOBJ_TYPE(peer); DEFINE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp)); DEFINE_HOOK(bgp_instance_state, (struct bgp *bgp), (bgp)); +DEFINE_HOOK(bgp_routerid_update, (struct bgp *bgp, bool withdraw), (bgp, withdraw)); /* BGP process wide configuration. */ static struct bgp_master bgp_master; @@ -301,6 +302,8 @@ static int bgp_router_id_set(struct bgp *bgp, const struct in_addr *id, vpn_handle_router_id_update(bgp, true, is_config); + hook_call(bgp_routerid_update, bgp, true); + IPV4_ADDR_COPY(&bgp->router_id, id); /* Set all peer's local identifier with this value. */ @@ -318,6 +321,7 @@ static int bgp_router_id_set(struct bgp *bgp, const struct in_addr *id, vpn_handle_router_id_update(bgp, false, is_config); + hook_call(bgp_routerid_update, bgp, false); return 0; } diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 47214e52e5..a493673e59 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -907,6 +907,7 @@ DECLARE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp)); DECLARE_HOOK(bgp_hook_vrf_update, (struct vrf *vrf, bool enabled), (vrf, enabled)); DECLARE_HOOK(bgp_instance_state, (struct bgp *bgp), (bgp)); +DECLARE_HOOK(bgp_routerid_update, (struct bgp *bgp, bool withdraw), (bgp, withdraw)); /* Thread callback information */ struct afi_safi_info {