From 4052c18a42b87feb2f3240cde33b8762f548f4fa Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Sun, 3 Nov 2024 22:44:55 +0100 Subject: [PATCH] bgpd: bmp, define hook for route distinguisher updates At startup, if bmp loc-rib is enabled, the peer_id of the loc-rib per peer header message has the route distinguisher set to 0:0. Actually, the route distinguisher has been updated after the peer up message is sent, and the information is not refreshed. Create a hook API to handle route distinguisher config events: pre and post configuration. 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 | 12 +++++++++++- bgpd/bgp_vty.c | 12 ++++++++++++ bgpd/bgpd.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index c33313b3ce..036bece359 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -3180,7 +3180,7 @@ static int bgp_bmp_early_fini(void) } /* called when the routerid of an instance changes */ -static int bmp_routerid_update(struct bgp *bgp, bool withdraw) +static int bmp_bgp_attribute_updated(struct bgp *bgp, bool withdraw) { struct bmp_bgp *bmpbgp = bmp_bgp_find(bgp); @@ -3200,6 +3200,15 @@ static int bmp_routerid_update(struct bgp *bgp, bool withdraw) return 1; } +static int bmp_routerid_update(struct bgp *bgp, bool withdraw) +{ + return bmp_bgp_attribute_updated(bgp, withdraw); +} + +static int bmp_route_distinguisher_update(struct bgp *bgp, afi_t afi, bool preconfig) +{ + return bmp_bgp_attribute_updated(bgp, preconfig); +} /* called when a bgp instance goes up/down, implying that the underlying VRF * has been created or deleted in zebra @@ -3255,6 +3264,7 @@ static int bgp_bmp_module_init(void) 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); + hook_register(bgp_route_distinguisher_update, bmp_route_distinguisher_update); return 0; } diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 550adf93db..2da77c314d 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -141,6 +141,8 @@ DEFINE_HOOK(bgp_inst_config_write, DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp)); DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp)); DEFINE_HOOK(bgp_snmp_traps_config_write, (struct vty * vty), (vty)); +DEFINE_HOOK(bgp_route_distinguisher_update, (struct bgp *bgp, afi_t afi, bool preconfig), + (bgp, afi, preconfig)); static struct peer_group *listen_range_exists(struct bgp *bgp, struct prefix *range, int exact); @@ -9805,6 +9807,14 @@ DEFPY (af_rd_vpn_export, vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), bgp); + if (!bgp->vpn_policy[afi].tovpn_rd_pretty && !rd_str) + return CMD_SUCCESS; + + if (yes && bgp->vpn_policy[afi].tovpn_rd_pretty && rd_str && + strmatch(rd_str, bgp->vpn_policy[afi].tovpn_rd_pretty)) + return CMD_SUCCESS; + + hook_call(bgp_route_distinguisher_update, bgp, afi, true); if (yes) { if (bgp->vpn_policy[afi].tovpn_rd_pretty) XFREE(MTYPE_BGP_NAME, bgp->vpn_policy[afi].tovpn_rd_pretty); @@ -9815,9 +9825,11 @@ DEFPY (af_rd_vpn_export, BGP_VPN_POLICY_TOVPN_RD_SET); } else { XFREE(MTYPE_BGP_NAME, bgp->vpn_policy[afi].tovpn_rd_pretty); + bgp->vpn_policy[afi].tovpn_rd_pretty = NULL; UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET); } + hook_call(bgp_route_distinguisher_update, bgp, afi, false); /* post-change: re-export vpn routes */ vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index a493673e59..65b268c4ea 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -908,6 +908,8 @@ 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)); +DECLARE_HOOK(bgp_route_distinguisher_update, (struct bgp *bgp, afi_t afi, bool preconfig), + (bgp, afi, preconfig)); /* Thread callback information */ struct afi_safi_info { -- 2.39.5