[netfilter-cvslog] r3639 - trunk/iptables/libiptc

laforge at netfilter.org laforge at netfilter.org
Tue Feb 1 17:45:57 CET 2005


Author: laforge at netfilter.org
Date: 2005-02-01 17:45:56 +0100 (Tue, 01 Feb 2005)
New Revision: 3639

Modified:
   trunk/iptables/libiptc/libiptc.c
Log:
re-implement alphabetic sorting to not confuse users who upgrade to 1.3.0


Modified: trunk/iptables/libiptc/libiptc.c
===================================================================
--- trunk/iptables/libiptc/libiptc.c	2005-02-01 15:53:07 UTC (rev 3638)
+++ trunk/iptables/libiptc/libiptc.c	2005-02-01 16:45:56 UTC (rev 3639)
@@ -356,12 +356,6 @@
  * RULESET PARSER (blob -> cache)
  **********************************************************************/
 
-static int alphasort(const void *a, const void *b)
-{
-	return strcmp(((struct chain_head *)a)->name,
-		      ((struct chain_head *)b)->name);
-}
-
 /* Delete policy rule of previous chain, since cache doesn't contain
  * chain policy rules.
  * WARNING: This function has ugly design and relies on a lot of context, only
@@ -397,6 +391,22 @@
 	return 0;
 }
 
+/* alphabetically insert a chain into the list */
+static inline void iptc_insert_chain(TC_HANDLE_T h, struct chain_head *c)
+{
+	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;
+		}
+	}
+
+	/* survived till end of list: add at tail */
+	list_add_tail(&c->list, &h->chains);
+}
+
 /* Another ugly helper function split out of cache_add_entry to make it less
  * spaghetti code */
 static void __iptcc_p_add_chain(TC_HANDLE_T h, struct chain_head *c,
@@ -407,7 +417,8 @@
 	c->head_offset = offset;
 	c->index = *num;
 
-	list_add_tail(&c->list, &h->chains);
+	iptc_insert_chain(h, c);
+	
 	h->chain_iterator_cur = c;
 }
 




More information about the netfilter-cvslog mailing list