From 286880219bb33cabda834223904f28ee6a719533 Mon Sep 17 00:00:00 2001 From: melifaro Date: Tue, 29 Jul 2014 08:00:13 +0000 Subject: [PATCH] * Change algorthm names to "type:algo" (e.g. "iface:array", "cidr:radix") format. * Pass number of items changed in add/del hooks to permit adding/deleting multiple values at once. --- sys/netpfil/ipfw/ip_fw_table.c | 18 +++++++++++------- sys/netpfil/ipfw/ip_fw_table.h | 4 ++-- sys/netpfil/ipfw/ip_fw_table_algo.c | 27 +++++++++++++++++---------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/sys/netpfil/ipfw/ip_fw_table.c b/sys/netpfil/ipfw/ip_fw_table.c index b328bed26834..c75c2788ab27 100644 --- a/sys/netpfil/ipfw/ip_fw_table.c +++ b/sys/netpfil/ipfw/ip_fw_table.c @@ -139,6 +139,7 @@ add_table_entry(struct ip_fw_chain *ch, struct tid_info *ti, struct namedobj_instance *ni; uint16_t kidx; int error; + uint32_t num; uint64_t aflags; char ta_buf[128]; @@ -222,16 +223,16 @@ add_table_entry(struct ip_fw_chain *ch, struct tid_info *ti, /* We've got valid table in @tc. Let's add data */ kidx = tc->no.kidx; ta = tc->ta; + num = 0; IPFW_WLOCK(ch); - - error = ta->add(tc->astate, KIDX_TO_TI(ch, kidx), tei, &ta_buf, &aflags); - + error = ta->add(tc->astate, KIDX_TO_TI(ch, kidx), tei, &ta_buf, + &aflags, &num); IPFW_WUNLOCK(ch); /* Update number of records. */ - if (error == 0 && (tei->flags & TEI_FLAGS_UPDATED) == 0) - tc->count++; + if (error == 0) + tc->count += num; tc->flags = aflags; @@ -252,6 +253,7 @@ del_table_entry(struct ip_fw_chain *ch, struct tid_info *ti, struct namedobj_instance *ni; uint16_t kidx; int error; + uint32_t num; uint64_t aflags; char ta_buf[128]; @@ -302,13 +304,15 @@ del_table_entry(struct ip_fw_chain *ch, struct tid_info *ti, } kidx = tc->no.kidx; + num = 0; IPFW_WLOCK(ch); - error = ta->del(tc->astate, KIDX_TO_TI(ch, kidx), tei, &ta_buf,&aflags); + error = ta->del(tc->astate, KIDX_TO_TI(ch, kidx), tei, &ta_buf, + &aflags, &num); IPFW_WUNLOCK(ch); if (error == 0) - tc->count--; + tc->count -= num; tc->flags = aflags; IPFW_UH_WUNLOCK(ch); diff --git a/sys/netpfil/ipfw/ip_fw_table.h b/sys/netpfil/ipfw/ip_fw_table.h index 59f52d8454de..abcbfd720961 100644 --- a/sys/netpfil/ipfw/ip_fw_table.h +++ b/sys/netpfil/ipfw/ip_fw_table.h @@ -70,9 +70,9 @@ typedef int (ta_prepare_add)(struct ip_fw_chain *ch, struct tentry_info *tei, typedef int (ta_prepare_del)(struct ip_fw_chain *ch, struct tentry_info *tei, void *ta_buf); typedef int (ta_add)(void *ta_state, struct table_info *ti, - struct tentry_info *tei, void *ta_buf, uint64_t *pflags); + struct tentry_info *tei, void *ta_buf, uint64_t *pflags, uint32_t *pnum); typedef int (ta_del)(void *ta_state, struct table_info *ti, - struct tentry_info *tei, void *ta_buf, uint64_t *pflags); + struct tentry_info *tei, void *ta_buf, uint64_t *pflags, uint32_t *pnum); typedef void (ta_flush_entry)(struct ip_fw_chain *ch, struct tentry_info *tei, void *ta_buf); diff --git a/sys/netpfil/ipfw/ip_fw_table_algo.c b/sys/netpfil/ipfw/ip_fw_table_algo.c index 3147464c7cc4..7b8b6067bb58 100644 --- a/sys/netpfil/ipfw/ip_fw_table_algo.c +++ b/sys/netpfil/ipfw/ip_fw_table_algo.c @@ -365,8 +365,8 @@ ta_prepare_add_cidr(struct ip_fw_chain *ch, struct tentry_info *tei, } static int -ta_add_cidr(void *ta_state, struct table_info *ti, - struct tentry_info *tei, void *ta_buf, uint64_t *pflags) +ta_add_cidr(void *ta_state, struct table_info *ti, struct tentry_info *tei, + void *ta_buf, uint64_t *pflags, uint32_t *pnum) { struct radix_node_head *rnh; struct radix_node *rn; @@ -408,11 +408,13 @@ ta_add_cidr(void *ta_state, struct table_info *ti, /* Indicate that update has happened instead of addition */ tei->flags |= TEI_FLAGS_UPDATED; + *pnum = 0; return (0); } tb->ent_ptr = NULL; + *pnum = 1; return (0); } @@ -474,8 +476,8 @@ ta_prepare_del_cidr(struct ip_fw_chain *ch, struct tentry_info *tei, } static int -ta_del_cidr(void *ta_state, struct table_info *ti, - struct tentry_info *tei, void *ta_buf, uint64_t *pflags) +ta_del_cidr(void *ta_state, struct table_info *ti, struct tentry_info *tei, + void *ta_buf, uint64_t *pflags, uint32_t *pnum) { struct radix_node_head *rnh; struct radix_node *rn; @@ -495,6 +497,8 @@ ta_del_cidr(void *ta_state, struct table_info *ti, if (rn == NULL) return (ENOENT); + *pnum = 1; + return (0); } @@ -511,7 +515,7 @@ ta_flush_cidr_entry(struct ip_fw_chain *ch, struct tentry_info *tei, } struct table_algo radix_cidr = { - .name = "radix_cidr", + .name = "cidr:radix", .lookup = ta_lookup_radix, .init = ta_init_radix, .destroy = ta_destroy_radix, @@ -808,8 +812,8 @@ ta_prepare_add_ifidx(struct ip_fw_chain *ch, struct tentry_info *tei, } static int -ta_add_ifidx(void *ta_state, struct table_info *ti, - struct tentry_info *tei, void *ta_buf, uint64_t *pflags) +ta_add_ifidx(void *ta_state, struct table_info *ti, struct tentry_info *tei, + void *ta_buf, uint64_t *pflags, uint32_t *pnum) { struct iftable_cfg *icfg; struct ifentry *ife, *tmp; @@ -843,6 +847,7 @@ ta_add_ifidx(void *ta_state, struct table_info *ti, /* Indicate that update has happened instead of addition */ tei->flags |= TEI_FLAGS_UPDATED; + *pnum = 0; return (0); } @@ -859,6 +864,7 @@ ta_add_ifidx(void *ta_state, struct table_info *ti, } tb->ife = NULL; + *pnum = 1; return (0); } @@ -890,8 +896,8 @@ ta_prepare_del_ifidx(struct ip_fw_chain *ch, struct tentry_info *tei, * runtime array. Removed interface notification. */ static int -ta_del_ifidx(void *ta_state, struct table_info *ti, - struct tentry_info *tei, void *ta_buf, uint64_t *pflags) +ta_del_ifidx(void *ta_state, struct table_info *ti, struct tentry_info *tei, + void *ta_buf, uint64_t *pflags, uint32_t *pnum) { struct iftable_cfg *icfg; struct ifentry *ife; @@ -931,6 +937,7 @@ ta_del_ifidx(void *ta_state, struct table_info *ti, icfg->count--; tb->ife = ife; + *pnum = 1; return (0); } @@ -1161,7 +1168,7 @@ ta_foreach_ifidx(void *ta_state, struct table_info *ti, ta_foreach_f *f, } struct table_algo idx_iface = { - .name = "idx_iface", + .name = "iface:array", .lookup = ta_lookup_ifidx, .init = ta_init_ifidx, .destroy = ta_destroy_ifidx,