From 6082fb4249ce59b5e19b2257d78c4d91316a11bc Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 17 Oct 2022 18:23:16 +0200 Subject: [PATCH] zebra: upon srte leave, flush sr policies Upon srte leave, flush SR policies. Signed-off-by: Philippe Guibert --- zebra/zapi_msg.c | 4 +++- zebra/zebra_srte.c | 17 +++++++++++++++++ zebra/zebra_srte.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 761ba789b8..3461391e9b 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -2605,8 +2605,10 @@ static void zread_sr_policy_set(ZAPI_HANDLER_ARGS) return; policy = zebra_sr_policy_find(zp.color, &zp.endpoint); - if (!policy) + if (!policy) { policy = zebra_sr_policy_add(zp.color, &zp.endpoint, zp.name); + policy->sock = client->sock; + } /* TODO: per-VRF list of SR-TE policies. */ policy->zvrf = zvrf; diff --git a/zebra/zebra_srte.c b/zebra/zebra_srte.c index c0f18dd091..7d95607fcf 100644 --- a/zebra/zebra_srte.c +++ b/zebra/zebra_srte.c @@ -384,6 +384,23 @@ int zebra_sr_policy_label_update(mpls_label_t label, return 0; } +static int zebra_srte_client_close_cleanup(struct zserv *client) +{ + int sock = client->sock; + struct zebra_sr_policy *policy; + + if (!sock) + return 0; + + RB_FOREACH (policy, zebra_sr_policy_instance_head, + &zebra_sr_policy_instances) { + if (policy->sock == sock) + zebra_sr_policy_del(policy); + } + return 1; +} + void zebra_srte_init(void) { + hook_register(zserv_client_close, zebra_srte_client_close_cleanup); } diff --git a/zebra/zebra_srte.h b/zebra/zebra_srte.h index fe77809446..dff2f595fd 100644 --- a/zebra/zebra_srte.h +++ b/zebra/zebra_srte.h @@ -45,6 +45,7 @@ struct zebra_sr_policy { struct zapi_srte_tunnel segment_list; struct zebra_lsp *lsp; struct zebra_vrf *zvrf; + int sock; }; RB_HEAD(zebra_sr_policy_instance_head, zebra_sr_policy); RB_PROTOTYPE(zebra_sr_policy_instance_head, zebra_sr_policy, entry,