]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Perform protocol value parsing in callback
authorPhil Sutter <phil@nwl.cc>
Wed, 15 Nov 2023 14:43:42 +0000 (15:43 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 5 Dec 2023 15:35:37 +0000 (16:35 +0100)
The code is same in iptables and ip6tables, but different in ebtables.
Therefore move it into the callback to keep that part of do_parse()
generic.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/xshared.c
iptables/xshared.h

index 53e6720169950f4e3cd3675639f747ea507f872d..ff809f2be3438bbed664ad502cebc8b7b388f6f8 100644 (file)
@@ -1547,12 +1547,6 @@ void do_parse(int argc, char *argv[],
                                *cs->protocol = tolower(*cs->protocol);
 
                        cs->protocol = optarg;
-                       args->proto = xtables_parse_protocol(cs->protocol);
-
-                       if (args->proto == 0 &&
-                           (args->invflags & XT_INV_PROTO))
-                               xtables_error(PARAMETER_PROBLEM,
-                                          "rule would never match protocol");
 
                        /* This needs to happen here to parse extensions */
                        if (p->ops->proto_parse)
@@ -1865,7 +1859,13 @@ void do_parse(int argc, char *argv[],
 void ipv4_proto_parse(struct iptables_command_state *cs,
                      struct xtables_args *args)
 {
-       cs->fw.ip.proto = args->proto;
+       cs->fw.ip.proto = xtables_parse_protocol(cs->protocol);
+
+       if (cs->fw.ip.proto == 0 &&
+           (args->invflags & XT_INV_PROTO))
+               xtables_error(PARAMETER_PROBLEM,
+                             "rule would never match protocol");
+
        cs->fw.ip.invflags = args->invflags;
 }
 
@@ -1881,7 +1881,13 @@ static int is_exthdr(uint16_t proto)
 void ipv6_proto_parse(struct iptables_command_state *cs,
                      struct xtables_args *args)
 {
-       cs->fw6.ipv6.proto = args->proto;
+       cs->fw6.ipv6.proto = xtables_parse_protocol(cs->protocol);
+
+       if (cs->fw6.ipv6.proto == 0 &&
+           (args->invflags & XT_INV_PROTO))
+               xtables_error(PARAMETER_PROBLEM,
+                             "rule would never match protocol");
+
        cs->fw6.ipv6.invflags = args->invflags;
 
        /* this is needed for ip6tables-legacy only */
index d2ce72e90824a1cfd20487aa4d08b4ba71543f7a..3df2153fd6a10bb9c7936b5f0ceb3c31ad92af63 100644 (file)
@@ -249,7 +249,6 @@ struct addr_mask {
 
 struct xtables_args {
        int             family;
-       uint16_t        proto;
        uint8_t         flags;
        uint16_t        invflags;
        char            iniface[IFNAMSIZ], outiface[IFNAMSIZ];