From: David Lamparter Date: Fri, 10 May 2019 13:31:04 +0000 (+0200) Subject: bgpd: add instance delete & config write hooks X-Git-Tag: base_7.2~156^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=2b9bcf306d2ae15d4f38bc3dd9281e321018ec6a;p=matthieu%2Ffrr.git bgpd: add instance delete & config write hooks 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 --- diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index cb90d39266..d79a68dcab 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -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 diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index c329c8a7ea..777db0ce22 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -24,6 +24,7 @@ #include "qobj.h" #include +#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) \