diff options
author | ae <ae@FreeBSD.org> | 2016-08-04 11:26:52 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2016-08-04 11:26:52 +0000 |
commit | 0d5e1b683a7833199897c98c6182f8288c63dbf9 (patch) | |
tree | b3742a62a5e7399253007b38abc959ebe9ff3cb6 /sbin/ipfw | |
parent | d3b5f988692dfaa6e384a5d5b1863958311cc168 (diff) | |
download | FreeBSD-src-0d5e1b683a7833199897c98c6182f8288c63dbf9.zip FreeBSD-src-0d5e1b683a7833199897c98c6182f8288c63dbf9.tar.gz |
MFC r303615:
An old tables implementation had all tables preallocated,
so when user did `ipfw table N flush` it always worked, but now
when table N doesn't exist the kernel returns ESRCH error.
This isn't fatal error for flush and destroy commands. Do not
call err(3) when errno is equal to ESRCH. Also warn only when
quiet mode isn't enabled. This fixes a regression in behavior,
when old rules are loaded from file.
Also use correct value for switch in the table_swap().
Reported by: Kevin Oberman
Approved by: re (kib)
Diffstat (limited to 'sbin/ipfw')
-rw-r--r-- | sbin/ipfw/tables.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/sbin/ipfw/tables.c b/sbin/ipfw/tables.c index d14c9e9..5b0dd95 100644 --- a/sbin/ipfw/tables.c +++ b/sbin/ipfw/tables.c @@ -225,18 +225,30 @@ ipfw_table_handler(int ac, char *av[]) table_modify(&oh, ac, av); break; case TOK_DESTROY: - if (table_destroy(&oh) != 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); break; case TOK_FLUSH: if (is_all == 0) { - if ((error = table_flush(&oh)) != 0) + if ((error = table_flush(&oh)) == 0) + break; + if (errno != ESRCH) err(EX_OSERR, "failed to flush table %s info", tablename); + /* ESRCH isn't fatal, warn if not quiet mode */ + if (co.do_quiet == 0) + warn("failed to flush table %s info", + tablename); } else { error = tables_foreach(table_flush_one, &oh, 1); if (error != 0) err(EX_OSERR, "failed to flush tables list"); + /* XXX: we ignore errors here */ } break; case TOK_SWAP: @@ -593,14 +605,14 @@ table_do_swap(ipfw_obj_header *oh, char *second) static int table_swap(ipfw_obj_header *oh, char *second) { - int error; if (table_check_name(second) != 0) errx(EX_USAGE, "table name %s is invalid", second); - error = table_do_swap(oh, second); + if (table_do_swap(oh, second) == 0) + return (0); - switch (error) { + switch (errno) { case EINVAL: errx(EX_USAGE, "Unable to swap table: check types"); case EFBIG: |