Skip to contentSkip to conversation

iptables: Fix handling of non-existent chains

PATCH In review Jacek Tomasiak 2 participants 2 messages Jun 19, 2023 – Jun 21, 2023 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iptables: Fix handling of non-existent chains

Since 694612adf87 the "compatibility" check considers non-existent chains as "incompatible". This broke some scripts which used calls like iptables -L CHAIN404 to test for chain existence and expect "No chain/target/match by that name." in the output.

This patch changes the logic of nft_is_table_compatible() to report non-existent chains as "compatible" which restores the old behavior.

Fixes 694612adf87 ("nft: Fix selective chain compatibility checks")
---
 iptables/nft.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
iptables/nft.c +1 -1
index 1cb104e7..020553a4 100644
@@ -3860,7 +3860,7 @@ bool nft_is_table_compatible(struct nft_handle *h,
 	if (chain) {
 		struct nft_chain *c = nft_chain_find(h, table, chain);
 
-		return c && !nft_is_chain_compatible(c, h);
+		return !c || !nft_is_chain_compatible(c, h);
 	}
 
 	return !nft_chain_foreach(h, table, nft_is_chain_compatible, h);
Signature · 1 line
2.35.3
reviewer
#1 lore raw
Quoted 5 lines · Jacek Tomasiak

Since 694612adf87 the "compatibility" check considers non-existent chains as "incompatible". This broke some scripts which used calls like iptables -L CHAIN404 to test for chain existence and expect "No chain/target/match by that name." in the output.

Quoted 8 lines

This patch changes the logic of nft_is_table_compatible() to report non-existent chains as "compatible" which restores the old behavior.

Fixes 694612adf87 ("nft: Fix selective chain compatibility checks")

Also applied after adding testsuite coverage to it.

Thanks, Phil