From: Daniel Wagner <daniel.wag...@bmw-carit.de>

There are a few useless checks in there. prepare_rule_inclusion()
already does those tests. Also add some comments what is happening
in here.
---
 src/iptables.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/src/iptables.c b/src/iptables.c
index 5363ce1..3886cfc 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -733,33 +733,31 @@ static struct ipt_entry *new_rule(struct ipt_ip *ip,
        return new_entry;
 }
 
-static void update_hooks(struct connman_iptables *table, GList *chain_head,
-                               struct ipt_entry *entry)
+static void insert_update_hooks(struct connman_iptables *table, GList 
*chain_head,
+                               struct ipt_entry *new_entry)
 {
+       struct connman_iptables_entry *e;
        GList *list;
-       struct connman_iptables_entry *head, *e;
-       int builtin;
-
-       if (chain_head == NULL)
-               return;
-
-       head = chain_head->data;
 
-       builtin = head->builtin;
-       if (builtin < 0)
-               return;
-
-       table->underflow[builtin] += entry->next_offset;
+       /*
+        * We insert the rule into e->builtin chain, so we do not have
+        * to updated the current hook_entry.
+        */
+       e = chain_head->data;
+       table->underflow[e->builtin] += new_entry->next_offset;
 
+       /*
+        * All builtin chains which follow the current chain
+        * need to be updated.
+        */
        for (list = chain_head->next; list; list = list->next) {
                e = list->data;
 
-               builtin = e->builtin;
-               if (builtin < 0)
+               if (e->builtin < 0)
                        continue;
 
-               table->hook_entry[builtin] += entry->next_offset;
-               table->underflow[builtin] += entry->next_offset;
+               table->hook_entry[e->builtin] += new_entry->next_offset;
+               table->underflow[e->builtin] += new_entry->next_offset;
        }
 }
 
@@ -800,7 +798,7 @@ static struct ipt_entry *prepare_rule_inclusion(struct 
connman_iptables *table,
                 * underflow.
                 */
 
-               update_hooks(table, chain_head, new_entry);
+               insert_update_hooks(table, chain_head, new_entry);
 
                /*
                 * The new entry needs gets the builtin marker
-- 
1.8.1.3.566.gaa39828

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to