svn commit: r269370 - projects/ipfw/sys/netpfil/ipfw
Alexander V. Chernikov
melifaro at FreeBSD.org
Fri Aug 1 07:35:19 UTC 2014
Author: melifaro
Date: Fri Aug 1 07:35:17 2014
New Revision: 269370
URL: http://svnweb.freebsd.org/changeset/base/269370
Log:
* Use TA_FLAG_DEFAULT for default algorithm selection instead of
exporting algorithm structures directly.
* Pass needed state buffer size in algo structures as preparation
for tables add/del requests batching.
Modified:
projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c
projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h
projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c
Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c
==============================================================================
--- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Fri Aug 1 06:20:25 2014 (r269369)
+++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Fri Aug 1 07:35:17 2014 (r269370)
@@ -91,6 +91,7 @@ struct tables_config {
struct namedobj_instance *namehash;
int algo_count;
struct table_algo *algo[256];
+ struct table_algo *def_algo[IPFW_TABLE_MAXTYPE + 1];
};
static struct table_config *find_table(struct namedobj_instance *ni,
@@ -1544,6 +1545,9 @@ find_table_algo(struct tables_config *tc
int i, l;
struct table_algo *ta;
+ if (ti->type > IPFW_TABLE_MAXTYPE)
+ return (NULL);
+
/* Search by index */
if (ti->atype != 0) {
if (ti->atype > tcfg->algo_count)
@@ -1575,19 +1579,8 @@ find_table_algo(struct tables_config *tc
return (NULL);
}
- /* Search by type */
- switch (ti->type) {
- case IPFW_TABLE_CIDR:
- return (&cidr_radix);
- case IPFW_TABLE_INTERFACE:
- return (&iface_idx);
- case IPFW_TABLE_NUMBER:
- return (&number_array);
- case IPFW_TABLE_FLOW:
- return (&flow_hash);
- }
-
- return (NULL);
+ /* Return default algorithm for given type if set */
+ return (tcfg->def_algo[ti->type]);
}
int
@@ -1600,6 +1593,8 @@ ipfw_add_table_algo(struct ip_fw_chain *
if (size > sizeof(struct table_algo))
return (EINVAL);
+ KASSERT(ta->type >= IPFW_TABLE_MAXTYPE,("Increase IPFW_TABLE_MAXTYPE"));
+
ta_new = malloc(sizeof(struct table_algo), M_IPFW, M_WAITOK | M_ZERO);
memcpy(ta_new, ta, size);
@@ -1610,6 +1605,11 @@ ipfw_add_table_algo(struct ip_fw_chain *
tcfg->algo[++tcfg->algo_count] = ta_new;
ta_new->idx = tcfg->algo_count;
+ /* Set algorithm as default one for given type */
+ if ((ta_new->flags & TA_FLAG_DEFAULT) != 0 &&
+ tcfg->def_algo[ta_new->type] == NULL)
+ tcfg->def_algo[ta_new->type] = ta_new;
+
*idx = ta_new->idx;
return (0);
@@ -1628,6 +1628,10 @@ ipfw_del_table_algo(struct ip_fw_chain *
ta = tcfg->algo[idx];
KASSERT(ta != NULL, ("algo idx %d is NULL", idx));
+
+ if (tcfg->def_algo[ta->type] == ta)
+ tcfg->def_algo[ta->type] = NULL;
+
free(ta, M_IPFW);
}
Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h
==============================================================================
--- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Fri Aug 1 06:20:25 2014 (r269369)
+++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Fri Aug 1 07:35:17 2014 (r269370)
@@ -99,10 +99,11 @@ typedef int ta_dump_tinfo(void *ta_state
struct table_algo {
char name[16];
- int idx;
- int type;
- int refcnt;
- int spare;
+ uint32_t idx;
+ uint32_t type;
+ uint32_t refcnt;
+ uint32_t flags;
+ size_t ta_buf_size;
ta_init *init;
ta_destroy *destroy;
ta_prepare_add *prepare_add;
@@ -121,13 +122,12 @@ struct table_algo {
ta_print_config *print_config;
ta_dump_tinfo *dump_tinfo;
};
+#define TA_FLAG_DEFAULT 0x01 /* Algorithm is default for given type */
int ipfw_add_table_algo(struct ip_fw_chain *ch, struct table_algo *ta,
size_t size, int *idx);
void ipfw_del_table_algo(struct ip_fw_chain *ch, int idx);
-extern struct table_algo cidr_radix, iface_idx, number_array, flow_hash;
-
void ipfw_table_algo_init(struct ip_fw_chain *chain);
void ipfw_table_algo_destroy(struct ip_fw_chain *chain);
Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c
==============================================================================
--- projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c Fri Aug 1 06:20:25 2014 (r269369)
+++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c Fri Aug 1 07:35:17 2014 (r269370)
@@ -517,6 +517,8 @@ ta_flush_cidr_entry(struct ip_fw_chain *
struct table_algo cidr_radix = {
.name = "cidr:radix",
.type = IPFW_TABLE_CIDR,
+ .flags = TA_FLAG_DEFAULT,
+ .ta_buf_size = sizeof(struct ta_buf_cidr),
.init = ta_init_radix,
.destroy = ta_destroy_radix,
.prepare_add = ta_prepare_add_cidr,
@@ -1364,6 +1366,7 @@ ta_flush_mod_chash(void *ta_buf)
struct table_algo cidr_hash = {
.name = "cidr:hash",
.type = IPFW_TABLE_CIDR,
+ .ta_buf_size = sizeof(struct ta_buf_chash),
.init = ta_init_chash,
.destroy = ta_destroy_chash,
.prepare_add = ta_prepare_add_chash,
@@ -2021,6 +2024,8 @@ ta_foreach_ifidx(void *ta_state, struct
struct table_algo iface_idx = {
.name = "iface:array",
.type = IPFW_TABLE_INTERFACE,
+ .flags = TA_FLAG_DEFAULT,
+ .ta_buf_size = sizeof(struct ta_buf_ifidx),
.init = ta_init_ifidx,
.destroy = ta_destroy_ifidx,
.prepare_add = ta_prepare_add_ifidx,
@@ -2384,6 +2389,7 @@ ta_foreach_numarray(void *ta_state, stru
struct table_algo number_array = {
.name = "number:array",
.type = IPFW_TABLE_NUMBER,
+ .ta_buf_size = sizeof(struct ta_buf_numarray),
.init = ta_init_numarray,
.destroy = ta_destroy_numarray,
.prepare_add = ta_prepare_add_numarray,
@@ -3051,6 +3057,8 @@ ta_flush_mod_fhash(void *ta_buf)
struct table_algo flow_hash = {
.name = "flow:hash",
.type = IPFW_TABLE_FLOW,
+ .flags = TA_FLAG_DEFAULT,
+ .ta_buf_size = sizeof(struct ta_buf_fhash),
.init = ta_init_fhash,
.destroy = ta_destroy_fhash,
.prepare_add = ta_prepare_add_fhash,
More information about the svn-src-projects
mailing list