Skip to contentSkip to conversation

nft: Fix command name in ip6tables error message

PATCH In review Phil Sutter 2 participants 4 messages Aug 7, 2020 – Aug 13, 2020 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH v2 1/2 nft: Fix command name in ip6tables error message

Upon errors, ip6tables-nft would prefix its error messages with 'iptables:' instead of 'ip6tables:'. Turns out the command name was hard-coded, use 'progname' variable instead.
While being at it, merge the two mostly identical fprintf() calls into one.

---
Changes since v1:
- Added this fix. Related test ignored the prefix value, so this went unnoticed.

---
 iptables/xtables-standalone.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
iptables/xtables-standalone.c +4 -8
index dd6fb7919d2e1..7b71db62f1ea6 100644
@@ -75,14 +75,10 @@ xtables_main(int family, const char *progname, int argc, char *argv[])
 	xtables_fini();
 
 	if (!ret) {
-		if (errno == EINVAL) {
-			fprintf(stderr, "iptables: %s. "
-					"Run `dmesg' for more information.\n",
-				nft_strerror(errno));
-		} else {
-			fprintf(stderr, "iptables: %s.\n",
-				nft_strerror(errno));
-		}
+		fprintf(stderr, "%s: %s.%s\n", progname, nft_strerror(errno),
+			(errno == EINVAL ?
+			 " Run `dmesg' for more information." : ""));
+
 		if (errno == EAGAIN)
 			exit(RESOURCE_PROBLEM);
 	}
Signature · 1 line
2.27.0
author reviewer
#1 lore raw

PATCH v2 2/2 tests: shell: Merge and extend return codes test

Merge scripts for iptables and ip6tables, they were widely identical. Also extend the test by one check (removing a non-existent rule with valid chain and target) and quote the error messages where differences are deliberately ignored.

---
Changes since v1:
- Check error prefix value also.

---
 .../testcases/ip6tables/0004-return-codes_0   |  39 ------
 .../testcases/iptables/0004-return-codes_0    | 113 ++++++++++--------
 2 files changed, 61 insertions(+), 91 deletions(-)
 delete mode 100755 iptables/tests/shell/testcases/ip6tables/0004-return-codes_0
iptables/tests/shell/testcases/ip6tables/0004-return-codes_0 deleted +0 -39
deleted file mode 100755
index c583b0ebd97c3..0000000000000
@@ -1,39 +0,0 @@
-#!/bin/sh
-
-# make sure error return codes are as expected useful cases
-# (e.g. commands to check ruleset state)
-
-global_rc=0
-
-cmd() { # (rc, cmd, [args ...])
-	rc_exp=$1; shift
-
-	$XT_MULTI "$@"
-	rc=$?
-
-	[ $rc -eq $rc_exp ] || {
-		echo "---> expected $rc_exp, got $rc for command '$@'"
-		global_rc=1
-	}
-}
-
-# test chain creation
-cmd 0 ip6tables -N foo
-cmd 1 ip6tables -N foo
-# iptables-nft allows this - bug or feature?
-#cmd 2 ip6tables -N "invalid name"
-
-# test rule adding
-cmd 0 ip6tables -A INPUT -j ACCEPT
-cmd 1 ip6tables -A noexist -j ACCEPT
-cmd 2 ip6tables -I INPUT -j foobar
-
-# test rule checking
-cmd 0 ip6tables -C INPUT -j ACCEPT
-cmd 1 ip6tables -C FORWARD -j ACCEPT
-cmd 1 ip6tables -C nonexist -j ACCEPT
-cmd 2 ip6tables -C INPUT -j foobar
-cmd 2 ip6tables -C INPUT -m foobar -j ACCEPT
-cmd 3 ip6tables -t foobar -C INPUT -j ACCEPT
-
-exit $global_rc
iptables/tests/shell/testcases/iptables/0004-return-codes_0 +61 -52

136 lines not on this page · raw message

Signature · 1 line
2.27.0
maintainer Acked-by on v2 2/2
#2 lore raw

Re: [iptables PATCH v2 2/2] tests: shell: Merge and extend return codes test

Quoted 6 lines · Phil Sutter

Merge scripts for iptables and ip6tables, they were widely identical. Also extend the test by one check (removing a non-existent rule with valid chain and target) and quote the error messages where differences are deliberately ignored.