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 <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2018-03-15 21:06:44 -04:00
parent 46fe6fd557
commit e69aa08419
3 changed files with 25 additions and 0 deletions

View File

@ -133,6 +133,25 @@ void zebra_pbr_del_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule)
__PRETTY_FUNCTION__); __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. * Handle success or failure of rule (un)install in the kernel.
*/ */

View File

@ -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 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 void zebra_pbr_rules_free(void *arg);
extern uint32_t zebra_pbr_rules_hash_key(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); extern int zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2);
#endif /* _ZEBRA_PBR_H */ #endif /* _ZEBRA_PBR_H */

View File

@ -2631,6 +2631,9 @@ static void zebra_client_free(struct zserv *client)
/* Send client de-registration to BFD */ /* Send client de-registration to BFD */
zebra_ptm_bfd_client_deregister(client->proto); 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. */ /* Cleanup any registered nexthops - across all VRFs. */
zebra_client_close_cleanup_rnh(client); zebra_client_close_cleanup_rnh(client);