netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] iptables-compat: fix chain policy reset with iptables -L -n
@ 2014-10-23 11:18 Pablo Neira Ayuso
  2014-10-23 11:18 ` [PATCH 2/3] iptables-compat: statify unused built-in table/chain functions Pablo Neira Ayuso
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2014-10-23 11:18 UTC (permalink / raw)
  To: netfilter-devel; +Cc: anarey

Initialize built-in tables/chains if they don't exists, otherwise
simply skip.

This avoids the chain policy reset to NF_ACCEPT by when you call
iptables -L -n.

Reported-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 iptables/nft.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/iptables/nft.c b/iptables/nft.c
index ca199cd..b68b275 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -620,11 +620,17 @@ __nft_chain_builtin_init(struct nft_handle *h,
 			 int policy)
 {
 	int i, default_policy;
+	struct nft_chain_list *list = nft_chain_dump(h);
+	struct nft_chain *c;
 
-	/* Initialize all built-in chains. Exception, for e one received as
-	 * parameter, set the default policy as requested.
-	 */
+	/* Initialize built-in chains if they don't exist yet */
 	for (i=0; i<NF_IP_NUMHOOKS && table->chains[i].name != NULL; i++) {
+
+		c = nft_chain_list_find(list, table->name,
+					table->chains[i].name);
+		if (c != NULL)
+			continue;
+
 		if (chain && strcmp(table->chains[i].name, chain) == 0)
 			default_policy = policy;
 		else
@@ -633,6 +639,8 @@ __nft_chain_builtin_init(struct nft_handle *h,
 		nft_chain_builtin_add(h, table, &table->chains[i],
 					default_policy);
 	}
+
+	nft_chain_list_free(list);
 }
 
 int
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-24  7:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-23 11:18 [PATCH 1/3] iptables-compat: fix chain policy reset with iptables -L -n Pablo Neira Ayuso
2014-10-23 11:18 ` [PATCH 2/3] iptables-compat: statify unused built-in table/chain functions Pablo Neira Ayuso
2014-10-23 11:18 ` [PATCH 3/3] iptables-compat: assume chain policy NF_ACCEPT when creating built-in chains Pablo Neira Ayuso
2014-10-24  7:49 ` [PATCH 1/3] iptables-compat: fix chain policy reset with iptables -L -n Ana Rey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).