iptables: Update the hook entries correctly in iptables_delete_rule()
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 12 Feb 2013 09:19:55 +0000 (10:19 +0100)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 12 Feb 2013 10:35:14 +0000 (12:35 +0200)
The builtin value is only valid in the chain head entry and not
in any other entry. That means we need to lookup the head entry
and use that builtin value (== hook id) and then update all
references which follow that chain.

src/iptables.c

index 97b9539..83612b9 100644 (file)
@@ -970,11 +970,15 @@ static int iptables_delete_rule(struct connman_iptables *table,
                                struct xtables_rule_match *xt_rm)
 {
        struct connman_iptables_entry *entry;
-       GList *chain_tail, *list;
+       GList *chain_head, *chain_tail, *list;
        int builtin, removed;
 
        removed = 0;
 
+       chain_head = find_chain_head(table, chain_name);
+       if (chain_head == NULL)
+               return -EINVAL;
+
        chain_tail = find_chain_tail(table, chain_name);
        if (chain_tail == NULL)
                return -EINVAL;
@@ -984,12 +988,13 @@ static int iptables_delete_rule(struct connman_iptables *table,
        if (list == NULL)
                return -EINVAL;
 
+       entry = chain_head->data;
+       builtin = entry->builtin;
+
        entry = list->data;
        if (entry == NULL)
                return -EINVAL;
 
-       builtin = entry->builtin;
-
        /* We have deleted a rule,
         * all references should be bumped accordingly */
        if (list->next != NULL)