All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch] ip{,6}tables-restore -n with existing user defined chain
@ 2005-05-18 16:07 Charlie Brady
  2005-05-19 14:14 ` [Patch] ip{, 6}tables-restore " Charlie Brady
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Charlie Brady @ 2005-05-18 16:07 UTC (permalink / raw)
  To: netfilter-devel


I want to redefine an existing chain atomically. I can't do that with the 
iptables command, but can almost do it with iptables-restore -n. When I 
try, iptables barfs because the chain already exists. Duh! Yeah, I know 
it exists, but I want to redefine it.

I don't see the semantics of this case defined anywhere, and I can't find 
discussion of it in the archives. So I suggest that the semantics be 
redefined, so that iptables-restore -n can redefine an existing chain 
(iptables-restore without -n already does that). I really can't think why 
anyone would depend on the current semantics.

Index: ip6tables-restore.c
===================================================================
--- ip6tables-restore.c	(revision 3922)
+++ ip6tables-restore.c	(working copy)
@@ -233,12 +233,21 @@
  			}

  			if (ip6tc_builtin(chain, handle) <= 0) {
-				DEBUGP("Creating new chain '%s'\n", chain);
-				if (!ip6tc_create_chain(chain, &handle))
-					exit_error(PARAMETER_PROBLEM,
-						   "error creating chain "
-						   "'%s':%s\n", chain,
-						   strerror(errno));
+				if (noflush && ip6tc_is_chain(chain, handle)) {
+					DEBUGP("Flushing existing user defined chain '%s'\n", chain);
+					if (!ip6tc_flush_entries(chain, &handle))
+						exit_error(PARAMETER_PROBLEM,
+							   "error flushing chain "
+							   "'%s':%s\n", chain,
+							   strerror(errno));
+				} else {
+					DEBUGP("Creating new chain '%s'\n", chain);
+					if (!ip6tc_create_chain(chain, &handle))
+						exit_error(PARAMETER_PROBLEM,
+							   "error creating chain "
+							   "'%s':%s\n", chain,
+							   strerror(errno));
+				}
  			}

  			policy = strtok(NULL, " \t\n");
Index: iptables-restore.c
===================================================================
--- iptables-restore.c	(revision 3922)
+++ iptables-restore.c	(working copy)
@@ -236,12 +236,21 @@
  			}

  			if (iptc_builtin(chain, handle) <= 0) {
-				DEBUGP("Creating new chain '%s'\n", chain);
-				if (!iptc_create_chain(chain, &handle))
-					exit_error(PARAMETER_PROBLEM,
-						   "error creating chain "
-						   "'%s':%s\n", chain,
-						   strerror(errno));
+				if (noflush && iptc_is_chain(chain, handle)) {
+					DEBUGP("Flushing existing user defined chain '%s'\n", chain);
+					if (!iptc_flush_entries(chain, &handle))
+						exit_error(PARAMETER_PROBLEM,
+							   "error flushing chain "
+							   "'%s':%s\n", chain,
+							   strerror(errno));
+				} else {
+					DEBUGP("Creating new chain '%s'\n", chain);
+					if (!iptc_create_chain(chain, &handle))
+						exit_error(PARAMETER_PROBLEM,
+							   "error creating chain "
+							   "'%s':%s\n", chain,
+							   strerror(errno));
+				}
  			}

  			policy = strtok(NULL, " \t\n");

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

end of thread, other threads:[~2005-06-13  2:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-18 16:07 [Patch] ip{,6}tables-restore -n with existing user defined chain Charlie Brady
2005-05-19 14:14 ` [Patch] ip{, 6}tables-restore " Charlie Brady
2005-05-19 15:43 ` Jonas Berlin
2005-05-19 15:57   ` Charlie Brady
2005-05-19 16:04     ` Charlie Brady
2005-05-19 16:37   ` Carl-Daniel Hailfinger
2005-05-19 16:46     ` Charlie Brady
2005-06-11 16:12 ` Patrick McHardy
2005-06-12  9:56   ` Harald Welte
2005-06-12 13:38     ` Patrick McHardy
2005-06-12 15:20       ` Charlie Brady
2005-06-12 15:43         ` Patrick McHardy
2005-06-13  2:24           ` Charlie Brady

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.