]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: Drop xtables_globals 'optstring' field
authorPhil Sutter <phil@nwl.cc>
Thu, 5 May 2022 21:48:50 +0000 (23:48 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 11 May 2022 10:02:35 +0000 (12:02 +0200)
Define the different optstrings in xshared.h instead, they are not
relevant for other libxtables users.

This is a partial revert of commit 65b150ae382a8 ("xshared: Store
optstring in xtables_globals") to avoid breaking libxtables' ABI
compatibility.

Signed-off-by: Phil Sutter <phil@nwl.cc>
include/xtables.h
iptables/ip6tables.c
iptables/iptables.c
iptables/xshared.c
iptables/xshared.h
iptables/xtables-arp.c
iptables/xtables-eb.c
iptables/xtables.c

index a93e8f6e91585f2f28b7226c3f0ccf2ff43e757a..8c1065bc7e010fc358d2aac1c89d309d16ffc76a 100644 (file)
@@ -420,7 +420,6 @@ struct xtables_globals
 {
        unsigned int option_offset;
        const char *program_name, *program_version;
-       const char *optstring;
        struct option *orig_opts;
        struct option *opts;
        void (*exit_err)(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3)));
index 5806a13ce0710f1ec7217ffb432d47b579260f91..75984cc1bcdd88337d5c1981b774c295548c5799 100644 (file)
@@ -90,7 +90,6 @@ static struct option original_opts[] = {
 struct xtables_globals ip6tables_globals = {
        .option_offset = 0,
        .program_version = PACKAGE_VERSION " (legacy)",
-       .optstring = OPTSTRING_COMMON "R:S::W::" "46bg:h::m:nvw::x",
        .orig_opts = original_opts,
        .compat_rev = xtables_compatible_revision,
 };
index edde604cf2367cd8a66d362b59f2707cd9376f88..e5207ba106057dad88246e68286554c1f3a973f1 100644 (file)
@@ -87,7 +87,6 @@ static struct option original_opts[] = {
 struct xtables_globals iptables_globals = {
        .option_offset = 0,
        .program_version = PACKAGE_VERSION " (legacy)",
-       .optstring = OPTSTRING_COMMON "R:S::W::" "46bfg:h::m:nvw::x",
        .orig_opts = original_opts,
        .compat_rev = xtables_compatible_revision,
 };
index e959f203e5cc9474a6d0b1dbb0ef64be279fd220..fae5ddd5df93ed7af760d3295a83ad3b0ca114d6 100644 (file)
@@ -1340,6 +1340,20 @@ static void check_inverse(struct xtables_args *args, const char option[],
        }
 }
 
+static const char *optstring_lookup(int family)
+{
+       switch (family) {
+       case AF_INET:
+       case AF_INET6:
+               return IPT_OPTSTRING;
+       case NFPROTO_ARP:
+               return ARPT_OPTSTRING;
+       case NFPROTO_BRIDGE:
+               return EBT_OPTSTRING;
+       }
+       return "";
+}
+
 void do_parse(int argc, char *argv[],
              struct xt_cmd_parse *p, struct iptables_command_state *cs,
              struct xtables_args *args)
@@ -1370,7 +1384,8 @@ void do_parse(int argc, char *argv[],
        opterr = 0;
 
        xt_params->opts = xt_params->orig_opts;
-       while ((cs->c = getopt_long(argc, argv, xt_params->optstring,
+       while ((cs->c = getopt_long(argc, argv,
+                                   optstring_lookup(afinfo->family),
                                    xt_params->opts, NULL)) != -1) {
                switch (cs->c) {
                        /*
index e69da7351efa4379fa72f96657febfc941fc7dc0..14568bb00fb6510cdadb79ba0b9fa49a39ec4522 100644 (file)
@@ -68,6 +68,9 @@ struct xtables_rule_match;
 struct xtables_target;
 
 #define OPTSTRING_COMMON "-:A:C:D:E:F::I:L::M:N:P:VX::Z::" "c:d:i:j:o:p:s:t:"
+#define IPT_OPTSTRING  OPTSTRING_COMMON "R:S::W::" "46bfg:h::m:nvw::x"
+#define ARPT_OPTSTRING OPTSTRING_COMMON "R:S::" "h::l:nv" /* "m:" */
+#define EBT_OPTSTRING  OPTSTRING_COMMON "hv"
 
 /* define invflags which won't collide with IPT ones */
 #define IPT_INV_SRCDEVADDR     0x0080
index bf7d44e7b815bdcaea6fec7edd3c2c05cecba124..71518a9cbdb6a14482f0772228fe93e1ffc3b75a 100644 (file)
@@ -86,7 +86,6 @@ static struct option original_opts[] = {
 struct xtables_globals arptables_globals = {
        .option_offset          = 0,
        .program_version        = PACKAGE_VERSION " (nf_tables)",
-       .optstring              = OPTSTRING_COMMON "C:R:S::" "h::l:nv" /* "m:" */,
        .orig_opts              = original_opts,
        .compat_rev             = nft_compatible_revision,
 };
index a7bfb9c5c60b8c68c580f045a735b751de6c7c08..3d15063e80e91ed6b3234833639a06ba53a6e265 100644 (file)
@@ -220,7 +220,6 @@ struct option ebt_original_options[] =
 struct xtables_globals ebtables_globals = {
        .option_offset          = 0,
        .program_version        = PACKAGE_VERSION " (nf_tables)",
-       .optstring              = OPTSTRING_COMMON "hv",
        .orig_opts              = ebt_original_options,
        .compat_rev             = nft_compatible_revision,
 };
@@ -734,7 +733,7 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
        opterr = false;
 
        /* Getopt saves the day */
-       while ((c = getopt_long(argc, argv, xt_params->optstring,
+       while ((c = getopt_long(argc, argv, EBT_OPTSTRING,
                                        opts, NULL)) != -1) {
                cs.c = c;
                switch (c) {
index 41b6eb483873317e0fb84103a516c60ed6f32a5c..70924176df8c19a7c0baebf0d896c303a44ca5b2 100644 (file)
@@ -88,7 +88,6 @@ static struct option original_opts[] = {
 struct xtables_globals xtables_globals = {
        .option_offset = 0,
        .program_version = PACKAGE_VERSION " (nf_tables)",
-       .optstring = OPTSTRING_COMMON "R:S::W::" "46bfg:h::m:nvw::x",
        .orig_opts = original_opts,
        .compat_rev = nft_compatible_revision,
 };