summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2012-02-01 14:38:15 (GMT)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>2012-02-03 12:54:44 (GMT)
commit42e7dcc2adac3f0acd0588cdcd43e1ba0b0f52ce (patch)
treed0ae0410969fb6a118535b82259548ffaa6b87ad /tools
parentcd7146afc61f0addd46d94ae8783747289f2f962 (diff)
downloadconnman-42e7dcc2adac3f0acd0588cdcd43e1ba0b0f52ce.zip
connman-42e7dcc2adac3f0acd0588cdcd43e1ba0b0f52ce.tar.gz
connman-42e7dcc2adac3f0acd0588cdcd43e1ba0b0f52ce.tar.bz2
test: refactoring rule finding part into iptables-test
Diffstat (limited to 'tools')
-rw-r--r--tools/iptables-test.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/tools/iptables-test.c b/tools/iptables-test.c
index b3f1ce1..b41e349 100644
--- a/tools/iptables-test.c
+++ b/tools/iptables-test.c
@@ -755,7 +755,7 @@ static gboolean is_same_match(struct xt_entry_match *xt_e_m1,
return TRUE;
}
-static int connman_iptables_delete_rule(struct connman_iptables *table,
+static GList *find_existing_rule(struct connman_iptables *table,
struct ipt_ip *ip, char *chain_name,
char *target_name, struct xtables_target *xt_t,
struct xtables_match *xt_m,
@@ -766,24 +766,22 @@ static int connman_iptables_delete_rule(struct connman_iptables *table,
struct xt_entry_match *xt_e_m = NULL;
struct connman_iptables_entry *entry;
struct ipt_entry *entry_test;
- int builtin, removed;
-
- removed = 0;
+ int builtin;
chain_head = find_chain_head(table, chain_name);
if (chain_head == NULL)
- return -EINVAL;
+ return NULL;
chain_tail = find_chain_tail(table, chain_name);
if (chain_tail == NULL)
- return -EINVAL;
+ return NULL;
if (!xt_t && !xt_m)
- return -EINVAL;
+ return NULL;
entry_test = new_rule(ip, target_name, xt_t, xt_rm);
if (entry_test == NULL)
- return -EINVAL;
+ return NULL;
if (xt_t != NULL)
xt_e_t = ipt_get_target(entry_test);
@@ -798,7 +796,7 @@ static int connman_iptables_delete_rule(struct connman_iptables *table,
else
list = chain_head->next;
- for (entry = NULL; list != chain_tail->prev; list = list->next) {
+ for (; list != chain_tail->prev; list = list->next) {
struct connman_iptables_entry *tmp;
struct ipt_entry *tmp_e;
@@ -826,14 +824,44 @@ static int connman_iptables_delete_rule(struct connman_iptables *table,
continue;
}
- entry = tmp;
break;
}
- if (entry == NULL) {
- g_free(entry_test);
+ g_free(entry_test);
+
+ if (list != chain_tail->prev)
+ return list;
+
+ return NULL;
+}
+
+static int connman_iptables_delete_rule(struct connman_iptables *table,
+ struct ipt_ip *ip, char *chain_name,
+ char *target_name, struct xtables_target *xt_t,
+ struct xtables_match *xt_m,
+ struct xtables_rule_match *xt_rm)
+{
+ struct connman_iptables_entry *entry;
+ GList *chain_tail, *list;
+ int builtin, removed;
+
+ removed = 0;
+
+ chain_tail = find_chain_tail(table, chain_name);
+ if (chain_tail == NULL)
return -EINVAL;
- }
+
+ list = find_existing_rule(table, ip, chain_name, target_name,
+ xt_t, xt_m, xt_rm);
+ if (list == NULL)
+ return -EINVAL;
+
+ entry = list->data;
+
+ if (entry == NULL)
+ return -EINVAL;
+
+ builtin = entry->builtin;
/* We have deleted a rule,
* all references should be bumped accordingly */