tools: iptables-test delete a chain if only it is already flushed.
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Thu, 22 Sep 2011 12:39:21 +0000 (15:39 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 22 Sep 2011 13:22:46 +0000 (15:22 +0200)
tools/iptables-test.c

index 5e7c866..2ae6bb2 100644 (file)
@@ -407,30 +407,31 @@ static int connman_iptables_flush_chain(struct connman_iptables *table,
 static int connman_iptables_delete_chain(struct connman_iptables *table,
                                                char *name)
 {
-       GList *chain_head, *chain_tail, *list, *next;
+       GList *chain_head, *chain_tail;
        struct connman_iptables_entry *entry;
 
        chain_head = find_chain_head(table, name);
        if (chain_head == NULL)
                return -EINVAL;
 
+       entry = chain_head->data;
+
+       /* We cannot remove builtin chain */
+       if (entry->builtin >= 0)
+               return -EINVAL;
+
        chain_tail = find_chain_tail(table, name);
        if (chain_tail == NULL)
                return -EINVAL;
 
-       list = chain_head;
-
-       while (list != chain_tail) {
-               entry = list->data;
-               next = g_list_next(list);
-
-               table->num_entries--;
-               table->size -= entry->entry->next_offset;
+       /* Chain must be flushed */
+       if (chain_head->next != chain_tail->prev)
+               return -EINVAL;
 
-               table->entries = g_list_remove(table->entries, list->data);
+       remove_table_entry(table, entry);
 
-               list = next;
-       }
+       entry = chain_tail->prev->data;
+       remove_table_entry(table, entry);
 
        update_offsets(table);