Partially revert "rule, set_elem: remove trailing \n in userdata snprintf"
Phil Sutter
reviewerPATCH 1/1 Partially revert "rule, set_elem: remove trailing \n in userdata snprintf"
This reverts the rule-facing part of commitc759027a526ac09ce413dc88c308a4ed98b33416.
It can't be right: Rules without userdata are printed with a trailing newline, so this commit made behaviour inconsistent.
--- src/rule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/rule.c +1 -1
@@ -601,7 +601,7 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,SNPRINTF_BUFFER_SIZE (ret, remain, offset); } - ret =snprintf (buf + offset, remain," }" ); + ret =snprintf (buf + offset, remain," }\n" );SNPRINTF_BUFFER_SIZE (ret, remain, offset); }
Signature · 1 line
2.43.0
Pablo Neira Ayuso
maintainerQuoted 5 lines · Phil Sutter
This reverts the rule-facing part of commit
c759027a526ac09ce413dc88c308a4ed98b33416.It can't be right: Rules without userdata are printed with a trailing newline, so this commit made behaviour inconsistent.
Did you run tests/py with this? It is the primary user for this.
Quoted 22 lines
Fixes c759027a526ac ("rule, set_elem: remove trailing \n in userdata snprintf")Signed-off-by Phil Sutter <[email protected]>--- src/rule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/rule.c +1
-1@@ -601,7 +601,7 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,SNPRINTF_BUFFER_SIZE (ret, remain, offset); } - ret =snprintf (buf + offset, remain," }" ); + ret =snprintf (buf + offset, remain," }\n" );SNPRINTF_BUFFER_SIZE (ret, remain, offset); }Signature · 1 line
2.43.0
Phil Sutter
reviewerHi Pablo,
Quoted 8 lines · Pablo Neira Ayuso
Quoted 5 lines · Phil Sutter
This reverts the rule-facing part of commit
c759027a526ac09ce413dc88c308a4ed98b33416.It can't be right: Rules without userdata are printed with a trailing newline, so this commit made behaviour inconsistent.
Did you run tests/py with this? It is the primary user for this.
It doesn't cover this because there's no test containing a rule with a comment. I just added a respective test, but only to notice it does not matter because nft-test.py compares rules' payload individually per-rule and thus does not care whether output has a trailing newline or not.
I noticed it when testing the iptables compat ext stuff. You can easily reproduce it like so:
| # nft --check --debug=netlink 'table t { chain c { accept comment mycomment; accept; accept;};}'
| ip (null) (null) use 0
| ip t c
| [ immediate reg 0 accept ]
| userdata = { \x00\x0amycomment\x00 }
| ip t c
| [ immediate reg 0 accept ]
|
| ip t c
| [ immediate reg 0 accept ]Note the missing empty line after the first rule.
Cheers, Phil
Pablo Neira Ayuso
maintainerQuoted 31 lines · Phil Sutter
Hi Pablo,
Quoted 8 lines · Pablo Neira Ayuso
Quoted 5 lines · Phil Sutter
This reverts the rule-facing part of commit
c759027a526ac09ce413dc88c308a4ed98b33416.It can't be right: Rules without userdata are printed with a trailing newline, so this commit made behaviour inconsistent.
Did you run tests/py with this? It is the primary user for this.
It doesn't cover this because there's no test containing a rule with a comment. I just added a respective test, but only to notice it does not matter because
nft-test.pycompares rules' payload individually per-rule and thus does not care whether output has a trailing newline or not.I noticed it when testing the iptables compat ext stuff. You can easily reproduce it like so:
| # nft --check --debug=netlink 'table t { chain c { accept comment mycomment; accept; accept;};}' | ip (null) (null) use 0 | ip t c | [ immediate reg 0 accept ] | userdata = { \x00\x0amycomment\x00 } | ip t c | [ immediate reg 0 accept ] | | ip t c | [ immediate reg 0 accept ]
Quoted 1 line
Note the missing empty line after the first rule.
None of the existing libnftnl _snprintf functions terminate string with line break, right?. I mean, for consistency with other existing _snprintf functions. Maybe fix nft instead?
Phil Sutter
reviewerQuoted 32 lines · Pablo Neira Ayuso
Quoted 31 lines · Phil Sutter
Hi Pablo,
Quoted 8 lines · Pablo Neira Ayuso
Quoted 5 lines · Phil Sutter
This reverts the rule-facing part of commit
c759027a526ac09ce413dc88c308a4ed98b33416.It can't be right: Rules without userdata are printed with a trailing newline, so this commit made behaviour inconsistent.
Did you run tests/py with this? It is the primary user for this.
It doesn't cover this because there's no test containing a rule with a comment. I just added a respective test, but only to notice it does not matter because
nft-test.pycompares rules' payload individually per-rule and thus does not care whether output has a trailing newline or not.I noticed it when testing the iptables compat ext stuff. You can easily reproduce it like so:
| # nft --check --debug=netlink 'table t { chain c { accept comment mycomment; accept; accept;};}' | ip (null) (null) use 0 | ip t c | [ immediate reg 0 accept ] | userdata = { \x00\x0amycomment\x00 } | ip t c | [ immediate reg 0 accept ] | | ip t c | [ immediate reg 0 accept ]
Quoted 5 lines
Quoted 1 line
Note the missing empty line after the first rule.
None of the existing libnftnl
_snprintffunctions terminate string with line break, right?. I mean, for consistency with other existing_snprintffunctions. Maybe fix nft instead?
Correct, though others don't emit newlines at all. I'll change rule debug output to never append a newline and see what breaks.
Thanks, Phil