tools: Factorization of target reference update in iptables-test
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Thu, 22 Sep 2011 12:39:30 +0000 (15:39 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 22 Sep 2011 13:22:47 +0000 (15:22 +0200)
tools/iptables-test.c

index b995afc..446331b 100644 (file)
@@ -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);