From: Phil Sutter <phil@nwl.cc>
To: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH 1/2] tests: iptables-test: Properly assert rule deletion errors
Date: Tue, 5 Nov 2024 21:36:10 +0100 [thread overview]
Message-ID: <20241105203611.11182-1-phil@nwl.cc> (raw)
Capture any non-zero return code, iptables not necessarily returns 1 on
error.
A known issue with trying to delete a rule by spec is the unsupported
--set-counters option. Strip it before deleting the rule.
Fixes: c8b7aaabbe1fc ("add iptables unit test infrastructure")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
iptables-test.py | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/iptables-test.py b/iptables-test.py
index 0d2f30dfb0d7c..413e3fdccc9e3 100755
--- a/iptables-test.py
+++ b/iptables-test.py
@@ -58,10 +58,23 @@ STDERR_IS_TTY = sys.stderr.isatty()
def delete_rule(iptables, rule, filename, lineno, netns = None):
'''
Removes an iptables rule
+
+ Remove any --set-counters arguments, --delete rejects them.
'''
+ delrule = rule.split()
+ for i in range(len(delrule)):
+ if delrule[i] in ['-c', '--set-counters']:
+ delrule.pop(i)
+ if ',' in delrule.pop(i):
+ break
+ if len(delrule) > i and delrule[i].isnumeric():
+ delrule.pop(i)
+ break
+ rule = " ".join(delrule)
+
cmd = iptables + " -D " + rule
ret = execute_cmd(cmd, filename, lineno, netns)
- if ret == 1:
+ if ret != 0:
reason = "cannot delete: " + iptables + " -I " + rule
print_error(reason, filename, lineno)
return -1
--
2.47.0
next reply other threads:[~2024-11-05 20:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 20:36 Phil Sutter [this message]
2024-11-05 20:36 ` [iptables PATCH 2/2] tests: iptables-test: Extend fast mode docs a bit Phil Sutter
2024-11-05 23:03 ` [iptables PATCH 1/2] tests: iptables-test: Properly assert rule deletion errors Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241105203611.11182-1-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox