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>
{
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)));
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,
};
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,
};
}
}
+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)
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) {
/*
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
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,
};
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,
};
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) {
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,
};