]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
Implement some optimization for finding rules to replace in TC_REPLACE_ENTRY.
authorMartin Josefsson <gandalf@wlug.westbo.se>
Sat, 18 Dec 2004 17:18:49 +0000 (17:18 +0000)
committerMartin Josefsson <gandalf@wlug.westbo.se>
Sat, 18 Dec 2004 17:18:49 +0000 (17:18 +0000)
Stolen from TC_DELETE_NUM_ENTRY.

libiptc/libiptc.c

index 218ff0393345f54f309a1ad40c8603f6a67f4812..dfa2d1f097b574201bfd011b4d9e1cebc2a57c08 100644 (file)
@@ -1,4 +1,4 @@
-/* Library which manipulates firewall rules.  Version $Revision: 1.56 $ */
+/* Library which manipulates firewall rules.  Version $Revision$ */
 
 /* Architecture of firewall rules is as follows:
  *
@@ -1319,11 +1319,18 @@ TC_REPLACE_ENTRY(const IPT_CHAINLABEL chain,
                return 0;
        }
 
-       if (!(old = iptcc_get_rule_num(c, rulenum + 1))) {
+       if (rulenum >= c->num_rules) {
                errno = E2BIG;
                return 0;
        }
 
+       /* Take advantage of the double linked list if possible. */
+       if (rulenum + 1 <= c->num_rules/2) {
+               old = iptcc_get_rule_num(c, rulenum + 1);
+       } else {
+               old = iptcc_get_rule_num_reverse(c, c->num_rules - rulenum);
+       }
+
        if (!(r = iptcc_alloc_rule(c, e->next_offset))) {
                errno = ENOMEM;
                return 0;