From e69aa084193bcadc7a48c99c381741e8ff307658 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 15 Mar 2018 21:06:44 -0400 Subject: [PATCH] zebra: Allow for deletion of rules when the originator goes away When zebra detects that the originator has dissapeared delete all rules associated with that client. Signed-off-by: Donald Sharp --- zebra/zebra_pbr.c | 19 +++++++++++++++++++ zebra/zebra_pbr.h | 3 +++ zebra/zserv.c | 3 +++ 3 files changed, 25 insertions(+) diff --git a/zebra/zebra_pbr.c b/zebra/zebra_pbr.c index 4da09dc538..090ec2c502 100644 --- a/zebra/zebra_pbr.c +++ b/zebra/zebra_pbr.c @@ -133,6 +133,25 @@ void zebra_pbr_del_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule) __PRETTY_FUNCTION__); } +static void zebra_pbr_cleanup_rules(struct hash_backet *b, void *data) +{ + struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT); + struct zebra_pbr_rule *rule = b->data; + int *sock = data; + + if (rule->sock == *sock) { + kernel_del_pbr_rule(rule); + hash_release(zns->rules_hash, rule); + } +} + +void zebra_pbr_client_close_cleanup(int sock) +{ + struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT); + + hash_iterate(zns->rules_hash, zebra_pbr_cleanup_rules, &sock); +} + /* * Handle success or failure of rule (un)install in the kernel. */ diff --git a/zebra/zebra_pbr.h b/zebra/zebra_pbr.h index 4b28b6ec35..f910d8e742 100644 --- a/zebra/zebra_pbr.h +++ b/zebra/zebra_pbr.h @@ -132,7 +132,10 @@ extern void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule, */ extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule); +extern void zebra_pbr_client_close_cleanup(int sock); + extern void zebra_pbr_rules_free(void *arg); extern uint32_t zebra_pbr_rules_hash_key(void *arg); extern int zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2); + #endif /* _ZEBRA_PBR_H */ diff --git a/zebra/zserv.c b/zebra/zserv.c index 57b1be4b8b..5a903f051c 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -2631,6 +2631,9 @@ static void zebra_client_free(struct zserv *client) /* Send client de-registration to BFD */ zebra_ptm_bfd_client_deregister(client->proto); + /* Cleanup any rules installed from this client */ + zebra_pbr_client_close_cleanup(client->sock); + /* Cleanup any registered nexthops - across all VRFs. */ zebra_client_close_cleanup_rnh(client); -- 2.39.5