summaryrefslogtreecommitdiffstats
path: root/iptables/xtables-restore.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-05-05 20:04:41 +0200
committerPhil Sutter <phil@nwl.cc>2023-08-11 15:56:38 +0200
commit11c464ed015b52a28d90c63c69e10e5f7d4053d4 (patch)
tree5c2d3bd5a627720284e609dd966ff94246847ac8 /iptables/xtables-restore.c
parentca709b5784c982de12d6eab361cfc9c900aec4c7 (diff)
Add --compat option to *tables-nft and *-nft-restore commands
The flag sets nft_handle::compat boolean, indicating a compatible rule implementation is wanted. Users expecting their created rules to be fetched from kernel by an older version of *tables-nft may use this to avoid potential compatibility issues. Changes since v1: - Expect short option '-C' in {ip,ip6,eb}tables-nft-restore command line parser - Support -C/--compat in arptables-nft-restore, too - Update man pages with the new flag Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/xtables-restore.c')
-rw-r--r--iptables/xtables-restore.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
index 23cd3498..bd8c6bc1 100644
--- a/iptables/xtables-restore.c
+++ b/iptables/xtables-restore.c
@@ -26,6 +26,7 @@ static int counters, verbose;
/* Keeping track of external matches and targets. */
static const struct option options[] = {
{.name = "counters", .has_arg = false, .val = 'c'},
+ {.name = "compat", .has_arg = false, .val = 'C'},
{.name = "verbose", .has_arg = false, .val = 'v'},
{.name = "version", .has_arg = 0, .val = 'V'},
{.name = "test", .has_arg = false, .val = 't'},
@@ -45,8 +46,9 @@ static const struct option options[] = {
static void print_usage(const char *name, const char *version)
{
- fprintf(stderr, "Usage: %s [-c] [-v] [-V] [-t] [-h] [-n] [-T table] [-M command] [-4] [-6] [file]\n"
+ fprintf(stderr, "Usage: %s [-c] [-C] [-v] [-V] [-t] [-h] [-n] [-T table] [-M command] [-4] [-6] [file]\n"
" [ --counters ]\n"
+ " [ --compat ]\n"
" [ --verbose ]\n"
" [ --version]\n"
" [ --test ]\n"
@@ -289,6 +291,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
.cb = &restore_cb,
};
bool noflush = false;
+ bool compat = false;
struct nft_handle h;
int c;
@@ -303,7 +306,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
exit(1);
}
- while ((c = getopt_long(argc, argv, "bcvVthnM:T:wW", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "bcCvVthnM:T:wW", options, NULL)) != -1) {
switch (c) {
case 'b':
fprintf(stderr, "-b/--binary option is not implemented\n");
@@ -311,6 +314,9 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
case 'c':
counters = 1;
break;
+ case 'C':
+ compat = true;
+ break;
case 'v':
verbose++;
break;
@@ -387,6 +393,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
}
h.noflush = noflush;
h.restore = true;
+ h.compat = compat;
xtables_restore_parse(&h, &p);
@@ -417,6 +424,7 @@ static const struct nft_xt_restore_cb ebt_restore_cb = {
};
static const struct option ebt_restore_options[] = {
+ {.name = "compat", .has_arg = 0, .val = 'C'},
{.name = "noflush", .has_arg = 0, .val = 'n'},
{.name = "verbose", .has_arg = 0, .val = 'v'},
{ 0 }
@@ -429,12 +437,16 @@ int xtables_eb_restore_main(int argc, char *argv[])
.cb = &ebt_restore_cb,
};
bool noflush = false;
+ bool compat = false;
struct nft_handle h;
int c;
- while ((c = getopt_long(argc, argv, "nv",
+ while ((c = getopt_long(argc, argv, "Cnv",
ebt_restore_options, NULL)) != -1) {
switch(c) {
+ case 'C':
+ compat = true;
+ break;
case 'n':
noflush = 1;
break;
@@ -443,7 +455,7 @@ int xtables_eb_restore_main(int argc, char *argv[])
break;
default:
fprintf(stderr,
- "Usage: ebtables-restore [ --verbose ] [ --noflush ]\n");
+ "Usage: ebtables-restore [ --compat ] [ --verbose ] [ --noflush ]\n");
exit(1);
break;
}
@@ -451,6 +463,7 @@ int xtables_eb_restore_main(int argc, char *argv[])
nft_init_eb(&h, "ebtables-restore");
h.noflush = noflush;
+ h.compat = compat;
xtables_restore_parse(&h, &p);
nft_fini_eb(&h);
@@ -465,15 +478,37 @@ static const struct nft_xt_restore_cb arp_restore_cb = {
.chain_restore = nft_cmd_chain_restore,
};
+static const struct option arp_restore_options[] = {
+ {.name = "compat", .has_arg = 0, .val = 'C'},
+ { 0 }
+};
+
int xtables_arp_restore_main(int argc, char *argv[])
{
struct nft_xt_restore_parse p = {
.in = stdin,
.cb = &arp_restore_cb,
};
+ bool compat = false;
struct nft_handle h;
+ int c;
+
+ while ((c = getopt_long(argc, argv, "C",
+ arp_restore_options, NULL)) != -1) {
+ switch(c) {
+ case 'C':
+ compat = true;
+ break;
+ default:
+ fprintf(stderr,
+ "Usage: arptables-restore [ --compat ]\n");
+ exit(1);
+ break;
+ }
+ }
nft_init_arp(&h, "arptables-restore");
+ h.compat = compat;
xtables_restore_parse(&h, &p);
nft_fini(&h);
xtables_fini();