]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
ipset: Set maxelem to a fixed size
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Mar 2022 10:18:16 +0000 (10:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Mar 2022 10:18:16 +0000 (10:18 +0000)
When we try to load a changed set which might have more entries, a
previous maxelem could have been smaller preventing us from adding new
entries.

We also cannot run the "create" command with a changed maxelem
parameter which is why this patch set the value to something that should
be large enough for everything.

The downside of this is also, that we cannot modify the hashsize when we
reload a set, which is probably okay, since sets should not change too
much in size and therefore will only run *slightly* less efficient - if
at all.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/export.py

index 10cf2b79bcafad99f9e7d61af431e23d855ab774..10f84f45f3ba6abd03b32e107f8d3f986079ac4d 100644 (file)
@@ -131,22 +131,13 @@ class IpsetOutputWriter(OutputWriter):
                # Return the size of the hash
                return 2 ** math.ceil(exponent)
 
-       @property
-       def maxelem(self):
-               """
-                       Tells ipset how large the set will be.
-
-                       Since these are considered immutable, we will use the total number of networks.
-               """
-               return self.networks
-
        def _write_header(self):
                # This must have a fixed size, because we will write the header again in the end
                self.f.write("create %s hash:net family inet%s" % (
                        self.prefix,
                        "6" if self.family == socket.AF_INET6 else ""
                ))
-               self.f.write(" hashsize %8d maxelem %8d -exist\n" % (self.hashsize, self.maxelem))
+               self.f.write(" hashsize %8d maxelem 1048576 -exist\n" % self.hashsize)
                self.f.write("flush %s\n" % self.prefix)
 
        def write(self, network):