]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Support rule range deletion in do_parse()
authorPhil Sutter <phil@nwl.cc>
Wed, 15 Nov 2023 12:09:27 +0000 (13:09 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 5 Dec 2023 15:35:37 +0000 (16:35 +0100)
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
iptables/xshared.h

index 177f3ddd1c19e22e802a682a8a9e295a6ed94cb1..62ae4141325ed02bc62621b2aa766e6c4b047d3e 100644 (file)
@@ -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;
index 69f50e505cb9be49a4d44347c2257e29c4a94bc6..2fd15c725faafe09cb8f53bf538817c08c5c7a29 100644 (file)
@@ -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;
 };