xshared: restore legal options for combined `-L -Z` commands
PATCH 1/1 xshared: restore legal options for combined `-L -Z` commands
Prior to commit 9c09d28102bb ("xshared: Simplify generic_opt_check()"), if multiple commands were given, options which were legal for any of the commands were considered legal for all of them. This allowed one to do things like:
# iptables -n -L Z chain
Commit 9c09d28102bb did away with this behaviour. Restore it for the specific combination of -L and -Z.
--- iptables/xshared.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
iptables/xshared.c +3 -3
@@ -943,16 +943,16 @@ static void parse_rule_range(struct xt_cmd_parse *p, const char *argv)#define CMD_IDRAC CMD_INSERT | CMD_DELETE | CMD_REPLACE | \ CMD_APPEND | CMD_CHECK | CMD_CHANGE_COUNTERSstatic const unsigned int options_v_commands[NUMBER_OF_OPT ] = { -/*OPT_NUMERIC*/ CMD_LIST , +/*OPT_NUMERIC*/ CMD_LIST |CMD_ZERO ,/*OPT_SOURCE*/ CMD_IDRAC ,/*OPT_DESTINATION*/ CMD_IDRAC ,/*OPT_PROTOCOL*/ CMD_IDRAC ,/*OPT_JUMP*/ CMD_IDRAC ,/*OPT_VERBOSE*/ UINT_MAX , -/*OPT_EXPANDED*/ CMD_LIST , +/*OPT_EXPANDED*/ CMD_LIST |CMD_ZERO ,/*OPT_VIANAMEIN*/ CMD_IDRAC ,/*OPT_VIANAMEOUT*/ CMD_IDRAC , -/*OPT_LINENUMBERS*/ CMD_LIST , +/*OPT_LINENUMBERS*/ CMD_LIST |CMD_ZERO ,/*OPT_COUNTERS*/ CMD_INSERT |CMD_REPLACE |CMD_APPEND |CMD_SET_POLICY ,/*OPT_FRAGMENT*/ CMD_IDRAC ,/*OPT_S_MAC*/ CMD_IDRAC ,
Signature · 1 line
2.51.0
Quoted 5 lines · Jeremy Sowden
Prior to commit
9c09d28102bb("xshared: Simplifygeneric_opt_check()"), if multiple commands were given, options which were legal for any of the commands were considered legal for all of them. This allowed one to do things like:# iptables -n -L Z chain
# iptables -n -L -Z chain
Quoted 37 lines
Commit
9c09d28102bbdid away with this behaviour. Restore it for the specific combination of-Land-Z.Fixes 9c09d28102bb ("xshared: Simplify generic_opt_check()")Signed-off-by Jeremy Sowden <[email protected]>--- iptables/xshared.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)iptables/xshared.c +3
-4@@ -943,16 +943,16 @@ static void parse_rule_range(struct xt_cmd_parse *p, const char *argv)#define CMD_IDRAC CMD_INSERT | CMD_DELETE | CMD_REPLACE | \ CMD_APPEND | CMD_CHECK | CMD_CHANGE_COUNTERSstatic const unsigned int options_v_commands[NUMBER_OF_OPT ] = { -/*OPT_NUMERIC*/ CMD_LIST , +/*OPT_NUMERIC*/ CMD_LIST |CMD_ZERO ,/*OPT_SOURCE*/ CMD_IDRAC ,/*OPT_DESTINATION*/ CMD_IDRAC ,/*OPT_PROTOCOL*/ CMD_IDRAC ,/*OPT_JUMP*/ CMD_IDRAC ,/*OPT_VERBOSE*/ UINT_MAX , -/*OPT_EXPANDED*/ CMD_LIST , +/*OPT_EXPANDED*/ CMD_LIST |CMD_ZERO ,/*OPT_VIANAMEIN*/ CMD_IDRAC ,/*OPT_VIANAMEOUT*/ CMD_IDRAC , -/*OPT_LINENUMBERS*/ CMD_LIST , +/*OPT_LINENUMBERS*/ CMD_LIST |CMD_ZERO ,/*OPT_COUNTERS*/ CMD_INSERT |CMD_REPLACE |CMD_APPEND |CMD_SET_POLICY ,/*OPT_FRAGMENT*/ CMD_IDRAC ,/*OPT_S_MAC*/ CMD_IDRAC , --2.51.0
Florian Westphal
maintainerQuoted 8 lines · Jeremy Sowden
Quoted 5 lines · Jeremy Sowden
Prior to commit
9c09d28102bb("xshared: Simplifygeneric_opt_check()"), if multiple commands were given, options which were legal for any of the commands were considered legal for all of them. This allowed one to do things like:# iptables -n -L Z chain# iptables -n -L -Z chain
Whats wrong with it?
This failed before192c3a6bc18f ("xshared: Accept an option if any given command allows it"), yes.
Is it still broken? If yes, what isn't working?
Quoted 6 lines · Florian Westphal
Quoted 5 lines · Jeremy Sowden
Quoted 3 lines · Jeremy Sowden
Prior to commit
9c09d28102bb("xshared: Simplifygeneric_opt_check()"), if multiple commands were given, options which were legal for any of the commands were considered legal for all of them. This allowed one to do things like:
Quoted 8 lines
Quoted 1 line
# iptables -n -L -Z chainWhats wrong with it?
This failed before
192c3a6bc18f("xshared: Accept an option if any given command allows it"), yes.Is it still broken? If yes, what isn't working?
The iptables man-page description of the -L command includes the following:
Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups. It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atomically listed and zeroed.
This works as expected in 1.8.10:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft --version iptables v1.8.10 (nf_tables) $ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT # Warning: iptables-legacy tables present, use iptables-legacy to see them Chain INPUT (policy ACCEPT) target prot opt source destination LIBVIRT_INP 0 -- 0.0.0.0/0 0.0.0.0/0
However, it does not work in 1.8.11:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT iptables v1.8.11 (nf_tables): Illegal option `--numeric' with this command Try `iptables -h' or 'iptables --help' for more information.
In the old option-checking code, replaced in 9c09d28102bb, if multiple commands are given, once an option is marked as legal in combination with a command, it retains that status even if it would not otherwise be legal with a later command (v1.8.10, xshared.c, ll. 927 ff.):
/* Table of legal combinations of commands and options. If any of the
* given commands make an option legal, that option is legal (applies to
* CMD_LIST and CMD_ZERO only).
The new code, however, makes no such allowance (v1.8.11, xshared.c, ll. 945 ff.):
static const unsigned int options_v_commands[NUMBER_OF_OPT] = {
/*OPT_NUMERIC*/ CMD_LIST,
...
/*OPT_EXPANDED*/ CMD_LIST,
...
/*OPT_LINENUMBERS*/ CMD_LIST,
...
};My proposed fix is just to add CMD_ZERO to these entries. It's more permissive than before, in as much as it allows -n &c. to be combined with -Z on its own, but they will be ignored.
J.
Florian Westphal
maintainerQuoted 34 lines · Jeremy Sowden
Quoted 6 lines · Florian Westphal
Quoted 5 lines · Jeremy Sowden
Quoted 3 lines · Jeremy Sowden
Prior to commit
9c09d28102bb("xshared: Simplifygeneric_opt_check()"), if multiple commands were given, options which were legal for any of the commands were considered legal for all of them. This allowed one to do things like:Quoted 8 lines
Quoted 1 line
# iptables -n -L -Z chainWhats wrong with it?
This failed before
192c3a6bc18f("xshared: Accept an option if any given command allows it"), yes.Is it still broken? If yes, what isn't working?
The iptables man-page description of the
-Lcommand includes the following:Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups. It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atomically listed and zeroed.
This works as expected in 1.8.10:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft --version iptables v1.8.10 (nf_tables) $ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT # Warning: iptables-legacy tables present, use iptables-legacy to see them Chain INPUT (policy ACCEPT) target prot opt source destination LIBVIRT_INP 0 -- 0.0.0.0/0 0.0.0.0/0
Quoted 5 lines
However, it does not work in 1.8.11:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT iptables v1.8.11 (nf_tables): Illegal option `--numeric' with this command Try `iptables -h' or 'iptables --help' for more information.
But this works in git :-/
So again, what exactly is broken? AFAICS everything works as expected:
iptables/xtables-nft-multi iptables -n -L -v -Z foo Chain foo (1 references)
pkts bytes target prot opt in out source destination
1 36 all -- * * 0.0.0.0/0 0.0.0.0/0
Zeroing chain `foo'
iptables/xtables-nft-multi iptables -n -L -v -Z foo
Chain foo (1 references)
pkts bytes target prot opt in out source destination
0 0 all -- * * 0.0.0.0/0 0.0.0.0/0Zeroing chain `foo'
Quoted 47 lines · Florian Westphal
Quoted 34 lines · Jeremy Sowden
Quoted 6 lines · Florian Westphal
Quoted 5 lines · Jeremy Sowden
Quoted 3 lines · Jeremy Sowden
Prior to commit
9c09d28102bb("xshared: Simplifygeneric_opt_check()"), if multiple commands were given, options which were legal for any of the commands were considered legal for all of them. This allowed one to do things like:Quoted 8 lines
Quoted 1 line
# iptables -n -L -Z chainWhats wrong with it?
This failed before
192c3a6bc18f("xshared: Accept an option if any given command allows it"), yes.Is it still broken? If yes, what isn't working?
The iptables man-page description of the
-Lcommand includes the following:Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups. It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atomically listed and zeroed.
This works as expected in 1.8.10:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft --version iptables v1.8.10 (nf_tables) $ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT # Warning: iptables-legacy tables present, use iptables-legacy to see them Chain INPUT (policy ACCEPT) target prot opt source destination LIBVIRT_INP 0 -- 0.0.0.0/0 0.0.0.0/0Quoted 5 lines
However, it does not work in 1.8.11:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT iptables v1.8.11 (nf_tables): Illegal option `--numeric' with this command Try `iptables -h' or 'iptables --help' for more information.But this works in git :-/
So again, what exactly is broken? AFAICS everything works as expected:
iptables/xtables-nft-multi iptables -n -L -v -Z foo Chain foo (1 references)
Quoted 8 lines
pkts bytes target prot opt in out source destination 1 36 all -- * * 0.0.0.0/0 0.0.0.0/0 Zeroing chain `foo' iptables/xtables-nft-multi iptables -n -L -v -Z foo Chain foo (1 references) pkts bytes target prot opt in out source destination 0 0 all -- * * 0.0.0.0/0 0.0.0.0/0Zeroing chain `foo'
Damn it. You're right. Obviously, it's already been fixed. Apologies. Been rather unwell this week and clearly I'm still somewhat dim-witted.
Thanks, Florian.
J.
Phil Sutter
reviewerHi,
Quoted 57 lines · Jeremy Sowden
Quoted 47 lines · Florian Westphal
Quoted 34 lines · Jeremy Sowden
Quoted 6 lines · Florian Westphal
Quoted 5 lines · Jeremy Sowden
Quoted 3 lines · Jeremy Sowden
Prior to commit
9c09d28102bb("xshared: Simplifygeneric_opt_check()"), if multiple commands were given, options which were legal for any of the commands were considered legal for all of them. This allowed one to do things like:Quoted 8 lines
Quoted 1 line
# iptables -n -L -Z chainWhats wrong with it?
This failed before
192c3a6bc18f("xshared: Accept an option if any given command allows it"), yes.Is it still broken? If yes, what isn't working?
The iptables man-page description of the
-Lcommand includes the following:Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups. It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atomically listed and zeroed.
This works as expected in 1.8.10:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft --version iptables v1.8.10 (nf_tables) $ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT # Warning: iptables-legacy tables present, use iptables-legacy to see them Chain INPUT (policy ACCEPT) target prot opt source destination LIBVIRT_INP 0 -- 0.0.0.0/0 0.0.0.0/0Quoted 5 lines
However, it does not work in 1.8.11:
$ schroot -r -c iptables-sid -u root -- /usr/local/sbin/iptables-nft -n -L -Z INPUT iptables v1.8.11 (nf_tables): Illegal option `--numeric' with this command Try `iptables -h' or 'iptables --help' for more information.But this works in git :-/
So again, what exactly is broken? AFAICS everything works as expected:
iptables/xtables-nft-multi iptables -n -L -v -Z foo Chain foo (1 references)
Quoted 8 lines
pkts bytes target prot opt in out source destination 1 36 all -- * * 0.0.0.0/0 0.0.0.0/0 Zeroing chain `foo' iptables/xtables-nft-multi iptables -n -L -v -Z foo Chain foo (1 references) pkts bytes target prot opt in out source destination 0 0 all -- * * 0.0.0.0/0 0.0.0.0/0Zeroing chain `foo'
Quoted 2 lines
Damn it. You're right. Obviously, it's already been fixed. Apologies. Been rather unwell this week and clearly I'm still somewhat dim-witted.
Yes, it is fixed by commit 192c3a6bc18f2 ("xshared: Accept an option if any given command allows it"). Reminds me that we should release v1.8.12, v1.8.11 is already a year old. There are only 21 commits on top in HEAD, but I see six Fixes: tags in there.
Cheers, Phil