diff options
author | Phil Sutter <phil@nwl.cc> | 2021-09-27 16:59:49 +0200 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2021-10-20 11:32:54 +0200 |
commit | ab0a785a72a6be0d4a37e3492069a8719418cfbc (patch) | |
tree | 26641d332425a0bd39605e8400c8d6a614b6f354 /iptables/xtables-standalone.c | |
parent | 6cf3976ef7f06b3892a111a3c187c6ca37dbc19e (diff) |
xtables: Derive xtables_globals from family
Prepare xtables_main() for use with other families than IPV4 or IPV6
which both use the same xtables_globals object. Therefore introduce a
function to map from family value to xtables_globals object pointer.
In do_parse(), use xt_params pointer as well instead of direct
reference.
While being at it, Declare arptables_globals and ebtables_globals in
xtables_multi.h which seems to be the proper place for that.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/xtables-standalone.c')
-rw-r--r-- | iptables/xtables-standalone.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/iptables/xtables-standalone.c b/iptables/xtables-standalone.c index 54c70c54..19d663b0 100644 --- a/iptables/xtables-standalone.c +++ b/iptables/xtables-standalone.c @@ -39,19 +39,34 @@ #include "xtables-multi.h" #include "nft.h" +static struct xtables_globals *xtables_globals_lookup(int family) +{ + switch (family) { + case AF_INET: + case AF_INET6: + return &xtables_globals; + case NFPROTO_ARP: + return &arptables_globals; + case NFPROTO_BRIDGE: + return &ebtables_globals; + default: + xtables_error(OTHER_PROBLEM, "Unknown family value %d", family); + } +} + static int xtables_main(int family, const char *progname, int argc, char *argv[]) { - int ret; char *table = "filter"; struct nft_handle h; + int ret; - xtables_globals.program_name = progname; - ret = xtables_init_all(&xtables_globals, family); + ret = xtables_init_all(xtables_globals_lookup(family), family); if (ret < 0) { fprintf(stderr, "%s: Failed to initialize xtables\n", progname); exit(1); } + xt_params->program_name = progname; #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS) init_extensions(); init_extensions4(); @@ -60,7 +75,7 @@ xtables_main(int family, const char *progname, int argc, char *argv[]) if (nft_init(&h, family) < 0) { fprintf(stderr, "%s: Failed to initialize nft: %s\n", - xtables_globals.program_name, strerror(errno)); + xt_params->program_name, strerror(errno)); exit(EXIT_FAILURE); } |