diff options
author | Harald Welte <laforge@gnumonks.org> | 2005-02-01 16:45:56 +0000 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2005-02-01 16:45:56 +0000 |
commit | ec30b6c4d3ebb09d2c05e44f3904428893ef13bd (patch) | |
tree | 0c0443f533de2391cd0f24f08ab107e58b3aeee5 /libiptc | |
parent | 37963e0e357b31b6378cc711a7ca54dad5f7f921 (diff) |
re-implement alphabetic sorting to not confuse users who upgrade to 1.3.0
Diffstat (limited to 'libiptc')
-rw-r--r-- | libiptc/libiptc.c | 25 |
1 files changed, 18 insertions, 7 deletions
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; } |