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>
# 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):