]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Introduce option_test_and_reject()
authorPhil Sutter <phil@nwl.cc>
Tue, 28 Nov 2023 23:30:02 +0000 (00:30 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 5 Dec 2023 15:35:37 +0000 (16:35 +0100)
Just a small helper eliminating the repetitive code there.

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

index 50f23757d4aff3ebc31881cbb2ec32da850da85b..ebe172223486e133f2c6ed2bbb661aa7a3036152 100644 (file)
@@ -1439,6 +1439,15 @@ static void parse_change_counters_rule(int argc, char **argv,
                              "Packet counter '%s' invalid", argv[optind - 1]);
 }
 
+static void option_test_and_reject(struct xt_cmd_parse *p,
+                                  struct iptables_command_state *cs,
+                                  unsigned int option)
+{
+       if (cs->options & option)
+               xtables_error(PARAMETER_PROBLEM, "Can't use %s with %s",
+                             p->ops->option_name(option), p->chain);
+}
+
 void do_parse(int argc, char *argv[],
              struct xt_cmd_parse *p, struct iptables_command_state *cs,
              struct xtables_args *args)
@@ -1924,21 +1933,13 @@ void do_parse(int argc, char *argv[],
                if (strcmp(p->chain, "PREROUTING") == 0
                    || strcmp(p->chain, "INPUT") == 0) {
                        /* -o not valid with incoming packets. */
-                       if (cs->options & OPT_VIANAMEOUT)
-                               xtables_error(PARAMETER_PROBLEM,
-                                             "Can't use %s with %s\n",
-                                             p->ops->option_name(OPT_VIANAMEOUT),
-                                             p->chain);
+                       option_test_and_reject(p, cs, OPT_VIANAMEOUT);
                }
 
                if (strcmp(p->chain, "POSTROUTING") == 0
                    || strcmp(p->chain, "OUTPUT") == 0) {
                        /* -i not valid with outgoing packets */
-                       if (cs->options & OPT_VIANAMEIN)
-                               xtables_error(PARAMETER_PROBLEM,
-                                             "Can't use %s with %s\n",
-                                             p->ops->option_name(OPT_VIANAMEIN),
-                                             p->chain);
+                       option_test_and_reject(p, cs, OPT_VIANAMEIN);
                }
        }
 }