summaryrefslogtreecommitdiffstats
path: root/sbin/ipfw
diff options
context:
space:
mode:
authormelifaro <melifaro@FreeBSD.org>2014-08-08 21:09:22 +0000
committermelifaro <melifaro@FreeBSD.org>2014-08-08 21:09:22 +0000
commit57d917cb999b3ca0620d53795938338b40ab5904 (patch)
tree45e1754ea12684fe088b5eaba1277d3345b58dce /sbin/ipfw
parentdeeb40d882b2cea0871cad31896ee9feda938ebb (diff)
downloadFreeBSD-src-57d917cb999b3ca0620d53795938338b40ab5904.zip
FreeBSD-src-57d917cb999b3ca0620d53795938338b40ab5904.tar.gz
Kernel changes:
* Fix buffer calculation for table dumps * Fix IPv6 radix entiries addition broken in r269371. Userland changes: * Fix bug in retrieving statric ruleset * Fix several bugs in retrieving table list
Diffstat (limited to 'sbin/ipfw')
-rw-r--r--sbin/ipfw/ipfw2.c7
-rw-r--r--sbin/ipfw/tables.c37
2 files changed, 27 insertions, 17 deletions
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index fba03cb..d90ac1a 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -2659,7 +2659,7 @@ ipfw_get_config(struct cmdline_opts *co, struct format_opts *fo,
sz = 4096;
cfg = NULL;
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < 16; i++) {
if (cfg != NULL)
free(cfg);
if ((cfg = calloc(1, sz)) == NULL)
@@ -2676,9 +2676,10 @@ ipfw_get_config(struct cmdline_opts *co, struct format_opts *fo,
}
/* Buffer size is not enough. Try to increase */
- sz = sz * 2 + 200;
+ sz = sz * 2;
if (sz < cfg->size)
- sz = cfg->size + 200;
+ sz = cfg->size;
+ continue;
}
*pcfg = cfg;
diff --git a/sbin/ipfw/tables.c b/sbin/ipfw/tables.c
index 9167137..b78bbeb 100644
--- a/sbin/ipfw/tables.c
+++ b/sbin/ipfw/tables.c
@@ -67,7 +67,7 @@ static void table_fill_ntlv(ipfw_obj_ntlv *ntlv, char *name, uint32_t set,
static int table_flush_one(ipfw_xtable_info *i, void *arg);
static int table_show_one(ipfw_xtable_info *i, void *arg);
-static int table_get_list(ipfw_xtable_info *i, ipfw_obj_header *oh);
+static int table_do_get_list(ipfw_xtable_info *i, ipfw_obj_header **poh);
static void table_show_list(ipfw_obj_header *oh, int need_header);
static void table_show_entry(ipfw_xtable_info *i, ipfw_obj_tentry *tent);
@@ -760,10 +760,7 @@ table_show_one(ipfw_xtable_info *i, void *arg)
ipfw_obj_header *oh;
int error;
- if ((oh = calloc(1, i->size)) == NULL)
- return (ENOMEM);
-
- if ((error = table_get_list(i, oh)) != 0) {
+ if ((error = table_do_get_list(i, &oh)) != 0) {
err(EX_OSERR, "Error requesting table %s list", i->tablename);
return (error);
}
@@ -1304,31 +1301,43 @@ tables_foreach(table_cb_t *f, void *arg, int sort)
/*
* Retrieves all entries for given table @i in
- * eXtended format. Assumes buffer of size
- * @i->size has already been allocated by caller.
+ * eXtended format. Allocate buffer large enough
+ * to store result. Called needs to free it later.
*
* Returns 0 on success.
*/
static int
-table_get_list(ipfw_xtable_info *i, ipfw_obj_header *oh)
+table_do_get_list(ipfw_xtable_info *i, ipfw_obj_header **poh)
{
+ ipfw_obj_header *oh;
size_t sz;
int error, c;
sz = 0;
- for (c = 0; c < 3; c++) {
- table_fill_objheader(oh, i);
+ oh = NULL;
+ error = 0;
+ for (c = 0; c < 8; c++) {
if (sz < i->size)
- sz = i->size;
-
+ sz = i->size + 44;
+ if (oh != NULL)
+ free(oh);
+ if ((oh = calloc(1, sz)) == NULL)
+ continue;
+ table_fill_objheader(oh, i);
oh->opheader.version = 1; /* Current version */
error = do_get3(IP_FW_TABLE_XLIST, &oh->opheader, &sz);
+ if (error == 0) {
+ *poh = oh;
+ return (0);
+ }
+
if (error != ENOMEM)
- return (errno);
+ break;
}
+ free(oh);
- return (ENOMEM);
+ return (error);
}
/*
OpenPOWER on IntegriCloud