All of lore.kernel.org
 help / color / mirror / Atom feed
* [iptables 1.3.0 / libiptc patch] sort chains by hooknum/names
@ 2005-03-04 20:21 Olaf Rempel
  2005-03-04 22:08 ` Phil Oester
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Olaf Rempel @ 2005-03-04 20:21 UTC (permalink / raw)
  To: netfilter-devel

hi list

>From 1.3.0 all chain names were alphabetically sorted when listing tables.
A user-defined chain 'AAA' is listed before the buildin chain "INPUT", and 
"FORWARD" is listed before "INPUT".

I've created two patches to revert it to the "old" behavior:
first buildin chains, sorted by hooknum, than userdefined chains, sorted by name.

OK, why two patches? 
The first one need some preconditions: 
*all* buildin chains need to be "in order" and in front of *any* user chain 
when parsing the kernel-list.

I was not sure about this, so I made a second patch, that does not need these
preconditions. 

Olaf


diff -uNr iptables-1.3.0.org/libiptc/libiptc.c iptables-1.3.0/libiptc/libiptc.c
--- iptables-1.3.0.org/libiptc/libiptc.c	2005-02-12 21:05:32.000000000 +0100
+++ iptables-1.3.0/libiptc/libiptc.c	2005-03-04 17:12:17.909906736 +0100
@@ -396,10 +396,13 @@
 {
 	struct chain_head *tmp;
 
-	list_for_each_entry(tmp, &h->chains, list) {
-		if (strcmp(c->name, tmp->name) <= 0) {
-			list_add(&c->list, tmp->list.prev);
-			return;
+	/* sort only user defined chains */
+	if (!c->hooknum) {
+		list_for_each_entry(tmp, &h->chains, list) {
+			if (strcmp(c->name, tmp->name) <= 0) {
+				list_add(&c->list, tmp->list.prev);
+				return;
+			}
 		}
 	}


diff -uNr iptables-1.3.0.org/libiptc/libiptc.c iptables-1.3.0/libiptc/libiptc.c
--- iptables-1.3.0.org/libiptc/libiptc.c	2005-02-12 21:05:32.000000000 +0100
+++ iptables-1.3.0/libiptc/libiptc.c	2005-03-04 17:20:12.720724520 +0100
@@ -396,10 +396,23 @@
 {
 	struct chain_head *tmp;
 
-	list_for_each_entry(tmp, &h->chains, list) {
-		if (strcmp(c->name, tmp->name) <= 0) {
-			list_add(&c->list, tmp->list.prev);
-			return;
+	/* sort only user defined chains */
+	if (!c->hooknum) {
+		/* sort user-defined by name and after builtins */
+		list_for_each_entry(tmp, &h->chains, list) {
+			if (!tmp->hooknum && strcmp(c->name, tmp->name) <= 0) {
+				list_add(&c->list, tmp->list.prev);
+				return;
+			}
+		}
+	
+	} else {
+		/* sort builtins by hooknum and before user-defined */
+		list_for_each_entry(tmp, &h->chains, list) {
+			if (!tmp->hooknum || tmp->hooknum > c->hooknum) {
+				list_add(&c->list, tmp->list.prev);
+				return;
+			}
 		}
 	}
 

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

end of thread, other threads:[~2005-04-19 14:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-04 20:21 [iptables 1.3.0 / libiptc patch] sort chains by hooknum/names Olaf Rempel
2005-03-04 22:08 ` Phil Oester
2005-03-04 22:38   ` Patrick McHardy
2005-03-04 23:15   ` Olaf Rempel
2005-03-04 23:04 ` Patrick McHardy
2005-04-19 14:51   ` Jonas Berlin
2005-03-05  2:07 ` Herve Eychenne

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.