summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2011-09-22 12:39:21 (GMT)
committerSamuel Ortiz <sameo@linux.intel.com>2011-09-22 13:22:46 (GMT)
commitf3c74f0ea3d1665e41b3661676865803c8fb8955 (patch)
treeb5d1a4e43f593e2ae5b6c6d566cdba6ef0b54b54 /tools
parentc8b43c537ad8efe6f0d8de62bc4114c328185f16 (diff)
downloadconnman-f3c74f0ea3d1665e41b3661676865803c8fb8955.zip
connman-f3c74f0ea3d1665e41b3661676865803c8fb8955.tar.gz
connman-f3c74f0ea3d1665e41b3661676865803c8fb8955.tar.bz2
tools: iptables-test delete a chain if only it is already flushed.
Diffstat (limited to 'tools')
-rw-r--r--tools/iptables-test.c25
1 files changed, 13 insertions, 12 deletions
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);