aboutsummaryrefslogtreecommitdiff
path: root/sbin/ipfw
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2014-08-08 06:36:26 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2014-08-08 06:36:26 +0000
commit28ea4fa355406524ed6c852e95a41d59040af9db (patch)
tree388e64527255c2c46e8e05586663f3851718c3f5 /sbin/ipfw
parent91e721d772ee5527a70a2faca5818cedea64fb8a (diff)
downloadsrc-28ea4fa355406524ed6c852e95a41d59040af9db.tar.gz
src-28ea4fa355406524ed6c852e95a41d59040af9db.zip
Remove IP_FW_TABLES_XGETSIZE opcode.
It is superseded by IP_FW_TABLES_XLIST.
Notes
Notes: svn path=/projects/ipfw/; revision=269704
Diffstat (limited to 'sbin/ipfw')
-rw-r--r--sbin/ipfw/tables.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/sbin/ipfw/tables.c b/sbin/ipfw/tables.c
index bfa04d03fbd4..cfc182b3790b 100644
--- a/sbin/ipfw/tables.c
+++ b/sbin/ipfw/tables.c
@@ -1147,41 +1147,46 @@ tablename_cmp(const void *a, const void *b)
static int
tables_foreach(table_cb_t *f, void *arg, int sort)
{
- ipfw_obj_lheader req, *olh;
+ ipfw_obj_lheader *olh;
ipfw_xtable_info *info;
size_t sz;
int i, error;
- memset(&req, 0, sizeof(req));
- sz = sizeof(req);
+ /* Start with reasonable default */
+ sz = sizeof(*olh) + 16 * sizeof(ipfw_xtable_info);
- if ((error = do_get3(IP_FW_TABLES_XGETSIZE, &req.opheader, &sz)) != 0)
- return (errno);
+ for (;;) {
+ if ((olh = calloc(1, sz)) == NULL)
+ return (ENOMEM);
- sz = req.size;
- if ((olh = calloc(1, sz)) == NULL)
- return (ENOMEM);
+ olh->size = sz;
+ error = do_get3(IP_FW_TABLES_XLIST, &olh->opheader, &sz);
+ if (error == ENOMEM) {
+ sz = olh->size;
+ free(olh);
+ continue;
+ } else if (error != 0) {
+ free(olh);
+ return (error);
+ }
- olh->size = sz;
- if ((error = do_get3(IP_FW_TABLES_XLIST, &olh->opheader, &sz)) != 0) {
- free(olh);
- return (errno);
- }
+ if (sort != 0)
+ qsort(olh + 1, olh->count, olh->objsize, tablename_cmp);
- if (sort != 0)
- qsort(olh + 1, olh->count, olh->objsize, tablename_cmp);
+ info = (ipfw_xtable_info *)(olh + 1);
+ for (i = 0; i < olh->count; i++) {
+ error = f(info, arg); /* Ignore errors for now */
+ info = (ipfw_xtable_info *)((caddr_t)info + olh->objsize);
+ }
- info = (ipfw_xtable_info *)(olh + 1);
- for (i = 0; i < olh->count; i++) {
- error = f(info, arg); /* Ignore errors for now */
- info = (ipfw_xtable_info *)((caddr_t)info + olh->objsize);
+ free(olh);
+ break;
}
- free(olh);
-
return (0);
}
+
/*
* Retrieves all entries for given table @i in
* eXtended format. Assumes buffer of size