Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Aug 2016 11:26:53 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r303741 - stable/11/sbin/ipfw
Message-ID:  <201608041126.u74BQre9092404@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Thu Aug  4 11:26:52 2016
New Revision: 303741
URL: https://svnweb.freebsd.org/changeset/base/303741

Log:
  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)

Modified:
  stable/11/sbin/ipfw/tables.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sbin/ipfw/tables.c
==============================================================================
--- stable/11/sbin/ipfw/tables.c	Thu Aug  4 11:22:51 2016	(r303740)
+++ stable/11/sbin/ipfw/tables.c	Thu Aug  4 11:26:52 2016	(r303741)
@@ -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 
 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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608041126.u74BQre9092404>