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 <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2019-05-10 15:31:04 +02:00
parent 2ed9fe4a2b
commit 2b9bcf306d
2 changed files with 15 additions and 0 deletions

View 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

View 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) \