summaryrefslogtreecommitdiff
path: root/src/iptables.c
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2013-03-12 18:16:46 +0100
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-03-18 14:31:26 +0200
commit2d95249a237dba384561558ad89d432ca24ee201 (patch)
tree9772470c609493222472c98a3058ac0fdc1f2777 /src/iptables.c
parentedaf6f6182a256a29926b0c016d72cc50f1f0c75 (diff)
downloadconnman-2d95249a237dba384561558ad89d432ca24ee201.tar.gz
connman-2d95249a237dba384561558ad89d432ca24ee201.tar.bz2
connman-2d95249a237dba384561558ad89d432ca24ee201.zip
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.
Diffstat (limited to 'src/iptables.c')
-rw-r--r--src/iptables.c60
1 files changed, 27 insertions, 33 deletions
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);