Misc fixes (more or less)
Phil Sutter
reviewercover Misc fixes (more or less)
This is early fallout from working on a merge of ebtables commandline parsers with the shared one. It is a mix of actual bug fixes, small improvements and an implementaion of --change-counters command for ebtables-nft.
Phil Sutter (12):
Makefile: Install arptables-translate link and man page
nft-bridge: nft_bridge_add() uses wrong flags
xshared: struct xt_cmd_parse::xlate is unused
xshared: All variants support -v, update OPTSTRING_COMMON
xshared: Drop needless assignment in --help case
xshared: Drop pointless CMD_REPLACE check
tests: xlate: Print failing command line
ebtables: Drop append_entry() wrapper
ebtables: Make ebt_load_match_extensions() static
ebtables: Align line number formatting with legacy
xshared: do_parse: Ignore '-j CONTINUE'
ebtables: Implement --change-counters command
iptables/Makefile.am | 11 +- iptables/nft-bridge.c | 6 +- iptables/nft-bridge.h | 1 - iptables/nft-cmd.c | 20 ++++ iptables/nft-cmd.h | 12 +++ iptables/nft.c | 65 +++++++++++ iptables/nft.h | 1 + .../testcases/ebtables/0010-change-counters_0 | 45 ++++++++ iptables/xshared.c | 11 +- iptables/xshared.h | 9 +- iptables/xtables-eb.c | 102 ++++++++++-------- iptables/xtables-translate.8 | 12 ++- iptables/xtables-translate.c | 1 - xlate-test.py | 5 +- 14 files changed, 229 insertions(+), 72 deletions(-) create mode 100755 iptables/tests/shell/testcases/ebtables/0010-change-counters_0
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 1/12 Makefile: Install arptables-translate link and man page
While at it, introduce a variable to hold the various semantic links to xtables-translate.8 man page.
--- iptables/Makefile.am | 11 +++++++---- iptables/xtables-translate.8 | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-)
iptables/Makefile.am +7 -4
@@ -69,10 +69,12 @@ man_MANS = iptables.8 iptables-restore.8 iptables-save.8 \ dist_sbin_SCRIPTS = iptables-apply dist_pkgdata_DATA = iptables.xslt +xlate_man_links = iptables-translate.8 ip6tables-translate.8 \ + iptables-restore-translate.8 ip6tables-restore-translate.8 \ + ebtables-translate.8 arptables-translate.8 + if ENABLE_NFTABLES -man_MANS += iptables-translate.8 ip6tables-translate.8 \ - iptables-restore-translate.8 ip6tables-restore-translate.8 \ - xtables-monitor.8 ebtables-translate.8 +man_MANS += ${xlate_man_links} xtables-monitor.8 dist_man_MANS = xtables-nft.8 xtables-translate.8 xtables-legacy.8 \ arptables-nft.8 arptables-nft-restore.8 arptables-nft-save.8 \
@@ -97,6 +99,7 @@ x_sbin_links = iptables-nft iptables-nft-restore iptables-nft-save \ arptables-nft arptables \ arptables-nft-restore arptables-restore \ arptables-nft-save arptables-save \ + arptables-translate \ ebtables-nft ebtables \ ebtables-nft-restore ebtables-restore \ ebtables-nft-save ebtables-save \
@@ -108,7 +111,7 @@ iptables-extensions.8: iptables-extensions.8.tmpl ../extensions/matches.man ../e -e '/@MATCH@/ r ../extensions/matches.man' \ -e '/@TARGET@/ r ../extensions/targets.man' $< >$@; -iptables-translate.8 ip6tables-translate.8 iptables-restore-translate.8 ip6tables-restore-translate.8 ebtables-translate.8: +${xlate_man_links}: ${AM_VERBOSE_GEN} echo '.so man8/xtables-translate.8' >$@ ip6tables.8 ip6tables-apply.8 ip6tables-restore.8 ip6tables-save.8:
iptables/xtables-translate.8 +8 -4
@@ -30,10 +30,12 @@ iptables-translate \(em translation tool to migrate from iptables to nftables ip6tables-translate \(em translation tool to migrate from ip6tables to nftables .P ebtables-translate \(em translation tool to migrate from ebtables to nftables +.P +arptables-translate \(em translation tool to migrate from arptables to nftables .SH DESCRIPTION There is a set of tools to help the system administrator translate a given -ruleset from \fBiptables(8)\fP, \fBip6tables(8)\fP and \fBebtables(8)\fP to -\fBnftables(8)\fP. +ruleset from \fBiptables(8)\fP, \fBip6tables(8)\fP, \fBebtables(8)\fP and +\fBarptables(8)\fP to \fBnftables(8)\fP. The available commands are:
@@ -47,11 +49,13 @@ ip6tables\-translate ip6tables\-restore\-translate .IP \[bu] 2 ebtables\-translate +.IP \[bu] 2 +arptables\-translate .SH USAGE They take as input the original -\fBiptables(8)\fP/\fBip6tables(8)\fP/\fBebtables(8)\fP syntax and -output the native \fBnftables(8)\fP syntax. +\fBiptables(8)\fP/\fBip6tables(8)\fP/\fBebtables(8)\fP/\fBarptables(8)\fP +syntax and output the native \fBnftables(8)\fP syntax. The \fBiptables-restore-translate\fP tool reads a ruleset in the syntax produced by \fBiptables-save(8)\fP. Likewise, the
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 2/12 nft-bridge: nft_bridge_add() uses wrong flags
In reply to Phil SutterWhen checking whether -s or -d was given, invflags were used by accident. This change has no functional effect since the values remain the same, but this way it's clear where the previously assigned flags are used.
--- iptables/nft-bridge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
iptables/nft-bridge.c +2 -2
@@ -134,14 +134,14 @@ static int nft_bridge_add(struct nft_handle *h, struct nft_rule_ctx *ctx,struct ebt_entry *fw = &cs->eb;uint32_t op; -if (fw->bitmask &EBT_ISOURCE ) { +if (fw->bitmask &EBT_SOURCEMAC ) { op =nft_invflags2cmp (fw->invflags,EBT_ISOURCE );add_addr (h, r,NFT_PAYLOAD_LL_HEADER , offsetof(struct ethhdr , h_source), fw->sourcemac, fw->sourcemsk,ETH_ALEN , op); } -if (fw->bitmask &EBT_IDEST ) { +if (fw->bitmask &EBT_DESTMAC ) { op =nft_invflags2cmp (fw->invflags,EBT_IDEST ); add_addr(h, r, NFT_PAYLOAD_LL_HEADER, offsetof(struct ethhdr, h_dest),
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 3/12 xshared: struct xt_cmd_parse::xlate is unused
In reply to Phil SutterDrop the boolean, it was meant to disable some existence checks in do_parse() prior to the caching rework. Now that do_parse() runs before any caching is done, the checks in question don't exist anymore so drop this relict.
--- iptables/xshared.h | 1 - iptables/xtables-translate.c | 1 - 2 files changed, 2 deletions(-)
iptables/xshared.h +0 -1
@@ -284,7 +284,6 @@ struct xt_cmd_parse {bool restore;int line;int verbose; -bool xlate;struct xt_cmd_parse_ops *ops; };
iptables/xtables-translate.c +0 -1
@@ -259,7 +259,6 @@ static int do_command_xlate(struct nft_handle *h, int argc, char *argv[], .table = *table, .restore = restore, .line = line, - .xlate = true, .ops = &h->ops->cmd_parse, };struct iptables_command_state cs = {
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 4/12 xshared: All variants support -v
In reply to Phil SutterUpdate OPTSTRING_COMMON and remove the flag from *_OPTSTRING defines.
--- iptables/xshared.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
iptables/xshared.h +4 -4
@@ -75,10 +75,10 @@ struct xtables_globals;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:nvx"/* "m:" */ -#define EBT_OPTSTRING OPTSTRING_COMMON "hv" +#define OPTSTRING_COMMON "-:A:C:D:E:F::I:L::M:N:P:VX::Z::" "c:d:i:j:o:p:s:t:v" +#define IPT_OPTSTRING OPTSTRING_COMMON "R:S::W::" "46bfg:h::m:nw::x" +#define ARPT_OPTSTRING OPTSTRING_COMMON "R:S::" "h::l:nx"/* "m:" */ +#define EBT_OPTSTRING OPTSTRING_COMMON "h"/* define invflags which won't collide with IPT ones. * arptables-nft does NOT use the legacy ARPT_INV_* defines.
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 5/12 xshared: Drop needless assignment in --help case
In reply to Phil SutterHelp text printing code does not refer to optarg, so there is no need to assign to it if unset.
--- iptables/xshared.c | 3 --- 1 file changed, 3 deletions(-)
iptables/xshared.c +0 -3
@@ -1527,9 +1527,6 @@ void do_parse(int argc, char *argv[],break ;case 'h' : -if (!optarg) - optarg = argv[optind]; -/* iptables -p icmp -h */ if (!cs->matches && cs->protocol) xtables_find_match(cs->protocol,
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 6/12 xshared: Drop pointless CMD_REPLACE check
In reply to Phil SutterAll current users set default source and destination addresses in their post_parse callbacks, so legacy variants are safe and nft variants don't have this restriction anyway.
--- iptables/xshared.c | 5 ----- 1 file changed, 5 deletions(-)
iptables/xshared.c +0 -5
@@ -1836,11 +1836,6 @@ void do_parse(int argc, char *argv[],if (p->ops->post_parse) p->ops->post_parse (p->command, cs, args); -if (p->command ==CMD_REPLACE && - (args->s.naddrs !=1 || args->d.naddrs !=1 )) -xtables_error (PARAMETER_PROBLEM ,"Replacement rule does not " -"specify a unique address" ); -generic_opt_check (p->command, cs->options);if (p->chain !=NULL &&strlen (p->chain) >=XT_EXTENSION_MAXNAMELEN )
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 7/12 tests: xlate: Print failing command line
In reply to Phil SutterIf the command segfaults, 'error' variable is empty and the resulting error message is even misleading as the called program may not have been iptables-translate.
--- xlate-test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xlate-test.py +3 -2
@@ -41,9 +41,10 @@ xtables_nft_multi = 'xtables-nft-multi' def test_one_xlate(name, sourceline, expected, result): - rc, output, error = run_proc([xtables_nft_multi] + shlex.split(sourceline)) + cmd = [xtables_nft_multi] + shlex.split(sourceline) + rc, output, error = run_proc(cmd) if rc != 0: - result.append(name + ": " + red("Error: ") + "iptables-translate failure") + result.append(name + ": " + red("Error: ") + "Call failed: " + " ".join(cmd)) result.append(error) return False
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 8/12 ebtables: Drop append_entry() wrapper
In reply to Phil SutterThere is no point in having it when there is no code to share.
--- iptables/xtables-eb.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
iptables/xtables-eb.c +4 -22
@@ -112,24 +112,6 @@ static int parse_rule_number(const char *rule)return rule_nr; } -static int -append_entry (struct nft_handle *h, -const char *chain, -const char *table, -struct iptables_command_state *cs, -int rule_nr, -bool verbose,bool append) -{ -int ret =1 ; - -if (append) - ret =nft_cmd_rule_append (h, chain, table, cs, verbose); -else - ret =nft_cmd_rule_insert (h, chain, table, cs, rule_nr, verbose); - -return ret; -} - static int delete_entry(struct nft_handle *h, const char *chain,
@@ -1178,11 +1160,11 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table, }else if (command =='F' ) { ret =nft_cmd_rule_flush (h, chain, *table, flags &OPT_VERBOSE ); }else if (command =='A' ) { - ret =append_entry (h, chain, *table, &cs,0 , - flags &OPT_VERBOSE , true); + ret =nft_cmd_rule_append (h, chain, *table, &cs, + flags &OPT_VERBOSE ); }else if (command =='I' ) { - ret =append_entry (h, chain, *table, &cs, rule_nr -1 , - flags &OPT_VERBOSE , false); + ret =nft_cmd_rule_insert (h, chain, *table, &cs, + rule_nr -1 , flags &OPT_VERBOSE ); }else if (command =='D' ) { ret =delete_entry (h, chain, *table, &cs, rule_nr -1 , rule_nr_end, flags &OPT_VERBOSE );
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 9/12 ebtables: Make ebt_load_match_extensions() static
In reply to Phil SutterThe function is not used outside of xtables-eb.c.
--- iptables/nft-bridge.h | 1 - iptables/xtables-eb.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
iptables/nft-bridge.h +0 -1
@@ -115,7 +115,6 @@ static inline const char *ebt_target_name(unsigned int verdict) }) \void ebt_cs_clean (struct iptables_command_state *cs); -void ebt_load_match_extensions (void );void ebt_add_match (struct xtables_match *m,struct iptables_command_state *cs); void ebt_add_watcher(struct xtables_target *watcher,
iptables/xtables-eb.c +1 -1
@@ -504,7 +504,7 @@ static void ebt_load_watcher(const char *name)xtables_error (OTHER_PROBLEM ,"Can't alloc memory" ); } -void ebt_load_match_extensions (void ) +static void ebt_load_match_extensions (void ) { opts = ebt_original_options;ebt_load_match ("802_3" );
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 10/12 ebtables: Align line number formatting with legacy
In reply to Phil SutterLegacy ebtables appends a dot to the number printed in first column if --Ln flag was given.
--- iptables/nft-bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
iptables/nft-bridge.c +1 -1
@@ -354,7 +354,7 @@ static void nft_bridge_print_rule(struct nft_handle *h, struct nftnl_rule *r,struct iptables_command_state cs = {};if (format &FMT_LINENUMBERS ) -printf ("%d " , num); +printf ("%d. " , num);nft_rule_to_ebtables_command_state (h, r, &cs);__nft_bridge_save_rule (&cs, format);
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 11/12 xshared: do_parse: Ignore '-j CONTINUE'
In reply to Phil SutterWhile iptables does not support his NOP, arptables man page claims it does (although legacy arptables rejects it) and ebtables prefers to print it instead of omitting the '-j' option.
Accept and ignore the target when parsing to at least fix for arptables-nft and prepare for ebtables-nft using do_parse() as well.
--- iptables/xshared.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
iptables/xshared.c +2 -1
@@ -1634,7 +1634,8 @@ void do_parse(int argc, char *argv[],case 'j' :set_option (&cs->options,OPT_JUMP , &args->invflags, invert); -command_jump (cs, optarg); +if (strcmp (optarg,"CONTINUE" )) +command_jump (cs, optarg);break ;case 'i' :
Signature · 1 line
2.41.0
Phil Sutter
reviewerPATCH 12/12 ebtables: Implement --change-counters command
In reply to Phil SutterTreat it like --replace against the same rule with changed counters. The operation is obviously not atomic, so rule counters may change in kernel while the rule is fetched, modified and replaced.
--- iptables/nft-cmd.c | 20 +++++ iptables/nft-cmd.h | 12 +++ iptables/nft.c | 65 ++++++++++++++++ iptables/nft.h | 1 + .../testcases/ebtables/0010-change-counters_0 | 45 +++++++++++ iptables/xtables-eb.c | 74 ++++++++++++++----- 6 files changed, 197 insertions(+), 20 deletions(-) create mode 100755 iptables/tests/shell/testcases/ebtables/0010-change-counters_0
iptables/nft-cmd.c +20 -0
@@ -400,3 +400,23 @@ int ebt_cmd_user_chain_policy(struct nft_handle *h, const char *table,return 1 ; } + +int nft_cmd_rule_change_counters (struct nft_handle *h, +const char *chain,const char *table, +struct iptables_command_state *cs, +int rule_nr,uint8_t counter_op,bool verbose) +{ +struct nft_cmd *cmd; + + cmd =nft_cmd_new (h,NFT_COMPAT_RULE_CHANGE_COUNTERS , table, chain, + rule_nr ==-1 ? cs :NULL , rule_nr, verbose); +if (!cmd) +return 0 ; + + cmd->counter_op = counter_op; + cmd->counters = cs->counters; + +nft_cache_level_set (h,NFT_CL_RULES , cmd); + +return 1 ; +}
iptables/nft-cmd.h +12 -0
@@ -7,6 +7,13 @@struct nftnl_rule ; +enum { +CTR_OP_INC_PKTS =1 <<0 , +CTR_OP_DEC_PKTS =1 <<1 , +CTR_OP_INC_BYTES =1 <<2 , +CTR_OP_DEC_BYTES =1 <<3 , +}; +struct nft_cmd {struct list_head head;int command;
@@ -22,6 +29,7 @@ struct nft_cmd { } obj;const char *policy;struct xt_counters counters; +uint8_t counter_op;const char *rename;int counters_save;struct {
@@ -77,6 +85,10 @@ int nft_cmd_rule_list_save(struct nft_handle *h, const char *chain, const char *table, int rulenum, int counters);int ebt_cmd_user_chain_policy (struct nft_handle *h,const char *table,const char *chain,const char *policy); +int nft_cmd_rule_change_counters (struct nft_handle *h, +const char *chain,const char *table, +struct iptables_command_state *cs, +int rule_nr,uint8_t counter_op,bool verbose);void nft_cmd_table_new (struct nft_handle *h,const char *table);#endif /* _NFT_CMD_H_ */
iptables/nft.c +65 -0
101 lines not on this page · raw message
iptables/nft.h +1 -0
@@ -72,6 +72,7 @@ enum obj_update_type {NFT_COMPAT_RULE_SAVE ,NFT_COMPAT_RULE_ZERO ,NFT_COMPAT_BRIDGE_USER_CHAIN_UPDATE , + NFT_COMPAT_RULE_CHANGE_COUNTERS, }; struct cache_chain {
iptables/tests/shell/testcases/ebtables/0010-change-counters_0 new file +45 -0
45 lines not on this page · raw message
iptables/xtables-eb.c +54 -20
129 lines not on this page · raw message
Signature · 1 line
2.41.0
Phil Sutter
reviewerQuoted 5 lines · Phil Sutter
This is early fallout from working on a merge of ebtables commandline parsers with the shared one. It is a mix of actual bug fixes, small improvements and an implementaion of --change-counters command for ebtables-nft.
Quoted 13 lines
Phil Sutter (12):
Makefile: Install arptables-translate link and man page
nft-bridge:nft_bridge_add()uses wrong flags
xshared: structxt_cmd_parse::xlateis unused
xshared: All variants support -v, updateOPTSTRING_COMMON
xshared: Drop needless assignment in --help case
xshared: Drop pointlessCMD_REPLACEcheck
tests: xlate: Print failing command line
ebtables: Dropappend_entry()wrapper
ebtables: Makeebt_load_match_extensions()static
ebtables: Align line number formatting with legacy
xshared:do_parse: Ignore '-j CONTINUE'
ebtables: Implement --change-counters command
Series applied.