diff options
author | ae <ae@FreeBSD.org> | 2017-05-10 05:01:05 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2017-05-10 05:01:05 +0000 |
commit | 1315752a993f2475ae9edd5a523ab888e229d64e (patch) | |
tree | 908b762a7a403425fbd053602d3275c63430ca25 | |
parent | 411e7fee1b56c4c65f802efd2ef8f11f365c0ab5 (diff) | |
download | FreeBSD-src-1315752a993f2475ae9edd5a523ab888e229d64e.zip FreeBSD-src-1315752a993f2475ae9edd5a523ab888e229d64e.tar.gz |
MFC r317682:
Add `ipfw table all destroy` support.
PR: 212669
-rw-r--r-- | sbin/ipfw/ipfw.8 | 4 | ||||
-rw-r--r-- | sbin/ipfw/tables.c | 42 |
2 files changed, 37 insertions, 9 deletions
diff --git a/sbin/ipfw/ipfw.8 b/sbin/ipfw/ipfw.8 index 999bf8a..d9a991b 100644 --- a/sbin/ipfw/ipfw.8 +++ b/sbin/ipfw/ipfw.8 @@ -50,7 +50,9 @@ in-kernel NAT. .Nm .Oo Cm set Ar N Oc Cm table Ar name Cm create Ar create-options .Nm -.Oo Cm set Ar N Oc Cm table Ar name Cm destroy +.Oo Cm set Ar N Oc Cm table +.Brq Ar name | all +.Cm destroy .Nm .Oo Cm set Ar N Oc Cm table Ar name Cm modify Ar modify-options .Nm diff --git a/sbin/ipfw/tables.c b/sbin/ipfw/tables.c index 6f41de3..b8a8cd2 100644 --- a/sbin/ipfw/tables.c +++ b/sbin/ipfw/tables.c @@ -54,6 +54,7 @@ static int table_swap(ipfw_obj_header *oh, char *second); static int table_get_info(ipfw_obj_header *oh, ipfw_xtable_info *i); static int table_show_info(ipfw_xtable_info *i, void *arg); +static int table_destroy_one(ipfw_xtable_info *i, void *arg); 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_do_get_list(ipfw_xtable_info *i, ipfw_obj_header **poh); @@ -132,7 +133,7 @@ lookup_host (char *host, struct in_addr *ipaddr) * This one handles all table-related commands * ipfw table NAME create ... * ipfw table NAME modify ... - * ipfw table NAME destroy + * ipfw table {NAME | all} destroy * ipfw table NAME swap NAME * ipfw table NAME lock * ipfw table NAME unlock @@ -200,6 +201,7 @@ ipfw_table_handler(int ac, char *av[]) case TOK_INFO: case TOK_DETAIL: case TOK_FLUSH: + case TOK_DESTROY: break; default: if (is_all != 0) @@ -223,13 +225,21 @@ ipfw_table_handler(int ac, char *av[]) table_modify(&oh, ac, av); break; case TOK_DESTROY: - if (table_destroy(&oh) == 0) - break; - if (errno != ESRCH) - err(EX_OSERR, "failed to destroy table %s", tablename); - /* ESRCH isn't fatal, warn if not quiet mode */ - if (co.do_quiet == 0) - warn("failed to destroy table %s", tablename); + if (is_all == 0) { + if (table_destroy(&oh) == 0) + break; + if (errno != ESRCH) + err(EX_OSERR, "failed to destroy table %s", + tablename); + /* ESRCH isn't fatal, warn if not quiet mode */ + if (co.do_quiet == 0) + warn("failed to destroy table %s", tablename); + } else { + error = tables_foreach(table_destroy_one, &oh, 1); + if (error != 0) + err(EX_OSERR, + "failed to destroy tables list"); + } break; case TOK_FLUSH: if (is_all == 0) { @@ -567,6 +577,22 @@ table_destroy(ipfw_obj_header *oh) return (0); } +static int +table_destroy_one(ipfw_xtable_info *i, void *arg) +{ + ipfw_obj_header *oh; + + oh = (ipfw_obj_header *)arg; + table_fill_ntlv(&oh->ntlv, i->tablename, i->set, 1); + if (table_destroy(oh) != 0) { + if (co.do_quiet == 0) + warn("failed to destroy table(%s) in set %u", + i->tablename, i->set); + return (-1); + } + return (0); +} + /* * Flushes given table specified by @oh->ntlv. * Returns 0 on success. |