From: Daniel Wagner <[email protected]>
find_chain_tail() returns the list element after the chain end.
If we return the real last element of the chain we can simplify
the code considerable.
This allows a simple bug fix in the next patch.
---
src/iptables.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/iptables.c b/src/iptables.c
index 1a4e758..086b8bf 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -376,7 +376,7 @@ static GList *find_chain_head(struct connman_iptables
*table,
static GList *find_chain_tail(struct connman_iptables *table,
const char *chain_name)
{
- struct connman_iptables_entry *tail;
+ struct connman_iptables_entry *entry;
GList *chain_head, *list;
chain_head = find_chain_head(table, chain_name);
@@ -385,10 +385,12 @@ static GList *find_chain_tail(struct connman_iptables
*table,
/* Then we look for the next chain */
for (list = chain_head->next; list; list = list->next) {
- tail = list->data;
+ entry = list->data;
+
+ if (is_chain(table, entry) == FALSE)
+ continue;
- if (is_chain(table, tail))
- return list;
+ return g_list_previous(list);
}
/* Nothing found, we return the table end */
@@ -529,6 +531,10 @@ static int iptables_flush_chain(struct connman_iptables
*table,
if (chain_tail == NULL)
return -EINVAL;
+ /* Is chain already emtpy ?*/
+ if (chain_head == chain_tail)
+ return 0;
+
entry = chain_head->data;
builtin = entry->builtin;
@@ -537,10 +543,7 @@ static int iptables_flush_chain(struct connman_iptables
*table,
else
list = chain_head->next;
- if (list == chain_tail->prev)
- return 0;
-
- while (list != chain_tail->prev) {
+ while (list != chain_tail) {
entry = list->data;
next = g_list_next(list);
@@ -666,13 +669,10 @@ static int iptables_delete_chain(struct connman_iptables
*table,
if (chain_tail == NULL)
return -EINVAL;
- /* Chain must be flushed */
- if (chain_head->next != chain_tail->prev)
- return -EINVAL;
-
+ entry = chain_head->data;
remove_table_entry(table, entry);
- entry = chain_tail->prev->data;
+ entry = chain_tail->data;
remove_table_entry(table, entry);
update_offsets(table);
--
1.8.1.3.566.gaa39828
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman