Skip to contentSkip to conversation

Fix DEBUG build

PATCH In review Phil Sutter 2 participants 5 messages Dec 4, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/2 Fix DEBUG build

Fixed commit missed to update this conditional call to nft_rule_print_save().

Fixes 1e8ef6a584754 ("nft: family_ops: Pass nft_handle to 'rule_to_cs' callback")
---
 iptables/nft-shared.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
iptables/nft-shared.c +1 -1
index 78e422781723f..426765641cff6 100644
@@ -998,7 +998,7 @@ bool nft_ipv46_rule_find(struct nft_handle *h, struct nftnl_rule *r, void *data)
 
 	DEBUGP("comparing with... ");
 #ifdef DEBUG_DEL
-	nft_rule_print_save(r, NFT_RULE_APPEND, 0);
+	nft_rule_print_save(h, r, NFT_RULE_APPEND, 0);
 #endif
 	if (!h->ops->is_same(cs, &this))
 		goto out;
Signature · 1 line
2.24.0
author reviewer
#1 lore raw

PATCH 2/2 xtables-restore: Fix parser feed from line buffer

When called with --noflush, xtables-restore would trip over chain lines:
Parser uses strtok() to separate chain name, policy and counters which inserts nul-chars into the source string. Therefore strlen() can't be used anymore to find end of line. Fix this by caching line length before calling xtables_restore_parse_line().

Fixes 09cb517949e69 ("xtables-restore: Improve performance of --noflush operation")
---
 .../testcases/ipt-restore/0010-noflush-new-chain_0     | 10 ++++++++++
 iptables/xtables-restore.c                             |  4 +++-
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100755 iptables/tests/shell/testcases/ipt-restore/0010-noflush-new-chain_0
iptables/tests/shell/testcases/ipt-restore/0010-noflush-new-chain_0 new file +10 -0
new file mode 100755
index 0000000000000..739e684a21183
@@ -0,0 +1,10 @@
+#!/bin/sh -e
+
+# assert input feed from buffer doesn't trip over
+# added nul-chars from parsing chain line.
+
+$XT_MULTI iptables-restore --noflush <<EOF
+*filter
+:foobar - [0:0]
+-A foobar -j ACCEPT
+COMMIT
iptables/xtables-restore.c +3 -1
index 2f0fe7d439d94..dd907e0b8ddd5 100644
@@ -327,10 +327,12 @@ void xtables_restore_parse(struct nft_handle *h,
 	line = 0;
 	ptr = preload_buffer;
 	while (*ptr) {
+		size_t len = strlen(ptr);
+
 		h->error.lineno = ++line;
 		DEBUGP("%s: buffered line %d: '%s'\n", __func__, line, ptr);
 		xtables_restore_parse_line(h, p, &state, ptr);
-		ptr += strlen(ptr) + 1;
+		ptr += len + 1;
 	}
 	if (*buffer) {
 		h->error.lineno = ++line;
Signature · 1 line
2.24.0
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [iptables PATCH 2/2] xtables-restore: Fix parser feed from line buffer

Quoted 8 lines · Phil Sutter

When called with --noflush, xtables-restore would trip over chain lines:
Parser uses strtok() to separate chain name, policy and counters which inserts nul-chars into the source string. Therefore strlen() can't be used anymore to find end of line. Fix this by caching line length before calling xtables_restore_parse_line().

Fixes 09cb517949e69 ("xtables-restore: Improve performance of --noflush operation")
maintainer Acked-by on v1 1/2
#3 lore raw
In reply to Phil Sutter
Quoted 5 lines · Phil Sutter

Fixed commit missed to update this conditional call to nft_rule_print_save().

Fixes 1e8ef6a584754 ("nft: family_ops: Pass nft_handle to 'rule_to_cs' callback")

If you still find all this debugging useful.

Otherwise, remove the nft DEBUG is another option. IIRC those were added at very early stage to fix a few issues with -D and -C commands.

Pick the one you prefer. Thanks!

author reviewer
#4 lore raw

Hi,

Quoted 7 lines · Pablo Neira Ayuso
Quoted 5 lines · Phil Sutter

Fixed commit missed to update this conditional call to nft_rule_print_save().

Fixes 1e8ef6a584754 ("nft: family_ops: Pass nft_handle to 'rule_to_cs' callback")
Quoted 8 lines

If you still find all this debugging useful.

Otherwise, remove the nft DEBUG is another option. IIRC those were added at very early stage to fix a few issues with -D and -C commands.

Pick the one you prefer. Thanks!

While it's definitely not as convenient as calling 'nft --debug=<foo>', it's better than nothing. So I'm rather tempted to try and implement a permanent debug output option although all the added jumps will probably kill kubernetes. ;)

Cheers, Phil