* 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.
This commit is contained in:
Alexander V. Chernikov 2014-07-29 08:00:13 +00:00
parent 68394ec88e
commit adea620132
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/ipfw/; revision=269227
3 changed files with 30 additions and 19 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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,