diff options
author | melifaro <melifaro@FreeBSD.org> | 2014-07-29 22:44:26 +0000 |
---|---|---|
committer | melifaro <melifaro@FreeBSD.org> | 2014-07-29 22:44:26 +0000 |
commit | bf787a59a7c6413b1dd1682177a0f93b72f0b0b3 (patch) | |
tree | 0e45b9c7486c12007aabc924bc8523b0e8a47c2f /sbin/ipfw/tables.c | |
parent | 7e2cb6d90122052f5da200ce45c6e923f38e5b31 (diff) | |
download | FreeBSD-src-bf787a59a7c6413b1dd1682177a0f93b72f0b0b3.zip FreeBSD-src-bf787a59a7c6413b1dd1682177a0f93b72f0b0b3.tar.gz |
* Dump available table algorithms via "ipfw talist" cmd.
Kernel changes:
* Add type/refcount fields to table algo instances.
* Add IP_FW_TABLES_ALIST opcode to export available algorihms to userland.
Userland changes:
* Fix cores on empty input inside "ipfw table" handler.
* Add "ipfw talist" cmd to print availabled kernel algorithms.
* Change "table info" output to reflect long algorithm config lines.
Diffstat (limited to 'sbin/ipfw/tables.c')
-rw-r--r-- | sbin/ipfw/tables.c | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/sbin/ipfw/tables.c b/sbin/ipfw/tables.c index bd46dc3..ddb6e48 100644 --- a/sbin/ipfw/tables.c +++ b/sbin/ipfw/tables.c @@ -146,6 +146,7 @@ ipfw_table_handler(int ac, char *av[]) set = 0; ac--; av++; + NEED1("table needs name"); tablename = *av; if (table_check_name(tablename) == 0) { @@ -158,11 +159,11 @@ ipfw_table_handler(int ac, char *av[]) errx(EX_USAGE, "table name %s is invalid", tablename); } ac--; av++; + NEED1("table needs command"); if ((tcmd = match_token(tablecmds, *av)) == -1) errx(EX_USAGE, "invalid table command %s", *av); - NEED1("table needs command"); switch (tcmd) { case TOK_LIST: case TOK_INFO: @@ -416,8 +417,8 @@ table_show_info(ipfw_xtable_info *i, void *arg) vtype = "unknown"; printf(" type: %s, kindex: %d\n", ttype, i->kidx); - printf(" valtype: %s, algorithm: %s\n", vtype, i->algoname); - printf(" references: %u\n", i->refcnt); + printf(" valtype: %s, references: %u\n", vtype, i->refcnt); + printf(" algorithm: %s\n", i->algoname); printf(" items: %u, size: %u\n", i->count, i->size); return (0); @@ -901,6 +902,59 @@ table_show_entry(ipfw_xtable_info *i, ipfw_obj_tentry *tent) } } +static int +table_do_get_algolist(ipfw_obj_lheader **polh) +{ + ipfw_obj_lheader req, *olh; + size_t sz; + int error; + + memset(&req, 0, sizeof(req)); + sz = sizeof(req); + + error = do_get3(IP_FW_TABLES_ALIST, &req.opheader, &sz); + if (error != 0 && error != ENOMEM) + return (error); + + sz = req.size; + if ((olh = calloc(1, sz)) == NULL) + return (ENOMEM); + + olh->size = sz; + if ((error = do_get3(IP_FW_TABLES_ALIST, &olh->opheader, &sz)) != 0) { + free(olh); + return (error); + } + + *polh = olh; + return (0); +} + +void +ipfw_list_ta(int ac, char *av[]) +{ + ipfw_obj_lheader *olh; + ipfw_ta_info *info; + int error, i; + const char *atype; + + error = table_do_get_algolist(&olh); + if (error != 0) + err(EX_OSERR, "Unable to request algorithm list"); + + info = (ipfw_ta_info *)(olh + 1); + for (i = 0; i < olh->count; i++) { + if ((atype = match_value(tabletypes, info->type)) == NULL) + atype = "unknown"; + + printf("%s type: %s references: %u\n", info->algoname, + atype, info->refcnt); + info = (ipfw_ta_info *)((caddr_t)info + olh->objsize); + } + + free(olh); +} + int compare_ntlv(const void *_a, const void *_b) { |