diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 85eb6b3451..130fb972db 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -2606,8 +2606,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,