From 2d95249a237dba384561558ad89d432ca24ee201 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 12 Mar 2013 18:16:46 +0100 Subject: iptables: Factor out duplicated update hook code After removing one or more rules the builtin hooks need to be updated accordingly. iptables_flush_chain() and iptables_delete_rule() share a common code part. --- src/iptables.c | 60 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) (limited to 'src/iptables.c') diff --git a/src/iptables.c b/src/iptables.c index 2c6580be..e4935b2d 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -515,6 +515,29 @@ static int remove_table_entry(struct connman_iptables *table, return removed; } +static void delete_update_hooks(struct connman_iptables *table, + int builtin, GList *chain_head, + int removed) +{ + struct connman_iptables_entry *e; + GList *list; + + e = chain_head->data; + e->builtin = builtin; + + table->underflow[builtin] -= removed; + + for (list = chain_head->next; list; list = list->next) { + e = list->data; + + if (e->builtin < 0) + continue; + + table->hook_entry[e->builtin] -= removed; + table->underflow[e->builtin] -= removed; + } +} + static int iptables_flush_chain(struct connman_iptables *table, const char *name) { @@ -552,26 +575,8 @@ static int iptables_flush_chain(struct connman_iptables *table, list = next; } - if (builtin >= 0) { - struct connman_iptables_entry *e; - - entry = list->data; - - entry->builtin = builtin; - - table->underflow[builtin] -= removed; - - for (list = chain_tail; list; list = list->next) { - e = list->data; - - builtin = e->builtin; - if (builtin < 0) - continue; - - table->hook_entry[builtin] -= removed; - table->underflow[builtin] -= removed; - } - } + if (builtin >= 0) + delete_update_hooks(table, builtin, chain_tail->prev, removed); update_offsets(table); @@ -1050,19 +1055,8 @@ static int iptables_delete_rule(struct connman_iptables *table, removed += remove_table_entry(table, entry); - if (builtin >= 0) { - table->underflow[builtin] -= removed; - for (list = chain_tail; list; list = list->next) { - entry = list->data; - - builtin = entry->builtin; - if (builtin < 0) - continue; - - table->hook_entry[builtin] -= removed; - table->underflow[builtin] -= removed; - } - } + if (builtin >= 0) + delete_update_hooks(table, builtin, chain_head, removed); update_offsets(table); -- cgit v1.2.3