]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
re-implement alphabetic sorting to not confuse users who upgrade to 1.3.0
authorHarald Welte <laforge@gnumonks.org>
Tue, 1 Feb 2005 16:45:56 +0000 (16:45 +0000)
committerHarald Welte <laforge@gnumonks.org>
Tue, 1 Feb 2005 16:45:56 +0000 (16:45 +0000)
libiptc/libiptc.c

index 3557f57aa76db6d7b2086bc3aa68e6c0ab66ce92..7bed22115fec163ab16e3869e1f7757dcde75449 100644 (file)
@@ -356,12 +356,6 @@ static void iptcc_delete_rule(struct rule_head *r)
  * 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 @@ static int __iptcc_p_del_policy(TC_HANDLE_T h, unsigned int num)
        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 @@ static void __iptcc_p_add_chain(TC_HANDLE_T h, struct chain_head *c,
        c->head_offset = offset;
        c->index = *num;
 
-       list_add_tail(&c->list, &h->chains);
+       iptc_insert_chain(h, c);
+       
        h->chain_iterator_cur = c;
 }