]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: add instance delete & config write hooks
authorDavid Lamparter <equinox@diac24.net>
Fri, 10 May 2019 13:31:04 +0000 (15:31 +0200)
committerDavid Lamparter <equinox@diac24.net>
Wed, 3 Jul 2019 14:56:22 +0000 (16:56 +0200)
Both of these hooks are necessary for proper operation of extensions
that need to latch on to a particular instance.

- without the delete hook, it's impossible to get rid of stale
  references, leading to crashes with invalid instance pointers.
- the config-write hook is necessary because per-instance config needs
  to be written inside the "router bgp" block to have the appropriate
  context; adding a separate config node can't do that.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgpd.c
bgpd/bgpd.h

index cb90d39266ff2c5a484d2247ec35be10f8ecb56b..d79a68dcab2873150d56d91afd6da1f8ba867ac0 100644 (file)
@@ -94,6 +94,10 @@ DEFINE_MTYPE_STATIC(BGPD, BGP_EVPN_INFO, "BGP EVPN instance information");
 DEFINE_QOBJ_TYPE(bgp_master)
 DEFINE_QOBJ_TYPE(bgp)
 DEFINE_QOBJ_TYPE(peer)
+DEFINE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp))
+DEFINE_HOOK(bgp_inst_config_write,
+               (struct bgp *bgp, struct vty *vty),
+               (bgp, vty))
 
 /* BGP process wide configuration.  */
 static struct bgp_master bgp_master;
@@ -3286,6 +3290,9 @@ int bgp_delete(struct bgp *bgp)
        int i;
 
        assert(bgp);
+
+       hook_call(bgp_inst_delete, bgp);
+
        THREAD_OFF(bgp->t_startup);
        THREAD_OFF(bgp->t_maxmed_onstartup);
        THREAD_OFF(bgp->t_update_delay);
@@ -7797,6 +7804,8 @@ int bgp_config_write(struct vty *vty)
                /* EVPN configuration.  */
                bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
 
+               hook_call(bgp_inst_config_write, bgp, vty);
+
 #if ENABLE_BGP_VNC
                bgp_rfapi_cfg_write(vty, bgp);
 #endif
index c329c8a7eaffb1e526b66a4abfe97eda28a9c6fa..777db0ce223eeff4c33189bee0e8d1c42740c1f3 100644 (file)
@@ -24,6 +24,7 @@
 #include "qobj.h"
 #include <pthread.h>
 
+#include "hook.h"
 #include "frr_pthread.h"
 #include "lib/json.h"
 #include "vrf.h"
@@ -572,6 +573,11 @@ struct bgp {
 };
 DECLARE_QOBJ_TYPE(bgp)
 
+DECLARE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp))
+DECLARE_HOOK(bgp_inst_config_write,
+               (struct bgp *bgp, struct vty *vty),
+               (bgp, vty))
+
 #define BGP_ROUTE_ADV_HOLD(bgp) (bgp->main_peers_update_hold)
 
 #define IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)                                        \