From ed78b7c8251277bebbd5780e32d5bff3fb072751 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Sat, 24 Mar 2018 14:55:06 +0100 Subject: zebra: add a helper structure to look zebra_pbr_ipset per ipsetname Add an intermediate helper structure that is used to walk the list of ipset entries, and look for associated name. Signed-off-by: Philippe Guibert --- zebra/zebra_pbr.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'zebra/zebra_pbr.c') diff --git a/zebra/zebra_pbr.c b/zebra/zebra_pbr.c index 42b3f37da..eb686bf5a 100644 --- a/zebra/zebra_pbr.c +++ b/zebra/zebra_pbr.c @@ -335,20 +335,6 @@ static void *pbr_ipset_alloc_intern(void *arg) return new; } -static struct zebra_pbr_ipset *zpi_found; - -static int zebra_pbr_ipset_pername_walkcb(struct hash_backet *backet, void *arg) -{ - struct zebra_pbr_ipset *zpi = (struct zebra_pbr_ipset *)backet->data; - char *ipset_name = (char *)arg; - - if (!strncmp(ipset_name, zpi->ipset_name, ZEBRA_IPSET_NAME_SIZE)) { - zpi_found = zpi; - return HASHWALK_ABORT; - } - return HASHWALK_CONTINUE; -} - void zebra_pbr_create_ipset(struct zebra_ns *zns, struct zebra_pbr_ipset *ipset) { @@ -375,14 +361,38 @@ void zebra_pbr_destroy_ipset(struct zebra_ns *zns, __PRETTY_FUNCTION__); } +struct pbr_ipset_name_lookup { + struct zebra_pbr_ipset *ipset; + char ipset_name[ZEBRA_IPSET_NAME_SIZE]; +}; + +static int zebra_pbr_ipset_pername_walkcb(struct hash_backet *backet, void *arg) +{ + struct pbr_ipset_name_lookup *pinl = + (struct pbr_ipset_name_lookup *)arg; + struct zebra_pbr_ipset *zpi = (struct zebra_pbr_ipset *)backet->data; + + if (!strncmp(pinl->ipset_name, zpi->ipset_name, + ZEBRA_IPSET_NAME_SIZE)) { + pinl->ipset = zpi; + return HASHWALK_ABORT; + } + return HASHWALK_CONTINUE; +} + struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(struct zebra_ns *zns, char *ipsetname) { + struct pbr_ipset_name_lookup pinl; + struct pbr_ipset_name_lookup *ptr = &pinl; + if (!ipsetname) return NULL; - zpi_found = NULL; - hash_walk(zns->ipset_hash, zebra_pbr_ipset_pername_walkcb, ipsetname); - return zpi_found; + memset(ptr, 0, sizeof(struct pbr_ipset_name_lookup)); + snprintf((char *)ptr->ipset_name, ZEBRA_IPSET_NAME_SIZE, "%s", + ipsetname); + hash_walk(zns->ipset_hash, zebra_pbr_ipset_pername_walkcb, ptr); + return ptr->ipset; } static void *pbr_ipset_entry_alloc_intern(void *arg) -- cgit v1.2.3