From ec30b6c4d3ebb09d2c05e44f3904428893ef13bd Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 1 Feb 2005 16:45:56 +0000 Subject: re-implement alphabetic sorting to not confuse users who upgrade to 1.3.0 --- libiptc/libiptc.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'libiptc') diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c index 3557f57a..7bed2211 100644 --- a/libiptc/libiptc.c +++ b/libiptc/libiptc.c @@ -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; } -- cgit v1.2.3