From d24af713c14c4c6eb5d475e8a92626cf4843b074 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Tue, 26 Mar 2019 14:48:13 +0100 Subject: [PATCH] bfdd: upon vrf enable/disable, update bs and obs list parse observer list, and update bs context if vrf pointer is not yet populated. this is helpful for validation, but also will permit bfd to send notification to remote daemon. Signed-off-by: Philippe Guibert --- bfdd/bfd.c | 8 ++++++-- bfdd/bfd.h | 2 ++ bfdd/ptm_adapter.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/bfdd/bfd.c b/bfdd/bfd.c index 8acf779660..06ab5ea409 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -1503,8 +1503,10 @@ static int bfd_vrf_enable(struct vrf *vrf) thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echov6, &bvrf->bg_ev[5]); - if (vrf->vrf_id != VRF_DEFAULT) + if (vrf->vrf_id != VRF_DEFAULT) { bfdd_zclient_register(vrf->vrf_id); + bfdd_sessions_enable_vrf(vrf); + } return 0; } @@ -1516,8 +1518,10 @@ static int bfd_vrf_disable(struct vrf *vrf) return 0; bvrf = vrf->info; - if (vrf->vrf_id != VRF_DEFAULT) + if (vrf->vrf_id != VRF_DEFAULT) { + bfdd_sessions_disable_vrf(vrf); bfdd_zclient_unregister(vrf->vrf_id); + } log_debug("VRF disable %s id %d", vrf->name, vrf->vrf_id); /* Close all descriptors. */ diff --git a/bfdd/bfd.h b/bfdd/bfd.h index c94b9a6371..2bfdcc4055 100644 --- a/bfdd/bfd.h +++ b/bfdd/bfd.h @@ -588,6 +588,8 @@ void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv); void bfdd_zclient_stop(void); void bfdd_zclient_unregister(vrf_id_t vrf_id); void bfdd_zclient_register(vrf_id_t vrf_id); +void bfdd_sessions_enable_vrf(struct vrf *vrf); +void bfdd_sessions_disable_vrf(struct vrf *vrf); int ptm_bfd_notify(struct bfd_session *bs); diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c index a98d19aa2f..abfb4e4a26 100644 --- a/bfdd/ptm_adapter.c +++ b/bfdd/ptm_adapter.c @@ -605,6 +605,52 @@ static void bfdd_sessions_disable_interface(struct interface *ifp) } } +void bfdd_sessions_enable_vrf(struct vrf *vrf) +{ + struct bfd_session_observer *bso; + struct bfd_session *bs; + + /* it may affect configs without interfaces */ + TAILQ_FOREACH(bso, &bglobal.bg_obslist, bso_entry) { + bs = bso->bso_bs; + if (bs->vrf) + continue; + if (bs->key.vrfname[0] && + strcmp(vrf->name, bs->key.vrfname)) + continue; + /* need to update the vrf information on + * bs so that callbacks are handled + */ + bs->vrf = vrf; + /* Skip enabled sessions. */ + if (bs->sock != -1) + continue; + /* Try to enable it. */ + bfd_session_enable(bs); + } +} + +void bfdd_sessions_disable_vrf(struct vrf *vrf) +{ + struct bfd_session_observer *bso; + struct bfd_session *bs; + + TAILQ_FOREACH(bso, &bglobal.bg_obslist, bso_entry) { + if (bso->bso_isinterface) + continue; + bs = bso->bso_bs; + if (bs->key.vrfname[0] && + strcmp(vrf->name, bs->key.vrfname)) + continue; + /* Skip disabled sessions. */ + if (bs->sock == -1) + continue; + + /* Try to enable it. */ + bfd_session_disable(bs); + } +} + static int bfdd_interface_update(ZAPI_CALLBACK_ARGS) { struct interface *ifp; -- 2.39.5