]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: bmp, define hook for route distinguisher updates
authorPhilippe Guibert <philippe.guibert@6wind.com>
Sun, 3 Nov 2024 21:44:55 +0000 (22:44 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 30 Dec 2024 14:13:38 +0000 (15:13 +0100)
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 <philippe.guibert@6wind.com>
bgpd/bgp_bmp.c
bgpd/bgp_vty.c
bgpd/bgpd.h

index c33313b3ce48c6550764cf4d2fa9bb30beab695c..036bece35970db19c7c875158ffff3414d0aa42c 100644 (file)
@@ -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;
 }
 
index 550adf93dba1139e450a75d6e3ed410d62ea2a87..2da77c314d0cfe0f81f9b0ba1974622213cbe5ee 100644 (file)
@@ -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,
index a493673e5985dd48fe0e45deb3abb23bcf6dd694..65b268c4eaff99e26caa1cad4948e7365de5e760 100644 (file)
@@ -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 {