netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH 05/13] xshared: Support rule range deletion in do_parse()
Date: Wed, 29 Nov 2023 14:28:19 +0100	[thread overview]
Message-ID: <20231129132827.18166-6-phil@nwl.cc> (raw)
In-Reply-To: <20231129132827.18166-1-phil@nwl.cc>

This is a distinct ebtables feature. Introduce struct
xt_cmd_parse::rule_ranges boolean indicating support for it and bail
otherwise if a range was specified by the user.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 iptables/xshared.c | 34 +++++++++++++++++++++++++++++++++-
 iptables/xshared.h |  2 ++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/iptables/xshared.c b/iptables/xshared.c
index 177f3ddd1c19e..62ae4141325ed 100644
--- a/iptables/xshared.c
+++ b/iptables/xshared.c
@@ -903,6 +903,38 @@ static int parse_rulenumber(const char *rule)
 	return rulenum;
 }
 
+static void parse_rule_range(struct xt_cmd_parse *p, const char *argv)
+{
+	char *colon = strchr(argv, ':'), *buffer;
+
+	if (colon) {
+		if (!p->rule_ranges)
+			xtables_error(PARAMETER_PROBLEM,
+				      "Rule ranges are not supported");
+
+		*colon = '\0';
+		if (*(colon + 1) == '\0')
+			p->rulenum_end = -1; /* Until the last rule */
+		else {
+			p->rulenum_end = strtol(colon + 1, &buffer, 10);
+			if (*buffer != '\0' || p->rulenum_end == 0)
+				xtables_error(PARAMETER_PROBLEM,
+					      "Invalid rule range end`%s'",
+					      colon + 1);
+		}
+	}
+	if (colon == argv)
+		p->rulenum = 1; /* Beginning with the first rule */
+	else {
+		p->rulenum = strtol(argv, &buffer, 10);
+		if (*buffer != '\0' || p->rulenum == 0)
+			xtables_error(PARAMETER_PROBLEM,
+				      "Invalid rule number `%s'", argv);
+	}
+	if (!colon)
+		p->rulenum_end = p->rulenum;
+}
+
 /* list the commands an option is allowed with */
 #define CMD_IDRAC	CMD_INSERT | CMD_DELETE | CMD_REPLACE | \
 			CMD_APPEND | CMD_CHECK
@@ -1411,7 +1443,7 @@ void do_parse(int argc, char *argv[],
 			add_command(&p->command, CMD_DELETE, CMD_NONE, invert);
 			p->chain = optarg;
 			if (xs_has_arg(argc, argv)) {
-				p->rulenum = parse_rulenumber(argv[optind++]);
+				parse_rule_range(p, argv[optind++]);
 				p->command = CMD_DELETE_NUM;
 			}
 			break;
diff --git a/iptables/xshared.h b/iptables/xshared.h
index 69f50e505cb9b..2fd15c725faaf 100644
--- a/iptables/xshared.h
+++ b/iptables/xshared.h
@@ -280,6 +280,7 @@ struct xt_cmd_parse_ops {
 struct xt_cmd_parse {
 	unsigned int			command;
 	unsigned int			rulenum;
+	unsigned int			rulenum_end;
 	char				*table;
 	const char			*chain;
 	const char			*newname;
@@ -287,6 +288,7 @@ struct xt_cmd_parse {
 	bool				restore;
 	int				line;
 	int				verbose;
+	bool				rule_ranges;
 	struct xt_cmd_parse_ops		*ops;
 };
 
-- 
2.41.0


  parent reply	other threads:[~2023-11-29 13:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-29 13:28 [iptables PATCH 00/13] ebtables: Use the shared commandline parser Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 01/13] xshared: do_parse: Skip option checking for CMD_DELETE_NUM Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 02/13] xshared: Perform protocol value parsing in callback Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 03/13] xshared: Turn command_default() into a callback Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 04/13] xshared: Introduce print_help callback (again) Phil Sutter
2023-11-29 13:28 ` Phil Sutter [this message]
2023-11-29 13:28 ` [iptables PATCH 06/13] xshared: Support for ebtables' --change-counters command Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 07/13] ebtables{,-translate}: Convert if-clause to switch() Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 08/13] ebtables: Change option values to avoid clashes Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 09/13] ebtables: Pass struct iptables_command_state to print_help() Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 10/13] ebtables: Make 'h' case just a call " Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 11/13] ebtables: Use struct xt_cmd_parse Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 12/13] xshared: Introduce option_test_and_reject() Phil Sutter
2023-11-29 13:28 ` [iptables PATCH 13/13] ebtables: Use do_parse() from xshared Phil Sutter
2023-12-05 16:25 ` [iptables PATCH 00/13] ebtables: Use the shared commandline parser 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=20231129132827.18166-6-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;
as well as URLs for NNTP newsgroup(s).