From: Tomasz Bursztyka Date: Thu, 22 Sep 2011 12:39:21 +0000 (+0300) Subject: tools: iptables-test delete a chain if only it is already flushed. X-Git-Tag: 2.0_alpha~1105 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3c74f0ea3d1665e41b3661676865803c8fb8955;p=framework%2Fconnectivity%2Fconnman.git tools: iptables-test delete a chain if only it is already flushed. --- diff --git a/tools/iptables-test.c b/tools/iptables-test.c index 5e7c866..2ae6bb2 100644 --- a/tools/iptables-test.c +++ b/tools/iptables-test.c @@ -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);