From: Tomasz Bursztyka Date: Thu, 22 Sep 2011 12:39:30 +0000 (+0300) Subject: tools: Factorization of target reference update in iptables-test X-Git-Tag: 0.78~207 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a7a3c975deb32ef04fdcbb658ca317639ede7e4;p=platform%2Fupstream%2Fconnman.git tools: Factorization of target reference update in iptables-test --- diff --git a/tools/iptables-test.c b/tools/iptables-test.c index b995afc..446331b 100644 --- a/tools/iptables-test.c +++ b/tools/iptables-test.c @@ -278,13 +278,32 @@ static void update_offsets(struct connman_iptables *table) } } +static void update_targets_reference(struct connman_iptables *table, + struct connman_iptables_entry *entry_before, + struct connman_iptables_entry *modified_entry) +{ + struct connman_iptables_entry *tmp; + struct xt_standard_target *t; + GList *list; + + for (list = table->entries; list; list = list->next) { + tmp = list->data; + + if (!is_jump(tmp)) + continue; + + t = (struct xt_standard_target *)ipt_get_target(tmp->entry); + + if (t->verdict > entry_before->offset) + t->verdict += modified_entry->entry->next_offset; + } +} + static int connman_add_entry(struct connman_iptables *table, struct ipt_entry *entry, GList *before, int builtin) { - GList *list; - struct connman_iptables_entry *e, *tmp, *entry_before; - struct xt_standard_target *t; + struct connman_iptables_entry *e, *entry_before; if (table == NULL) return -1; @@ -312,17 +331,7 @@ static int connman_add_entry(struct connman_iptables *table, * We've just appended/insterted a new entry. All references * should be bumped accordingly. */ - for (list = table->entries; list; list = list->next) { - tmp = list->data; - - if (!is_jump(tmp)) - continue; - - t = (struct xt_standard_target *)ipt_get_target(tmp->entry); - - if (t->verdict > entry_before->offset) - t->verdict += entry->next_offset; - } + update_targets_reference(table, entry_before, e); update_offsets(table);