diff options
author | melifaro <melifaro@FreeBSD.org> | 2014-08-08 06:36:26 +0000 |
---|---|---|
committer | melifaro <melifaro@FreeBSD.org> | 2014-08-08 06:36:26 +0000 |
commit | 3ad34df4472b316ac80c927629d2174c81a8be1f (patch) | |
tree | 388e64527255c2c46e8e05586663f3851718c3f5 /sbin/ipfw | |
parent | c2c120701d7e4f33daa7f3ca7e852aed0b6a5f4c (diff) | |
download | FreeBSD-src-3ad34df4472b316ac80c927629d2174c81a8be1f.zip FreeBSD-src-3ad34df4472b316ac80c927629d2174c81a8be1f.tar.gz |
Remove IP_FW_TABLES_XGETSIZE opcode.
It is superseded by IP_FW_TABLES_XLIST.
Diffstat (limited to 'sbin/ipfw')
-rw-r--r-- | sbin/ipfw/tables.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/sbin/ipfw/tables.c b/sbin/ipfw/tables.c index bfa04d0..cfc182b 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 |